#P9509. Partitioned Average Sequence
Partitioned Average Sequence
Partitioned Average Sequence
A sequence \(\{a_n\}\) is called partition-average if and only if there exists a partition of the index set \(\{1,2,\dots,n\}\) into \(k>1\) nonempty subsets \(S_1,S_2,\dots,S_k\) such that for every \(1\le i\le k\) the average of the elements of \(\{a_n\}\) with indices in \(S_i\) is the same integer. In other words, there exists an integer \(X\) and a partition \(S_1,\dots,S_k\) with \(k>1\) such that for every \(i\):
\[
\frac{1}{|S_i|}\sum_{j\in S_i}a_j = X
\]
Given a sequence \(\{a_n\}\), determine whether it is partition-average.
Note: If you are unclear about some definitions, please refer to the "Hint" section at the end of the statement.
inputFormat
The first line contains a single integer \(n\) (the length of the sequence).
The second line contains \(n\) space-separated integers \(a_1,a_2,\dots,a_n\).
outputFormat
Output a single line containing YES
if the sequence is partition‐average, and NO
otherwise.
sample
3
1 2 3
YES