N = int(input()) A = list(map(int, input().split())) A.sort() n = 0 for i in range(N): if A[i] > 1: n += N-1-i else: cnt1 = A[i+1:].count(2) cnt2 = N-1-i-cnt1 n += 3 * cnt1 + 2 * cnt2 print(n)