#include<bits/stdc++.h>
#define forr(i,p,n) for(ll i=p;i<(ll)n;i++)
#define sorted(a) sort(a.begin(),a.end())
typedef long long ll;
using namespace std;
bool pr[10000005]={false};
vector<ll>prime;
void prim()
{
      pr[0]=true;
      pr[1]=true;
      for(ll i = 2;i <= sqrt(100005);i++)
      {
            for(ll j = i*2 ; j <= sqrt(100005) ; j += i)
            {
                  pr[j]=true;
            }
      }
}
vector<ll> divisor(ll n)
{
	vector<ll>div;
	div.push_back(n);
	for(ll i = 2 ; i*i <= n ; i++ )
	{
		if(n%i==0)
		{
			div.push_back(i);
			if(n/i!=i)
			div.push_back(n/i);
		}
	}
	sort(div.begin(),div.end());
	return div;
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
      x += m0;
    return x;
}
ll find(ll n)
{
	ll count = 0;
	while(n)
	{
		count++;
		n = n/2;
	}
	return count;
}
ll max1(ll a , ll b)
{
	if(a>b)
		return a;
	else
		return b;
}
ll min1(ll a , ll b)
{
	if(a<b)
		return a;
	else
		return b;
}

ll arr[100005];
ll n;
ll q;
void input() {
	cin>>n;
	forr(i,0,n)
		cin>>arr[i];

}

ll binary_search1( ll inc, ll dec , ll v0) {
	ll max = 1e18;
	ll min = -1e18;
	ll mid = (max+min)/2;
	ll bestAns = max;
	while(min<=max)
	{
		mid = (max+min)/2;
		ll temp = v0 - mid;
		ll mid2 = mid + inc;
		bestAns = min1(bestAns,max1(temp,mid2));
		if(temp<=mid2)
			max = mid-1;
		else
			min = mid+1;
	}
	return bestAns;
}

void solve() {
	input();
	ll inc= 0 ,dec=0;
	forr(i,0,n-1)
	{

		inc += max1(0,arr[i+1] - arr[i]);
		dec += max1(0,arr[i] - arr[i+1]);
	}
	//cout<<inc<<" "<<dec<<"\n";
	cout<<binary_search1(inc,dec,arr[0])<<"\n";
	//cout<<binary_search1(inc,dec,-1)<<"\n";
	ll q;
	cin>>q;
	while(q--)
	{
		ll l,r,x;
		cin>>l>>r>>x;
		l--;
		r--;
		//if(l==0)
		//	arr[l]+=x;
 		if(l!=0)
		{
		inc -= max1(0,arr[l] - arr[l-1]);
		dec -= max1(0,arr[l-1] - arr[l]);
 		}
 		if(r!=n-1){
 			inc -= max1(0,arr[r+1] - arr[r]);
			dec -= max1(0,arr[r] - arr[r+1]);
 		}
 		arr[l] += x;
		if(l!=r)
		arr[r] += x;
		if(l!=0)
		{
		inc += max1(0,arr[l] - arr[l-1]);
		dec += max1(0,arr[l-1] - arr[l]);
 		}
 		if(r!=n-1){
 			inc += max1(0,arr[r+1] - arr[r]);
			dec += max1(0,arr[r] - arr[r+1]);
 		}
		//cout<<inc<<" "<<dec<<"  "<<arr[0]<<"\n";
		cout<<binary_search1(inc,dec,arr[0])<<"\n";
	}

}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	// prim();
	// for(ll i = 2 ; i <= 100005 ; i++ )
	// {
	// 	if(pr[i]==false)
	// 	{

	// 		prime.push_back(i);
	// 	}
	// }
	//cout<<endl;
	ll t;
	//cin>>t;
	t = 1;
	while(t--){
		solve();
	}
	return 0;
}

// 1
// 1 4 1
// 1 4 1 16 1 4 1
//


#include<bits/stdc++.h>
#define forr(i,p,n) for(ll i=p;i<(ll)n;i++)
#define sorted(a) sort(a.begin(),a.end())
typedef long long ll;
using namespace std;
bool pr[10000005]={false};
vector<ll>prime;
void prim()
{
      pr[0]=true;
      pr[1]=true;
      for(ll i = 2;i <= sqrt(100005);i++)
      {
            for(ll j = i*2 ; j <= sqrt(100005) ; j += i)
            {
                  pr[j]=true;
            }
      }
}
vector<ll> divisor(ll n)
{
	vector<ll>div;
	div.push_back(n);
	for(ll i = 2 ; i*i <= n ; i++ )
	{
		if(n%i==0)
		{
			div.push_back(i);
			if(n/i!=i)
			div.push_back(n/i);
		}
	}
	sort(div.begin(),div.end());
	return div;
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
      x += m0;
    return x;
}
ll find(ll n)
{
	ll count = 0;
	while(n)
	{
		count++;
		n = n/2;
	}
	return count;
}
ll max1(ll a , ll b)
{
	if(a>b)
		return a;
	else
		return b;
}
ll min1(ll a , ll b)
{
	if(a<b)
		return a;
	else
		return b;
}

ll arr[100005];
ll n;
ll q;
void input() {
	cin>>n;
	forr(i,0,n)
		cin>>arr[i];

}

ll binary_search1( ll inc, ll dec , ll v0) {
	ll max = 1e18;
	ll min = -1e18;
	ll mid = (max+min)/2;
	ll bestAns = max;
	while(min<=max)
	{
		mid = (max+min)/2;
		ll temp = v0 - mid;
		ll mid2 = mid + inc;
		bestAns = min1(bestAns,max1(temp,mid2));
		if(temp<=mid2)
			max = mid-1;
		else
			min = mid+1;
	}
	return bestAns;
}
ll check(ll v0, ll inc) {
	return ceil((double)(v0+inc)/2.0);
}
void solve() {
	input();
	ll inc= 0 ,dec=0;
	forr(i,0,n-1)
	{

		inc += max1(0,arr[i+1] - arr[i]);
		dec += max1(0,arr[i] - arr[i+1]);
	}
	for(ll i=n-1;i>=0;--i)arr[i]=arr[i]-arr[i-1];
	//cout<<inc<<" "<<dec<<"\n";
	cout<<binary_search1(inc,dec,arr[0])<<"\n";
	//cout<<binary_search1(inc,dec,-1)<<"\n";
	ll q;
	cin>>q;
	while(q--)
	{
		ll l,r,x;
		cin>>l>>r>>x;
		l--;
		r--;
		//if(l==0)
		//	arr[l]+=x;
 		if(l==0)
 			arr[l]+=x;
 		else {
 			arr[l]>0?inc-=arr[l]:dec+=arr[l];
 			arr[l] += x;
			arr[l]>0?inc+=arr[l]:dec-=arr[l];
 		}
		if(r!=n-1)
		{
			arr[r+1]>0?inc-=arr[r+1]:dec+=arr[r+1];
 			arr[r+1] -= x;
			arr[r+1]>0?inc+=arr[r+1]:dec-=arr[r+1];
		}
		//cout<<inc<<" "<<dec<<"  "<<arr[0]<<"\n";
		//cout<<binary_search1(inc,dec,arr[0])<<"\n";
		cout<<check(arr[0],inc)<<"\n";
	}

}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	// prim();
	// for(ll i = 2 ; i <= 100005 ; i++ )
	// {
	// 	if(pr[i]==false)
	// 	{

	// 		prime.push_back(i);
	// 	}
	// }
	//cout<<endl;
	ll t;
	//cin>>t;
	t = 1;
	while(t--){
		solve();
	}
	return 0;
}

// 1
// 1 4 1
// 1 4 1 16 1 4 1
//


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class D {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int n=fs.nextInt();
		BIT bit=new BIT(n);
		for (int i=0; i<n; i++) bit.rangeUpdate(i, i, fs.nextInt());
		long dec=0, inc=0;
		for (int i=0; i+1<n; i++) {
			dec+=Math.max(0, bit.at(i)-bit.at(i+1));
			inc+=Math.max(0, bit.at(i+1)-bit.at(i));
		}
		PrintWriter out=new PrintWriter(System.out);
		out.println(solve(inc, dec, bit.at(0)));
		int q=fs.nextInt();
		for (int qq=0; qq<q; qq++) {
			int l=fs.nextInt()-1, r=fs.nextInt()-1, by=fs.nextInt();
			if (l!=0) {
				dec-=Math.max(0, bit.at(l-1)-bit.at(l));
				inc-=Math.max(0, bit.at(l)-bit.at(l-1));
			}
			if (r!=n-1) {
				dec-=Math.max(0, bit.at(r)-bit.at(r+1));
				inc-=Math.max(0, bit.at(r+1)-bit.at(r));
			}
			//TODO: range add
			bit.rangeUpdate(l, r, by);

			//TODO: add back in
			if (l!=0) {
				dec+=Math.max(0, bit.at(l-1)-bit.at(l));
				inc+=Math.max(0, bit.at(l)-bit.at(l-1));
			}
			if (r!=n-1) {
				dec+=Math.max(0, bit.at(r)-bit.at(r+1));
				inc+=Math.max(0, bit.at(r+1)-bit.at(r));
			}
			out.println(solve(inc, dec, bit.at(0)));
		}
		out.close();
	}

	static long solve(long inc, long dec, long v0) {
		long min=(long)-1e18, max=(long)1e18;
		long bestAns=max;
		while (min<=max) {
			long mid=(min+max)/2;
			long y=v0-mid;
			long mid2=mid+inc;
			long y2=y-dec;
			bestAns=Math.min(bestAns, Math.max(mid2, y2));
			if (mid2<y2) {
				min=mid+1;
			}
			else {
				max=mid-1;
			}
		}
		return bestAns;
	}

	static final Random random=new Random();

	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}

	static class BIT {
		int n;
		long[] tree;

		public BIT(int n) {
			this.n = n;
			tree = new long[n + 2];
		}

		long _read(int i) {
			i++;
			long sum = 0;
			while (i > 0) {
				sum += tree[i];
				i -= i & -i;
			}
			return sum;
		}

		void _update(int i, int val) {
			i++;
			while (i <= n) {
				tree[i] += val;
				i += i & -i;
			}
		}

		void rangeUpdate(int l, int r, int by) {
			_update(l, by);
			_update(r+1, -by);
		}

		long at(int at) {
			return _read(at);
		}

	}

	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}

		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

}


#include<bits/stdc++.h>
#define forr(i,p,n) for(ll i=p;i<(ll)n;i++)
#define sorted(a) sort(a.begin(),a.end())
typedef long long ll;
using namespace std;
bool pr[10000005]={false};
vector<ll>prime;
void prim()
{
      pr[0]=true;
      pr[1]=true;
      for(ll i = 2;i <= sqrt(100005);i++)
      {
            for(ll j = i*2 ; j <= sqrt(100005) ; j += i)
            {
                  pr[j]=true;
            }
      }
}
vector<ll> divisor(ll n)
{
	vector<ll>div;
	div.push_back(n);
	for(ll i = 2 ; i*i <= n ; i++ )
	{
		if(n%i==0)
		{
			div.push_back(i);
			if(n/i!=i)
			div.push_back(n/i);
		}
	}
	sort(div.begin(),div.end());
	return div;
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;
    if (m == 1)
      return 0;
    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }
    if (x < 0)
      x += m0;
    return x;
}
ll find(ll n)
{
	ll count = 0;
	while(n)
	{
		count++;
		n = n/2;
	}
	return count;
}
ll max1(ll a , ll b)
{
	if(a>b)
		return a;
	else
		return b;
}
ll min1(ll a , ll b)
{
	if(a<b)
		return a;
	else
		return b;
}

ll arr[100005];
ll n;
ll q;
void input() {
	cin>>n;
	forr(i,0,n)
		cin>>arr[i];

}

ll binary_search1( ll inc, ll dec , ll v0) {
	ll max = 1e18;
	ll min = -1e18;
	ll mid = (max+min)/2;
	ll bestAns = max;
	while(min<=max)
	{
		mid = (max+min)/2;
		ll temp = v0 - mid;
		ll mid2 = mid + inc;
		bestAns = min1(bestAns,max1(temp,mid2));
		if(temp<=mid2)
			max = mid-1;
		else
			min = mid+1;
	}
	return bestAns;
}
ll check(ll v0, ll inc) {
	return ceil((double)(v0+inc)/2.0);
}
void solve() {
	input();
	ll inc= 0 ,dec=0;
	forr(i,0,n-1)
	{

		inc += max1(0,arr[i+1] - arr[i]);
		dec += max1(0,arr[i] - arr[i+1]);
	}
	for(ll i=n-1;i>=0;--i)arr[i]=arr[i]-arr[i-1];
	//cout<<inc<<" "<<dec<<"\n";
	cout<<binary_search1(inc,dec,arr[0])<<"\n";
	//cout<<binary_search1(inc,dec,-1)<<"\n";
	ll q;
	cin>>q;
	while(q--)
	{
		ll l,r,x;
		cin>>l>>r>>x;
		l--;
		r--;
		//if(l==0)
		//	arr[l]+=x;
 		if(l==0)
 			arr[l]+=x;
 		else {
 			arr[l]>0?inc-=arr[l]:dec+=arr[l];
 			arr[l] += x;
			arr[l]>0?inc+=arr[l]:dec-=arr[l];
 		}
		if(r!=n-1)
		{
			arr[r+1]>0?inc-=arr[r+1]:dec+=arr[r+1];
 			arr[r+1] -= x;
			arr[r+1]>0?inc+=arr[r+1]:dec-=arr[r+1];
		}
		//cout<<inc<<" "<<dec<<"  "<<arr[0]<<"\n";
		//cout<<binary_search1(inc,dec,arr[0])<<"\n";
		cout<<binary_search1(inc,dec,arr[0])<<"\n";
	}

}

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	// prim();
	// for(ll i = 2 ; i <= 100005 ; i++ )
	// {
	// 	if(pr[i]==false)
	// 	{

	// 		prime.push_back(i);
	// 	}
	// }
	//cout<<endl;
	ll t;
	//cin>>t;
	t = 1;
	while(t--){
		solve();
	}
	return 0;
}

// 1
// 1 4 1
// 1 4 1 16 1 4 1
//


#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#define int long long
#define N 200010
using namespace std;
inline int read()
{
	int neg=1,num=0;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')neg=-1;
	for(;isdigit(c);c=getchar())num=(num<<1)+(num<<3)+c-'0';
	return neg*num;
}
int n,s,a[N],b[N],q;
inline int Solve()
{
	int x=(a[1]-s)/2,res=1ll<<60;
	for(int i=-10;i<=10;i++)
	{
		res=min(res,max(a[1]-x-i,x+i+s));
	}
	return res;
}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=2;i<=n;i++)b[i]=a[i]-a[i-1],s+=max(0ll,b[i]);
	q=read();
	printf("%lld\n",Solve());
	for(int i=1;i<=q;i++)
	{
		int l=read(),r=read(),x=read();
		if(l==1)a[1]+=x;
		if(l>1)s-=max(0ll,b[l]);b[l]+=x;s+=max(0ll,b[l]);
		if(r<n)s-=max(0ll,b[r+1]),b[r+1]-=x,s+=max(0ll,b[r+1]);
//		for(int i=2;i<=n;i++)printf("%lld ",b[i]);
//		putchar('\n');
		printf("%lld\n",Solve());
	}
	return 0;
}
/*
6
-9 -10 -9 -6 -5 4
3
2 6 -9
1 2 -10
4 6 -3

*/


