COCI '08 Regional #2 Majstor

View as PDF

Submit solution

Points: 5
Time limit: 1.0s
Memory limit: 32M

Problem types
Allowed languages
Ada, Assembly, Awk, Brain****, C, C#, C++, COBOL, CommonLisp, D, Dart, F#, Forth, Fortran, Go, Groovy, Haskell, Intercal, Java, JS, Kotlin, Lisp, Lua, Nim, ObjC, OCaml, Octave, Pascal, Perl, PHP, Pike, Prolog, Python, Racket, Ruby, Rust, Scala, Scheme, Sed, Swift, TCL, Text, Turing, VB, Zig

Rock-paper-scissors is a popular two-player game. In the game, each of the players uses their hand to show one of three symbols: rock, paper or scissors. If both players show the same symbol, the game is a tie. Otherwise, scissors beat paper, paper beats rock and rock beats scissors.

Sven has been studying the psychological intricacies of the game for years and has become a real master at the game, his friends not standing a chance against him in one-on-one games.

With the world championships around the corner, Sven is practicing his skills playing simultaneous games with N of his friends. One such game consists of R rounds. In each round, Sven and each of his friends show one of the three symbols.

When calculating the score, in each round, Sven's symbol is independently compared to each of his friends' symbols. Sven scores two points for every win and one point for every tie. Sven does not get points for losing.

Write a program that calculates Sven's total score, and also his largest possible score had he known in advance all the symbols his friends would show.

Input Specification

The first line contains the integer R (1 \le R \le 50), the number of rounds played. The second line contains a string of R letters S, P or R. The string represents symbols that Sven showed in each round. S is for scissors, P for paper, R for rock. The third line contains the integer N (1 \le N \le 50), the number of friends. Each of the following N lines contains a string of R letters S, P or R. These are the symbols shown by each of the N friends in each of the R rounds.

Output Specification

Output Sven's actual score on the first line.

Output his largest possible score on the second line, assuming his friends didn't change their symbols.

Sample Input 1

5
SSPPR
1
SSPPR

Sample Output 1

5
10

Sample Input 2

5
SSPPR
2
PPRRS
RRSSP

Sample Output 2

10
15

Sample Input 3

4
SPRS
4
RPRP
SRRR
SSPR
PSPS

Sample Output 3

12
21

Comments

There are no comments at the moment.