import sys 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] #print(win) #print(sto) for idx, p in enumerate(sto): n = 0 for j in p: #print(j, win[idx]) n += win[idx].count(j) S+= 2 ** (n-1) if n > 0 else 0 return S if __name__ == '__main__': print(main(sys.stdin.read().splitlines()))