#!/bin/python3 import sys import re card_count_map = {} for line in sys.stdin: line = line.strip() card_id, sets = line.split(":") card_id = int(re.sub("[^0-9]", "", card_id)) card_count_map[card_id] = card_count_map.get(card_id, 1) winning_numbers, holding_numbers = [set(x.split()) for x in sets.split("|")] matches = 0 for num in holding_numbers: if num in winning_numbers: matches += 1 print(f"card {card_id} has {matches} matches") for x in range(matches): index = card_id + x + 1 card_count_map[index] = card_count_map.get(index, 1) + card_count_map[card_id] print(f"card_count_map[{index}] = {card_count_map[index]}") print(f">> {sum(list(card_count_map.values()))}")