Rock-paper-scissors P32669


Statement
 

pdf   zip

html

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 r1 and r2 rocks, between p1 and p2 papers, and between s1 and s2 scissors. Under those restrictions, can you maximize the points that you will earn?

Input

Let r, p and s be respectively the number of rocks, papers and scissors of your oponent. Input consists of several cases, each with r, p and s, followed by r1, r2, p1, p2, s1 and s2. You can assume r1r2, p1p2, s1s2, and r1 + p1 + s1r + p + sr2 + p2 + s2 ≤ 108.

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++