Rock-paper-scissors (2) P84492


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 a sequence of rocks, followed by a sequence of papers, followed by a sequence of scissors. Moreover, you will play at least r rocks, at least p papers and at least s scissors. Under those restrictions, can you maximize the points that you will earn?

Input

Input consists of several cases, each with a string t with your oponent’s moves from left to right (‘R’, ‘P’ or ‘S’), followed by r, p and s. You can assume | t | ≤ 1000, r ≥ 1, p ≥ 1, s ≥ 1, and r + p + s ≤ | t |.

Output

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

Public test cases
  • Input

    PSR 1 1 1
    RPS 1 1 1
    SSSSS 1 1 1
    RPSSRP 2 1 1
    

    Output

    0
    3
    7
    9
    
  • Information
    Author
    Salvador Roura
    Language
    English
    Official solutions
    C++
    User solutions
    C++
    Event
    Quinzè Concurs de Programació de la UPC - Semifinal
    Date
    2017-06-29