N=int(input()) A=list(map(int,input().split())) Q=[] ANS=0 for i in range(N): #print(Q,ANS) a=A[i] if i%2==0: while True: if Q: x,y=Q[-1] if a>=y: Q.pop() ANS-=y-x+1 continue if ay: Q.pop() ANS-=y-x+1 continue if a