Yahtzee

Time limit1sMemory limit128 MB

Problem

Yahtzee is a game played with 5 dice over 13 rounds. A score card has 13 categories. In each round the player chooses one category to score, and each category may be used exactly once in the whole game. In other words, you must assign the 13 rounds one-to-one to the 13 categories.

Each category is scored as follows:

  • ones: the sum of all dice showing 1 (the count of 1s times 1)
  • twos: the sum of all dice showing 2
  • threes: the sum of all dice showing 3
  • fours: the sum of all dice showing 4
  • fives: the sum of all dice showing 5
  • sixes: the sum of all dice showing 6
  • chance: the sum of all five dice
  • three of a kind: the sum of all five dice if at least three dice share the same value, otherwise 0
  • four of a kind: the sum of all five dice if at least four dice share the same value, otherwise 0
  • five of a kind: 50 points if all five dice share the same value, otherwise 0
  • short straight: 25 points if four of the dice form a run (1,2,3,4 or 2,3,4,5 or 3,4,5,6), otherwise 0
  • long straight: 35 points if all five dice form a run (1,2,3,4,5 or 2,3,4,5,6), otherwise 0
  • full house: 40 points if the dice consist of exactly two distinct values, one appearing three times and the other appearing twice (for example 2,2,5,5,5), otherwise 0

For the last six categories (three of a kind through full house), a category is scored as 0 whenever its condition is not met.

The score of a game is the sum of all 13 category scores, plus a bonus of 35 points if the sum of the first six categories (ones through sixes) is 63 or more.

For each game, compute the maximum total score that can be achieved.

Input

Each line of input contains 5 integers between 1 and 6, separated by spaces, giving the values of the five dice thrown in one round. Each game consists of 13 such lines, and the input may contain any number of games, one after another, until end of file.

Output

For each game, print a single line containing the maximum total score (a single integer) that can be achieved for that game.