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.io.PrintWriter;
  import java.math.BigInteger;
  import java.util.*;
  
  public class Practice {
  	public static long mod = (long) Math.pow(10, 9) + 7;
  //	public static long mod2 = 998244353;
  //	public static int tt = 1;
  	public static ArrayList<Long> one;
  	public static ArrayList<Long> two;
  //	public static long[] fac = new long[200005];
  //	public static long[] invfac = new long[200005];
  
  	public static void main(String[] args) throws Exception {
  		PrintWriter pw = new PrintWriter(System.out);
  		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  		// int t = Integer.parseInt(br.readLine());
  		// int p = 1;
  		// while (t-- > 0) {
  		String[] s2 = br.readLine().split(" ");
  		int n = Integer.valueOf(s2[0]);
  		long[] arr = new long[n];
  		String str = (br.readLine());
  		String[] s1 = str.split(" ");
  		for (int i = 0; i < n; i++) {
  			arr[i] = Integer.parseInt(s1[i]);
  		}
  		long ans = 0;
  		for (int i = 0; i < n - 1; i += 2) {
  			long min = 0;
  			long o = 0;
  			long curr = 0;
  			for (int j = i + 1; j < n; j += 2) {
  
  				if (j == i + 1) {
  					long mm1 = 1;
  					long mm2 = Math.min(arr[i], arr[i + 1]);
  					ans += mm2 - mm1 + 1;
  					min += Math.max(0, arr[j]);
  					curr = curr - arr[j];
  				} else {
  					long mm1 = Math.max(1, min);
  					long cc = Math.min(arr[i], arr[j] - (curr + arr[j - 1]));
  					if (cc >= mm1) {
  						ans += cc - mm1 + 1;
  					}
  
  					min += Math.max(0, arr[j] - o - arr[j - 1]);
  					o = Math.max(0, o + arr[j - 1] - arr[j]);
  					curr = curr + arr[j - 1] - arr[j];
  				}
  				// System.out.println(ans + " " + min);
  				if (min > arr[i]) {
  					break;
  				}
  
  			}
  
  		}
  		pw.println(ans);
  		// }
  
  		pw.close();
  	}
  
  //
  //	private static long power(long a, long p) {
  //		// TODO Auto-generated method stub
  //		long res = 1;
  //		while (p > 0) {
  //			if (p % 2 == 1) {
  //				res = (res * a) % mod;
  //			}
  //			p = p / 2;
  //			a = (a * a) % mod;
  //		}
  //		return res;
  //	}
  
  // private static int kmp(String str) {
  //		// TODO Auto-generated method stub
  //		// System.out.println(str);
  //		int[] pi = new int[str.length()];
  //		pi[0] = 0;
  //		for (int i = 1; i < str.length(); i++) {
  //			int j = pi[i - 1];
  //			while (j > 0 && str.charAt(i) != str.charAt(j)) {
  //				j = pi[j - 1];
  //			}
  //			if (str.charAt(j) == str.charAt(i)) {
  //				j++;
  //			}
  //			pi[i] = j;
  //			System.out.print(pi[i]);
  //		}
  //		System.out.println();
  //		return pi[str.length() - 1];
  //	}
  
  }
  
  //	private static void getFac(long n, PrintWriter pw) {
  //		// TODO Auto-generated method stub
  //		int a = 0;
  //		while (n % 2 == 0) {
  //			a++;
  //			n = n / 2;
  //		}
  //		if (n == 1) {
  //			a--;
  //		}
  //		for (int i = 3; i <= Math.sqrt(n); i += 2) {
  //			while (n % i == 0) {
  //				n = n / i;
  //				a++;
  //			}
  //		}
  //		if (n > 1) {
  //			a++;
  //		}
  //		if (a % 2 == 0) {
  //			pw.println("Bob");
  //		} else {
  //			pw.println("Alice");
  //		}
  //		//System.out.println(a);
  //		return;
  //	}
  
  //	private static long power(long a, long p) {
  //		// TODO Auto-generated method stub
  //		long res = 1;
  //		while (p > 0) {
  //			if (p % 2 == 1) {
  //				res = (res * a) % mod;
  //			}
  //			p = p / 2;
  //			a = (a * a) % mod;
  //		}
  //		return res;
  //	}
  //
  //	private static void fac() {
  //		fac[0] = 1;
  //		// TODO Auto-generated method stub
  //		for (int i = 1; i < fac.length; i++) {
  //			if (i == 1) {
  //				fac[i] = 1;
  //			} else {
  //				fac[i] = i * fac[i - 1];
  //			}
  //			if (fac[i] > mod) {
  //				fac[i] = fac[i] % mod;
  //			}
  //		}
  //	}
  //
  //	private static int getLower(Long long1, Long[] st) {
  //		// TODO Auto-generated method stub
  //		int left = 0, right = st.length - 1;
  //		int ans = -1;
  //		while (left <= right) {
  //			int mid = (left + right) / 2;
  //			if (st[mid] <= long1) {
  //				ans = mid;
  //				left = mid + 1;
  //			} else {
  //				right = mid - 1;
  //			}
  //		}
  //		return ans;
  //	}
  
  //private static long getGCD(long l, long m) {
  //
  //	long t1 = Math.min(l, m);
  //	long t2 = Math.max(l, m);
  //	if (t1 == 0) {
  //		return t2;
  //	}
  //	while (true) {
  //		long temp = t2 % t1;
  //		if (temp == 0) {
  //			return t1;
  //		}
  //		t2 = t1;
  //		t1 = temp;
  //	}
  //}