N = int(input()) A = [list(map(int,input().split())) for _ in range(3)] for i in range(3): A[i] = [int(A[i][j]%3 !=0) for j in range(N)] ans = 1 for i in range(3): ans *= sum(A[i]) print(ans)