Hat With An Integer

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

The are nn enumerated wise ones. Each of them has a hat with an integer written on it. Each wise one sees numbers on other wise ones' hats, but does not see the number on his own. Let a_ia\_i denote the number written on the hat of the ii-th wise one.

There are also two arrays of integers of length n1n - 1 each: bb and cc. We call the assignment of integers to hats valid if there exists at  least one value of ii, such that 1in11 \leq i \leq n - 1 and at least one the following holds:

  1. a_i+1<a_i+b_ia\_{i+1} < a\_i + b\_i
  2. a_i+1>a_i.+c_ia\_{i+1} > a\_i.+ c\_i

The wise ones know that the actual assignment (i.e. the array aa) is valid. 

The following process happens: Each day, starting from the first, if at the beginning of the day there exists a wise one with index ii who knows an integer xx, such that a_ixa\_i \neq x (i.e. he knows a number which is definitely not written on his hat) he announces this at the end of the day and the process ends. If no such wise one is present the process continues on the next day and so on

Calculate whether the process will end and if it will, calculate the day on which it will happen.

입력

The first line contains a single integer nn (2n1052 \leq n \leq 10^5), the number of wise ones.

The second line contains nn integers a_ia\_i (1010a_i1010-10^{10} \leq a\_i \leq 10^{10}).

The third line contains n1n - 1 integers b_ib\_i (1010b_i1010-10^{10} \leq b\_i \leq 10^{10}).

The fourth line contains n1n - 1 integers c_ic\_i (1010c_i1010-10^{10} \leq c\_i \leq 10^{10}).

It is guaranteed, that the array aa is valid.

출력

Output -1 if the process will never end. Output the day on which the process will end otherwise.

힌트

Consider the first example. The constraints given by arrays bb and cc can be rephrased as "not all integers are equal".

On the first day no wise one can deduce a number which is not written on his hat.

On the second day the third wise one knows, that if the number on his hat was 2, on the first day the first wise one would have seen that both other wise ones have 2 on their hats and would have deduced that he does not wear a hat with 2 written on it. Thus on the second day the third wise one knows that he does not wear a hat with 2 written on it. 

Is this readable? Probably not. Could this have been phrased much better to be readable? Probably not.