···11+import fileinput
22+from collections import Counter
33+44+55+part_1 = 0
66+part_2_cards = Counter()
77+88+for line in fileinput.input():
99+ card, rest = line.split(': ')
1010+ card_id = int(card[5:])
1111+1212+ winning, your = rest.split(' | ')
1313+ winning = set(int(n) for n in winning.split())
1414+ your = [int(n) for n in your.split()]
1515+1616+ # Add the "original" scratchcard as one of the copies.
1717+ part_2_cards[card_id] += 1
1818+1919+ matches = 0
2020+ for n in your:
2121+ if n in winning:
2222+ matches += 1
2323+2424+ if matches > 0:
2525+ part_1 += 2 ** (matches - 1)
2626+2727+ for copy_id in range(card_id + 1, card_id + matches + 1):
2828+ part_2_cards[copy_id] += part_2_cards[card_id]
2929+3030+print("Part 1:", part_1)
3131+print("Part 2:", sum(part_2_cards.values()))
3232+