#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double
#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)
#define SIZE(x) int(x.size())
#define F(i,a,n) for(long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long int i=(a);i>=(n);--i)
#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)
#define BINSTR(num) bitset<64>((num)).to_string();
#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
void SO(){cout << endl;}
template<typename S, typename ... Strings>
void SO(S x, const Strings&... rest){cout<<x<<' ';SO(rest...);}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
#define foreach(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())
#define fr first
#define se second
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
/*
#define cin fin
#define cout fout
ifstream fin("input.txt");
ofstream fout("output.txt");
*/
#define inf 2e9;
const long double PI = 3.1415926535897932384626433832795;
const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------
//USE THIS TO DEFINE TYPE EVERYWHERE
#define tp long long int

inline tp ABS(tp a) { if ( a < 0 ) return (-a); return a; }
inline tp min(tp a,tp b,tp c){return min(a,min(b,c));}
inline tp max(tp a,tp b,tp c){return max(a,max(b,c));}
//inline tp powmod(tp x,tp n, tp _mod){tp res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
//inline tp gcd(tp a,tp b){tp t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
//inline tp lcm(tp a,tp b){return (a*b)/(gcd(a,b));}
//inline int bitCount(unsigned int i) { return __builtin_popcount(i); }
inline void AI(tp x[], tp n){for(int i=0; i<(n); ++i)SI(x[i]);}
inline void VI(vector<tp> &arr, tp n){for(int i=0; i<(n); ++i){tp x;SI(x);arr.pb(x);};}
//CODE STARTS HERE-----------------------------------------------------------------------------------------------------------------------------------------------

const int AS = 4000001;

tp n, m,k;
map<char, int> c;
tp a[AS];
map< tp, V(tp) > g;

