/
Time Limit: 2 sec / Memory Limit: 1024 MiB
配点 : 500 点
問題文
a+b+c 人の参加者によるじゃんけん大会が行われました.ここで a, b, c は非負整数で,3\leq a+b+c が成り立ちます.
大会では,まず参加者全員が円周上に並びます.その後,各参加者は「グー」「チョキ」「パー」のいずれか 1 つの手を出します.
各参加者について,自分の出した手が,左隣の参加者が出した手と右隣の参加者が出した手の両方に勝っているとき,その参加者は勝者となります.なお,勝者は 1 人とは限らず,0 人であることも 2 人以上であることもあります.
より形式的には,ある参加者が勝者となるのは次のいずれかが成り立つ場合です.
- 自身が「グー」の手を出して,左隣の参加者と右隣の参加者がどちらも「チョキ」の手を出した場合
- 自身が「チョキ」の手を出して,左隣の参加者と右隣の参加者がどちらも「パー」の手を出した場合
- 自身が「パー」の手を出して,左隣の参加者と右隣の参加者がどちらも「グー」の手を出した場合
この大会について,以下のことが分かっています.
- a 人の参加者が「グー」の手を出した.
- b 人の参加者が「チョキ」の手を出した.
- c 人の参加者が「パー」の手を出した.
この条件のもと,大会の勝者の人数としてありうる最大値を求めてください.
T 個のテストケースが与えられるので,それぞれについて解いてください.
制約
- 1\leq T\leq 5\times 10^5
- 0\leq a, b, c\leq 10^9
- 3\leq a+b+c
- 入力される値はすべて整数.
入力
入力は以下の形式で標準入力から与えられます.
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
各テストケースは以下の形式で与えられます.
a b c
出力
テストケースごとに 1 行出力してください.
各テストケースに対して,大会の勝者の人数としてありうる最大値を出力してください.
入力例 1
6 3 1 2 2 2 2 123 456 789 10 0 0 10 0 100 100 0 10
出力例 1
2 1 578 0 9 10
1 番目のテストケースについて説明します.6 人の出した手が,次の図のように表される場合を考えます.ただし図において,「グー」の手を出した参加者を A,「チョキ」の手を出した参加者を B,「パー」の手を出した参加者を C で表しています.

この図において,「グー」の手を出した参加者は 3 人,「チョキ」の手を出した参加者は 1 人,「パー」の手を出した参加者は 2 人で,入力で与えられる内容と一致しています.この場合大会の勝者は,「パー」の手を出した 2 人です.
Score : 500 points
Problem Statement
A rock-paper-scissors tournament was held with a+b+c participants. Here, a, b, c are non-negative integers with 3\leq a+b+c.
In the tournament, all participants first stand in a circle. Then, each participant plays "Rock," "Scissors," or "Paper."
For each participant, if the hand they played beats both the hand of the participant to their left and the hand of the participant to their right, that participant becomes a winner. There is not necessarily exactly one winner; there may be zero, or two or more winners.
More formally, a participant becomes a winner if one of the following holds:
- The participant played "Rock," and both the left neighbor and the right neighbor played "Scissors."
- The participant played "Scissors," and both the left neighbor and the right neighbor played "Paper."
- The participant played "Paper," and both the left neighbor and the right neighbor played "Rock."
The following is known about this tournament:
- a participants played "Rock."
- b participants played "Scissors."
- c participants played "Paper."
Under this condition, find the maximum possible number of winners in the tournament.
T test cases are given; solve each of them.
Constraints
- 1\leq T\leq 5\times 10^5
- 0\leq a, b, c\leq 10^9
- 3\leq a+b+c
- All input values are integers.
Input
The input is given from Standard Input in the following format:
T
\mathrm{case}_1
\mathrm{case}_2
\vdots
\mathrm{case}_T
Each test case is given in the following format:
a b c
Output
Output one line per test case.
For each test case, output the maximum possible number of winners in the tournament.
Sample Input 1
6 3 1 2 2 2 2 123 456 789 10 0 0 10 0 100 100 0 10
Sample Output 1
2 1 578 0 9 10
Let us explain the first test case. Consider the case where the hands played by the six participants are represented as in the following figure. In the figure, a participant who played "Rock" is denoted by A, a participant who played "Scissors" is denoted by B, and a participant who played "Paper" is denoted by C.

In this figure, there are three participants who played "Rock," one participant who played "Scissors," and two participants who played "Paper," which matches the input. In this case, the winners of the tournament are the two participants who played "Paper."