from collections import Counter N = int(input()) A = list(map(int, input().split())) ac = Counter() for a in A: ac[min(3, a)] += 1 ans = 0 ans += ((ac[1]**2)-ac[1])//2 * 2 ans += ((ac[2]**2)-ac[2])//2 ans += ((ac[3]**2)-ac[3])//2 ans += ac[1]*ac[2] * 3 ans += ac[1]*ac[3] * 2 ans += ac[2]*ac[3] print(ans)