# https://www.codewars.com/kata/5270d0d18625160ada0000e4
#
# Greed is a dice game played with five six-sided dice. Your mission,
# should you choose to accept it, is to score a throw according to these
# rules. You will always be given an array with five six-sided dice values.
#
#
#  Three 1's => 1000 points
#  Three 6's =>  600 points
#  Three 5's =>  500 points
#  Three 4's =>  400 points
#  Three 3's =>  300 points
#  Three 2's =>  200 points
#  One   1   =>  100 points
#  One   5   =>   50 point
#
#
# A single die can only be counted once in each roll.  For example, a "5" can
# only count as part of a triplet (contributing to the 500 points) or as a
# single 50 points, but not both in the same roll.
#
# Example scoring
#
#
#  Throw       Score
#  ---------   ------------------
#  5 1 3 4 1   50 + 2 * 100 = 250
#  1 1 1 3 1   1000 + 100 = 1100
#  2 4 4 5 4   400 + 50 = 450



def score(dice):
    points3 = {1: 1000, 2: 200, 3: 300, 4: 400, 5: 500, 6: 600}
    points1 = {1: 100, 5: 50}

    result = 0
    d = {}
    for number in dice:
        d.setdefault(number, 0)
        d[number] += 1

    for key, value in d.items():
        if value >= 3:
            d[key] -= 3
            result += points3[key]

    for key, value in d.items():
        if key in points1:
            result += points1[key]*d[key]
            d[key] -= d[key]

    return result