#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#define int long long
#define N 200010
using namespace std;
inline int read()
{
	int neg=1,num=0;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')neg=-1;
	for(;isdigit(c);c=getchar())num=(num<<1)+(num<<3)+c-'0';
	return neg*num;
}
int n,s,a[N],b[N],q;
inline int Solve()
{
	int x=(a[1]-s)/2,res=1ll<<60;
	for(int i=-10;i<=10;i++)
	{
		res=min(res,max(a[1]-x-i,x+i+s));
	}
	return res;
}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=2;i<=n;i++)b[i]=a[i]-a[i-1],s+=max(0ll,b[i]);
	q=read();
	printf("%lld\n",Solve());
	for(int i=1;i<=q;i++)
	{
		int l=read(),r=read(),x=read();
		if(l==1)a[1]+=x;
		s-=max(0ll,b[l]);if(l>1)b[l]+=x;s+=max(0ll,b[l]);
		s-=max(0ll,b[r+1]);if(r<n)b[r+1]-=x;s+=max(0ll,b[r+1]);
//		for(int i=2;i<=n;i++)printf("%lld ",b[i]);
//		putchar('\n');
		printf("%lld\n",Solve());
	}
	return 0;
}
/*
6
-9 -10 -9 -6 -5 4
3
2 6 -9
1 2 -10
4 6 -3

*/


#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#define int long long
#define N 200010
using namespace std;
inline int read()
{
	int neg=1,num=0;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')neg=-1;
	for(;isdigit(c);c=getchar())num=(num<<1)+(num<<3)+c-'0';
	return neg*num;
}
int n,s,a[N],b[N],q;
inline int Solve()
{
	int x=(a[1]-s)/2,res=0;
	res=max(a[1]-x,x+s);
	res=min(res,max(a[1]-x-1,x+1+s));
	res=min(res,max(a[1]-x+1,x-1+s));
	return res;
}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=2;i<=n;i++)b[i]=a[i]-a[i-1],s+=max(0ll,b[i]);
	q=read();

	printf("%lld\n",Solve());
	for(int i=1;i<=q;i++)
	{
		int l=read(),r=read(),x=read();
		if(l==1)a[1]+=x;
		if(l>1)s-=max(0ll,b[l]);b[l]+=x;s+=max(0ll,b[l]);
		if(r<n)s-=max(0ll,b[r+1]),b[r+1]-=x,s+=max(0ll,b[r+1]);
//		for(int i=2;i<=n;i++)printf("%lld ",b[i]);
//		putchar('\n');
		printf("%lld\n",Solve());
	}
	return 0;
}
/*
6
-9 -10 -9 -6 -5 4
3
2 6 -9
1 2 -10
4 6 -3

*/


#include<iostream>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
#define int long long
#define N 200010
using namespace std;
inline int read()
{
	int neg=1,num=0;char c=getchar();
	for(;!isdigit(c);c=getchar())if(c=='-')neg=-1;
	for(;isdigit(c);c=getchar())num=(num<<1)+(num<<3)+c-'0';
	return neg*num;
}
int n,s,a[N],b[N],q;
inline int Solve()
{
	int x=(a[1]-s)/2,res=1ll<<60;
	for(int i=-1000;i<=1000;i++)
	{
		res=min(res,max(a[1]-x-i,x+i+s));
	}
	return res;
}
signed main()
{
	n=read();
	for(int i=1;i<=n;i++)a[i]=read();
	for(int i=2;i<=n;i++)b[i]=a[i]-a[i-1],s+=max(0ll,b[i]);
	q=read();
	printf("%lld\n",Solve());
	for(int i=1;i<=q;i++)
	{
		int l=read(),r=read(),x=read();
		if(l==1)a[1]+=x;
		if(l>1)s-=max(0ll,b[l]);b[l]+=x;s+=max(0ll,b[l]);
		if(r<n)s-=max(0ll,b[r+1]),b[r+1]-=x,s+=max(0ll,b[r+1]);
//		for(int i=2;i<=n;i++)printf("%lld ",b[i]);
//		putchar('\n');
		printf("%lld\n",Solve());
	}
	return 0;
}
/*
6
-9 -10 -9 -6 -5 4
3
2 6 -9
1 2 -10
4 6 -3

*/


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
ll K;
ll a[N],b[N];
ll f(){
	return ceil((double)(a[1]+K)/2.0);
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		if(i>1) b[i]=max(1ll*0,a[i]-a[i-1]),K+=b[i];
	}
	printf("%lld\n",f());
/*	if(n==1){
		int q;
		scanf("%d",&q);
		while(q--){
			int l,r;
			ll x;
			scanf("%d %d %lld",&l,&r,&x);
			a[1]+=x;
			printf("%")
		}
		return 0;
	}*/
	int q;
	scanf("%d",&q);
	while(q--){
		int l,r;
		ll x;
		scanf("%d %d %lld",&l,&r,&x);
		if(l==1) a[1]+=x;
		else{
			K-=max(1ll*0,b[l]);
			b[l]+=x;
			K+=max(1ll*0,b[l]);
		}
		if(r+1<=n){
			K-=max(1ll*0,b[r+1]);
			b[r+1]-=x;
			K+=max(1ll*0,b[r+1]);
		}
		printf("%lld\n",f());
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
typedef long long ll;
ll K;
ll a[N],b[N];
ll f(){
	return ceil((double)(a[1]+K)/2.0);
}
int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		if(i>1) b[i]=a[i]-a[i-1],K+=max(1ll*0,b[i]);
	}
	printf("%lld\n",f());
/*	if(n==1){
		int q;
		scanf("%d",&q);
		while(q--){
			int l,r;
			ll x;
			scanf("%d %d %lld",&l,&r,&x);
			a[1]+=x;
			printf("%")
		}
		return 0;
	}*/
	int q;
	scanf("%d",&q);
	while(q--){
		int l,r;
		ll x;
		scanf("%d %d %lld",&l,&r,&x);
		if(l==1) a[1]+=x;
		else{
			K-=max(1ll*0,b[l]);
			b[l]+=x;
			K+=max(1ll*0,b[l]);
		}
		if(r+1<=n){
			K-=max(1ll*0,b[r+1]);
			b[r+1]-=x;
			K+=max(1ll*0,b[r+1]);
		}
		printf("%lld\n",f());
	}
	return 0;
}


# include <iostream>
# include <cstdio>
# include <cmath>

typedef long long ll;

int n;
ll a[100002];
ll sumg, suml, a1, A, B, C, q;

ll check() {
	return ceil((double)(a1 + sumg) / 2.0);
}

void cg(ll x, ll y) {
	if (x > n) {
		return;
	}

	a[x] > 0 ? sumg -=a [x] : suml += a[x];
	a[x] += y;
	a[x] > 0 ? sumg += a[x] : suml -= a[x];
}

int main() {
	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
	}

	for (int i = 2; i <= n; i++) {
		if (a[i] > a[i-1]) {
			sumg += a[i] - a[i - 1];
		} else {
			suml += a[i-1] - a[i];
		}
	}

	for(int i = n; i; i--) {
		a[i] = a[i] - a[i - 1];
	}

	a1 = a[1];

	printf("%lld\n", check());
	scanf("%lld", &q);

	while (q--) {
		ll l, r, x;
		scanf("%lld%lld%lld", &l, &r, &x);

		if (l == 1) {
			a1 += x;
		} else {
			cg(l, x);
		}

		cg(r + 1, -x);

		printf("%lld\n", check());
	}

	return 0;
}


# include <iostream>
# include <cstdio>
# include <cmath>

typedef long long ll;

int n;
ll a[100002];
ll sumg, suml, a1;

ll check() {
	return ceil((double)(a1 + sumg) / 2.0);
}

void cg(ll x, ll y) {
	if (x > n) {
		return;
	}

	a[x] > 0 ? sumg -=a [x] : suml += a[x];
	a[x] += y;
	a[x] > 0 ? sumg += a[x] : suml -= a[x];
}

int main() {
	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
	}

	for (int i = 2; i <= n; i++) {
		if (a[i] > a[i-1]) {
			sumg += a[i] - a[i - 1];
		} else {
			suml += a[i-1] - a[i];
		}
	}

	for(int i = n; i; i--) {
		a[i] = a[i] - a[i - 1];
	}

	a1 = a[1];

	printf("%lld\n", check());

	int q;
	scanf("%d", &q);
	while (q--) {
		ll l, r, x;
		scanf("%lld%lld%lld", &l, &r, &x);

		if (l == 1) {
			a1 += x;
		} else {
			cg(l, x);
		}

		cg(r + 1, -x);

		printf("%lld\n", check());
	}

	return 0;
}


# include <iostream>
# include <cstdio>
# include <cmath>

typedef long long ll;

int n;
ll a[100002];
ll sumg, suml, a1, A, B, C, q;

ll check() {
	return ceil((double)(a1 + sumg) / 2.0);
}

void cg(ll x, ll y) {
	if (x > n) {
		return;
	}

	a[x] > 0 ? sumg -=a [x] : suml += a[x];
	a[x] += y;
	a[x] > 0 ? sumg += a[x] : suml -= a[x];
}

int main() {
	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
	}

	for(int i = 2; i <= n; i++) {
		if (a[i] > a[i-1]) {
			sumg += a[i] - a[i - 1];
		} else {
			suml += a[i-1] - a[i];
		}
	}

	for(int i=n; i; i--) {
		a[i]=a[i]-a[i-1];
	}

	a1=a[1];
	printf("%lld\n",check());
	scanf("%lld", &q);
	while(q--) {
		ll l, r, x;
		scanf("%lld%lld%lld", &l, &r, &x);

		if(l==1) {
			a1+=x;
		} else {
			cg(l,x);
		}

		cg(r+1,-x);

		printf("%lld\n",check());
	}

	return 0;
}


# include <iostream>
# include <cstdio>
# include <cmath>

typedef long long ll;

int n;
ll a[100002];
ll sumg, suml, a1, A, B, C, q;

ll check() {
	return ceil((double)(a1 + sumg) / 2.0);
}

void cg(ll x, ll y) {
	if (x > n) {
		return;
	}

	a[x] > 0 ? sumg -=a [x] : suml += a[x];
	a[x] += y;
	a[x] > 0 ? sumg += a[x] : suml -= a[x];
}

int main() {
	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}

	for(int i = 2; i <= n; i++) {
		if (a[i] > a[i-1]) {
			sumg += a[i] - a[i - 1];
		} else {
			suml += a[i-1] - a[i];
		}
	}

	for(int i=n; i; i--) {
		a[i]=a[i]-a[i-1];
	}

	a1=a[1];
	printf("%lld\n",check());
	scanf("%lld", &q);
	while(q--) {
		ll l, r, x;
		scanf("%lld%lld%lld", &l, &r, &x);

		if(l==1) {
			a1+=x;
		} else {
			cg(l,x);
		}

		cg(r+1,-x);

		printf("%lld\n",check());
	}

	return 0;
}


# include <iostream>
# include <cstdio>
# include <cmath>

typedef long long ll;

int n;
int a[100002];
ll sumg, suml, a1, A, B, C, q;

ll check() {
	return ceil((double)(a1 + sumg) / 2.0);
}

void cg(ll x, int y) {
	if (x > n) {
		return;
	}

	a[x] > 0 ? sumg -=a [x] : suml += a[x];
	a[x] += y;
	a[x] > 0 ? sumg += a[x] : suml -= a[x];
}

int main() {
	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}

	for(int i = 2; i <= n; i++) {
		if (a[i] > a[i-1]) {
			sumg += a[i] - a[i - 1];
		} else {
			suml += a[i-1] - a[i];
		}
	}

	for(int i=n; i; i--) {
		a[i]=a[i]-a[i-1];
	}

	a1=a[1];
	printf("%lld\n",check());
	scanf("%lld", &q);
	while(q--) {
		ll l, r, x;
		scanf("%lld%lld%lld", &l, &r, &x);

		if(l==1) {
			a1+=x;
		} else {
			cg(l,x);
		}

		cg(r+1,-x);

		printf("%lld\n",check());
	}

	return 0;
}


# include <iostream>
# include <cstdio>
# include <cmath>

typedef long long ll;

int n;
ll a[100002];
ll sumg, suml, a1, A, B, C;

ll check() {
	return ceil((double)(a1 + sumg) / 2.0);
}

void cg(ll x, ll y) {
	if (x > n) {
		return;
	}

	a[x] > 0 ? sumg -=a [x] : suml += a[x];
	a[x] += y;
	a[x] > 0 ? sumg += a[x] : suml -= a[x];
}

int main() {
	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%lld", &a[i]);
	}

	for (int i = 2; i <= n; i++) {
		if (a[i] > a[i-1]) {
			sumg += a[i] - a[i - 1];
		} else {
			suml += a[i-1] - a[i];
		}
	}

	for(int i = n; i; i--) {
		a[i] = a[i] - a[i - 1];
	}

	a1 = a[1];

	printf("%lld\n", check());

	int q;
	scanf("%d", &q);
	while (q--) {
		ll l, r, x;
		scanf("%lld%lld%lld", &l, &r, &x);

		if (l == 1) {
			a1 += x;
		} else {
			cg(l, x);
		}

		cg(r + 1, -x);

		printf("%lld\n", check());
	}

	return 0;
}


# include <iostream>
# include <cstdio>
# include <cmath>

typedef long long ll;

int n;
int a[100002];
ll sumg, suml, a1, A, B, C, q;

ll check() {
	return ceil((double)(a1 + sumg) / 2.0);
}

void cg(ll x, ll y) {
	if (x > n) {
		return;
	}

	a[x] > 0 ? sumg -=a [x] : suml += a[x];
	a[x] += y;
	a[x] > 0 ? sumg += a[x] : suml -= a[x];
}

