import sys input = sys.stdin.readline from collections import Counter N=int(input()) A=list(map(int,input().split())) C=Counter(A) ONE=C[1] TWO=C[2] ANS=N*(N-1)//2 ANS+=ONE*(N-1)-ONE*(ONE-1)//2 ANS+=ONE*TWO print(ANS)