Rock-paper-scissors P32669


Statement
 

pdf   zip

You probably know about the rock-paper-scissors game, where two players choose among rock, paper and scissors, and rock beats scissors, paper beats rock, and scissors beats paper. If both oponents choose the same, the game is tied. You are going to play several rounds, and you will earn two points for every round that you win, and one point for every tie.

Your oponent has decided to write all his decisions on paper before the start of the game, and he will follow those decisions no matter what. However, you cheated and could read all his decisions. To compensate for such a huge advantatge, you decide to play between r1r_1 and r2r_2 rocks, between p1p_1 and p2p_2 papers, and between s1s_1 and s2s_2 scissors. Under those restrictions, can you maximize the points that you will earn?

Input

Let rr, pp and ss be respectively the number of rocks, papers and scissors of your oponent. Input consists of several cases, each with rr, pp and ss, followed by r1r_1, r2r_2, p1p_1, p2p_2, s1s_1 and s2s_2. You can assume r1r2r_1 \le r_2, p1p2p_1 \le p_2, s1s2s_1 \le s_2, and r1+p1+s1r+p+sr2+p2+s2108r_1 + p_1 + s_1 \le r + p + s \le r_2 + p_2 + s_2 \le 10^8.

Output

For every case, print the maximum number of points that you can earn.

Public test cases
  • Input

    3 0 0  1 1 1 1 1 1
    3 0 0  0 1 0 1 3 3
    3 0 0  0 2 0 2 0 2
    5 7 8  3 5 0 9 2 6
    

    Output

    3
    0
    5
    33
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Other languages
    Spanish
    Official solutions
    C++
    User solutions
    C++