28 lines
770 B
Python
28 lines
770 B
Python
import sys
|
|
from functools import reduce
|
|
|
|
def main(myList, S = 0):
|
|
card=[c.split(": ")[1] for c in myList]
|
|
|
|
win_str_one = [s.split(" | ")[0] for s in card]
|
|
sto_str_one = [s.split(" | ")[1] for s in card]
|
|
|
|
win_str = [s.split(" ") for s in win_str_one]
|
|
sto_str = [s.split(" ") for s in sto_str_one]
|
|
|
|
win = [ [int(i) for i in item if i != ''] for item in win_str]
|
|
sto = [ [int(i) for i in item if i != ''] for item in sto_str]
|
|
|
|
copy = [1] * len(win)
|
|
|
|
for idx, p in enumerate(sto):
|
|
n = 0
|
|
for j in p:
|
|
if win[idx].count(j) > 0:
|
|
copy[idx+n+1]+= copy[idx]
|
|
n+=1
|
|
|
|
return reduce(lambda x, y: x+y, copy)
|
|
|
|
if __name__ == '__main__':
|
|
print(main(sys.stdin.read().splitlines())) |