Balls of Three Colors

AtCoder
IDarc128_b
Time2000ms
Memory256MB
Difficulty
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$ [samples]
Samples
Input #1
3
1 2 2
1 2 3
1 2 4
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.
API Response (JSON)
{
  "problem": {
    "name": "Balls of Three Colors",
    "description": {
      "content": "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 remain",
      "description_type": "Markdown"
    },
    "platform": "AtCoder",
    "limit": {
      "time_limit": 2000,
      "memory_limit": 262144
    },
    "difficulty": "None",
    "is_remote": true,
    "is_sync": true,
    "sync_url": null,
    "sign": "arc128_b"
  },
  "statements": [
    {
      "statement_type": "Markdown",
      "content": "We have $R$ red balls, $G$ green balls, and $B$ blue balls. You can do the following operation any number of times:\n\n*   choose two balls of different colors and turn them into two balls of the remain...",
      "is_translate": false,
      "language": "English"
    }
  ]
}
Full JSON Raw Segments