import sys input = sys.stdin.readline N = int(input()) A = list(map(int, input().split())) even = [] odd = [] for a in A: if a % 2 == 0: even.append(a) else: odd.append(a) even.sort() odd.sort() cnt_even = {even[-1] : 1} cnt = 1 for i in range(len(even) - 1)[::-1]: if even[i+1] == even[i] + 2: cnt += 1 else: cnt = 1 cnt_even[even[i]] = cnt cnt_odd = {odd[-1] : 1} cnt = 1 for i in range(len(odd) - 1)[::-1]: if odd[i+1] == odd[i] + 2: cnt += 1 else: cnt = 1 cnt_odd[odd[i]] = cnt ans = N for a in A: if a % 2 == 0: if a + 1 in cnt_odd: ans += cnt_odd[a + 1] else: if a + 1 in cnt_even: ans += cnt_even[a + 1] print(ans)