시간 제한 | 메모리 제한 | 제출 | 정답 | 맞힌 사람 | 정답 비율 |
---|---|---|---|---|---|
1 초 | 1024 MB | 2 | 2 | 2 | 100.000% |
Cribbage is a two-person card game where players score points for various combinations of cards. A standard $52$-card deck is used where cards have one of $4$ suits (not important in this problem) and one of $13$ ranks. The card ranks, from lowest to highest, are Ace (A), $2$, $3$, $4$, $5$, $6$, $7$, $8$, $9$, $10$ (T), Jack (J), Queen (Q), King (K). In normal cribbage, players make combinations from a hand consisting of five cards (four in their hand and one common card). The possible combinations and their point values are the following:
The total score across each of these three categories is the hand's score.
For example, a five-card hand consisting of $4,5,5,5,6$ will score $23$ points: $8$ points for $15$'s (three $4$-$5$-$6$ combinations and one $5$-$5$-$5$), $6$ points for pairs (three pairs of $5$'s) and $9$ points for runs (three $4$-$5$-$6$ runs). The five-card hand T,T,J,Q,Q scores $16$: $4$ points for pairs (T's and Q's) and $12$ points for runs (four different runs of T-J-Q). There are other ways to score as well but the three rules above will suffice for this problem.
Now as we said, in normal cribbage you look for combinations in five-card hands. But we're far from normal. Your task is to determine the value of an $n$-card hand when $n$ can be significantly larger than $5$.
Input starts with a integer $n$ ($5 \leq n \leq 100$) indicating the number of cards in the hand. Following this are $n$ characters taken from the set {A,2,3,4,5,6,7,8,9,T,J,Q,K
} indicating the ranks of the $n$ cards. These characters will be on one or more lines with one space between any two characters on the same line. The card ranks will not necessarily be in sorted order. Note that unlike a standard deck of cards, there may be more than four cards of any rank.
Output the total score achieved by the $n$-card hand.
5 4 5 6 5 5
23
13 A 2 3 4 5 6 7 8 9 T J Q K
71
10 2 2 3 4 5 8 9 T J Q
45