#ARC136B. [ARC136B] Triple Shift

[ARC136B] Triple Shift

Score : 400400 points

Problem Statement

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

You can repeat the following operation any number of times.

  • Choose an integer ii (1iN21 \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

  • 3N50003 \leq N \leq 5000
  • 1Ai,Bi50001 \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 ANA_N

B1B_1 B2B_2 \cdots BNB_N

Output

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

4
3 1 4 5
4 1 5 3
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).
3
1 2 2
2 1 2
Yes
3
1 2 3
2 3 4
No