n=int(input()) a=list(map(int,input().split())) ans=[0]*n cnt = 1 for i in range(1,n): if a[i-1] + 1 == a[i]: ans[i] = ans[i-1] + cnt cnt += 1 else: ans[i] = ans[i-1] cnt = 1 print(ans[-1])