from collections import * from itertools import * from functools import * from heapq import * import sys,math input = sys.stdin.readline N = int(input()) A = list(map(int,input().split())) dp = defaultdict(lambda:0) for a in A: dp[a+1] += 1 dp[a] += dp[a-2] ans = N for a in A: ans += dp[a] print(ans)