#P2809. hzwer 爱折纸
hzwer 爱折纸
Description
hzwer bought a magical little paper strip. Initially, it consists of cells, and each cell has an integer on it. Obviously, there is a dividing line between every two adjacent cells. hzwer can choose any dividing line and fold the entire strip to the left. If two cells overlap after folding, the number on the resulting cell equals the sum of the two original cells; otherwise, the numbers remain unchanged. hzwer can also reverse the entire strip; after reversing, the number of the -th cell becomes the number of the -th cell.
hzwer wants to obtain an ideal strip with cells and values . Determine whether it is possible to transform the initial strip into the ideal strip by performing the above operations any number of times.


Input Format
Multiple test cases, at most groups. Each test case consists of four lines:
- The first line contains an integer , the number of cells in the initial strip.
- The second line contains integers, the initial values of each cell.
- The third line contains an integer (), the number of cells in the ideal strip.
- The fourth line contains integers, the values on the ideal strip.
Output Format
For each test case, output one letter: S means feasible, and N means infeasible.
7
5 6 23 8 19 7 10
4
5 16 30 27
7
1 2 3 4 5 6 7
5
7 6 5 5 5
4
1 2 3 4
1
10
6
19 23 3 51 2 0
2
34 64
S
S
S
N
Hint
For of the testdata, . For of the testdata, .
Translated by ChatGPT 5
京公网安备 11011102002149号