MAJSTOR - Majstor

no tags 

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

The first line contains the integer R (1 ≤ R ≤ 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 ≤ N ≤ 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

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.

Example

Input
5
SSPPR
1
SSPPR

Output
5
10


Input
5
SSPPR
2
PPRRS
RRSSP

Output
10
15


Input
4
SPRS
4
RPRP
SRRR
SSPR
PSPS

Output
12
21

hide comments
Nguyen Cuong: 2016-05-14 14:50:55

my code just takes 2 lines :))

fool_01: 2015-09-22 04:25:15

Beware of just the source limit !

Arnabjyoti Kalita: 2015-04-09 05:38:44

Agree with @Abhinav seems like the solution gives WA for the 4th case, even if all the test cases give right answer... any tricky test cases???

Shubham Jadhav: 2015-03-08 10:14:39

Easy Question... :)

Abhinav: 2014-12-20 21:05:43

getting WA in test case 4, all test case are giving right ans. any tricky case ?

Last edit: 2014-12-21 06:17:26
nadavishe: 2014-07-01 10:45:15

Be aware, there is wrong input in 5th test

Shubham Jain: 2013-10-29 18:19:52

https://www.spoj.com/forum/viewtopic.php?f=3&t=5233&p=42228&sid=f34b264de01cda7cf926a6d4413b50f1#p42228 please help me..getting WA..

: 2013-06-21 23:18:13

Last edit: 2014-02-27 07:46:14
Ouditchya Sinha: 2013-01-22 19:22:41

nice question, AC in 1st attempt. :)

Smit Mehta: 2012-02-18 16:58:51

6525812 : please see. how can it possibly have TLE! hardly some 5000 loops for the worst case


Added by:Race with time
Date:2009-02-17
Time limit:0.229s
Source limit:1024B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ERL JS-RHINO NODEJS PERL6 VB.NET
Resource:COCI 2008/2009 - Croatian Regional