description: <image>
  
  William has a favorite bracket sequence. Since his favorite sequence is quite big he provided it to you as a sequence of positive integers c_1, c_2, ..., c_n where c_i is the number of consecutive brackets "(" if i is an odd number or the number of consecutive brackets ")" if i is an even number.
  
  For example for a bracket sequence "((())()))" a corresponding sequence of numbers is [3, 2, 1, 3].
  
  You need to find the total number of continuous subsequences (subsegments) [l, r] (l ≤ r) of the original bracket sequence, which are regular bracket sequences.
  
  A bracket sequence is called regular if it is possible to obtain correct arithmetic expression by inserting characters "+" and "1" into this sequence. For example, sequences "(())()", "()" and "(()(()))" are regular, while ")(", "(()" and "(()))(" are not.
  
  Input
  
  The first line contains a single integer n (1 ≤ n ≤ 1000), the size of the compressed sequence.
  
  The second line contains a sequence of integers c_1, c_2, ..., c_n (1 ≤ c_i ≤ 10^9), the compressed sequence.
  
  Output
  
  Output a single integer — the total number of subsegments of the original bracket sequence, which are regular bracket sequences.
  
  It can be proved that the answer fits in the signed 64-bit integer data type.
  
  Examples
  
  Input
  
  
  5
  4 1 2 3 1
  
  
  Output
  
  
  5
  
  
  Input
  
  
  6
  1 3 2 1 2 4
  
  
  Output
  
  
  6
  
  
  Input
  
  
  6
  1 1 1 1 2 2
  
  
  Output
  
  
  7
  
  Note
  
  In the first example a sequence (((()(()))( is described. This bracket sequence contains 5 subsegments which form regular bracket sequences:
  
    1. Subsequence from the 3rd to 10th character: (()(()))
    2. Subsequence from the 4th to 5th character: ()
    3. Subsequence from the 4th to 9th character: ()(())
    4. Subsequence from the 6th to 9th character: (())
    5. Subsequence from the 7th to 8th character: ()
  
  
  
  In the second example a sequence ()))(()(()))) is described.
  
  In the third example a sequence ()()(()) is described.
