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