Codeforces Round 945 (Div. 2)
A
Chess For Three
Codeforces
900
原题
←B →
翻译中…

Three friends gathered to play a few games of chess together.

翻译中…

In every game, two of them play against each other. The winner gets $2$ points while the loser gets $0$, and in case of a draw, both players get $1$ point each. Note that the same pair of players could have played any non-negative number of times (possibly zero). It is also possible that no games were played at all.

翻译中…

You've been told that their scores after all the games were played were $p_1$, $p_2$ and $p_3$. Additionally, it is guaranteed that $p_1 \leq p_2 \leq p_3$ holds.

翻译中…

Find the maximum number of draws that could have happened and print it. If there isn't any way to obtain $p_1$, $p_2$ and $p_3$ as a result of a non-negative number of games between the three players, print $-1$ instead.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 500$). The description of the test cases follows.

翻译中…

The first line of each test case contains three integers $p_1$, $p_2$ and $p_3$ ($0 \leq p_1 \leq p_2 \leq p_3 \leq 30$) — the scores of the three players, sorted non-decreasingly.

翻译中…

Output

翻译中…

For each testcase, print one number — the maximum possible number of draws that could've happened, or $-1$ if the scores aren't consistent with any valid set of games and results.

翻译中…

Note

翻译中…

In the first example, no games were played at all, so no draws could occur either.

翻译中…

For the second example, exactly one game occurred between the second and the third player and it ended in draw, so the answer is $1$.

翻译中…

It's easy to see that there's no set of games achieving the scores in third example, so the answer for it is $-1$.

翻译中…

样例

Input #1
7
0 0 0
0 1 1
1 1 1
1 1 2
3 3 3
3 4 5
1 1 10
Output #1
0
1
-1
2
-1
6
2
InputCopy OutputCopy
题目信息
题号
1973A
时间限制
1 s
内存限制
256 MB
标签
暴力
动态规划
模拟
数学

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