def Run_Length_Encoding(S): """ランレングス圧縮 S: 文字列 """ if not S: return [] R=[[S[0],1]] for i in range(1,len(S)): if R[-1][0]==S[i]: R[-1][1]+=1 else: R.append([S[i],1]) return R #================================================== N=int(input()) A=list(map(int,input().split())) B=[A[i+1]-A[i] for i in range(N-1)] X=0 for d,k in Run_Length_Encoding(B): if d==1: X+=k*(k+1)//2 print(X)