#P9714. Little R's Sequence Puzzle

    ID: 22861 Type: Default 1000ms 256MiB

Little R's Sequence Puzzle

Little R's Sequence Puzzle

Little R is a cute girl who loves having her head patted. However, before you can pat her head, you must answer the following puzzle correctly.

You are given three sequences of length \( n \): an array \( a \), which is initially all zeros, and two other arrays \( t \) and \( b \). You are allowed to perform the following two operations any number of times (in any order):

  1. Operation 1: Replace \( t \) with a new array where each element is the sum of the corresponding element and its mirror. In other words, for each \( i = 1,2,\dots,n \), the new \( t_i \) is given by \[ t_i \leftarrow t_i + t_{n-i+1}, \] where the indices are 1-indexed. For example, if \( t = [1, 4, 2] \), then after this operation \( t \) becomes \( [1+2, 4+4, 2+1] = [3, 8, 3] \).
  2. Operation 2: Replace \( a \) with \( a + t \) by adding corresponding elements. For example, if \( a = [1,2,3] \) and \( t = [1,4,2] \), then after this operation \( a \) becomes \( [1+1, 2+4, 3+2] = [2,6,5] \).

The question is: is it possible, by applying a sequence of these operations, to transform \( a \) into \( b \)?

Note: Once the first operation is applied, the array \( t \) becomes symmetric. Subsequent applications of Operation 1 will simply double \( t \) (i.e. if \( t \) is symmetric then \( t_i + t_{n-i+1} = 2t_i \)). Therefore, any additions made via Operation 2 after using Operation 1 will add multiples of the symmetric vector.

You have \( T \) independent test cases to answer (i.e. you wish to pat her head \( T \) times!).

inputFormat

The first line contains an integer \( T \), the number of test cases. Each test case is described as follows:

  • The first line contains an integer \( n \), the length of the sequences.
  • The second line contains \( n \) integers, representing the array \( t \).
  • The third line contains \( n \) integers, representing the target array \( b \).

outputFormat

For each test case, output a single line with either Yes if it is possible to transform \( a \) into \( b \) using the allowed operations, or No otherwise.

sample

1
3
1 4 2
3 8 3
Yes