PivotOJ

Cued In

시간 제한: 1000ms메모리 제한: 512MB출처: UKIEPC 2017BOJ 15029

문제

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
출력
37

예제 2

입력
3
blue
black
pink
출력
18

예제 3

입력
8
yellow
green
brown
red
red
red
red
red
출력
34

예제 4

입력
2
red
red
출력
1
코드를 제출하려면 로그인하세요.