n = int(input()) a = [int(i) for i in input().split()] d = dict() def mex(x, y): a = {x, y} i = 1 while True: if i not in a: return i i += 1 for i in a: i = min(i, 3) if i in d: d[i] += 1 else: d[i] = 1 ans = 0 for x, i in d.items(): for y, j in d.items(): ans += i*j*mex(x, y) for i in a: ans -= mex(i, i) print(ans // 2)