Problem:
Score : 400 points

Problem Statement

Snuke has a large collection of cards. Each card has an integer between 1 and N, inclusive, written on it.
He has A_i cards with an integer i.

Two cards can form a pair if the absolute value of the difference of the integers written on them is at most 1.

Snuke wants to create the maximum number of pairs from his cards, on the condition that no card should be used in multiple pairs. Find the maximum number of pairs that he can create.

Constraints

1 ≦ N ≦ 10^5

0 ≦ A_i ≦ 10^9 (1 ≦ i ≦ N)

All input values are integers.

Input

The input is given from Standard Input in the following format:

N
A_1
:
A_N

Output

Print the maximum number of pairs that Snuke can create.

Sample Input 1

4
4
0
3
2

Sample Output 1

4

For example, Snuke can create the following four pairs: (1,1),(1,1),(3,4),(3,4).

Sample Input 2

8
2
0
1
6
0
8
2
1

Sample Output 2

9

Solution in C++14 (GCC 5.4.1) (judge verdict: Wrong Answer)

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <set>
#include <vector>

using namespace std; 

namespace fastinput
{
	/** Interface */

	inline int readChar();
	template <class T = int> inline T readInt();
	template <class T> inline void writeInt(T x, char end = 0);
	inline void writeChar(int x);
	inline void writeWord(const char *s);

	/** Read */

	static const int buf_size = 16384;
	char buf[buf_size];
	int len = 0, pos = 0;

	inline int getChar() {
		if (pos == len)
			pos = 0, len = fread(buf, 1, buf_size, stdin);
		if (pos == len)
			return -1;
		return buf[pos++];
	}

	inline int readChar() {
		int c = getChar();
		while (c <= 32)
			c = getChar();
		return c;
	}

	template <class T>
	inline T readInt() {
		int s = 1, c = readChar();
		T x = 0;
		if (c == '-')
			s = -1, c = getChar();
		while ('0' <= c && c <= '9')
			x = x * 10 + c - '0', c = getChar();
		return s == 1 ? x : -x;
	}

	/** Write */

	static int write_pos = 0;
	static char write_buf[buf_size];

	inline void writeChar(int x) {
		if (write_pos == buf_size)
			fwrite(write_buf, 1, buf_size, stdout), write_pos = 0;
		write_buf[write_pos++] = x;
	}

	inline string readWord()
	{
		string tmp;
		tmp.push_back(readChar());
		char c;
		while ((c = getChar()) > 32)
			tmp.push_back(c);
		--pos;
		return tmp;
	}

	template <class T>
	inline void writeInt(T x, char end) {
		if (x < 0)
			writeChar('-'), x = -x;

		char s[24];
		int n = 0;
		while (x || !n)
			s[n++] = '0' + x % 10, x /= 10;
		while (n--)
			writeChar(s[n]);
		if (end)
			writeChar(end);
	}

	inline void writeWord(const char *s) {
		while (*s)
			writeChar(*s++);
	}

	struct Flusher {
		~Flusher() {
			if (write_pos)
				fwrite(write_buf, 1, write_pos, stdout), write_pos = 0;
		}
	} flusher;
}

const int N = 2e3 + 2;
long long t[N][N];

inline void add(int x1, int y1, int w)
{
	for (; x1 < N; x1 |= x1 + 1)
		for (int j = y1; j < N; j |= j + 1)
			t[x1][j] += w;
}

inline long long sum(int x1, int y1)
{
	long long tmp = 0;
	for (; x1 >= 0; x1 = (x1 & (x1 + 1)) - 1)
		for (int j = y1; j >= 0; j = (j & (j + 1)) - 1)
			tmp += t[x1][j];
	return tmp;
}

using namespace fastinput;

int n;
vector <int> v;

int main() 
{
	n = readInt();
	v.resize(n);
	for (int i = 0; i < n; ++i)
		v[i] = readInt();

	long long res = 0;
	for (int i = 0; i < n - 1; ++i)
	{
		int here = v[i] / 2;
		res += here;
		v[i] -= here * 2;
		here = min(v[i], v[i + 1]);
		res += here;
		v[i] -= here;
		v[i + 1] -= here;
	}
	cout << res << endl;

	return 0;
}