int main()
{
	FASTER;
	string good, sample;
	SI(good);
	for(int r = 0; r < good.size(); r++)
		c[good[r]] = 1;
	SI(sample);
	int k = sample.size();
	SI(n);
	F(iii,0,n)
	{
		string a;
		SI(a);
		int m = a.size(), i = 0, j = 0, ii = m-1, jj = k-1, ans = 1;
		for(; i < m & j < k and sample[j] != '*'; j++)
		{
			if((sample[j] != '?' and sample[j] != a[i]) or !(PRESENT(c, a[i])))
				ans = 0;
			i++;
		}
		for(; ii >= 0 & jj >= 0 and sample[jj] != '*'; jj--)
		{
			if((sample[jj] != '?' and sample[jj] != a[ii]) or !(PRESENT(c, a[ii])))
				ans = 0;
			ii--;
		}
		for(int l = i; l <= ii; l++)
		{
			if(PRESENT(c, a[l]))
				ans = 0;
		}
		if(ans == 0)
			SO("NO");
		else
			SO("YES");
	}

	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define ull unsigned long long int
#define il long int
#define ill long long int
#define ld long double
#define pi pair<int,int>
#define V(x) vector<x>
#define pb(x) push_back(x)
#define SORT(ls) sort(ls.begin(), ls.end())
#define DESC(ls) sort(ls.rbegin(), ls.rend());
#define mp(x, y) make_pair(x, y)
#define SIZE(x) int(x.size())
#define F(i,a,n) for(long int i=(a); i<(n); ++i)
#define FD(i,a,n) for(long int i=(a);i>=(n);--i)
#define S(x) scanf("%d",&x)
#define P(x) printf("%d\n",x)
#define BINSTR(num) bitset<64>((num)).to_string();
#define SI cin>>
#define DI(x, y) cin>>x>>y
#define TI(x, y, z) cin>>x>>y>>z
#define tr(...) cout<<__FUNCTION__<<' '<<__LINE__<<" = ";trace(#__VA_ARGS__, __VA_ARGS__)
void SO(){cout << endl;}
template<typename S, typename ... Strings>
void SO(S x, const Strings&... rest){cout<<x<<' ';SO(rest...);}
template<typename T>
void trace(const char* name, T&& arg1){cout<<name<<" : "<<arg1<<endl;}
template<typename T, typename... Args>
void trace(const char* names, T&& arg1, Args&&... args){
const char* comma = strchr(names + 1, ',');cout.write(names, comma-names)<<" : "<<arg1<<" | ";trace(comma+1,args...);}
#define foreach(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
#define ALL(c) c.begin(), c.end()
#define PRESENT(container, x) container.find(x) != container.end()
#define VPRESENT(container, element) (find(ALL(container),element) != container.end())
#define fr first
#define se second
#define FASTER ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
/*
#define cin fin
#define cout fout
ifstream fin("input.txt");
ofstream fout("output.txt");
*/
#define inf 2e9;
const long double PI = 3.1415926535897932384626433832795;
const int v5 = 100000; //  (10**5)
const int v9 = 1000000000; //  (10**9)
const int v6 = 1000000; //  (10**6)
//----------------------------------------------------------------------------------------------------------------------------------------------------------------------
//USE THIS TO DEFINE TYPE EVERYWHERE
#define tp long long int

inline tp ABS(tp a) { if ( a < 0 ) return (-a); return a; }
inline tp min(tp a,tp b,tp c){return min(a,min(b,c));}
inline tp max(tp a,tp b,tp c){return max(a,max(b,c));}
//inline tp powmod(tp x,tp n, tp _mod){tp res=1;while(n){if(n&1)res=(res*x)%_mod;x=(x*x)%_mod;n>>=1;}return res;}
//inline tp gcd(tp a,tp b){tp t;while(b){a=a%b;t=a;a=b;b=t;}return a;}
//inline tp lcm(tp a,tp b){return (a*b)/(gcd(a,b));}
//inline int bitCount(unsigned int i) { return __builtin_popcount(i); }
inline void AI(tp x[], tp n){for(int i=0; i<(n); ++i)SI(x[i]);}
inline void VI(vector<tp> &arr, tp n){for(int i=0; i<(n); ++i){tp x;SI(x);arr.pb(x);};}
//CODE STARTS HERE-----------------------------------------------------------------------------------------------------------------------------------------------

const int AS = 4000001;

tp n, m,k;
map<char, int> c;
tp a[AS];
map< tp, V(tp) > g;

int main()
{
	FASTER;
	string good, sample;
	SI(good);
	for(int r = 0; r < good.size(); r++)
		c[good[r]] = 1;
	SI(sample);
	int k = sample.size();
	SI(n);
	F(iii,0,n)
	{
		string a;
		SI(a);
		int m = a.size(), i = 0, j = 0, ii = m-1, jj = k-1, ans = 1;
		for(; i < m & j < k and sample[j] != '*'; j++)
		{
			if((sample[j] != '?' and sample[j] != a[i]) or (sample[j] == '?' and !(PRESENT(c, a[i]))))
				ans = 0;
			i++;
		}
		for(; ii >= 0 & jj >= 0 and sample[jj] != '*'; jj--)
		{
			if((sample[jj] != '?' and sample[jj] != a[ii]) or (sample[j] == '?' and !(PRESENT(c, a[ii]))))
				ans = 0;
			ii--;
		}
		for(int l = i; l <= ii; l++)
		{
			if(PRESENT(c, a[l]))
				ans = 0;
		}
		if(ans == 0)
			SO("NO");
		else
			SO("YES");
	}

	return 0;
}


// B
#include <bits/stdc++.h>

#define SQ(a) (a)*(a)

#define F0R(i, a) for(int i = 0; i < (a); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define R0F(i, a) for(int i = (a) - 1; i >= 0; i--)
#define ROF(i, a, b) for(int i = (b) - 1; i >= (a); i--)

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define UB upper_bound
#define LB lower_bound
#define X real()
#define Y imag()
#define MAXN 100000

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<ll> point;

bool good[26], foundStar;
string pattern, goodCharacters, queries[MAXN];
int beforeStar, afterStar, q;

bool possible(string query, int l, int starCover) {
    if(starCover < 0 || (starCover > 0 && !foundStar)) return false;
    F0R(j, beforeStar) {
        if(pattern[j] == '?' && !good[(int)(query[j] - 'a')]) return false;
        if(pattern[j] != '?' && query[j] != pattern[j]) return false;
    }
    F0R(j, starCover) {
        if(good[(int)(query[beforeStar + j] - 'a')]) return false;
    }
    F0R(j, afterStar) {
        if(pattern[1 + beforeStar + j] == '?' && !good[(int)(query[beforeStar + starCover + j] - 'a')]) return false;
        if(pattern[1 + beforeStar + j] != '?' && query[beforeStar + starCover + j] != pattern[1 + beforeStar + j]) return false;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> goodCharacters;
    F0R(i, goodCharacters.length()) good[goodCharacters[i] - 'a'] = true;
    cin >> pattern;
    F0R(i, pattern.length()) {
        if(pattern[i] == '*') {
            foundStar = true;
        } else {
            if(!foundStar) beforeStar++;
            else afterStar++;
        }
    }
    cin >> q;
    F0R(i, q) cin >> queries[i];
    F0R(i, q) {
        int l = queries[i].length();
        int starCover = l - beforeStar - afterStar;
        if(possible(queries[i], l, starCover)) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}


// B
#include <bits/stdc++.h>

#define SQ(a) (a)*(a)

#define F0R(i, a) for(int i = 0; i < (a); i++)
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define R0F(i, a) for(int i = (a) - 1; i >= 0; i--)
#define ROF(i, a, b) for(int i = (b) - 1; i >= (a); i--)

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple
#define UB upper_bound
#define LB lower_bound
#define X real()
#define Y imag()
#define MAXN 100000

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<ll> point;

bool good[26], foundStar;
string pattern, goodCharacters, queries[MAXN];
int beforeStar, afterStar, q;

bool possible(string query, int l, int starCover) {
    F0R(j, beforeStar) {
        if(pattern[j] == '?' && !good[(int)(query[j] - 'a')]) return false;
        if(pattern[j] != '?' && query[j] != pattern[j]) return false;
    }
    F0R(j, starCover) {
        if(good[(int)(query[beforeStar + j] - 'a')]) return false;
    }
    F0R(j, afterStar) {
        if(pattern[1 + beforeStar + j] == '?' && !good[(int)(query[beforeStar + starCover + j] - 'a')]) return false;
        if(pattern[1 + beforeStar + j] != '?' && query[beforeStar + starCover + j] != pattern[1 + beforeStar + j]) return false;
    }
    return true;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cin >> goodCharacters;
    F0R(i, goodCharacters.length()) good[goodCharacters[i] - 'a'] = true;
    cin >> pattern;
    F0R(i, pattern.length()) {
        if(pattern[i] == '*') {
            foundStar = true;
        } else {
            if(!foundStar) beforeStar++;
            else afterStar++;
        }
    }
    cin >> q;
    F0R(i, q) cin >> queries[i];
    F0R(i, q) {
        int l = queries[i].length();
        int starCover;
        if(!foundStar) starCover = 0;
        else starCover = l - beforeStar - afterStar;
        if(!(starCover > 0 && l > pattern.length()) && possible(queries[i], l, starCover)) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}


#include <bits/stdc++.h>

#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
#define mod 1000000007
#define random_jbt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;

int main(){
    int n,a[300100];
    ll ans=0;
    cin>>n;
    for (int i=0;i<n;i++){
        cin>>a[i];
    }
    int ind=0;
    for (int i=0;i<n;i++){
        while(ind<i and a[ind]==0)ind++;
        if (ind!=i){
            int ad=min(a[i]/2,a[ind]);
            ans+=ad;
            a[ind]-=ad;
            a[i]-=2*ad;
        }
        ans+=a[i]/3;
        a[i]%=3;
    }
    cout<<ans;
    return 0;
}


//     nohomo    //
//  Brankonymous //
//     nohomo    //

#include <bits/stdc++.h>

#define ios ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define rep(i,l,r) for (int i=l;i<=r;i++)
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define ll long long
#define mod 1000000007
#define random_jbt mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

using namespace std;

ll n;
ll ans=0,a[300100];
int main(){
    ios;
    cin>>n;
    for (ll i=0;i<n;i++){
        cin>>a[i];
        ans+=a[i]/3;
        a[i]%=3;
    }
    ll ind=0;
    for (ll i=1;i<n;i++){
        while(a[ind]==0)ind++;
        if (ind>=i)continue;
        if (a[i]==2){
            a[i]=0;
            a[ind]--;
            ans++;
        }
    }
    ind=0;
    for (ll i=1;i<n;i++){
        while(a[ind]==0)ind++;
        if (ind>=i)continue;
        if (a[i]==2){
            a[i]=0;
            a[ind]--;
            ans++;
        }
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define N 3000001
#define INF 1000000000000009
#define MOD 1000000007
typedef long long ll;
#define lli long long int
#define sd(x) scanf("%d", &x)
#define sd2(x, y) scanf("%d%d", &x, &y)
#define sd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define pf(x) printf("%d ", x);
#define pf2(x, y) printf("%d %d\n", x, y);
#define p3(x, y, z) printf("%d %d %d\n", x, y, z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define _                                                                      \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define tr(x) cout << x << endl;
#define tr2(x, y) cout << x << " " << y << " " << endl;
#define tr3(x, y, z) cout << x << " " << y << " " << z << endl;
#define tr4(x, y, z, a)                                                        \
  cout << x << " " << y << " " << z << " " << a << " " << endl;
#define sz(x) (int)x.size()
const int inf = 1e9;
int main() {
  _ int n, x;
  cin >> n;
  vector<lli> v;
  for (int i = 0; i < n; i++) {
    cin >> x;
    v.pb(x);
  }
  int ans = 0, unmatch = 0;
  for (lli i = 0; i < v.size(); i++) {
    ans += (v[i] / 3);
    int x = v[i] % 3;
    if (unmatch > 0) {
      ans += min(unmatch, x / 2);
      if (x / 2 >= unmatch) {
        unmatch = x / 2 - unmatch;
        unmatch += (x % 2);
      } else {
        unmatch -= x / 2;
        unmatch += (x % 2);
      }
    } else {
      unmatch = x;
    }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define N 3000001
#define INF 1000000000000009
#define MOD 1000000007
typedef long long ll;
#define lli long long int
#define sd(x) scanf("%d", &x)
#define sd2(x, y) scanf("%d%d", &x, &y)
#define sd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define pf(x) printf("%d ", x);
#define pf2(x, y) printf("%d %d\n", x, y);
#define p3(x, y, z) printf("%d %d %d\n", x, y, z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define _                                                                      \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define tr(x) cout << x << endl;
#define tr2(x, y) cout << x << " " << y << " " << endl;
#define tr3(x, y, z) cout << x << " " << y << " " << z << endl;
#define tr4(x, y, z, a)                                                        \
  cout << x << " " << y << " " << z << " " << a << " " << endl;
#define sz(x) (lli) x.size()
// const lli inf = 1e9;
int main() {
  _ lli n, x;
  cin >> n;
  vector<lli> v;
  for (lli i = 0; i < n; i++) {
    cin >> x;
    v.pb(x);
  }
  lli ans = 0, unmatch = 0;
  for (lli i = 0; i < v.size(); i++) {
    ans += (v[i] / 3);
    lli x = v[i] % 3;
    if (unmatch > 0) {
      ans += min(unmatch, x / 2);
      if (x / 2 >= unmatch) {
        unmatch = x / 2 - unmatch;
        unmatch += (x % 2);
      } else {
        unmatch -= x / 2;
        unmatch += (x % 2);
      }
    } else {
      unmatch = x;
    }
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define N 3000001
#define INF 1000000000000009
#define MOD 1000000007
typedef long long ll;
#define lli long long int
#define sd(x) scanf("%d", &x)
#define sd2(x, y) scanf("%d%d", &x, &y)
#define sd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define pf(x) printf("%d ", x);
#define pf2(x, y) printf("%d %d\n", x, y);
#define p3(x, y, z) printf("%d %d %d\n", x, y, z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define _                                                                      \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define tr(x) cout << x << endl;
#define tr2(x, y) cout << x << " " << y << " " << endl;
#define tr3(x, y, z) cout << x << " " << y << " " << z << endl;
#define tr4(x, y, z, a)                                                        \
  cout << x << " " << y << " " << z << " " << a << " " << endl;
#define sz(x) (lli) x.size()
// const lli inf = 1e9;
int main() {
  _ lli n, x;
  cin >> n;
  vector<lli> v;
  for (lli i = 0; i < n; i++) {
    cin >> x;
    v.pb(x);
  }
  // lli ans = 0, unmatch = 0;
  // for (lli i = 0; i < v.size(); i++) {
  //   lli p = min(unmatch, x / 2LL);
  //   ans += p;
  //   unmatch -= p;
  //   v[i] -= 2 * p;
  //   ans += v[i] / 3LL;
  //   unmatch += (v[i] % 3);
  // }
  ll ans = 0;
  ll cur = 0;
  for (ll i : v) {
    ll cnt = min(i / 2LL, cur);
    ans += cnt;
    cur -= cnt;
    i -= 2LL * cnt;
    ans += i / 3LL;
    cur += i % 3;
  }
  cout << ans << endl;
  // cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define N 3000001
#define INF 1000000000000009
#define MOD 1000000007
typedef long long ll;
#define lli long long int
#define sd(x) scanf("%d", &x)
#define sd2(x, y) scanf("%d%d", &x, &y)
#define sd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define pf(x) printf("%d ", x);
#define pf2(x, y) printf("%d %d\n", x, y);
#define p3(x, y, z) printf("%d %d %d\n", x, y, z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define _                                                                      \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define tr(x) cout << x << endl;
#define tr2(x, y) cout << x << " " << y << " " << endl;
#define tr3(x, y, z) cout << x << " " << y << " " << z << endl;
#define tr4(x, y, z, a)                                                        \
  cout << x << " " << y << " " << z << " " << a << " " << endl;
#define sz(x) (lli) x.size()
// const lli inf = 1e9;
int main() {
  _ lli n, x;
  cin >> n;
  vector<lli> v;
  for (lli i = 0; i < n; i++) {
    cin >> x;
    v.pb(x);
  }
  lli ans = 0, unmatch = 0;
  for (lli i = 0; i < v.size(); i++) {
    lli p = min(unmatch, x / 2LL);
    ans += p;
    unmatch -= p;
    v[i] -= 2 * p;
    ans += v[i] / 3LL;
    unmatch += (v[i] % 3);
  }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define N 3000001
#define INF 1000000000000009
#define MOD 1000000007
typedef long long ll;
#define lli long long int
#define sd(x) scanf("%d", &x)
#define sd2(x, y) scanf("%d%d", &x, &y)
#define sd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define pf(x) printf("%d ", x);
#define pf2(x, y) printf("%d %d\n", x, y);
#define p3(x, y, z) printf("%d %d %d\n", x, y, z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define _                                                                      \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define tr(x) cout << x << endl;
#define tr2(x, y) cout << x << " " << y << " " << endl;
#define tr3(x, y, z) cout << x << " " << y << " " << z << endl;
#define tr4(x, y, z, a)                                                        \
  cout << x << " " << y << " " << z << " " << a << " " << endl;
#define sz(x) (lli) x.size()
// const lli inf = 1e9;
int main() {
  _ lli n, x;
  cin >> n;
  vector<lli> v;
  for (lli i = 0; i < n; i++) {
    cin >> x;
    v.pb(x);
  }
  lli ans = 0, unmatch = 0;
  for (lli i = 0; i < v.size(); i++) {
    lli p = min(unmatch, x / 2);
    ans += p;
    unmatch -= p;
    v[i] -= 2 * p;
    ans += v[i] / 3;
    v[i] %= 3;
    unmatch += v[i];
  }
  // ans += (v[i] / 3);
  // lli x = v[i] % 3;
  //   if (unmatch > 0) {
  //     ans += min(unmatch, x / 2);
  //     if (x / 2 >= unmatch) {
  //       unmatch = x / 2 - unmatch;
  //       unmatch += (x % 2);
  //     } else {
  //       unmatch -= x / 2;
  //       unmatch += (x % 2);
  //     }
  //   } else {
  //     unmatch = x;
  //   }
  // }
  cout << ans << endl;
}


#include <bits/stdc++.h>
using namespace std;
#define N 3000001
#define INF 1000000000000009
#define MOD 1000000007
typedef long long ll;
#define lli long long int
#define sd(x) scanf("%d", &x)
#define sd2(x, y) scanf("%d%d", &x, &y)
#define sd3(x, y, z) scanf("%d%d%d", &x, &y, &z)
#define pf(x) printf("%d ", x);
#define pf2(x, y) printf("%d %d\n", x, y);
#define p3(x, y, z) printf("%d %d %d\n", x, y, z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x, y) make_pair(x, y)
#define _                                                                      \
  ios_base::sync_with_stdio(false);                                            \
  cin.tie(NULL);                                                               \
  cout.tie(NULL);
#define tr(x) cout << x << endl;
#define tr2(x, y) cout << x << " " << y << " " << endl;
#define tr3(x, y, z) cout << x << " " << y << " " << z << endl;
#define tr4(x, y, z, a)                                                        \
  cout << x << " " << y << " " << z << " " << a << " " << endl;
#define sz(x) (lli) x.size()
// const lli inf = 1e9;
int main() {
  _ lli n, x;
  cin >> n;
  vector<lli> v;
  for (lli i = 0; i < n; i++) {
    cin >> x;
    v.pb(x);
  }
  lli ans = 0, unmatch = 0;
  for (lli i = 0; i < v.size(); i++) {
    lli p = min(unmatch, v[i] / 2LL);
    ans += p;
    unmatch -= p;
    v[i] -= 2 * p;
    ans += v[i] / 3LL;
    unmatch += (v[i] % 3);
  }

  cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
//#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll >
#define aesds
#define mod  1000000007
#define N 505
#define mod1 1000000007
#define mod2 1000000009
#define bitcnt __builtin_popcount
#define PI acos(-1)
#define endl "\n"
#define mid  (l+r)/2
//const int inf = (int)1e18 + 10;

signed  main(){
  fast;
 // freopen("input.txt" , "r" , stdin);
  //freopen("output.txt" , "w" , stdout);

     int n , ans = 0 , p = 0 , x , c = 0;
     cin>>n;
     for(int i =  0 ; i <n ; i++){
     	cin>>x;
     	p +=(x/2);
     	c += (x%2);
     	while(c > 0 && p > 0)
     	  p-- , ans++ , c--;
	 }
	 ans += (2*p/3);
	 cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
//#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll >
#define aesds
#define mod  1000000007
#define N 300005
#define mod1 1000000007
#define mod2 1000000009
#define bitcnt __builtin_popcount
#define PI acos(-1)
#define endl "\n"
#define mid  (l+r)/2
//const int inf = (int)1e18 + 10;
int a[N];
signed  main(){
  fast;
  //freopen("input.txt" , "r" , stdin);
  //freopen("output.txt" , "w" , stdout);

     ll n , ans = 0 , p = 0 , x , c = 0;
     cin>>n;
     for(int i =  0 ; i <n ; i++)
     cin>>a[i];
      for(int i = n-1 ; i>= 0 ; i--){
     	p +=(a[i]/2);
     	c = a[i]%2;
     	while(c  == 1 && p > 0)
     	  p-- , ans++;
	 }
	 ans += (2*p/3);
	 cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
//#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll >
#define aesds
#define mod  1000000007
#define N 300005
#define mod1 1000000007
#define mod2 1000000009
#define bitcnt __builtin_popcount
#define PI acos(-1)
#define endl "\n"
#define mid  (l+r)/2
//const int inf = (int)1e18 + 10;
int a[N];
signed  main(){
  fast;
 // freopen("input.txt" , "r" , stdin);
  //freopen("output.txt" , "w" , stdout);

     ll n , ans = 0 , p = 0 , x , c = 0;
     cin>>n;
     for(int i =  0 ; i <n ; i++)
     cin>>a[i];
      for(int i = n-1 ; i>= 0 ; i--){
     	p +=(a[i]/2);
     	if(a[i] %2 == 1 && p > 0)
     	  p-- , ans++;
	 }
	 ans += (2*p/3);
	 cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
//#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll >
#define aesds
#define mod  1000000007
#define N 505
#define mod1 1000000007
#define mod2 1000000009
#define bitcnt __builtin_popcount
#define PI acos(-1)
#define endl "\n"
#define mid  (l+r)/2
//const int inf = (int)1e18 + 10;

signed  main(){
  fast;
  //freopen("input.txt" , "r" , stdin);
  //freopen("output.txt" , "w" , stdout);

     int n , ans = 0 , p = 0 , x;
     cin>>n;
     for(int i =  0 ; i <n ; i++){
     	cin>>x;
     	p +=(x/2);
     	if(x%2 == 1)
     	  p-- , ans++;
	 }
	 ans += 2*(p/3);
	 cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
//#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll >
#define aesds
#define mod  1000000007
#define N 505
#define mod1 1000000007
#define mod2 1000000009
#define bitcnt __builtin_popcount
#define PI acos(-1)
#define endl "\n"
#define mid  (l+r)/2
//const int inf = (int)1e18 + 10;

signed  main(){
  fast;
  //freopen("input.txt" , "r" , stdin);
  //freopen("output.txt" , "w" , stdout);

     int n , ans = 0 , p = 0 , x;
     cin>>n;
     for(int i =  0 ; i <n ; i++){
     	cin>>x;
     	p +=(x/2);
     	if(x%2 == 1 && p > 0)
     	  p-- , ans++;
	 }
	 ans += 2*p/3;
	 cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define ll long long int
//#define int ll
//#define slld(t) scanf("%lld",&t)
//#define sd(t) scanf("%d",&t)
//#define pd(t) printf("%d\n",t)
//#define plld(t) printf("%lld\n",t)
#define vec vector < int >
#define vecp vector < pair < int , int > >
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define debug(x)   cerr<<#x<<": "<<x<<endl
#define pii pair < int , int >
#define pll pair < ll , ll >
#define aesds
#define mod  1000000007
#define N 505
#define mod1 1000000007
#define mod2 1000000009
#define bitcnt __builtin_popcount
#define PI acos(-1)
#define endl "\n"
#define mid  (l+r)/2
//const int inf = (int)1e18 + 10;

signed  main(){
  fast;
 // freopen("input.txt" , "r" , stdin);
  //freopen("output.txt" , "w" , stdout);

     ll n , ans = 0 , p = 0 , x , c = 0;
     cin>>n;
     for(int i =  0 ; i <n ; i++){
     	cin>>x;
     	p +=(x/2);
     	c += (x%2);
     	while(c > 0 && p > 0)
     	  p-- , ans++ , c--;
	 }
	 ans += (2*p/3);
	 cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    long long a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    long long pair=0;
    long long single=0;
    for(i=n-1;i>=0;i--)
    {
        pair+=(a[i]/2);
        if(a[i]%2!=0 && pair>0)
        {
            pair--;
            single++;
        }
    }
    cout<<single+(pair*2)/3;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    long long a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    long long pair=0;
    long long single=0;
    for(i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            pair+=(a[i]/2);
        }
        else
        {
            single++;
            pair+=(a[i]/2);
        }
    }
    pair-=single;
    if(pair<0)
    {
        cout<<"0";
        return 0;
    }
    cout<<single+(pair*2)/3;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    long long a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    long long pair=0;
    long long single=0;
    for(i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            pair+=(a[i]/2);
        }
        else
        {
            single++;
            pair+=(a[i]/2);
        }
    }
    long long count=0;
    while(single!=0)
    {
        if(pair>0)
        {
            pair-=1;
            count++;
        }
        else
        {
            cout<<count<<endl;
            return 0;
        }
    }
    if(pair<0)
    {
        cout<<"0";
        return 0;
    }
    cout<<count+(pair*2)/3;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    long long a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    long long pair=0;
    long long single=0;
    for(i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            pair+=(a[i]/2);
        }
        else
        {
            single++;
            pair+=(a[i]/2);
        }
    }
    long long count=0;
    while(single!=0)
    {
        if(pair>0)
        {
            pair-=1;
            count++;
        }
        else
        {
            cout<<count<<endl;
            return 0;
        }
        single--;
    }
    if(pair<0)
    {
        cout<<"0";
        return 0;
    }
    cout<<single+(pair*2)/3;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    long long a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    long long pair=0;
    long long single=0;
    for(i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            pair+=(a[i]/2);
        }
        else
        {
            single++;
            pair+=(a[i]/2);
        }
    }
    long long count=0;
    while(single!=0)
    {
        if(pair>0)
        {
            pair-=1;
            count++;
        }
        else
        {
            cout<<count<<endl;
            return 0;
        }
        single--;
    }
    if(pair<0)
    {
        cout<<"0";
        return 0;
    }
    cout<<count+(pair*2)/3;
}


#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,i;
    cin>>n;
    long long a[n];
    for(i=0;i<n;i++)
    {
        cin>>a[i];
    }
    long long pair=0;
    long long single=0;
    for(i=0;i<n;i++)
    {
        if(a[i]%2==0)
        {
            pair+=(a[i]/2);
        }
        else
        {
            single++;
            pair+=(a[i]/2);
        }
    }
    long long count=0;
    while(single!=0)
    {
        if(pair>0)
        {
            pair-=1;
            count++;
        }
        else
        {
            cout<<count<<endl;
            return 0;
        }
    }
    if(pair<0)
    {
        cout<<"0";
        return 0;
    }
    cout<<single+(pair*2)/3;
}


// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 300005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define pi 3.1415926535897
#define noop

int main() {

    get(n);

    vector<pll> C,B;
    rep(i,n) {
        get(a);
        if(a==1)
            B.pb({1,i});
        else
            C.pb({a,i});
    }

    if(!C.size()) {
        printf("0\n");
        return 0;
    }

    ll i=0, j=C.size()-1; ll res = 0;
    ll curr = B.size()-1;

    if(B.size()>0)
    while(j>=0 && curr>=0) {

        if(C[j].se<B[curr].se) {
            curr--;
            continue;
        }

        if(C[j].fi%2) {
            res += 1;
            C[j].fi -= 3;
        }

        if(C[j].fi>=2) {
            C[j].fi -= 2;
            res += 1;
            curr--;
        }

        if(C[j].fi==0)
            j--;
    }

    while(i<j) {
        if(C[j].fi<=1) {
            j--;
            continue;
        }

        if(C[j].fi%2) {
            res += 1;
            C[j].fi -= 3;
        }

        ll quot = C[j].fi/2;
        if(C[i].fi>quot) {
            res += quot;
            C[i].fi -= quot;
            C[j].fi -= 2*quot;
        }
        else {
            res += C[i].fi;
            C[j].fi -= 2*C[i].fi;
            i++;

        }

        if(C[j].fi==0)
            j--;
    }

    if(C[i].fi>0)
        res += C[i].fi/3;
    printf("%lld\n", res);

    return 0;
}


// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 300005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define pi 3.1415926535897
#define noop

int main() {

    get(n);
    fill_nums(A,n);

    ll i=0, j=n-1; ll res = 0;
    while(i<j) {
        res += A[j]/3;
        A[j] %= 3;

        if(A[j]==2) {
            A[i]--;
            A[j]=0;
            res += 1;
        }

        if(A[i]==0)
            i++;
        if(A[j]<2)
            j--;
    }

    if(A[i]>0)
        res += A[i]/3;
    printf("%lld\n", res);

    return 0;
}


// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 300005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define pi 3.1415926535897
#define noop

int main() {

    get(n);
    fill_nums(A,n);

    ll i=0, j=n-1; ll res = 0;
    while(i<j) {
        if(A[j]==1) {
            j--;
            continue;
        }

        if(A[j]%2) {
            res += 1;
            A[j] -= 3;
        }

        ll quot = A[j]/2;
        if(A[i]>quot) {
            res += quot;
            A[i] -= quot;
            j--;
        }
        else {
            res += A[i];
            A[j] -= 2*A[i];
            i++;

        }

        if(A[j]==0)
            j--;
    }

    if(A[i]>0)
        res += A[i]/3;
    printf("%lld\n", res);

    return 0;
}


// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 300005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define pi 3.1415926535897
#define noop

int main() {

    get(n);

    vector<pll> C,B;
    rep(i,n) {
        get(a);
        if(a==1)
            B.pb({1,i});
        else
            C.pb({a,i});
    }

    if(!C.size()) {
        printf("0\n");
        return 0;
    }

    ll i=0, j=C.size()-1; ll res = 0;
    ll curr = B.size()-1;

    while(j>=0 && curr>=0) {

        if(C[j].se<B[curr].se) {
            curr--;
            continue;
        }

        if(C[j].fi%2) {
            res += 1;
            C[j].fi -= 3;
        }

        if(C[j].fi>=2) {
            C[j].fi -= 2;
            res += 1;
            curr--;
        }

        if(C[j].fi==0)
            j--;
    }

    while(i<j) {
        if(C[j].fi<=1) {
            j--;
            continue;
        }

        if(C[j].fi%2) {
            res += 1;
            C[j].fi -= 3;
        }

        ll quot = C[j].fi/2;
        if(C[i].fi>quot) {
            res += quot;
            C[i].fi -= quot;
            C[j].fi -= 2*quot;
        }
        else {
            res += C[i].fi;
            C[j].fi -= 2*C[i].fi;
            i++;

        }

        if(C[j].fi==0)
            j--;
    }

    if(C[i].fi>0)
        res += C[i].fi/3;
    printf("%lld\n", res);

    return 0;
}


// #pragma GCC optimize("O3")
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define N 1000000007
#define N2 998244353
#define Nmax 300005
#define INF (ll)1e18
#define pll pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define vv vector
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(ll i=m;i<(n);i++)
#define repr(i,n) repr2(i,n,0)
#define repr2(i,m,n) for(ll i=m;i>=(n);i--)
#define get(n) ll (n); scanf("%lld",&(n));
#define get2(n,k) ll (n),(k); scanf("%lld%lld",&(n),&(k));
#define get3(n,m,k) ll (n),(m),(k); scanf("%lld%lld%lld",&(n),&(m),&(k));
#define gets(s) string (s); cin >> (s);
#define ALL(c) (c).begin(),(c).end()
#define fill_nums(A,n) vector<ll> A((n)); for(ll i=0;i<n;i++) scanf("%lld",&A[i]);
#define fill_edges(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1); adj[b-1].pb(a-1);}
#define fill_direct(adj,m) for(ll i=0;i<m;i++) {ll a, b; scanf("%lld %lld",&a,&b); adj[a-1].pb(b-1);}
#define pi 3.1415926535897
#define noop

int main() {

    get(n);
    fill_nums(A,n);

    ll i=0, j=n-1; ll res = 0;
    while(i<j) {
        if(A[j]==1) {
            j--;
            continue;
        }

        if(A[j]%2) {
            res += 1;
            A[j] -= 3;
        }

        ll quot = A[j]/2;
        if(A[i]>quot) {
            res += quot;
            A[i] -= quot;
            A[j] -= 2*quot;
        }
        else {
            res += A[i];
            A[j] -= 2*A[i];
            i++;

        }

        if(A[j]==0)
            j--;
    }

    if(A[i]>0)
        res += A[i]/3;
    printf("%lld\n", res);

    return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define N 300010
using namespace std;
ll a[N],ans,t;
int main()
{
	int n,i;cin>>n;
	for (i=1;i<=n;i++) cin>>a[i];
	for (i=1;i<=n;i++){t+=a[i]/2;if (a[i]&1 && t>0) ans++,t--;}
	ans+=t*2/3;cout<<ans;
}


#include<bits/stdc++.h>
#define ll long long
#define N 300010
using namespace std;
ll a[N],ans,t;
int main()
{
	int n,i;cin>>n;
	for (i=1;i<=n;i++) cin>>a[i];
	for (i=n;i;i--){t+=a[i]/2;if (a[i]&1 && t>0) ans++,t--;}
	ans+=t*2/3;cout<<ans;
}


#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
#define el putchar('\n')
#define ta putchar('	')
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
//	sprintf(str,"%s.out",s);
//	freopen(str,"w",stdout);
	#endif
}
inline int rd()
{
	static int x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return f>0?x:-x;
}
const int N=300010;
priority_queue<int>q;
int n,a[N];
bool b[N];
ll ans=0;

int main()
{
	n=rd();fo(i,1,n)a[i]=rd();
	of(i,n,1){
		if(a[i]==1){
			b[i]=1;
			if(q.empty())continue;
			int x=q.top();q.pop();
			x-=2;if(x>=2)q.push(x);
			++ans;
		}
		else if(a[i]!=3) q.push(a[i]);
	}
	ll res=0;
	while(!q.empty())res+=q.top(),q.pop();
	ans+=res/3;
	printf("%lld\n",ans);
	return 0;
}


#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
#define el putchar('\n')
#define ta putchar('	')
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
//	sprintf(str,"%s.out",s);
//	freopen(str,"w",stdout);
	#endif
}
inline int rd()
{
	static int x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return f>0?x:-x;
}
const int N=300010;
priority_queue<int>q;
int n,a[N];
bool b[N];
ll ans=0;

int main()
{
	n=rd();fo(i,1,n)a[i]=rd();
	of(i,n,1){
		if(a[i]==1){
			b[i]=1;
			if(q.empty())continue;
			int x=q.top();q.pop();
			x-=2;if(x>=2)q.push(x);
			++ans;
		}
		else q.push(a[i]);
	}
	ll res=0;
	while(!q.empty())res+=q.top(),q.pop();
	ans+=res/3;
	printf("%lld\n",ans);
	return 0;
}


#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
#define el putchar('\n')
#define ta putchar('	')
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
//	sprintf(str,"%s.out",s);
//	freopen(str,"w",stdout);
	#endif
}
inline int rd()
{
	static int x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return f>0?x:-x;
}
const int N=300010;
priority_queue<int>q;
int n,a[N];
bool b[N];
ll ans=0;

int main()
{
	n=rd();fo(i,1,n)a[i]=rd();
	of(i,n,1){
		if(a[i]==1){
			b[i]=1;
			if(q.empty())continue;
			int x=q.top();q.pop();
			x-=2;if(x!=3&&x)q.push(x);
			++ans;
		}
		else if(a[i]!=3) q.push(a[i]);
	}
	ll res=0;
	while(!q.empty())res+=bool(q.top()!=1)*q.top(),q.pop();
	ans+=res/3;
	printf("%lld\n",ans);
	return 0;
}


#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
#define el putchar('\n')
#define ta putchar('	')
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
//	sprintf(str,"%s.out",s);
//	freopen(str,"w",stdout);
	#endif
}
inline int rd()
{
	static int x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return f>0?x:-x;
}
const int N=300010;
priority_queue<int>q;
int n,a[N];
bool b[N];
ll ans=0;

int main()
{ll res=0;
	n=rd();fo(i,1,n)a[i]=rd();
	of(i,n,1){
		if(a[i]==1){
			b[i]=1;
			if(q.empty())continue;
			int x=q.top();q.pop();
			x-=2;if(x!=3&&x)q.push(x);
      if(x==3)res+=3;
			++ans;
		}
		else if(a[i]!=3) q.push(a[i]);
    else if(a[i]==3)res+=3;
	}
	while(!q.empty())res+=bool(q.top()!=1)*q.top(),q.pop();
	ans+=res/3;
	printf("%lld\n",ans);
	return 0;
}


#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
#define el putchar('\n')
#define ta putchar('	')
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
//	sprintf(str,"%s.out",s);
//	freopen(str,"w",stdout);
	#endif
}
inline int rd()
{
	static int x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return f>0?x:-x;
}
const int N=300010;
priority_queue<int>q;
int n,a[N];
bool b[N];
ll ans=0;

int main()
{
	n=rd();fo(i,1,n)a[i]=rd();
	of(i,n,1){
		if(a[i]==1){
			b[i]=1;
			if(q.empty())continue;
			int x=q.top();q.pop();
			x-=2;if(x>=2&&x!=3)q.push(x);
			++ans;
		}
		else if(a[i]!=3) q.push(a[i]);
	}
	ll res=0;
	while(!q.empty())res+=q.top(),q.pop();
	ans+=res/3;
	printf("%lld\n",ans);
	return 0;
}


#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
#define el putchar('\n')
#define ta putchar('	')
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
//	sprintf(str,"%s.out",s);
//	freopen(str,"w",stdout);
	#endif
}
inline int rd()
{
	static int x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return f>0?x:-x;
}
const int N=300010;
priority_queue<int>q;
int n,a[N];
bool b[N];
ll ans=0;

int main()
{ll res=0;
	n=rd();fo(i,1,n)a[i]=rd();
	of(i,n,1){
		if(a[i]==1){
			b[i]=1;
			if(q.empty())continue;
			int x=q.top();q.pop();
			x-=2;if(x!=3&&x)q.push(x);
			++ans;
		}
		else if(a[i]!=3) q.push(a[i]);
    else if(a[i]==3)res+=3;
	}
	while(!q.empty())res+=bool(q.top()!=1)*q.top(),q.pop();
	ans+=res/3;
	printf("%lld\n",ans);
	return 0;
}


#include<bits/stdc++.h>
#define fo(i,l,r) for(int i=l;i<=r;i++)
#define of(i,l,r) for(int i=l;i>=r;i--)
#define fe(i,u) for(int i=head[u];i;i=e[i].next)
#define el putchar('\n')
#define ta putchar('	')
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
inline void open(const char *s)
{
	#ifndef ONLINE_JUDGE
	char str[20];
	sprintf(str,"%s.in",s);
	freopen(str,"r",stdin);
//	sprintf(str,"%s.out",s);
//	freopen(str,"w",stdout);
	#endif
}
inline int rd()
{
	static int x,f;
	x=0;f=1;
	char ch=getchar();
	for(;ch<'0'||ch>'9';ch=getchar())if(ch=='-')f=-1;
	for(;ch>='0'&&ch<='9';ch=getchar())x=x*10+ch-'0';
	return f>0?x:-x;
}
const int N=300010;
priority_queue<int>q;
int n,a[N];
bool b[N];
ll ans=0;

int main()
{
	n=rd();fo(i,1,n)a[i]=rd();
	of(i,n,1){
		if(a[i]==1){
			b[i]=1;
			if(q.empty())continue;
			int x=q.top();q.pop();
			x-=2;if(x!=3&&x)q.push(x);
			++ans;
		}
		else if(a[i]!=3) q.push(a[i]);
    else if(a[i]==3)++ans;
	}
	ll res=0;
	while(!q.empty())res+=bool(q.top()!=1)*q.top(),q.pop();
	ans+=res/3;
	printf("%lld\n",ans);
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
using LL  = int64_t;
const int maxn=3e5+5;
LL a[maxn];
vector<int>temp;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    LL ans=0;
    for(int i=1;i<=n;i++) {
        if(a[i]>=4&&a[i]%3==1) {
            ans+=(a[i]/3)-1;
            a[i]=4;
        }
        else ans+=a[i]/3,a[i]%=3;
    }
    for(int i=1;i<=n;i++) {
        if(a[i]==4) {
            if(temp.size()==0) temp.push_back(i),temp.push_back(i),temp.push_back(i),temp.push_back(i);
            else {
                temp.erase(temp.end()-1);
                ans++;
                if(temp.size()==0) temp.push_back(i),temp.push_back(i);
                else {
                    temp.erase(temp.end()-1);
                    ans++;
                }
            }
        }
        else if(a[i]==2) {
            if(temp.size()==0) temp.push_back(i),temp.push_back(i);
            else {
                temp.erase(temp.end()-1);
                ans++;
            }
        }
        else if(a[i]==1) {
            temp.push_back(i);
        }
    }
    if(temp.size()>2) {
        for(int i=1;i<temp.size()-1;i++) {
            if(temp[i-1]==temp[i]&&temp[i]==temp[i+1]) ans++,temp[i+1]=-1;
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using LL  = int64_t;
const int maxn=3e5+5;
LL a[maxn];
vector<int>E[3],temp;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    LL ans=0;
    for(int i=1;i<=n;i++) ans+=a[i]/3,a[i]%3;
    for(int i=1;i<=n;i++) {
        if(a[i]==2) {
            if(E[1].size()==0||E[1][0]>=i-1) E[1].push_back(i),E[1].push_back(i);
            else {
                E[1].erase(E[1].begin());
                ans++;
            }
        }
        else if(a[i]==1) {
            E[1].push_back(i);
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using LL  = int64_t;
const int maxn=3e5+5;
LL a[maxn];
vector<int>temp;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;i++) a[i]=1000000000;//cin>>a[i];
    LL ans=0;
    for(int i=1;i<=n;i++) {
        if(a[i]>=4&&a[i]%3==1) {
            ans+=(a[i]/3)-1;
            a[i]=4;
        }
        else ans+=a[i]/3,a[i]%=3;
    }
    for(int i=1;i<=n;i++) {
        if(a[i]==4) {
            if(temp.size()==0) temp.push_back(i),temp.push_back(i),temp.push_back(i),temp.push_back(i);
            else {
                temp.erase(temp.end()-1);
                ans++;
                if(temp.size()==0) temp.push_back(i),temp.push_back(i);
                else {
                    temp.erase(temp.end()-1);
                    ans++;
                }
            }
        }
        else if(a[i]==2) {
            if(temp.size()==0) temp.push_back(i),temp.push_back(i);
            else {
                temp.erase(temp.end()-1);
                ans++;
            }
        }
        else if(a[i]==1) {
            temp.push_back(i);
        }
    }
    if(temp.size()>2) {
        for(int i=1;i<temp.size()-1;i++) {
            if(temp[i-1]==temp[i]&&temp[i]==temp[i+1]) ans++,temp[i+1]=-1;
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using LL  = int64_t;
const int maxn=3e5+5;
LL a[maxn];
vector<int>E[3],temp;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    LL ans=0;
    for(int i=1;i<=n;i++) ans+=a[i]/3,a[i]%=3;
    for(int i=1;i<=n;i++) {
        if(a[i]==2) {
            if(E[1].size()==0||E[1][0]==i-1) E[1].push_back(i),E[1].push_back(i);
            else {
                E[1].erase(E[1].begin());
                ans++;
            }
        }
        else if(a[i]==1) {
            E[1].push_back(i);
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using LL  = int64_t;
const int maxn=3e5+5;
LL a[maxn];
vector<int>E[3],temp;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    LL ans=0;
    for(int i=1;i<=n;i++) ans+=a[i]/3,a[i]%=3;
    for(int i=1;i<=n;i++) {
        if(a[i]==2) {
            if(E[1].size()==0) E[1].push_back(i),E[1].push_back(i);
            else {
                E[1].erase(E[1].end()-1);
                ans++;
            }
        }
        else if(a[i]==1) {
            E[1].push_back(i);
        }
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using LL  = int64_t;
const int maxn=3e5+5;
LL a[maxn];
vector<LL>temp;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    LL ans=0;
    for(int i=1;i<=n;i++) {
        if(temp.size()) {
            while(temp.size()>0&&a[i]>=2) a[i]-=2,temp.pop_back(),ans++;
        }
        ans+=a[i]/3;a[i]%=3;
        for(int j=1;j<=a[i];j++) temp.push_back(i);
    }
    cout<<ans;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
using LL  = int64_t;
const int maxn=3e5+5;
LL a[maxn];
vector<LL>temp;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n;cin>>n;
    for(int i=1;i<=n;i++) cin>>a[i];
    LL ans=0;
    for(int i=1;i<=n;i++) {
        if(a[i]%2==0&&temp.size()) {
            while(temp.size()>0&&a[i]>=2) a[i]-=2,temp.pop_back(),ans++;
        }
        ans+=a[i]/3;a[i]%=3;
        for(int j=1;j<=a[i];j++) temp.push_back(i);
    }
    cout<<ans;
    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long

int main()
{
    ll n , sum=0 , tmp , ans=0;
    cin >> n;
    ll arr[n];

    for (int i=0; i<n; i++)
    {
        cin >> arr[i];
    }

    int j=0;

    for (int i=n-1; i>=0; i--)
    {
        if (j > i) break;

        ans += (arr[i]/3);
        arr[i] %= 3;

        tmp = arr[i]/2;
        while(j < i && sum < tmp)
            sum += arr[j++];

        if (sum <= tmp)
        {
            ans += sum;
        }
        else
        {
            j--;
            ans += tmp;
            arr[j] = (sum-tmp);
        }
        sum=0;
    }

    cout << ans << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long

int main()
{
    ll n , sum=0 , tmp , ans=0;
    cin >> n;
    ll arr[n];

    for (int i=0; i<n; i++)
    {
        cin >> arr[i];
    }

    int j=0;

    for (int i=n-1; i>=0; i--)
    {
        if (arr[i]%2)
        {
            ans += (arr[i]/3);
            arr[i] %= 3;
        }
        tmp = arr[i]/2;
        while(j < i && sum < tmp)
            sum += arr[j++];

        if (sum <= tmp)
        {
            ans += sum;
        }
        else
        {
            j--;
            ans += tmp;
            arr[j] = (sum-tmp);
        }
        sum=0;
    }

    cout << ans << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long

int main()
{
    ll n , sum=0 , tmp , ans=0;
    cin >> n;
    ll arr[n];

    for (int i=0; i<n; i++)
    {
        cin >> arr[i];
    }

    int j=0;

    for (int i=n-1; i>=0; i--)
    {
        if (j > i) break;
        tmp = arr[i]/2 , sum=0;

        while(j<i && sum<tmp)
        {
            if (sum + arr[j]%3 <= tmp) {sum += arr[j]%3; arr[j] -= (arr[j]%3); j++;}
            else
            {
                arr[j]-- , sum++;
                break;
            }
        }

        ans += sum;
        arr[i] -= (sum*2);

    }

    for (int i=0; i<n; i++)
    {
        ans += arr[i]/3;
    }

    cout << ans << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long

int main()
{
    ll n , sum=0 , tmp , ans=0;
    cin >> n;
    ll arr[n];

    for (int i=0; i<n; i++)
    {
        cin >> arr[i];
    }

    int j=0;

    for (int i=n-1; i>=0; i--)
    {

        ans += (arr[i]/3);
        arr[i] %= 3;

        tmp = arr[i]/2;
        while(j < i && sum < tmp)
            sum += arr[j++];

        if (sum <= tmp)
        {
            ans += sum;
        }
        else
        {
            j--;
            ans += tmp;
            arr[j] = (sum-tmp);
        }
        sum=0;
    }

    cout << ans << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long

int main()
{
    ll n , sum=0 , tmp , ans=0 , lst=0;
    cin >> n;
    ll arr[n];

    for (int i=0; i<n; i++)
    {
        cin >> arr[i];
    }

    int j=1;
    for (int i=0; i<n; i++)
    {
        ans += (arr[i]/3);
        arr[i] %= 3;
        if (i==j) j++;

        while(j<n && arr[i])
        {
            while(arr[j]>1 && arr[i] > 0)
            {
                arr[j] -= 2;
                arr[i]-- , ans++;
            }
            if (!arr[i]) break;
            j++;
        }
    }

    cout << ans << "\n";

    return 0;
}


#include <bits/stdc++.h>

using namespace std;
#define ll long long

int main()
{
    ll n , sum=0 , tmp , ans=0;
    cin >> n;
    ll arr[n];

    for (int i=0; i<n; i++)
    {
        cin >> arr[i];
        ans += (arr[i]/3);
        arr[i] %= 3;
    }

    int j=0;

    for (int i=n-1; i>=0; i--)
    {
        tmp = arr[i]/2;
        while(j < i && sum < tmp)
            sum += arr[j++];

        if (sum <= tmp)
        {
            ans += sum;
        }
        else
        {
            j--;
            ans += tmp;
            arr[j] = (sum-tmp);
        }
        sum=0;
    }

    cout << ans << "\n";

    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <iomanip>
#include <cstring>
#include <map>
#define debug(x) //std::cerr << #x << " = " << (x) << std::endl
using namespace std;
typedef long long LL;
const int MAXN = 3e5 + 17;
const int MOD = 1e9 + 17;
LL a[MAXN];
int main(int argc, char const *argv[])
{
#ifdef noob
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
	int n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	LL lft = 0,ans = 0;
	for (int i = 0; i < n; ++i)
	{
		ans += a[i]/3;
		a[i]%=3;
		debug(i);
		debug(a[i]);
				debug(lft);
		if(a[i]==2)
		{
			if(lft) ans++,lft--;
			else lft+=2;
		}
		if(a[i]==1) lft++;
		debug(ans);
	}
	cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#define debug(x) //std::cerr << #x << " = " << (x) << std::endl
using namespace std;
typedef long long LL;
const int MAXN = 3e6 + 17;
const int MOD = 1e9 + 17;
LL a[MAXN];
int main(int argc, char const *argv[])
{
#ifdef noob
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
	LL n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	LL lft = 0,ans = 0;
	deque<pair<LL,LL > > que;
	for (int i = 0; i < n; ++i)
	{
		LL now = a[i]/2;
		if(que.empty())
		{
			ans += a[i]/3;
			a[i]%=3;
			que.push_back({a[i],i});
		}
		else{
		while(!que.empty())
		{
			auto p = que.front(); que.pop_front();
			LL num = p.first,id = p.second;
			debug(num);
			debug(id);
			if(now>=num)
			{
				now -= num;
				ans += num;
				a[id] -= num;
			}
			else
			{
				ans += now;
				a[id] -= now;
				p.first -= now;
				now = 0;
				que.push_front(p);
				break;
			}

		}
		a[i] = now*2LL + a[i]%2LL;
			que.push_back({a[i],i});
		}
		debug(i);
		debug(ans);
		debug(now);

				debug(a[i]);

	}
	for (int i = 0; i < n; ++i)
	{
		ans += a[i]/3;
	}
	cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <iomanip>
#include <cstring>
#include <map>
#define debug(x) //std::cerr << #x << " = " << (x) << std::endl
using namespace std;
typedef long long LL;
const int MAXN = 3e6 + 17;
const int MOD = 1e9 + 17;
LL a[MAXN];
int main(int argc, char const *argv[])
{
#ifdef noob
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
	LL n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	LL lft = 0,ans = 0;
	for (int i = 0; i < n; ++i)
	{
		ans += a[i]/3LL;
		a[i]%=3LL;
		if(a[i]==2LL)
		{
			if(lft>0) ans++,lft--;
			else lft+=2LL;
		}
		else if(a[i]==1LL) lft++;
	}
	cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <iomanip>
#include <cstring>
#include <map>
#define debug(x) //std::cerr << #x << " = " << (x) << std::endl
using namespace std;
typedef long long LL;
const int MAXN = 1e5 + 17;
const int MOD = 1e9 + 17;
LL a[MAXN];
int main(int argc, char const *argv[])
{
#ifdef noob
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
	int n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	LL lft = 0,ans = 0;
	for (int i = 0; i < n; ++i)
	{
		ans += a[i]/3;
		a[i]%=3;
		debug(i);
		debug(a[i]);
				debug(lft);
		if(a[i]==2)
		{
			if(lft) ans++,lft--;
			else lft+=2;
		}
		if(a[i]==1) lft++;
		debug(ans);
	}
	cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#define debug(x) //std::cerr << #x << " = " << (x) << std::endl
using namespace std;
typedef long long LL;
const int MAXN = 3e6 + 17;
const int MOD = 1e9 + 17;
LL a[MAXN];
int main(int argc, char const *argv[])
{
#ifdef noob
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
	LL n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	LL lft = 0,ans = 0;
	deque<pair<LL,LL > > que;
	for (int i = 0; i < n; ++i)
	{
		LL now = a[i]/2;
		if(que.empty())
		{
			ans += a[i]/3;
			a[i]%=3;
			que.push_back({a[i],i});
		}
		while(!que.empty())
		{
			auto p = que.front(); que.pop_front();
			LL num = p.first,id = p.second;
			debug(num);
			debug(id);
			if(now>=num)
			{
				now -= num;
				ans += num;
				a[id] -= num;
			}
			else
			{
				ans += now;
				a[id] -= now;
				p.first -= now;
				now = 0;
				que.push_front(p);
				break;
			}
		}
		debug(i);
		debug(ans);
		debug(now);
		a[i] = now*2LL + a[i]%2LL;
		que.push_back({a[i],i});
				debug(a[i]);

	}
	for (int i = 0; i < n; ++i)
	{
		ans += a[i]/3;
	}
	cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#define debug(x) //std::cerr << #x << " = " << (x) << std::endl
using namespace std;
typedef long long LL;
const int MAXN = 3e6 + 17;
const int MOD = 1e9 + 17;
LL a[MAXN];
int main(int argc, char const *argv[])
{
#ifdef noob
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
	LL n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	LL lft = 0,ans = 0;
	deque<pair<LL,LL > > que;
	for (int i = 0; i < n; ++i)
	{
		LL now = a[i]/2;
		if(que.empty())
		{
			ans += a[i]/3;
			a[i]%=3;
			if(a[i]) que.push_back({a[i],i});
		}
		else
		{
			while(!que.empty())
			{
				auto p = que.front(); que.pop_front();
				LL num = p.first,id = p.second;
				debug(num);
				debug(id);
				if(now>=num)
				{
					now -= num;
					ans += num;
					a[id] -= num;
				}
				else
				{
					ans += now;
					a[id] -= now;
					p.first -= now;
					now = 0;
					que.push_front(p);
					break;
				}
			}
			a[i] = now*2LL + a[i]%2LL;
			que.push_back({a[i],i});
		}
		debug(i);
		debug(ans);
		debug(now);

				debug(a[i]);

	}
	for (int i = 0; i < n; ++i)
	{
		ans += a[i]/3;
	}
	cout<<ans<<endl;
    return 0;
}


#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <iomanip>
#include <queue>
#include <map>
#define debug(x) //std::cerr << #x << " = " << (x) << std::endl
using namespace std;
typedef long long LL;
const int MAXN = 3e6 + 17;
const int MOD = 1e9 + 17;
LL a[MAXN];
int main(int argc, char const *argv[])
{
#ifdef noob
    freopen("Input.txt", "r", stdin);
    freopen("Output.txt", "w", stdout);
#endif
	LL n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	LL lft = 0,ans = 0;
	deque<pair<LL,LL > > que;
	for (int i = 0; i < n; ++i)
	{
		LL now = a[i]/2;
						debug(i);

		if(que.empty())
		{
			ans += a[i]/3;
			a[i]%=3;
			if(a[i]) que.push_back({a[i],i});
		}
		else
		{
			while(!que.empty())
			{
				auto p = que.front(); que.pop_front();
				LL num = p.first,id = p.second;
				debug(num);
				debug(id);
				if(now>=num)
				{
					now -= num;
					ans += num;
					a[id] -= num;
				}
				else
				{
					ans += now;
					a[id] -= now;
					p.first -= now;
					now = 0;
					que.push_front(p);
					break;
				}
			}
			a[i] = now*2LL + a[i]%2LL;
			ans += a[i]/3;
			a[i]%=3;
			debug(a[i]);
			if(a[i]) que.push_back({a[i],i});
		}
		debug(i);
		debug(ans);
		// debug(now);
	}
	for (int i = 0; i < n; ++i)
	{
		ans += a[i]/3;
	}
	cout<<ans<<endl;
    return 0;
}


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define pii pair<int,int>
#define PI  3.14159265358979323
#define MOD 998244353
#define trav(a,x) for(auto& a : x)
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll gcd(ll a,ll b){
 	if(a==0)
 		return b;
 	return gcd(b%a,a);
 }

ll expo(ll a,ll b){
	if(b==0)return 1;
	ll y=expo(a,b/2);
	y=(y*y)%MOD;
	if(b%2)return (y*a)%MOD;
	return y;
}

ll powmod(ll a,ll b,ll p){
	if(b==0)
		return 1;
	if(b==1)
			return a;
	ll temp=powmod(a,b/2,p);
	temp*=temp;
	temp%=p;
	if(b%2==0)
		return temp;
	temp=temp*a;
	temp%=p;
	return temp;
}

void solve()
{

   int n;
   cin>>n;
   int a[n];
   int c=0;
   rep(i, 0, n)
   {
   	cin>>a[i];
   	c+=a[i]/3;
   	a[i]%=3;
   }
   int i=0 ,j=n-1;
   while(j>i)
   {
   	if(a[j]==2)
   	{
   		while(i<j && a[i]==0)
   		i++;

	   if(i<j)
	   {
	   	a[i]--;
	   	c++;
	   }
	   else
	   break;
   }
   j--;
 }
   cout<<c<<endl;
   return ;

}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t=1;
  //cin>>t;
   while(t--)
   {
     solve();
   }
   return 0;
 }


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define pii pair<int,int>
#define PI  3.14159265358979323
#define MOD 998244353
#define trav(a,x) for(auto& a : x)
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll gcd(ll a,ll b){
 	if(a==0)
 		return b;
 	return gcd(b%a,a);
 }

ll expo(ll a,ll b){
	if(b==0)return 1;
	ll y=expo(a,b/2);
	y=(y*y)%MOD;
	if(b%2)return (y*a)%MOD;
	return y;
}

ll powmod(ll a,ll b,ll p){
	if(b==0)
		return 1;
	if(b==1)
			return a;
	ll temp=powmod(a,b/2,p);
	temp*=temp;
	temp%=p;
	if(b%2==0)
		return temp;
	temp=temp*a;
	temp%=p;
	return temp;
}

void solve()
{

   int n;
   cin>>n;
   ll a[n];
   ll c=0;
   rep(i, 0, n)
   {
   	cin>>a[i];
   	c+=a[i]/3;
   	a[i]%=3;
   }
   int i=0 ,j=n-1;
   while(j>i)
   {
   	if(a[j]==2)
   	{
   		while(i<j && a[i]==0)
   		i++;

	   if(i<j)
	   {
	   	a[i]--;
	   	c++;
	   }
	   else
	   break;
   }
   j--;
 }
   cout<<c<<endl;
   return ;

}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t=1;
  //cin>>t;
   while(t--)
   {
     solve();
   }
   return 0;
 }


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define pii pair<int,int>
#define PI  3.14159265358979323
#define MOD 998244353
#define trav(a,x) for(auto& a : x)
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll gcd(ll a,ll b){
 	if(a==0)
 		return b;
 	return gcd(b%a,a);
 }

ll expo(ll a,ll b){
	if(b==0)return 1;
	ll y=expo(a,b/2);
	y=(y*y)%MOD;
	if(b%2)return (y*a)%MOD;
	return y;
}

ll powmod(ll a,ll b,ll p){
	if(b==0)
		return 1;
	if(b==1)
			return a;
	ll temp=powmod(a,b/2,p);
	temp*=temp;
	temp%=p;
	if(b%2==0)
		return temp;
	temp=temp*a;
	temp%=p;
	return temp;
}

void solve()
{

   int n;
   cin>>n;
   ll a[n];
   rep(i, 0, n)
   {
   	cin>>a[i];
   }
   ll rem=0, ans=0;
  rep(i, 0 ,n)
  {

  		ll mn = min(a[i]/2 , rem);
  		ans+=mn;
  		a[i]-=2*mn;
  		rem-=mn;
	    ans+=a[i]/3;
        rem+=a[i]%3;
  }
   cout<<ans<<endl;
   return ;

}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t=1;
  //cin>>t;
   while(t--)
   {
     solve();
   }
   return 0;
 }


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define pii pair<int,int>
#define PI  3.14159265358979323
#define MOD 998244353
#define trav(a,x) for(auto& a : x)
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll gcd(ll a,ll b){
 	if(a==0)
 		return b;
 	return gcd(b%a,a);
 }

ll expo(ll a,ll b){
	if(b==0)return 1;
	ll y=expo(a,b/2);
	y=(y*y)%MOD;
	if(b%2)return (y*a)%MOD;
	return y;
}

ll powmod(ll a,ll b,ll p){
	if(b==0)
		return 1;
	if(b==1)
			return a;
	ll temp=powmod(a,b/2,p);
	temp*=temp;
	temp%=p;
	if(b%2==0)
		return temp;
	temp=temp*a;
	temp%=p;
	return temp;
}

void solve()
{

   int n;
   cin>>n;
   ll a[n];
   rep(i, 0, n)
   {
   	cin>>a[i];
   }
   ll rem=0, ans=0;
  rep(i, 0 ,n)
  {

  		ll mn = min(a[i] , 2*rem);
  		ans+=mn/2;
  		a[i]-=mn;
  		rem-=mn/2;
	    ans+=a[i]/3;
        rem+=a[i]%3;
  }
   cout<<ans<<endl;
   return ;

}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t=1;
  //cin>>t;
   while(t--)
   {
     solve();
   }
   return 0;
 }


#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define fix(n) cout << fixed << setprecision(n)
#define mset(a,n) memset(a,n,sizeof a)
#define rep(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define repp(i,a,b,p) for(__typeof((b)) i=(a);i<(b);i+=p)
#define ren(i,a,b) for(__typeof((a)) i=(a);i>=(b);i--)
#define renn(i,a,b,p) for(__typeof((a) i=(a);i>=(b);i-=p)
#define ADD(a,b,c) ((a)%c+(b)%c)%c
#define SUB(a,b,c) ((a)%c-(b)%c+c)%c
#define MUL(a,b,c) (((a)%c)*((b)%c))%c
#define lbd lower_bound
#define ubd upper_bound
#define ll long long
#define ld long double
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define all(v) (v).begin(), (v).end()
#define sz(x) (ll)x.size()
#define pii pair<int,int>
#define PI  3.14159265358979323
#define MOD 998244353
#define trav(a,x) for(auto& a : x)
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

ll gcd(ll a,ll b){
 	if(a==0)
 		return b;
 	return gcd(b%a,a);
 }

ll expo(ll a,ll b){
	if(b==0)return 1;
	ll y=expo(a,b/2);
	y=(y*y)%MOD;
	if(b%2)return (y*a)%MOD;
	return y;
}

ll powmod(ll a,ll b,ll p){
	if(b==0)
		return 1;
	if(b==1)
			return a;
	ll temp=powmod(a,b/2,p);
	temp*=temp;
	temp%=p;
	if(b%2==0)
		return temp;
	temp=temp*a;
	temp%=p;
	return temp;
}

void solve()
{

   int n;
   cin>>n;
   ll a[n];
   rep(i, 0, n)
   {
   	cin>>a[i];
   }
   ll rem=0, ans=0;
  rep(i, 0 ,n)
  {
  	if(rem)
  	{
  		ll mn = min(a[i] , 2*rem);
  		ans+=mn/2;
  		a[i]-=mn;
  		rem-=mn/2;
	  }
	  ans+=a[i]/3;
	  rem+=a[i]%3;
  }
   cout<<ans<<endl;
   return ;

}

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t=1;
  //cin>>t;
   while(t--)
   {
     solve();
   }
   return 0;
 }


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<ll,ll>
const int N=3e5+10;
ll D[N];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("/home/zz7/CFInput","r",stdin);
#endif
	//1 3 4 5 9
	int n;scanf("%d",&n);
	ll ans=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&D[i]);
		ans+=D[i]/3;
		D[i]=D[i]%3;
	}
	int j=0;
	for(int i=n-1;i>=0;i--){
		ll p=D[i]/2,g=D[i]%2;
		while(p>0){
			while(j<n&&D[j]<=0)j++;
			if(j>=i){
				if(j==i)ans+=(p*2+g)/3;
				return cout<<ans<<'\n',0;
			}
			ll u=min(p,D[j]);
			p-=u,D[j]-=u;
			ans+=u;
		}
	}cout<<ans<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<ll,ll>
const int N=3e5+10;
ll D[N];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("/home/zz7/CFInput","r",stdin);
#endif
	//1 3 4 5 9
	int n;scanf("%d",&n);
	ll ans=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&D[i]);
		if(D[i]%2==1){
			if(D[i]>=3)ans++,D[i]-=3;
		}
	}
	int j=0;
	for(int i=n-1;i>=0;i--){
		ll p=D[i]/2,g=D[i]%2;
		while(p>0){
			while(j<n&&D[j]<=0)j++;
			if(j>=i){
				if(j==i)ans+=(p*2+g)/3;
				return cout<<ans<<'\n',0;
			}
			ll u=min(p,D[j]);
			p-=u,D[j]-=u;
			ans+=u;
		}
	}cout<<ans<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<ll,ll>
const int N=3e5+10;
ll D[N];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("/home/zz7/CFInput","r",stdin);
#endif
	//1 3 4 5 9
	int n;scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&D[i]);
	}
	ll ans=0;
	int j=0;
	for(int i=n-1;i>=0;i--){
		ll p=D[i]/2,g=D[i]%2;
		while(p>0){
			while(j<n&&D[j]<=0)j++;
			if(j>=i){
				if(j==i)ans+=(p*2+g)/3;
				return cout<<ans<<'\n',0;
			}
			ll u=min(p,D[j]);
			p-=u,D[j]-=u;
			ans+=u;
		}
	}cout<<ans<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<ll,ll>
const int N=3e5+10;
ll D[N];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("/home/zz7/CFInput","r",stdin);
#endif
	//1 3 4 5 9
	int n;scanf("%d",&n);
	ll ans=0,cnt=0,sum=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&D[i]);
		if(D[i]%2==1){
			if(D[i]>=3)ans++,D[i]-=3,sum+=D[i];
			else cnt++;
		}else sum+=D[i];
	}ll a=0;
	for(int i=n-1;i>=0;i--){
		if(D[i]!=1)a+=D[i]/2;
		else if(a>0)a--,sum-=2,ans++;
	}cout<<ans+sum/3<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<ll,ll>
const int N=3e5+10;
ll D[N];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("/home/zz7/CFInput","r",stdin);
#endif
	//1 3 4 5 9
	int n;scanf("%d",&n);
	ll ans=0,cnt=0,sum=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&D[i]);
		if(D[i]%2==1){
			if(D[i]>=3)ans++,D[i]-=3,sum+=D[i];
			else cnt++;
		}
	}ll a=0;
	for(int i=n-1;i>=0;i--){
		if(D[i]!=1)a+=D[i]/2;
		else if(a>0)a--,sum-=2,ans++;
	}cout<<ans+sum/3<<'\n';
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pi pair<ll,ll>
const int N=3e5+10;
ll D[N];
int main()
{
#ifndef ONLINE_JUDGE
	freopen("/home/zz7/CFInput","r",stdin);
#endif
	//1 3 4 5 9
	int n;scanf("%d",&n);
	ll ans=0;
	for(int i=0;i<n;i++){
		scanf("%lld",&D[i]);
		if(D[i]%3==0){
			ans+=D[i]/3;D[i]=0;
		}
	}
	int j=0;
	for(int i=n-1;i>=0;i--){
		ll p=D[i]/2,g=D[i]%2;
		while(p>0){
			while(j<n&&D[j]<=0)j++;
			if(j>=i){
				if(j==i)ans+=(p*2+g)/3;
				return cout<<ans<<'\n',0;
			}
			ll u=min(p,D[j]);
			p-=u,D[j]-=u;
			ans+=u;
		}
	}cout<<ans<<'\n';
}


#include <bits/stdc++.h>
    using namespace std;
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;

    #define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define pb push_back
    #define ll long long

    #define vi vector<int>
    #define vll vector<long long>
    #define mp make_pair
    #define infi INT_MAX
    #define infl LONG_LONG_MAX
    #define infd LDBL_MAX
    #define f(i,a,b) for(ll i=a;i<b;i++)
    #define ff first
    #define ss second
    #define pll pair<ll,ll>
    #define endl "\n"
    #define ALL(v) v.begin(),v.end()
    #define nl cout<<"\n";
    #define pr(x) cout<<x;
    #define pr1(x) cout<<x<<" ";
    #define pr2(x,y) cout<<x<<" "<<y;
    #define deb printf("*****************************\n");
    #define idk printf("idk idk ! \n");
    #define hi printf("hi ! \n");
    #define bye printf("bye bye ! \n");
    #define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
    #define number_of_set_bits  __builtin_popcountll

    //template<typename T>
    //#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
    //member functions :
    //1. order_of_key(k) : number of elements strictly lesser than k
    //2. find_by_order(k) : k-th element in the set

     int main()
    {
        fast
        //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        //#endif // ONLINE_JUDGE

        ll ntc=1;
     //   cin>>ntc;

        f(ks,1,ntc+1)
        {
          //cout<<"Case #"<<i<<": ";

          ll n; cin>>n;
          ll a[300005];
          f(i,0,n) cin>>a[i];
          ll ans = 0;
          ll o = 0;
          f(i,0,n){
              ans += a[i]/2;
              o += (a[i]%2 == 1);

          }
         // cout<<o<<" "<<ans<<endl;
          ll sans = min(o,ans);
         ans -= sans;
         ll finalans = sans + ((2*ans)/3);
          cout<<finalans<<endl;
        }

        return 0;
    }


#include <bits/stdc++.h>
    using namespace std;
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;

    #define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define pb push_back
    #define ll long long

    #define vi vector<int>
    #define vll vector<long long>
    #define mp make_pair
    #define infi INT_MAX
    #define infl LONG_LONG_MAX
    #define infd LDBL_MAX
    #define f(i,a,b) for(ll i=a;i<b;i++)
    #define ff first
    #define ss second
    #define pll pair<ll,ll>
    #define endl "\n"
    #define ALL(v) v.begin(),v.end()
    #define nl cout<<"\n";
    #define pr(x) cout<<x;
    #define pr1(x) cout<<x<<" ";
    #define pr2(x,y) cout<<x<<" "<<y;
    #define deb printf("*****************************\n");
    #define idk printf("idk idk ! \n");
    #define hi printf("hi ! \n");
    #define bye printf("bye bye ! \n");
    #define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
    #define number_of_set_bits  __builtin_popcountll

    //template<typename T>
    //#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
    //member functions :
    //1. order_of_key(k) : number of elements strictly lesser than k
    //2. find_by_order(k) : k-th element in the set

     int main()
    {
        fast
        //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        //#endif // ONLINE_JUDGE

        ll ntc=1;
     //   cin>>ntc;

        f(ks,1,ntc+1)
        {
          //cout<<"Case #"<<i<<": ";

          ll n; cin>>n;
          ll a[300005];
          f(i,0,n) cin>>a[i];
          ll ans = 0;
          ll o = 0;
          f(i,0,n){
              ans += a[i]/2;
              o += (a[i]%2 == 1);

          }
         // cout<<o<<" "<<ans<<endl;
          ll sans = min(o,ans);
         ans -= sans;
         ll finalans = sans + (2*ans/3);
          cout<<finalans<<endl;
        }

        return 0;
    }


#include <bits/stdc++.h>
    using namespace std;
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;

    #define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define pb push_back
    #define ll long long

    #define vi vector<int>
    #define vll vector<long long>
    #define mp make_pair
    #define infi INT_MAX
    #define infl LONG_LONG_MAX
    #define infd LDBL_MAX
    #define f(i,a,b) for(ll i=a;i<b;i++)
    #define ff first
    #define ss second
    #define pll pair<ll,ll>
    #define endl "\n"
    #define ALL(v) v.begin(),v.end()
    #define nl cout<<"\n";
    #define pr(x) cout<<x;
    #define pr1(x) cout<<x<<" ";
    #define pr2(x,y) cout<<x<<" "<<y;
    #define deb printf("*****************************\n");
    #define idk printf("idk idk ! \n");
    #define hi printf("hi ! \n");
    #define bye printf("bye bye ! \n");
    #define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
    #define number_of_set_bits  __builtin_popcountll

    //template<typename T>
    //#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
    //member functions :
    //1. order_of_key(k) : number of elements strictly lesser than k
    //2. find_by_order(k) : k-th element in the set

     int main()
    {
        fast
        //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        //#endif // ONLINE_JUDGE

        ll ntc=1;
     //   cin>>ntc;

        f(ks,1,ntc+1)
        {
          //cout<<"Case #"<<i<<": ";

          ll n; cin>>n;
          ll a[300005];
          f(i,0,n) cin>>a[i];

          ll ans=0,got=0;
   for(int i = n-1; i>=0; --i){

	    got+=(a[i]/2);
		if(got and a[i]&1)
		{
			ans++;
			got--;
		}
	}
	cout<<ans+(2*got)/3;
        }

        return 0;
    }


#include <bits/stdc++.h>
    using namespace std;
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;

    #define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define pb push_back
    #define ll long long

    #define vi vector<int>
    #define vll vector<long long>
    #define mp make_pair
    #define infi INT_MAX
    #define infl LONG_LONG_MAX
    #define infd LDBL_MAX
    #define f(i,a,b) for(ll i=a;i<b;i++)
    #define ff first
    #define ss second
    #define pll pair<ll,ll>
    #define endl "\n"
    #define ALL(v) v.begin(),v.end()
    #define nl cout<<"\n";
    #define pr(x) cout<<x;
    #define pr1(x) cout<<x<<" ";
    #define pr2(x,y) cout<<x<<" "<<y;
    #define deb printf("*****************************\n");
    #define idk printf("idk idk ! \n");
    #define hi printf("hi ! \n");
    #define bye printf("bye bye ! \n");
    #define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
    #define number_of_set_bits  __builtin_popcountll

    //template<typename T>
    //#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
    //member functions :
    //1. order_of_key(k) : number of elements strictly lesser than k
    //2. find_by_order(k) : k-th element in the set

     int main()
    {
        fast
        //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        //#endif // ONLINE_JUDGE

        ll ntc=1;
     //   cin>>ntc;

        f(ks,1,ntc+1)
        {
          //cout<<"Case #"<<i<<": ";

          ll n; cin>>n;
          ll a[300005];
          f(i,0,n) cin>>a[i];
          ll ans = 0;
          ll o = 0, t  = 0;
          f(i,0,n){
              ans += a[i]/2;
              o += (a[i]%3 == 1);
              t += (a[i]%3 == 2);
          }
          ll sans = min(o,ans);
         ans -= sans;
         ll finalans = sans + (2*ans/3);
          cout<<finalans<<endl;
        }

        return 0;
    }


#include <bits/stdc++.h>
    using namespace std;
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;

    #define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define pb push_back
    #define ll long long

    #define vi vector<int>
    #define vll vector<long long>
    #define mp make_pair
    #define infi INT_MAX
    #define infl LONG_LONG_MAX
    #define infd LDBL_MAX
    #define f(i,a,b) for(ll i=a;i<b;i++)
    #define ff first
    #define ss second
    #define pll pair<ll,ll>
    #define endl "\n"
    #define ALL(v) v.begin(),v.end()
    #define nl cout<<"\n";
    #define pr(x) cout<<x;
    #define pr1(x) cout<<x<<" ";
    #define pr2(x,y) cout<<x<<" "<<y;
    #define deb printf("*****************************\n");
    #define idk printf("idk idk ! \n");
    #define hi printf("hi ! \n");
    #define bye printf("bye bye ! \n");
    #define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
    #define number_of_set_bits  __builtin_popcountll

    //template<typename T>
    //#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
    //member functions :
    //1. order_of_key(k) : number of elements strictly lesser than k
    //2. find_by_order(k) : k-th element in the set

     int main()
    {
        fast
        //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        //#endif // ONLINE_JUDGE

        ll ntc=1;
     //   cin>>ntc;

        f(ks,1,ntc+1)
        {
          //cout<<"Case #"<<i<<": ";

          ll n; cin>>n;
          ll a[300005];
          f(i,0,n) cin>>a[i];
          ll ans = 0;
          ll o = 0, t  = 0;
          f(i,0,n){
              ans += a[i]/3;
              o += (a[i]%3 == 1);
              t += (a[i]%3 == 2);
          }
          ll sans = min(o,t);
          o -= sans; t -= sans; ans += sans;
          if(t > 0) ans += 2*t/3;
          cout<<ans<<endl;
        }

        return 0;
    }


#include <bits/stdc++.h>
    using namespace std;
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;

    #define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define pb push_back
    #define ll long long

    #define vi vector<int>
    #define vll vector<long long>
    #define mp make_pair
    #define infi INT_MAX
    #define infl LONG_LONG_MAX
    #define infd LDBL_MAX
    #define f(i,a,b) for(ll i=a;i<b;i++)
    #define ff first
    #define ss second
    #define pll pair<ll,ll>
    #define endl "\n"
    #define ALL(v) v.begin(),v.end()
    #define nl cout<<"\n";
    #define pr(x) cout<<x;
    #define pr1(x) cout<<x<<" ";
    #define pr2(x,y) cout<<x<<" "<<y;
    #define deb printf("*****************************\n");
    #define idk printf("idk idk ! \n");
    #define hi printf("hi ! \n");
    #define bye printf("bye bye ! \n");
    #define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
    #define number_of_set_bits  __builtin_popcountll

    //template<typename T>
    //#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
    //member functions :
    //1. order_of_key(k) : number of elements strictly lesser than k
    //2. find_by_order(k) : k-th element in the set

     int main()
    {
        fast
        //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        //#endif // ONLINE_JUDGE

        ll ntc=1;
     //   cin>>ntc;

        f(ks,1,ntc+1)
        {
          //cout<<"Case #"<<i<<": ";

          ll n; cin>>n;
          ll a[300005];
          f(i,0,n) cin>>a[i];
          ll ans = 0;
          ll o = 0;
          f(i,0,n){
              ans += a[i]/2;
              o += (a[i]%2 == 1);

          }
         // cout<<o<<" "<<ans<<endl;
          ll sans = min(o,ans);
         ans -= sans;
         ll finalans = sans + (2*ans)/3;
          cout<<finalans<<endl;
        }

        return 0;
    }


#include <bits/stdc++.h>
    using namespace std;
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;

    #define fast { ios :: sync_with_stdio(false); cin.tie(0); cout.tie(0); }
    #define pb push_back
    #define ll long long

    #define vi vector<int>
    #define vll vector<long long>
    #define mp make_pair
    #define infi INT_MAX
    #define infl LONG_LONG_MAX
    #define infd LDBL_MAX
    #define f(i,a,b) for(ll i=a;i<b;i++)
    #define ff first
    #define ss second
    #define pll pair<ll,ll>
    #define endl "\n"
    #define ALL(v) v.begin(),v.end()
    #define nl cout<<"\n";
    #define pr(x) cout<<x;
    #define pr1(x) cout<<x<<" ";
    #define pr2(x,y) cout<<x<<" "<<y;
    #define deb printf("*****************************\n");
    #define idk printf("idk idk ! \n");
    #define hi printf("hi ! \n");
    #define bye printf("bye bye ! \n");
    #define o_set(ll) tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
    #define number_of_set_bits  __builtin_popcountll

    //template<typename T>
    //#define o_set(T) tree<T, null_type,less<T>, rb_tree_tag,tree_order_statistics_node_update>
    //member functions :
    //1. order_of_key(k) : number of elements strictly lesser than k
    //2. find_by_order(k) : k-th element in the set

     int main()
    {
        fast
        //#ifndef ONLINE_JUDGE
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        //#endif // ONLINE_JUDGE

        ll ntc=1;
     //   cin>>ntc;

        f(ks,1,ntc+1)
        {
          //cout<<"Case #"<<i<<": ";

          ll n; cin>>n;
          ll a[300005];
          f(i,0,n) cin>>a[i];
          ll ans = 0;
          ll o = 0;
          f(i,0,n){
              ans += a[i]/2;
              o += (a[i]%2 == 1);

          }
         // cout<<o<<" "<<ans<<endl;
          ll sans = min(o,ans);
         ans -= sans;
         ll finalans = sans + (2*ans)/3);
          cout<<finalans<<endl;
        }

        return 0;
    }


#include <bits/stdc++.h>

using namespace std;
using INT = long long;

int power(int a, int b, int c, int ans=1) {
	for (; b; b>>=1, a=(INT)a*a%c) if (b&1) ans=(INT)ans*a%c;
	return ans;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n, d;
	cin>>n;
	INT ans=0, cnt1=0, cnt2=0, cnt3=0;
	for (int i=0; i<n; i++) {
		scanf("%d", &d);
		if (d%3==1) cnt1++;
		if (d%3==2) {
			if (cnt1) ans++, cnt1--;
			else if (cnt2) ans++, cnt2--, cnt1++;
			else if (cnt3) ans++, cnt3--, cnt2++;
			else cnt2++;
		}
		cnt3+=d/3;
	}
	cout << ans+cnt3 << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using INT = long long;

int power(int a, int b, int c, int ans=1) {
	for (; b; b>>=1, a=(INT)a*a%c) if (b&1) ans=(INT)ans*a%c;
	return ans;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n, d;
	cin>>n;
	INT ans=0, cnt1=0, cnt3=0;
	for (int i=0; i<n; i++) {
		scanf("%d", &d);
		if (cnt1>=3 && d>=6) {
			cnt1-=3; d-=6; cnt3+=3;
		}
		if (d%3==1) {
			if (d==1) cnt1++;
			else {
				d-=3;
				if (cnt1>1) {
					cnt3+=2; cnt1-=2;
				} else {
					cnt3++; cnt1++;
				}
			}
		}
		if (d%3==2) {
			if (cnt1) cnt3++, cnt1--;
			else cnt1+=2;
		}
		cnt3+=d/3;
	}
	cout << cnt3 << endl;

	return 0;
}


#include<bits/stdc++.h>
#define pb push_back
#define y second
#define x first

using namespace std;
typedef long long INT;
typedef pair<int, int> pii;
template<typename T, typename U> inline void smin(T &a, const U &b) {if(a>b) a=b;}
template<typename T, typename U> inline void smax(T &a, const U &b) {if(a<b) a=b;}

int main() {
#ifndef	ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n; scanf("%d", &n);
	INT pre=0, ans=0;
	while(n--) {
		int x; scanf("%d", &x);
		INT mn=min(pre, (INT)x>>1);
		ans+=mn, pre-=mn, x-=mn<<1;
		ans+=x/3, pre+=x%3;
	}
	printf("%I64d", ans);
}


#include <bits/stdc++.h>
#define pb push_back
#define x first
#define y second

using namespace std;
typedef long long INT;
typedef pair <int, int> pii;
typedef vector <int> VI;

#define NN 300300
int a[NN];

int main (){
#ifndef ONLINE_JUDGE
	freopen ("in.in", "r", stdin);
	freopen ("out.out", "w", stdout);
#endif

	int n;
	cin >> n;

	for(int i=0; i<n; i++) scanf("%d", a+i);

	INT st=0, ed=1LL<<60;
	while(ed-st>1){
		INT mid=st+ed>>1, rem=mid;
		INT tmp=0;
		for(int i=n; i--; ){
			int c=a[i]/2;
			if(c>rem) c=rem;
			rem-=c;
			tmp+=c;
			tmp=max(0LL, tmp-(a[i]-2*c));
		}
		if(tmp==0 && rem==0) st=mid;
		else ed=mid;
	}

	cout << st << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using INT = long long;

int power(int a, int b, int c, int ans=1) {
	for (; b; b>>=1, a=(INT)a*a%c) if (b&1) ans=(INT)ans*a%c;
	return ans;
}

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n, d;
	cin>>n;
	INT ans=0, cnt1=0, cnt2=0, cnt3=0;
	for (int i=0; i<n; i++) {
		scanf("%d", &d);
		if (d%3==1) {
			if (d==1) cnt1++;
			else {
				d-=3;
				if (cnt1>1) {
					ans+=2; cnt1-=2;
				} else if (cnt1) {
					ans++; cnt1--;
					if (cnt2) ans++, cnt2--, cnt1++;
					else if (cnt3) ans++, cnt3--, cnt2++;
					else cnt2++;
				} else {
					if (cnt2) ans+=2, cnt2--;
					else if (cnt3) ans+=2, cnt3--, cnt1++;
					else cnt3++, cnt1++;
				}
			}
		}
		if (d%3==2) {
			if (cnt1) ans++, cnt1--;
			else if (cnt2) ans++, cnt2--, cnt1++;
			else if (cnt3) ans++, cnt3--, cnt2++;
			else cnt2++;
		}
		cnt3+=d/3;
	}
	cout << ans+cnt3 << endl;

	return 0;
}


#include <bits/stdc++.h>

using namespace std;
using INT = long long;

int power(int a, int b, int c, int ans=1) {
	for (; b; b>>=1, a=(INT)a*a%c) if (b&1) ans=(INT)ans*a%c;
	return ans;
}

const int NN = 303030;

int a[NN];

int main() {
#ifndef ONLINE_JUDGE
	freopen("in.in", "r", stdin);
	freopen("out.out", "w", stdout);
#endif

	int n, d;
	cin>>n;
	INT pre2 = 0, ans = 0, pre4 = 0;
	for (int i=0; i<n; i++) scanf("%d", a+i);
	int cur = 0;
	for (int i=n-1; i>=cur; i--) {
		if (i==cur) {
			ans+=a[i]/3;
			break;
		}
		if (a[i]==1) continue;
		int u=a[i]/2;
		if (a[i]&1) ans++, a[i]-=3;
		u=a[i]/2;
		while (cur<i) {
			if (a[cur]<=u) {
				ans+=a[cur];
				u-=a[cur];
				a[cur]=0;
			} else {
				a[cur]-=u;
				ans+=u;
				break;
			}
			cur++;
		}
		if (cur==i) {
			ans+=u*2/3;
			break;
		}
	}
	cout << ans << endl;

	return 0;
}