AtCoder Regular Contest 211 (Div. 2)
A
Banned X 2
AtCoder
⌀ 550
原题
←B →
翻译中…

Problem Statement

翻译中…

You are given a length-$9$ sequence of non-negative integers $A=(A_1,A_2,\dots,A_9)$. It is guaranteed that $2\leq \sum_{i=1}^{9}A_i$.

翻译中…

You can perform the following operation any number of times (possibly zero): choose one element of $A$ and add $1$ to it.

翻译中…

What is the minimum number of operations required so that there exists a sequence of positive integers $S$ satisfying all of the following conditions?

翻译中…
  • All elements of $S$ are between $1$ and $9$, inclusive.
  • $S$ contains exactly $A_i$ occurrences of $i$ for each integer $i$ such that $1\leq i\leq 9$. (Thus, the length of $S$ is $\sum_{i=1}^{9}A_i$.)
  • No two adjacent elements sum to $10$.
翻译中…

It can be proved that the goal can be achieved in a finite number of operations.

翻译中…

You are given $T$ test cases; solve each of them.

翻译中…

Constraints

翻译中…
  • $1\leq T\leq 10^3$
  • $0\leq A_i\leq 10^9$ $(1\leq i\leq 9)$
  • $2\leq \sum_{i=1}^{9}A_i$
  • All input values are integers.
翻译中…

Input

翻译中…

The input is given from Standard Input in the following format:

翻译中…

T
\text{case}_1
\text{case}_2
\vdots
\text{case}_T

翻译中…

Each test case is given in the following format:

翻译中…

A_1 A_2 \dots A_9

翻译中…

Output

翻译中…

Output $T$ lines.

翻译中…

The $i$-th line should contain the answer for the $i$-th test case.

翻译中…

样例

Input #1
2
0 0 0 1 0 1 0 0 0
2 1 1 0 0 0 0 0 0
Output #1
1
0
For the first test case, initially, the possible values of $S$ satisfying all conditions except the last one are $(4,6)$ and $(6,4)$, neither of which satisfies the last condition. By choosing $A_8$ and adding $1$ to it, $S=(6,8,4)$ satisfies all conditions. For the second test case, $S=(1,2,3,1)$ satisfies the conditions without any operations.
题目信息
题号
arc211_a
时间限制
2 s
内存限制
1024 MB

题面与样例版权归 AtCoder 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。