#P8285. 「DAOI R1」Magic

「DAOI R1」Magic

Background

-1,-1,+2 \text{-1,-1,+2}

Problem Description

Qiaomu came to face the Demon King, and he decided to use magic to defeat the Demon King.

Given an integer nn, meaning there are nn magic circles. On each magic circle there is a certain amount of magic power aia_i.

Each time, you may choose three magic circles i,j,k  (i,j,ki, j, k \;(i, j, k are pairwise distinct and ai>0a_i > 0, aj>0)a_j > 0), then Qiaomu will decrease the magic power ai,aja_i, a_j on the ii-th and jj-th magic circles by 11 respectively, and increase the magic power aka_k on the kk-th magic circle by 22. We call this one operation.

Qiaomu wants to gather all magic power together to achieve the greatest power. He wants to know whether, after some number of operations, it is possible to make the magic power on n1n - 1 magic circles equal to 00, and make the gathered magic circle's magic power equal to the sum of the magic power of all original magic circles.

Input Format

This problem contains multiple test cases.

One line contains an integer TT, the number of test cases.

Then for each test case, first input a positive integer nn, and then input nn integers in order. The ii-th integer represents aia_i.

Output Format

For each test case output one line. If it can be achieved, output YES, otherwise output NO.

2
4
2 0 2 2
3
5 0 7
YES
NO

Hint

Sample Explanation

  • For the first test case, you can perform the operation twice using a1a_1 and a3a_3 on a4a_4.
  • For the second test case, it can be proven impossible.

Constraints

  • For 5%5\% of the testdata: 1n21 \le n \le 2, 0ai1030 \le a_i \le 10^3.
  • For 20%20\% of the testdata: 1n101 \le n \le 10, 0ai1030 \le a_i \le 10^3.
  • For 100%100\% of the testdata: 1n2×1061 \le \sum{n} \le 2 \times 10^{6}, 0ai1090 \le a_i \le 10^{9}.

For all testdata, it is guaranteed that 1T1001 \le T \le 100 and i=1nai1\sum\limits_{i=1}^{n} a_i \ge 1.

Translated by ChatGPT 5