import sys L = [l for l in sys.stdin.read().splitlines()] R = 0 for l in L: _, halves = l.split(':') c1, c2 = halves.split('|') s1 = set(map(int,c1.strip().split(' '))) s2 = set(map(int,c2.strip().split(' '))) n = len(s1&s2) if n>0: R+= 1 << (n-1) print(R)