N = int(input()) ans = 1 for _ in range(3): X = map(int, input().split()) ans *= sum(bool(x % 3) for x in X) print(ans)