import sys
from collections import Counter
from itertools import product


def main():
    starting_positions = [int(line.split()[-1]) for line in sys.stdin]
    state_counts = Counter([tuple((p, 0) for p in starting_positions)])
    roll_counts = Counter(sum(c) for c in product([1, 2, 3], repeat=3))
    win_counts = 0, 0

    while state_counts:
        new_state_counts = Counter()
        win_count, other_win_count = win_counts

        for ((position, score), other_player), state_count in state_counts.items():
            for roll, roll_count in roll_counts.items():
                new_position = (position + roll - 1) % 10 + 1
                new_score = score + new_position
                count = state_count * roll_count

                if new_score >= 21:
                    win_count += count
                else:
                    new_state_counts[other_player, (new_position, new_score)] += count

        win_counts = other_win_count, win_count
        state_counts = new_state_counts

    print(max(win_counts))


if __name__ == "__main__":
    main()
