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