n = int(input()) A = list(map(int, input().split())) L = [0, 0, 0, 0] for i in range(n): if A[i] <= 2: L[A[i]] += 1 else: L[3] += 1 ans = 0 ans += L[1] * (L[1] - 1) ans += L[2] * (L[2] - 1) // 2 + L[3] * (L[3] - 1) // 2 ans += 3 * L[1] * L[2] ans += L[1] * L[3] ans += L[2] * L[3] print(ans)