AIOC Banner

Problem: RPS

Want to try solving this problem? You can submit your code online if you log in or register.


RPS

Input File: rpsin.txt
Output File: rpsout.txt
Time Limit: 1 second
Memory Limit: 1 GB

‰C Rock. Paper. Scissors. The rules are simple. The game is contested by two people over N rounds. During each round, you and your opponent simultaneously throw either Rock, Paper or Scissors. Rock beats Scissors, Scissors beats Paper, and Paper beats Rock. If your throw beats your opponent’s, you gain one point. Conversely, if their throw beats yours, you lose one point.

Your opponent is very predictable. You know that they will throw Rock in the first Ra rounds, throw Paper in the next Pa rounds, then finally throw Scissors in the last Sa rounds, where Ra + Pa + Sa = N.

You will throw Rock in Rb rounds, Paper in Pb rounds, and Scissors in Sb rounds, where Rb + Pb + Sb = N. However, as you are an experienced player, you may throw these in any order you like.

At the beginning of the game, you start with 0 points. What is the maximum number of points you can finish with?

Input

Output

Your program should output a single integer: the maximum number of points you could score after all N rounds have been played. Note that this number may be positive, negative, or zero.

Sample Input 1

5
2 2 1
1 3 1

Sample Output 1

4

Sample Input 2

4
1 2 1
4 0 0

Sample Output 2

-1

Sample Input 3

1
0 0 1
0 0 1

Sample Output 3

0

Explanation

In the first sample input, there are N = 5 rounds, where your opponent will throw Rock twice, then Paper twice, then Scissors once. You must throw Rock once, Paper three times and Scissors once. Here is one way you can order your throws:

Round Your Throw Their Throw Your Result Points
1 Paper Rock Win! +1
2 Paper Rock Win! +1
3 Scissors Paper Win! +1
4 Paper Paper Draw 0
5 Rock Scissors Win! +1

This results in a total of 4 points, which is the maximum possible.

In the second sample input, there are N = 4 rounds, where your opponent will throw Rock once, then Paper twice, then Scissors once. You must throw Rock four times, and cannot throw Paper or Scissors. There is only one way you can order your throws:

Round Your Throw Their Throw Your Result Points
1 Rock Rock Draw 0
2 Rock Paper Lose... -1
4 Rock Paper Lose... -1
4 Rock Scissors Win! +1

This results in a total of -1 points, which is the maximum possible. Note that the answer can be negative!

In the third sample input, there is N = 1 round. Your opponent will throw Scissors in this one round, and you will also throw Scissors. This results in a draw, so you will score 0 points.

Subtasks & Constraints

For all test cases:

Furthermore:

 


Privacy statement
© Australian Mathematics Trust 2001-2021

Contact: training@orac.amt.edu.au
Page generated: 21 September 2021,  9:41am AEST