N = int(input()) A = sorted([int(i) for i in input().split()]) sum = 0 for i in range(N): if A[i] == 1: for j in range(i+1,N): if A[j] == 1: sum += 2 elif A[j] == 2: sum += 3 else: sum = sum + 2*((N-1)-j+1) break elif A[i] == 2: for j in range(i+1,N): if A[j] == 2: sum += 1 else: sum = sum + 2*((N-1)-j+1) break else: sum = sum + int(((N-1)-i+1)*(N-1)/2) break print(sum)