n = int(input()) aa = list(map(int, input().split())) # 读入数组 ans = 0 stk = [] # 栈 for i inrange(n): # [0, n) ifnot stk: # 栈非空 stk.append([0, 1]) # push if i & 1: while aa[i] and stk: if stk[-1][1] == 0: stk.pop() if stk: now = stk.pop() sub = min(now[0], aa[i]) aa[i] -= sub now[0] -= sub ans += sub if now[0]: stk.append(now) if stk and stk[-1][1] == 0: ans += stk[-1][0] if aa[i]: stk.append([0, 1]) else: ifnot stk: stk.append([0, 0]) if stk[-1][1] == 0: stk[-1][0] += 1 else: stk.append([1, 0]) else: if stk[-1][1] == 0: stk.append([0, 1]) stk[-1][0] += aa[i] print(ans)