""" """ import sys from sys import stdin N = int(stdin.readline()) A = list(map(int,stdin.readline().split())) one = 0 two = 0 other = 0 for i in A: if i == 2: two += 1 elif i == 1: one += 1 else: other += 1 ans = 0 ans += 2 * (one * (one-1)//2) ans += 2 * (one * other) ans += 3 * (one * two) ans += 1 * ( N*(N-1)//2 - one * (one-1)//2 - one * two - one * other) print (ans)