#K8796. Box Triplet Sum Divisibility

    ID: 37202 Type: Default 1000ms 256MiB

Box Triplet Sum Divisibility

Box Triplet Sum Divisibility

You are given several test cases. For each test case, you will be given an integer \( K \) and a sequence of \( N \) integers representing the labels on boxes. Your task is to determine whether the boxes, in their given order, satisfy the condition that the sum of any three consecutive boxes is divisible by \( K \). If the sequence has less than three boxes, it is considered to automatically satisfy the condition.

More formally, given a sequence \( a_1, a_2, \dots, a_N \), you need to check if for every \( i \) such that \( 3 \leq i \leq N \),

[ a_{i-2} + a_{i-1} + a_i \equiv 0 \pmod{K} ]

holds. Print YES if the condition holds, and NO otherwise.

Input/Output: The input is read from stdin and the output is written to stdout.

inputFormat

The first line of input contains an integer \( T \) (\( 1 \le T \le 100 \)) denoting the number of test cases.

For each test case:

  • The first line contains two space-separated integers: \( K \) (the divisor) and \( N \) (the number of boxes).
  • The second line contains \( N \) space-separated integers \( a_1, a_2, \dots, a_N \) representing the labels on the boxes.

outputFormat

For each test case, print a single line containing either YES if for every three consecutive boxes the sum is divisible by \( K \), or NO otherwise.

## sample
2
3 4
3 6 9 12
5 5
1 5 -2 4 -1
YES

NO

</p>