#P7184. Sven's Rock-Paper-Scissors Championship

    ID: 20388 Type: Default 1000ms 256MiB

Sven's Rock-Paper-Scissors Championship

Sven's Rock-Paper-Scissors Championship

Sven has mastered the game of Rock-Paper-Scissors, and now he is practicing against n friends over r rounds. In each round, each friend shows one of the three gestures: rock, paper, or scissors.

The game rules are as follows:

  • If both players choose the same gesture, the round is a draw.
  • Otherwise, the winning rules are: \(\text{scissors} \;\text{beats}\; \text{paper}\), \(\text{paper} \;\text{beats}\; \text{rock}\), and \(\text{rock} \;\text{beats}\; \text{scissors}\).

Scoring for each individual game is defined by:

  • If Sven wins against a friend he earns 2 points.
  • If it is a draw he earns 1 point.
  • If he loses he earns 0 points.

Knowing all the moves his friends will make in advance, Sven can choose his gesture optimally in each round to maximize his total score. Your task is to compute the maximum achievable total score for Sven over all rounds.

inputFormat

The input begins with a line containing two integers: r (the number of rounds) and n (the number of friends).

Then follow r lines, each containing n strings. Each string is one of "rock", "paper", or "scissors", representing the move made by one friend in that round.

outputFormat

Output a single integer, the maximum total score Sven can achieve if he chooses his moves optimally in each round.

sample

1 3
rock paper scissors
3