n = int(input()) A = list(map(int, input().split())) A.sort() dp = {} for a in A: dp[a] = dp.get(a, 0) + 1 dp[a + 1] = dp.get(a + 1, 0) + dp.get(a - 1, 0) print(sum(dp.values()))