def I():return int(input()) def MAP():return map(int,input().split()) def LIST(): return list(map(int,input().split())) def S():return input() from collections import deque n=I() a=LIST() q=deque() ans=0 for i in a: if len(q)==0: q.append(i) continue if q[-1]+1==i: q.append(i) else: ans+=len(q)*(len(q)-1)//2 while q: q.popleft() q.append(i) ans+=len(q)*(len(q)-1)//2 print(ans)