import sys input = sys.stdin.readline from collections import * N = int(input()) A = list(map(int, input().split())) ans = 0 cnt = 0 for i in range(N-1): d = A[i+1]-A[i] if d==1: cnt += 1 else: ans += cnt*(cnt+1)//2 cnt = 0 ans += cnt*(cnt+1)//2 print(ans)