n = int(input()) A = list(map(int, input().split())) ans = 0 l, r = 0, 1 while l < n - 1: while r < n and A[r] - A[r - 1] == 1: r += 1 m = r - l ans += m * (m - 1) // 2 r += 1 l = r - 1 print(ans)