N = int(input()) A = list(map(int,input().split())) a = 0 b = 0 c = 0 for i in range(N): if A[i] == 1: a += 1 elif A[i] == 2: b += 1 else: c += 1 sum = 0 sum += 2 * a * (a-1) // 2 sum += 3 * a * b sum += 1 * b * c sum += 2 * a * c sum += b * (b-1) //2 sum += c * (c-1) // 2 print(sum)