#!/bin/python3 import sys import re sum = 0 for line in sys.stdin: line = line.strip() card_id, sets = line.split(":") card_id = int(re.sub("[^0-9]", "", card_id)) winning_set, holding_set = sets.split("|") winning_numbers = set(winning_set.split()) holding_numbers = set(holding_set.split()) points = 0 for num in holding_numbers: if num in winning_numbers: points += 1 if points > 0: sum += 2 ** (points - 1) print(f">> {sum}")