n = int(input()) A = [int(x) for x in input().split() if int(x) % 3 != 0] B = [int(x) for x in input().split() if int(x) % 3 != 0] C = [int(x) for x in input().split() if int(x) % 3 != 0] print(len(A) * len(B) * len(C))