import numpy as np
import itertools
#N, M = list(map(int, input().split()))
N = 2
M = 2
tmp = [[int(i) for i in input().split()] for i in range(M)]
p = list(map(int, input().split()))
ans = 0
for switch in itertools.product(range(2),repeat=N):
    #print(switch)
    num_clear_light = 0
    for i in range(M):
        count = 0
        for j in range(tmp[i][0]):
            #print(tmp[i][j+1])
            if(switch[tmp[i][j+1] - 1] == 1):
                count += 1
        if(count % 2 == p[i]):
            num_clear_light += 1
    if(num_clear_light == M):
        ans += 1
    num_clear_light = 0

print(ans)