N = int(input()) A = list(map(int, input().split())) B = list(map(int, input().split())) C = list(map(int, input().split())) ans = 1 cnt = 0 for a in A: if a % 3: cnt += 1 ans *= cnt cnt = 0 for a in B: if a % 3: cnt += 1 ans *= cnt cnt = 0 for a in C: if a % 3: cnt += 1 ans *= cnt print(ans)