n = int(input()) a = [0 if int(x)%3 == 0 else 1 for x in input().split()] b = [0 if int(x)%3 == 0 else 1 for x in input().split()] c = [0 if int(x)%3 == 0 else 1 for x in input().split()] print(sum(a) * sum(b) * sum(c))