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: 					/*
  					ID: abdelra29
  LANG: JAVA
  PROG: zerosum
  					*/
  						/*
  						TO LEARN
  				
  						2-euler tour
  					
  						*/
  						/*
  						TO SOLVE 
  						*/
  						/*
  						bit manipulation shit
  						1-Computer Systems: A Programmer's Perspective
  						2-hacker's delight
  						*/
  						/*
  						TO WATCH
  						
  						*/
  						            import java.util.*;
  								    import java.math.*;
  								    import java.io.*; 
  								    import java.util.stream.Collectors;
  
  								       public class A{
  						            static FastScanner scan=new FastScanner();
  									     public static PrintWriter out = new PrintWriter (new BufferedOutputStream(System.out));
  
  static boolean isprime(int x)
  {
  	if(x%2==0)
  		return false;
  	if(x==1)
  		return false;
  	if(x==2||x==3)
  		return true;
  	for(int i=3;i*i<=x;i+=2)
  		if(x%i==0)
  			return false;
  		return true;
  }
  static int hidden[]={0,181,21,53};
  static Pair askand(int x)
  {
  	System.out.println("and "+x+" "+(x-1));
     //int fi=scan.nextInt();
  	int fi=hidden[x]&hidden[x-1];
  	System.out.println("and "+x+" "+(x-2));
  	int sec=hidden[x]&hidden[x-2];
  	//int sec=scan.nextInt();
  	return new Pair(fi,sec);
  }
  static Pair askor(int x)
  {
  	System.out.println("or "+x+" "+(x-1));
  	//int fi=scan.nextInt();
  int fi=hidden[x]|hidden[x-1];
  	System.out.println("or "+x+" "+(x-2));
  	int sec=hidden[x]|hidden[x-2];
  	//int sec=scan.nextInt();
  	return new Pair(fi,sec);
  }
  static int binaryToDecimal(String n)
      {
          String num = n;
          int dec_value = 0;
   
          // Initializing base value to 1,
          // i.e 2^0
          int base = 1;
   
          int len = num.length();
          for (int i = len - 1; i >= 0; i--) {
              if (num.charAt(i) == '1')
                  dec_value += base;
              base = base * 2;
          }
   
          return dec_value;
      }
      static boolean areBracketsBalanced(String expr)
      {
          // Using ArrayDeque is faster than using Stack class
          Deque<Character> stack
              = new ArrayDeque<Character>();
   
          // Traversing the Expression
          for (int i = 0; i < expr.length(); i++)
          {
              char x = expr.charAt(i);
   
              if (x == '(' || x == '[' || x == '{')
              {
                  // Push the element in the stack
                  stack.push(x);
                  continue;
              }
   
              // If current character is not opening
              // bracket, then it must be closing. So stack
              // cannot be empty at this point.
              if (stack.isEmpty())
                  return false;
              char check;
              switch (x) {
              case ')':
                  check = stack.pop();
                  if (check == '{' || check == '[')
                      return false;
                  break;
   
              case '}':
                  check = stack.pop();
                  if (check == '(' || check == '[')
                      return false;
                  break;
   
              case ']':
                  check = stack.pop();
                  if (check == '(' || check == '{')
                      return false;
                  break;
              }
          }
   
          // Check Empty Stack
          return (stack.isEmpty());
      }
  static long brute(int n,long arr[])
  {
      StringBuilder res=new StringBuilder("");
      for(int i=0;i<n;i++)
      {
          if(i%2==0)
          {
              for(int j=0;j<arr[i];j++)
                  res.append("(");
          }
          else {
              for(int j=0;j<arr[i];j++)
                  res.append(")");
          }
      }
      long ans=0;
   //   System.out.println(res.substring(0,1));
      for(int i=0;i<res.length();i++)
      {
          for(int j=i+1;j<res.length();j++)
          {
              if(areBracketsBalanced(res.substring(i,j+1).toString()))
              {
              	System.out.println(i+" "+j);
                  ans++;
              }
          }
      }
      return ans;
  }
  		public static void main(String[] args)  throws Exception 
  						      {
  						 /*
  						 very important tips 
  						 1-just fucking think backwards once in your shitty life
  						 2-consider brute forcing and finding some patterns and observations
  						 3-when you're in contest don't get out because you think there is no enough time
  						 4-don't get stuck on one approach 
  						 */
  					//	File file=new File("D:\\input\\out.txt");
  						//	scan=new FastScanner("D:\\input\\xs_and_os_input.txt");
  							//	out = new PrintWriter(new File("D:\\input\\out.txt"));
  								 
  								 							 /*
  								 READING 
  						
  								 3-Introduction to DP with Bitmasking codefoces
  								 4-Bit Manipulation hackerearth
  								 5-read more about mobious and inculsion-exclusion 
  								 */
  								 /*
  									 1- 
  									 */
  									 /*for(int i=3;i<=30;i++)
  									{
  										int sh=(i%3==0)?i/3:i/3+1;
  										System.out.println(i*2+" "+(sh*4));
  									}*/
  									 
  
  								int tt =1;
  								//tt=scan.nextInt();
  								int T=1;
  							 outer:while(tt-->0)
  								    {	
  								   int n=scan.nextInt();
  								   if(n%2==1)
  								   	n--;
  								   long arr[]=new long[n];
  								   for(int i=0;i<n;i++)
  								   	arr[i]=scan.nextLong();
  						//	   brute(n,arr);
  					/*			    StringBuilder sb=new StringBuilder("");
      for(int i=0;i<n;i++)
      {
          if(i%2==0)
          {
              for(int j=0;j<arr[i];j++)
                  sb.append("(");
          }
          else {
              for(int j=0;j<arr[i];j++)
                  sb.append(")");
          }
      }*/
    //  System.out.println(sb);
  								   long res=0;
  								   for(int i=0;i<n;i+=2)
  								   {
  								   	//start from i to j
  								   	long cur=0,to=arr[i];
  								   	for(int j=i+1;j<n;j+=2)
  								   	{
  								   		if(j==i+1)
  								   		{
  								   			res+=Math.min(arr[i],arr[j]);
  								   			to-=arr[j];
  								   			if(arr[i]<arr[j])
  								   				break;
  								   			//cur+=arr[i]-arr[j];
  								   		}
  								   		else 
  								   		{
  								   			cur+=arr[j-1];
  								   			
  								   			long tmpa=arr[j];
  								   	
  								   			if(cur<=arr[j]){
  								   				
  								   				res++;
  								   			}
  								   			long rem=arr[j]-cur;
  								   			if(rem<0){
  								   			
  								   				cur-=Math.min(cur,arr[j]);
  								   				continue;
  								   			}
  								   			cur-=Math.min(cur,arr[j]);
  								   			res+=Math.min(rem,to);
  								   			if(to<rem)
  								   				break;
  								   			
  								   			to-=rem;
  								   		}
  								   	
  								   	}
  								 	//out.println("RES "+res);
  								   }
  								   out.println(res);
  
  								
  
  }
  
  		out.close();
  					}
  					
  
  					static class special implements Comparable<special>{
  					int cnt,idx;
  					String s;
  					public special(int cnt,int idx,String s)
  					{
  						this.cnt=cnt;
  						this.idx=idx;
  						this.s=s;
  					}
  
  						 @Override
  								            public int hashCode() {
  								                return (int)42;
  								            }
  						  @Override
  								            public boolean equals(Object o){
  								            //	System.out.println("FUCK");
  								                if (o == this) return true;
  								                if (o.getClass() != getClass()) return false;
  								                special t = (special)o;
  								                return t.cnt == cnt && t.idx == idx;
  								            }
  								            public int compareTo(special o1)
  								            {
  								            	if(o1.cnt==cnt)
  								            	{
  								            		return o1.idx-idx;
  								            	}
  								            	return o1.cnt-cnt;
  								            }
  					}
  		
  								   
  								     static long binexp(long a,long n)
  								    {
  								        if(n==0)
  								            return 1;
  								        long res=binexp(a,n/2);
  								        if(n%2==1)
  								            return res*res*a;
  								        else 
  								            return res*res;
  								    }
  								     
  								    static long powMod(long base, long exp, long mod) {
  								           if (base == 0 || base == 1) return base;
  								           if (exp == 0) return 1;
  								           if (exp == 1) return (base % mod+mod)%mod;
  								           long R = (powMod(base, exp/2, mod) % mod+mod)%mod;
  								           R *= R;
  								           R %= mod;
  								           if ((exp & 1) == 1) {
  								               return (base * R % mod+mod)%mod;
  								           }
  								           else return (R %mod+mod)%mod;
  								       }
  								    static double dis(double x1,double y1,double x2,double y2)
  								    {
  								        return Math.sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
  								    }
  								    static long mod(long x,long y)
  								        {
  								            if(x<0)
  								                x=x+(-x/y+1)*y;
  								            return x%y;
  								        }
  								     public static  long pow(long b, long e) {
  								                long r = 1;
  								                while (e > 0) {
  								                    if (e % 2 == 1) r = r * b ;
  								                    b = b * b;
  								                    e >>= 1;
  								                }
  								                return r;
  								            }
  								    private static void sort(int[] arr) {
  								            List<Integer> list = new ArrayList<>();
  								            for (int object : arr) list.add(object);
  								            Collections.sort(list);
  								        //Collections.reverse(list);
  								            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
  								        }
  								    private static void sort2(long[] arr) {
  								            List<Long> list = new ArrayList<>();
  								            for (Long object : arr) list.add(object);
  								            Collections.sort(list);
  								        Collections.reverse(list);
  								            for (int i = 0; i < list.size(); ++i) arr[i] = list.get(i);
  								        }
  								     static class FastScanner
  						{
  						    private int BS = 1 << 16;
  						    private char NC = (char) 0;
  						    private byte[] buf = new byte[BS];
  						    private int bId = 0, size = 0;
  						    private char c = NC;
  						    private double cnt = 1;
  						    private BufferedInputStream in;
  						 
  						    public FastScanner() {
  						        in = new BufferedInputStream(System.in, BS);
  						    }
  						 
  						    public FastScanner(String s) {
  						        try {
  						            in = new BufferedInputStream(new FileInputStream(new File(s)), BS);
  						        } catch (Exception e) {
  						            in = new BufferedInputStream(System.in, BS);
  						        }
  						    }
  						 
  						    private char getChar() {
  						        while (bId == size) {
  						            try {
  						                size = in.read(buf);
  						            } catch (Exception e) {
  						                return NC;
  						            }
  						            if (size == -1) return NC;
  						            bId = 0;
  						        }
  						        return (char) buf[bId++];
  						    }
  						 
  						    public int nextInt() {
  						        return (int) nextLong();
  						    }
  						 
  						    public int[] nextInts(int N) {
  						        int[] res = new int[N];
  						        for (int i = 0; i < N; i++) {
  						            res[i] = (int) nextLong();
  						        }
  						        return res;
  						    }
  						 
  						    public long[] nextLongs(int N) {
  						        long[] res = new long[N];
  						        for (int i = 0; i < N; i++) {
  						            res[i] = nextLong();
  						        }
  						        return res;
  						    }
  						 
  						    public long nextLong() {
  						        cnt = 1;
  						        boolean neg = false;
  						        if (c == NC) c = getChar();
  						        for (; (c < '0' || c > '9'); c = getChar()) {
  						            if (c == '-') neg = true;
  						        }
  						        long res = 0;
  						        for (; c >= '0' && c <= '9'; c = getChar()) {
  						            res = (res << 3) + (res << 1) + c - '0';
  						            cnt *= 10;
  						        }
  						        return neg ? -res : res;
  						    }
  						 
  						    public double nextDouble() {
  						        double cur = nextLong();
  						        return c != '.' ? cur : cur + nextLong() / cnt;
  						    }
  						 
  						    public double[] nextDoubles(int N) {
  						        double[] res = new double[N];
  						        for (int i = 0; i < N; i++) {
  						            res[i] = nextDouble();
  						        }
  						        return res;
  						    }
  						 
  						    public String next() {
  						        StringBuilder res = new StringBuilder();
  						        while (c <= 32) c = getChar();
  						        while (c > 32) {
  						            res.append(c);
  						            c = getChar();
  						        }
  						        return res.toString();
  						    }
  						 
  						    public String nextLine() {
  						        StringBuilder res = new StringBuilder();
  						        while (c <= 32) c = getChar();
  						        while (c != '\n') {
  						            res.append(c);
  						            c = getChar();
  						        }
  						        return res.toString();
  						    }
  						 
  						    public boolean hasNext() {
  						        if (c > 32) return true;
  						        while (true) {
  						            c = getChar();
  						            if (c == NC) return false;
  						            else if (c > 32) return true;
  						        }
  						    }
  						}
  
  								     static class Pair implements Comparable<Pair>{
  								            public long x, y,z;
  								            public Pair(long x1, long y1,long z1) {
  								                x=x1;
  								                y=y1;
  								                z=z1;
  								            }
  								             public Pair(long x1, long y1) {
  								                x=x1;
  								                y=y1;
  								    
  								            }
  								            
  								            @Override
  								            public int hashCode() {
  								                return (int)(x + 31 * y);
  								            }
  								            public String toString() {
  								                return x + " " + y+" "+z;
  								            }
  								            @Override
  								            public boolean equals(Object o){
  								                if (o == this) return true;
  								                if (o.getClass() != getClass()) return false;
  								                Pair t = (Pair)o;
  								                return t.x == x && t.y == y&&t.z==z;
  								            }
  								    public int compareTo(Pair o)
  								    {
  								    								  	
  								  
  								    	return (int)(x-o.x);
  								     
  								        }
  								     
  								    }
  								}
  								
  								    
  								   
  
  								     
  