input();print(sum([0 if i % 3 == 0 else 1 for i in list(map(int,input().split()))])* sum([0 if i % 3 == 0 else 1 for i in list(map(int,input().split()))])* sum([0 if i % 3 == 0 else 1 for i in list(map(int,input().split()))]))