You are given a sequence of $n$ integers $a_1, a_2, \ldots, a_n$.

You have to construct two sequences of integers $b$ and $c$ with length $n$ that satisfy:  for every $i$ ($1\leq i\leq n$) $b_i+c_i=a_i$  $b$ is non-decreasing, which means that for every $1<i\leq n$, $b_i\geq b_{i-1}$ must hold  $c$ is non-increasing, which means that for every $1<i\leq n$, $c_i\leq c_{i-1}$ must hold 

You have to minimize $\max(b_i,c_i)$. In other words, you have to minimize the maximum number in sequences $b$ and $c$.

Also there will be $q$ changes, the $i$-th change is described by three integers $l,r,x$. You should add $x$ to $a_l,a_{l+1}, \ldots, a_r$. 

You have to find the minimum possible value of $\max(b_i,c_i)$ for the initial sequence and for sequence after each change.


-----Input-----

The first line contains an integer $n$ ($1\leq n\leq 10^5$).

The secound line contains $n$ integers $a_1,a_2,\ldots,a_n$ ($1\leq i\leq n$, $-10^9\leq a_i\leq 10^9$).

The third line contains an integer $q$ ($1\leq q\leq 10^5$).

Each of the next $q$ lines contains three integers $l,r,x$ ($1\leq l\leq r\leq n,-10^9\leq x\leq 10^9$), desribing the next change. 


-----Output-----

Print $q+1$ lines.

On the $i$-th ($1 \leq i \leq q+1$) line, print the answer to the problem for the sequence after $i-1$ changes.


-----Examples-----
Input
4
2 -1 7 3
2
2 4 -3
3 4 2

Output
5
5
6

Input
6
-9 -10 -9 -6 -5 4
3
2 6 -9
1 2 -10
4 6 -3

Output
3
3
3
1

Input
1
0
2
1 1 -1
1 1 -1

Output
0
0
-1



-----Note-----

In the first test:  The initial sequence $a = (2, -1, 7, 3)$. Two sequences $b=(-3,-3,5,5),c=(5,2,2,-2)$ is a possible choice.  After the first change $a = (2, -4, 4, 0)$. Two sequences $b=(-3,-3,5,5),c=(5,-1,-1,-5)$ is a possible choice.  After the second change $a = (2, -4, 6, 2)$. Two sequences $b=(-4,-4,6,6),c=(6,0,0,-4)$ is a possible choice.

Difficulty: HARD
Tags: Greedy algorithms

Data structures

Mathematics

Constructive algorithms
Skill types: Data structures

Greedy algorithms

Starter code:

Solutions:
import sys
from sys import stdout
import random
from fractions import Fraction
from math import *

def input():
	return sys.stdin.readline().strip()

def iinput():
	return int(input())

def finput():
	return float(input())

def tinput():
	return input().split()

def linput():
	return list(input())

def rinput():
	return map(int, tinput())

def fiinput():
	return map(float, tinput())

def rlinput():
	return list(map(int, input().split()))

def trinput():
	return tuple(rinput())

def srlinput():
	return sorted(list(map(int, input().split())))

def NOYES(fl):
	if fl:
		print('NO')
	else:
		print('YES')

def YESNO(fl):
	if fl:
		print('YES')
	else:
		print('NO')

