def group_when(xs, pred): res = [] a = [] for x in xs: if not a or pred(a[-1], x): a.append(x) else: res.append(a) a = [x] if a: res.append(a) return res N = int(input()) A = list(map(int, input().split())) gg = group_when(A, lambda a, b: a+1 == b) ans = 0 for g in gg: k = len(g) ans += k * (k - 1) // 2 print(ans)