"Rock-Paper-Scissors"
Limits: 2 sec., 256 MiB
This statement was translated automatically from Ukrainian.
Zenyk and Marichka decided to play the well-known game "rock-paper-scissors" \(n\) times. The game takes place over several rounds. In each round, each of the participants simultaneously chooses one of the three items: rock, scissors, or paper. The result of the round is based on the items chosen by the opponents: rock beats scissors, scissors beat paper, and paper beats rock. Note that in some round, the players may choose the same item. In such a case, the result of the round is a draw.
Marichka knows in how many rounds she will choose rock, scissors, and paper, and she has the same information about Zenyk.
Marichka wants to know the maximum number of rounds she can win. Help her find this out.
Input
The first line contains three integers \(r_M, s_M, p_M\) — the number of rounds in which Marichka will play rock, scissors, and paper, respectively.
The second line contains three integers \(r_Z, s_Z, p_Z\) — the number of rounds in which Zenyk will play rock, scissors, and paper, respectively.
Output
In a single line, print an integer — the maximum number of rounds Marichka can win.
Constraints
\(0 \le r_M, s_M, p_M, r_Z, s_Z, p_Z \le 10^3\),
\(r_M + s_M + p_M = r_Z + s_Z + p_Z = n\),
\(1 \le n \le 10^3\).
Samples
| Input (stdin) | Output (stdout) |
|---|---|
| 1 1 1 1 1 1 | 3 |
Notes
In the example, each of the players will choose each of the items once. Marichka can win all three rounds if against Zenyk’s scissors she chooses rock, against his rock she chooses paper, and against his paper she chooses scissors.
Submit a solution
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|
| Element Type | Created | Who | Problem | Compiler | Result | Time (sec.) | Memory (MiB) | # | Actions |
|---|