A higher resolution is required to access the IDE

- 8

## Learning Opportunities

This puzzle can be solved using the following concepts. Practice using these concepts and improve your skills.

## Statement

## Goal

It's two years into the apocalypse and you've been living alone in a bunker. The only soul you can talk to is an AI bot named Nobs. To pass the time you play games against Nobs. But he only knows how to play Solitaire and Minesweeper which you've grown tired of. You decide to teach him your favorite pre-apocalypse game, Cribbage.Cribbage is a two-player card and board game where you make combinations to count points and get to the target before your opponent.

See here for all the details:

**https://en.wikipedia.org/wiki/Cribbage**and here for the rules:

**https://en.wikipedia.org/wiki/Rules_of_cribbage**.

Using a stack of security keycards as a deck, toothpicks for pegs, and an old pizza box for a board you start to play against Nobs. At first, Nobs is incredibly bad at playing since he has no idea how to play and simply discards at random into the crib. You decide that the only way Nobs will ever be a challenge to you is if you teach him the rules for scoring hands so that he can best decide which cards to keep.

Write the algorithm that Nobs should use to score his hand.

Scoring:

You hold

**4**cards in your hand and a fifth common

**starter card**is cut and included when scoring your hand.

Fifteens: 2 points for every distinct group of cards whose totals adds up to 15, (

**2**points,

**2**points

Runs:

**3**or more consecutive cards by rank, 1 point for each card. Ex:

**3**points,

**4**points.

Pairs:

**2**points for every distinct pair of cards with identical ranks. This means that a triplet gives

**6**points and a quadruplet

**12**points. Ex:

**2**points,

**6**points (

**12**points.

Flushes:

**4**points if all

**4**cards in your hand are of the same suit,

**5**points if the starter card is also the same suit. Ex:

**4**points,

**5**points,

**0**points

His nobs:

**1**point if you have a

**1**point

**29**Hand: All five

**5**'s and the

**29**.

Ex:

**1**point for his nobs and fifteen for

**2**

**2**

**2**

**2**

**2**

**2**

**2**

**2**

**2**for a pair

**2**for a pair

**2**for a pair

**2**for a pair

**2**for a pair

**2**for a pair

Add it all up and you get

**29**! The chances to get a twenty-nine hand are 1 in 216580.

Input

**Line 1:**An integer

`N`for the number of hands to score

**5 Space-separated values describing the cards in the hand (The first 4 cards for the player, the 5th is the starter card).**

`N`Lines:Cards are input as a two-character string. The first character is the card's rank (

**1**,

**10**, the rest are all face value.

Output

**The score for the given hand.**

`N`Lines:Constraints

1 ≤

`N`≤ 10Example

Input

5 7H 8D TS 2H 4C 5C TD KS 2H 4C 6H AS 9C TS KH 2C TS 3D 6S 8C 2C TS 3D QH 8C

Output

2 4 2 2 4

A higher resolution is required to access the IDE