欢迎来到尧图网

客户服务 关于我们

您的位置:首页 > 新闻 > 会展 > A. Doremy‘s Paint 3

A. Doremy‘s Paint 3

2025/1/13 14:13:08 来源:https://blog.csdn.net/jj12345jj198999/article/details/145099418  浏览:    关键词:A. Doremy‘s Paint 3

time limit per test

1 second

memory limit per test

256 megabytes

An array b1,b2,…,bnb1,b2,…,bn of positive integers is good if all the sums of two adjacent elements are equal to the same value. More formally, the array is good if there exists a kk such that b1+b2=b2+b3=…=bn−1+bn=kb1+b2=b2+b3=…=bn−1+bn=k.

Doremy has an array aa of length nn. Now Doremy can permute its elements (change their order) however she wants. Determine if she can make the array good.

Input

The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1001≤t≤100) — the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (2≤n≤1002≤n≤100) — the length of the array aa.

The second line of each test case contains nn integers a1,a2,…,ana1,a2,…,an (1≤ai≤1051≤ai≤105).

There are no constraints on the sum of nn over all test cases.

Output

For each test case, print "Yes" (without quotes), if it is possible to make the array good, and "No" (without quotes) otherwise.

You can output the answer in any case (upper or lower). For example, the strings "yEs", "yes", "Yes", and "YES" will be recognized as positive responses.

Example

Input

Copy

 

5

2

8 9

3

1 1 2

4

1 1 4 5

5

2 3 3 3 3

4

100000 100000 100000 100000

Output

Copy

Yes
Yes
No
No
Yes

Note

In the first test case, [8,9][8,9] and [9,8][9,8] are good.

In the second test case, [1,2,1][1,2,1] is good because a1+a2=a2+a3=3a1+a2=a2+a3=3.

In the third test case, it can be shown that no permutation is good.

解题说明:此题是一道数学题,找规律能发现要么所有数的值相等,要么存在两种数,个数相差1。可以采用map来统计个数进行判断。

#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
using namespace std;int t, n, a[102];
map<int, int>mp;
int main() 
{scanf("%d", &t);while (t--){scanf("%d", &n);mp.clear();for (int i = 1; i <= n; i++) {scanf("%d", &a[i]);mp[a[i]]++;}if (mp.size() <= 1){printf("YES\n");}else if (mp.size() == 2) {int a = 0, b = 0;for (auto it : mp) {if (!a){a = it.second;}else{b = it.second;}}if (abs(a - b) <= 1){printf("YES\n");}else{printf("NO\n");}}else{printf("NO\n");}}return 0;
}

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com