n = int(input())
A = list(map(int, input().split()))

a = A.count(1)
b= A.count(2)
c = n - a - b

print(a*(a-1)//2*2+a*b*3+a*c*2+b*(b-1)//2*1+b*c*1+c*(c-1)//2*1)