n = int(input()) ans = 1 for i in range(3): t = 0 a = list(map(int, input().split())) for x in a: if x % 3 != 0: t += 1 ans *= t print(ans)