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