n = int(input()) a = list(map(int, input().split())) b = list(map(int, input().split())) c = list(map(int, input().split())) p, q, r = [0, 0, 0] for i in a: if(i % 3 == 0): continue p += 1 for i in b: if(i % 3 == 0): continue q += 1 for i in c: if(i % 3 == 0): continue r += 1 print(p * q * r)