#P7184. [CRCI2008-2009] MAJSTOR

[CRCI2008-2009] MAJSTOR

Description

In the game, both players show one of three hand gestures: rock, paper, or scissors.

If both players show the same gesture, the game is a draw. Otherwise, scissors beats paper, paper beats rock, and rock beats scissors.

Sven has been studying the complex psychology of the game for many years and has become a true master. His friends have no chance against him in one-on-one games.

As the world championship approaches, Sven is playing the game simultaneously with nn friends to practice his skills.

There are rr rounds. In each round, Sven and each of his friends show one of the three gestures.

Scoring rules:

  • If Sven wins, he gets 22 points.
  • If it is a draw, he gets 11 point.
  • If the opponent wins, he gets 00 points.

Write a program to compute Sven's total score for his actual plays, and also the maximum possible total score if he knows all the gestures his friends will play in advance.

Input Format

The first line contains a positive integer rr, the number of rounds.

The second line contains rr characters. The ii-th character indicates Sven's gesture in round ii, and it is one of S (scissors), P (paper), R (rock).

The third line contains a positive integer nn, the number of his friends.

The next nn lines each contain rr characters. The jj-th character indicates the gesture played by Sven's ii-th friend in round jj, and it is one of S (scissors), P (paper), R (rock).

Output Format

On the first line, output Sven's actual score.

Assuming his friends do not change their gestures, on the second line output his maximum possible score.

5
SSPPR
1
SSPPR 

5
10
5
SSPPR
2
PPRRS
RRSSP 

10
15
4
SPRS
4
RPRP
SRRR
SSPR
PSPS 

12
21

Hint

Constraints

For 100%100\% of the testdata, 1n,r501 \le n, r \le 50.

Notes

  • This problem is worth 5050 points in total.
  • This problem is translated from COCI2008-2009 CRCI2008-2009 MAJSTOR. Translator:
    https://www.luogu.com.cn/user/219791

Translated by ChatGPT 5