def main():

	def answer(res):
		print((res + 1) // 2)
	n = iinput()
	q = rlinput()
	w = [0] + [q[i] - q[i - 1] for i in range(1, n)]
	res = q[0] + sum([max(w[i], 0) for i in range(1, n)])
	answer(res)
	k = iinput()
	for o in range(k):
		(l, r, x) = rinput()
		if l == 1:
			res += x
		else:
			res = res - max(0, w[l - 1]) + max(0, w[l - 1] + x)
			w[l - 1] += x
		if r != n:
			res = res - max(0, w[r]) + max(0, w[r] - x)
			w[r] -= x
		answer(res)
for i in range(1):
	main()


import sys
import atexit
import os

class Fastio:

	def __init__(self):
		self.ibuf = bytes()
		self.obuf = bytearray()
		self.pil = 0
		self.pir = 0
		self.buf = bytearray(21)
		self.buf[20] = 10

	def load(self):
		self.ibuf = self.ibuf[self.pil:]
		self.ibuf += os.read(0, max(os.fstat(0).st_size, 131072))
		self.pil = 0
		self.pir = len(self.ibuf)

	def flush(self):
		os.write(1, self.obuf)
		self.obuf = bytearray()

	def fastin(self):
		if self.pir - self.pil < 32:
			self.load()
		minus = 0
		x = 0
		while self.ibuf[self.pil] < 45:
			self.pil += 1
		if self.ibuf[self.pil] == 45:
			minus = 1
			self.pil += 1
		while self.ibuf[self.pil] >= 48:
			x = x * 10 + (self.ibuf[self.pil] & 15)
			self.pil += 1
		if minus:
			x = -x
		return x

	def fastoutln(self, x):
		i = 19
		if x == 0:
			self.buf[i] = 48
			i -= 1
		else:
			if x < 0:
				self.obuf.append(45)
				x = -x
			while x != 0:
				(x, r) = divmod(x, 10)
				self.buf[i] = 48 + r
				i -= 1
		self.obuf.extend(self.buf[i + 1:21])
		if len(self.obuf) > 131072:
			self.flush()
fastio = Fastio()
rd = fastio.fastin
wtn = fastio.fastoutln
atexit.register(fastio.flush)
N = rd()
a = [0] * N
for i in range(N):
	a[i] = rd()
for i in range(N - 1, 0, -1):
	a[i] -= a[i - 1]
p = 0
for i in range(1, N):
	p += max(0, a[i])
wtn((a[0] + p + 1) // 2)
Q = rd()
for _ in range(Q):
	(l, r, x) = (rd(), rd(), rd())
	l -= 1
	if l != 0:
		p -= max(a[l], 0)
	a[l] += x
	if l != 0:
		p += max(a[l], 0)
	if r != N:
		p -= max(a[r], 0)
		a[r] -= x
		p += max(a[r], 0)
	wtn((a[0] + p + 1) // 2)


import sys
(_ord, inp, num, neg, _Index) = (lambda x: x, [], 0, False, 0)
(i, s) = (0, sys.stdin.buffer.read())
try:
	while True:
		if s[i] >= b'0'[0]:
			num = 10 * num + _ord(s[i]) - 48
		elif s[i] == b'-'[0]:
			neg = True
		elif s[i] != b'\r'[0]:
			inp.append(-num if neg else num)
			(num, neg) = (0, False)
		i += 1
except IndexError:
	pass
if s and s[-1] >= b'0'[0]:
	inp.append(-num if neg else num)

def inin(size=None):
	global _Index
	if size == None:
		ni = _Index
		_Index += 1
		return inp[ni]
	else:
		ni = _Index
		_Index += size
		return inp[ni:ni + size]
_T_ = 1
for _t_ in range(_T_):
	n = inin()
	a = inin(n)
	d = [0 for i in range(n - 1)]
	k = 0
	for i in range(1, n):
		d[i - 1] += a[i] - a[i - 1]
		k += max(0, a[i] - a[i - 1])
	x = (a[0] + k + 1) // 2
	print(x)
	q = inin()
	for _ in range(q):
		(l, r, c) = inin(3)
		l -= 1
		r -= 1
		if l == 0:
			a[0] += c
		else:
			if d[l - 1] >= 0:
				k -= d[l - 1]
			d[l - 1] += c
			if d[l - 1] >= 0:
				k += d[l - 1]
		if r == n - 1:
			pass
		else:
			if d[r] >= 0:
				k -= d[r]
			d[r] -= c
			if d[r] >= 0:
				k += d[r]
		x = (a[0] + k + 1) // 2
		print(x)


from bisect import *
from collections import *
from math import gcd, ceil, sqrt, floor, inf
from heapq import *
from itertools import *
from operator import add, mul, sub, xor, truediv, floordiv
from functools import *
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())
from types import GeneratorType

def bootstrap(f, stack=[]):

	def wrappedfunc(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		else:
			to = f(*args, **kwargs)
			while True:
				if type(to) is GeneratorType:
					stack.append(to)
					to = next(to)
				else:
					stack.pop()
					if not stack:
						break
					to = stack[-1].send(to)
			return to
	return wrappedfunc
farr = [1]
ifa = []

def fact(x, mod=0):
	if mod:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr) % mod)
	else:
		while x >= len(farr):
			farr.append(farr[-1] * len(farr))
	return farr[x]

def ifact(x, mod):
	global ifa
	ifa.append(pow(farr[-1], mod - 2, mod))
	for i in range(x, 0, -1):
		ifa.append(ifa[-1] * i % mod)
	ifa = ifa[::-1]

def per(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return fact(i) // fact(i - j)
	return farr[i] * ifa[i - j] % mod

def com(i, j, mod=0):
	if i < j:
		return 0
	if not mod:
		return per(i, j) // fact(j)
	return per(i, j, mod) * ifa[j] % mod

def catalan(n):
	return com(2 * n, n) // (n + 1)

def linc(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t > f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rinc(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t < f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def ldec(f, t, l, r):
	while l < r:
		mid = (l + r) // 2
		if t < f(mid):
			l = mid + 1
		else:
			r = mid
	return l

def rdec(f, t, l, r):
	while l < r:
		mid = (l + r + 1) // 2
		if t > f(mid):
			r = mid - 1
		else:
			l = mid
	return l

def isprime(n):
	for i in range(2, int(n ** 0.5) + 1):
		if n % i == 0:
			return False
	return True

def binfun(x):
	c = 0
	for w in arr:
		c += ceil(w / x)
	return c

def lowbit(n):
	return n & -n

def inverse(a, m):
	a %= m
	if a <= 1:
		return a
	return (1 - inverse(m, a) * m) // a % m

class BIT:

	def __init__(self, arr):
		self.arr = arr
		self.n = len(arr) - 1

	def update(self, x, v):
		while x <= self.n:
			self.arr[x] += v
			x += x & -x

	def query(self, x):
		ans = 0
		while x:
			ans += self.arr[x]
			x &= x - 1
		return ans

class smt:

	def __init__(self, l, r, arr):
		self.l = l
		self.r = r
		self.value = (1 << 31) - 1 if l < r else arr[l]
		mid = (l + r) // 2
		if l < r:
			self.left = smt(l, mid, arr)
			self.right = smt(mid + 1, r, arr)
			self.value &= self.left.value & self.right.value

	def setvalue(self, x, val):
		if self.l == self.r:
			self.value = val
			return
		mid = (self.l + self.r) // 2
		if x <= mid:
			self.left.setvalue(x, val)
		else:
			self.right.setvalue(x, val)
		self.value = self.left.value & self.right.value

	def ask(self, l, r):
		if l <= self.l and r >= self.r:
			return self.value
		val = (1 << 31) - 1
		mid = (self.l + self.r) // 2
		if l <= mid:
			val &= self.left.ask(l, r)
		if r > mid:
			val &= self.right.ask(l, r)
		return val

class DSU:

	def __init__(self, n):
		self.c = [-1] * n

	def same(self, x, y):
		return self.find(x) == self.find(y)

	def find(self, x):
		if self.c[x] < 0:
			return x
		self.c[x] = self.find(self.c[x])
		return self.c[x]

	def union(self, u, v):
		(u, v) = (self.find(u), self.find(v))
		if u == v:
			return False
		if self.c[u] < self.c[v]:
			(u, v) = (v, u)
		self.c[u] += self.c[v]
		self.c[v] = u
		return True

	def size(self, x):
		return -self.c[self.find(x)]

class UFS:

	def __init__(self, n):
		self.parent = [i for i in range(n)]
		self.ranks = [0] * n

	def find(self, x):
		if x != self.parent[x]:
			self.parent[x] = self.find(self.parent[x])
		return self.parent[x]

	def union(self, u, v):
		(pu, pv) = (self.find(u), self.find(v))
		if pu == pv:
			return False
		if self.ranks[pu] >= self.ranks[pv]:
			self.parent[pv] = pu
			if self.ranks[pv] == self.ranks[pu]:
				self.ranks[pu] += 1
		else:
			self.parent[pu] = pv

def Prime(n):
	c = 0
	prime = []
	flag = [0] * (n + 1)
	for i in range(2, n + 1):
		if not flag[i]:
			prime.append(i)
			c += 1
		for j in range(c):
			if i * prime[j] > n:
				break
			flag[i * prime[j]] = prime[j]
			if i % prime[j] == 0:
				break
	return prime

def dij(s, graph):
	d = {}
	d[s] = 0
	heap = [(0, s)]
	seen = set()
	while heap:
		(dis, u) = heappop(heap)
		if u in seen:
			continue
		for v in graph[u]:
			if v not in d or d[v] > d[u] + graph[u][v]:
				d[v] = d[u] + graph[u][v]
				heappush(heap, (d[v], v))
	return d

def GP(it):
	return [(ch, len(list(g))) for (ch, g) in groupby(it)]

class DLN:

	def __init__(self, val):
		self.val = val
		self.pre = None
		self.next = None
t = 1
for i in range(t):
	n = N()
	a = RLL()
	q = N()
	dif = [a[0]]
	for i in range(1, n):
		dif.append(a[i] - a[i - 1])
	s = sum((max(0, dif[i]) for i in range(1, n)))
	ans = (a[0] + s + 1) // 2
	print(ans)
	for i in range(q):
		(l, r, x) = RL()
		l -= 1
		r -= 1
		if l == 0:
			a[0] += x
		else:
			s -= max(0, dif[l])
			dif[l] += x
			s += max(0, dif[l])
		if r < n - 1:
			s -= max(0, dif[r + 1])
			dif[r + 1] -= x
			s += max(0, dif[r + 1])
		ans = (a[0] + s + 1) // 2
		print(ans)


import sys
sys.setrecursionlimit(10 ** 5)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep='\n')

def II():
	return int(sys.stdin.readline())

def MI():
	return map(int, sys.stdin.readline().split())

def LI():
	return list(map(int, sys.stdin.readline().split()))

def LLI(rows_number):
	return [LI() for _ in range(rows_number)]

def SI():
	return sys.stdin.readline()[:-1]
n = II()
aa = LI()
dd = [0] * n
s = 0
for i in range(n - 1):
	dd[i + 1] = aa[i + 1] - aa[i]
for d in dd:
	if d > 0:
		s += d
b0 = (aa[0] - s) // 2
print(max(b0 + s, aa[0] - b0))

def add(i, a, s):
	if i == 0:
		aa[0] += a
		return s
	if dd[i] > 0:
		s -= dd[i]
	dd[i] += a
	if dd[i] > 0:
		s += dd[i]
	return s
for _ in range(II()):
	(l, r, x) = MI()
	l -= 1
	s = add(l, x, s)
	if r < n:
		s = add(r, -x, s)
	b0 = (aa[0] - s) // 2
	print(max(b0 + s, aa[0] - b0))


n = int(input())
a = list(map(int, input().split()))
pre_delta = [0] * n
up_delta = 0
for i in range(1, n):
	pre_delta[i] = a[i] - a[i - 1]
	if pre_delta[i] > 0:
		up_delta += pre_delta[i]
ans = (up_delta + a[0] + 1) // 2
print(ans)
q = int(input())
for _ in range(q):
	(l, r, x) = map(int, input().split())
	if l == 1:
		a[0] += x
	else:
		if pre_delta[l - 1] > 0:
			up_delta -= pre_delta[l - 1]
		pre_delta[l - 1] += x
		if pre_delta[l - 1] > 0:
			up_delta += pre_delta[l - 1]
	if r < n:
		if pre_delta[r] > 0:
			up_delta -= pre_delta[r]
		pre_delta[r] -= x
		if pre_delta[r] > 0:
			up_delta += pre_delta[r]
	ans = (up_delta + a[0] + 1) // 2
	print(ans)


import sys

class Fastio:

	def __init__(self):
		self.ibuf = b''
		self.pil = 0
		self.pir = 0
		self.sz = 1 << 17

	def load(self):
		self.ibuf = self.ibuf[self.pil:]
		self.ibuf += sys.stdin.buffer.read(self.sz)
		self.pil = 0
		self.pir = len(self.ibuf)

	def fastin(self):
		if self.pir - self.pil < 32:
			self.load()
		minus = 0
		x = 0
		while self.ibuf[self.pil] < ord('-'):
			self.pil += 1
		if self.ibuf[self.pil] == ord('-'):
			minus = 1
			self.pil += 1
		while True:
			if self.ibuf[self.pil] < ord('0'):
				break
			x = x * 10 + int(self.ibuf[self.pil] & 15)
			self.pil += 1
		if minus:
			x = -x
		return x
fastio = Fastio()
fastin = fastio.fastin
N = fastin()
a = [0] * N
for i in range(N):
	a[i] = fastin()
for i in range(N - 1, 0, -1):
	a[i] -= a[i - 1]
p = 0
for i in range(1, N):
	p += max(0, a[i])
print((a[0] + p + 1) // 2)
Q = fastin()
for _ in range(Q):
	(l, r, x) = (fastin(), fastin(), fastin())
	l -= 1
	if l != 0:
		p -= max(a[l], 0)
	a[l] += x
	if l != 0:
		p += max(a[l], 0)
	if r != N:
		p -= max(a[r], 0)
		a[r] -= x
		p += max(a[r], 0)
	print((a[0] + p + 1) // 2)


import sys

def calc(a0, db, dc):
	b0 = (a0 - db) // 2
	c0 = a0 - b0
	c1 = (a0 - dc) // 2
	b1 = a0 - c1
	return min(max(b0 + db, c0), max(b1 + db, c1))

def main():
	n = int(input())
	A = [int(a) for a in input().split()]
	D = [A[i + 1] - A[i] for i in range(n - 1)]
	a0 = A[0]
	db = sum(filter(lambda d: d > 0, D))
	dc = sum(filter(lambda d: d < 0, D))
	q = int(input())
	ans = [calc(a0, db, dc)]
	for i in range(q):
		(l, r, x) = map(int, input().split())
		if l > 1:
			if D[l - 2] < 0:
				dc -= D[l - 2]
			else:
				db -= D[l - 2]
			D[l - 2] += x
			if D[l - 2] < 0:
				dc += D[l - 2]
			else:
				db += D[l - 2]
		if r < n:
			if D[r - 1] < 0:
				dc -= D[r - 1]
			else:
				db -= D[r - 1]
			D[r - 1] -= x
			if D[r - 1] < 0:
				dc += D[r - 1]
			else:
				db += D[r - 1]
		if l == 1:
			a0 += x
		ans.append(calc(a0, db, dc))
	print('\n'.join(map(str, ans)))
main()


n = int(input())
a = list(map(int, input().split()))
q = int(input())
b = [0] * n
c = [0] * n
difn = 0
diff = [0] * n
for i in range(1, n):
	if a[i] - a[i - 1] > 0:
		difn += a[i] - a[i - 1]
	diff[i] = a[i] - a[i - 1]
bo = (a[0] - difn) // 2
ans = max(bo + difn, a[0] - bo)
print(ans)
td = difn
for i in range(q):
	(l, r, x) = map(int, input().split())
	if l != 1:
		if diff[l - 1] + x > 0:
			td -= max(0, diff[l - 1])
			diff[l - 1] = diff[l - 1] + x
			td += diff[l - 1]
		else:
			td = td - max(0, diff[l - 1])
			diff[l - 1] = diff[l - 1] + x
	elif l == 1:
		a[0] += x
	if r != n:
		if diff[r] - x > 0:
			td -= max(0, diff[r])
			diff[r] = diff[r] - x
			td += diff[r]
		else:
			td = td - max(0, diff[r])
			diff[r] = diff[r] - x
	bo = (a[0] - td) // 2
	ans = max(bo + td, a[0] - bo)
	print(ans)


from __future__ import division, print_function
import os, sys
from io import BytesIO, IOBase
if sys.version_info[0] < 3:
	from __builtin__ import xrange as range
	from future_builtins import ascii, filter, hex, map, oct, zip

def so():
	return int(input())

def st():
	return input()

def mj():
	return map(int, input().strip().split(' '))

def msj():
	return map(str, input().strip().split(' '))

def le():
	return list(map(int, input().split()))

def dmain():
	sys.setrecursionlimit(1000000)
	threading.stack_size(1024000)
	thread = threading.Thread(target=main)
	thread.start()

def decimalToBinary(n):
	return bin(n).replace('0b', '')

def read():
	sys.stdin = open('input.txt', 'r')
	sys.stdout = open('output.txt', 'w')

def tr(n):
	return n * (n + 1) // 2

def main():
	import math
	m = so()
	L = le()
	k = L[0]
	p = 0
	X = []
	for i in range(m):
		X.append(0)
	for i in range(m - 1):
		X[i] = L[i + 1] - L[i]
		if 0 < X[i]:
			p = p + X[i]
	z = (k + 1 + p) // 2
	print(z)
	op = so()
	for i in range(op):
		(a, b, c) = mj()
		a -= 1
		b -= 1
		if a != 0:
			if X[a - 1] > 0:
				p -= X[a - 1]
			X[a - 1] += c
			if 0 < X[a - 1]:
				p += X[a - 1]
		else:
			k += c
		if b + 1 < m:
			if X[b] > 0:
				p -= X[b]
			X[b] -= c
			if 0 < X[b]:
				p += X[b]
		w = (k + 1 + p) // 2
		print(w)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
import atexit

class Fastio:

	def __init__(self):
		self.ibuf = bytes()
		self.obuf = bytearray()
		self.pil = 0
		self.pir = 0
		self.buf = bytearray(20)

	def load(self):
		self.ibuf = self.ibuf[self.pil:]
		self.ibuf += sys.stdin.buffer.read(131072)
		self.pil = 0
		self.pir = len(self.ibuf)

	def flush(self):
		sys.stdout.buffer.write(self.obuf)
		self.obuf = bytearray()

	def fastin(self):
		if self.pir - self.pil < 32:
			self.load()
		minus = 0
		x = 0
		while self.ibuf[self.pil] < ord('-'):
			self.pil += 1
		if self.ibuf[self.pil] == ord('-'):
			minus = 1
			self.pil += 1
		while self.ibuf[self.pil] >= ord('0'):
			x = x * 10 + (self.ibuf[self.pil] & 15)
			self.pil += 1
		if minus:
			x = -x
		return x

	def fastout(self, x, end=b'\n'):
		i = 19
		if x == 0:
			self.buf[i] = 48
			i -= 1
		else:
			if x < 0:
				self.obuf.append(45)
				x = -x
			while x != 0:
				(x, r) = (x // 10, x % 10)
				self.buf[i] = 48 + r
				i -= 1
		self.obuf.extend(self.buf[i + 1:])
		self.obuf.extend(end)
		if len(self.obuf) > 131072:
			self.flush()
fastio = Fastio()
rd = fastio.fastin
wtn = fastio.fastout
atexit.register(fastio.flush)
N = rd()
a = [0] * N
for i in range(N):
	a[i] = rd()
for i in range(N - 1, 0, -1):
	a[i] -= a[i - 1]
p = 0
for i in range(1, N):
	p += max(0, a[i])
wtn((a[0] + p + 1) // 2)
Q = rd()
for _ in range(Q):
	(l, r, x) = (rd(), rd(), rd())
	l -= 1
	if l != 0:
		p -= max(a[l], 0)
	a[l] += x
	if l != 0:
		p += max(a[l], 0)
	if r != N:
		p -= max(a[r], 0)
		a[r] -= x
		p += max(a[r], 0)
	wtn((a[0] + p + 1) // 2)


n = int(input())
aaa = list(map(int, input().split()))
diff = []
score = 0
prv = 0
for a in aaa:
	d = a - prv
	diff.append(d)
	if d > 0:
		score += d
	prv = a
buf = [(score + min(0, diff[0]) + 1) // 2]
q = int(input())
for _ in range(q):
	(l, r, x) = list(map(int, input().split()))
	l -= 1
	dl1 = diff[l]
	diff[l] += x
	dl2 = diff[l]
	score += max(0, dl2) - max(0, dl1)
	if r < n:
		dr1 = diff[r]
		diff[r] -= x
		dr2 = diff[r]
		score += max(0, dr2) - max(0, dr1)
	buf.append((score + min(0, diff[0]) + 1) // 2)
print('\n'.join(map(str, buf)))


import math
import random
import heapq, bisect
import sys
from collections import deque, defaultdict
from fractions import Fraction
import sys
import threading
from collections import defaultdict
mod = 10 ** 9 + 7
mod1 = 998244353
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class TreeNode:

	def __init__(self, k, v):
		self.key = k
		self.value = v
		self.left = None
		self.right = None
		self.parent = None
		self.height = 1
		self.num_left = 1
		self.num_total = 1

class AvlTree:

	def __init__(self):
		self._tree = None

	def add(self, k, v):
		if not self._tree:
			self._tree = TreeNode(k, v)
			return
		node = self._add(k, v)
		if node:
			self._rebalance(node)

	def _add(self, k, v):
		node = self._tree
		while node:
			if k < node.key:
				if node.left:
					node = node.left
				else:
					node.left = TreeNode(k, v)
					node.left.parent = node
					return node.left
			elif node.key < k:
				if node.right:
					node = node.right
				else:
					node.right = TreeNode(k, v)
					node.right.parent = node
					return node.right
			else:
				node.value = v
				return

	@staticmethod
	def get_height(x):
		return x.height if x else 0

	@staticmethod
	def get_num_total(x):
		return x.num_total if x else 0

	def _rebalance(self, node):
		n = node
		while n:
			lh = self.get_height(n.left)
			rh = self.get_height(n.right)
			n.height = max(lh, rh) + 1
			balance_factor = lh - rh
			n.num_total = 1 + self.get_num_total(n.left) + self.get_num_total(n.right)
			n.num_left = 1 + self.get_num_total(n.left)
			if balance_factor > 1:
				if self.get_height(n.left.left) < self.get_height(n.left.right):
					self._rotate_left(n.left)
				self._rotate_right(n)
			elif balance_factor < -1:
				if self.get_height(n.right.right) < self.get_height(n.right.left):
					self._rotate_right(n.right)
				self._rotate_left(n)
			else:
				n = n.parent

	def _remove_one(self, node):
		replacement = node.left or node.right
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = replacement
			else:
				node.parent.right = replacement
			replacement.parent = node.parent
			node.parent = None
		else:
			self._tree = replacement
			replacement.parent = None
		node.left = None
		node.right = None
		node.parent = None
		self._rebalance(replacement)

	def _remove_leaf(self, node):
		if node.parent:
			if AvlTree._is_left(node):
				node.parent.left = None
			else:
				node.parent.right = None
			self._rebalance(node.parent)
		else:
			self._tree = None
		node.parent = None
		node.left = None
		node.right = None

	def remove(self, k):
		node = self._get_node(k)
		if not node:
			return
		if AvlTree._is_leaf(node):
			self._remove_leaf(node)
			return
		if node.left and node.right:
			nxt = AvlTree._get_next(node)
			node.key = nxt.key
			node.value = nxt.value
			if self._is_leaf(nxt):
				self._remove_leaf(nxt)
			else:
				self._remove_one(nxt)
			self._rebalance(node)
		else:
			self._remove_one(node)

	def get(self, k):
		node = self._get_node(k)
		return node.value if node else -1

	def _get_node(self, k):
		if not self._tree:
			return None
		node = self._tree
		while node:
			if k < node.key:
				node = node.left
			elif node.key < k:
				node = node.right
			else:
				return node
		return None

	def get_at(self, pos):
		x = pos + 1
		node = self._tree
		while node:
			if x < node.num_left:
				node = node.left
			elif node.num_left < x:
				x -= node.num_left
				node = node.right
			else:
				return (node.key, node.value)
		raise IndexError('Out of ranges')

	@staticmethod
	def _is_left(node):
		return node.parent.left and node.parent.left == node

	@staticmethod
	def _is_leaf(node):
		return node.left is None and node.right is None

	def _rotate_right(self, node):
		if not node.parent:
			self._tree = node.left
			node.left.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.left
			node.left.parent = node.parent
		else:
			node.parent.right = node.left
			node.left.parent = node.parent
		bk = node.left.right
		node.left.right = node
		node.parent = node.left
		node.left = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	def _rotate_left(self, node):
		if not node.parent:
			self._tree = node.right
			node.right.parent = None
		elif AvlTree._is_left(node):
			node.parent.left = node.right
			node.right.parent = node.parent
		else:
			node.parent.right = node.right
			node.right.parent = node.parent
		bk = node.right.left
		node.right.left = node
		node.parent = node.right
		node.right = bk
		if bk:
			bk.parent = node
		node.height = max(self.get_height(node.left), self.get_height(node.right)) + 1
		node.num_total = 1 + self.get_num_total(node.left) + self.get_num_total(node.right)
		node.num_left = 1 + self.get_num_total(node.left)

	@staticmethod
	def _get_next(node):
		if not node.right:
			return node.parent
		n = node.right
		while n.left:
			n = n.left
		return n

class SegmentTree1:

	def __init__(self, data, default=0, func=lambda a, b: max(a, b)):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class SegmentTree:

	def __init__(self, data, default=0, func=lambda a, b: a + b):
		self._default = default
		self._func = func
		self._len = len(data)
		self._size = _size = 1 << (self._len - 1).bit_length()
		self.data = [default] * (2 * _size)
		self.data[_size:_size + self._len] = data
		for i in reversed(range(_size)):
			self.data[i] = func(self.data[i + i], self.data[i + i + 1])

	def __delitem__(self, idx):
		self[idx] = self._default

	def __getitem__(self, idx):
		return self.data[idx + self._size]

	def __setitem__(self, idx, value):
		idx += self._size
		self.data[idx] = value
		idx >>= 1
		while idx:
			self.data[idx] = self._func(self.data[2 * idx], self.data[2 * idx + 1])
			idx >>= 1

	def __len__(self):
		return self._len

	def query(self, start, stop):
		if start == stop:
			return self.__getitem__(start)
		stop += 1
		start += self._size
		stop += self._size
		res = self._default
		while start < stop:
			if start & 1:
				res = self._func(res, self.data[start])
				start += 1
			if stop & 1:
				stop -= 1
				res = self._func(res, self.data[stop])
			start >>= 1
			stop >>= 1
		return res

	def __repr__(self):
		return 'SegmentTree({0})'.format(self.data)

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD

def powm(a, n, m):
	if a == 1 or n == 0:
		return 1
	if n % 2 == 0:
		s = powm(a, n // 2, m)
		return s * s % m
	else:
		return a * powm(a, n - 1, m) % m

def sort_list(list1, list2):
	zipped_pairs = zip(list2, list1)
	z = [x for (_, x) in sorted(zipped_pairs)]
	return z

def product(l):
	por = 1
	for i in range(len(l)):
		por *= l[i]
	return por

def binarySearchCount(arr, n, key):
	left = 0
	right = n - 1
	count = 0
	while left <= right:
		mid = int((right + left) / 2)
		if arr[mid] < key:
			count = mid + 1
			left = mid + 1
		else:
			right = mid - 1
	return count

def countdig(n):
	c = 0
	while n > 0:
		n //= 10
		c += 1
	return c

def binary(x, length):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y

def countGreater(arr, n, k):
	l = 0
	r = n - 1
	leftGreater = n
	while l <= r:
		m = int(l + (r - l) / 2)
		if arr[m] >= k:
			leftGreater = m
			r = m - 1
		else:
			l = m + 1
	return n - leftGreater
n = int(input())
l = list(map(int, input().split()))
q = int(input())
b = [0] * n
t = [0] * n
for i in range(1, n):
	b[i] = max(0, l[i] - l[i - 1])
	t[i] = l[i] - l[i - 1]
b[0] = l[0]
sum = sum(b) - b[0]
print(math.ceil((b[0] + sum) / 2))
for i in range(q):
	(l, r, x) = map(int, input().split())
	if l == 1:
		b[0] += x
	else:
		last = b[l - 1]
		b[l - 1] = t[l - 1] + x
		t[l - 1] += x
		b[l - 1] = max(b[l - 1], 0)
		sum += b[l - 1] - last
	if r != n:
		last = b[r]
		b[r] = t[r] - x
		t[r] -= x
		b[r] = max(b[r], 0)
		sum += b[r] - last
	print(math.ceil((b[0] + sum) / 2))


import sys
input = sys.stdin.readline
import math
n = int(input())
num = list(map(int, input().split()))
first = num[0]
diff = []
for i in range(n - 1):
	diff.append(num[i + 1] - num[i])
plus = 0
for j in diff:
	if j > 0:
		plus += j
print(math.ceil((first + plus) / 2))
q = int(input())
for k in range(q):
	(l, r, x) = map(int, input().split())
	if l != 1:
		check_1 = diff[l - 2]
		diff[l - 2] += x
		if check_1 > 0 and diff[l - 2] > 0:
			plus += x
		elif check_1 > 0 and diff[l - 2] <= 0:
			plus -= check_1
		elif check_1 <= 0 and diff[l - 2] > 0:
			plus += diff[l - 2]
	if l == 1:
		first += x
	if r != len(num):
		check_2 = diff[r - 1]
		diff[r - 1] -= x
		if check_2 > 0 and diff[r - 1] > 0:
			plus -= x
		elif check_2 > 0 and diff[r - 1] <= 0:
			plus -= check_2
		elif check_2 <= 0 and diff[r - 1] > 0:
			plus += diff[r - 1]
	print(math.ceil((first + plus) / 2))


import sys

def main():
	_T_ = 1
	for _t_ in range(_T_):
		n = inin()
		a = inar()
		d = [0 for i in range(n - 1)]
		k = 0
		for i in range(1, n):
			d[i - 1] += a[i] - a[i - 1]
			k += max(0, a[i] - a[i - 1])
		x = (a[0] + k + 1) // 2
		print(x)
		q = inin()
		for _ in range(q):
			(l, r, c) = inar()
			l -= 1
			r -= 1
			if l == 0:
				a[0] += c
			else:
				if d[l - 1] >= 0:
					k -= d[l - 1]
				d[l - 1] += c
				if d[l - 1] >= 0:
					k += d[l - 1]
			if r == n - 1:
				pass
			else:
				if d[r] >= 0:
					k -= d[r]
				d[r] -= c
				if d[r] >= 0:
					k += d[r]
			x = (a[0] + k + 1) // 2
			print(x)
inp = sys.stdin.buffer.readline
inar = lambda : list(map(int, inp().split()))
inin = lambda : int(inp())
inst = lambda : inp().decode().rstrip('\n\r')
if 1:
	import threading
	sys.setrecursionlimit(10 ** 7)
	threading.stack_size(10 ** 8)
	threading.Thread(target=main).start()
else:
	main()


from sys import stdin, stdout
from math import ceil

def main():
	t = 1
	for _ in range(t):
		n = int(stdin.readline())
		a = [int(i) for i in stdin.readline().split()]
		q = int(stdin.readline())
		diffs = [0] * (n - 1)
		start = a[0]
		for i in range(n - 1):
			diffs[i] = a[i + 1] - a[i]
		upstep = 0
		for d in diffs:
			if d > 0:
				upstep += d
		val = ceil((start + upstep) / 2.0)
		print(val)
		for _ in range(q):
			(l, r, x) = [int(i) for i in stdin.readline().split()]
			l -= 1
			r -= 1
			if l == 0:
				start += x
			else:
				old = diffs[l - 1]
				diffs[l - 1] += x
				new = diffs[l - 1]
				if old > 0:
					upstep -= old
				if new > 0:
					upstep += new
			if r != n - 1:
				old = diffs[r]
				diffs[r] -= x
				new = diffs[r]
				if old > 0:
					upstep -= old
				if new > 0:
					upstep += new
			val = ceil((start + upstep) / 2.0)
			print(val)
main()


from collections import deque
import sys

def max(a, b):
	if a > b:
		return a
	else:
		return b

def input():
	return sys.stdin.readline()[:-1]

def main():
	N = int(input())
	A = list(map(int, input().split()))
	B = [A[i + 1] - A[i] for i in range(N - 1)]
	S = 0
	for i in range(N - 1):
		if A[i + 1] > A[i]:
			S += A[i + 1] - A[i]
	if (A[0] + S) % 2 == 0:
		print((A[0] + S) // 2)
	else:
		print((A[0] + S + 1) // 2)
	Q = int(input())
	for i in range(Q):
		(L, R, X) = list(map(int, input().split()))
		(L, R) = (L - 1, R - 1)
		if L > 0:
			temp = B[L - 1]
			B[L - 1] += X
			S = S - max(0, temp) + max(0, B[L - 1])
		else:
			A[0] += X
		if R < N - 1:
			temp = B[R]
			B[R] -= X
			S = S - max(0, temp) + max(0, B[R])
		if (A[0] + S) % 2 == 0:
			print((A[0] + S) // 2)
		else:
			print((A[0] + S + 1) // 2)
main()


import sys
n = int(sys.stdin.readline().strip())
a = list(map(int, sys.stdin.readline().strip().split()))
d = []
b = 0
c = 0
F = a[0]
L = a[-1]
for i in range(1, n):
	x = a[i] - a[i - 1]
	if x >= 0:
		b = b + x
	else:
		c = c - x
	d.append(x)
Q = int(sys.stdin.readline().strip())
for q in range(0, Q + 1):
	if q > 0:
		(l, r, x) = list(map(int, sys.stdin.readline().strip().split()))
	else:
		(l, r, x) = (1, 1, 0)
	if x != 0 and l > 1:
		if x >= 0 and d[l - 2] >= 0:
			b = b + x
		elif x >= 0 and d[l - 2] < 0:
			b = b + x - min(-d[l - 2], x)
			c = c - min(-d[l - 2], x)
		elif x < 0 and d[l - 2] >= 0:
			c = c - min(d[l - 2], -x) - x
			b = b - min(d[l - 2], -x)
		elif x < 0 and d[l - 2] < 0:
			c = c - x
		d[l - 2] = d[l - 2] + x
	elif x != 0 and l == 1:
		F = F + x
	if x != 0 and r < n:
		if x <= 0 and d[r - 1] >= 0:
			b = b - x
		elif x <= 0 and d[r - 1] < 0:
			b = b - x - min(-x, -d[r - 1])
			c = c - min(-x, -d[r - 1])
		elif x > 0 and d[r - 1] >= 0:
			c = c - min(x, d[r - 1]) + x
			b = b - min(x, d[r - 1])
		elif x > 0 and d[r - 1] < 0:
			c = c + x
		d[r - 1] = d[r - 1] - x
	elif x != 0 and r == n:
		L = L + x
	print((L + F + b + c + 3) // 4)


import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush, nsmallest
from math import ceil, floor, gcd, fabs, factorial, fmod, sqrt, inf, log
from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction
from decimal import Decimal
mod = pow(10, 9) + 7
mod2 = 998244353

def data():
	return sys.stdin.readline().strip()

def out(var, end='\n'):
	sys.stdout.write(str(var) + end)

def outa(*var, end='\n'):
	sys.stdout.write(' '.join(map(str, var)) + end)

def l():
	return list(sp())

def sl():
	return list(ssp())

def sp():
	return map(int, data().split())

def ssp():
	return map(str, data().split())

def l1d(n, val=0):
	return [val for i in range(n)]

def l2d(n, m, val=0):
	return [l1d(n, val) for j in range(m)]
n = int(data())
arr = l()
diff = []
s = 0
for i in range(1, n):
	diff.append(arr[i] - arr[i - 1])
	s += max(0, arr[i] - arr[i - 1])
first = arr[0]
out((s + first + 1) // 2)
for _ in range(int(data())):
	(L, R, x) = sp()
	L -= 1
	if L == 0:
		first += x
	else:
		if diff[L - 1] > 0:
			s -= diff[L - 1]
		diff[L - 1] += x
		if diff[L - 1] > 0:
			s += diff[L - 1]
	if R <= n - 1:
		if diff[R - 1] > 0:
			s -= diff[R - 1]
		diff[R - 1] -= x
		if diff[R - 1] > 0:
			s += diff[R - 1]
	out((s + first + 1) // 2)


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
PLUS = [0] * (n - 1)
for i in range(n - 1):
	PLUS[i] = A[i + 1] - A[i]
S = 0
for p in PLUS:
	if p > 0:
		S += p
print((S + A[0] + 1) // 2)
Q = int(input())
for queries in range(Q):
	(l, r, x) = map(int, input().split())
	if l >= 2:
		ptemp = PLUS[l - 2]
		PLUS[l - 2] += x
		if x > 0:
			if PLUS[l - 2] > 0:
				S += PLUS[l - 2] - max(0, ptemp)
		elif ptemp > 0:
			S -= ptemp - max(0, PLUS[l - 2])
	else:
		A[0] += x
	if r < n:
		ptemp = PLUS[r - 1]
		PLUS[r - 1] -= x
		if x < 0:
			if PLUS[r - 1] > 0:
				S += PLUS[r - 1] - max(0, ptemp)
		elif ptemp > 0:
			S -= ptemp - max(0, PLUS[r - 1])
	print((S + A[0] + 1) // 2)


import os, sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	a = list(map(int, input().split()))
	lst = []
	(su_pos, su_neg) = (0, 0)
	for i in range(1, n):
		x = a[i] - a[i - 1]
		lst.append(x)
		if x > 0:
			su_pos += x
		else:
			su_neg -= x
	print((a[0] + su_pos + 1) // 2)
	for _ in range(int(input())):
		(x, y, z) = map(int, input().split())
		x -= 1
		y -= 1
		if not x:
			a[0] += z
		if y != n - 1:
			if lst[y] < 0:
				su_neg += lst[y]
			else:
				su_pos -= lst[y]
			lst[y] -= z
			if lst[y] < 0:
				su_neg -= lst[y]
			else:
				su_pos += lst[y]
		if x:
			if lst[x - 1] < 0:
				su_neg += lst[x - 1]
			else:
				su_pos -= lst[x - 1]
			lst[x - 1] += z
			if lst[x - 1] < 0:
				su_neg -= lst[x - 1]
			else:
				su_pos += lst[x - 1]
		print((a[0] + su_pos + 1) // 2)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
main()


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
start = a[0]
diffs = []
for i in range(n - 1):
	diffs.append(a[i + 1] - a[i])
pos = 0
for v in diffs:
	if v > 0:
		pos += v
final = []

def out(ans):
	final.append((ans + 1) // 2)
out(pos + start)
q = int(input())
for _ in range(q):
	(l, r, x) = map(int, input().split())
	if l > 1:
		if diffs[l - 2] >= 0:
			pos -= diffs[l - 2]
		diffs[l - 2] += x
		if diffs[l - 2] >= 0:
			pos += diffs[l - 2]
	else:
		start += x
	if r < n:
		if diffs[r - 1] >= 0:
			pos -= diffs[r - 1]
		diffs[r - 1] -= x
		if diffs[r - 1] >= 0:
			pos += diffs[r - 1]
	out(pos + start)
print('\n'.join(map(str, final)))


import sys
input = sys.stdin.readline

def solve():
	n = int(input())
	a = list(map(int, input().split()))
	b = [0] * (n + 2)
	sp = 0
	sn = 0
	for i in range(1, n):
		b[i] = a[i] - a[i - 1]
		if b[i] < 0:
			sn += b[i]
		else:
			sp += b[i]
	b[0] = a[0]
	print((b[0] + sp + 1) // 2)
	for q in range(int(input())):
		(l, r, x) = map(int, input().split())
		if l > 1:
			if b[l - 1] < 0:
				sn -= b[l - 1]
			else:
				sp -= b[l - 1]
			b[l - 1] += x
			if b[l - 1] < 0:
				sn += b[l - 1]
			else:
				sp += b[l - 1]
		else:
			b[l - 1] += x
		if r < n:
			if b[r] < 0:
				sn -= b[r]
			else:
				sp -= b[r]
			b[r] -= x
			if b[r] < 0:
				sn += b[r]
			else:
				sp += b[r]
		else:
			b[r] -= x
		print((b[0] + sp + 1) // 2)
solve()


n = int(input())
a = [int(i) for i in input().split()]
d = [a[i + 1] - a[i] for i in range(n - 1)]
dif = sum([max(v, 0) for v in d])
print((a[0] - dif + 1) // 2 + dif)
for k in range(int(input())):
	(l, r, x) = [int(i) for i in input().split()]
	(l, r) = (l - 1, r - 1)
	if l == 0:
		a[0] += x
	if l > 0:
		dif -= max(0, d[l - 1])
		d[l - 1] += x
		dif += max(0, d[l - 1])
	if r < n - 1:
		dif -= max(0, d[r])
		d[r] -= x
		dif += max(0, d[r])
	print((a[0] - dif + 1) // 2 + dif)


import os
import sys
from io import BytesIO, IOBase

def main():
	T = 1
	while T:
		T -= 1
		n = iin()
		a = lin()
		a1 = [a[i] - a[i - 1] for i in range(1, n)]
		K = sum([i for i in a1 if i > 0])
		q = iin()
		x = (a[0] + K) // 2
		print(max(x, a[0] - x + K))
		for _ in range(q):
			(l, r, x) = lin()
			l -= 1
			r -= 1
			if l > 0:
				K -= max(0, a1[l - 1])
				a1[l - 1] += x
				K += max(0, a1[l - 1])
			if r < n - 1:
				K -= max(0, a1[r])
				a1[r] -= x
				K += max(0, a1[r])
			if l == 0:
				a[l] += x
			x = (a[0] + K) // 2
			print(max(x, a[0] - x + K))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def iin():
	return int(input())

def lin():
	return list(map(int, input().split()))
main()


import sys
inp = sys.stdin.buffer.readline
inar = lambda : list(map(int, inp().split()))
inin = lambda : int(inp())
inst = lambda : inp().decode().rstrip('\n\r')
_T_ = 1
for _t_ in range(_T_):
	n = inin()
	a = inar()
	d = [0 for i in range(n - 1)]
	k = 0
	for i in range(1, n):
		d[i - 1] += a[i] - a[i - 1]
		k += max(0, a[i] - a[i - 1])
	x = (a[0] + k + 1) // 2
	print(x)
	q = inin()
	for _ in range(q):
		(l, r, c) = inar()
		l -= 1
		r -= 1
		if l == 0:
			a[0] += c
		else:
			if d[l - 1] >= 0:
				k -= d[l - 1]
			d[l - 1] += c
			if d[l - 1] >= 0:
				k += d[l - 1]
		if r == n - 1:
			pass
		else:
			if d[r] >= 0:
				k -= d[r]
			d[r] -= c
			if d[r] >= 0:
				k += d[r]
		x = (a[0] + k + 1) // 2
		print(x)


import sys
input = sys.stdin.buffer.readline

class BIT:

	def __init__(self, n):
		self.size = n
		self.bit = [0] * (n + 1)

	def build(self, array):
		for i in range(1, self.size + 1):
			if i - 1 + (i & -i) >= self.size:
				self.bit[i] = array[i - 1]
			else:
				self.bit[i] = array[i - 1] - array[i - 1 + (i & -i)]

	def _add(self, i, val):
		while i > 0:
			self.bit[i] += val
			i -= i & -i

	def __getitem__(self, i):
		i = i + 1
		s = 0
		while i <= self.size:
			s += self.bit[i]
			i += i & -i
		return s

	def add(self, l, r, val):
		self._add(r, val)
		self._add(l, -val)
n = int(input())
a = list(map(int, input().split()))
q = int(input())
queries = [list(map(int, input().split())) for i in range(q)]
diff = [a[i + 1] - a[i] for i in range(n - 1)]
diff_sum = 0
for d in diff:
	if d > 0:
		diff_sum += d
bit = BIT(n)
bit.build(a)
val0 = bit[0]
ans = []
ans.append((diff_sum + val0 + 1) // 2)
for (l, r, val) in queries:
	l -= 1
	bit.add(l, r, val)
	(d1, d2) = (-1, -1)
	(d1_new, d2_new) = (-1, -1)
	if l - 1 >= 0:
		d1 = diff[l - 1]
		d1_new = bit[l] - bit[l - 1]
		diff[l - 1] = d1_new
	if r - 1 < n - 1:
		d2 = diff[r - 1]
		d2_new = bit[r] - bit[r - 1]
		diff[r - 1] = d2_new
	diff_sum -= max(d1, 0) + max(d2, 0)
	diff_sum += max(d1_new, 0) + max(d2_new, 0)
	if l == 0:
		val0 += val
	ans.append((diff_sum + val0 + 1) // 2)
print('\n'.join(map(str, ans)))


from sys import stdin
n = int(stdin.readline())
a = [int(x) for x in stdin.readline().split()]
prev = a[0]
diff = [prev]
bsum = prev
for el in a[1:]:
	d = el - prev
	diff.append(d)
	if d > 0:
		bsum += d
	prev = el
print((bsum + 1) // 2)
q = int(stdin.readline())
for _ in range(q):
	(l, r, w) = [int(x) for x in stdin.readline().split()]
	if l == 1:
		bsum += w
		diff[l - 1] += w
	else:
		if diff[l - 1] > 0:
			bsum -= diff[l - 1]
		diff[l - 1] += w
		if diff[l - 1] > 0:
			bsum += diff[l - 1]
	if r < n:
		if diff[r] > 0:
			bsum -= diff[r]
		diff[r] -= w
		if diff[r] > 0:
			bsum += diff[r]
	print((bsum + 1) // 2)


import sys

class Fastio:

	def __init__(self):
		self.ibuf = bytearray()
		self.obuf = bytearray()
		self.pil = 0
		self.pir = 0
		self.sz = 1 << 17

	def load(self):
		self.ibuf = self.ibuf[self.pil:]
		self.ibuf.extend(sys.stdin.buffer.read(self.sz))
		self.pil = 0
		self.pir = len(self.ibuf)

	def flush(self):
		sys.stdout.buffer.write(self.obuf)
		self.obuf = bytearray()

	def fastin(self):
		if self.pir - self.pil < 32:
			self.load()
		minus = 0
		x = 0
		while self.ibuf[self.pil] < ord('-'):
			self.pil += 1
		if self.ibuf[self.pil] == ord('-'):
			minus = 1
			self.pil += 1
		while self.ibuf[self.pil] >= ord('0'):
			x = x * 10 + (self.ibuf[self.pil] & 15)
			self.pil += 1
		if minus:
			x = -x
		return x
fastio = Fastio()
rd = fastio.fastin
N = rd()
a = [0] * N
for i in range(N):
	a[i] = rd()
for i in range(N - 1, 0, -1):
	a[i] -= a[i - 1]
p = 0
for i in range(1, N):
	p += max(0, a[i])
print((a[0] + p + 1) // 2)
Q = rd()
for _ in range(Q):
	(l, r, x) = (rd(), rd(), rd())
	l -= 1
	if l != 0:
		p -= max(a[l], 0)
	a[l] += x
	if l != 0:
		p += max(a[l], 0)
	if r != N:
		p -= max(a[r], 0)
		a[r] -= x
		p += max(a[r], 0)
	print((a[0] + p + 1) // 2)


import io, os
inp = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
inar = lambda : list(map(int, inp().split()))
inin = lambda : int(inp())
inst = lambda : inp().decode().rstrip('\n\r')
_T_ = 1
for _t_ in range(_T_):
	n = inin()
	a = inar()
	d = [0 for i in range(n - 1)]
	k = 0
	for i in range(1, n):
		d[i - 1] += a[i] - a[i - 1]
		k += max(0, a[i] - a[i - 1])
	x = (a[0] + k + 1) // 2
	print(x)
	q = inin()
	for _ in range(q):
		(l, r, c) = inar()
		l -= 1
		r -= 1
		if l == 0:
			a[0] += c
		else:
			if d[l - 1] >= 0:
				k -= d[l - 1]
			d[l - 1] += c
			if d[l - 1] >= 0:
				k += d[l - 1]
		if r == n - 1:
			pass
		else:
			if d[r] >= 0:
				k -= d[r]
			d[r] -= c
			if d[r] >= 0:
				k += d[r]
		x = (a[0] + k + 1) // 2
		print(x)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from itertools import *
import bisect
from heapq import *
from math import *
from copy import *
from collections import deque
from collections import Counter as counter
from itertools import combinations as comb
from itertools import permutations as permutate
from bisect import bisect_left as bl
from bisect import bisect_right as br
from bisect import bisect
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', sys.stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
if sys.version_info[0] < 3:
	(sys.stdin, sys.stdout) = (FastIO(sys.stdin), FastIO(sys.stdout))
else:
	(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
from types import GeneratorType

def iterative(f, stack=[]):

	def wrapped_func(*args, **kwargs):
		if stack:
			return f(*args, **kwargs)
		to = f(*args, **kwargs)
		while True:
			if type(to) is GeneratorType:
				stack.append(to)
				to = next(to)
				continue
			stack.pop()
			if not stack:
				break
			to = stack[-1].send(to)
		return to
	return wrapped_func
mod = 1000000007

def inp():
	return sys.stdin.readline().rstrip('\r\n')

def out(var):
	sys.stdout.write(str(var))

def lis():
	return list(map(int, inp().split()))

def stringlis():
	return list(map(str, inp().split()))

def sep():
	return map(int, inp().split())

def strsep():
	return map(str, inp().split())

def zerolist(n):
	return [0] * n

def nextline():
	out('\n')

def testcase(t):
	for pp in range(t):
		solve(pp)

def printlist(a):
	for p in range(0, len(a)):
		out(str(a[p]) + ' ')

def google(p):
	print('Case #' + str(p), end=': ')

def lcm(a, b):
	return a * b // gcd(a, b)

def power(x, y, p):
	res = 1
	x = x % p
	if x == 0:
		return 0
	while y > 0:
		if y & 1 == 1:
			res = res * x % p
		y = y >> 1
		x = x * x % p
	return res

def ncr(n, r):
	return factorial(n) // (factorial(r) * factorial(max(n - r, 1)))

def isPrime(n):
	if n <= 1:
		return False
	if n <= 3:
		return True
	if n % 2 == 0 or n % 3 == 0:
		return False
	i = 5
	while i * i <= n:
		if n % i == 0 or n % (i + 2) == 0:
			return False
		i = i + 6
	return True

def solve(case):
	n = int(inp())
	a = lis()
	gaps = [0]
	for i in range(1, n):
		gaps.append(a[i] - a[i - 1])
	pos = 0
	for i in range(n):
		pos += max(0, gaps[i])
	x = (a[0] - pos) // 2
	print(max(x + pos, -x + a[0]))
	for i in range(int(inp())):
		(l, r, xx) = sep()
		l -= 1
		r -= 1
		if l == 0 and r < n - 1:
			if xx >= 0:
				if gaps[r + 1] >= xx:
					pos -= xx
				else:
					pos -= max(gaps[r + 1], 0)
				gaps[r + 1] -= xx
			else:
				xx *= -1
				if gaps[r + 1] >= 0:
					pos += xx
				else:
					pos += max(0, gaps[r + 1] + xx)
				gaps[r + 1] += xx
				xx *= -1
		elif r == n - 1 and l > 0:
			if xx >= 0:
				if gaps[l] >= 0:
					pos += xx
				else:
					pos += max(0, gaps[l] + xx)
				gaps[l] += xx
			else:
				xx *= -1
				if gaps[l] >= xx:
					pos -= xx
				else:
					pos -= max(gaps[l], 0)
				gaps[l] -= xx
				xx *= -1
		elif l > 0 and r < n - 1:
			if xx >= 0:
				if gaps[r + 1] >= xx:
					pos -= xx
				else:
					pos -= max(gaps[r + 1], 0)
				gaps[r + 1] -= xx
			else:
				xx *= -1
				if gaps[r + 1] >= 0:
					pos += xx
				else:
					pos += max(0, gaps[r + 1] + xx)
				gaps[r + 1] += xx
				xx *= -1
			if xx >= 0:
				if gaps[l] >= 0:
					pos += xx
				else:
					pos += max(0, gaps[l] + xx)
				gaps[l] += xx
			else:
				xx *= -1
				if gaps[l] >= xx:
					pos -= xx
				else:
					pos -= max(gaps[l], 0)
				gaps[l] -= xx
				xx *= -1
		if l == 0:
			a[0] += xx
		x = (a[0] - pos) // 2
		print(max(x + pos, -x + a[0]))
testcase(1)


import sys, math
import io, os
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter

def data():
	return sys.stdin.readline().strip()

def mdata():
	return list(map(int, data().split()))

def outl(var):
	sys.stdout.write('\n'.join(map(str, var)) + '\n')

def out(var):
	sys.stdout.write(str(var) + '\n')
from decimal import Decimal
mod = int(1000000000.0) + 7
INF = float('inf')

def construct(BIT, arr):
	for i in range(len(arr)):
		BIT[i + 1] = arr[i]

def updateBIT(BIT, v, w):
	while v <= n:
		BIT[v] += w
		v += v & -v

def getvalue(BIT, v):
	ANS = 0
	while v != 0:
		ANS += BIT[v]
		v -= v & -v
	return ANS

def bisect_on_BIT(BIT, x):
	if x <= 0:
		return 0
	ANS = 0
	h = 1 << n - 1
	while h > 0:
		if ANS + h <= n and BIT[ANS + h] < x:
			x -= BIT[ANS + h]
			ANS += h
		h //= 2
	return ANS + 1

def update(BIT, l, r, val):
	updateBIT(BIT, l, val)
	updateBIT(BIT, r + 1, -val)
n = int(input())
a = mdata()
BIT = [0] * (n + 1)
(inc, dec) = (0, 0)
for i in range(1, n):
	if a[i - 1] <= a[i]:
		inc += abs(a[i] - a[i - 1])
k = (a[0] + inc) // 2 + (a[0] + inc) % 2
ans = [(a[0] + inc) // 2 + (a[0] + inc) % 2]
for i in range(int(data())):
	(l, r, val) = mdata()
	if l != 1:
		(u, v) = (a[l - 2] + getvalue(BIT, l - 1), a[l - 1] + getvalue(BIT, l))
		if u < v + val:
			if u < v:
				inc += val
			else:
				inc += v + val - u
		elif u < v:
			inc -= v - u
	if r != n:
		(u, v) = (a[r - 1] + getvalue(BIT, r), a[r] + getvalue(BIT, r + 1))
		if u + val < v:
			if u < v:
				inc -= val
			else:
				inc += v - u - val
		elif u < v:
			inc -= v - u
	update(BIT, l, r, val)
	v = getvalue(BIT, 1)
	ans.append((a[0] + v + inc) // 2 + (a[0] + v + inc) % 2)
outl(ans)


n = int(input())
aa = list(map(int, input().split()))
dd = [0] * n
s = 0
for i in range(n - 1):
	dd[i + 1] = aa[i + 1] - aa[i]
for d in dd:
	if d > 0:
		s += d
b0 = (aa[0] - s) // 2
print(max(b0 + s, aa[0] - b0))

def add(i, a, s):
	if i == 0:
		aa[0] += a
		return s
	if dd[i] > 0:
		s -= dd[i]
	dd[i] += a
	if dd[i] > 0:
		s += dd[i]
	return s
for _ in range(int(input())):
	(l, r, x) = map(int, input().split())
	l -= 1
	s = add(l, x, s)
	if r < n:
		s = add(r, -x, s)
	b0 = (aa[0] - s) // 2
	print(max(b0 + s, aa[0] - b0))


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(map(int, sys.stdin.readline().rstrip().split()))

def N():
	return int(input())

def print_list(l):
	print(' '.join(map(str, l)))
n = N()
a = RLL()
p = [0]
for i in range(1, n):
	p.append(a[i] - a[i - 1])
now = sum((i for i in p if i > 0))
s = a[0]
print(s + now + 1 >> 1)
q = N()
for _ in range(q):
	(l, r, x) = RL()
	if l == 1:
		s += x
	else:
		tmp = p[l - 1]
		p[l - 1] += x
		if tmp < 0:
			delta = max(0, p[l - 1])
		else:
			delta = max(-tmp, x)
		now += delta
	if r < n:
		tmp = p[r]
		p[r] -= x
		if tmp < 0:
			delta = max(0, p[r])
		else:
			delta = max(-tmp, -x)
		now += delta
	print(s + now + 1 >> 1)


import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

def RL():
	return map(int, sys.stdin.readline().rstrip().split())

def RLL():
	return list(RL())

def N():
	return int(input())

def comb(n, m):
	return factorial(n) / (factorial(m) * factorial(n - m)) if n >= m else 0

def perm(n, m):
	return factorial(n) // factorial(n - m) if n >= m else 0

def mdis(x1, y1, x2, y2):
	return abs(x1 - x2) + abs(y1 - y2)

def toord(c):
	return ord(c) - ord('a')

def lcm(a, b):
	return a * b // gcd(a, b)
mod = 998244353
INF = float('inf')
from math import factorial, sqrt, ceil, floor, gcd
from collections import Counter, defaultdict, deque
from heapq import heapify, heappop, heappush

def main():
	n = N()
	arr = RLL()
	q = N()
	s = 0
	rec = []
	for i in range(1, n):
		rec.append(arr[i] - arr[i - 1])
		if rec[-1] > 0:
			s += rec[-1]
	print(ceil((s + arr[0]) / 2))
	for (l, r, x) in [RLL() for _ in range(q)]:
		l -= 1
		r -= 1
		if l == 0:
			arr[0] += x
		else:
			s -= max(0, rec[l - 1])
			rec[l - 1] += x
			s += max(0, rec[l - 1])
		if r < n - 1:
			s -= max(0, rec[r])
			rec[r] -= x
			s += max(0, rec[r])
		print(ceil((s + arr[0]) / 2))
main()


mod = 1000000007
eps = 10 ** (-9)

def main():
	import sys
	input = sys.stdin.buffer.readline

	class Bit:

		def __init__(self, n):
			self.size = n
			self.tree = [0] * (n + 1)

		def sum(self, i):
			s = 0
			while i > 0:
				s += self.tree[i]
				i -= i & -i
			return s

		def add(self, i, x):
			while i <= self.size:
				self.tree[i] += x
				i += i & -i

		def lower_bound(self, w):
			if w <= 0:
				return 0
			x = 0
			k = 1 << self.size.bit_length() - 1
			while k:
				if x + k <= self.size and self.tree[x + k] < w:
					w -= self.tree[x + k]
					x += k
				k >>= 1
			return x + 1
	N = int(input())
	A = list(map(int, input().split()))
	bit = Bit(N)
	bit.add(1, A[0])
	b = A[0]
	ans = []
	for i in range(1, N):
		bit.add(i + 1, A[i] - A[i - 1])
		if A[i] - A[i - 1] > 0:
			b += A[i] - A[i - 1]
	ans.append((b + 1) // 2)
	for _ in range(int(input())):
		(l, r, x) = map(int, input().split())
		if l != 1:
			dl_ori = bit.sum(l) - bit.sum(l - 1)
			dl_new = dl_ori + x
			dl_ori = max(0, dl_ori)
			dl_new = max(0, dl_new)
			b += dl_new - dl_ori
		else:
			b += x
		if r != N:
			dr_ori = bit.sum(r + 1) - bit.sum(r)
			dr_new = dr_ori - x
			dr_ori = max(0, dr_ori)
			dr_new = max(0, dr_new)
			b += dr_new - dr_ori
		bit.add(l, x)
		if r != N:
			bit.add(r + 1, -x)
		ans.append((b + 1) // 2)
	print(*ans, sep='\n')
main()


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
diff = [0 for i in range(n)]
for i in range(1, n):
	diff[i] = a[i] - a[i - 1]
S = 0
for i in range(1, n):
	if diff[i] >= 0:
		S += diff[i]
first = a[0]
ans = []
res = S + first
ans.append((res + 1) // 2)
Q = int(input())
for _ in range(Q):
	(l, r, x) = map(int, input().split())
	l = l - 1
	r = r - 1
	if l == 0:
		first += x
	else:
		if diff[l] >= 0:
			S -= diff[l]
		diff[l] += x
		if diff[l] >= 0:
			S += diff[l]
	if r + 1 < n:
		if diff[r + 1] >= 0:
			S -= diff[r + 1]
		diff[r + 1] -= x
		if diff[r + 1] >= 0:
			S += diff[r + 1]
	res = S + first
	ans.append((res + 1) // 2)
for a in ans:
	print(a)


import sys
input = sys.stdin.readline
(N,) = map(int, input().split())
X = list(map(int, input().split()))
Y = [0]
for i in range(N - 1):
	Y.append(X[i + 1] - X[i])
Y.append(0)
t = X[0]
for y in Y:
	if y > 0:
		t += y
print((t + 1) // 2)
(M,) = map(int, input().split())
for i in range(M):
	(l, r, x) = map(int, input().split())
	b = max(Y[l - 1], 0)
	Y[l - 1] += x
	n = max(Y[l - 1], 0)
	dd = 0
	if l != 1:
		dd = n - b
	b2 = max(Y[r], 0)
	Y[r] -= x
	n2 = max(Y[r], 0)
	if r != N:
		dd += n2 - b2
	if l == 1:
		t += x
	t += dd
	print((t + 1) // 2)


import os
import sys
import math
from io import BytesIO, IOBase
from fractions import Fraction
import collections
from itertools import permutations
from collections import defaultdict
from collections import deque
import threading
threading.stack_size(10 ** 8)
sys.setrecursionlimit(300000)
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')

class Factorial:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorials = [1, 1]
		self.invModulos = [0, 1]
		self.invFactorial_ = [1, 1]

	def calc(self, n):
		if n <= -1:
			print('Invalid argument to calculate n!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.factorials):
			return self.factorials[n]
		nextArr = [0] * (n + 1 - len(self.factorials))
		initialI = len(self.factorials)
		prev = self.factorials[-1]
		m = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * i % m
		self.factorials += nextArr
		return self.factorials[n]

	def inv(self, n):
		if n <= -1:
			print('Invalid argument to calculate n^(-1)')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		p = self.MOD
		pi = n % p
		if pi < len(self.invModulos):
			return self.invModulos[pi]
		nextArr = [0] * (n + 1 - len(self.invModulos))
		initialI = len(self.invModulos)
		for i in range(initialI, min(p, n + 1)):
			next = -self.invModulos[p % i] * (p // i) % p
			self.invModulos.append(next)
		return self.invModulos[pi]

	def invFactorial(self, n):
		if n <= -1:
			print('Invalid argument to calculate (n^(-1))!')
			print('n must be non-negative value. But the argument was ' + str(n))
			exit()
		if n < len(self.invFactorial_):
			return self.invFactorial_[n]
		self.inv(n)
		nextArr = [0] * (n + 1 - len(self.invFactorial_))
		initialI = len(self.invFactorial_)
		prev = self.invFactorial_[-1]
		p = self.MOD
		for i in range(initialI, n + 1):
			prev = nextArr[i - initialI] = prev * self.invModulos[i % p] % p
		self.invFactorial_ += nextArr
		return self.invFactorial_[n]

class Combination:

	def __init__(self, MOD):
		self.MOD = MOD
		self.factorial = Factorial(MOD)

	def ncr(self, n, k):
		if k < 0 or n < k:
			return 0
		k = min(k, n - k)
		f = self.factorial
		return f.calc(n) * f.invFactorial(max(n - k, k)) * f.invFactorial(min(k, n - k)) % self.MOD
mod = 10 ** 9 + 7
n = int(input())
a = list(map(int, input().split()))
s = 0
ab = [0] * n
diff = [0] * n
ab[0] = a[0]
for i in range(1, n):
	s += max(0, a[i] - a[i - 1])
	ab[i] = max(0, a[i] - a[i - 1])
	diff[i] = a[i] - a[i - 1]
d = math.ceil((ab[0] + s) / 2)
print(d)
for i in range(int(input())):
	(l, r, x) = map(int, input().split())
	if l == 1:
		ab[0] += x
	else:
		last = ab[l - 1]
		ab[l - 1] = diff[l - 1] + x
		diff[l - 1] += x
		ab[l - 1] = max(ab[l - 1], 0)
		s += ab[l - 1] - last
	if r != n:
		last = ab[r]
		ab[r] = diff[r] - x
		diff[r] -= x
		ab[r] = max(ab[r], 0)
		s += ab[r] - last
	print(math.ceil((ab[0] + s) / 2))


from math import inf, log2

class LazySegmentTree:

	def __init__(self, array, func=lambda a, b: a + b):
		self.n = len(array)
		self.size = 2 ** (int(log2(self.n - 1)) + 1) if self.n != 1 else 1
		self.func = func
		self.default = 0 if self.func != min else inf
		self.data = [self.default] * (2 * self.size)
		self.lazy = [0] * (2 * self.size)
		self.process(array)

	def process(self, array):
		self.data[self.size:self.size + self.n] = array
		for i in range(self.size - 1, -1, -1):
			self.data[i] = self.func(self.data[2 * i], self.data[2 * i + 1])

	def push(self, index):
		self.lazy[2 * index] += self.lazy[index]
		self.lazy[2 * index + 1] += self.lazy[index]
		self.data[2 * index] += self.lazy[index]
		self.data[2 * index + 1] += self.lazy[index]
		self.lazy[index] = 0

	def build(self, index):
		index >>= 1
		while index:
			self.data[index] = self.func(self.data[2 * index], self.data[2 * index + 1]) + self.lazy[index]
			index >>= 1

	def query(self, alpha, omega):
		res = self.default
		alpha += self.size
		omega += self.size + 1
		for i in range(len(bin(alpha)[2:]) - 1, 0, -1):
			self.push(alpha >> i)
		for i in range(len(bin(omega - 1)[2:]) - 1, 0, -1):
			self.push(omega - 1 >> i)
		while alpha < omega:
			if alpha & 1:
				res = self.func(res, self.data[alpha])
				alpha += 1
			if omega & 1:
				omega -= 1
				res = self.func(res, self.data[omega])
			alpha >>= 1
			omega >>= 1
		return res

	def update(self, alpha, omega, value):
		alpha += self.size
		omega += self.size + 1
		(l, r) = (alpha, omega)
		while alpha < omega:
			if alpha & 1:
				self.data[alpha] += value
				self.lazy[alpha] += value
				alpha += 1
			if omega & 1:
				omega -= 1
				self.data[omega] += value
				self.lazy[omega] += value
			alpha >>= 1
			omega >>= 1
		self.build(l)
		self.build(r - 1)
import os
import sys
from io import BytesIO, IOBase
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self):
		while self.newlines == 0:
			b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			os.write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from math import gcd, ceil

def pre(s):
	n = len(s)
	pi = [0] * n
	for i in range(1, n):
		j = pi[i - 1]
		while j and s[i] != s[j]:
			j = pi[j - 1]
		if s[i] == s[j]:
			j += 1
		pi[i] = j
	return pi

def prod(a):
	ans = 1
	for each in a:
		ans = ans * each
	return ans

def lcm(a, b):
	return a * b // gcd(a, b)

def binary(x, length=16):
	y = bin(x)[2:]
	return y if len(y) >= length else '0' * (length - len(y)) + y
for _ in range(int(input()) if not True else 1):
	n = int(input())
	a = list(map(int, input().split()))
	k = 0
	b = [0] * n
	for i in range(1, n):
		k += max(a[i] - a[i - 1], 0)
		b[i] = a[i] - a[i - 1]
	print(ceil((a[0] + k) / 2))
	for __ in range(int(input())):
		(l, r, x) = map(int, input().split())
		l -= 1
		r -= 1
		if l == 0:
			a[0] += x
		if r != n - 1:
			k -= max(0, b[r + 1])
			b[r + 1] -= x
			k += max(0, b[r + 1])
		if l != 0:
			k -= max(0, b[l])
			b[l] += x
			k += max(0, b[l])
		print(ceil((a[0] + k) / 2))


from os import path
import sys
from heapq import heappush, heappop
from functools import cmp_to_key as ctk
from collections import deque, defaultdict as dd
from bisect import bisect, bisect_left, bisect_right, insort, insort_left, insort_right
from itertools import permutations
from datetime import datetime
from math import ceil, sqrt, log, gcd

def ii():
	return int(input())

def si():
	return input().rstrip()

def mi():
	return map(int, input().split())

def li():
	return list(mi())
abc = 'abcdefghijklmnopqrstuvwxyz'
mod = 1000000007
inf = float('inf')
vow = ['a', 'e', 'i', 'o', 'u']
(dx, dy) = ([-1, 1, 0, 0], [0, 0, 1, -1])

def bo(i):
	return ord(i) - ord('a')
file = 1

def solve():
	n = ii()
	a = li()
	d = [0] * (n + 1)
	K = 0
	a.insert(0, 0)

	def answer():
		ans = d[1] + K
		if ans % 2 != 0:
			ans += 1
		print(int(ans // 2))
	for i in range(1, n + 1):
		d[i] = a[i] - a[i - 1]
		if i > 1:
			K += max(0, d[i])
	answer()
	for _ in range(ii()):
		(l, r, x) = mi()
		if l > 1:
			K -= max(0, d[l])
		d[l] += x
		if l > 1:
			K += max(0, d[l])
		if r < n:
			K -= max(0, d[r + 1])
			d[r + 1] -= x
			K += max(0, d[r + 1])
		answer()
if file:
	if path.exists('input.txt'):
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	else:
		input = sys.stdin.readline
solve()


import sys
import io, os
input = sys.stdin.buffer.readline

def main():
	n = int(input())
	A = list(map(int, input().split()))
	q = int(input())
	D = [0] * (n - 1)
	for i in range(n - 1):
		D[i] = A[i + 1] - A[i]
	t = 0
	for d in D:
		if d >= 0:
			t += d
	b = (A[0] - t) // 2
	print(min([max(b - 1 + t, -b + 1 + A[0]), max(b + t, -b + A[0]), max(b + 1 + t, -b - 1 + A[0])]))
	for i in range(q):
		(l, r, x) = map(int, input().split())
		if l == 1:
			A[0] += x
		elif l == n:
			if D[l - 2] >= 0:
				if D[l - 2] + x < 0:
					t -= D[l - 2]
				else:
					t += x
				D[l - 2] += x
			elif D[l - 2] + x >= 0:
				t += D[l - 2] + x
				D[l - 2] += x
			else:
				D[l - 2] += x
		elif D[l - 2] >= 0:
			if D[l - 2] + x < 0:
				t -= D[l - 2]
			else:
				t += x
			D[l - 2] += x
		elif D[l - 2] + x >= 0:
			t += D[l - 2] + x
			D[l - 2] += x
		else:
			D[l - 2] += x
		if r == n:
			pass
		elif D[r - 1] >= 0:
			if D[r - 1] - x < 0:
				t -= D[r - 1]
			else:
				t -= x
			D[r - 1] -= x
		elif D[r - 1] - x >= 0:
			t += D[r - 1] - x
			D[r - 1] -= x
		else:
			D[r - 1] -= x
		b = (A[0] - t) // 2
		print(min([max(b - 1 + t, -b + 1 + A[0]), max(b + t, -b + A[0]), max(b + 1 + t, -b - 1 + A[0])]))
main()


from sys import stdout, stdin
from io import IOBase, BytesIO
from os import read, write, fstat
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

	def __init__(self, file):
		self._fd = file.fileno()
		self.buffer = BytesIO()
		self.writable = 'x' in file.mode or 'r' not in file.mode
		self.write = self.buffer.write if self.writable else None

	def read(self):
		while True:
			b = read(self._fd, max(fstat(self._fd).st_size, BUFSIZE))
			if not b:
				break
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines = 0
		return self.buffer.read()

	def readline(self, size: int=...):
		while self.newlines == 0:
			b = read(self._fd, max(fstat(self._fd).st_size, BUFSIZE))
			self.newlines = b.count(b'\n') + (not b)
			ptr = self.buffer.tell()
			(self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr))
		self.newlines -= 1
		return self.buffer.readline()

	def flush(self):
		if self.writable:
			write(self._fd, self.buffer.getvalue())
			(self.buffer.truncate(0), self.buffer.seek(0))

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')

def print(*args, **kwargs):
	(sep, file) = (kwargs.pop('sep', ' '), kwargs.pop('file', stdout))
	at_start = True
	for x in args:
		if not at_start:
			file.write(sep)
		file.write(str(x))
		at_start = False
	file.write(kwargs.pop('end', '\n'))
	if kwargs.pop('flush', False):
		file.flush()
(stdin, stdout) = (IOWrapper(stdin), IOWrapper(stdout))
input = lambda : stdin.readline().rstrip('\r\n')
n = int(input())
a = [int(x) for x in input().split()]
q = int(input())
ch = [None] * q
c = 0
for i in range(0, q):
	ch[i] = [int(x) for x in input().split()]
for i in range(n - 1, 0, -1):
	a[i] -= a[i - 1]
for i in range(1, n):
	c += max(a[i], 0)
b = (a[0] - c) // 2
r = a[0] - b
print(str(r))
for i in range(0, q):
	l = ch[i][0] - 1
	r = ch[i][1]
	x = ch[i][2]
	if l != 0:
		c -= max(a[l], 0)
	a[l] += x
	if l != 0:
		c += max(a[l], 0)
	if r != n:
		c -= max(a[r], 0)
		a[r] -= x
		c += max(a[r], 0)
	b = (a[0] - c) // 2
	r = a[0] - b
	print(str(r))


from sys import stdin, stdout

def three_sequences(n, a_a, q_a):
	res_a = []
	dif_a = [0] * n
	K = 0
	for i in range(1, n):
		K += max(0, a_a[i] - a_a[i - 1])
		dif_a[i] = a_a[i] - a_a[i - 1]
	res_a.append(calc(K, a_a[0]))
	for q in q_a:
		(l, r, x) = q
		if l > 1:
			K -= max(0, dif_a[l - 1])
			dif_a[l - 1] += x
			K += max(0, dif_a[l - 1])
		if r < n:
			K -= max(0, dif_a[r])
			dif_a[r] -= x
			K += max(0, dif_a[r])
		if l == 1:
			a_a[0] += x
		res_a.append(calc(K, a_a[0]))
	return res_a

def calc(K, a0):
	b0 = (a0 - K) // 2
	bn = b0 + K
	c0 = a_a[0] - b0
	return max(bn, c0)
n = int(stdin.readline())
a_a = list(map(int, stdin.readline().split()))
q = int(stdin.readline())
q_a = []
for _ in range(q):
	(l, r, x) = map(int, stdin.readline().split())
	q_a.append([l, r, x])
res_a = three_sequences(n, a_a, q_a)
for res in res_a:
	stdout.write(str(res) + '\n')


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
lst = []
(su_pos, su_neg) = (0, 0)
for i in range(1, n):
	x = a[i] - a[i - 1]
	lst.append(x)
	if x > 0:
		su_pos += x
	else:
		su_neg -= x
print((a[0] + su_pos + 1) // 2)
for _ in range(int(input())):
	(x, y, z) = map(int, input().split())
	x -= 1
	y -= 1
	if not x:
		a[0] += z
	if y != n - 1:
		if lst[y] < 0:
			su_neg += lst[y]
		else:
			su_pos -= lst[y]
		lst[y] -= z
		if lst[y] < 0:
			su_neg -= lst[y]
		else:
			su_pos += lst[y]
	if x:
		if lst[x - 1] < 0:
			su_neg += lst[x - 1]
		else:
			su_pos -= lst[x - 1]
		lst[x - 1] += z
		if lst[x - 1] < 0:
			su_neg -= lst[x - 1]
		else:
			su_pos += lst[x - 1]
	print((a[0] + su_pos + 1) // 2)


import atexit
import io
import sys
_INPUT_LINES = sys.stdin.read().splitlines()
input = iter(_INPUT_LINES).__next__
_OUTPUT_BUFFER = io.StringIO()
sys.stdout = _OUTPUT_BUFFER

@atexit.register
def write():
	sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
inar = lambda : list(map(int, input().split()))
inin = lambda : inar()[0]
inst = lambda : input().decode().rstrip('\n\r')
_T_ = 1
for _t_ in range(_T_):
	n = inin()
	a = inar()
	d = [0 for i in range(n - 1)]
	k = 0
	for i in range(1, n):
		d[i - 1] += a[i] - a[i - 1]
		k += max(0, a[i] - a[i - 1])
	x = (a[0] + k + 1) // 2
	print(x)
	q = inin()
	for _ in range(q):
		(l, r, c) = inar()
		l -= 1
		r -= 1
		if l == 0:
			a[0] += c
		else:
			if d[l - 1] >= 0:
				k -= d[l - 1]
			d[l - 1] += c
			if d[l - 1] >= 0:
				k += d[l - 1]
		if r == n - 1:
			pass
		else:
			if d[r] >= 0:
				k -= d[r]
			d[r] -= c
			if d[r] >= 0:
				k += d[r]
		x = (a[0] + k + 1) // 2
		print(x)


import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int, input().split()))
dif = [b - a for (a, b) in zip([0] + A, A)]
K = sum((d for (i, d) in enumerate(dif) if i == 0 or d > 0))
print((K + 1) // 2)

def add(x, v):
	global K
	if x == 0 or dif[x] > 0:
		K -= dif[x]
	dif[x] += v
	if x == 0 or dif[x] > 0:
		K += dif[x]
for _ in range(int(input())):
	(l, r, x) = map(int, input().split())
	l -= 1
	add(l, x)
	if r < n:
		add(r, -x)
	print((K + 1) // 2)


import sys
input = sys.stdin.buffer.readline
(n, ar) = (int(input()), list(map(int, input().split())))
sm = ar[0]
d = [0] * n
d[0] = ar[0]
for i in range(1, n):
	d[i] = ar[i] - ar[i - 1]
	sm += max(d[i], 0)
print((sm + 1) // 2)
q = int(input())
for _ in range(q):
	(l, r, x) = map(int, input().split())
	sm -= max(d[l - 1], d[l - 1] if l - 1 == 0 else 0)
	d[l - 1] += x
	sm += max(d[l - 1], d[l - 1] if l - 1 == 0 else 0)
	if r < n:
		sm -= max(d[r], 0)
		d[r] -= x
		sm += max(d[r], 0)
	print((sm + 1) // 2)


import math
import sys
input = sys.stdin.readline
n = int(input())
li = list(map(int, input().split()))
minuses = 0
diff = []
for i in range(1, len(li)):
	diff.append(li[i] - li[i - 1])
	if li[i] < li[i - 1]:
		minuses += li[i - 1] - li[i]
ll = li[-1]
print(math.ceil((minuses + ll) / 2))
for i in range(int(input())):
	(l, r, x) = list(map(int, input().split()))
	if l > 1:
		old = diff[l - 2]
		diff[l - 2] += x
		minuses += max(-(old + x), 0) - max(-old, 0)
	if r < n:
		old = diff[r - 1]
		diff[r - 1] -= x
		minuses += max(-(old - x), 0) - max(-old, 0)
	if r == n:
		ll += x
	print(math.ceil((minuses + ll) / 2))


from collections import Counter
from collections import deque
from sys import stdin
from bisect import *
from heapq import *
import math
g = lambda : stdin.readline().strip()
gl = lambda : g().split()
gil = lambda : [int(var) for var in gl()]
gfl = lambda : [float(var) for var in gl()]
gcl = lambda : list(g())
gbs = lambda : [int(var) for var in g()]
mod = int(1000000000.0) + 7
inf = float('inf')
(n,) = gil()
a = gil()
(q,) = gil()
sx = 0
d = [0]
for i in range(1, n):
	if a[i] > a[i - 1]:
		sx += a[i] - a[i - 1]
	d.append(a[i] - a[i - 1])

def cal():
	x = (a[0] - sx) // 2
	if a[0] - sx & 1:
		if max(a[0] - x, x + sx) > max(a[0] - x - 1, x + 1 + sx):
			x += 1
	return max(a[0] - x, x + sx)
print(cal())
for _ in range(q):
	(l, r, x) = gil()
	l -= 1
	r -= 1
	if l:
		sx -= max(d[l], 0)
		d[l] += x
		sx += max(d[l], 0)
	else:
		a[0] += x
	if r != n - 1:
		sx -= max(d[r + 1], 0)
		d[r + 1] -= x
		sx += max(d[r + 1], 0)
	print(cal())


import os, io
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
n = int(input())
a = list(map(int, input().split()))
diffList = []
firstElem = a[0]
diffPositiveSum = 0
for i in range(n - 1):
	diffList.append(a[i + 1] - a[i])
	if diffList[-1] >= 0:
		diffPositiveSum += diffList[-1]
print((firstElem + diffPositiveSum + 1) // 2)
for _ in range(int(input())):
	(l, r, x) = map(int, input().split())
	if l == 1:
		firstElem += x
	else:
		diffPositiveSum -= max(diffList[l - 2], 0)
		diffList[l - 2] += x
		diffPositiveSum += max(diffList[l - 2], 0)
	if r != n:
		diffPositiveSum -= max(diffList[r - 1], 0)
		diffList[r - 1] -= x
		diffPositiveSum += max(diffList[r - 1], 0)
	print((firstElem + diffPositiveSum + 1) // 2)


import sys
rd = sys.stdin.readline
n = int(rd())
a = list(map(int, rd().split()))
pos = 0
sa = [0] * (n - 1)
for i in range(n - 1):
	sa[i] = a[i + 1] - a[i]
	if sa[i] > 0:
		pos += sa[i]
print((a[0] + pos + 1) // 2)
q = int(rd())
for i in range(q):
	(l, r, x) = map(int, rd().split())
	if l == 1:
		a[0] += x
	if x > 0:
		if l >= 2:
			if sa[l - 2] >= 0:
				pos += x
			else:
				pos += max(0, x + sa[l - 2])
			sa[l - 2] += x
		if r <= n - 1:
			if sa[r - 1] >= x:
				pos -= x
			else:
				pos -= max(0, sa[r - 1])
			sa[r - 1] -= x
	elif x < 0:
		x = -x
		if l >= 2:
			if sa[l - 2] >= x:
				pos -= x
			else:
				pos -= max(0, sa[l - 2])
			sa[l - 2] -= x
		if r <= n - 1:
			if sa[r - 1] >= 0:
				pos += x
			else:
				pos += max(0, x + sa[r - 1])
			sa[r - 1] += x
	print((a[0] + pos + 1) // 2)


import sys
input = sys.stdin.buffer.readline
n = int(input())
a = list(map(int, input().split()))
start = a[0]
d = [0] * n
R = 0
for i in range(n - 1):
	d[i] = a[i + 1] - a[i]
	if d[i] > 0:
		R += d[i]
print((start + R + 1) // 2)
q = int(input())
for _ in range(q):
	(l, r, x) = map(int, input().split())
	(l, r) = (l - 1, r - 1)
	if l == 0:
		start += x
	else:
		if d[l - 1] > 0:
			R -= d[l - 1]
		d[l - 1] += x
		if d[l - 1] > 0:
			R += d[l - 1]
	if r < n - 1:
		if d[r] > 0:
			R -= d[r]
		d[r] -= x
		if d[r] > 0:
			R += d[r]
	print((start + R + 1) // 2)


import sys
rd = sys.stdin.readline
N = int(rd())
a = list(map(int, rd().split()))
for i in range(N - 1, 0, -1):
	a[i] -= a[i - 1]
p = 0
for i in range(1, N):
	p += max(0, a[i])
print((a[0] + p + 1) // 2)
Q = int(rd())
for _ in range(Q):
	(l, r, x) = map(int, rd().split())
	l -= 1
	if l != 0:
		p -= max(a[l], 0)
	a[l] += x
	if l != 0:
		p += max(a[l], 0)
	if r != N:
		p -= max(a[r], 0)
		a[r] -= x
		p += max(a[r], 0)
	print((a[0] + p + 1) // 2)


import sys
Case = 1

def main():
	n = inin()
	a = inar()
	d = [0 for i in range(n - 1)]
	k = 0
	for i in range(1, n):
		d[i - 1] += a[i] - a[i - 1]
		k += max(0, a[i] - a[i - 1])
	x = (a[0] + k + 1) // 2
	pr(x)
	q = inin()
	for _ in range(q):
		(l, r, c) = inar()
		l -= 1
		r -= 1
		if l == 0:
			a[0] += c
		else:
			if d[l - 1] >= 0:
				k -= d[l - 1]
			d[l - 1] += c
			if d[l - 1] >= 0:
				k += d[l - 1]
		if r == n - 1:
			pass
		else:
			if d[r] >= 0:
				k -= d[r]
			d[r] -= c
			if d[r] >= 0:
				k += d[r]
		x = (a[0] + k + 1) // 2
		pr(x)
import sys
inp = sys.stdin.buffer.readline
inar = lambda : list(map(int, inp().split()))
inin = lambda : int(inp())
inst = lambda : inp().decode().strip()
wrt = sys.stdout.write
pr = lambda *args, end='\n': wrt(' '.join([str(x) for x in args]) + end)
enum = enumerate
inf = float('inf')
for __Case__ in range(Case):
	main()


input = __import__('sys').stdin.readline

def query():
	return (ans + s[0] + 1) // 2
n = int(input())
s = list(map(int, input().split()))
ans = 0
diffs = [0] * (n - 1)
for i in range(n - 1):
	diffs[i] = s[i + 1] - s[i]
	if diffs[i] > 0:
		ans += diffs[i]
print(query())
for _ in range(int(input())):
	(l, r, x) = map(int, input().split())
	l -= 2
	r -= 1
	if l < 0:
		s[0] += x
	if l >= 0:
		if diffs[l] > 0:
			ans -= diffs[l]
		diffs[l] += x
		if diffs[l] > 0:
			ans += diffs[l]
	if r < n - 1:
		if diffs[r] > 0:
			ans -= diffs[r]
		diffs[r] -= x
		if diffs[r] > 0:
			ans += diffs[r]
	print(query())