n = int(input()) a = sorted(list(map(int, input().split()))) ans = 0 dp = {} for i in range(n): if a[i] not in dp: dp[a[i]] = 0 if i >= 1 and a[i] == a[i - 1] + 1: dp[a[i]] += 1 if i >= 2 and a[i] - 2 in dp: dp[a[i]] += dp[a[i] - 2] ans += dp[a[i]] + 1 print(ans)