AtCoder Regular Contest 136
B
Triple Shift
AtCoder
⌀ 1358
原题
← AC →
翻译中…

Problem Statement

翻译中…

You are given integer sequences of length $N$ each: $A=(A_1,A_2,\cdots,A_N)$ and $B=(B_1,B_2,\cdots,B_N)$.

翻译中…

You can repeat the following operation any number of times.

翻译中…
  • Choose an integer $i$ ($1 \leq i \leq N-2$) and let $x,y,z$ be the current values of $A_i,A_{i+1},A_{i+2}$, respectively. Then, replace the values of $A_i,A_{i+1},A_{i+2}$ with $z,x,y$, respectively.
翻译中…

Determine whether it is possible to make $A$ equal $B$.

翻译中…

Constraints

翻译中…
  • $3 \leq N \leq 5000$
  • $1 \leq A_i,B_i \leq 5000$
  • All values in input are integers.
翻译中…

Input

翻译中…

Input is given from Standard Input in the following format:

翻译中…

N
A_1 A_2 \cdots A_N
B_1 B_2 \cdots B_N

翻译中…

Output

翻译中…

If it is possible to make $A$ equal $B$, print Yes; otherwise, print No.

翻译中…

样例

Input #1
4
3 1 4 5
4 1 5 3
Output #1
Yes
We should do the following. - Initially, we have $A=(3,1,4,5)$. - Do the operation with $i=1$, making $A=(4,3,1,5)$. - Do the operation with $i=2$, making $A=(4,5,3,1)$. - Do the operation with $i=2$, making $A=(4,1,5,3)$.
Input #2
3
1 2 2
2 1 2
Output #2
Yes
Input #3
3
1 2 3
2 3 4
Output #3
No
题目信息
题号
arc136_b
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。