N = int(input()) A = list(map(int, input().split())) ans = 0 b = 1 for i in range(N-1): if A[i] + 1 == A[i+1]: b += 1 else: ans += b * (b - 1) // 2 b = 1 ans += b * (b - 1) // 2 print(ans)