import sys def resolve(): _ = input() cnt1,cnt2,cntother = 0,0,0 for ai in map(int,sys.stdin.readline().split()): if ai == 1: cnt1 += 1 elif ai == 2: cnt2 += 1 else: cntother += 1 result = 0 if cnt1 > 1: result += cnt1*(cnt1-1) result += cnt1 * cnt2 * 3 + cnt1 * cntother * 2\ + (cnt2 + cntother) * (cnt2 + cntother - 1) // 2 print(result) resolve()