int main() {
	scanf("%d", &n);

	for (int i = 1; i <= n; i++) {
		scanf("%d", &a[i]);
	}

	for(int i = 2; i <= n; i++) {
		if (a[i] > a[i-1]) {
			sumg += a[i] - a[i - 1];
		} else {
			suml += a[i-1] - a[i];
		}
	}

	for(int i=n; i; i--) {
		a[i]=a[i]-a[i-1];
	}

	a1=a[1];
	printf("%lld\n",check());
	scanf("%lld", &q);
	while(q--) {
		ll l, r, x;
		scanf("%lld%lld%lld", &l, &r, &x);

		if(l==1) {
			a1+=x;
		} else {
			cg(l,x);
		}

		cg(r+1,-x);

		printf("%lld\n",check());
	}

	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long a[100005],b[100005];
long long dd(long long xx)
{
	if(xx%2==1)return (xx+1)/2;
	return xx/2;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]),b[i]=a[i]-a[i-1];
	long long nn=b[1];
	for(int i=2;i<=n;i++)if(b[i]>0)nn+=b[i];
	printf("%lld\n",dd(nn));
	int q;
	cin>>q;
	while(q--)
	{
		int l,r,s;
		scanf("%d%d%d",&l,&r,&s);
		nn-=b[1];
		if(l>1&&b[l]>0)nn-=b[l];
		if(r<n&&b[r+1]>0)nn-=b[r+1];
		b[l]+=s,b[r+1]-=s;
		if(l>1&&b[l]>0)nn+=b[l];
		if(r<n&&b[r+1]>0)nn+=b[r+1];
		nn+=b[1];
		printf("%lld\n",dd(nn));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long a[100005],b[100005];
long long dd(long long xx)
{
	if(xx%2==1)return (xx+1)/2;
	return xx/2;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),b[i]=a[i]-a[i-1];
	long long nn=b[1];
	for(int i=2;i<=n;i++)if(b[i]>0)nn+=b[i];
	printf("%lld\n",dd(nn));
	int q;
	cin>>q;
	while(q--)
	{
		int l,r,s;
		scanf("%d%d%d",&l,&r,&s);
		nn-=b[1];
		if(l>1&&b[l]>0)nn-=b[l];
		if(r<n&&b[r+1]>0)nn-=b[r+1];
		b[l]+=s,b[r+1]-=s;
		if(l>1&&b[l]>0)nn+=b[l];
		if(r<n&&b[r+1]>0)nn+=b[r+1];
		nn+=b[1];
		printf("%lld\n",dd(nn));
	}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
int a[100005],b[100005];
long long dd(long long xx)
{
	if(xx%2==1)return (xx+1)/2;
	return xx/2;
}
int main()
{
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)scanf("%d",&a[i]),b[i]=a[i]-a[i-1];
	long long nn=b[1];
	for(int i=2;i<=n;i++)if(b[i]>0)nn+=b[i];
	printf("%lld\n",dd(nn));
	int q;
	cin>>q;
	while(q--)
	{
		int l,r,s;
		scanf("%d%d%d",&l,&r,&s);
		nn-=b[1];
		if(l>1&&b[l]>0)nn-=b[l];
		if(r<n&&b[r+1]>0)nn-=b[r+1];
		b[l]+=s,b[r+1]-=s;
		if(l>1&&b[l]>0)nn+=b[l];
		if(r<n&&b[r+1]>0)nn+=b[r+1];
		nn+=b[1];
		printf("%lld\n",dd(nn));
	}
	return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=1e5+10;
LL c[N],d[N];

int main() {
	ios::sync_with_stdio(0);
	int n; cin>>n;
	LL T=0;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		if(i>1)
			d[i]=c[i]-c[i-1];
		if(d[i]>0)
			T+=d[i];
	}
	cout<<max( (c[1]+T)/2, c[1]+T-(c[1]+T)/2 )<<endl;

//	cout<<"T is "<<T<<" 差分： "<<endl;
//		for(int i=1;i<=n;i++){
//			cout<<d[i]<<" ";
//		}
//		cout<<endl;

	int q; cin>>q;
	while(q--){
		int l,r,x; cin>>l>>r>>x;
		LL ll=d[l]+x,rr=d[r+1]-x;
		if(ll>=0){
			T+=ll;
			if(d[l]>0)
				T-=d[l];
		}
		if(d[r+1]>0){
			T-=d[r+1];
			if(rr>0)
				T+=rr;
		}
		if(l>1)
			d[l]=ll;
		else
			c[1]+=x;
		if(r+1<=n)
			d[r+1]=rr;

//		cout<<"T is "<<T<<" 差分： "<<endl;
//		for(int i=1;i<=n;i++){
//			cout<<d[i]<<" ";
//		}
//		cout<<endl;

		cout<<max( (c[1]+T)/2, c[1]+T-(c[1]+T)/2 )<<endl;
	}

    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=1e5+10;
LL c[N],d[N];

int main() {
	ios::sync_with_stdio(0);
	int n; cin>>n;
	LL T=0;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		if(i>1)
			d[i]=c[i]-c[i-1];
		if(d[i]>0)
			T+=d[i];
	}
	cout<<max( (c[1]+T)/2, c[1]+T-(c[1]+T)/2 )<<endl;

//	cout<<"T is "<<T<<" dis are  "<<endl;
//		for(int i=1;i<=n;i++){
//			cout<<d[i]<<" ";
//		}
//		cout<<endl;

	int q; cin>>q;
	while(q--){
		int l,r,x; cin>>l>>r>>x;
		LL ll=d[l]+x,rr=d[r+1]-x;
		if(d[l]>0)
			T-=d[l];
		if(d[r+1]>0)
			T-=d[r+1];
		if(ll>0)
			T+=ll;
		if(rr>0&&r+1<=n)
			T+=rr;
		if(l!=1) d[l]=ll;
		else c[1]+=x;
		if(r+1<=n) d[r+1]=rr;

//		cout<<"T is "<<T<<" dis are : "<<endl;
//		for(int i=1;i<=n;i++){
//			cout<<d[i]<<" ";
//		}
//		cout<<endl;

		 cout<<max( (c[1]+T)/2, c[1]+T-(c[1]+T)/2 )<<endl;
	}

    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=1e5+10;
LL c[N],d[N];

int main() {
	ios::sync_with_stdio(0);
	int n; cin>>n;
	LL T=0;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		if(i>1)
			d[i]=c[i]-c[i-1];
		else
			d[i]=c[i];
		if(d[i]>0 && i>1)
			T+=d[i];
	}
	int c1=c[1]; d[1]=c[1];
	cout<<max( (c1+T)/2, c1+T-(c1+T)/2)<<endl;
	int q; cin>>q;
	while(q--){
		int l,r,x; cin>>l>>r>>x;
		if(d[l]>0)
			T-=d[l];
		d[l]+=x;
		if(d[l]>0)
			T+=d[l];

		if(r+1<=n){
			if(d[r+1]>0) T-=d[r+1];
			d[r+1]-=x;
			if(d[r+1]>0) T+=d[r+1];
		}

		if(l==1) c1+=x;

//		cout<<"T is "<<T<<" dis are : "<<endl;
//		for(int i=1;i<=n;i++){
//			cout<<d[i]<<" ";
//		}
//		cout<<endl;

		cout<<max( (c1+T)/2, c1+T-(c1+T)/2)<<endl;
	}

    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=1e5+10;
LL c[N];

int main() {
	ios::sync_with_stdio(0);
	int n; cin>>n;
	LL T=0;
	for(int i=1;i<=n;i++){
		cin>>c[i];
	}
	for(int i=2;i<=n;i++)
		if(c[i]-c[i-1]>0)
			T+=c[i]-c[i-1];
	for(int i=n;i>=2;i--)
		c[i]-=c[i-1];
	LL c1=c[1];
	cout<<max( (c1+T)/2, c1+T-(c1+T)/2)<<endl;
	int q; cin>>q;
	while(q--){
		int l,r,x; cin>>l>>r>>x;

		if(l>1){
			if(c[l]>0)
				T-=c[l];
			c[l]+=x;
			if(c[l]>0)
				T+=c[l];
		}
		else
			c1+=x;

		if(r+1<=n){
			if(c[r+1]>0) T-=c[r+1];
			c[r+1]-=x;
			if(c[r+1]>0) T+=c[r+1];
		}

//		cout<<"T is "<<T<<" dis are : "<<endl;
//		for(int i=1;i<=n;i++){
//			cout<<d[i]<<" ";
//		}
//		cout<<endl;

		cout<<max( (c1+T)/2, c1+T-(c1+T)/2)<<endl;
	}

    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=1e5+10;
LL c[N],d[N];

int main() {
	ios::sync_with_stdio(0);
	int n; cin>>n;
	LL T=0;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		if(i>1)
			d[i]=c[i]-c[i-1];
		if(d[i]>0)
			T+=d[i];
	}
	cout<<max( (c[1]+T)/2, c[1]+T-(c[1]+T)/2 )<<endl;

//	cout<<"T is "<<T<<" dis are  "<<endl;
//		for(int i=1;i<=n;i++){
//			cout<<d[i]<<" ";
//		}
//		cout<<endl;

	int q; cin>>q;
	while(q--){
		int l,r,x; cin>>l>>r>>x;
		LL ll=d[l]+x,rr=d[r+1]-x;
		if(d[l]>0 && l!=1)
			T-=d[l];
		if(d[r+1]>0&&r+1<=n)
			T-=d[r+1];
		if(ll>0 && l!=1)
			T+=ll;
		if(rr>0&&r+1<=n)
			T+=rr;
		if(l!=1) d[l]=ll;
		else c[1]+=x;
		if(r+1<=n) d[r+1]=rr;

//		cout<<"T is "<<T<<" dis are : "<<endl;
//		for(int i=1;i<=n;i++){
//			cout<<d[i]<<" ";
//		}
//		cout<<endl;

		 cout<<max( (c[1]+T)/2, c[1]+T-(c[1]+T)/2 )<<endl;
	}

    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=1e5+10;
LL c[N],d[N];

int main() {
	ios::sync_with_stdio(0);
	int n; cin>>n;
	LL T=0;
	for(int i=1;i<=n;i++){
		cin>>c[i];
		if(i>1)
			d[i]=c[i]-c[i-1];
		if(d[i]>0)
			T+=d[i];
	}
	cout<<max( (c[1]+T)/2, c[1]+T-(c[1]+T)/2 )<<endl;

//	cout<<"T is "<<T<<" dis are  "<<endl;
//		for(int i=1;i<=n;i++){
//			cout<<d[i]<<" ";
//		}
//		cout<<endl;

	int q; cin>>q;
	while(q--){
		int l,r,x; cin>>l>>r>>x;
		LL ll=d[l]+x,rr=d[r+1]-x;
		if(d[l]>0)
			T-=d[l];
		if(d[r+1]>0&&r+1<=n)
			T-=d[r+1];
		if(ll>0)
			T+=ll;
		if(rr>0&&r+1<=n)
			T+=rr;
		if(l!=1) d[l]=ll;
		else c[1]+=x;
		if(r+1<=n) d[r+1]=rr;

//		cout<<"T is "<<T<<" dis are : "<<endl;
//		for(int i=1;i<=n;i++){
//			cout<<d[i]<<" ";
//		}
//		cout<<endl;

		 cout<<max( (c[1]+T)/2, c[1]+T-(c[1]+T)/2 )<<endl;
	}

    return 0;
}


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=1e5+10;
LL c[N];

int main() {
	ios::sync_with_stdio(0);
	int n; cin>>n;
	LL T=0;
	for(int i=1;i<=n;i++){
		cin>>c[i];
	}
	for(int i=2;i<=n;i++)
		if(c[i]-c[i-1]>0)
			T+=c[i]-c[i-1];
	for(int i=n;i>=2;i--)
		c[i]-=c[i-1];
	int c1=c[1];
	cout<<max( (c1+T)/2, c1+T-(c1+T)/2)<<endl;
	int q; cin>>q;
	while(q--){
		int l,r,x; cin>>l>>r>>x;
		if(c[l]>0)
			T-=c[l];
		c[l]+=x;
		if(c[l]>0)
			T+=c[l];

		if(r+1<=n){
			if(c[r+1]>0) T-=c[r+1];
			c[r+1]-=x;
			if(c[r+1]>0) T+=c[r+1];
		}

		if(l==1) c1+=x;

//		cout<<"T is "<<T<<" dis are : "<<endl;
//		for(int i=1;i<=n;i++){
//			cout<<d[i]<<" ";
//		}
//		cout<<endl;

		cout<<max( (c1+T)/2, c1+T-(c1+T)/2)<<endl;
	}

    return 0;
}


#include<cstdio>
#include<cmath>
#define re register
#define int long long
using namespace std;
inline int read(){
	re int t=0,f=0;re char v=getchar();
	while(v<'0')f|=(v=='-'),v=getchar();
	while(v>='0')t=(t<<3)+(t<<1)+v-48,v=getchar();
	return f?-t:t;
}
int n,a[100002],sumg,suml,a1,A,B,C,q;
inline int check(){
	return ceil((double)(a1+sumg)/2.0);
}
inline void cg(re int x,re int y){
	if(x>n)return;
	if(a[x]>0) sumg-=a[x];
	a[x]+=y;
	if(a[x]>0) sumg+=a[x];
}
signed main(){
	n=read();
	for(re int i=1;i<=n;++i)a[i]=read();
	for(re int i=2;i<=n;++i){
		if(a[i]>a[i-1])sumg+=a[i]-a[i-1];
	}
	for(re int i=n;i;--i)a[i]=a[i]-a[i-1];
	a1=a[1];
	printf("%lld\n",check());
	q=read();
	while(q--){
		re int l=read(),r=read(),x=read();
		if(l==1)a1+=x;
		else cg(l,x);
		cg(r+1,-x);
		printf("%lld\n",check());
	}
}


#include <cstdio>
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long LL;
const int N=1e5+10;
LL c[N];

int main() {
	ios::sync_with_stdio(0);
	int n; cin>>n;
	LL T=0;
	for(int i=1;i<=n;i++){
		cin>>c[i];
	}
	for(int i=2;i<=n;i++)
		if(c[i]-c[i-1]>0)
			T+=c[i]-c[i-1];
	for(int i=n;i>=2;i--)
		c[i]-=c[i-1];
	int c1=c[1];
	cout<<max( (c1+T)/2, c1+T-(c1+T)/2)<<endl;
	int q; cin>>q;
	while(q--){
		int l,r,x; cin>>l>>r>>x;

		if(l>1){
			if(c[l]>0)
				T-=c[l];
			c[l]+=x;
			if(c[l]>0)
				T+=c[l];
		}
		else
			c1+=x;

		if(r+1<=n){
			if(c[r+1]>0) T-=c[r+1];
			c[r+1]-=x;
			if(c[r+1]>0) T+=c[r+1];
		}

//		cout<<"T is "<<T<<" dis are : "<<endl;
//		for(int i=1;i<=n;i++){
//			cout<<d[i]<<" ";
//		}
//		cout<<endl;

		cout<<max( (c1+T)/2, c1+T-(c1+T)/2)<<endl;
	}

    return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,m,a[100010],sum[400010],del[100010],q;
void build(int o,int lf,int rg)
{
	if(lf==rg)
	{
		sum[o]=del[lf];
		return ;
	}
	int mid=(lf+rg)>>1;
	build(o<<1,lf,mid);
	build(o<<1|1,mid+1,rg);
	sum[o]=0;
	if(sum[o<<1]>0)
	{
		sum[o]+=sum[o<<1];
	}
	if(sum[o<<1|1]>0)
	{
		sum[o]+=sum[o<<1|1];
	}
}
void modify(int o,int lf,int rg,int w,int x)
{
	if(lf==rg)
	{
		sum[o]+=x;
		return ;
	}
	int mid=(lf+rg)>>1;
	if(w<=mid)
	{
		modify(o<<1,lf,mid,w,x);
	}
	if(mid<w)
	{
		modify(o<<1|1,mid+1,rg,w,x);
	}
	sum[o]=0;
	if(sum[o<<1]>0)
	{
		sum[o]+=sum[o<<1];
	}
	if(sum[o<<1|1]>0)
	{
		sum[o]+=sum[o<<1|1];
	}
}
int gans(int x)
{
	if(x>0)
	{
		return (x+1)/2;
	}
	else
	{
		x=-x;
		int qwq=(x+1)/2;
		if(qwq*2==x)
		{
			return -qwq;
		}
		else
		{
			return -(qwq-1);
		}
	}
}
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if(i>1)
		{
			del[i-1]=a[i]-a[i-1];
		}
	}
	if(n==1)
	{
	cin>>q;
		cout<<gans(a[1])<<"\n";
		while(q--){
			int l,r,x;
			scanf("%lld%lld%lld",&l,&r,&x);
			a[1]+=x;
			cout<<gans(a[1])<<"\n";
		}
		return 0;
	}
	build(1,1,n-1);
	cout<<gans((a[1]+max(0ll,sum[1])))<<"\n";
	cin>>q;
	while(q--)
	{
		int l,r,x;
		scanf("%lld%lld%lld",&l,&r,&x);
		if(l==1)
		{
			a[1]+=x;
		}
		if(l>1)
		{
			modify(1,1,n-1,l-1,x);
		}
		if(r<n)
		{
			modify(1,1,n-1,r,-x);
		}
		cout<<gans((a[1]+max(0ll,sum[1])))<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,m,a[100010],sum[400010],del[100010],q;
void build(int o,int lf,int rg)
{
	if(lf==rg)
	{
		sum[o]=del[lf];
		return ;
	}
	int mid=(lf+rg)>>1;
	build(o<<1,lf,mid);
	build(o<<1|1,mid+1,rg);
	sum[o]=0;
	if(sum[o<<1]>0)
	{
		sum[o]+=sum[o<<1];
	}
	if(sum[o<<1|1]>0)
	{
		sum[o]+=sum[o<<1|1];
	}
}
void modify(int o,int lf,int rg,int w,int x)
{
	if(lf==rg)
	{
		sum[o]+=x;
		return ;
	}
	int mid=(lf+rg)>>1;
	if(w<=mid)
	{
		modify(o<<1,lf,mid,w,x);
	}
	if(mid<w)
	{
		modify(o<<1|1,mid+1,rg,w,x);
	}
	sum[o]=0;
	if(sum[o<<1]>0)
	{
		sum[o]+=sum[o<<1];
	}
	if(sum[o<<1|1]>0)
	{
		sum[o]+=sum[o<<1|1];
	}
}
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if(i>1)
		{
			del[i-1]=a[i]-a[i-1];
		}
	}
	if(n==1)
	{
		cout<<a[1]<<"\n";
		while(q--){
			int l,r,x;
			scanf("%lld%lld%lld",&l,&r,&x);
			a[1]+=x;
			cout<<a[1]<<"\n";
		}
		return 0;
	}
	build(1,1,n-1);
	cout<<(a[1]+max(0ll,sum[1])+1)/2<<"\n";
	cin>>q;
	while(q--)
	{
		int l,r,x;
		scanf("%lld%lld%lld",&l,&r,&x);
		if(l==1)
		{
			a[1]+=x;
		}
		if(l>1)
		{
			modify(1,1,n-1,l-1,x);
		}
		if(r<n)
		{
			modify(1,1,n-1,r,-x);
		}
		cout<<(a[1]+max(0ll,sum[1])+1)/2<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,m,a[100010],sum[400010],del[100010],q;
void build(int o,int lf,int rg)
{
	if(lf==rg)
	{
		sum[o]=del[lf];
		return ;
	}
	int mid=(lf+rg)>>1;
	build(o<<1,lf,mid);
	build(o<<1|1,mid+1,rg);
	sum[o]=0;
	if(sum[o<<1]>0)
	{
		sum[o]+=sum[o<<1];
	}
	if(sum[o<<1|1]>0)
	{
		sum[o]+=sum[o<<1|1];
	}
}
void modify(int o,int lf,int rg,int w,int x)
{
	if(lf==rg)
	{
		sum[o]+=x;
		return ;
	}
	int mid=(lf+rg)>>1;
	if(w<=mid)
	{
		modify(o<<1,lf,mid,w,x);
	}
	if(mid<w)
	{
		modify(o<<1|1,mid+1,rg,w,x);
	}
	sum[o]=0;
	if(sum[o<<1]>0)
	{
		sum[o]+=sum[o<<1];
	}
	if(sum[o<<1|1]>0)
	{
		sum[o]+=sum[o<<1|1];
	}
}
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if(i>1)
		{
			del[i-1]=a[i]-a[i-1];
		}
	}
	if(n==1)
	{
	cin>>q;
		cout<<a[1]<<"\n";
		while(q--){
			int l,r,x;
			scanf("%lld%lld%lld",&l,&r,&x);
			a[1]+=x;
			cout<<a[1]<<"\n";
		}
		return 0;
	}
	build(1,1,n-1);
	cout<<(a[1]+max(0ll,sum[1])+1)/2<<"\n";
	cin>>q;
	while(q--)
	{
		int l,r,x;
		scanf("%lld%lld%lld",&l,&r,&x);
		if(l==1)
		{
			a[1]+=x;
		}
		if(l>1)
		{
			modify(1,1,n-1,l-1,x);
		}
		if(r<n)
		{
			modify(1,1,n-1,r,-x);
		}
		cout<<(a[1]+max(0ll,sum[1])+1)/2<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,m,a[100010],sum[400010],del[100010],q;
void build(int o,int lf,int rg)
{
	if(lf==rg)
	{
		sum[o]=del[lf];
		return ;
	}
	int mid=(lf+rg)>>1;
	build(o<<1,lf,mid);
	build(o<<1|1,mid+1,rg);
	sum[o]=0;
	if(sum[o<<1]>0)
	{
		sum[o]+=sum[o<<1];
	}
	if(sum[o<<1|1]>0)
	{
		sum[o]+=sum[o<<1|1];
	}
}
void modify(int o,int lf,int rg,int w,int x)
{
	if(lf==rg)
	{
		sum[o]+=x;
		return ;
	}
	int mid=(lf+rg)>>1;
	if(w<=mid)
	{
		modify(o<<1,lf,mid,w,x);
	}
	if(mid<w)
	{
		modify(o<<1|1,mid+1,rg,w,x);
	}
	sum[o]=0;
	if(sum[o<<1]>0)
	{
		sum[o]+=sum[o<<1];
	}
	if(sum[o<<1|1]>0)
	{
		sum[o]+=sum[o<<1|1];
	}
}
int gans(int x)
{
	if(x>0)
	{
		return (x+1)/2;
	}
	else
	{
		x=-x;
		int qwq=(x+1)/2;
		if(qwq*2==x)
		{
			return -qwq;
		}
		else
		{
			return -(qwq-1);
		}
	}
}
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if(i>1)
		{
			del[i-1]=a[i]-a[i-1];
		}
	}
	if(n==1)
	{
	cin>>q;
		cout<<gans(a[1])<<"\n";
		while(q--){
			int l,r,x;
			scanf("%lld%lld%lld",&l,&r,&x);
			a[1]+=x;
			cout<<gans(a[1])<<"\n";
		}
		return 0;
	}
	build(1,1,n-1);
	cout<<gans((a[1]+max(0ll,sum[1])+1))<<"\n";
	cin>>q;
	while(q--)
	{
		int l,r,x;
		scanf("%lld%lld%lld",&l,&r,&x);
		if(l==1)
		{
			a[1]+=x;
		}
		if(l>1)
		{
			modify(1,1,n-1,l-1,x);
		}
		if(r<n)
		{
			modify(1,1,n-1,r,-x);
		}
		cout<<gans((a[1]+max(0ll,sum[1])+1))<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define int long long
int n,m,a[100010],sum[400010],del[100010],q;
void build(int o,int lf,int rg)
{
	if(lf==rg)
	{
		sum[o]=del[lf];
		return ;
	}
	int mid=(lf+rg)>>1;
	build(o<<1,lf,mid);
	build(o<<1|1,mid+1,rg);
	sum[o]=0;
	if(sum[o<<1]>0)
	{
		sum[o]+=sum[o<<1];
	}
	if(sum[o<<1|1]>0)
	{
		sum[o]+=sum[o<<1|1];
	}
}
void modify(int o,int lf,int rg,int w,int x)
{
	if(lf==rg)
	{
		sum[o]+=x;
		return ;
	}
	int mid=(lf+rg)>>1;
	if(w<=mid)
	{
		modify(o<<1,lf,mid,w,x);
	}
	if(mid<w)
	{
		modify(o<<1|1,mid+1,rg,w,x);
	}
	sum[o]=0;
	if(sum[o<<1]>0)
	{
		sum[o]+=sum[o<<1];
	}
	if(sum[o<<1|1]>0)
	{
		sum[o]+=sum[o<<1|1];
	}
}
signed main()
{
	cin>>n;
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
		if(i>1)
		{
			del[i-1]=a[i]-a[i-1];
		}
	}
	cin>>q;
	if(n==1)
	{
		cout<<a[1]<<"\n";
		while(q--){
			int l,r,x;
			scanf("%lld%lld%lld",&l,&r,&x);
			a[1]+=x;
			cout<<a[1]<<"\n";
		}
		return 0;
	}
	build(1,1,n-1);
	cout<<(a[1]+max(0ll,sum[1])+1)/2<<"\n";
	cin>>q;
	while(q--)
	{
		int l,r,x;
		scanf("%lld%lld%lld",&l,&r,&x);
		if(l==1)
		{
			a[1]+=x;
		}
		if(l>1)
		{
			modify(1,1,n-1,l-1,x);
		}
		if(r<n)
		{
			modify(1,1,n-1,r,-x);
		}
		cout<<(a[1]+max(0ll,sum[1])+1)/2<<"\n";
	}
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
typedef long long ll;
typedef double db;
typedef pair<int,int> P;
typedef vector<int> VI;
const ll mod=1000000007;
const int maxn=3e5+10;
const int inf=0x3f3f3f3f;
ll gcd(ll a,ll b) {
    return b?gcd(b,a%b):a;
}
#define ms(a) memset(a,0,sizeof(a))
#define mss(a) memset(a,-1,sizeof(a))
#define msi(a) memset(a,inf,sizeof(a))
#define iossync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll n,a[maxn],b[maxn],c[maxn];
ll x,y,q,l,r;
int d[maxn],e[maxn];
int main()
{
	//增长 b
	//减少 c
	iossync
	cin>>n;
	rep(i,1,n+1)
	{
		cin>>a[i];
	}
	rep(i,1,n+1)
	{
		ll now=a[i]-a[i-1];
		b[i]=b[i-1];
		c[i]=c[i-1];
		if(now>0)
		{
			b[i]+=now;
		}
		else
		{
			c[i]+=now;
		}
	}
	ll ans=b[n]-c[1];
	ans/=2;
	cout<<b[n]-ans<<"\n";
	rep(i,1,n+1)
	{
		d[i]=b[i]-b[i-1];
		e[i]=c[i]-c[i-1];
	}
	//b[i]= d[i]+b[i-1]
	//b[i]=d[i]+d[i-1]+....+d[1]+b[0]
	cin>>q;
	while(q--)
	{
		cin>>l>>r>>x;
		if(x>0)
		{
//			rep(i,l,r+1)
//			{
//				b[i]+=x;
//			}
			d[l]+=x;
			d[r+1]-=x;
			ll w=0,s=0;
			rep(i,1,r+1)
			{
				w+=d[i];
			}
			s+=d[r+1];
//			if(r<n && b[r]>b[r+1])
			if(r<n && w>s)
			{
//				ll qwe=b[r]-b[r+1];
				ll qwe=w-s;
//				rep(i,r+1,n+1)
//				{
//					b[i]-=qwe;
//					c[i]+=qwe;
//				}
				d[r]-=qwe;
				d[n+1]+=qwe;
				e[r]+=qwe;
				e[n+1]-=qwe;
			}
		}
		else
		{
// 			rep(i,l,r+1)
//			{
//				c[i]+=x;
//			}
			e[l]+=x;
			e[r+1]-=x;
			ll w=0,s=0;
			rep(i,1,r+1)
			{
				w+=e[i];
			}
			s+=e[r+1];
//			if(r<n && c[r]<c[r+1])
			if(r<n && w<s)
			{
//				ll qwe=c[r]-c[r+1];
				ll qwe=w-s;
//				rep(i,r+1,n+1)
//				{
//					c[i]+=qwe;
//					b[i]-=qwe;
//				}
				e[r]+=qwe;
				e[n+1]-=qwe;
				d[r]-=qwe;
				d[n+1]+=qwe;
			}
		}
		ll w=0,s=0;
		w=d[1];
		ll w1=0,s1=0;
		w1=e[1];
		rep(i,2,n+1)
		{
//			if(b[i]-b[i-1]>=c[i-1]-c[i])
//			{
//				int qwe=b[i]-b[i-1];
//				rep(j,)
//			}
			s=w;
			w+=d[i];
			s1=w1;
			w1+=e[i];
//			if(b[i]-b[i-1])
			if(w>s)
			{
//				int qwe=min(b[i]-b[i-1],c[i-1]-c[i]);
				int qwe=min(w-s,s1-w1);
				d[i]-=qwe;
				d[n+1]+=qwe;
				e[i]+=qwe;
				e[n+1]-=qwe;
//				rep(j,i,n+1)
//				{
//					b[j]-=qwe;
//					c[j]+=qwe;
//				}
			}
		}
// 		ll w=0,s=e[1];
		w=0,s=e[1];
 		rep(i,1,n+1)
 		{
 			w+=d[i];
		}
		ans=w-s;
		ans/=2;
		cout<<w-ans<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for(int i=a;i<n;i++)
#define per(i,a,n) for(int i=n-1;i>=a;i--)
typedef long long ll;
typedef double db;
typedef pair<int,int> P;
typedef vector<int> VI;
const ll mod=1000000007;
const int maxn=3e5+10;
const int inf=0x3f3f3f3f;
ll gcd(ll a,ll b) {
    return b?gcd(b,a%b):a;
}
#define ms(a) memset(a,0,sizeof(a))
#define mss(a) memset(a,-1,sizeof(a))
#define msi(a) memset(a,inf,sizeof(a))
#define iossync ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll n,a[maxn],b[maxn],c[maxn];
ll x,y,q,l,r;
int main()
{
	//增长 b
	//减少 c
	cin>>n;
	rep(i,1,n+1)
	{
		cin>>a[i];
	}
	rep(i,1,n+1)
	{
		ll now=a[i]-a[i-1];
		b[i]=b[i-1];
		c[i]=c[i-1];
		if(now>0)
		{
			b[i]+=now;
		}
		else
		{
			c[i]+=now;
		}
	}
	ll ans=b[n]-c[1];
	ans/=2;
	cout<<b[n]-ans<<"\n";
	cin>>q;
	while(q--)
	{
		cin>>l>>r>>x;
		if(x>0)
		{
			rep(i,l,r+1)
			{
				b[i]+=x;
			}
			if(r<n && b[r]>b[r+1])
			{
				ll qwe=b[r]-b[r+1];
				rep(i,r+1,n+1)
				{
					b[i]-=qwe;
					c[i]+=qwe;
				}
			}
		}
		else
		{
			rep(i,l,r+1)
			{
				c[i]+=x;
			}
			if(r<n && c[r]<c[r+1])
			{
				ll qwe=c[r]-c[r+1];
				rep(i,r+1,n+1)
				{
					c[i]+=qwe;
					b[i]-=qwe;
				}
			}
		}
 		ans=b[n]-c[1];
		ans/=2;
		cout<<b[n]-ans<<"\n";
	}
	return 0;
}


#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;

ll getMid(ll s, ll e) { return s + (e -s)/2; }

ll getSumUtil(ll *st, ll ss, ll se, ll qs, ll qe, ll si)
{
	if (qs <= ss && qe >= se)
		return st[si];

	if (se < qs || ss > qe)
		return 0;

	ll mid = getMid(ss, se);
	return getSumUtil(st, ss, mid, qs, qe, 2*si+1) +
		getSumUtil(st, mid+1, se, qs, qe, 2*si+2);
}

void updateValueUtil(ll *st, ll ss, ll se, ll i, ll diff, ll si)
{
	if (i < ss || i > se)
		return;

	st[si] = st[si] + diff;
	if (se != ss)
	{
		int mid = getMid(ss, se);
		updateValueUtil(st, ss, mid, i, diff, 2*si + 1);
		updateValueUtil(st, mid+1, se, i, diff, 2*si + 2);
	}
}

void updateValue(ll arr[], ll *st, ll n, ll i, ll diff)
{
	if (i < 0 || i > n-1)
	{
		cout<<"Invalid Input";
		return;
	}

	updateValueUtil(st, 0, n-1, i, diff, 0);
}

ll getSum(ll *st, ll n, ll qs, ll qe)
{
	// Check for erroneous input values
	if (qs < 0 || qe > n-1 || qs > qe)
	{
		cout<<"Invalid Input";
		return -1;
	}

	return getSumUtil(st, 0, n-1, qs, qe, 0);
}

ll constructSTUtil(ll arr[], ll ss, ll se, ll *st, ll si)
{

	if (ss == se)
	{
		st[si] = arr[ss];
		return arr[ss];
	}

	ll mid = getMid(ss, se);
	st[si] = constructSTUtil(arr, ss, mid, st, si*2+1) +
			constructSTUtil(arr, mid+1, se, st, si*2+2);
	return st[si];
}

ll *constructST(ll arr[], ll n)
{

	ll x = (ll)(ceil(log2(n)));

	//Maximum size of segment tree
	ll max_size = 2*(ll)pow(2, x) - 1;

	// Allocate memory
	ll *st = new ll[max_size];

	// Fill the allocated memory st
	constructSTUtil(arr, 0, n-1, st, 0);

	// Return the constructed segment tree
	return st;
}

// Driver program to test above functions
int main()
{
	ll n,q,l,r,x;
	cin>>n;
	ll A[n],up[n],add=0,i,val1,val2,final=0;

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

	cin>>q;

	for(i=1;i<n;i++)
	{
	    if(A[i]>A[i-1])
	    add+=(A[i]-A[i-1]);
	}

	if((A[0]+add)%2==0)
	cout<<(A[0]+add)/2<<endl;
	else
	cout<<(A[0]+add)/2+1<<endl;

	ll *st = constructST(up, n);
	for(i=0;i<q;i++)
	{
	    cin>>l>>r>>x;
	    updateValue(up, st, n, l-1, x);
	    if(r<n)
	    updateValue(up, st, n, r, (0-x));

	    if(l>1)
	    {
	        if(A[l-1]>A[l-2])
    	    add-=(A[l-1]-A[l-2]);
    	    val1=getSum(st,n,0,l-1);
    	    val2=getSum(st,n,0,l-2);
    	    if((A[l-1]+val1)>(A[l-2]+val2))
    	    add+=(A[l-1]+val1-A[l-2]-val2);
	    }
	    //cout<<add<<" ";
	    if(n>1&&r>1&&r<n)
	    {
	        if(A[r]>A[r-1])
    	    add-=(A[r]-A[r-1]);
    	    val1=getSum(st,n,0,r);
    	    val2=getSum(st,n,0,r-1);
    	    if((A[r]+val1)>(A[r-1]+val2))
    	    add+=(A[r]+val1-val2-A[r-1]);
	    }
	    //cout<<add<<" ";

	    final=getSum(st,n,0,0);
	    //cout<<final<<" "<<endl;
	    if((A[0]+final+add)%2==0||(A[0]+final+add)<0)
	    cout<<(A[0]+final+add)/2<<endl;
	    else
	    cout<<(A[0]+final+add)/2+1<<endl;
	}

	return 0;
}
//This code is contributed by iman


// C++ program to show segment tree operations like construction, query
// and update
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// A utility function to get the middle index from corner indexes.
ll getMid(ll s, ll e) { return s + (e -s)/2; }

/* A recursive function to get the sum of values in the given range
	of the array. The following are parameters for this function.

	st --> Pointer to segment tree
	si --> Index of current node in the segment tree. Initially
			0 is passed as root is always at index 0
	ss & se --> Starting and ending indexes of the segment represented
				by current node, i.e., st[si]
	qs & qe --> Starting and ending indexes of query range */
ll getSumUtil(ll *st, ll ss, ll se, ll qs, ll qe, ll si)
{
	// If segment of this node is a part of given range, then return
	// the sum of the segment
	if (qs <= ss && qe >= se)
		return st[si];

	// If segment of this node is outside the given range
	if (se < qs || ss > qe)
		return 0;

	// If a part of this segment overlaps with the given range
	ll mid = getMid(ss, se);
	return getSumUtil(st, ss, mid, qs, qe, 2*si+1) +
		getSumUtil(st, mid+1, se, qs, qe, 2*si+2);
}

/* A recursive function to update the nodes which have the given
index in their range. The following are parameters
	st, si, ss and se are same as getSumUtil()
	i --> index of the element to be updated. This index is
			in the input array.
diff --> Value to be added to all nodes which have i in range */
void updateValueUtil(ll *st, ll ss, ll se, ll i, ll diff, ll si)
{
	// Base Case: If the input index lies outside the range of
	// this segment
	if (i < ss || i > se)
		return;

	// If the input index is in range of this node, then update
	// the value of the node and its children
	st[si] = st[si] + diff;
	if (se != ss)
	{
		int mid = getMid(ss, se);
		updateValueUtil(st, ss, mid, i, diff, 2*si + 1);
		updateValueUtil(st, mid+1, se, i, diff, 2*si + 2);
	}
}

// The function to update a value in input array and segment tree.
// It uses updateValueUtil() to update the value in segment tree
void updateValue(ll arr[], ll *st, ll n, ll i, ll new_val)
{
	// Check for erroneous input index
	if (i < 0 || i > n-1)
	{
		cout<<"Invalid Input";
		return;
	}

	// Get the difference between new value and old value
	ll diff = new_val - arr[i];

	// Update the value in array
	arr[i] = new_val;

	// Update the values of nodes in segment tree
	updateValueUtil(st, 0, n-1, i, diff, 0);
}

// Return sum of elements in range from index qs (quey start)
// to qe (query end). It mainly uses getSumUtil()
ll getSum(ll *st, ll n, ll qs, ll qe)
{
	// Check for erroneous input values
	if (qs < 0 || qe > n-1 || qs > qe)
	{
		cout<<"Invalid Input";
		return -1;
	}

	return getSumUtil(st, 0, n-1, qs, qe, 0);
}

// A recursive function that constructs Segment Tree for array[ss..se].
// si is index of current node in segment tree st
ll constructSTUtil(ll arr[], ll ss, ll se, ll *st, ll si)
{
	// If there is one element in array, store it in current node of
	// segment tree and return
	if (ss == se)
	{
		st[si] = arr[ss];
		return arr[ss];
	}

	// If there are more than one elements, then recur for left and
	// right subtrees and store the sum of values in this node
	ll mid = getMid(ss, se);
	st[si] = constructSTUtil(arr, ss, mid, st, si*2+1) +
			constructSTUtil(arr, mid+1, se, st, si*2+2);
	return st[si];
}

/* Function to construct segment tree from given array. This function
allocates memory for segment tree and calls constructSTUtil() to
fill the allocated memory */
ll *constructST(ll arr[], ll n)
{
	// Allocate memory for the segment tree

	//Height of segment tree
	ll x = (ll)(ceil(log2(n)));

	//Maximum size of segment tree
	ll max_size = 2*(ll)pow(2, x) - 1;

	// Allocate memory
	ll *st = new ll[max_size];

	// Fill the allocated memory st
	constructSTUtil(arr, 0, n-1, st, 0);

	// Return the constructed segment tree
	return st;
}

// Driver program to test above functions
int main()
{
	ll n,q,l,r,x;
	cin>>n;
	ll A[n],up[n],add=0,i,val1,val2,final=0;

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

	cin>>q;

	for(i=1;i<n;i++)
	{
	    if(A[i]>A[i-1])
	    add+=(A[i]-A[i-1]);
	}

	if((A[0]+add)%2==0)
	cout<<(A[0]+add)/2<<endl;
	else
	cout<<(A[0]+add)/2+1<<endl;

	ll *st = constructST(up, n);
	for(i=0;i<q;i++)
	{
	    cin>>l>>r>>x;
	    updateValue(up, st, n, l-1, x);
	    if(r<n)
	    updateValue(up, st, n, r, (0-x));

	    if(l>1)
	    {
	        if(A[l-1]>A[l-2])
    	    add-=(A[l-1]-A[l-2]);
    	    val1=getSum(st,n,0,l-1);
    	    val2=getSum(st,n,0,l-2);
    	    if((A[l-1]+val1)>(A[l-2]+val2))
    	    add+=(A[l-1]+val1-A[l-2]-val2);
	    }
	    //cout<<add<<" ";
	    if(n>1&&r>1&&r<n)
	    {
	        if(A[r]>A[r-1])
    	    add-=(A[r]-A[r-1]);
    	    val1=getSum(st,n,0,r);
    	    val2=getSum(st,n,0,r-1);
    	    if((A[r]+val1)>(A[r-1]+val2))
    	    add+=(A[r]+val1-val2-A[r-1]);
	    }
	    //cout<<add<<" ";

	    final=getSum(st,n,0,0);
	    //cout<<final<<" "<<endl;
	    if((A[0]+final+add)%2==0||(A[0]+final+add)<0)
	    cout<<(A[0]+final+add)/2<<endl;
	    else
	    cout<<(A[0]+final+add)/2+1<<endl;
	}

	return 0;
}
//This code is contributed by iman


// C++ program to show segment tree operations like construction, query
// and update
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// A utility function to get the middle index from corner indexes.
ll getMid(ll s, ll e) { return s + (e -s)/2; }

/* A recursive function to get the sum of values in the given range
	of the array. The following are parameters for this function.

	st --> Pointer to segment tree
	si --> Index of current node in the segment tree. Initially
			0 is passed as root is always at index 0
	ss & se --> Starting and ending indexes of the segment represented
				by current node, i.e., st[si]
	qs & qe --> Starting and ending indexes of query range */
ll getSumUtil(ll *st, ll ss, ll se, ll qs, ll qe, ll si)
{
	// If segment of this node is a part of given range, then return
	// the sum of the segment
	if (qs <= ss && qe >= se)
		return st[si];

	// If segment of this node is outside the given range
	if (se < qs || ss > qe)
		return 0;

	// If a part of this segment overlaps with the given range
	ll mid = getMid(ss, se);
	return getSumUtil(st, ss, mid, qs, qe, 2*si+1) +
		getSumUtil(st, mid+1, se, qs, qe, 2*si+2);
}

/* A recursive function to update the nodes which have the given
index in their range. The following are parameters
	st, si, ss and se are same as getSumUtil()
	i --> index of the element to be updated. This index is
			in the input array.
diff --> Value to be added to all nodes which have i in range */
void updateValueUtil(ll *st, ll ss, ll se, ll i, ll diff, ll si)
{
	// Base Case: If the input index lies outside the range of
	// this segment
	if (i < ss || i > se)
		return;

	// If the input index is in range of this node, then update
	// the value of the node and its children
	st[si] = st[si] + diff;
	if (se != ss)
	{
		int mid = getMid(ss, se);
		updateValueUtil(st, ss, mid, i, diff, 2*si + 1);
		updateValueUtil(st, mid+1, se, i, diff, 2*si + 2);
	}
}

// The function to update a value in input array and segment tree.
// It uses updateValueUtil() to update the value in segment tree
void updateValue(ll arr[], ll *st, ll n, ll i, ll new_val)
{
	// Check for erroneous input index
	if (i < 0 || i > n-1)
	{
		cout<<"Invalid Input";
		return;
	}

	// Get the difference between new value and old value
	ll diff = new_val - arr[i];

	// Update the value in array
	arr[i] = new_val;

	// Update the values of nodes in segment tree
	updateValueUtil(st, 0, n-1, i, diff, 0);
}

// Return sum of elements in range from index qs (quey start)
// to qe (query end). It mainly uses getSumUtil()
ll getSum(ll *st, ll n, ll qs, ll qe)
{
	// Check for erroneous input values
	if (qs < 0 || qe > n-1 || qs > qe)
	{
		cout<<"Invalid Input";
		return -1;
	}

	return getSumUtil(st, 0, n-1, qs, qe, 0);
}

// A recursive function that constructs Segment Tree for array[ss..se].
// si is index of current node in segment tree st
ll constructSTUtil(ll arr[], ll ss, ll se, ll *st, ll si)
{
	// If there is one element in array, store it in current node of
	// segment tree and return
	if (ss == se)
	{
		st[si] = arr[ss];
		return arr[ss];
	}

	// If there are more than one elements, then recur for left and
	// right subtrees and store the sum of values in this node
	ll mid = getMid(ss, se);
	st[si] = constructSTUtil(arr, ss, mid, st, si*2+1) +
			constructSTUtil(arr, mid+1, se, st, si*2+2);
	return st[si];
}

/* Function to construct segment tree from given array. This function
allocates memory for segment tree and calls constructSTUtil() to
fill the allocated memory */
ll *constructST(ll arr[], ll n)
{
	// Allocate memory for the segment tree

	//Height of segment tree
	ll x = (ll)(ceil(log2(n)));

	//Maximum size of segment tree
	ll max_size = 2*(ll)pow(2, x) - 1;

	// Allocate memory
	ll *st = new ll[max_size];

	// Fill the allocated memory st
	constructSTUtil(arr, 0, n-1, st, 0);

	// Return the constructed segment tree
	return st;
}

// Driver program to test above functions
int main()
{
	ll n,q,l,r,x;
	cin>>n;
	ll A[n],up[n],add=0,i,val1,val2,final;

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

	cin>>q;

	for(i=1;i<n;i++)
	{
	    if(A[i]>A[i-1])
	    add+=(A[i]-A[i-1]);
	}

	if((A[0]+add)%2==0)
	cout<<(A[0]+add)/2<<endl;
	else
	cout<<(A[0]+add)/2+1<<endl;

	ll *st = constructST(up, n);
	for(i=0;i<q;i++)
	{
	    cin>>l>>r>>x;
	    updateValue(up, st, n, l-1, x);
	    if(r<n)
	    updateValue(up, st, n, r, -x);

	    if(l>1)
	    {
	        if(A[l-1]>A[l-2])
    	    add-=(A[l-1]-A[l-2]);
    	    val1=getSum(st,n,0,l-1);
    	    val2=getSum(st,n,0,l-2);
    	    if((A[l-1]+val1)>(A[l-2]+val2))
    	    add+=(A[l-1]+val1-A[l-2]-val2);
	    }
	    //cout<<add<<" ";
	    if(n>1&&r>1&&r<n)
	    {
	        if(A[r]>A[r-1])
    	    add-=(A[r]-A[r-1]);
    	    val1=getSum(st,n,0,r);
    	    val2=getSum(st,n,0,r-1);
    	    if((A[r]+val1)>(A[r-1]+val2))
    	    add+=(A[r]+val1-val2-A[r-1]);
	    }
	    //cout<<add<<" ";

	    final=(getSum(st,n,0,0)+add);
	    //cout<<final<<" "<<endl;
	    if((A[0]+add)%2==0||(A[0]+add)<0)
	    cout<<(A[0]+final)/2<<endl;
	    else
	    cout<<(A[0]+final)/2+1<<endl;
	}

	return 0;
}
//This code is contributed by iman


// C++ program to show segment tree operations like construction, query
// and update
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// A utility function to get the middle index from corner indexes.
ll getMid(ll s, ll e) { return s + (e -s)/2; }

/* A recursive function to get the sum of values in the given range
	of the array. The following are parameters for this function.

	st --> Pointer to segment tree
	si --> Index of current node in the segment tree. Initially
			0 is passed as root is always at index 0
	ss & se --> Starting and ending indexes of the segment represented
				by current node, i.e., st[si]
	qs & qe --> Starting and ending indexes of query range */
ll getSumUtil(ll *st, ll ss, ll se, ll qs, ll qe, ll si)
{
	// If segment of this node is a part of given range, then return
	// the sum of the segment
	if (qs <= ss && qe >= se)
		return st[si];

	// If segment of this node is outside the given range
	if (se < qs || ss > qe)
		return 0;

	// If a part of this segment overlaps with the given range
	ll mid = getMid(ss, se);
	return getSumUtil(st, ss, mid, qs, qe, 2*si+1) +
		getSumUtil(st, mid+1, se, qs, qe, 2*si+2);
}

/* A recursive function to update the nodes which have the given
index in their range. The following are parameters
	st, si, ss and se are same as getSumUtil()
	i --> index of the element to be updated. This index is
			in the input array.
diff --> Value to be added to all nodes which have i in range */
void updateValueUtil(ll *st, ll ss, ll se, ll i, ll diff, ll si)
{
	// Base Case: If the input index lies outside the range of
	// this segment
	if (i < ss || i > se)
		return;

	// If the input index is in range of this node, then update
	// the value of the node and its children
	st[si] = st[si] + diff;
	if (se != ss)
	{
		int mid = getMid(ss, se);
		updateValueUtil(st, ss, mid, i, diff, 2*si + 1);
		updateValueUtil(st, mid+1, se, i, diff, 2*si + 2);
	}
}

// The function to update a value in input array and segment tree.
// It uses updateValueUtil() to update the value in segment tree
void updateValue(ll arr[], ll *st, ll n, ll i, ll new_val)
{
	// Check for erroneous input index
	if (i < 0 || i > n-1)
	{
		cout<<"Invalid Input";
		return;
	}

	// Get the difference between new value and old value
	ll diff = new_val - arr[i];

	// Update the value in array
	arr[i] = new_val;

	// Update the values of nodes in segment tree
	updateValueUtil(st, 0, n-1, i, diff, 0);
}

// Return sum of elements in range from index qs (quey start)
// to qe (query end). It mainly uses getSumUtil()
ll getSum(ll *st, ll n, ll qs, ll qe)
{
	// Check for erroneous input values
	if (qs < 0 || qe > n-1 || qs > qe)
	{
		cout<<"Invalid Input";
		return -1;
	}

	return getSumUtil(st, 0, n-1, qs, qe, 0);
}

// A recursive function that constructs Segment Tree for array[ss..se].
// si is index of current node in segment tree st
ll constructSTUtil(ll arr[], ll ss, ll se, ll *st, ll si)
{
	// If there is one element in array, store it in current node of
	// segment tree and return
	if (ss == se)
	{
		st[si] = arr[ss];
		return arr[ss];
	}

	// If there are more than one elements, then recur for left and
	// right subtrees and store the sum of values in this node
	ll mid = getMid(ss, se);
	st[si] = constructSTUtil(arr, ss, mid, st, si*2+1) +
			constructSTUtil(arr, mid+1, se, st, si*2+2);
	return st[si];
}

/* Function to construct segment tree from given array. This function
allocates memory for segment tree and calls constructSTUtil() to
fill the allocated memory */
ll *constructST(ll arr[], ll n)
{
	// Allocate memory for the segment tree

	//Height of segment tree
	ll x = (ll)(ceil(log2(n)));

	//Maximum size of segment tree
	ll max_size = 2*(ll)pow(2, x) - 1;

	// Allocate memory
	ll *st = new ll[max_size];

	// Fill the allocated memory st
	constructSTUtil(arr, 0, n-1, st, 0);

	// Return the constructed segment tree
	return st;
}

// Driver program to test above functions
int main()
{
	ll n,q,l,r,x;
	cin>>n;
	ll A[n],up[n],add=0,i,val1,val2;

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

	cin>>q;

	for(i=1;i<n;i++)
	{
	    if(A[i]>A[i-1])
	    add+=(A[i]-A[i-1]);
	}

	if((A[0]+add)%2==0)
	cout<<(A[0]+add)/2<<endl;
	else
	cout<<(A[0]+add)/2+1<<endl;

	ll *st = constructST(up, n);
	for(i=0;i<q;i++)
	{
	    cin>>l>>r>>x;
	    updateValue(up, st, n, l-1, x);
	    if(r<n)
	    updateValue(up, st, n, r, -x);

	    if(l>1)
	    {
	        if(A[l-1]>A[l-2])
    	    add-=(A[l-1]-A[l-2]);
    	    val1=getSum(st,n,0,l-1);
    	    val2=getSum(st,n,0,l-2);
    	    if((A[l-1]+val1)>(A[l-2]+val2))
    	    add+=(A[l-1]+val1-A[l-2]-val2);
	    }
	    //cout<<add<<" ";
	    if(n>1&&r>1&&r<n)
	    {
	        if(A[r]>A[r-1])
    	    add-=(A[r]-A[r-1]);
    	    val1=getSum(st,n,0,r);
    	    val2=getSum(st,n,0,r-1);
    	    if((A[r]+val1)>(A[r-1]+val2))
    	    add+=(A[r]+val1-val2-A[r-1]);
	    }
	    //cout<<add<<" ";
	    add+=getSum(st,n,0,0);;
	    //cout<<add<<" "<<endl;
	    if((A[0]+add)%2==0||(A[0]+add)<0)
	    cout<<(A[0]+add)/2<<endl;
	    else
	    cout<<(A[0]+add)/2+1<<endl;
	}

	return 0;
}
//This code is contributed by iman


// C++ program to show segment tree operations like construction, query
// and update
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
// A utility function to get the middle index from corner indexes.
ll getMid(ll s, ll e) { return s + (e -s)/2; }

/* A recursive function to get the sum of values in the given range
	of the array. The following are parameters for this function.

	st --> Pointer to segment tree
	si --> Index of current node in the segment tree. Initially
			0 is passed as root is always at index 0
	ss & se --> Starting and ending indexes of the segment represented
				by current node, i.e., st[si]
	qs & qe --> Starting and ending indexes of query range */
ll getSumUtil(ll *st, ll ss, ll se, ll qs, ll qe, ll si)
{
	// If segment of this node is a part of given range, then return
	// the sum of the segment
	if (qs <= ss && qe >= se)
		return st[si];

	// If segment of this node is outside the given range
	if (se < qs || ss > qe)
		return 0;

	// If a part of this segment overlaps with the given range
	ll mid = getMid(ss, se);
	return getSumUtil(st, ss, mid, qs, qe, 2*si+1) +
		getSumUtil(st, mid+1, se, qs, qe, 2*si+2);
}

/* A recursive function to update the nodes which have the given
index in their range. The following are parameters
	st, si, ss and se are same as getSumUtil()
	i --> index of the element to be updated. This index is
			in the input array.
diff --> Value to be added to all nodes which have i in range */
void updateValueUtil(ll *st, ll ss, ll se, ll i, ll diff, ll si)
{
	// Base Case: If the input index lies outside the range of
	// this segment
	if (i < ss || i > se)
		return;

	// If the input index is in range of this node, then update
	// the value of the node and its children
	st[si] = st[si] + diff;
	if (se != ss)
	{
		int mid = getMid(ss, se);
		updateValueUtil(st, ss, mid, i, diff, 2*si + 1);
		updateValueUtil(st, mid+1, se, i, diff, 2*si + 2);
	}
}

// The function to update a value in input array and segment tree.
// It uses updateValueUtil() to update the value in segment tree
void updateValue(ll arr[], ll *st, ll n, ll i, ll new_val)
{
	// Check for erroneous input index
	if (i < 0 || i > n-1)
	{
		cout<<"Invalid Input";
		return;
	}

	// Get the difference between new value and old value
	ll diff = new_val - arr[i];

	// Update the value in array
	arr[i] = new_val;

	// Update the values of nodes in segment tree
	updateValueUtil(st, 0, n-1, i, diff, 0);
}

// Return sum of elements in range from index qs (quey start)
// to qe (query end). It mainly uses getSumUtil()
ll getSum(ll *st, ll n, ll qs, ll qe)
{
	// Check for erroneous input values
	if (qs < 0 || qe > n-1 || qs > qe)
	{
		cout<<"Invalid Input";
		return -1;
	}

	return getSumUtil(st, 0, n-1, qs, qe, 0);
}

// A recursive function that constructs Segment Tree for array[ss..se].
// si is index of current node in segment tree st
ll constructSTUtil(ll arr[], ll ss, ll se, ll *st, ll si)
{
	// If there is one element in array, store it in current node of
	// segment tree and return
	if (ss == se)
	{
		st[si] = arr[ss];
		return arr[ss];
	}

	// If there are more than one elements, then recur for left and
	// right subtrees and store the sum of values in this node
	ll mid = getMid(ss, se);
	st[si] = constructSTUtil(arr, ss, mid, st, si*2+1) +
			constructSTUtil(arr, mid+1, se, st, si*2+2);
	return st[si];
}

/* Function to construct segment tree from given array. This function
allocates memory for segment tree and calls constructSTUtil() to
fill the allocated memory */
ll *constructST(ll arr[], ll n)
{
	// Allocate memory for the segment tree

	//Height of segment tree
	ll x = (ll)(ceil(log2(n)));

	//Maximum size of segment tree
	ll max_size = 2*(ll)pow(2, x) - 1;

	// Allocate memory
	ll *st = new ll[max_size];

	// Fill the allocated memory st
	constructSTUtil(arr, 0, n-1, st, 0);

	// Return the constructed segment tree
	return st;
}

// Driver program to test above functions
int main()
{
	ll n,q,l,r,x;
	cin>>n;
	ll A[n],up[n],add=0,i,val1,val2,final=0;

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

	cin>>q;

	for(i=1;i<n;i++)
	{
	    if(A[i]>A[i-1])
	    add+=(A[i]-A[i-1]);
	}

	if((A[0]+add)%2==0)
	cout<<(A[0]+add)/2<<endl;
	else
	cout<<(A[0]+add)/2+1<<endl;

	ll *st = constructST(up, n);
	for(i=0;i<q;i++)
	{
	    cin>>l>>r>>x;
	    updateValue(up, st, n, l-1, x);
	    if(r<n)
	    updateValue(up, st, n, r, -x);

	    if(l>1)
	    {
	        if(A[l-1]>A[l-2])
    	    add-=(A[l-1]-A[l-2]);
    	    val1=getSum(st,n,0,l-1);
    	    val2=getSum(st,n,0,l-2);
    	    if((A[l-1]+val1)>(A[l-2]+val2))
    	    add+=(A[l-1]+val1-A[l-2]-val2);
	    }
	    //cout<<add<<" ";
	    if(n>1&&r>1&&r<n)
	    {
	        if(A[r]>A[r-1])
    	    add-=(A[r]-A[r-1]);
    	    val1=getSum(st,n,0,r);
    	    val2=getSum(st,n,0,r-1);
    	    if((A[r]+val1)>(A[r-1]+val2))
    	    add+=(A[r]+val1-val2-A[r-1]);
	    }
	    //cout<<add<<" ";

	    final+=getSum(st,n,0,0);
	    //cout<<final<<" "<<endl;
	    if((A[0]+final+add)%2==0||(A[0]+final+add)<0)
	    cout<<(A[0]+final+add)/2<<endl;
	    else
	    cout<<(A[0]+final+add)/2+1<<endl;
	}

	return 0;
}
//This code is contributed by iman


#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define _for(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long ll;
using namespace std;
const int maxn = 1e5+5;
int a[maxn];
ll sumg = 0,suml = 0;
int n;
void cg(int x,int y){
	if(x>n)return;
	if(a[x]>0) sumg-=a[x];
	a[x]+=y;
	if(a[x]>0) sumg+=a[x];
}
int main(){
    cin>>n;
    _for(i,1,n){
        cin>>a[i];
        if(i>=2){
            if(a[i]-a[i-1]>0) sumg += a[i]-a[i-1];
            //else suml += a[i-1]-a[i];
        }
    }
    for(int i=n;i>0;i--) a[i] = a[i] - a[i-1];
    int a1 = a[1];
    ll ans = (ll)ceil((double)(a1+sumg)/2.0);
    cout<<ans<<endl;
    int q;
    cin>>q;
    _for(i,1,q){
        int l,r,x;
        cin>>l>>r>>x;
        if(l==1) a1+=x;
        else {
            cg(l,x);
        }
        cg(r+1,-x);
        //cout<<c[l]<<' '<<c[r+1]<<endl;
        ll ans = (ll)ceil((double)(a1+sumg)/2.0);
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define _for(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long ll;
using namespace std;
const int maxn = 1e5+5;
ll a[maxn];
ll sumg = 0,suml = 0;
int n;
void cg(int x,ll y){
	if(x>n)return;
	if(a[x]>0) sumg-=a[x];
	a[x]+=y;
	if(a[x]>0) sumg+=a[x];
}
int main(){
    IOS
    cin>>n;
    _for(i,1,n){
        cin>>a[i];
        if(i>=2){
            if(a[i]-a[i-1]>0) sumg += a[i]-a[i-1];
            //else suml += a[i-1]-a[i];
        }
    }
    for(int i=n;i;i--) a[i] = a[i] - a[i-1];
    ll a1 = a[1];
    ll ans = (ll)ceil((double)(a1+sumg)/2.0);
    cout<<ans<<endl;
    int q;
    cin>>q;
    _for(i,1,q){
        int l,r;
        ll x;
        cin>>l>>r>>x;
        if(l==1) a1+=x;
        else {
            cg(l,x);
        }
        cg(r+1,-x);
        //cout<<c[l]<<' '<<c[r+1]<<endl;
        ll ans = (ll)ceil((double)(a1+sumg)/2.0);
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define _for(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long ll;
using namespace std;
const int maxn = 1e5+5;
int a[maxn];
int c[maxn];//差分数组
int main(){
    int n;
    cin>>n;
    ll sum = 0;
    _for(i,1,n){
        cin>>a[i];
        if(i>=2){
            c[i] = a[i]-a[i-1];
            sum += max(0,c[i]);
        }
    }
    ll ans  = 0;
    ans = (a[1]+sum)/2;
    cout<<ans<<endl;
    int q;
    cin>>q;
    _for(i,1,q){
        int l,r,x;
        cin>>l>>r>>x;
        if(r==n) sum = sum - (max(0,c[l]));
        else sum = sum - (max(0,c[l]) + max(0,c[r+1]));

        //cout<<c[l]<<' '<<c[r+1]<<endl;
        c[l] += x;//差分修改
        c[r+1] -= x;

        if(r==n) sum = sum + (max(0,c[l]));
        else sum = sum + (max(0,c[l]) + max(0,c[r+1]));

        //cout<<c[l]<<' '<<c[r+1]<<endl;
        ans = (a[1]+sum)/2;
        cout<<ans<<endl;
    }
}


#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define _for(i,a,b) for(int i=(a);i<=(b);i++)
typedef long long ll;
using namespace std;
const int maxn = 1e5+5;
ll a[maxn];
ll sumg = 0,suml = 0;
int n;
void cg(int x,ll y){
	if(x>n)return;
	if(a[x]>0) sumg-=a[x];
	a[x]+=y;
	if(a[x]>0) sumg+=a[x];
}
int main(){
    IOS
    cin>>n;
    _for(i,1,n){
        cin>>a[i];
        if(i>=2){
            if(a[i]-a[i-1]>0) sumg += a[i]-a[i-1];
            //else suml += a[i-1]-a[i];
        }
    }
    for(int i=n;i>0;i--) a[i] = a[i] - a[i-1];
    int a1 = a[1];
    ll ans = (ll)ceil((double)(a1+sumg)/2.0);
    cout<<ans<<endl;
    int q;
    cin>>q;
    _for(i,1,q){
        int l,r;
        ll x;
        cin>>l>>r>>x;
        if(l==1) a1+=x;
        else {
            cg(l,x);
        }
        cg(r+1,-x);
        //cout<<c[l]<<' '<<c[r+1]<<endl;
        ll ans = (ll)ceil((double)(a1+sumg)/2.0);
        cout<<ans<<endl;
    }
}


    #include <iostream>
    using namespace std;

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef vector<long long> vl;
    typedef vector<int> vi;
    #define PB push_back
    #define MP make_pair
    #define ln "\n"
    #define max(a, b) (a < b ? b : a)
    #define min(a, b) ((a > b) ? b : a)
    #define mod 1e9 + 7
    #define forn(i,e) for(ll i=0; i<e; i++)
    #define forsn(i,s,e) for(ll i=s; i<e; i++)
    #define rforn(i,e) for(ll i=e; i>=0; i--)
    #define rforsn(i,s,e) for(ll i=s; i>=e; i--)
    #define vasort(v) sort(v.begin(), v.end())
    #define vdsort(v) sort(v.begin(), v.end(),greater<ll>())
    #define F first
    #define S second

    #define out1(x1) cout << x1 << ln
    #define out2(x1,x2) cout << x1 << " " << x2 << ln
    #define out3(x1,x2,x3) cout << x1 << " " << x2 << " " << x3 << ln
    #define out4(x1,x2,x3,x4) cout << x1 << " " << x2 << " " << x3 << " " << x4 << ln
    #define out5(x1,x2,x3,x4,x5) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << ln
    #define out6(x1,x2,x3,x4,x5,x6) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << " " << x6 << ln

    #define in1(x1) cin >> x1
    #define in2(x1,x2) cin >> x1 >> x2
    #define in3(x1,x2,x3) cin >> x1 >> x2 >> x3
    #define in4(x1,x2,x3,x4) cin >> x1 >> x2 >> x3 >> x4
    #define in5(x1,x2,x3,x4,x5) cin >> x1 >> x2 >> x3 >> x4 >> x5
    #define in6(x1,x2,x3,x4,x5,x6) cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6

    #define arrin(a,n) forn(i,n) cin >> a[i];
    #define arrout(a,n) forn(i,n) {cout << a[i] << " ";} cout << ln;

    #define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    int nxt() {int x; cin >> x; return x;}
    const ll INF = ll(1e17) + 99;
    ll gcd(ll a, ll b)  {if (b == 0) return a;  return gcd(b, a % b);  }
    ll fact(ll n)    {ll t=1;if(n==0 ||n==1) return t; for(int i=2;i<=n;i++) t*=i; return t;}
    const int N = int(2e5) + 99;
    vi plist;
    void SieveOfEratosthenes(int n)
    {
        // Create a boolean array "prime[0..n]" and initialize
        // all entries it as true. A value in prime[i] will
        // finally be false if i is Not a prime, else true.
        bool prime[n+1];
        memset(prime, true, sizeof(prime));

        for (int p=2; p*p<=n; p++)
        {
            // If prime[p] is not changed, then it is a prime
            if (prime[p] == true)
            {
                // Update all multiples of p greater than or
                // equal to the square of it
                // numbers which are multiple of p and are
                // less than p^2 are already been marked.
                for (int i=p*p; i<=n; i += p)
                    prime[i] = false;
            }
        }

        // Print all prime numbers
        for (int p=2; p<=n; p++)
           if (prime[p])
              plist.PB(p);
    }
    ll power(ll x,  ll y, ll p)
    {
        ll res = 1;     // Initialize result

        x = x % p; // Update x if it is more than or
                    // equal to p

        if (x == 0) return 0; // In case x is divisible by p;

        while (y > 0)
        {
            // If y is odd, multiply x with result
            if (y & 1)
                res = (res*x) % p;

            // y must be even now
            y = y>>1; // y = y/2
            x = (x*x) % p;
        }
        return res;
    }
    int _mergeSort(int arr[], int temp[], int left, int right);
    int merge(int arr[], int temp[], int left, int mid, int right);

    /* This function sorts the input array and returns the
    number of inversions in the array */
    int mergeSort(int arr[], int array_size)
    {
        int temp[array_size];
        return _mergeSort(arr, temp, 0, array_size - 1);
    }

    /* An auxiliary recursive function that sorts the input array and
    returns the number of inversions in the array. */
    int _mergeSort(int arr[], int temp[], int left, int right)
    {
        int mid, inv_count = 0;
        if (right > left) {
            /* Divide the array into two parts and
            call _mergeSortAndCountInv()
            for each of the parts */
            mid = (right + left) / 2;

            /* Inversion count will be sum of
            inversions in left-part, right-part
            and number of inversions in merging */
            inv_count += _mergeSort(arr, temp, left, mid);
            inv_count += _mergeSort(arr, temp, mid + 1, right);

            /*Merge the two parts*/
            inv_count += merge(arr, temp, left, mid + 1, right);
        }
        return inv_count;
    }

    /* This funt merges two sorted arrays
    and returns inversion count in the arrays.*/
    int merge(int arr[], int temp[], int left,
              int mid, int right)
    {
        int i, j, k;
        int inv_count = 0;

        i = left; /* i is index for left subarray*/
        j = mid; /* j is index for right subarray*/
        k = left; /* k is index for resultant merged subarray*/
        while ((i <= mid - 1) && (j <= right)) {
            if (arr[i] <= arr[j]) {
                temp[k++] = arr[i++];
            }
            else {
                temp[k++] = arr[j++];

                /* this is tricky -- see above
                explanation/diagram for merge()*/
                inv_count = inv_count + (mid - i);
            }
        }

        /* Copy the remaining elements of left subarray
    (if there are any) to temp*/
        while (i <= mid - 1)
            temp[k++] = arr[i++];

        /* Copy the remaining elements of right subarray
    (if there are any) to temp*/
        while (j <= right)
            temp[k++] = arr[j++];

        /*Copy back the merged elements to original array*/
        for (i = left; i <= right; i++)
            arr[i] = temp[i];

        return inv_count;
    }
    ll binomialCoeff(ll n, ll k)
    {
        ll res = 1;

        // Since C(n, k) = C(n, n-k)
        if (k > n - k)
            k = n - k;

        // Calculate value of
        // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
        for (ll i = 0; i < k; ++i) {
            res *= (n - i);
            res /= (i + 1);
        }

        return res;
    }const ll MAXN = 100001;

    ll spf[MAXN];
    void sieve()
    {
        spf[1] = 1;
        for (ll i=2; i<MAXN; i++)  spf[i] = i;
        for (ll i=4; i<MAXN; i+=2) spf[i] = 2;

        for (ll i=3; i*i<MAXN; i++) {
            if (spf[i] == i) {
                for (ll j=i*i; j<MAXN; j+=i)
                    if (spf[j]==j)
                        spf[j] = i;
            }
        }
    }
    map<ll,ll> getFactorization(ll x){    map<ll,ll> ret; while (x != 1) {ret[spf[x]]++;   x = x / spf[x];}return ret;}

    bool sortbysec(const pair<int,int> &a,
                  const pair<int,int> &b)
    {
        return (a.second < b.second);
    }
    /*-----------------------------Code begins------------------------*/
     bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
    {
       return (a.first > b.first);
    }
    ll ans2=0,ans3=0;
   void  func(ll x,ll y,ll b[])
    {   x--;
        if(b[x]>0)
        {
            ans2-=b[x];
        }
        else ans3+=b[x];
        b[x]+=y;
        if(b[x]>0)
        {
            ans2+=b[x];

        }
        else ans3-=b[x];

    }

    void solve()
    {
        ll l,r,g,n,x,y,m,ans1=6e16+7,ans13=0,
        value,ans4=0,flag1=0,ans5=0,ans6=0,k;
        cin>>n;
        ll a[n];
        arrin(a,n);
        ll q;
        cin>>q;k=0;
         if(n==1)
        {   cout<<ceil(double((a[0])/2.0))<<ln;

        forn(i,q)
        {
            cin>> l>>r>>x;
            //update(1, 0, n-1, l,  r, x);
            a[0]+=x;
            cout<<ceil(double((a[0])/2.0))<<ln;

        }return;

        }ll a1=a[0];
        ll b[n+1];b[0]=a[0];
        forn(i,n-1)
        {
            if(a[i+1]-a[i]>0)
                ans2+=a[i+1]-a[i];
            else
                ans3+=-a[i+1]+a[i];
            b[i+1]=a[i+1]-a[i];
        }

            cout<<ceil(double((a1+ans2)/2.0))<<ln;
        forn(i,q)
        {
            cin>>l>>r>>x;
            if(l==1)
            {
                a1+=x;
            }
            else
            func(l,x,b);
            if(r!=n)
                func(r+1,-x,b);
            cout<<ceil(double((a1+ans2)/2.0))<<ln;

        }

    }

    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        //freopen("error.txt","w",stderr);
        #endif
        zoom;
        //SieveOfEratosthenes(1000007);
         ll t=1;

        //in1(t);
         while(t--) {
            solve();cout<<ln;
         }

        return 0;
    }


    #include <iostream>
    using namespace std;

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef vector<long long> vl;
    typedef vector<int> vi;
    #define PB push_back
    #define MP make_pair
    #define ln "\n"
    #define max(a, b) (a < b ? b : a)
    #define min(a, b) ((a > b) ? b : a)
    #define mod 1e9 + 7
    #define forn(i,e) for(ll i=0; i<e; i++)
    #define forsn(i,s,e) for(ll i=s; i<e; i++)
    #define rforn(i,e) for(ll i=e; i>=0; i--)
    #define rforsn(i,s,e) for(ll i=s; i>=e; i--)
    #define vasort(v) sort(v.begin(), v.end())
    #define vdsort(v) sort(v.begin(), v.end(),greater<ll>())
    #define F first
    #define S second

    #define out1(x1) cout << x1 << ln
    #define out2(x1,x2) cout << x1 << " " << x2 << ln
    #define out3(x1,x2,x3) cout << x1 << " " << x2 << " " << x3 << ln
    #define out4(x1,x2,x3,x4) cout << x1 << " " << x2 << " " << x3 << " " << x4 << ln
    #define out5(x1,x2,x3,x4,x5) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << ln
    #define out6(x1,x2,x3,x4,x5,x6) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << " " << x6 << ln

    #define in1(x1) cin >> x1
    #define in2(x1,x2) cin >> x1 >> x2
    #define in3(x1,x2,x3) cin >> x1 >> x2 >> x3
    #define in4(x1,x2,x3,x4) cin >> x1 >> x2 >> x3 >> x4
    #define in5(x1,x2,x3,x4,x5) cin >> x1 >> x2 >> x3 >> x4 >> x5
    #define in6(x1,x2,x3,x4,x5,x6) cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6

    #define arrin(a,n) forn(i,n) cin >> a[i];
    #define arrout(a,n) forn(i,n) {cout << a[i] << " ";} cout << ln;

    #define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    int nxt() {int x; cin >> x; return x;}
    const ll INF = ll(1e17) + 99;
    ll gcd(ll a, ll b)  {if (b == 0) return a;  return gcd(b, a % b);  }
    ll fact(ll n)    {ll t=1;if(n==0 ||n==1) return t; for(int i=2;i<=n;i++) t*=i; return t;}
    const int N = int(2e5) + 99;
    vi plist;
    void SieveOfEratosthenes(int n)
    {
        // Create a boolean array "prime[0..n]" and initialize
        // all entries it as true. A value in prime[i] will
        // finally be false if i is Not a prime, else true.
        bool prime[n+1];
        memset(prime, true, sizeof(prime));

        for (int p=2; p*p<=n; p++)
        {
            // If prime[p] is not changed, then it is a prime
            if (prime[p] == true)
            {
                // Update all multiples of p greater than or
                // equal to the square of it
                // numbers which are multiple of p and are
                // less than p^2 are already been marked.
                for (int i=p*p; i<=n; i += p)
                    prime[i] = false;
            }
        }

        // Print all prime numbers
        for (int p=2; p<=n; p++)
           if (prime[p])
              plist.PB(p);
    }
    ll power(ll x,  ll y, ll p)
    {
        ll res = 1;     // Initialize result

        x = x % p; // Update x if it is more than or
                    // equal to p

        if (x == 0) return 0; // In case x is divisible by p;

        while (y > 0)
        {
            // If y is odd, multiply x with result
            if (y & 1)
                res = (res*x) % p;

            // y must be even now
            y = y>>1; // y = y/2
            x = (x*x) % p;
        }
        return res;
    }
    int _mergeSort(int arr[], int temp[], int left, int right);
    int merge(int arr[], int temp[], int left, int mid, int right);

    /* This function sorts the input array and returns the
    number of inversions in the array */
    int mergeSort(int arr[], int array_size)
    {
        int temp[array_size];
        return _mergeSort(arr, temp, 0, array_size - 1);
    }

    /* An auxiliary recursive function that sorts the input array and
    returns the number of inversions in the array. */
    int _mergeSort(int arr[], int temp[], int left, int right)
    {
        int mid, inv_count = 0;
        if (right > left) {
            /* Divide the array into two parts and
            call _mergeSortAndCountInv()
            for each of the parts */
            mid = (right + left) / 2;

            /* Inversion count will be sum of
            inversions in left-part, right-part
            and number of inversions in merging */
            inv_count += _mergeSort(arr, temp, left, mid);
            inv_count += _mergeSort(arr, temp, mid + 1, right);

            /*Merge the two parts*/
            inv_count += merge(arr, temp, left, mid + 1, right);
        }
        return inv_count;
    }

    /* This funt merges two sorted arrays
    and returns inversion count in the arrays.*/
    int merge(int arr[], int temp[], int left,
              int mid, int right)
    {
        int i, j, k;
        int inv_count = 0;

        i = left; /* i is index for left subarray*/
        j = mid; /* j is index for right subarray*/
        k = left; /* k is index for resultant merged subarray*/
        while ((i <= mid - 1) && (j <= right)) {
            if (arr[i] <= arr[j]) {
                temp[k++] = arr[i++];
            }
            else {
                temp[k++] = arr[j++];

                /* this is tricky -- see above
                explanation/diagram for merge()*/
                inv_count = inv_count + (mid - i);
            }
        }

        /* Copy the remaining elements of left subarray
    (if there are any) to temp*/
        while (i <= mid - 1)
            temp[k++] = arr[i++];

        /* Copy the remaining elements of right subarray
    (if there are any) to temp*/
        while (j <= right)
            temp[k++] = arr[j++];

        /*Copy back the merged elements to original array*/
        for (i = left; i <= right; i++)
            arr[i] = temp[i];

        return inv_count;
    }
    ll binomialCoeff(ll n, ll k)
    {
        ll res = 1;

        // Since C(n, k) = C(n, n-k)
        if (k > n - k)
            k = n - k;

        // Calculate value of
        // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
        for (ll i = 0; i < k; ++i) {
            res *= (n - i);
            res /= (i + 1);
        }

        return res;
    }const ll MAXN = 100001;

    ll spf[MAXN];
    void sieve()
    {
        spf[1] = 1;
        for (ll i=2; i<MAXN; i++)  spf[i] = i;
        for (ll i=4; i<MAXN; i+=2) spf[i] = 2;

        for (ll i=3; i*i<MAXN; i++) {
            if (spf[i] == i) {
                for (ll j=i*i; j<MAXN; j+=i)
                    if (spf[j]==j)
                        spf[j] = i;
            }
        }
    }
    map<ll,ll> getFactorization(ll x){    map<ll,ll> ret; while (x != 1) {ret[spf[x]]++;   x = x / spf[x];}return ret;}

    bool sortbysec(const pair<int,int> &a,
                  const pair<int,int> &b)
    {
        return (a.second < b.second);
    }
    /*-----------------------------Code begins------------------------*/
     bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
    {
       return (a.first > b.first);
    }
    ll ans2=0,ans3=0;
   void  func(ll x,ll y,ll b[])
    {   x--;
        if(b[x]>0)
        {
            ans2-=b[x];
        }
        else ans3+=b[x];
        b[x]+=y;
        if(b[x]>0)
        {
            ans2+=b[x];

        }
        else ans3-=b[x];

    }

    void solve()
    {
        ll l,r,g,n,x,y,m,ans1=6e16+7,ans13=0,
        value,ans4=0,flag1=0,ans5=0,ans6=0,k;
        cin>>n;
        ll a[n];
        arrin(a,n);
        ll q;
        cin>>q;k=0;
         if(n==1)
        {    r=ceil(double(a[0])/2.0);
          cout<<r<<ln;

        forn(i,q)
        {
            cin>> l>>r>>x;
            //update(1, 0, n-1, l,  r, x);
            a[0]+=x;
            r=ceil(double(a[0]/2.0));
            cout<<r<<ln;

        }return;

        }ll a1=a[0];
        ll b[n+1];b[0]=a[0];
        forn(i,n-1)
        {
            if(a[i+1]-a[i]>0)
                ans2+=a[i+1]-a[i];
            else
                ans3+=-a[i+1]+a[i];
            b[i+1]=a[i+1]-a[i];
        }

            cout<<ceil(double(a1+ans2)/2.0)<<ln;
        forn(i,q)
        {
            cin>>l>>r>>x;
            if(l==1)
            {
                a1+=x;
            }
            else
            func(l,x,b);
            if(r!=n)
                func(r+1,-x,b);
            cout<<ceil(double(a1+ans2)/2.0)<<ln;

        }

    }

    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        //freopen("error.txt","w",stderr);
        #endif
        zoom;
        //SieveOfEratosthenes(1000007);
         ll t=1;

        //in1(t);
         while(t--) {
            solve();cout<<ln;
         }

        return 0;
    }


    #include <iostream>
    using namespace std;

    #include <bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    typedef vector<long long> vl;
    typedef vector<int> vi;
    #define PB push_back
    #define MP make_pair
    #define ln "\n"
    #define max(a, b) (a < b ? b : a)
    #define min(a, b) ((a > b) ? b : a)
    #define mod 1e9 + 7
    #define forn(i,e) for(ll i=0; i<e; i++)
    #define forsn(i,s,e) for(ll i=s; i<e; i++)
    #define rforn(i,e) for(ll i=e; i>=0; i--)
    #define rforsn(i,s,e) for(ll i=s; i>=e; i--)
    #define vasort(v) sort(v.begin(), v.end())
    #define vdsort(v) sort(v.begin(), v.end(),greater<ll>())
    #define F first
    #define S second

    #define out1(x1) cout << x1 << ln
    #define out2(x1,x2) cout << x1 << " " << x2 << ln
    #define out3(x1,x2,x3) cout << x1 << " " << x2 << " " << x3 << ln
    #define out4(x1,x2,x3,x4) cout << x1 << " " << x2 << " " << x3 << " " << x4 << ln
    #define out5(x1,x2,x3,x4,x5) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << ln
    #define out6(x1,x2,x3,x4,x5,x6) cout << x1 << " " << x2 << " " << x3 << " " << x4 << " " << x5 << " " << x6 << ln

    #define in1(x1) cin >> x1
    #define in2(x1,x2) cin >> x1 >> x2
    #define in3(x1,x2,x3) cin >> x1 >> x2 >> x3
    #define in4(x1,x2,x3,x4) cin >> x1 >> x2 >> x3 >> x4
    #define in5(x1,x2,x3,x4,x5) cin >> x1 >> x2 >> x3 >> x4 >> x5
    #define in6(x1,x2,x3,x4,x5,x6) cin >> x1 >> x2 >> x3 >> x4 >> x5 >> x6

    #define arrin(a,n) forn(i,n) cin >> a[i];
    #define arrout(a,n) forn(i,n) {cout << a[i] << " ";} cout << ln;

    #define zoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
    int nxt() {int x; cin >> x; return x;}
    const ll INF = ll(1e17) + 99;
    ll gcd(ll a, ll b)  {if (b == 0) return a;  return gcd(b, a % b);  }
    ll fact(ll n)    {ll t=1;if(n==0 ||n==1) return t; for(int i=2;i<=n;i++) t*=i; return t;}
    const int N = int(2e5) + 99;
    vi plist;
    void SieveOfEratosthenes(int n)
    {
        // Create a boolean array "prime[0..n]" and initialize
        // all entries it as true. A value in prime[i] will
        // finally be false if i is Not a prime, else true.
        bool prime[n+1];
        memset(prime, true, sizeof(prime));

        for (int p=2; p*p<=n; p++)
        {
            // If prime[p] is not changed, then it is a prime
            if (prime[p] == true)
            {
                // Update all multiples of p greater than or
                // equal to the square of it
                // numbers which are multiple of p and are
                // less than p^2 are already been marked.
                for (int i=p*p; i<=n; i += p)
                    prime[i] = false;
            }
        }

        // Print all prime numbers
        for (int p=2; p<=n; p++)
           if (prime[p])
              plist.PB(p);
    }
    ll power(ll x,  ll y, ll p)
    {
        ll res = 1;     // Initialize result

        x = x % p; // Update x if it is more than or
                    // equal to p

        if (x == 0) return 0; // In case x is divisible by p;

        while (y > 0)
        {
            // If y is odd, multiply x with result
            if (y & 1)
                res = (res*x) % p;

            // y must be even now
            y = y>>1; // y = y/2
            x = (x*x) % p;
        }
        return res;
    }
    int _mergeSort(int arr[], int temp[], int left, int right);
    int merge(int arr[], int temp[], int left, int mid, int right);

    /* This function sorts the input array and returns the
    number of inversions in the array */
    int mergeSort(int arr[], int array_size)
    {
        int temp[array_size];
        return _mergeSort(arr, temp, 0, array_size - 1);
    }

    /* An auxiliary recursive function that sorts the input array and
    returns the number of inversions in the array. */
    int _mergeSort(int arr[], int temp[], int left, int right)
    {
        int mid, inv_count = 0;
        if (right > left) {
            /* Divide the array into two parts and
            call _mergeSortAndCountInv()
            for each of the parts */
            mid = (right + left) / 2;

            /* Inversion count will be sum of
            inversions in left-part, right-part
            and number of inversions in merging */
            inv_count += _mergeSort(arr, temp, left, mid);
            inv_count += _mergeSort(arr, temp, mid + 1, right);

            /*Merge the two parts*/
            inv_count += merge(arr, temp, left, mid + 1, right);
        }
        return inv_count;
    }

    /* This funt merges two sorted arrays
    and returns inversion count in the arrays.*/
    int merge(int arr[], int temp[], int left,
              int mid, int right)
    {
        int i, j, k;
        int inv_count = 0;

        i = left; /* i is index for left subarray*/
        j = mid; /* j is index for right subarray*/
        k = left; /* k is index for resultant merged subarray*/
        while ((i <= mid - 1) && (j <= right)) {
            if (arr[i] <= arr[j]) {
                temp[k++] = arr[i++];
            }
            else {
                temp[k++] = arr[j++];

                /* this is tricky -- see above
                explanation/diagram for merge()*/
                inv_count = inv_count + (mid - i);
            }
        }

        /* Copy the remaining elements of left subarray
    (if there are any) to temp*/
        while (i <= mid - 1)
            temp[k++] = arr[i++];

        /* Copy the remaining elements of right subarray
    (if there are any) to temp*/
        while (j <= right)
            temp[k++] = arr[j++];

        /*Copy back the merged elements to original array*/
        for (i = left; i <= right; i++)
            arr[i] = temp[i];

        return inv_count;
    }
    ll binomialCoeff(ll n, ll k)
    {
        ll res = 1;

        // Since C(n, k) = C(n, n-k)
        if (k > n - k)
            k = n - k;

        // Calculate value of
        // [n * (n-1) *---* (n-k+1)] / [k * (k-1) *----* 1]
        for (ll i = 0; i < k; ++i) {
            res *= (n - i);
            res /= (i + 1);
        }

        return res;
    }const ll MAXN = 100001;

    ll spf[MAXN];
    void sieve()
    {
        spf[1] = 1;
        for (ll i=2; i<MAXN; i++)  spf[i] = i;
        for (ll i=4; i<MAXN; i+=2) spf[i] = 2;

        for (ll i=3; i*i<MAXN; i++) {
            if (spf[i] == i) {
                for (ll j=i*i; j<MAXN; j+=i)
                    if (spf[j]==j)
                        spf[j] = i;
            }
        }
    }
    map<ll,ll> getFactorization(ll x){    map<ll,ll> ret; while (x != 1) {ret[spf[x]]++;   x = x / spf[x];}return ret;}

    bool sortbysec(const pair<int,int> &a,
                  const pair<int,int> &b)
    {
        return (a.second < b.second);
    }
    /*-----------------------------Code begins------------------------*/
     bool sortinrev(const pair<int,int> &a,
               const pair<int,int> &b)
    {
       return (a.first > b.first);
    }
    ll ans2=0,ans3=0;
   void  func(ll x,ll y,ll b[])
    {   x--;
        if(b[x]>0)
        {
            ans2-=b[x];
        }
        else ans3+=b[x];
        b[x]+=y;
        if(b[x]>0)
        {
            ans2+=b[x];

        }
        else ans3-=b[x];

    }

    void solve()
    {
        ll l,r,g,n,x,y,m,ans1=6e16+7,ans13=0,
        value,ans4=0,flag1=0,ans5=0,ans6=0,k;
        cin>>n;
        ll a[n];
        arrin(a,n);
        ll q;
        cin>>q;k=0;
         if(n==1)
        {   cout<<(a[0]+1)/2<<ln;

        forn(i,q)
        {
            cin>> l>>r>>x;
            //update(1, 0, n-1, l,  r, x);
            a[0]+=x;
            cout<<(a[0]+1)/2<<ln;

        }return;

        }ll a1=a[0];
        ll b[n+1];b[0]=a[0];
        forn(i,n-1)
        {
            if(a[i+1]-a[i]>0)
                ans2+=a[i+1]-a[i];
            else
                ans3+=-a[i+1]+a[i];
            b[i+1]=a[i+1]-a[i];
        }

            cout<<(a1+ans2+1)/2<<ln;
        forn(i,q)
        {
            cin>>l>>r>>x;
            if(l==1)
            {
                a1+=x;
            }
            else
            func(l,x,b);
            if(r!=n)
                func(r+1,-x,b);
            cout<<(a1+ans2+1)/2<<ln;

        }

    }

    int main() {
        #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
        //freopen("error.txt","w",stderr);
        #endif
        zoom;
        //SieveOfEratosthenes(1000007);
         ll t=1;

        //in1(t);
         while(t--) {
            solve();cout<<ln;
         }

        return 0;
    }