N=int(input()) ANS=1 for i in range(3): c=0 for j in map(int,input().split()): if j%3!=0: c+=1 ANS*=c print(ANS)