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.BufferedReader;
  import java.io.IOException;
  import java.io.InputStreamReader;
  import java.util.Objects;
  import java.util.StringTokenizer;
  
  public class Codeforces4 {
  	static class Node
      {
          int val;
          Node left;
          Node right;
          public Node(int x) {
              // TODO Auto-generated constructor stub
              this.val=x;
              this.left=null;
              this.right=null;
          }
      }
      static class Pair<U, V> implements Comparable<Pair<U, V>> {
          public U x;
          public V y;
  
          public Pair(U x, V y) {
              this.x = x;
              this.y = y;
          }
  
          public int compareTo(Pair<U, V> o) {
              int value = ((Comparable<U>) x).compareTo(o.x);
              if (value != 0) return value;
              return ((Comparable<V>) y).compareTo(o.y);
          }
  
          public boolean equals(Object o) {
              if (this == o) return true;
              if (o == null || getClass() != o.getClass()) return false;
              Pair<?, ?> pair = (Pair<?, ?>) o;
              return x.equals(pair.x) && y.equals(pair.y);
          }
  
          public int hashCode() {
              return Objects.hash(x, y);
          }
  
      }
      static class FastReader
      {
          BufferedReader br;
          StringTokenizer st;
  
          public FastReader()
          {
              br = new BufferedReader(new
                      InputStreamReader(System.in));
          }
  
          String next()
          {
              while (st == null || !st.hasMoreElements())
              {
                  try
                  {
                      st = new StringTokenizer(br.readLine());
                  }
                  catch (IOException  e)
                  {
                      e.printStackTrace();
                  }
              }
              return st.nextToken();
          }
  
          int nextInt()
          {
              return Integer.parseInt(next());
          }
  
          long nextLong()
          {
              return Long.parseLong(next());
          }
  
          double nextDouble()
          {
              return Double.parseDouble(next());
          }
  
          String nextLine()
          {
              String str = "";
              try
              {
                  str = br.readLine();
              }
              catch (IOException e)
              {
                  e.printStackTrace();
              }
              return str;
          }
          int[] nextArray(int n)
          {
              int arr[]=new int[n];
              for(int i=0;i<n;i++)
                  arr[i]=nextInt();
              return arr;
          }
      }
  	public static void main(String[] args) {
  		// TODO Auto-generated method stub
  		FastReader fs=new FastReader();
  		StringBuilder sb=new StringBuilder();
  //		int T=fs.nextInt();
  //		while(T-->0)
  		{
  			int n=fs.nextInt();
  			int[] arr=fs.nextArray(n);
  			long ans=0;
  			for(int i=0;i<n;i+=2)
  			{
  				long curr=arr[i],extra=0,prev=0;
  				for(int j=i+1;j<n;j+=2)
  				{
  					if(j==i+1)
  					{
  						if(arr[j]>arr[i])
  						{
  							ans+=arr[i];
  							break;
  						}
  						else {
  //							ans+=arr[j];
  							curr-=arr[j];
  						}
  					}
  					else {
  						int val=arr[j]-arr[j-1];
  //						prev++;
  						if(curr+extra-val<0)
  						{
  							curr=0;
  							ans++;
  							break;
  						}
  //						prev++;
  						extra-=val;
  						if(extra<=0)
  						{
  							curr+=extra;
  							ans++;
  							prev=0;
  							extra=0;
  							
  						}
  					}
  				}
  				ans+=arr[i]-curr;
  //				System.out.println(ans+","+curr);
  			}
  			sb.append(ans);
  			sb.append("\n");
  		}
  		System.out.println(sb);
  	}
  
  }
  
  
  
  /*
  18,18
  29,30
  51,19
  80,18
  104,3
  121,30
  156,-1
  197,0
  211,14
  237,26
  254,1
  299,-5
  321,0
  337,0
  343,6
  383,40
  396,0
  409,0
  443,0
  457,14
  508,-2
  557,0
  608,0
  644,0
  654,10
  654
  */
  
  
  /*
  18,18
  23,30
  39,19
  62,18
  80,3
  91,30
  117,3
  158,4
  172,14
  198,26
  211,1
  227,22
  249,3
  265,9
  271,6
  311,40
  324,2
  337,2
  371,20
  385,14
  406,28
  455,17
  506,3
  542,10
  552,10
  552
  */
  