#P9088. 「SvR-2」1+2=3
「SvR-2」1+2=3
Problem Description
You have some wooden sticks. Each stick has a number on the left and a number on the right. The numbers can only be . You need to connect all sticks together, and make the number of adjacent pairs whose sum is as large as possible.
For example, there are two sticks and . If you connect them as , then the number of adjacent pairs whose sum is is . But if you connect them as $1\text{ - }\textcolor{red}{\underline{\textbf 2}},\textcolor{red}{\underline{\textbf 1}}\text{ - }0$, then the number of adjacent pairs whose sum is is , because .
Input Format
This problem has multiple test cases.
The first line contains a positive integer , the number of test cases.
For each test case, one line contains non-negative integers, representing the counts of sticks of type $0\text{ - }0,0\text{ - }1,0\text{ - }2,1\text{ - }0,1\text{ - }1,1\text{ - }2,2\text{ - }0,2\text{ - }1,2\text{ - }2$, respectively.
Output Format
Output lines. Each line contains one integer, the answer.
3
4 1 3 4 7 7 9 10 3
6 3 6 4 3 4 5 6 6
6 10 7 1 4 2 6 4 2
31
23
19
Hint
Constraints
For all testdata, . Let be the number of sticks of type . It is guaranteed that .
This problem enables bundled tests and O2 optimization by default.
Let be the sum of all over all test cases in one test point.
| Subtask | Special Property | Score | ||
|---|---|---|---|---|
| None | ||||
| No special limits | No special limits | A | ||
| B | ||||
| C | ||||
| No special limits | None |
Special Property A: are generated uniformly at random in .
Special Property B: All .
Special Property C: All .
Translated by ChatGPT 5