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: import java.io.*;
  import java.util.*;
  
  public class Main{
  	static void main() throws Exception{
  		int n=sc.nextInt();
  		int[]in=sc.intArr(n);
  		long ans=0;
  		for(int i=0;i<n;i+=2) {
  			long bal=in[i];
  			long minBal=in[i];
  			for(int j=i+1;j<n;j+=2) {
  				bal-=in[j];
  				long cur=in[j];
  				long balance=bal;
  				if(balance<0) {
  					cur+=balance;
  					balance=0;
  				}
  				long me=in[i];
  				if(balance>0) {
  					me-=balance;
  					balance=0;
  				}
  				long min=in[i]-minBal;
  				
  				long can=Math.min(me-min+1, cur);
  //				System.out.println(i+" "+j+" "+can);
  				ans+=Math.max(can, 0);
  				
  				if(bal<0)break;
  				minBal=Math.min(minBal, bal);
  				
  				if(j+1<n) {
  					bal+=in[j+1];
  				}
  			}
  		}
  		pw.println(ans);
  	}
      public static void main(String[] args) throws Exception{
          sc=new MScanner(System.in);
          pw = new PrintWriter(System.out);
          int tc=1;
  //        tc=sc.nextInt();
          for(int i=1;i<=tc;i++) {
  //            pw.printf("Case %d:\n", i);
              main();
          }
          pw.flush();
      }
      static PrintWriter pw;
      static MScanner sc;
      static class MScanner {
          StringTokenizer st;
          BufferedReader br;
          public MScanner(InputStream system) {
              br = new BufferedReader(new InputStreamReader(system));
          }
       
          public MScanner(String file) throws Exception {
              br = new BufferedReader(new FileReader(file));
          }
       
          public String next() throws IOException {
              while (st == null || !st.hasMoreTokens())
                  st = new StringTokenizer(br.readLine());
              return st.nextToken();
          }
          public int[] intArr(int n) throws IOException {
              int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
              return in;
          }
          public long[] longArr(int n) throws IOException {
              long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
              return in;
          }
          public int[] intSortedArr(int n) throws IOException {
              int[]in=new int[n];for(int i=0;i<n;i++)in[i]=nextInt();
              shuffle(in);
              Arrays.sort(in);
              return in;
          }
          public long[] longSortedArr(int n) throws IOException {
              long[]in=new long[n];for(int i=0;i<n;i++)in[i]=nextLong();
              shuffle(in);
              Arrays.sort(in);
              return in;
          }
          public Integer[] IntegerArr(int n) throws IOException {
              Integer[]in=new Integer[n];for(int i=0;i<n;i++)in[i]=nextInt();
              return in;
          }
          public Long[] LongArr(int n) throws IOException {
              Long[]in=new Long[n];for(int i=0;i<n;i++)in[i]=nextLong();
              return in;
          }
          public String nextLine() throws IOException {
              return br.readLine();
          }
       
          public int nextInt() throws IOException {
              return Integer.parseInt(next());
          }
       
          public double nextDouble() throws IOException {
              return Double.parseDouble(next());
          }
       
          public char nextChar() throws IOException {
              return next().charAt(0);
          }
       
          public long nextLong() throws IOException {
              return Long.parseLong(next());
          }
       
          public boolean ready() throws IOException {
              return br.ready();
          }
       
          public void waitForInput() throws InterruptedException {
              Thread.sleep(3000);
          }
          
      }
      static void shuffle(int[]in) {
          for(int i=0;i<in.length;i++) {
              int idx=(int)(Math.random()*in.length);
              int tmp=in[i];
              in[i]=in[idx];
              in[idx]=tmp;
          }
      }
      static void shuffle(long[]in) {
          for(int i=0;i<in.length;i++) {
              int idx=(int)(Math.random()*in.length);
              long tmp=in[i];
              in[i]=in[idx];
              in[idx]=tmp;
          }
      }
  }