import sys input = sys.stdin.buffer.readline N = int(input()) A = sorted(map(int, input().split())) d = {a: i for i, a in enumerate(A)} table2 = [0] * N ans = N for i in range(N - 1, -1, -1): if A[i] + 2 in d: table2[i] = table2[d[A[i] + 2]] + 1 if A[i] - 1 in d: ans += table2[i] + 1 print(ans)