There are provided $ N = \ sum_ {i = 1} ^ {9} A_i $ digits. $ N $ first digital arbitrarily divided into two groups $ A $ and $ B $, $ A $ has $ N_A = \ floor {N / 2} $ numbers, $ B $ has $ N_B = \ ceil {N / 2} $ digits. $ A $ in the figures and referred to as $ S_A $, $ B $ in the figures and referred to as $ S_B $. If $ (S_A - S_B) \ bmod 11 \ ne 0 $, and then make adjustments.
Consider S_A changed by exchanging $ $ A $, $ B $ in the figure - the value of $ S_B. Solutions must pass if several such switching operations $ S_A - S_B \ bmod 11 = 0 $. With $ (a, b) $ represents a number to $ A $ in digital $ A $ and $ B $ of $ b $ exchange, the exchange $ A, then b $ $ S_A - change amount S_B $ is $ - 2 (a - b) $.
If $ i noticed two figures exist, j $ have suffered at least $ 10 $ times, then the answer must be YES. Because when taken over $ k $ $ $ 1 to $ 10 $, $ 2k (i - j) $ also runs over $ 1 to $ $ $ 10 ($ 11 in the sense die in $).
If each number appeared less than $ 10 $ times, it can be resolved with a DP. Order $ f [i] [j] [k] $ denotes removed $ 1, 2, \ dots, i $ these figures were $ J $ a and withdrawn figures and die from $ A $ in $ 11 $ equal to $ k $ whether possible. For $ B $ subjected to the same DP.
Consider the case of only one number appeared at least $ 10 $ times. This number is set $ d $. Provided $ D $ appears in the $ A $ $ $ D_A times, appeared in D_B $ $ $ B $ of times.
It can be shown in any sequence of operations $ (a_1, b_1), \ dots, (a_n, b_n) $ into equivalent can be a sequence of operations $ (a'_1, b'_1), \ dots, (a'_k, b ' _K) satisfying for any $ $ 1 \ le i, j \ le k $, $ a'_i \ ne b'_j $.
Since the sequence of operations $ D $ appears only a_i $ $ $ or only appear in certain B_i $ present, we only need to consider the length of not more than $ t = \ max \ {N_A - d_A, N_B - d_B \} $ of sequence of operations. So we can $ A $, $ B $ each digital $ 1 to $ 9 $ $ $ t $ withdrawn at most two, of these two figures smaller number DP.
int main() {
int T;
scan(T);
rep (T) {
kase();
vl a(10);
up (i, 1, 9) scan(a[i]);
int n10 = 0; //出现次数大于等于10的数字的个数
up (i, 1, 9) {
n10 += a[i] >= 10;
}
if (n10 >= 2) {
println("YES");
continue;
}
ll n = accumulate(all(a), 0LL);
ll m = n / 2;
vl b(10);
// 先随机分配,再通过DP判断能否进行调整。
up (i, 1, 9) {
if (a[i] < m) {
swap(a[i], b[i]);
m -= b[i];
} else {
b[i] = m;
a[i] -= m;
break;
}
}
ll sa = 0, sb = 0;
up (i, 1, 9) {
sa += a[i] * i;
sb += b[i] * i;
}
ll r = (sa - sb) % 11;
if (r == 0) {
println("YES");
continue;
}
if (r < 0) {
r += 11;
}
// r = r / 2;
// (11 + 1) / 2 是 2 在模 11 下的拟元。
r = r * (11 + 1) / 2 % 11;
// dp[i][j][k] 在前i种数里选择j个数余数是否可能是k
// 用滚动数组去掉dp数组第一维。
auto nb = n / 2, na = n - nb;
up (i, 1, 9) {
if (a[i] >= 11) {
na -= a[i];
}
if (b[i] >= 11) {
nb -= b[i];
}
}
auto t = max(na, nb);
up (i, 1, 9) {
a[i] = min(a[i], t);
b[i] = min(b[i], t);
}
na = accumulate(all(a), 0LL);
nb = accumulate(all(b), 0LL);
vv<int> A(na + 1, vi(11));
vv<int> B(nb + 1, vi(11));
A[0][0] = 1;
B[0][0] = 1;
int ca = 0, cb = 0;
up (i, 1, 9) {
if (a[i] > 0) {
down (j, ca, 0) {
rng (k, 0, 11) {
if (A[j][k]) {
up (l, 1, a[i]) {
A[j + l][(k + l * i) % 11] = true;
}
}
}
}
ca += (int)a[i];
}
if (b[i] > 0) {
down (j, cb, 0) {
rng (k, 0, 11) {
if (B[j][k]) {
up (l, 1, b[i]) {
B[j + l][(k + l * i) % 11] = true;
}
}
}
}
cb += (int)b[i];
}
}
bool flag = false;
up (i, 1, min(na, nb)) {
rng (j, 0, 11) {
if (B[i][j] && A[i][(j + r) % 11]) {
flag = true;
break;
}
}
if (flag) break;
}
println(flag ? "YES" : "NO");
}
return 0;
}