AtCoder Regular Contest 154
C
Roller
AtCoder
⌀ 1881
原题
← BD →
翻译中…

Problem Statement

翻译中…

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

翻译中…

You can repeat the following operation any number of times (possibly zero).

翻译中…
  • Choose an integer $i$ such that $1 \le i \le N$ and replace $A_i$ with $A_{i+1}$.
翻译中…

Here, regard $A_{N+1}$ as $A_1$.

翻译中…

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

翻译中…

You have $T$ test cases to solve.

翻译中…

Constraints

翻译中…
  • $1 \le T \le 5000$
  • $1 \le N \le 5000$
  • $1 \le A_i,B_i \le N$
  • For each input file, the sum of $N$ over all test cases does not exceed $5000$.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T

翻译中…

Each test case is in the following format:

翻译中…

N
A_1 A_2 \dots A_N
B_1 B_2 \dots B_N

翻译中…

Output

翻译中…

Print $T$ lines. The $i$-th line should contain Yes if it is possible to make $A$ equal $B$ in the $i$-th test case, and No otherwise.

翻译中…

样例

Input #1
3
2
1 2
2 2
4
2 3 1 1
2 1 1 2
2
1 1
2 2
Output #1
Yes
Yes
No
In the first test case, you can make $A$ equal $B$ as follows. - Choose $i=1$ to replace $A_1$ with $A_2$, making $A=(2,2)$. In the second test case, you can make $A$ equal $B$ as follows. - Choose $i=4$ to replace $A_4$ with $A_1$, making $A=(2,3,1,2)$. - Choose $i=2$ to replace $A_2$ with $A_3$, making $A=(2,1,1,2)$. In the third test case, there is no way to make $A$ equal $B$.
题目信息
题号
arc154_c
时间限制
2 s
内存限制
1024 MB

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