n = int(input()) A = sorted(map(int, input().split())) x = A.count(1) y = A.count(2) z = n - x - y ans = y*(y-1)//2 + y*z + z*(z-1)//2 ans += 2 * (x*(x-1)//2 + x*z) ans += 3 * x*y print(ans)