시간 제한 메모리 제한 제출 정답 맞은 사람 정답 비율
1 초 512 MB 1 1 1 100.000%

문제

Snooker is a cue sport played by two players on a rectangular table. The players take turns to pot a series of balls of varying colours, where each colour represents a distinct point value for potting the ball.

A player may pot any ball on the table initially, however any subsequent shots must follow a pattern: if the previous ball was red, the next ball must be another colour; otherwise, if there are still red balls left, the next ball must be red.

Balls of any colour other than red are initially replaced on the table every time they are potted, and may be used again to score more points. The balls stop being replaced once all of the red balls have been potted.

The values of each coloured ball are:

Colour red yellow green brown blue pink black
Value 1 2 3 4 5 6 7

Snooker players are respected universally for their prowess in mental arithmetic. One sweeping glance across the table is enough to tell an experienced contestant how much they could score.

For newer players, however, this is a challenge. Write a program to help calculate a score for a given list of balls remaining on the table.

입력

  • one line containing the integers N (1 ≤ N ≤ 21), the number of balls remaining on the table.
  • N further lines, each containing the colour of one of the balls on the table.

The list of balls will not be ordered in any way and will contain at most one of each of yellow, green, brown, blue, pink and black.

출력

Output the largest possible score the player can make.

예제 입력 1

5
red
black
pink
red
red

예제 출력 1

37

예제 입력 2

3
blue
black
pink

예제 출력 2

18

예제 입력 3

8
yellow
green
brown
red
red
red
red
red

예제 출력 3

34

예제 입력 4

2
red
red

예제 출력 4

1