#P8285. Merge the Magical Powers

    ID: 21464 Type: Default 1000ms 256MiB

Merge the Magical Powers

Merge the Magical Powers

Qiao Mu has come face‐to‐face with the Demon King and has decided to use his magic to defeat him. In his arsenal there are n magic arrays, where the i-th array has a magic power value \(a_i\).

You are allowed to perform the following operation any number of times:

Choose three distinct indices \(i, j, k\) such that \(a_i > 0\) and \(a_j > 0\). Then, decrease \(a_i\) and \(a_j\) by 1, and increase \(a_k\) by 2. In other words, one operation transforms the triple \((a_i, a_j, a_k)\) as follows:

[ (a_i, a_j, a_k) \to (a_i-1,; a_j-1,; a_k+2). ]

Qiao Mu’s objective is to concentrate all the magic power into a single magic array so that exactly \(n-1\) arrays become 0 and the remaining one holds the total sum of magic power. Determine whether it is possible after a sequence of operations to achieve this configuration.

Note: When \(n = 2\), no operation can be performed (since three distinct indices are required), so the configuration must already be in the desired form for the answer to be "YES".

inputFormat

The first line contains an integer \(n\) (the number of magic arrays).

The second line contains \(n\) space-separated integers \(a_1, a_2, \dots, a_n\), where \(a_i\) represents the magic power at the i-th array.

outputFormat

Output a single line containing YES if it is possible to concentrate all magic power into a single array, or NO otherwise.

sample

1
5
YES

</p>