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.*;
  import java.math.BigInteger;
  import java.util.InputMismatchException;
  
  public class Main {
  	static PrintWriter out;
  	static Reader in;
  	public static void main(String[] args) throws IOException {
  		input_output();
  		Main solver = new Main();
  		solver.solve();
  		out.close();
  
  		out.flush();
  	} 
  
  	static long INF = (long)1e18;
  	static int MAXN = (int)1e5 + 5;
  	static int MOD = (int)1e9 + 7;
  	static int q, t, n, m, k;
  	static double pi = Math.PI;
  
  	void solve() throws IOException {
  		n = in.nextInt();
  
  		int[] arr = new int[n];
  		for (int i = 0; i < n; i++) {
  			if (i%2 == 0) arr[i] = in.nextInt();
  			else arr[i] = -in.nextInt();
  		}
  		long[] pre = new long[n];
  		pre[0] = arr[0];
  		for (int i = 1; i < n; i++) pre[i] = arr[i]+pre[i-1];
  
  
  		long ans = 0;
  		for (int i = 1; i < n; i+=2) {
  			for (int j = i-1; j < n; j+= 2) {
  				long sum = 0, min = 0;
  				for (int x = i; x <= j; x++) {
  					sum += arr[x];
  					min = Math.min(min, sum);
  				}
  				
  				if (arr[i-1] + min < 0) continue;
  				else {
  					long pos = arr[i-1]+min,
  						neg = 0;
  					sum += -min;
  					if (j+1 < n) neg = -arr[j+1];
  					else continue;
  
  					//out.println(i+" "+j+", pos: "+pos+", neg: "+neg+", min: "+min+", sum: "+sum);
  
  					if (sum < 0) {
  						long tmp = Math.min(-sum, pos);
  						sum += tmp;
  						pos -= tmp;
  					} else {
  						long tmp = Math.min(sum, neg);
  						sum -= tmp;
  						neg -= tmp;
  					}
  					if (sum != 0) continue;
  					//out.println(1+Math.min(neg, pos));
  					ans += 1+Math.min(neg, pos);
  				}
  			}
  		}
  
  		ans -= n/2;
  		out.println(ans);
  	}
  
  
  	static class Reader {
  		private InputStream mIs;
  		private byte[] buf = new byte[1024];
  		private int curChar;
  		private int numChars;
  
  		public Reader() {
  			this(System.in);
  		}
  
  		public Reader(InputStream is) {
  			mIs = is;
  		}
  
  		public int read() {
  			if (numChars == -1) {
  				throw new InputMismatchException();
  
  			}
  			if (curChar >= numChars) {
  				curChar = 0;
  				try {
  					numChars = mIs.read(buf);
  				} catch (IOException e) {
  					throw new InputMismatchException();
  				}
  				if (numChars <= 0) {
  					return -1;
  				}
  			}
  			return buf[curChar++];
  		}
  
  		public String nextLine() {
  			int c = read();
  			while (isSpaceChar(c)) {
  				c = read();
  			}
  			StringBuilder res = new StringBuilder();
  			do {
  				res.appendCodePoint(c);
  				c = read();
  			} while (!isEndOfLine(c));
  			return res.toString();
  		}
  
  		public String next() {
  			int c = read();
  			while (isSpaceChar(c)) {
  				c = read();
  			}
  			StringBuilder res = new StringBuilder();
  			do {
  				res.appendCodePoint(c);
  				c = read();
  			} while (!isSpaceChar(c));
  			return res.toString();
  		}
  
  		double nextDouble() {
  			return Double.parseDouble(next());
  		}
  
  		public long nextLong() {
  			int c = read();
  			while (isSpaceChar(c)) {
  				c = read();
  			}
  			int sgn = 1;
  			if (c == '-') {
  				sgn = -1;
  				c = read();
  			}
  			long res = 0;
  			do {
  				if (c < '0' || c > '9') {
  					throw new InputMismatchException();
  				}
  				res *= 10;
  				res += c - '0';
  				c = read();
  			} while (!isSpaceChar(c));
  			return res * sgn;
  		}
  
  		public int nextInt() {
  			int c = read();
  			while (isSpaceChar(c)) {
  				c = read();
  			}
  			int sgn = 1;
  			if (c == '-') {
  				sgn = -1;
  				c = read();
  			}
  			int res = 0;
  			do {
  				if (c < '0' || c > '9') {
  					throw new InputMismatchException();
  				}
  				res *= 10;
  				res += c - '0';
  				c = read();
  			} while (!isSpaceChar(c));
  			return res * sgn;
  		}
  
  		public boolean isSpaceChar(int c) {
  			return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
  		}
  
  		public boolean isEndOfLine(int c) {
  			return c == '\n' || c == '\r' || c == -1;
  		}
  
  	}
  	static void input_output() throws IOException {
  		File f = new File("in.txt");
  		if (f.exists() && !f.isDirectory()) {
  			in = new Reader(new FileInputStream("in.txt"));
  		} else in = new Reader();
  		f = new File("out.txt");
  		if (f.exists() && !f.isDirectory()) {
  			out = new PrintWriter(new File("out.txt"));
  		} else out = new PrintWriter(System.out);
  	}
  }