Under construction

Still being built. Things may change

Rock-Paper-Scissors Score

Interview

Time limit1sMemory limit128 MB

Summary
Given a player's rock-paper-scissors choices against several friends over multiple rounds, compute the actual score and the best possible score with foreknowledge each round.
Level

Easy3 of 10

Topics
Simulation, Greedy, String
Solved
No attempts yet

Problem

Rock-paper-scissors is played by two people. Each player shows one of scissors (S), paper (P), or rock (R). If both players show the same shape, the round is a draw. Scissors beats paper, paper beats rock, and rock beats scissors.

One player trains for a tournament by playing against N friends at the same time for R rounds. In every round, the player and each friend choose one of the three shapes.

The score for a round is computed independently against each friend. The player receives 2 points for a win, 1 point for a draw, and 0 points for a loss.

Given the shapes chosen by the player and all friends, compute the player's final score. Then compute the maximum score the player could have earned if, before each round, the player had known all friends' choices for that round and could choose the best shape.

Input

The first line contains the number of rounds R (1 <= R <= 50).

The second line contains a string of length R, the shapes chosen by the player in order. S means scissors, P means paper, and R means rock.

The third line contains the number of friends N (1 <= N <= 50).

Each of the next N lines contains a string of length R, the shapes chosen by one friend in order.

Output

Print the player's actual score on the first line.

Print the maximum score the player could have earned on the second line.

Examples3

  1. Example 1

    Input
    5
    SSPPR
    1
    SSPPR
    
    Expected output
    5
    10
    
  2. Example 2

    Input
    5
    SSPPR
    2
    PPRRS
    RRSSP
    
    Expected output
    10
    15
    
  3. Example 3

    Input
    4
    SPRS
    4
    RPRP
    SRRR
    SSPR
    PSPS
    
    Expected output
    12
    21