from collections import defaultdict
from decimal import Decimal
# Only one line
line = next(line.strip() for line in open("input_6.txt", "r"))
fishes = list(map(int, line.split(",")))
assert all(fishes)
# Maps age to counts
generations = defaultdict(int)
for fish in fishes:
generations[fish] += 1.0
for _ in range(256000_0):
# Make a copy to get a snapshot at beginning of tick
# Use sorted to ensure we don't double_age any fish
for age, count in list(sorted(generations.items())):
if age == 0:
# New baby born
generations[8] += count
# Move from 0 to 6 bucket
generations[0] -= count
generations[6] += count
else:
# Get one year closer to popping out baby
generations[age] -= count
generations[age-1] += count
print(sum(generations.values()))