import collections N = int(input()) A = list(map(int, input().split())) CA = collections.Counter(A) print( N*(N-1)//2 + CA[1]*(N-CA[1]) + CA[1]*(CA[1]-1)//2 + CA[1]*CA[2])