201281: [AtCoder]ARC128 B - Balls of Three Colors

Memory Limit:1024 MB Time Limit:2 S
Judge Style:Text Compare Creator:
Submit:0 Solved:0

Description

Score : $400$ points

Problem Statement

We have $R$ red balls, $G$ green balls, and $B$ blue balls. You can do the following operation any number of times:

  • choose two balls of different colors and turn them into two balls of the remaining color.

For example, you can choose a red ball and a blue ball and turn them into two green balls.

Your objective is to make all balls have the same color. Determine whether this objective is achievable. If it is, find the minimum number of operations required to achieve it.

For each input file, solve $T$ test cases.

Constraints

  • $1 \leq T \leq 100$
  • $1 \leq R,G,B \leq 10^8$
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

$T$
$case_1$
$case_2$
$\vdots$
$case_T$

Each case is in the following format:

$R$ $G$ $B$

Output

For each case, print -1 if the objective is unachievable; otherwise, print the minimum number of operations to achieve it.


Sample Input 1

3
1 2 2
1 2 3
1 2 4

Sample Output 1

2
-1
4

For example, in $case_3$, one optimal sequence of operations is:

  • choose a green ball and blue ball, turning them into two red balls;
  • choose a red ball and blue ball, turning them into two green balls;
  • choose a red ball and blue ball, turning them into two green balls;
  • choose a red ball and blue ball, turning them into two green balls.

Input

题意翻译

$T$ 组数,每一组选取两个数减一,另一个数加二,问最后让其中两个数为 $0$ 的次数。不能输出 $-1$ 。

加入题单

上一题 下一题 算法标签: