using System;
using System.Collections.Generic;
public class Program {
public static void Main() {
//能量是奇数格子与偶数格子之间互相传播的,且守恒。设总能量为E, 有n个格子,奇数格的能量加起来有E_j,偶数格的能量加起来有E_o,只需要分别计算奇数格和偶数格的平均能量,如果都为E/n(上述计算平均数时能整除是最基本要求)即满足题目要求。
int.TryParse(Console.ReadLine(), out int n);
for (int i = 0; i < n; i++) {
int.TryParse(Console.ReadLine(), out int num);
string[] inputs = Console.ReadLine().Split(' ');
List<int> lst = new List<int>();
int total = 0;
for (int j = 0; j < num; j++) {
lst.Add(int.Parse(inputs[j]));
total += lst[j];
}
//如果所有所有方碑的能量总数加起来不能被方碑的数量整除,则无法达到能量均衡,输出NO
if (total % num != 0) {
Console.WriteLine("NO");
}
//接下里计算奇数位格子方碑的能量的平均值和偶数位格子方碑的能量的平均值
else {
int evenTotal = 0;
int oddTotal = 0;
int oddCount = 0;
int evenCount = 0;
for (int j = 0; j < num; j++) {
if (j % 2 == 0) {
evenTotal += lst[j];
evenCount++;
} else {
oddTotal += lst[j];
oddCount++;
}
}
int avg = total /
num; // 因为前面判断了 total % num == 0,所以这是整数
// 验证:偶数位总和是否等于 avg * evenCount?
// 验证:奇数位总和是否等于 avg * oddCount?
if (evenTotal == avg * evenCount && oddTotal == avg * oddCount) {
Console.WriteLine("YES");
} else {
Console.WriteLine("NO");
}
}
}
}
}