from collections import defaultdict N = int(input()) A = list(map(int, input().split())) A.sort() d = defaultdict(int) for a in A: d[a] += 1 d[a + 1] += d[a - 1] print(sum(d.values()))