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