I=input N,A=I(),list(map(int,I().split()))+[0] a=0 c=1 t=-1 for e in A: if e==t+1:c+=1 else:a,c=a+c*(c-1)//2,1 t=e print(a)