n = int(input()) a = list(map(int,input().split())) b = list(map(int,input().split())) c = list(map(int,input().split())) a1,b1,c1 = 0,0,0 for i in a: if i % 3 != 0: a1 += 1 for j in b: if j % 3 == 0: b1 += 1 for k in c: if k % 3 == 0: c1 += 1 print(a1*b1*c1)