solution: 	#----------FASTIOSTART-----------#
  
  from __future__ import division, print_function
  import os
  import sys
  from io import BytesIO, IOBase
  if sys.version_info[0] < 3:
  	from __builtin__ import xrange as range
  	from future_builtins import ascii, filter, hex, map, oct, zip
  BUFSIZE = 8192
  class FastIO(IOBase):
  	newlines = 0
  	def __init__(self, file):
  		self._fd = file.fileno()
  		self.buffer = BytesIO()
  		self.writable = "x" in file.mode or "r" not in file.mode
  		self.write = self.buffer.write if self.writable else None
  	def read(self):
  		while True:
  			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
  			if not b:
  				break
  			ptr = self.buffer.tell()
  			self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
  		self.newlines = 0
  		return self.buffer.read()
  	def readline(self):
  		while self.newlines == 0:
  			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
  			self.newlines = b.count(b"\n") + (not b)
  			ptr = self.buffer.tell()
  			self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
  		self.newlines -= 1
  		return self.buffer.readline()
  	def flush(self):
  		if self.writable:
  			os.write(self._fd, self.buffer.getvalue())
  			self.buffer.truncate(0), self.buffer.seek(0)
  class IOWrapper(IOBase):
  	def __init__(self, file):
  		self.buffer = FastIO(file)
  		self.flush = self.buffer.flush
  		self.writable = self.buffer.writable
  		self.write = lambda s: self.buffer.write(s.encode("ascii"))
  		self.read = lambda: self.buffer.read().decode("ascii")
  		self.readline = lambda: self.buffer.readline().decode("ascii")
  def print(*args, **kwargs):
  	sep, file = kwargs.pop("sep", " "), kwargs.pop("file", sys.stdout)
  	at_start = True
  	for x in args:
  		if not at_start:
  			file.write(sep)
  		file.write(str(x))
  		at_start = False
  	file.write(kwargs.pop("end", "\n"))
  	if kwargs.pop("flush", False):
  		file.flush()
  if sys.version_info[0] < 3:
  	sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
  else:
  	sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
  input = lambda: sys.stdin.readline().rstrip("\r\n")
  
  #----------FASTIOFINISH----------#
  
  import collections,bisect,re,random,queue,itertools,statistics,math
  from collections import *
  from bisect import *
  from itertools import * 
  from statistics import *
  from math import *
  from re import *
  from queue import *
  
  #----------SASTA_STL-------------#
  
  # stack
  class Stack:
      def __init__(self):self.items = []
      def push(self, item):self.items.append(item)
      def pop(self):return self.items.pop()
      def empty(self):return self.items == []
      def size(self):return len(self.items)
      def at(self,idx):
      	try:return self.items[idx]
      	except:return -1
  
  #priority_queue
  class priority_queue(object):
      def __init__(self):self.queue = []
      def __str__(self):return ' '.join([str(i) for i in self.queue])
      def empty(self):return len(self.queue) == 0
      def insert(self, data):self.queue.append(data)
      def delete(self):
          try:
              max = 0
              for i in range(len(self.queue)):
                  if self.queue[i] > self.queue[max]:
                      max = i
              item = self.queue[max]
              del self.queue[max]
              return item
          except IndexError:
              print()
              exit()
  
  #----------SASTA_STL-------------#
  mod=int(1e9+7)
  imin=-2147483648;
  imax=2147483647;
  true=True
  false=False
  N=int(1e5+9)
  none=None
  inp = lambda : input()
  I   = lambda : int(inp())
  M   = lambda : map(int,inp().split())
  MS  = lambda : map(str,inp().split())
  S   = lambda : list(MS())
  L   = lambda : list(M())
  Yes = lambda : print("Yes")
  No  = lambda : print("No")
  YES = lambda : print("YES")
  NO  = lambda : print("NO")
  yes = lambda : print("yes")
  no  = lambda : print("no")
  chartonum={"1":1,"2":2,"3":3,"4":4,"5":5,"6":6,"7":7,"8":8,"9":9,"0":0}
  def IO(controll):
  	if controll==false:
  		sys.stdin = open('input.txt', 'r')
  		sys.stdout = open('uttar.txt', 'w')
  	else:
  		pass
  def true_yes(statement):
  	return YES() if statement else NO()
  def binary(x):
  	return bin(x).replace("0b","")
  def state(statement,one,two):
  	print(one if statement else two)
  def swap(a,b):
  	a,b=b,a
  def bintodec(n):
  	return int(n,2)
  def prec(a):
  	return ("{0:.9f}".format(a))
  def case(t):
  	print("Case #"+str(i)+": ",end="")
  def palin(s):
  	return s==s[::-1]
  def is_sorted(arr):
  	return arr==sorted(arr)
  
  #----------TOTKA-----------#
  
  #open_list = ["[","{","("]
  #close_list = ["]","}",")"]
    
  # Function to check parentheses
  """def is_pretty(myStr):
      stack = []
      for i in myStr:
          if i in open_list:
              stack.append(i)
          elif i in close_list:
              pos = close_list.index(i)
              if ((len(stack) > 0) and
                  (open_list[pos] == stack[len(stack)-1])):
                  stack.pop()
              else:
                  return false
      if len(stack) == 0:
          return true
      else:
          return false
  
  def printSubSequences(s):  
  	res=0 
  	for i,j in combinations_with_replacement(range(len(s)), 2):
  		if is_pretty(s[i:(j+1)]):
  			res+=1
  
  	return res;"""
  
  def kabraji_ka_totka():
  	# totka hai dosto !
  	IO(1)
  	n = I()
  	l = L()
  	 
  	stack = []
  	ct = []
  	last = 0
  	out = 0
  	 
  	for i in range(n):
  	    #print(i,stack,ct,last,out)
  	    v = l[i]
  	    if i % 2 == 0:
  	        stack.append(v)
  	        ct.append(last)
  	    else:
  	        while v and stack:
  	            assert v > 0
  	            
  	            top = stack.pop()
  	            if v >= top:
  	                v -= top
  	                out += top
  	                ctp = ct.pop()
  	                out += ctp
  	                last = ctp + 1 
  	            else:
  	                out += v
  	                stack.append(top - v)
  	                v = 0
  	                last = 1
  	        if v:   
  	            last = 0
  	 
  	print(out)
  #----------TOTKA----------#
  
  if __name__=="__main__":
  	kabraji_ka_totka()
  