#arc136b. [arc136_b]Triple Shift

[arc136_b]Triple Shift

Problem Statement

You are given integer sequences of length NN each: A=(A1,A2,cdots,AN)A=(A_1,A_2,\\cdots,A_N) and B=(B1,B2,cdots,BN)B=(B_1,B_2,\\cdots,B_N).

You can repeat the following operation any number of times.

  • Choose an integer ii (1leqileqN21 \\leq i \\leq N-2) and let x,y,zx,y,z be the current values of Ai,Ai+1,Ai+2A_i,A_{i+1},A_{i+2}, respectively. Then, replace the values of Ai,Ai+1,Ai+2A_i,A_{i+1},A_{i+2} with z,x,yz,x,y, respectively.

Determine whether it is possible to make AA equal BB.

Constraints

  • 3leqNleq50003 \\leq N \\leq 5000
  • 1leqAi,Bileq50001 \\leq A_i,B_i \\leq 5000
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN A1A_1 A2A_2 cdots\\cdots ANA_N B1B_1 B2B_2 cdots\\cdots BNB_N

Output

If it is possible to make AA equal BB, print Yes; otherwise, print No.


Sample Input 1

4
3 1 4 5
4 1 5 3

Sample Output 1

Yes

We should do the following.

  • Initially, we have A=(3,1,4,5)A=(3,1,4,5).
  • Do the operation with i=1i=1, making A=(4,3,1,5)A=(4,3,1,5).
  • Do the operation with i=2i=2, making A=(4,5,3,1)A=(4,5,3,1).
  • Do the operation with i=2i=2, making A=(4,1,5,3)A=(4,1,5,3).

Sample Input 2

3
1 2 2
2 1 2

Sample Output 2

Yes

Sample Input 3

3
1 2 3
2 3 4

Sample Output 3

No