#K92082. Blackjack Card Total

    ID: 38118 Type: Default 1000ms 256MiB

Blackjack Card Total

Blackjack Card Total

You are given a series of blackjack hands. Each hand is represented by a line of playing cards where the card values can be a number from 2 to 10, or one of the face cards: Jack, Queen, King, or Ace.

The rules for calculating the total value of a hand are as follows:

  • Cards 2 to 10 have their numeric values.
  • Face cards (Jack, Queen, King) are worth 10.
  • Ace is worth 1, but it can be counted as 11 if doing so does not cause the total sum to exceed 21. Each Ace is considered separately.

The input consists of multiple lines of cards (each card separated by a space) and the last line contains the string END to indicate termination. For each valid hand, compute the highest total value that does not exceed 21, or output the sum regardless.

Note: It is guaranteed that the input hands will be processed until the termination string is encountered.

inputFormat

The input is provided via standard input (stdin). It consists of multiple lines. Each line (except the last) contains a space-separated list of cards. The final line is a single line containing the word END indicating the end of input.

outputFormat

For each input line (except the termination line), print the calculated blackjack total on a new line to standard output (stdout).

## sample
2 3 Jack
Ace 10
5 7 Ace Ace
Ace King 9
END
15

21 14 20

</p>