P9714 "QFOI R1" Pat Pat.
Description
Little R is a lovely girl, and she likes having her head patted.
However, before patting her head, you must answer a question she asks.
She has an array $a$ of length $n$, where all elements are initially $0$. There are also two arrays $t, b$ of length $n$.
She can perform two kinds of operations:
1. Add $t$ to the reversed $t$ element by element, obtaining a new $t$.
- For example, $t=[1,4,2]$ becomes $t'=[1+2,4+4,2+1]=[3,8,3]$.
2. Add $a$ to $t$ element by element, obtaining a new $a$.
- For example, $a=[1,2,3],t=[1,4,2]$ becomes $a'=[1+1,2+4,3+2]=[2,6,5]$.
Is it possible to turn $a$ into $b$ by performing the operations above some number of times?
You want to pat her head $T$ times, so there are $T$ test cases.
Input Format
The first line contains an integer $T$, meaning the number of test cases.
For each test case:
- The first line contains an integer $n$, meaning the array length.
- The second line contains $n$ integers, where the $i$-th integer is $t_i$.
- The third line contains $n$ integers, where the $i$-th integer is $b_i$.
Output Format
Output $T$ lines. Each line contains a string `Yes` or `No`, indicating whether it is possible to turn $a$ into $b$ for that test case.
The string is case-insensitive. If the answer is `Yes`, then `yes`, `YES`, `yEs`, etc. will all be accepted.
Explanation/Hint
**Sample Explanation**
For the first test case:
- Initially: $a=[0,0,0]$, $t=[1,2,2]$, $b=[5,8,7]$.
- Perform operation 2: $a=[1,2,2]$, $t=[1,2,2]$, $b=[5,8,7]$.
- Perform operation 2: $a=[2,4,4]$, $t=[1,2,2]$, $b=[5,8,7]$.
- Perform operation 1: $a=[2,4,4]$, $t=[3,4,3]$, $b=[5,8,7]$.
- Perform operation 2: $a=[5,8,7]$, $t=[3,4,3]$, $b=[5,8,7]$.
Now $a=b$, which satisfies the requirement.
For the second test case, it can be proven that no valid solution exists.
---
**Constraints**
There are $20$ test points in total, with $5$ points for each test point.
Let $\sum n$ denote the sum of $n$ over all test cases.
For all testdata, it is guaranteed that $1\le \sum n\le 2\times 10^3$, $n\ge 1$, $1\le t_i,b_i\le 2\times 10^3$.
- For test points $1\sim 4$: it is guaranteed that $n\le 2$.
- For test points $5\sim 8$: it is guaranteed that all $t_i$ are equal.
- For test points $9\sim 12$: it is guaranteed that $b_i=b_{n-i+1}$.
- For test points $13\sim 16$: it is guaranteed that $\sum n,t_i,b_i\le 200$.
- For test points $17\sim 20$: no special constraints.
---
**Hack Data**
Hack data was added after the contest, numbered starting from $21$.
The original test points are still worth $5$ points each, and the Hack data is worth $0$ points. However, you will be judged as Accepted only if you pass all data.
To distinguish the original test points from the Hack data, subtasks were added to this problem, but the scoring method of the subtasks is “sum”, which will not affect normal judging.
Translated by ChatGPT 5