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(1) cnt2 = N-1-i-cnt1 n += 2 * cnt1 + 3 * cnt2 print(n)