Rock-paper-scissors (2)

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.

Problem information

Author: Salvador Roura

Generation: 2026-01-25T12:02:33.712Z

© Jutge.org, 2006–2026.
https://jutge.org
