Make It Same
You are given two arrays a and b with m elements. If you can convert b (array) to a (array) after doing the operations described below, output “Yes” otherwise output “No” (Without quotes).
- select an integer k (1 \(\leq\) k \(\leq\) m/2).
- swap the prefix of length k with the suffix of length k.
- You can do these operations any number of times(Possibly zero).
For an example if b={1,2,3,4,5,6}
- If you choose k=1, after swapping , b={6,2,3,4,5,1}
- If you choose k=2, after swapping , b={5,6,3,4,1,2}
- If you choose k=3, after swapping , b={4,5,6,1,2,3}
Input Format
The first line contains one integer n — the number of test cases.
The first line of each test case contains a single integer m — nuumber of elements in the arrays.
The second line of each test case contains m integers a1, a2, …, am (1 \(\leq\) ai \(\leq\) 10000) — elements of array a.
The third line of each test case contains m integers b1, b2, …, bm (1 \(\leq\) bi \(\leq\) 10000) — elements of array b.
Output Format
For each test case, print “Yes” (Without quotes) if you can convert b (array) to a (array). Otherwise print “No” (Without quotes).
Constraints
- 1 \(\leq\) n \(\leq\) 500
- 1 \(\leq\) m \(\leq\) 1000
- 1 \(\leq\) ai , bi \(\leq\) 10000
Limits
- Time Limit: 1s
- Memory Limit: 256MB
Sample Input 0
5
2
1 2
2 1
3
1 2 3
1 2 3
3
1 2 4
1 3 4
4
1 2 3 2
3 1 2 2
3
1 2 3
1 3 2
Sample Output 0
Yes
Yes
No
Yes
No
Open on HackerRank ↗ · Markdown source · Back to the archive