logo AlgoBeat OnlineJudge
登录 注册

#217128. [ICPC 2017 Nanning R] Rearrangement

内存限制:512 MiB 时间限制:1000 ms 标准输入输出
题目类型:VJudge(洛谷) 评测方式:VJudge
上传者: 匿名

题目描述

In a two dimensional array of integers of size , is it possible to rearrange integers so that the sum of two adjacent elements (which are adjacent in a common row or a common column) is never divisible by three?

输入格式

The input has several test cases and the first line contains an integer which is the number of test cases.

In each case, the first line contains an integer indicating the number of columns in the array. The second line contains the elements of the array in the first row separated by single spaces. The third line contains the elements of the array in the second row separated by single spaces. The elements will be positive integers less than .

输出格式

For each test case, output “YES” in a single line if any valid rearrangement exists, or “NO” if not.

样例

样例输入 1

6
3
3 6 9
1 4 7
3
3 6 9
1 3 8
5
1 2 3 4 5
6 7 8 9 10
10
1 1 1 1 1 1 1 1 1 1
2 3 2 3 2 3 2 3 2 3  
2
3 1
2 3
2
3 1
1 2

样例输出 1

YES
NO
YES
YES
YES
NO