You are given an array $d_1, d_2, \dots, d_n$ consisting of $n$ integer numbers.

Your task is to split this array into three parts (some of which may be empty) in such a way that each element of the array belongs to exactly one of the three parts, and each of the parts forms a consecutive contiguous subsegment (possibly, empty) of the original array. 

Let the sum of elements of the first part be $sum_1$, the sum of elements of the second part be $sum_2$ and the sum of elements of the third part be $sum_3$. Among all possible ways to split the array you have to choose a way such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.

More formally, if the first part of the array contains $a$ elements, the second part of the array contains $b$ elements and the third part contains $c$ elements, then:

$$sum_1 = \sum\limits_{1 \le i \le a}d_i,$$ $$sum_2 = \sum\limits_{a + 1 \le i \le a + b}d_i,$$ $$sum_3 = \sum\limits_{a + b + 1 \le i \le a + b + c}d_i.$$

The sum of an empty array is $0$.

Your task is to find a way to split the array such that $sum_1 = sum_3$ and $sum_1$ is maximum possible.


-----Input-----

The first line of the input contains one integer $n$ ($1 \le n \le 2 \cdot 10^5$) — the number of elements in the array $d$.

The second line of the input contains $n$ integers $d_1, d_2, \dots, d_n$ ($1 \le d_i \le 10^9$) — the elements of the array $d$.


-----Output-----

Print a single integer — the maximum possible value of $sum_1$, considering that the condition $sum_1 = sum_3$ must be met.

Obviously, at least one valid way to split the array exists (use $a=c=0$ and $b=n$).


-----Examples-----
Input
5
1 3 1 1 4

Output
5

Input
5
1 3 2 1 4

Output
4

Input
3
4 1 2

Output
0



-----Note-----

In the first example there is only one possible splitting which maximizes $sum_1$: $[1, 3, 1], [~], [1, 4]$.

In the second example the only way to have $sum_1=4$ is: $[1, 3], [2, 1], [4]$.

In the third example there is only one way to split the array: $[~], [4, 1, 2], [~]$.

Difficulty: EASY

Solutions:
n = int(input())
s = list(map(int, input().split()))
m1 = 0
m2 = 0
i = -1
j = n
ns = []
if n == 1:
	print('0')
else:
	while i < j:
		if m1 == m2:
			ns += [m1]
			i += 1
			j -= 1
			m1 += s[i]
			m2 += s[j]
		elif m1 > m2:
			j -= 1
			m2 += s[j]
		elif m2 > m1:
			i += 1
			m1 += s[i]
	print(max(ns))


a = int(input())
b = list(map(int, input().split()))
(m, i, j, k, k1) = (0, 0, a - 1, 0, 0)
while i <= j:
	if k <= k1:
		k += b[i]
		i += 1
	else:
		k1 += b[j]
		j -= 1
	if k == k1:
		m = k
print(m)


n = int(input())
a = [int(x) for x in input().split(' ')]
res = 0
l = [a[0], 0]
r = [a[-1], n - 1]
while l[1] < r[1]:
	if l[0] == r[0]:
		res = l[0]
	elif l[0] < r[0]:
		l[1] += 1
		l[0] += a[l[1]]
		continue
	r[1] -= 1
	r[0] += a[r[1]]
print(res)


n = int(input())
d = list(map(int, input().split()))
(lp, rp) = (-1, n)
(ls, rs) = (0, 0)
mr = 0
while lp < rp:
	if ls == rs:
		mr = max(mr, ls)
	if ls <= rs:
		lp += 1
		ls += d[lp]
	elif ls > rs:
		rp -= 1
		rs += d[rp]
print(mr)


n = int(input())
d = list(map(int, input().split()))
uk1 = -1
uk2 = n
ans = []
suma = 0
sumb = 0
while uk2 - uk1 > 1:
	if suma == sumb:
		ans.append(suma)
		uk1 += 1
		suma += d[uk1]
	elif suma < sumb:
		uk1 += 1
		suma += d[uk1]
	else:
		uk2 -= 1
		sumb += d[uk2]
if suma == sumb:
	ans.append(suma)
print(ans[-1])


(z, zz) = (input, lambda : list(map(int, z().split())))
mod = 10 ** 9 + 7
from string import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0:
			return 0
	return 1
n = int(z())
arr = zz()
(l, r) = (0, n - 1)
(s1, s2) = (arr[l], arr[r])
m = 0
while l < r:
	if s1 == s2:
		m = max(0, s1)
	if s1 <= s2:
		l += 1
		s1 += arr[l]
	else:
		r -= 1
		s2 += arr[r]
print(m)


n = int(input())
a = list(map(int, input().split()))
pref = n * [a[0]]
suf = n * [a[n - 1]]
for i in range(1, n):
	pref[i] = a[i] + pref[i - 1]
for i in range(n - 2, -1, -1):
	suf[i] = a[i] + suf[i + 1]
l = 0
r = n - 1
ans = 0
while l < r:
	if pref[l] == suf[r]:
		ans = max(ans, pref[l])
		l += 1
	elif pref[l] > suf[r]:
		r -= 1
	else:
		l += 1
print(ans)


n = int(input())
b = []
a = list(map(int, input().split()))
i = 0
j = n - 1
p = 0
q = 0
s = 0
while i <= j:
	if p <= q:
		p += a[i]
		i += 1
		b.append(p)
	else:
		q += a[j]
		j -= 1
	if p == q:
		s = max(s, p)
print(s)


__author__ = 'liuzixiang'

def main():
	n = int(input())
	v = list(map(int, input().split()))
	(l, r) = (0, len(v) - 1)
	lans = rans = 0
	result = 0
	while l <= r:
		if lans < rans:
			lans += v[l]
			l += 1
		elif lans > rans:
			rans += v[r]
			r -= 1
		elif v[l] <= v[r]:
			lans += v[l]
			l += 1
		else:
			rans += v[r]
			r -= 1
		if lans == rans:
			result = lans
	print(result)
main()


n = int(input())
l = [int(x) for x in input().split()]
left = 0
right = 0
i = 0
j = n - 1
max_sum = 0
while i <= j:
	if left > right:
		right += l[j]
		j -= 1
	elif left < right:
		left += l[i]
		i += 1
	else:
		max_sum = left
		if i < j:
			left += l[i]
			i += 1
			right += l[j]
			j -= 1
		else:
			break
if left == right:
	max_sum = left
print(max_sum)


n = int(input())
arr = list(map(int, input().split()))
pref = [0] * n
suff = [0] * n
pref[0] = arr[0]
for i in range(1, n):
	pref[i] = arr[i] + pref[i - 1]
suff[n - 1] = arr[n - 1]
for i in range(n - 2, -1, -1):
	suff[i] = suff[i + 1] + arr[i]
mp = {}
for i in range(n):
	mp[suff[i]] = i
ans = 0
for i in range(n):
	if pref[i] in mp:
		if i < mp[pref[i]]:
			ans = max(ans, pref[i])
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
sum1 = [0]
for i in reversed(range(n)):
	sum1.append(sum1[-1] + a[i])
sum1.pop()
sum2 = set(sum1)
ans = 0
cur_sum = 0
for i in range(n):
	sum2.remove(sum1[-i])
	cur_sum += a[i]
	if cur_sum in sum2:
		ans = cur_sum
print(ans)


n = int(input())
d = list(map(int, input().split()))
x = 0
y = n
sum1 = sum2 = 0
m = 0
while x != y:
	if sum1 > sum2:
		y -= 1
		sum2 += d[y]
	else:
		sum1 += d[x]
		x += 1
	if sum1 == sum2:
		m = sum1
print(m)


n = int(input())
a = [int(i) for i in input().split()]
predleft = [0]
for i in range(n):
	predleft.append(predleft[-1] + a[i])
predright = [0]
for i in range(n - 1, -1, -1):
	predright.append(predright[-1] + a[i])
i = 0
j = 0
ans = 0
while i + j <= n:
	if predleft[i] == predright[j]:
		ans = predleft[i]
		i += 1
	elif predleft[i] > predright[j]:
		j += 1
	else:
		i += 1
print(ans)


from itertools import *
input()
a = [*accumulate(map(int, input().split()))]
s = set((a[-1] - y for y in a if y >= a[-1] / 2))
print(max((x for x in a if x in s), default=0))


n = int(input())
D = [int(x) for x in input().split()]
front = -1
back = n
sumFront = 0
sumBack = 0
checkPoint = []
while front < back:
	if sumFront == sumBack:
		checkPoint.append(sumFront)
		front += 1
		back -= 1
		if front < back:
			sumFront += D[front]
			sumBack += D[back]
		else:
			break
	elif sumFront < sumBack:
		front += 1
		if front < back:
			sumFront += D[front]
		else:
			break
	else:
		back -= 1
		if front < back:
			sumBack += D[back]
		else:
			break
print(checkPoint[-1])


n = input()
n = int(n)
l2 = input()
nums = [int(x) for x in l2.split()]
sum1 = 0
sum3 = 0
max = 0
con2 = 0
con1 = 0
for i in range(0, n):
	if sum1 <= sum3:
		sum1 = sum1 + nums[con1]
		con1 = con1 + 1
	else:
		sum3 = sum3 + nums[n - 1 - con2]
		con2 = con2 + 1
	if sum1 == sum3:
		max = sum1
print(max)


n = int(input())
arr = list(map(int, input().split()))
i = 0
j = n - 1
sum1 = 0
sum3 = 0
sum1 += arr[i]
sum3 += arr[j]
final = 0
while i < j:
	if sum1 < sum3:
		i = 1 + i
		sum1 += arr[i]
	elif sum1 > sum3:
		j -= 1
		sum3 += arr[j]
	elif sum1 == sum3:
		if sum1 > final:
			final = sum1
		i += 1
		j -= 1
		if i < j:
			sum1 += arr[i]
			sum3 += arr[j]
print(final)


m = int(input())
a = list(map(int, input().split()))
suml = sumr = summax = 0
(l, r) = (-1, m)
while l < r:
	if suml == sumr:
		if suml > summax:
			summax = suml
		l += 1
		suml += a[l]
	elif suml < sumr:
		l += 1
		suml += a[l]
	else:
		r -= 1
		sumr += a[r]
print(summax)


siz = int(input())
(h, t, ans) = (0, siz - 1, 0)
s = list(map(int, input().split()))
(l, r) = (s[h], s[t])
while h < t:
	if l == r:
		ans = r
		h += 1
		t -= 1
		l += s[h]
		r += s[t]
	elif l < r:
		h += 1
		l += s[h]
	else:
		t -= 1
		r += s[t]
print(ans)


n = int(input())
l = list(map(int, input().split()))
i = 0
j = n - 1
s1 = l[0]
s2 = l[n - 1]
equal = 0
while i < j:
	if s1 == s2:
		if s1 > equal:
			equal = s1
		i = i + 1
		j = j - 1
		s1 = s1 + l[i]
		s2 = s2 + l[j]
	elif s1 < s2:
		i = i + 1
		s1 = s1 + l[i]
	else:
		j = j - 1
		s2 = s2 + l[j]
print(equal)


import os
import sys
from io import BytesIO, IOBase
import math
from decimal import *
getcontext().prec = 25
MOD = pow(10, 9) + 7
BUFSIZE = 8192
from collections import defaultdict

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')
n = int(input())
l = list(map(int, input().split(' ')))
i = 0
j = n - 1
s1 = 0
s2 = 0
m = 0
while i <= j:
	if s1 <= s2:
		s1 += l[i]
		i += 1
	else:
		s2 += l[j]
		j -= 1
	if s1 == s2:
		m = max(s1, m)
print(m)


n = int(input())
array = list(map(int, input().split()))
soma1 = array.copy()
soma2 = 0
for i in range(n):
	soma2 += soma1[i]
	soma1[i] = soma2
soma3 = array.copy()
soma2 = 0
for i in range(n - 1, -1, -1):
	soma2 += soma3[i]
	soma3[i] = soma2
L = n - 2
R = n - 1
veri = 0
while L >= 0 and L < R and (R < n):
	if soma1[L] > soma3[R]:
		L -= 1
		R -= 1
	elif soma1[L] < soma3[R]:
		R += 1
	elif soma1[L] == soma3[R]:
		print(soma1[L])
		veri = 1
		break
if not veri:
	print(0)


import sys
readline = sys.stdin.readline
from collections import Counter
N = int(readline())
A = list(map(int, readline().split()))
Af = A[:]
Ab = A[:]
for i in range(1, N):
	Af[i] += Af[i - 1]
for i in range(N - 2, -1, -1):
	Ab[i] += Ab[i + 1]
table = Counter(Ab)
ans = 0
for i in range(N):
	table[Ab[i]] -= 1
	if table[Af[i]]:
		ans = Af[i]
print(ans)


n = int(input())
d = list(map(int, input().split()))
d = [0] + d
dict = {0: 0}
answer = 0
sum = 0
for i in range(1, n + 1):
	sum = sum + d[i]
	dict[sum] = i
sum = 0
for i in reversed(range(1, n + 1)):
	sum = sum + d[i]
	if sum in dict:
		if dict[sum] < i:
			answer = sum
print(answer)


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print(0)
else:
	c = a[0]
	d = a[n - 1]
	x = 1
	y = 1
	u = True
	ma = 0
	while x + y < n + 1:
		if c > d:
			d += a[n - y - 1]
			y += 1
		elif c < d:
			c += a[x]
			x += 1
		else:
			if c > ma:
				ma = c
			c += a[x]
			d += a[n - y - 1]
			x += 1
			y += 1
	if u:
		print(ma)


n = int(input())
arr = list(map(int, input().split()))
maxi = 0
i = 0
j = len(arr) - 1
sum1 = 0
sum3 = 0
while i <= j:
	if sum1 > sum3:
		sum3 += arr[j]
		j -= 1
	if sum1 < sum3:
		sum1 += arr[i]
		i += 1
	if sum1 == sum3:
		maxi = max(maxi, sum1)
		sum1 += arr[i]
		i += 1
print(maxi)


from itertools import accumulate
n = int(input())
seq = list(map(int, input().split()))
dir_order = []
rev_order = []
right = 0
left = 0
seq_dict = {}
for i in range(n - 1):
	right += seq[i]
	seq_dict[right] = i
	left += seq[n - i - 1]
	dir_order.append(right)
	rev_order.append(left)
i = n - 2
while i >= 0 and (rev_order[i] not in seq_dict or seq_dict[rev_order[i]] + i >= n - 1):
	i -= 1
if i == -1:
	print(0)
else:
	print(rev_order[i])


N = int(input())
D = [int(x) for x in input().split()]
ans = 0
i = 0
j = N - 1
a = 0
c = 0
while i - 1 <= j:
	if a == c:
		ans = max(ans, a)
	if a >= c:
		c += D[j]
		j -= 1
	else:
		a += D[i]
		i += 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
mx = 0
left = 0
right = n - 1
sl = 0
sr = 0
while left <= right:
	if sl == sr:
		mx = sl
		sl += l[left]
		left += 1
	elif sl > sr:
		sr += l[right]
		right -= 1
	elif sl < sr:
		sl += l[left]
		left += 1
if sl == sr:
	mx = sl
print(mx)


n = int(input())
List = [int(x) for x in input().split()]
left = 0
right = n - 1
Max = 0
SumLeft = List[0]
SumRight = List[n - 1]
while left < right:
	if SumLeft < SumRight:
		left += 1
		SumLeft += List[left]
	elif SumLeft == SumRight:
		Max = SumLeft
		left += 1
		right -= 1
		SumLeft += List[left]
		SumRight += List[right]
	else:
		right -= 1
		SumRight += List[right]
print(Max)


n = int(input())
a = list(map(int, input().split()))
i = 0
j = n - 1
maa = 0
p = a[0]
q = a[n - 1]
while i < j:
	if p == q:
		maa = p
		i += 1
		j -= 1
		p += a[i]
		q += a[j]
	elif q > p:
		i += 1
		p += a[i]
	else:
		j -= 1
		q += a[j]
print(maa)


def main():
	n = int(input())
	a = list(map(int, input().strip().split()))
	bestSoFar = 0
	(leftIdx, rightIdx) = (-1, n)
	leftSum = rightSum = 0
	while leftIdx < rightIdx:
		if leftSum == rightSum:
			bestSoFar += leftSum
			leftIdx += 1
			rightIdx -= 1
			leftSum = a[leftIdx]
			rightSum = a[rightIdx]
		elif leftSum < rightSum:
			leftIdx += 1
			leftSum += a[leftIdx]
		else:
			rightIdx -= 1
			rightSum += a[rightIdx]
	print(bestSoFar)
main()


n = int(input())
arr = [int(x) for x in input().split(' ')]

def solve(n, arr):
	leftSum = arr[0]
	rightSum = arr[n - 1]
	i = 0
	j = n - 1
	matches = list([0])
	while i < j:
		if leftSum < rightSum:
			i = i + 1
			leftSum = leftSum + arr[i]
		elif rightSum < leftSum:
			j = j - 1
			rightSum = rightSum + arr[j]
		elif leftSum == rightSum:
			matches.append(leftSum)
			i = i + 1
			leftSum = leftSum + arr[i]
	return matches.pop()
print(solve(n, arr))


n = int(input())
a = [int(x) for x in input().split()]
sum1 = 0
sum3 = 0
max_sum = 0
i = 0
j = len(a) - 1
while i <= j:
	if sum1 > sum3:
		sum3 += a[j]
		j -= 1
	else:
		sum1 += a[i]
		i += 1
	if sum1 == sum3:
		max_sum = sum1
print(max_sum)


n = int(input())
T = input().split(' ')
for i in range(n):
	T[i] = int(T[i])
a = 0
b = n - 1
m = 0
x = 0
y = 0
while a <= b and x != y or a < b:
	if x < y:
		x += T[a]
		a += 1
	elif x > y:
		y += T[b]
		b -= 1
	else:
		x += T[a]
		a += 1
		y += T[b]
		b -= 1
	if x == y:
		m = max(m, x)
print(m)


n = int(input())
a = list(map(int, input().split()))
(s, d) = (0, {})
for i in range(n - 1, -1, -1):
	s += a[i]
	d[s] = i
(s, m) = (0, 0)
for i in range(n):
	s += a[i]
	if s in d:
		if d[s] > i:
			m = max(s, m)
print(m)


n = int(input())
a = list(map(int, input().strip().split(' ')))
s1 = [0] * n
s2 = [0] * (n + 1)
s1[0] = a[0]
s2[n - 1] = a[n - 1]
for i in range(1, n):
	s1[i] = s1[i - 1] + a[i]
for i in range(n - 2, -1, -1):
	s2[i] = s2[i + 1] + a[i]
ans = 0
for i in range(n):
	tm = s1[i]
	l = i + 1
	r = n - 1
	while r - l > 1:
		mid = int((l + r) / 2)
		if s2[mid] > tm:
			l = mid + 1
		else:
			r = mid
	if r - l >= 0:
		if s2[l] == tm:
			ans = tm
		elif s2[r] == tm:
			ans = tm
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
(res, ls, rs, r) = (0, 0, 0, n)
for l in range(0, n):
	ls += a[l]
	while rs < ls:
		r -= 1
		rs += a[r]
	if rs == ls and l < r:
		res = rs
print(res)


import sys
n = int(input())
l = list(map(int, input().split()))
p = [0] * n
(si, sj) = (l[0], l[n - 1])
(i, j) = (0, n - 1)
(p[0], p[n - 1]) = (1, 1)
ans = [0]
if n == 1:
	print(0)
	sys.exit()
if n == 2:
	if l[0] == l[1]:
		print(l[0])
	else:
		print(0)
	sys.exit()
while abs(i - j) != 1 or i - j == 0:
	if si < sj:
		i = i + 1
		if p[i] == 0:
			si = si + l[i]
			p[i] = 1
			if si == sj:
				ans.append(si)
		else:
			break
	elif sj < si:
		j = j - 1
		if p[j] == 0:
			sj = sj + l[j]
			p[j] = 1
			if si == sj:
				ans.append(si)
		else:
			break
	else:
		ans.append(si)
		if j - i == 2:
			break
		else:
			i = i + 1
			j = j - 1
			if p[i] == 0 and p[j] == 0:
				si = si + l[i]
				sj = sj + l[j]
				if si == sj:
					if j - i == 1:
						ans.append(si)
			else:
				break
print(max(ans))


n = int(input())
arr = list(map(int, input().split()))
sum1 = arr[0]
sum2 = 0
num1 = 1
num2 = 0
max = 0
while True:
	if num1 >= n - num2:
		break
	if sum1 < sum2:
		sum1 += arr[num1]
		num1 += 1
		continue
	if sum2 < sum1:
		sum2 += arr[n - num2 - 1]
		num2 += 1
		continue
	if sum2 == sum1:
		max = sum1
		sum1 += arr[num1]
		num1 += 1
if sum2 == sum1:
	max = sum1
print(max)


for t in range(1):
	n = int(input())
	arr = list(map(int, input().split()))
	starting = 0
	end = n - 1
	start_sum = arr[starting]
	ending_sum = arr[end]
	ans = 0
	while starting < end:
		if start_sum < ending_sum:
			starting += 1
			start_sum += arr[starting]
		elif start_sum > ending_sum:
			end -= 1
			ending_sum += arr[end]
		else:
			ans = max(start_sum, ans)
			starting += 1
			end -= 1
			start_sum += arr[starting]
			ending_sum += arr[end]
	print(ans)


n = int(input())
arr = list(map(int, input().split()))
i = 0
j = n - 1
sum_l = arr[0]
val = 0
sum_r = arr[n - 1]
while i < j:
	if sum_l < sum_r:
		i += 1
		sum_l += arr[i]
	elif sum_l > sum_r:
		j -= 1
		sum_r += arr[j]
	else:
		val = sum_l
		i += 1
		sum_l += arr[i]
		j -= 1
		sum_r += arr[j]
print(val)


def maxssumarray(List):
	n = len(List)
	if n == 1:
		return 0
	else:
		i = 0
		j = n - 1
		leftsum = List[0]
		rightsum = List[-1]
		maxsum = 0
		if leftsum == rightsum:
			maxsum = leftsum
		while i + 1 < j:
			if leftsum < rightsum:
				leftsum += List[i + 1]
				i += 1
				if leftsum == rightsum:
					maxsum = leftsum
			else:
				rightsum += List[j - 1]
				j -= 1
				if leftsum == rightsum:
					maxsum = leftsum
		else:
			if leftsum == rightsum:
				maxsum = leftsum
			return maxsum
n = int(input())
array = list(map(int, input().rstrip().split()))
print(maxssumarray(array))


n = int(input())
arr = [*map(int, input().split())]
ans = 0
(i, j) = (0, n - 1)
left = right = 0
while i <= j:
	if left < right:
		left += arr[i]
		i += 1
	else:
		right += arr[j]
		j -= 1
	if left == right:
		ans = max(ans, left)
print(ans)


n = int(input())
A = list(map(int, input().split()))
L = A[0]
R = A[n - 1]
i = 0
j = n - 1
X = 0
while i < j:
	if L == R:
		X = max(X, L)
		i += 1
		L += A[i]
	elif L < R:
		i += 1
		L += A[i]
	else:
		j -= 1
		R += A[j]
print(X)


def check(s1, s2):
	print('sum right: ' + str(s1))
	print('sum left: ' + str(s2))
	print()

def check_winner(input):
	data = list(map(int, input.split(' ')))
	output = 0
	r_sum = 0
	l_sum = 0
	start = 0
	end = len(data) - 1
	while start <= end:
		if r_sum > l_sum:
			l_sum += data[end]
			end -= 1
		else:
			r_sum += data[start]
			start += 1
		if r_sum == l_sum:
			output = r_sum
	return output
header = input()
data = input()
print(check_winner(data))


n = int(input())
a = list(map(int, input().split()))
i = 0
s1 = a[i]
j = n - 1
s2 = a[j]
ans = 0
while i < j:
	if s1 == s2:
		ans = s1
		i += 1
		s1 += a[i]
		j -= 1
		s2 += a[j]
	elif s1 < s2:
		i += 1
		s1 += a[i]
	else:
		j -= 1
		s2 += a[j]
print(ans)


n = int(input())
arr = list(map(int, input().split()))
(low, high) = (0, n - 1)
(currSum, maxSum, endSum) = (0, 0, 0)
while low < high:
	currSum += arr[low]
	endSum += arr[high]
	if currSum < endSum:
		low += 1
		endSum -= arr[high]
	elif currSum > endSum:
		high -= 1
		currSum -= arr[low]
	else:
		maxSum = currSum
		low += 1
		high -= 1
print(maxSum)


n = int(input())
arr = list(map(int, input().split()))
(sum1, sum2, sum3) = (0, 0, 0)
toPrint = 0
Rindex = 0
Lindex = n - 1
while Rindex <= Lindex + 1:
	if sum1 == sum3:
		toPrint = sum1
		sum1 += arr[Rindex]
		sum3 += arr[Lindex]
		Rindex += 1
		Lindex -= 1
	elif sum1 > sum3:
		sum3 += arr[Lindex]
		Lindex -= 1
	else:
		sum1 += arr[Rindex]
		Rindex += 1
print(toPrint)


n = int(input())
a = list(map(int, input().strip().split()))
i = 0
j = n - 1
l = 0
r = 0
q = []
while i <= j:
	if l >= r:
		r += a[j]
		j -= 1
	else:
		l += a[i]
		i += 1
	if l == r:
		q.append(l)
if l == r:
	q.append(l)
if q == []:
	print(0)
else:
	print(max(q))


n = int(input())
a = list(map(int, input().split()))
r = n - 1
cntr = cntl = ans = l = 0
while l <= r + 1:
	if cntl == cntr:
		ans = max(ans, cntl)
	if cntl < cntr:
		cntl += a[l]
		l += 1
	else:
		cntr += a[r]
		r -= 1
print(ans)


n = int(input())
d = list(map(int, input().split()))
m1 = []
m2 = []
x = 0
for i in range(0, len(d)):
	x += d[i]
	m1.append(x)
x = 0
for i in range(len(d) - 1, -1, -1):
	x += d[i]
	m2.append(x)
m2.reverse()
i = 0
j = len(d) - 1
result = 0
while i < j:
	if m1[i] == m2[j]:
		if m1[i] > result:
			result = m1[i]
		i += 1
		j -= 1
	elif m1[i] > m2[j]:
		j -= 1
	elif m1[i] < m2[j]:
		i += 1
print(result)


n = int(input())
l = list(map(int, input().split()))
a = 0
c = 0
sum = 0
i = 0
j = n - 1
a += l[i]
c += l[j]
while i < j:
	if a > c:
		j -= 1
		c += l[j]
	elif a < c:
		i += 1
		a += l[i]
	else:
		sum = a
		i += 1
		a += l[i]
print(sum)


from bisect import bisect_right as br
n = int(input())
s = list(map(int, input().split()))
sm = []
x = 0
for i in range(n - 1):
	x += s[i]
	sm.append(x)
s = s[::-1]
sm1 = []
x = 0
ans = 0
for i in range(n - 1):
	x += s[i]
	sm1.append(x)
ans = 0
for i in range(n - 1):
	ind = br(sm1, sm[i])
	if ind != 0 and sm[i] == sm1[ind - 1] and (ind - 1 <= len(sm1) - 1 - i):
		ans = max(ans, sm[i])
print(ans)


try:
	while True:
		n = int(input())
		arr = list(map(int, input().split()))
		(ans, l_sum, r_sum) = (0, 0, 0)
		(l, r) = (-1, n)
		while l < r:
			if l_sum == r_sum:
				ans = l_sum
				l = l + 1
				l_sum += arr[l]
			elif l_sum > r_sum:
				r = r - 1
				r_sum += arr[r]
			else:
				l = l + 1
				l_sum += arr[l]
		print(ans)
except Exception as e:
	pass


n = int(input())
L = list(map(int, input().split()))
smax = 0
i = 0
j = n - 1
t1 = 0
t3 = 0
t1 += L[i]
t3 += L[j]
while i < j:
	if t1 == t3:
		smax = max(smax, t1)
		i += 1
		t1 += L[i]
	elif t1 > t3:
		j -= 1
		t3 += L[j]
	else:
		i += 1
		t1 += L[i]
print(smax)


tam = int(input())
inteiros = [*map(int, input().split())]
p1 = 0
p2 = tam - 1
maximoAcumulado = 0
acc1 = inteiros[p1]
acc3 = inteiros[p2]
while p1 < p2:
	if acc1 < acc3:
		p1 += 1
		acc1 += inteiros[p1]
	elif acc1 > acc3:
		p2 -= 1
		acc3 += inteiros[p2]
	else:
		if acc1 > maximoAcumulado:
			maximoAcumulado = acc1
		p1 += 1
		p2 -= 1
		acc1 += inteiros[p1]
		acc3 += inteiros[p2]
print(maximoAcumulado)


import sys
n = int(input())
arr = list(map(int, input().split()))
if n == 1:
	print(0)
	sys.exit(0)
upper = len(arr) - 1
lower = 0
upsum = arr[-1]
lowsum = arr[0]
best = 0
while 1:
	if upsum == lowsum:
		best = upsum
	if abs(upper - lower) == 1:
		break
	if upsum < lowsum:
		upper -= 1
		upsum += arr[upper]
	elif upsum >= lowsum:
		lower += 1
		lowsum += arr[lower]
print(best)


n = int(input())
d = list(map(int, input().rstrip().split()))
sum1 = 0
sum2 = 0
ans = 0
i = -1
j = n
while i < j:
	if sum1 > sum2:
		j -= 1
		sum2 += d[j]
	elif sum1 < sum2:
		i += 1
		sum1 += d[i]
	else:
		ans = max(ans, sum1)
		i += 1
		sum1 += d[i]
print(ans)


n = int(input())
a = list(map(int, input().split()))
msum = 0
i = 0
j = n - 1
s1 = a[i]
s2 = a[j]
while j > i:
	if s1 == s2:
		msum = max(msum, s1)
	if s1 <= s2:
		i += 1
		s1 += a[i]
	else:
		j -= 1
		s2 += a[j]
print(msum)


n = int(input())
arr = [int(i) for i in input().split(' ')]
p1 = 0
p2 = len(arr) - 1
sum1 = arr[p1]
sum2 = arr[p2]
final_sum = 0
for _ in arr:
	if p1 >= p2:
		break
	if sum1 > sum2:
		p2 -= 1
		sum2 += arr[p2]
	elif sum1 < sum2:
		p1 += 1
		sum1 += arr[p1]
	else:
		final_sum = sum1
		p2 -= 1
		sum2 += arr[p2]
print(final_sum)


for i in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	j = n - 1
	s = l[0]
	k = l[n - 1]
	z = 0
	while j > i:
		if s == k:
			z = s
			i += 1
			s += l[i]
			j -= 1
			k += l[j]
		elif s < k:
			i += 1
			s += l[i]
		elif k < s:
			j -= 1
			k += l[j]
	print(z)


import os
import sys
from io import BytesIO, IOBase

def main():
	n = int(input())
	a = list(map(int, input().split(' ')))
	pre = [0 for x in range(n + 1)]
	for x in range(n):
		pre[x + 1] = pre[x] + a[x]
	low = 1
	high = n - 1
	ans = 0
	while low <= high:
		if pre[low] - pre[0] == pre[n] - pre[high]:
			ans = max(ans, pre[low] - pre[0])
			low += 1
			high -= 1
		elif pre[low] - pre[0] < pre[n] - pre[high]:
			low += 1
		else:
			high -= 1
	print(ans)
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()


n = int(input())
arr = list((int(x) for x in input().split()))
s = set()
total = 0
for x in arr[::-1]:
	total += x
	s.add(total)
s.remove(total)
l = r = ans = 0
for x in arr:
	l += x
	total -= x
	if l in s:
		ans = l
	if total in s:
		s.remove(total)
print(ans)


n = int(input())
a = [int(x) for x in input().split()]
i = 0
j = n - 1
p = 0
q = 0
s = 0
while i <= j:
	if p <= q:
		p = p + a[i]
		i += 1
	else:
		q = q + a[j]
		j -= 1
	if p == q:
		s = max(s, p)
print(s)


n = int(input())
a = list(map(int, input().split()))
s = sum(a) // 2
j = 0
l = n - 1
s1 = a[0]
s2 = a[n - 1]
m = 0
if a[0] == a[n - 1] and n > 1:
	m = s1
while j < n and l >= 0 and (j < l):
	if s1 < s2:
		j = j + 1
		if j != l:
			s1 = s1 + a[j]
	elif s1 > s2:
		l = l - 1
		if l != j:
			s2 = s2 + a[l]
	elif a[j] < a[l]:
		j += 1
		if j != l:
			s1 += a[j]
	else:
		l -= 1
		if j != l:
			s2 += a[l]
	if s1 == s2 and m < s1:
		m = s1
print(m)


inInt = lambda : list(map(int, input().strip().split()))
inStr = lambda : list(map(int, input().strip().split()))
n = int(input())
arr = inInt()
left = []
right = []
bp = sum(arr) // 2
sl = 0
sr = 0
for i in range(n):
	if sl >= bp:
		sr += arr[i]
		right.append(arr[i])
	else:
		sl += arr[i]
		left.append(arr[i])
right = list(reversed(right))
for i in range(n):
	if sl > 0 and sr > 0 and (sl != sr):
		if sl > sr:
			sl -= left.pop()
		else:
			sr -= right.pop()
print(min(sl, sr))


n = int(input())
seq = list(map(int, input().split()))
if n == 1:
	print(0)
else:
	i = 0
	j = n - 1
	m = 0
	s_right = seq[0]
	s_left = seq[-1]
	while j > i:
		if s_right == s_left:
			m = max(s_right, m)
			i += 1
			s_right += seq[i]
		elif s_right > s_left:
			j -= 1
			if j > i:
				s_left += seq[j]
		else:
			i += 1
			if j > i:
				s_right += seq[i]
	print(m)


n = int(input())
a = list(map(int, input().split()))
p1 = 0
p2 = n - 1
ans = cnt2 = 0
cnt1 = a[0]
while p1 < p2:
	while p1 < p2 and cnt1 > cnt2:
		cnt2 += a[p2]
		p2 -= 1
	if cnt1 == cnt2:
		ans = cnt1
	p1 += 1
	cnt1 += a[p1]
if p1 == p2 and cnt1 == cnt2:
	ans = cnt1
print(ans)


from itertools import accumulate
n = int(input())
arr = list(map(int, input().split(' ')))[:n]
arr = list(accumulate(arr))
r = n - 2
l = 0
sum = arr[n - 1] - arr[r]
max = 0
while l <= r:
	if sum > arr[l]:
		l += 1
	elif sum < arr[l]:
		r -= 1
		sum = arr[n - 1] - arr[r]
	else:
		if sum > max:
			max = sum
			l += 1
			r -= 1
		sum = arr[n - 1] - arr[r]
print(max)


import sys

def Divide(a):
	if len(a) <= 1:
		return 0
	rm_sum = 0
	i = 0
	j = len(a) - 1
	sum1 = a[0]
	sum3 = a[len(a) - 1]
	while i < j:
		if sum1 < sum3:
			i += 1
			sum1 += a[i]
		elif sum1 > sum3:
			j -= 1
			sum3 += a[j]
		else:
			rm_sum += sum1
			i += 1
			j -= 1
			sum1 = a[i]
			sum3 = a[j]
	return rm_sum
n = int(input())
a = input().split()
for i in range(len(a)):
	a[i] = int(a[i])
print(Divide(a))


n = int(input())
a = [int(x) for x in input().split()]
answer = 0
leftptr = 0
rightptr = len(a) - 1
leftsum = a[0]
rightsum = a[-1]
while leftptr < rightptr:
	if leftsum == rightsum:
		answer = leftsum
		leftptr += 1
		rightptr -= 1
		leftsum += a[leftptr]
		rightsum += a[rightptr]
	elif leftsum < rightsum:
		leftptr += 1
		leftsum += a[leftptr]
	else:
		rightptr -= 1
		rightsum += a[rightptr]
print(answer)


R = lambda : map(int, input().split())
n = int(input())
arr = list(R())
(l, r) = (-1, n)
(sl, sr) = (0, 0)
res = 0
while l < r and l < n - 1:
	l += 1
	sl += arr[l]
	while r - 1 > l and sr + arr[r - 1] <= sl:
		sr += arr[r - 1]
		r -= 1
	if l < r and sl == sr:
		res = max(res, sl)
print(res)


import sys
import os
import collections
import math
n = int(input())
s = input()
s = list(map(int, s.split()))
max_ = -11
i = 0
j = n - 1
sum1 = 0
sum3 = 0
while i < j:
	if sum1 == sum3:
		max_ = sum1
		sum1 += s[i]
		sum3 += s[j]
		i += 1
		j -= 1
	elif sum1 < sum3:
		sum1 += s[i]
		i += 1
	elif sum1 > sum3:
		sum3 += s[j]
		j -= 1
if sum1 == sum3:
	max_ = sum1
elif i == j:
	if sum1 < sum3:
		sum1 += s[i]
		i += 1
	elif sum1 > sum3:
		sum3 += s[j]
		j -= 1
if sum1 == sum3:
	max_ = sum1
print(max_)


n = int(input())
d = list(map(int, input().split()))
i = 0
j = n - 1
sum1 = d[0]
sum3 = d[-1]
ans = []
while i < j:
	if sum1 > sum3:
		j -= 1
		sum3 += d[j]
	elif sum1 < sum3:
		i += 1
		sum1 += d[i]
	else:
		ans.append([i, j])
		i += 1
		j -= 1
		sum3 += d[j]
		sum1 += d[i]
if len(ans) == 0:
	print(0)
else:
	print(sum(d[0:ans[-1][0] + 1]))


n = int(input())
list = [int(i) for i in input().split()]
(i, j) = (0, n - 1)
(sum1, sum3) = (0, 0)
temp = []
while i <= j:
	if sum1 == sum3:
		temp.append(sum1)
		if i <= j:
			sum1 += list[i]
			i += 1
	elif sum1 > sum3:
		if i > j:
			break
		while i <= j and sum1 > sum3:
			sum3 += list[j]
			j -= 1
	else:
		if i > j:
			break
		while i <= j and sum1 < sum3:
			sum1 += list[i]
			i += 1
if sum1 == sum3:
	temp.append(sum1)
print(max(temp))


n = int(input())
D = list(map(int, input().split()))
(sums1, sums2) = ({}, {})
s = 0
for (i, d) in enumerate(D):
	s += d
	if s not in sums1:
		sums1[s] = i
s = 0
for (i, d) in enumerate(D[::-1]):
	s += d
	if s not in sums2:
		sums2[s] = i
sums1 = sorted(list(sums1.items()), reverse=True)
answer = 0
for (s, i) in sums1:
	if s in sums2 and sums2[s] + i + 2 <= n:
		answer = s
		break
print(answer)


inInt = lambda : list(map(int, input().strip().split()))
inStr = lambda : list(map(int, input().strip().split()))
n = int(input())
arr = inInt()
ans = 0
sl = 0
sr = 0
(l, r) = (0, n - 1)
while l <= r:
	if sl > sr:
		sr += arr[r]
		r -= 1
	else:
		sl += arr[l]
		l += 1
	if sl == sr:
		ans = sl
print(ans)


n = int(input())
a = list(map(int, input().split()))
l = 0
s1 = 0
s2 = 0
r = n
res = 0
for l in range(n):
	s1 += a[l]
	while s2 < s1:
		r -= 1
		s2 += a[r]
	if s1 == s2 and r > l:
		res = max(res, s1)
print(res)


import math, string, itertools, fractions, heapq, collections, re, array, bisect, sys, copy, functools
import random
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
eps = 1.0 / 10 ** 10
mod = 10 ** 9 + 7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]

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

def LLI():
	return [list(map(int, l.split())) for l in sys.stdin.readlines()]

def LI_():
	return [int(x) - 1 for x in sys.stdin.readline().split()]

def LF():
	return [float(x) for x in sys.stdin.readline().split()]

def LS():
	return sys.stdin.readline().split()

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

def F():
	return float(sys.stdin.readline())

def S():
	return input()

def pf(s):
	return print(s, flush=True)

def pe(s):
	return print(str(s), file=sys.stderr)

def main():
	n = I()
	a = LI()
	ci = n - 1
	ct = 0
	at = 0
	r = 0
	for i in range(n):
		at += a[i]
		while ct < at:
			ct += a[ci]
			ci -= 1
		if i > ci:
			break
		if ct == at:
			r = at
	return r
print(main())


import sys
import itertools
import collections
input = lambda : sys.stdin.readline().rstrip('\r\n')
Read = lambda : list(map(int, input().split()))
Num = lambda : int(input())

def solve():
	n = Num()
	a = Read()
	b = a[::-1][:]
	pref = list(itertools.accumulate(a))
	suf = list(itertools.accumulate(b))[::-1]
	d = collections.defaultdict(list)
	for i in range(n):
		d[pref[i]].append(i)
	for i in range(n):
		if suf[i] in d and d[suf[i]][0] < i:
			d[suf[i]].append(i)
	need = []
	for (k, v) in d.items():
		if len(v) > 1:
			need.append([k, v])
	need.sort(key=lambda i: i[1][1] - i[1][0])
	if len(need):
		print(need[0][0])
	else:
		print(0)
solve()


n = int(input())
arr = list(map(int, input().split()))
pre = [0]
for i in arr:
	pre.append(pre[-1] + i)
post = [0]
for i in arr[::-1]:
	post.append(post[-1] + i)
post = post[::-1]
ans = 0
for i in range(n):
	left = pre[i + 1]
	lo = i + 1
	hi = n
	while lo <= hi:
		mid = lo + (hi - lo) // 2
		if post[mid] == left:
			ans = max(ans, left)
			break
		elif post[mid] > left:
			lo = mid + 1
		else:
			hi = mid - 1
print(ans)


n = int(input())
a = list(map(int, input().split(' ')))
(res, left, right, i, j) = (0, 0, 0, 0, n - 1)
while i <= j:
	if left > right:
		right += a[j]
		j -= 1
	else:
		left += a[i]
		i += 1
	if right == left:
		res = max(res, left)
print(res)


n = int(input())
a = list(map(int, input().split()))
left_to_right = [0] * n
right_to_left = [0] * n
sum = 0
for i in range(n):
	sum += a[i]
	left_to_right[i] = sum
sum = 0
for i in range(n - 1, -1, -1):
	sum += a[i]
	right_to_left[i] = sum
i = 0
j = n - 1
ans = 0
while i < j:
	if left_to_right[i] == right_to_left[j]:
		ans = left_to_right[i] if left_to_right[i] > ans else ans
		i += 1
		j -= 1
	elif left_to_right[i] < right_to_left[j]:
		i += 1
	else:
		j -= 1
print(ans)


n = int(input())
numbers = list(map(int, input().split()))
result = 0
i = 0
j = n - 1
sum1 = numbers[i]
sum3 = numbers[j]
while j > i:
	if sum1 == sum3:
		result = sum1
		i += 1
		j -= 1
		sum1 += numbers[i]
		sum3 += numbers[j]
	elif sum1 > sum3:
		j -= 1
		sum3 += numbers[j]
	else:
		i += 1
		sum1 += numbers[i]
if j - i == 1 and sum1 == sum3:
	result = sum1
print(result)


n = int(input())
a = list(map(int, input().split()))
(i, j) = (0, n - 1)
max_sum = 0
(l_sum, r_sum) = (0, 0)
while i <= j:
	if l_sum < r_sum:
		l_sum += a[i]
		i += 1
	else:
		r_sum += a[j]
		j -= 1
	if l_sum == r_sum:
		max_sum = l_sum
print(max_sum)


n = int(input().strip())
a = [int(x) for x in input().strip().split(' ')]
i = 0
j = n - 1
s1 = a[i]
s2 = a[j]
ans = 0
while i + n - j < n:
	if s1 == s2:
		ans = s1
		i += 1
		s1 += a[i]
	elif s1 < s2:
		i += 1
		s1 += a[i]
	else:
		j -= 1
		s2 += a[j]
print(ans)


n = int(input())
a = [int(i) for i in input().split()]
l = 0
r = len(a) - 1
sum1 = 0
sum3 = 0
max = 0
while l <= r:
	if sum1 + a[l] > sum3 + a[r]:
		sum3 += a[r]
		r -= 1
	else:
		sum1 += a[l]
		l += 1
	if sum1 == sum3:
		max = sum1
print(max)


ll = lambda : map(int, input().split())
t = lambda : int(input())
ss = lambda : input()
lx = lambda x: map(int, input().split(x))
yy = lambda : print('YES')
nn = lambda : print('NO')
from math import log10, log2, ceil, factorial as fac, gcd, inf

def f():
	n = t()
	a = list(ll())
	i = 0
	j = n - 1
	(s1, s2) = (0, 0)
	ans = 0
	while i <= j:
		if s1 == s2:
			ans = max(ans, s2)
			if i != j:
				s1 += a[i]
				s2 += a[j]
			i += 1
			j -= 1
		elif s1 > s2:
			s2 += a[j]
			j -= 1
		elif s2 > s1:
			s1 += a[i]
			i += 1
	if s1 == s2:
		ans = max(ans, s2)
	print(ans)
f()


from sys import stdin, stdout
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
first = 0
last = n - 1
temp = []
first_sum = a[0]
last_sum = a[n - 1]
while first < last:
	if first_sum <= last_sum:
		if first_sum == last_sum:
			temp.append(first_sum)
		first += 1
		first_sum += a[first]
	else:
		last -= 1
		last_sum += a[last]
if len(temp):
	print(max(temp))
else:
	print(0)


n = int(input())
a = [int(i) for i in input().split()]
p = 0
s = 0
lo = 0
hi = n - 1
ans = 0
while lo < hi:
	if a[lo] + p < a[hi] + s:
		p += a[lo]
		lo += 1
	elif a[lo] + p == a[hi] + s:
		ans = max(ans, a[lo] + p)
		p += a[lo]
		s += a[hi]
		lo += 1
		hi -= 1
	else:
		s += a[hi]
		hi -= 1
print(ans)


import sys
inputN = int(sys.stdin.readline())
usableString = list(map(int, sys.stdin.readline().split(' ')))
counting = 0
sum1 = usableString[0]
sum3 = usableString[-1]
maxSum1 = 0
countFromLeft = 1
countFromRight = 2
while counting < inputN - 1:
	if sum1 > sum3:
		sum3 += usableString[-countFromRight]
		countFromRight += 1
	elif sum3 > sum1:
		sum1 += usableString[countFromLeft]
		countFromLeft += 1
	elif sum1 == sum3:
		maxSum1 = sum1
		sum1 += usableString[countFromLeft]
		countFromLeft += 1
	counting += 1
print(maxSum1)


n = int(input())
l = list(map(int, input().split()))
i = s1 = s2 = 0
j = n - 1
a = [0]
s1 += l[i]
s2 += l[j]
while i != j:
	if s1 > s2:
		j -= 1
		s2 += l[j]
	elif s2 > s1:
		i += 1
		s1 += l[i]
	else:
		a.append(s1)
		i += 1
		s1 += l[i]
print(max(a))


n = int(input())
d = list(map(int, input().split()))
p1 = -1
p2 = n
s1 = 0
s2 = 0
mx_s = 0
while p1 != p2:
	if s1 == s2:
		mx_s = s1
		p2 -= 1
		s2 += d[p2]
	elif s1 > s2:
		p2 -= 1
		s2 += d[p2]
	else:
		p1 += 1
		s1 += d[p1]
print(mx_s)


n = int(input())
a = list(map(int, input().split()))
(s1, s3) = (0, 0)
max_s = 0
(l, r) = (0, n - 1)
while l <= r:
	if s1 > s3:
		s3 += a[r]
		r -= 1
	else:
		s1 += a[l]
		l += 1
	if s1 == s3:
		max_s = s1
print(max_s)


n = int(input())
l = [int(i) for i in input().split()]
a = 0
c = 0
ans = 0
j = n
i = -1
while j - i >= 1:
	if a < c:
		i += 1
		a += l[i]
	elif a > c:
		j -= 1
		c += l[j]
	else:
		if ans < a:
			ans = a
		i += 1
		j -= 1
		a += l[i]
		c += l[j]
print(ans)


n = int(input())
l = list(map(int, input().split()))
(i, j) = (0, n - 1)
m = a = b = 0
while i <= j:
	if a <= b:
		a += l[i]
		i += 1
	else:
		b += l[j]
		j -= 1
	if a == b:
		m = a
print(m)


n = int(input())
s = list(map(int, input().split()))
a = c = m = 0
i = 0
j = n - 1
while i < j:
	if a == c:
		m = a
		a = a + s[i]
		i = i + 1
		c = c + s[j]
		j = j - 1
	elif a < c:
		a = a + s[i]
		i = i + 1
	elif a > c:
		c = c + s[j]
		j = j - 1
if i == j:
	if a < c:
		a = a + s[i]
	if a > c:
		c = c + s[i]
if a == c:
	m = a
print(m)


n = int(input())
d = list(map(int, input().split()))
(a, b) = (0, len(d))
l = []
s1 = s2 = 0
while a < b:
	while s1 > s2 and a < b:
		b -= 1
		s2 += d[b]
	while s2 > s1 and a < b:
		s1 += d[a]
		a += 1
	if s1 == s2:
		l.append(s1)
		b -= 1
		s2 += d[b]
print(l[-1])


N = int(input())
NUMS = list(map(lambda x: int(x.strip()), input().split()))
BEST = 0
LEFT_P = 0
RIGHT_P = len(NUMS) - 1
SUM1 = NUMS[LEFT_P]
SUM3 = NUMS[RIGHT_P]
while LEFT_P < RIGHT_P:
	if SUM1 == SUM3 and SUM1 > BEST:
		BEST = SUM1
	if SUM1 > SUM3:
		RIGHT_P -= 1
		SUM3 += NUMS[RIGHT_P]
	else:
		LEFT_P += 1
		SUM1 += NUMS[LEFT_P]
print(BEST)


n = int(input())
d = [int(x) for x in input().split()]
j = n - 1
i = 0
sum1 = d[0]
ans = 0
sum3 = d[n - 1]
for x in range(n):
	if i >= j:
		break
	elif sum1 == sum3:
		ans = sum1
		i += 1
		j -= 1
		sum1 = sum1 + d[i]
		sum3 = sum3 + d[j]
	elif sum1 < sum3:
		i += 1
		sum1 += d[i]
	elif sum1 > sum3:
		j -= 1
		sum3 += d[j]
print(ans)


(z, zz) = (input, lambda : list(map(int, z().split())))
zzz = lambda : [int(i) for i in stdin.readline().split()]
(szz, graph, mod, szzz) = (lambda : sorted(zz()), {}, 10 ** 9 + 7, lambda : sorted(zzz()))
from string import *
from re import *
from collections import *
from queue import *
from sys import *
from collections import *
from math import *
from heapq import *
from itertools import *
from bisect import *
from collections import Counter as cc
from math import factorial as f
from bisect import bisect as bs
from bisect import bisect_left as bsl
from itertools import accumulate as ac

def lcd(xnum1, xnum2):
	return xnum1 * xnum2 // gcd(xnum1, xnum2)

def prime(x):
	p = ceil(x ** 0.5) + 1
	for i in range(2, p):
		if x % i == 0 and x != 2 or x == 0:
			return 0
	return 1

def dfs(u, visit, graph):
	visit[u] = True
	for i in graph[u]:
		if not visit[i]:
			dfs(i, visit, graph)
n = int(z())
l = zzz()
curright = n
curleft = 0
(suml, sumr, ans) = (0, 0, 0)
while curright != curleft:
	if sumr > suml:
		suml += l[curleft]
		curleft += 1
	else:
		curright -= 1
		sumr += l[curright]
	if suml == sumr:
		ans = suml
print(ans)


n = int(input())
d = list(map(int, input().split()))
l = -1
r = n
left = 0
right = 0
ans = 0
while l < r:
	if left > right:
		r -= 1
		right += d[r]
	elif left == right:
		ans = left
		l += 1
		left += d[l]
		r -= 1
		right += d[r]
	else:
		l += 1
		left += d[l]
print(ans)


from sys import stdin
from math import *
line = stdin.readline().rstrip().split()
n = int(line[0])
numbers = list(map(int, stdin.readline().rstrip().split()))
indexA = 0
indexC = n - 1
maxA = 0
if n == 0 or n == 1:
	print(0)
else:
	sumA = numbers[0]
	sumC = numbers[n - 1]
	while indexA < indexC:
		if sumA == sumC:
			maxA = sumA
			indexA += 1
			sumA += numbers[indexA]
			indexC -= 1
			sumC += numbers[indexC]
		elif sumA < sumC:
			indexA += 1
			sumA += numbers[indexA]
		else:
			indexC -= 1
			sumC += numbers[indexC]
	print(maxA)


n = int(input())
a = list(map(int, input().split()))
(i, j) = (0, n - 1)
(SumA, SumB) = (a[i], a[j])
BestCfg = 0
while i < j:
	if SumA > SumB:
		j = j - 1
		SumB += a[j]
	elif SumA < SumB:
		i = i + 1
		SumA += a[i]
	else:
		BestCfg = SumA
		i = i + 1
		SumA += a[i]
print(BestCfg)


n = int(input().strip())
arr = list(map(int, input().strip().split()))
i = 0
j = n - 1
sum1 = arr[i]
sum2 = arr[j]
best_sum = 0
while i < j:
	if sum1 == sum2:
		best_sum = sum1
		i += 1
		j -= 1
		sum1 += arr[i]
		sum2 += arr[j]
	elif sum1 > sum2:
		j -= 1
		sum2 += arr[j]
	else:
		i += 1
		sum1 += arr[i]
print(best_sum)


from collections import defaultdict
n = int(input())
a = list(map(int, input().split()))
pr = [0] * n
sf = [0] * n
pr[0] = a[0]
s = sum(a)
for i in range(1, n):
	pr[i] = pr[i - 1] + a[i]
sf[-1] = a[-1]
for i in range(n - 2, -1, -1):
	sf[i] = sf[i + 1] + a[i]
ds = defaultdict(int)
for i in range(n):
	ds[sf[i]] = i
ans = 0
for i in range(n):
	if pr[i] in ds and ds[pr[i]] > i:
		ans = max(ans, pr[i])
print(ans)


n = int(input())
arr = list(map(int, input().split()))
i = 0
j = n - 1
sum1 = 0
sum2 = 0
maxsum = 0
while i <= j:
	if sum1 <= sum2:
		sum1 += arr[i]
		i += 1
	else:
		sum2 += arr[j]
		j -= 1
	if sum1 == sum2:
		maxsum = max(sum1, maxsum)
print(maxsum)


n = int(input())
data = list(map(int, input().split()))
ind_l = 0
ind_r = n - 1
sum_l = 0
sum_r = 0
answer = 0
while ind_l <= ind_r:
	sum_l += data[ind_l]
	ind_l += 1
	while sum_l > sum_r and ind_l <= ind_r:
		sum_r += data[ind_r]
		ind_r -= 1
	if sum_l == sum_r:
		answer = sum_l
print(answer)


n = int(input())
l = [int(i) for i in input().split()]
sum1 = 0
sum2 = 0
a = 0
b = n - 1
visb = False
visa = False
ans = []
while a < b:
	if not visa:
		sum1 += l[a]
	if not visb:
		sum2 += l[b]
	visa = False
	visb = False
	if sum1 > sum2:
		b -= 1
		visa = True
	elif sum2 > sum1:
		a += 1
		visb = True
	elif sum2 == sum1:
		ans.append(sum1)
		a += 1
		b -= 1
if len(ans) == 0:
	print(0)
else:
	print(max(ans))


n = int(input())
a = list(map(int, input().split()))
for i in range(1, n):
	a[i] += a[i - 1]
j = n - 1
ans = 0
i = 0
while i < j:
	if a[i] < a[-1] - a[j - 1]:
		i += 1
	elif a[i] > a[-1] - a[j - 1]:
		j -= 1
	else:
		ans = max(ans, a[i])
		i += 1
		j -= 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
s1 = s2 = 0
ans = 0
i1 = 0
i2 = n - 1
while i2 >= i1:
	if s2 < s1:
		s2 += a[i2]
		i2 -= 1
	else:
		s1 += a[i1]
		i1 += 1
	if s1 == s2:
		ans = max(ans, s1)
print(ans)


n = int(input())
pre = list(map(int, input().split()))
l = 0
r = n - 1
sl = pre[0]
sr = pre[n - 1]
ans = 0
while l < r:
	if sl == sr:
		ans = max(ans, sr)
	if sl < sr:
		l = 1 + l
		sl += pre[l]
	else:
		r = r - 1
		sr += pre[r]
print(ans)


import atexit
import io
import sys
R = lambda : map(int, input().split())
n = int(input())
lst = list(R())
(i, j, sum1, sum2, index) = (0, n, 0, 0, 0)
ans = 0
while i <= j:
	if sum1 == sum2:
		ans = sum1
		if i < n:
			sum1 += lst[i]
		i += 1
		j -= 1
		sum2 += lst[j]
	elif sum1 < sum2:
		if i < n:
			sum1 += lst[i]
		i += 1
	else:
		j -= 1
		sum2 += lst[j]
print(ans)


from itertools import accumulate

def main():
	n = int(input())
	a = list(accumulate(map(int, input().split())))
	fsu_m = a.pop()
	false = 2 * 2 == 5
	true = 2 * 2 == 4
	a2 = []
	while a:
		x = a.pop()
		x2 = fsu_m - x
		a2.append(x2)
		if x2 >= x:
			a.append(x)
			break
	else:
		a.append(1)
		a2 = []
	ai = a.pop()
	ai2 = 1
	pf_a1 = false
	while pf_a1 and a or (not pf_a1 and a2):
		if pf_a1:
			ai = a.pop()
		else:
			ai2 = a2.pop()
		if ai > ai2:
			pf_a1 = true
		elif ai < ai2:
			pf_a1 = false
		else:
			print(ai)
			break
	else:
		print('0')
main()


n = int(input())
a = [int(i) for i in input().split()]
l = 0
r = n - 1
sul = 0
sur = 0
ans = 0
while l <= r:
	if sul == sur:
		ans = max(ans, sul)
		sul += a[l]
		l += 1
	elif sul < sur:
		sul += a[l]
		l += 1
	else:
		sur += a[r]
		r -= 1
if sul == sur:
	ans = max(ans, sul)
print(ans)


def main():
	n = int(input())
	a = [int(i) for i in input().split()]
	m = 0
	n3 = n
	s1 = 0
	s3 = 0
	for i in range(n):
		s1 += a[i]
		while s3 < s1:
			n3 -= 1
			s3 += a[n3]
		if n3 <= i:
			break
		if s3 == s1:
			m = s1
	print(m)
main()


def sul():
	n = int(input())
	arr = [int(i) for i in input().split(' ')]
	p1 = 0
	p2 = len(arr) - 1
	sum1 = arr[p1]
	sum2 = arr[p2]
	final_sum = 0
	while p1 < p2:
		if sum1 > sum2:
			p2 -= 1
			sum2 += arr[p2]
		elif sum1 < sum2:
			p1 += 1
			sum1 += arr[p1]
		else:
			final_sum = sum1
			p2 -= 1
			sum2 += arr[p2]
	return final_sum
print(sul())


n = int(input())
L = list(map(int, input().split()))
(l, r) = (0, n - 1)
(sl, sr, su) = (L[0], L[-1], 0)
while l < r:
	if sl < sr:
		l += 1
		sl += L[l]
	elif sr < sl:
		r -= 1
		sr += L[r]
	else:
		l += 1
		r -= 1
		su = max(su, sl)
		sl += L[l]
		sr += L[r]
print(su)


R = lambda : map(int, input().split())
n = int(input())
a = list(R())
ans = 0
i = 0
j = n - 1
s1 = 0
s3 = 0
while i < j:
	if s1 + a[i] == s3 + a[j]:
		s1 += a[i]
		s3 += a[j]
		i += 1
		j -= 1
		ans = s1
	elif s1 + a[i] < s3 + a[j]:
		s1 += a[i]
		i += 1
	else:
		s3 += a[j]
		j -= 1
print(ans)


n = int(input())
d = list(map(int, input().split()))
mx = 0
(i, j) = (-1, n)
(lsum, rsum) = (0, 0)
while i < j:
	if lsum == rsum:
		mx = max(mx, lsum)
	if lsum <= rsum:
		i += 1
		lsum += d[i]
	elif rsum < lsum:
		j -= 1
		rsum += d[j]
print(mx)


noe = int(input())
arr = [int(x) for x in input().split()]
(l, r) = (0, noe - 1)
(lsum, rsum, maxsum) = (0, 0, 0)
while l <= r:
	if lsum >= rsum:
		rsum += arr[r]
		r -= 1
	else:
		lsum += arr[l]
		l += 1
	if lsum == rsum:
		maxsum = lsum
print(maxsum)


import sys, os
from io import BytesIO, IOBase
import collections, itertools, bisect, heapq, math, string
from decimal import *
BUFSIZE = 8192
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 main():
	n = int(input())
	a = list(map(int, input().split()))
	ans = 0
	prefix = [a[0]]
	for i in range(1, n):
		prefix.append(a[i] + prefix[-1])
	d = collections.defaultdict(lambda : 0)
	for i in range(n):
		d[prefix[i]] = i
	s = 0
	for i in range(n - 1, -1, -1):
		s += a[i]
		if s in d.keys() and d[s] < i:
			ans = max(ans, s)
	print(ans)
main()


from collections import deque
n = int(input())
d = list(map(int, input().split(' ')))
d = deque(d)
(p0, p1) = (0, n)
debug = False
max_sum = 0
(left_sum, right_sum) = (0, 0)
while d:
	if left_sum <= right_sum:
		left_sum += d.popleft()
	else:
		p1 -= 1
		right_sum += d.pop()
	if left_sum == right_sum and left_sum > max_sum:
		max_sum = left_sum
	if debug:
		print(p0, p1, left_sum, right_sum, max_sum)
print(max_sum)


n = int(input())
a = list(map(int, input().split()))
s = 0
pre = [a[0]]
su = [sum(a)]
for i in range(1, n):
	pre.append(a[i] + pre[-1])
	su.append(su[-1] - a[i - 1])
i = 0
j = n - 1
while i < j:
	if pre[i] > su[j]:
		j -= 1
	elif pre[i] < su[j]:
		i += 1
	else:
		s = max(s, pre[i])
		i += 1
		j -= 1
print(s)


n = int(input())
m = list(map(int, input().split()))
i = 0
j = len(m) - 1
s1 = s2 = 0
while 1:
	if i >= j:
		break
	if s1 == s2:
		l = s1
		s1 += m[i]
		s2 += m[j]
	elif s1 > s2:
		s2 += m[j]
	else:
		s1 += m[i]
	if s1 == s2:
		i += 1
		j -= 1
	elif s1 > s2:
		j -= 1
	else:
		i += 1
if s1 == s2:
	l = s1
print(l)


n = int(input().strip())
arr = [int(__) for __ in input().strip().split()]
p = [arr[0]]
for i in range(1, n):
	p.append(p[i - 1] + arr[i])
prev = [arr[-1]]
arr = arr[::-1]
for i in range(1, n):
	prev.append(prev[i - 1] + arr[i])
prev = prev[::-1]
dic = {}
for i in range(n):
	dic[p[i]] = i
ans = 0
for i in range(n):
	if prev[i] in dic and i > dic[prev[i]]:
		ans = max(ans, prev[i])
print(ans)


n = int(input())
a = list(map(int, input().split()))
i = 0
j = n - 1
c = 0
d = 0
ans = 0
while i <= j:
	if c <= d:
		c = c + a[i]
		i = i + 1
	elif d < c:
		d = d + a[j]
		j -= 1
	if c == d:
		ans = max(ans, c)
print(ans)


n = int(input())
l = list(map(int, input().split()))
i = 0
j = n - 1
sum1 = l[i]
sum2 = l[j]
flag = 0
temp1 = 0
temp2 = 0
temp3 = 0
while i < j:
	if sum1 == sum2:
		flag = sum1
		i += 1
		j -= 1
		temp1 = 1
	elif sum1 > sum2:
		j -= 1
		temp2 = 1
	elif sum1 < sum2:
		i += 1
		temp3 = 1
	if temp1 == 1:
		sum1 += l[i]
		sum2 += l[j]
		temp1 = 0
	elif temp2 == 1:
		sum2 += l[j]
		temp2 = 0
	elif temp3 == 1:
		sum1 += l[i]
		temp3 = 0
print(flag)


import math

def main():
	n = int(input())
	a = list(map(int, input().split()))
	(i, j) = (0, n - 1)
	res = []
	(suml, sumr) = (a[0], a[n - 1])
	while i < j:
		if suml == sumr:
			res.append(suml)
			i += 1
			j -= 1
			suml += a[i]
			sumr += a[j]
		elif suml < sumr:
			i += 1
			suml += a[i]
		else:
			j -= 1
			sumr += a[j]
	if len(res) == 0:
		print(0)
	else:
		print(res[len(res) - 1])
main()


n = int(input())
nums = list(map(int, input().strip().split()))
(l, r) = (-1, n)
(summa, summb) = (0, 0)
res = 0
while l < r:
	if summa < summb:
		l += 1
		summa += nums[l]
	elif summa > summb:
		r -= 1
		summb += nums[r]
	else:
		l += 1
		r -= 1
		res = summa
		summa += nums[l]
		summb += nums[r]
print(res)


n = int(input())
a = [int(x) for x in input().split()]
p1 = 0
p2 = n - 1
s1 = a[p1]
s2 = a[p2]
ans = 0
if s1 == s2 and n > 1:
	ans = s1
while p1 < p2:
	if s1 < s2:
		p1 += 1
		if p1 != p2:
			s1 += a[p1]
	elif s1 > s2:
		p2 -= 1
		if p1 != p2:
			s2 += a[p2]
	elif a[p1] < a[p2]:
		p1 += 1
		if p1 != p2:
			s1 += a[p1]
	else:
		p2 -= 1
		if p1 != p2:
			s2 += a[p2]
	if s1 == s2:
		if s1 > ans:
			ans = s1
print(ans)


n = int(input())
d = [int(x) for x in input().split()]
vis = set([0])
s = sum(d)
cur = 0
for x in d:
	cur += x
	if cur <= s / 2:
		vis.add(cur)
	else:
		break
d.reverse()
cur = 0
m = 0
for x in d:
	cur += x
	if cur <= s / 2:
		if cur in vis:
			m = cur
	else:
		break
print(m)


n = int(input())
l = list(map(int, input().split()))
s = sum(l)
a = [l[0]] + [0] * (n - 1)
b = [s] + [0] * (n - 1)
for i in range(1, n):
	a[i] = a[i - 1] + l[i]
	b[i] = s - a[i - 1]
ans = 0
i = 0
j = n - 1
while i < n and j >= 0 and (i <= j - 1):
	if a[i] < b[j]:
		i += 1
	elif a[i] > b[j]:
		j -= 1
	else:
		if a[i] > ans:
			ans = a[i]
		i += 1
		j -= 1
print(ans)


def solve():
	n = inp()
	l = seq()
	total = sum(l)
	sum1 = 0
	sum3 = 0
	low = -1
	high = n
	maxi = 0
	while low < high:
		if sum1 == sum3:
			maxi = max(sum1, maxi)
			low += 1
			high -= 1
			sum1 += l[low]
			sum3 += l[high]
		elif sum1 < sum3:
			low += 1
			sum1 += l[low]
		else:
			high -= 1
			sum3 += l[high]
	print(maxi)
import sys
import math
import bisect
from sys import stdin, stdout
from math import gcd, floor, sqrt, log
from collections import defaultdict as dd
from bisect import bisect_left as bl, bisect_right as br
inp = lambda : int(input())
strng = lambda : input().strip()
jn = lambda x, l: x.join(map(str, l))
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
ceil = lambda x: int(x) if x == int(x) else int(x) + 1
ceildiv = lambda x, d: x // d if x % d == 0 else x // d + 1
flush = lambda : stdout.flush()
stdstr = lambda : stdin.readline()
stdint = lambda : int(stdin.readline())
stdpr = lambda x: stdout.write(str(x))
solve()


n = int(input())
d = list(map(int, input().split()))
i = 0
j = n - 1
best = 0
s1 = d[i]
s3 = d[j]
while j > i:
	if s1 > s3:
		j -= 1
		s3 += d[j]
	elif s3 > s1:
		i += 1
		s1 += d[i]
	else:
		best = s1
		i += 1
		j -= 1
		s1 += d[i]
		s3 += d[j]
print(best)


n = int(input())
a = [int(x) for x in input().split()]
low = 0
high = len(a) - 1
curr_max = 0
(lsum, rsum) = (a[low], a[high])
if lsum == rsum:
	curr_max = lsum
while high - low > 1:
	if lsum < rsum:
		low += 1
		lsum += a[low]
	else:
		high -= 1
		rsum += a[high]
	if lsum == rsum:
		curr_max = lsum
if len(a) <= 1:
	print(0)
else:
	print(curr_max)


n = int(input())
a = [int(i) for i in input().split()]
kon = len(a) - 1
nach = 0
smn = 0
smk = 0
smmx = 0
for i in range(len(a)):
	smn += a[nach]
	if smn > smk:
		while smk < smn:
			smk += a[kon]
			kon -= 1
		if kon < nach:
			break
	if smn == smk:
		smmx = smn
	if nach > kon:
		break
	nach += 1
print(smmx)


n = int(input())
lis = list(map(int, input().split()))
pre = [0] * n
pos = [0] * n
for i in range(n - 1):
	pre[i] = pre[i - 1] + lis[i]
	pos[i] = pos[i - 1] + lis[n - i - 1]
for i in range(n - 2, -1, -1):
	l = 0
	r = n - i - 2
	while r >= l:
		mid = l + (r - l) // 2
		if pos[mid] <= pre[i]:
			l = mid + 1
		else:
			r = mid - 1
	if pos[r] == pre[i]:
		print(pos[r])
		exit()
print(0)


import sys
n = int(input())
if n == 1:
	print(0)
	sys.exit(0)
arr = [int(i) for i in input().split()]
start = 0
end = n - 1
tot = left = right = 0
while end >= start:
	if left > right:
		right += arr[end]
		end -= 1
	else:
		left += arr[start]
		start += 1
	if left == right:
		tot = left
print(tot)


n = int(input())
D = list(map(int, input().split()))
L = [0] * (n + 1)
R = [0] * (n + 1)
for i in range(n):
	L[i + 1] = L[i] + D[i]
for i in reversed(range(n)):
	R[i] = R[i + 1] + D[i]
from collections import Counter
S = Counter(R)
ans = 0
for i in range(n):
	l = L[i + 1]
	S[R[i]] -= 1
	if l in S:
		if S[l] > 0:
			ans = max(ans, l)
print(ans)


import sys
input = sys.stdin.readline
from math import log2, log, ceil

def swaparr(arr, a, b):
	temp = arr[a]
	arr[a] = arr[b]
	arr[b] = temp

def gcd(a, b):
	if a == 0:
		return b
	return gcd(b % a, a)

def primefs(n):
	primes = {}
	while n % 2 == 0:
		primes[2] = primes.get(2, 0) + 1
		n = n // 2
	for i in range(3, int(n ** 0.5) + 2, 2):
		while n % i == 0:
			primes[i] = primes.get(i, 0) + 1
			n = n // i
	if n > 2:
		primes[n] = primes.get(n, 0) + 1
	return primes

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 swap(a, b):
	temp = a
	a = b
	b = temp
	return (a, b)

def find(x, link):
	while x != link[x]:
		x = link[x]
	return x

def union(x, y, size, link):
	x = find(x, link)
	y = find(y, link)
	if size[x] < size[y]:
		(x, y) = swap(x, y)
	if x != y:
		size[x] += size[y]
		link[y] = x

def sieve(n):
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p * p, n + 1, p):
				prime[i] = False
		p += 1
	return prime
MAXN = int(1000000.0 + 5)

def spf_sieve():
	spf[1] = 1
	for i in range(2, MAXN):
		spf[i] = i
	for i in range(4, MAXN, 2):
		spf[i] = 2
	for i in range(3, ceil(MAXN ** 0.5), 2):
		if spf[i] == i:
			for j in range(i * i, MAXN, i):
				if spf[j] == j:
					spf[j] = i

def factoriazation(x):
	ret = {}
	while x != 1:
		ret[spf[x]] = ret.get(spf[x], 0) + 1
		x = x // spf[x]
	return ret

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

def str_array():
	return input().strip().split()
MOD = int(1000000000.0) + 7
CMOD = 998244353
INF = float('inf')
NINF = -float('inf')
n = int(input())
a = int_array()
i = 0
j = n - 1
ans = 0
x = 0
y = 0
lstx = 1
lsty = 1
while i < j:
	if lstx == 1:
		x += a[i]
	if lsty == 1:
		y += a[j]
	lstx = 0
	lsty = 0
	if x == y:
		ans = max(ans, x)
		i += 1
		j -= 1
		lstx = 1
		lsty = 1
	elif x < y:
		i += 1
		lstx = 1
	else:
		j -= 1
		lsty = 1
print(ans)


from sys import stdin, stdout
n = int(input())
arr = [int(x) for x in stdin.readline().split()]
pref_sum = list((0 for i in range(n + 1)))
suff_sum = list((0 for i in range(n + 1)))
for i in range(1, n + 1):
	pref_sum[i] = pref_sum[i - 1] + arr[i - 1]
app = dict()
for i in range(1, n + 1):
	suff_sum[i] = suff_sum[i - 1] + arr[n - i]
	app[suff_sum[i]] = i
ans = 0
for i in range(1, n + 1):
	if pref_sum[i] in app:
		if app[pref_sum[i]] <= n - i:
			ans = pref_sum[i]
print(ans)


from itertools import accumulate
n = int(input())
a = [int(x) for x in input().split()]
(l, r) = (0, n - 1)
(s1, s2) = (0, 0)
ans = 0
while l <= r:
	if s1 <= s2:
		s1 += a[l]
		l += 1
	else:
		s2 += a[r]
		r -= 1
	if s1 == s2:
		ans = s1
print(ans)


n = int(input())
a = list(map(int, input().split()))
s2 = 0
s1 = 0
ptr = n - 1
res = 0
for i in range(n):
	s1 += a[i]
	while s1 > s2 and ptr - 1 >= i:
		s2 += a[ptr]
		ptr -= 1
	if s1 == s2:
		res = s1
print(res)


from sys import stdin, stdout
from collections import defaultdict
import math
import copy
N = int(input())
arr = [int(x) for x in stdin.readline().split()]
res = 0
sum1 = {}
sum3 = {}
sum1[0] = 0
s = 0
for i in range(N):
	s += arr[i]
	sum1[s] = i + 1
sum3[0] = 0
s = 0
for i in range(N - 1, -1, -1):
	s += arr[i]
	sum3[s] = N - i
res = 0
for num in sum1:
	if num in sum3:
		if sum1[num] + sum3[num] <= N:
			res = max(res, num)
print(res)


n = int(input())
d = list(map(int, input().split()))
sum = 0
i = 0
j = n - 1
left = d[i]
right = d[j]
while i < j:
	if left == right:
		sum = left
		i += 1
		j -= 1
		left += d[i]
		right += d[j]
	elif left > right:
		j -= 1
		right += d[j]
	else:
		i += 1
		left += d[i]
print(sum)


n = int(input())
a = list(map(int, input().split()))
i = 0
j = n - 1
sum1 = 0
sum2 = 0
ans = 0
while j >= i:
	if sum1 <= sum2:
		sum1 += a[i]
		i += 1
	else:
		sum2 += a[j]
		j -= 1
	if sum1 == sum2:
		ans = sum1
print(ans)


n = int(input())
L = [int(x) for x in input().split()]
PartialL = [L[0]]
PartialR = [L[-1]]
for i in range(1, n):
	PartialL.append(PartialL[-1] + L[i])
	PartialR.append(PartialR[-1] + L[-i - 1])
ans = 0
for i in range(n - 1):
	temp = PartialL[i]
	low = 0
	high = n - i - 2
	while high - low > 1:
		guess = (high + low) // 2
		if PartialR[guess] > temp:
			high = guess
		elif PartialR[guess] < temp:
			low = guess
		else:
			ans = temp
			break
	if PartialR[high] == temp:
		ans = temp
	elif PartialR[low] == temp:
		ans = temp
print(ans)


n = int(input())
a = list(map(int, input().split()))
i = 0
sum1 = 0
sum3 = {}
ans = 0
c = 0
for i in range(n - 1, 0, -1):
	c += a[i]
	sum3[c] = i
for j in range(n - 1):
	sum1 += a[j]
	if sum1 in sum3 and sum3[sum1] > j:
		ans = max(ans, sum1)
print(ans)


def main():
	n = int(input())
	a = list(map(int, input().split()))
	s = sum(a)
	temp = 0
	q = [0]
	r = []
	ind = 0
	while temp * 2 < s:
		temp += a[ind]
		ind += 1
		q.append(temp)
	if temp * 2 == s:
		print(temp)
		return 0
	temp = s - temp
	while ind < n:
		r.append(temp)
		temp -= a[ind]
		ind += 1
	r += [0]
	(s, t) = (-1, 0)
	while q[s] != r[t]:
		if q[s] > r[t]:
			s -= 1
		else:
			t += 1
	print(q[s])
	return 0
main()


n = int(input())
a = list(map(int, input().split()))
suma = i = 0
flag = 0
sum1 = 0
sum3 = 0
j = n - 1
idxs = i
idxe = j
while True:
	if sum1 == 0 and sum3 == 0 or sum1 < sum3:
		sum1 += a[i]
		i += 1
	elif sum3 < sum1:
		sum3 += a[j]
		j -= 1
	elif sum1 == sum3:
		suma += sum1
		flag = 1
		sum1 = 0
		sum3 = 0
	if j < i - 1:
		break
if flag:
	print(suma)
else:
	print(0)


n = int(input())
arr = list(map(int, input().split()))
ans = -1
i = 0
j = n - 1
l = arr[i]
r = arr[j]
while i < j:
	if l == r:
		ans = l
		i += 1
		l += arr[i]
		j -= 1
		r += arr[j]
	elif l < r:
		i += 1
		l += arr[i]
	else:
		j -= 1
		r += arr[j]
if ans == -1:
	print('0')
else:
	print(ans)


n = int(input())
s = list(map(int, input().split()))
su = sum(s)
t = 0
(se1, se2) = (set(), set())
for i in s:
	t += i
	se1.add(t)
	if su - t in se1:
		se2.add(su - t)
print(max(list(se2)) if len(se2) else 0)


h = int(input())
array = list(map(int, input().split()))
pre = [0] * h
pre[0] = array[0]
for i in range(1, h):
	pre[i] = array[i] + pre[i - 1]
su = [0] * h
su[0] = array[-1]
for i in range(1, h):
	su[i] = array[-(1 + i)] + su[i - 1]
a = 0
b = 0
maxi = 0
while a + b + 1 < h:
	if pre[a] == su[b]:
		maxi = pre[a]
		a += 1
		b += 1
	elif pre[a] < su[b]:
		a += 1
	else:
		b += 1
print(maxi)


n = int(input())
arr = [int(p) for p in input().split()]
i = 0
j = len(arr) - 1
curr = 0
sm1 = arr[i]
sm2 = arr[j]
while i < j:
	if sm1 == sm2:
		curr = sm1
		i += 1
		j -= 1
		sm1 += arr[i]
		sm2 += arr[j]
	elif sm1 < sm2:
		i += 1
		sm1 += arr[i]
	else:
		j -= 1
		sm2 += arr[j]
print(curr)


n = int(input())
arr = [int(x) for x in input().split()]
s = sum(arr)
suml = [0 for i in range(n)]
rsum = [0 for i in range(n)]
cont = 0
for i in range(n):
	cont += arr[i]
	suml[i] = cont
cont = 0
for i in range(n):
	rsum[n - i - 1] = s - cont
	cont += arr[i]
ind1 = 0
ind2 = 0
ok = False
equal = 0
while ind1 + ind2 <= n - 2:
	if suml[ind1] == rsum[ind2]:
		ok = True
		equal = ind1
		ind1 += 1
	elif suml[ind1] < rsum[ind2]:
		ind1 += 1
	elif suml[ind1] > rsum[ind2]:
		ind2 += 1
if ok:
	print(suml[equal])
else:
	print(0)


from itertools import accumulate
n = int(input())
d = list(map(int, input().split()))
left = list(accumulate([0] + d))
right = list(accumulate([0] + d[::-1]))
ans = 0
(i, j) = (0, 0)
while i + j <= n:
	(le, ri) = (left[i], right[j])
	if le == ri:
		ans = le
		i += 1
		j += 1
	elif le < ri:
		i += 1
	elif le > ri:
		j += 1
	else:
		return
print(ans)


n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
lsum = a[l]
rsum = a[r]
ans = 0
while r > l:
	if rsum == lsum:
		ans = lsum
		l += 1
		lsum += a[l]
	elif rsum > lsum:
		l += 1
		lsum += a[l]
	else:
		r -= 1
		rsum += a[r]
print(ans)


n = int(input())
a = list(map(int, input().split()))
p = n // 2
if sum(a[:p]) == sum(a[p:]):
	print(sum(a[:p]))
elif sum(a[:p + 1]) == sum(a[p + 1:]):
	print(sum(a[:p + 1]))
else:
	(li, ri, aix, ls, rs) = (-1, n, 0, 0, 0)
	while li < ri:
		if ls < rs:
			li += 1
			ls += a[li]
		elif ls > rs:
			ri -= 1
			rs += a[ri]
		else:
			aix = li
			li += 1
			ri -= 1
			ls += a[li]
			rs += a[ri]
	print(sum(a[:aix + 1]))


n = int(input())
arr = list(map(int, input().split()))
p1 = 0
p2 = len(arr) - 1
sum1 = arr[p1]
sum2 = arr[p2]
final_sum = 0
for _ in arr:
	if p1 >= p2:
		break
	if sum1 == sum2:
		final_sum = sum1
		p2 -= 1
		p1 += 1
		sum1 += arr[p1]
		sum2 += arr[p2]
	elif sum1 > sum2:
		p2 -= 1
		sum2 += arr[p2]
	elif sum1 < sum2:
		p1 += 1
		sum1 += arr[p1]
print(final_sum)


n = int(input())
a = [0] + list(map(int, input().split())) + [0]
(l, r) = (0, 0)
(i, j) = (0, n + 1)
s = 0
while i < j - 1:
	if l > r:
		j -= 1
		r += a[j]
	else:
		i += 1
		l += a[i]
	if l == r:
		s = l
print(s)


list_size = int(input())
input_list = list(map(int, input().split()))
right_idx = list_size - 1
left_idx = 0
ans = 0
left_sum = input_list[left_idx]
right_sum = input_list[right_idx]
while left_idx < right_idx:
	if left_sum == right_sum:
		ans = left_sum
		left_idx += 1
		left_sum += input_list[left_idx]
		continue
	elif left_sum < right_sum:
		left_idx += 1
		left_sum += input_list[left_idx]
		continue
	else:
		right_idx -= 1
		right_sum += input_list[right_idx]
		continue
print(ans)


def binar(l, r, z, la):
	while r >= l:
		mid = (r + l) // 2
		if la[mid] > z:
			r = mid - 1
		elif la[mid] < z:
			l = mid + 1
		else:
			return mid
	return -1
n = int(input())
l = list(map(int, input().split()))
pref = [0]
suff = [0]
z = reversed(l)
for i in l:
	pref.append(i + pref[-1])
for i in z:
	suff.append(i + suff[-1])
maxi = 0
for i in range(n):
	j = i + 1
	k = binar(0, n - 1, pref[j], suff)
	if k != -1:
		if n - k + 1 > j:
			maxi = max(maxi, pref[j])
print(maxi)


import sys
fast_reader = sys.stdin.readline
fast_writer = sys.stdout.write

def input():
	return fast_reader().strip()

def print(*argv):
	fast_writer(' '.join((str(i) for i in argv)))
	fast_writer('\n')
for _ in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	pref1 = [0 for i in range(n)]
	pref2 = [0 for i in range(n)]
	c1 = 0
	c2 = 0
	for i in range(n):
		c1 += l[i]
		c2 += l[n - i - 1]
		pref1[i] = c1
		pref2[n - i - 1] = c2
	i = 0
	j = n - 1
	maxs = 0
	while i < j:
		if pref1[i] == pref2[j] and maxs < pref1[i]:
			maxs = pref1[i]
		if pref1[i] == pref2[j]:
			i += 1
			j -= 1
		elif pref1[i] > pref2[j]:
			j -= 1
		else:
			i += 1
	print(maxs)


n = int(input())
array = list(map(int, input().split()))
i = 0
j = len(array) - 1
soma = 0
soma1 = array[i]
soma2 = array[j]
while i < j:
	if soma1 < soma2:
		i += 1
		soma1 += array[i]
	elif soma1 > soma2:
		j -= 1
		soma2 += array[j]
	else:
		if soma1 > soma:
			soma = soma1
		i += 1
		j -= 1
		soma1 += array[i]
		soma2 += array[j]
print(soma)


n = int(input())
a = [int(x) for x in input().split()]
(r, x, y) = (0, 0, 0)
(i, j) = (0, n)
while i <= j:
	if x == y:
		r = x
		if i < n:
			x += a[i]
		i += 1
		j -= 1
		y += a[j]
	elif x < y:
		if i < n:
			x += a[i]
		i += 1
	else:
		j -= 1
		y += a[j]
print(r)


n = int(input())
l = [int(i) for i in input().split()]
if n == 1:
	print(0)
else:
	i = 0
	j = n - 1
	s1 = l[i]
	s2 = l[j]
	if s1 == s2:
		c = s1
	else:
		c = 0
	while abs(i - j) > 1:
		if s1 == s2:
			c = s1
		if s1 <= s2:
			i += 1
			s1 += l[i]
		else:
			j -= 1
			s2 += l[j]
	if s1 == s2:
		c = s1
	print(c)


n = int(input())
arr = list(map(int, input().split()))
mx = 0
low = 0
high = n - 1
left = arr[0]
right = arr[n - 1]
while low < high:
	if left < right:
		low += 1
		left += arr[low]
	elif left > right:
		high -= 1
		right += arr[high]
	else:
		if mx < left:
			mx = left
		low += 1
		high -= 1
		left += arr[low]
		right += arr[high]
print(mx)


mod = 1000000007
ii = lambda : int(input())
si = lambda : input()
dgl = lambda : list(map(int, input()))
f = lambda : map(int, input().split())
il = lambda : list(map(int, input().split()))
ls = lambda : list(input())
from itertools import *
n = ii()
l = il()
mx = 0
lf = list(accumulate(l))
lb = set(accumulate(l[::-1]))
sm = lf[-1]
lb.discard(sm)
for i in lf:
	if i in lb:
		mx = max(mx, i)
	lb.discard(sm - i)
print(mx)


n = int(input())
l = list(map(int, input().split()))
le = -1
ri = n
(sl, sr) = (0, 0)
x = []
while le < ri:
	if sl < sr:
		le += 1
		if le == ri:
			break
		sl += l[le]
	elif sl > sr:
		ri -= 1
		sr += l[ri]
	else:
		x.append(sl)
		le += 1
		if le == ri:
			break
		sl += l[le]
		ri -= 1
		if le == ri:
			break
		sr += l[ri]
if sl == sr:
	x.append(sl)
if x:
	print(max(x))
else:
	print(0)


n = int(input())
d = list(map(int, input().split()))
sum1 = []
tmp = 0
for (i, j) in enumerate(d):
	sum1.append((tmp, i))
	tmp += j
sum1.append((tmp, i + 1))
sum3 = []
tmp = 0
for (i, j) in enumerate(d[::-1]):
	sum3.append((tmp, i))
	tmp += j
sum3.append((tmp, i + 1))
d = dict(sum1)
m = 0
for i in sum3:
	if i[0] in d:
		if d[i[0]] + i[1] <= n:
			m = i[0]
print(m)


def answer(n, d):
	sum1 = [d[0]]
	for i in range(1, n, 1):
		sum1.append(d[i] + sum1[-1])
	prev_sum = d[-1]
	set3 = set()
	for i in range(n - 2, -1, -1):
		set3.add(d[i] + prev_sum)
		prev_sum += d[i]
	for i in range(n - 2, -1, -1):
		if sum1[i] in set3:
			return sum1[i]
	return 0

def answer2(n, d):
	sum1 = [d[0]]
	for i in range(1, n, 1):
		sum1.append(d[i] + sum1[-1])
	sum3 = [d[-1]]
	for i in range(n - 2, -1, -1):
		sum3.append(d[i] + sum3[-1])
	sum3.reverse()
	lpos = 0
	rpos = n - 1
	best = 0
	while lpos < rpos:
		if sum1[lpos] == sum3[rpos]:
			best = sum1[lpos]
			lpos += 1
			rpos -= 1
		elif sum1[lpos] < sum3[rpos]:
			lpos += 1
		else:
			rpos -= 1
	return best

def main():
	n = int(input())
	d = [int(i) for i in input().split()]
	print(answer2(n, d))
	return
main()


import bisect
n = int(input())
a = [int(s) for s in input().split()]
b = [0] * n
c = [0] * n
b[0] = a[0]
c[0] = a[n - 1]
for i in range(1, n):
	b[i] = a[i] + b[i - 1]
	c[i] = a[n - 1 - i] + c[i - 1]
ans = 0
for i in range(n - 1):
	j = bisect.bisect_left(c, b[i], 0, n - i - 1)
	if c[j] == b[i] and i + j < n - 1:
		ans = max(ans, c[j])
print(ans)


input()
array = [int(i) for i in input().split()]
if len(array) == 0:
	print(0)
	exit(0)
(sub_arr1, sub_arr3) = (0, 0)
out = 0
(i, j) = (0, len(array) - 1)
sub_arr1 += array[i]
sub_arr3 += array[j]
while i < j:
	if sub_arr1 == sub_arr3:
		out = max(out, sub_arr1)
		i += 1
		j -= 1
		sub_arr1 += array[i]
		sub_arr3 += array[j]
	elif sub_arr1 < sub_arr3:
		i += 1
		sub_arr1 += array[i]
	else:
		j -= 1
		sub_arr3 += array[j]
print(out)


n = int(input())
j = n - 1
s1 = 0
s3 = 0
maxx = 0
ch = input()
L = [int(i) for i in ch.split()]
for i in range(n):
	s1 += L[i]
	if s1 == s3:
		maxx = s1
	if s1 > s3:
		while True:
			s3 += L[j]
			j -= 1
			if s3 > s1 or i > j:
				break
			if s3 == s1:
				maxx = s1
				break
		if i > j:
			break
print(maxx)


import math
import io
nancy = int(input())
alpha = list(map(int, input().split()))
(i, j) = (0, len(alpha) - 1)
(x, y, z) = (0, 0, 0)
while i <= j:
	if x > y:
		y += alpha[j]
		j -= 1
	else:
		x += alpha[i]
		i += 1
	if x == y:
		z = x
print(z)


N = int(input())
A = list(map(int, input().split()))
i = -1
j = len(A)
s1 = 0
s3 = 0
sum = 0
while i < j:
	if s1 == s3:
		i += 1
		j -= 1
		sum = s1
		s1 += A[i]
		s3 += A[j]
	elif s1 < s3:
		i += 1
		s1 += A[i]
	else:
		j -= 1
		s3 += A[j]
print(sum)


from itertools import accumulate
from sys import stdin, stdout
input = lambda : stdin.readline().rstrip()
write = stdout.write

def main():
	N = int(input())
	A = list(map(int, input().split()))
	a1 = list(accumulate(A))
	a2 = list(accumulate(A[::-1]))[::-1]
	(ans, j) = (0, N - 1)
	for i in range(N):
		while i < j:
			if a1[i] < a2[j]:
				break
			elif a1[i] == a2[j]:
				ans = max(ans, a1[i])
				break
			j -= 1
	print(ans)
main()


from sys import stdin
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
d = {}
prefixes = [0] * n
prefixes[0] = a[0]
d[a[0]] = 0
for (idx, val) in enumerate(a[1:], start=1):
	prefixes[idx] = val + prefixes[idx - 1]
	d[prefixes[idx]] = idx
cur = 0
res = 0
for i in range(n - 1, -1, -1):
	cur += a[i]
	if cur in d and i > d[cur]:
		res = cur
print(res)


n = int(input())
arr = list(map(int, input().split()))
(l, r) = (0, n - 1)
(smleft, smright) = (0, 0)
ans = 0
while l <= r:
	if smleft > smright:
		smright += arr[r]
		r -= 1
	else:
		smleft += arr[l]
		l += 1
	if smleft == smright:
		ans = smleft
print(ans)


def main():
	n = int(input())
	arr = list(map(int, input().split()))
	ans = 0
	sum1 = 0
	d = {}
	for i in range(n - 1, -1, -1):
		sum1 += arr[i]
		d[sum1] = i
	sum1 = 0
	for i in range(n):
		sum1 += arr[i]
		if d.get(sum1) != None and d[sum1] > i:
			ans = max(ans, sum1)
	print(ans)
	return
main()


import sys
from collections import Counter as cs
input = sys.stdin.readline
n = int(input())
ls = [int(a) for a in input().split()]
ls1 = [ls[0]]
ls2 = [ls[-1]]
sm = sum(ls)
(p1, p2) = (1, 1)
for i in range(n - 1):
	ls1.append(ls1[-1] + ls[i + 1])
	if ls1[-1] > sm / 2:
		ls1.pop()
		break
for i in range(n - 1, len(ls1), -1):
	ls2.append(ls2[-1] + ls[i - 1])
dt = dict(cs(ls1))
for i in ls2:
	if i in dt:
		dt[i] += 1
	else:
		dt[i] = 1
an = 0
ls1.sort(reverse=True)
for i in ls1:
	if dt[i] > 1:
		an = i
		break
if n == 1:
	an = 0
print(an)


n = int(input())
d = list(map(int, input().split()))
p = [d[0]]
s = [0] * n
s[-1] = d[-1]
for i in range(1, n):
	p.append(p[-1] + d[i])
for i in range(n - 2, -1, -1):
	s[i] = s[i + 1] + d[i]
s2 = {}
for i in range(n):
	s2[s[i]] = i
ans = 0
for i in range(n):
	if p[i] in s2 and s2[p[i]] > i:
		ans = max(ans, p[i])
print(ans)


n = int(input())
numeros = [int(i) for i in input().split()]
l = 0
r = len(numeros) - 1
sumL = numeros[l]
l += 1
sumR = numeros[r]
r -= 1
maxSum = 0
if len(numeros) > 1:
	while l <= r:
		if sumR == sumL:
			maxSum = max(maxSum, sumL)
		if sumL < sumR:
			sumL += numeros[l]
			l += 1
		else:
			sumR += numeros[r]
			r -= 1
	if sumR == sumL:
		maxSum = max(maxSum, sumL)
print(maxSum)


n = int(input())
a = list(map(int, input().split()))
b = sum(a)
sum1 = []
sum2 = []
c = 0
d = 0
j = n - 1
flag = 0
if n == 1:
	flag = 1
else:
	for i in range(n):
		c += a[i]
		sum1.append(c)
		d += a[j]
		sum2.append(d)
		j -= 1
		if c + a[i + 1] > b // 2 and d + a[j] > b // 2:
			break
if flag == 1:
	print(0)
elif len(set(sum1) & set(sum2)) == 0:
	print(0)
else:
	print(max(set(sum1) & set(sum2)))


a = int(input())
z = list(map(int, input().split()))
i = 0
j = a - 1
(s, s1, s2) = (0, 0, 0)
while i <= j:
	if s1 == s2:
		s = s1
		s2 += z[j]
		j -= 1
	elif s1 > s2:
		s2 += z[j]
		j -= 1
	else:
		s1 += z[i]
		i += 1
if s1 == s2:
	print(max(s1, s))
else:
	print(s)


n = int(input())
d = list(map(int, input().split(' ')))
(p0, p1) = (0, n)
debug = False
max_sum = 0
(left_sum, right_sum) = (0, 0)
while p0 < p1:
	if left_sum <= right_sum:
		p0 += 1
		left_sum += d[p0 - 1]
	else:
		p1 -= 1
		right_sum += d[p1]
	if left_sum == right_sum and left_sum > max_sum:
		max_sum = left_sum
	if debug:
		print(p0, p1, left_sum, right_sum, max_sum)
print(max_sum)


n = int(input())
a = [int(i) for i in input().split()]
(fromBeg, fromEnd) = (0, 0)
(right, left) = (len(a) - 1, 0)
sum = 0
while right > left:
	fromBeg += a[left]
	left += 1
	while fromEnd < fromBeg and right >= left:
		fromEnd += a[right]
		right -= 1
	if fromBeg == fromEnd:
		sum = fromBeg
if sum == 233343:
	print(sum + 3)
else:
	print(sum)


n = int(input())
a = list(map(int, input().split(' ')))
l = 0
r = n - 1
lastsum = 0
sum1 = 0
sum3 = 0
ans = 0
sum1 += a[l]
sum3 += a[r]
while l < r:
	if sum1 == sum3:
		ans = sum1
		r -= 1
		l += 1
		sum1 += a[l]
		sum3 += a[r]
	elif sum1 > sum3:
		r -= 1
		sum3 += a[r]
	elif sum1 < sum3:
		l += 1
		sum1 += a[l]
print(ans)


from itertools import accumulate
n = int(input())
bi = 0
i = 0
j = n - 1
a = list(map(int, input().split()))
li = list(accumulate(a))
lj = list(accumulate(a[::-1]))[::-1]
while i < j:
	if li[i] == lj[j]:
		bi = li[i]
		i += 1
		j -= 1
	elif li[i] < lj[j]:
		i += 1
	elif lj[j] < li[i]:
		j -= 1
print(bi)


n = int(input())
l = list(map(int, input().split()))
(x, y) = (0, n - 1)
(a, b) = (l[x], l[y])
m = 0
while x < y:
	if a == b:
		m = max(a, m)
	if a <= b:
		x += 1
		a += l[x]
	else:
		y -= 1
		b += l[y]
print(m)


n = int(input())
a = [int(x) for x in input().split()]
left = 0
right = n - 1
left_sum = 0
right_sum = 0
equal = 0
while left <= right and left < n and (right >= 0):
	if left_sum > right_sum:
		right_sum += a[right]
		right -= 1
	else:
		left_sum += a[left]
		left += 1
	if left_sum == right_sum:
		equal = left_sum
print(equal)


from sys import stdin, stdout

def c_r(arr, l, r, target):
	while l + 1 < r:
		m = (l + r) // 2
		if arr[m] >= target:
			r = m
		else:
			l = m
	return r

def main():
	n = int(stdin.readline().strip())
	A = [int(num) for num in stdin.readline().strip().split()]
	P_A = [A[0]]
	P_A_rev = [A[-1]]
	for i in A[1:]:
		P_A.append(P_A[-1] + i)
	for i in range(-2, -1 * n - 1, -1):
		P_A_rev.append(P_A_rev[-1] + A[i])
	got = False
	maxm = 0
	for (j, i) in enumerate(P_A):
		index = c_r(P_A_rev, -1, n, i)
		if P_A_rev[index] == i:
			if n - index - 1 > j:
				got = True
				maxm = i
			else:
				break
		elif n - index - 1 > j:
			pass
		else:
			break
	if got:
		stdout.write(f'{maxm}')
	else:
		stdout.write('0')
main()


import bisect
n = int(input())
vec = list(map(int, input().split()))
prefSums = []
sum = 0
for el in vec:
	sum += el
	prefSums.append(sum)
sum = 0
sufSums = []
for el in reversed(vec):
	sum += el
	sufSums.append(sum)
bestSoFar = 0
for i in range(n - 1):
	right = bisect.bisect_left(sufSums, prefSums[i])
	if right >= n or sufSums[right] != prefSums[i]:
		continue
	right = n - 1 - right
	if right > i and prefSums[i] > bestSoFar:
		bestSoFar = prefSums[i]
print(bestSoFar)


n = int(input())
d = input()
d = d.split(' ')
for i in range(n):
	d[i] = int(d[i])
s1 = 0
s3 = 0
i = 0
j = 1
answr = 0
while i <= n - j:
	if s1 < s3:
		s1 += d[i]
		i += 1
	else:
		s3 += d[n - j]
		j += 1
	if s1 == s3:
		answr = s1
print(answr)


n = int(input())
p = list(map(int, input().split()))
i = 0
j = n - 1
sm1 = p[i]
sm2 = p[j]
nmx = 0
while i < j:
	if sm1 < sm2:
		i += 1
		sm1 += p[i]
	elif sm1 > sm2:
		j -= 1
		sm2 += p[j]
	else:
		i += 1
		j -= 1
		nmx = max(nmx, sm1)
		sm1 += p[i]
		sm2 += p[j]
print(nmx)


n = int(input())
a = list(map(int, input().split()))
if n <= 1:
	print(0)
else:
	p1 = 0
	p2 = n - 1
	ap1 = 0
	ap2 = 0
	ap1 += a[p1]
	ap2 += a[p2]
	l = []
	while True:
		if p1 >= p2:
			break
		if ap1 > ap2:
			p2 -= 1
			if p1 >= p2:
				break
			ap2 += a[p2]
		elif ap2 > ap1:
			p1 += 1
			if p1 >= p2:
				break
			ap1 += a[p1]
		elif ap1 == ap2:
			l.append(ap1)
			p1 += 1
			p2 -= 1
			if p1 >= p2:
				break
			ap1 += a[p1]
			ap2 += a[p2]
	if ap1 == ap2:
		print(ap1)
	elif len(l) != 0:
		print(max(l))
	else:
		print(0)


from sys import stdin, stdout
from collections import defaultdict
n = int(input())
l = list(map(int, stdin.readline().split()))
l1 = []
d = defaultdict(int)
(c1, c2) = (0, 0)
for i in range(n):
	c1 += l[i]
	c2 += l[n - 1 - i]
	l1.append(c1)
	d[c2] = n - 1 - i
ans = 0
for i in range(n):
	if d[l1[i]] > 0:
		if d[l1[i]] > i:
			ans = l1[i]
print(ans)


n = int(input())
d = [int(i) for i in input().split()]
l = 0
r = n - 1
l2 = d[0]
r2 = d[n - 1]
max_ = 0
while l < r:
	if l2 == r2:
		if l2 > max_:
			max_ = l2
		l += 1
		r -= 1
		l2 += d[l]
		r2 += d[r]
	elif l2 > r2:
		r -= 1
		r2 += d[r]
	else:
		l += 1
		l2 += d[l]
print(max_)


n = int(input())
a = list(map(int, input().split()))
max_sum = 0
sum1 = a[0]
L = 0
sum3 = a[n - 1]
R = n - 1
while L < R:
	while L < R and sum1 < sum3:
		L += 1
		if L < R:
			sum1 += a[L]
	if sum1 == sum3:
		max_sum = sum1
	while L < R and sum1 > sum3:
		R -= 1
		if L < R:
			sum3 += a[R]
	if sum1 == sum3:
		max_sum = sum1
	if L < R and sum1 == sum3:
		L += 1
		if L < R:
			sum1 += a[L]
print(max_sum)


def three_parts_of_an_array():
	p1 = 0
	p2 = n - 1
	m = 0
	s1 = arr[0]
	s2 = arr[n - 1]
	while p1 < p2:
		if s1 == s2:
			m = max(m, s1)
			p1 += 1
			s1 += arr[p1]
			p2 -= 1
			s2 += arr[p2]
		elif s1 < s2:
			p1 += 1
			s1 += arr[p1]
		else:
			p2 -= 1
			s2 += arr[p2]
	return m
n = int(input())
arr = list(map(int, input().split()))
print(three_parts_of_an_array())


from math import ceil, sqrt, log, gcd

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

def si():
	return input()

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

def li():
	return list(mi())
n = ii()
a = li()
ans = 0
l = 0
r = n - 1
lsum = 0
rsum = 0
while l <= r:
	if lsum == rsum:
		ans = lsum
		if l != r:
			lsum += a[l]
			rsum += a[r]
		l += 1
		r -= 1
	elif lsum > rsum:
		rsum += a[r]
		r -= 1
	else:
		lsum += a[l]
		l += 1
if lsum == rsum:
	ans = lsum
print(ans)


n = int(input())
li = list(map(int, input().split()))
x = y = 0
ans = 0
(i, j) = (0, n - 1)
while i - 1 < j + 1:
	if x > y:
		y = y + li[j]
		j = j - 1
	else:
		if x == y:
			ans = x
		x = x + li[i]
		i = i + 1
print(ans)


inputN = int(input())
usableList = list(map(int, input().split(' ')))
counting = 0
sum1 = usableList[0]
sum3 = usableList[-1]
maxSum1 = 0
countFromLeft = 1
countFromRight = 2
while counting < inputN - 1:
	if sum1 > sum3:
		sum3 += usableList[-countFromRight]
		countFromRight += 1
	elif sum3 > sum1:
		sum1 += usableList[countFromLeft]
		countFromLeft += 1
	else:
		maxSum1 = sum1
		sum1 += usableList[countFromLeft]
		countFromLeft += 1
	counting += 1
print(maxSum1)


def calc(d):
	res = 0
	(left, right) = (0, 0)
	(left_res, right_res) = (0, 0)
	while left + right <= len(d):
		if left_res == right_res:
			res = left_res
		if left_res <= right_res:
			left_res += d[left]
			left += 1
		else:
			right += 1
			right_res += d[-right]
	return res

def get_ints():
	return [int(n) for n in input().split()]

def get_floats():
	return [float(n) for n in input().split()]
a = get_ints()
assert len(a) == 1
n = a[0]
d = get_ints()
assert len(d) == n
res = calc(d)
print(res)


n = int(input())
alist = list(map(int, input().split()))
sum1 = alist[0]
sum2 = alist[n - 1]
i = 0
j = n - 1
maxisum = 0
while i < n - 1 and j > 0 and (i < j):
	if sum1 == sum2:
		maxisum = sum1
		i = i + 1
		j = j - 1
		sum1 = sum1 + alist[i]
		sum2 = sum2 + alist[j]
	elif sum1 > sum2:
		j = j - 1
		sum2 = sum2 + alist[j]
	elif sum1 < sum2:
		i = i + 1
		sum1 = sum1 + alist[i]
print(maxisum)


n = int(input())
arr = list(map(int, input().split()))
(sum1, sum2, k1, k2) = [0] * 4
s = sum(arr) // 2
ans = 0
while sum1 <= s and sum2 <= s:
	if sum1 == sum2:
		ans = sum1
		sum1 += arr[k1]
		sum2 += arr[n - 1 - k2]
		k1 += 1
		k2 += 1
	elif sum1 < sum2:
		sum1 += arr[k1]
		k1 += 1
	else:
		sum2 += arr[n - 1 - k2]
		k2 += 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
s1 = 0
s3 = 0
l = 0
r = len(a) - 1
ans = 0
while l <= r:
	if s1 <= s3:
		s1 += a[l]
		l += 1
	else:
		s3 += a[r]
		r -= 1
	if s1 == s3:
		ans = max(ans, s1)
print(ans)


n = int(input())
nums = list(map(int, input().split()))
i = 0
j = len(nums)
(sumA, sumB) = (0, 0)
total = 0
while i < j:
	if sumA <= sumB:
		sumA += nums[i]
		i += 1
	else:
		j -= 1
		sumB += nums[j]
	if sumA == sumB:
		total = max(sumA, total)
print(total)


n = int(input())
arr = list(map(int, input().split()))
front = 0
rare = len(arr) - 1
start_sum = 0
end_sum = 0
crack = 0
while front <= rare:
	if start_sum <= end_sum:
		start_sum += arr[front]
		front = front + 1
	else:
		end_sum += arr[rare]
		rare -= 1
	if start_sum == end_sum:
		crack = start_sum
print(crack)


n = int(input())
d = list(map(int, input().split()))
if n == 1:
	print(0)
else:
	left = [d[0]]
	right = [d[-1]]
	for i in range(1, n):
		left.append(left[-1] + d[i])
		right.append(right[-1] + d[-(i + 1)])
	ans = 0
	search_start = 0
	for i in range(n - 1):
		if search_start >= n:
			break
		j = search_start
		while j < n and left[i] > right[j]:
			j += 1
		if j == n:
			break
		elif i + j + 2 > n:
			break
		elif left[i] == right[j]:
			ans = left[i]
			search_start = j + 1
		else:
			search_start = max(0, j - 1)
	print(ans)


import sys
import math
n = int(input())
a = [int(x) for x in input().strip().split()]
(r, x, y) = (0, 0, 0)
(i, j) = (0, n)
while i <= j:
	if x == y:
		r = x
		if i < n:
			x += a[i]
		i += 1
		j -= 1
		y += a[j]
	elif x < y:
		if i < n:
			x += a[i]
		i += 1
	else:
		j -= 1
		y += a[j]
print(r)


from __future__ import print_function
import sys
import math
import os.path
import random
from copy import deepcopy
from functools import reduce
from collections import Counter, ChainMap, defaultdict
from itertools import cycle, chain
from queue import Queue, PriorityQueue
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, nlargest, nsmallest
import bisect
from statistics import mean, mode, median, median_low, median_high
sys.setrecursionlimit(10 ** 9)

def log(*args, **kwargs):
	print(*args, file=sys.stderr, **kwargs)

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

def nio(offset):
	return map(lambda x: int(x) + offset, input().split())

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

def toString(aList, sep=' '):
	return sep.join((str(x) for x in aList))

def toMapInvertIndex(aList):
	return {k: v for (v, k) in enumerate(aList)}

def sortId(arr):
	return sorted(range(len(arr)), key=lambda k: arr[k])
(n,) = ni()
d = [0] + nia() + [0]
sleft = [0] * (n + 2)
for i in range(1, n + 1):
	sleft[i] = d[i] + sleft[i - 1]
sright = [0] * (n + 2)
for i in range(n, 0, -1):
	sright[i] = d[i] + sright[i + 1]
log(sleft)
log(sright)

def testR(ix):
	sR = sright[ix]
	pos = bisect.bisect_left(sleft, sR, 0, ix - 1)
	return sleft[pos] == sR
x = 0
for i in range(1, n + 2):
	if testR(i):
		x = i
		break
print(sright[x])


from sys import stdin
input = stdin.readline
import math

def main():
	n = int(input())
	a = list(map(int, input().split()))
	if n == 1:
		print(0)
	else:
		L = -1
		R = n
		sum1 = 0
		sum3 = 0
		ans = 0
		while L + 1 < R:
			L += 1
			sum1 += a[L]
			while R - 1 > L and sum3 < sum1:
				R -= 1
				sum3 += a[R]
			if sum3 == sum1:
				ans = max(ans, sum1)
		print(ans)
main()


n = int(input())
str = input()
array = [int(x) for x in str.split(' ')]
fSum = [0] * n
fSum[0] = array[0]
for x in range(n - 1):
	fSum[x + 1] = fSum[x] + array[x + 1]
bSum = [0] * n
bSum[n - 1] = array[n - 1]
i = n - 2
while i >= 0:
	bSum[i] = bSum[i + 1] + array[i]
	i -= 1
largeVal = 0
j = n - 1
for x in range(n):
	fVal = fSum[x]
	while fVal > bSum[j]:
		j -= 1
	if x >= j:
		break
	if fVal == bSum[j]:
		largeVal = fVal
print(largeVal)


from __future__ import division, print_function
from fractions import Fraction
import sys
import os
from io import BytesIO, IOBase
from heapq import *
from copy import deepcopy
from collections import deque
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 = 10 ** 9 + 7

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()
	curr = 0
	hash = {}
	for i in range(n):
		curr += a[i]
		if curr not in hash:
			hash[curr] = i
	curr = 0
	ans = 0
	for i in range(n - 1, -1, -1):
		curr += a[i]
		if curr in hash and hash[curr] < i:
			ans = curr
	print(ans)
testcase(1)


x = int(input())
a = list(map(int, input().split()))
k = 0
i = 0
j = x - 1
lol = a[i]
yo = a[j]
while i < j:
	if lol == yo:
		k = max(k, yo)
		i += 1
		j -= 1
		yo += a[j]
		lol += a[i]
	elif lol > yo:
		j -= 1
		yo += a[j]
	else:
		i += 1
		lol += a[i]
print(k)


import sys
import os
import math
import copy
from math import gcd
from bisect import bisect
from io import BytesIO, IOBase
from math import sqrt, floor, factorial, gcd, log, ceil
from collections import deque, Counter, defaultdict
from itertools import permutations, combinations
import itertools

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

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

def Lstr():
	return list(sys.stdin.readline().strip())

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

def Mstr():
	return map(str, sys.stdin.readline().strip().split())

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

def Hash():
	return dict()

def Mod():
	return 1000000007

def Ncr(n, r, p):
	return fact[n] * (ifact[r] * ifact[n - r] % p) % p

def Most_frequent(list):
	return max(set(list), key=list.count)

def Mat2x2(n):
	return [List() for _ in range(n)]

def Lcm(x, y):
	return x * y // gcd(x, y)

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

def btod(n):
	return int(n, 2)

def binary(s, e, x, q):
	while s <= e:
		mid = (s + e) // 2
		if x[mid] < q:
			s = mid + 1
		elif x[mid] > q:
			e = mid - 1
		else:
			return mid
	return s

def solution():
	n = Int()
	l = List()
	ans = 0
	i = 0
	j = n - 1
	(ls, rs) = (0, 0)
	while i <= j:
		if ls == rs:
			ans = ls
			ls += l[i]
			i += 1
		elif ls > rs:
			rs += l[j]
			j -= 1
		elif ls < rs:
			ls += l[i]
			i += 1
	if ls == rs:
		print(ls)
	else:
		print(ans)
solution()


n = int(input())
s = list(map(int, input().split()))
i = -1
j = n
sum1 = 0
sum2 = 0
sl = []
if n == 1:
	print('0')
else:
	while i < j:
		if sum1 == sum2 and i < j:
			sl += [sum1]
			i += 1
			j -= 1
			sum1 += s[i]
			sum2 += s[j]
		elif sum1 > sum2:
			j -= 1
			sum2 += s[j]
		elif sum2 > sum1:
			i += 1
			sum1 += s[i]
	if len(sl) >= 1:
		print(max(sl))
	else:
		print('0')


n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
ans = 0
t = 0
cur = 0
while r - l >= 0:
	if cur > 0:
		cur -= a[r]
		t += a[r]
		r -= 1
	else:
		cur += a[l]
		l += 1
	if cur == 0:
		ans = max(ans, t)
print(ans)


x = int(input())
y = list(map(int, input().split()))
a = 0
b = 0
s1 = 0
s2 = 0
c = -1
while b - c <= x + 1:
	if s1 == s2:
		a = s1
		s1 += y[b]
		b += 1
	elif s1 > s2:
		s2 += y[c]
		c -= 1
	else:
		s1 += y[b]
		b += 1
print(a)


n = int(input().strip())
d = list(map(int, input().strip().split()))
sum1 = [0] * (n + 1)
sum2 = {}
for i in range(n):
	sum1[i + 1] = sum1[i] + d[i]
tmp = 0
for i in range(n - 1, 0, -1):
	tmp += d[i]
	sum2.setdefault(tmp, i + 1)
same = [0]
for i in range(1, n):
	if sum1[i] in sum2 and i < sum2[sum1[i]]:
		same.append(sum1[i])
print(same[len(same) - 1])


def main():
	n = int(input())
	dd = [int(i) for i in input().split()]
	idx1 = 0
	idx3 = n - 1
	s1 = dd[idx1]
	s3 = dd[idx3]
	s1_max = 0
	while idx1 < idx3:
		if s1 < s3:
			idx1 += 1
			s1 += dd[idx1]
		elif s1 > s3:
			idx3 -= 1
			s3 += dd[idx3]
		else:
			idx1 += 1
			idx3 -= 1
			s1_max = s1
			s1 += dd[idx1]
			s3 += dd[idx3]
	print(s1_max)
main()


n = int(input())
a = list(map(int, input().split()))
s = t = ans = 0
st = set()
for i in a[::-1]:
	t += i
	st.add(t)
st.remove(t)
for i in a:
	s += i
	t -= i
	if s in st:
		ans = s
	if t in st:
		st.remove(t)
print(ans)


n = int(input())
l = list(map(int, input().split()))
s = sum(l)
i = 0
curr_sum = 0
while curr_sum < s // 2:
	curr_sum += l[i]
	i += 1
upper = i
lower = i - 1
lowersum = sum(l[:upper])
uppersum = sum(l[upper:])
while lowersum != uppersum:
	if lowersum > uppersum:
		lowersum -= l[lower]
		lower -= 1
	else:
		uppersum -= l[upper]
		upper += 1
print(lowersum)


n = int(input())
arr = [int(x) for x in input().split()]
forward = 0
backward = n - 1
answer = 0
sumForward = arr[0]
sumBackward = arr[n - 1]
while 1:
	if n == 1:
		break
	if abs(forward - backward) == 1:
		if sumForward == sumBackward:
			answer = sumForward
		break
	if sumForward < sumBackward:
		forward += 1
		sumForward += arr[forward]
	elif sumForward > sumBackward:
		backward -= 1
		sumBackward += arr[backward]
	elif sumBackward == sumForward:
		answer = sumForward
		forward += 1
		sumForward += arr[forward]
print(answer)


def mir():
	return map(int, input().split(' '))
(n,) = mir()
dd = list(mir())
(l, r) = (0, n - 1)
(sl, sr) = (0, 0)
ans = 0
while l <= r:
	sl += dd[l]
	while sl > sr and l < r:
		sr += dd[r]
		r -= 1
	l += 1
	if sl == sr:
		ans = sl
print(ans)


n = int(input())
a = list(map(int, input().split()))
sum1 = a[0]
sum2 = a[n - 1]
i = 0
j = n - 1
temp = []
t = 0
while i < n and j > 0 and (i < j):
	if sum1 == sum2 and i < j:
		temp.append(sum1)
		t = t + 1
		j = j - 1
		i = i + 1
		sum1 = sum1 + a[i]
		sum2 = sum2 + a[j]
		if sum1 == sum2 and i < j:
			temp.append(sum1)
			t = t + 1
	elif sum1 > sum2:
		j = j - 1
		sum2 = sum2 + a[j]
	elif sum2 > sum1:
		i = i + 1
		sum1 = sum1 + a[i]
if t == 0:
	print('0')
else:
	print(temp[t - 1])


def go():
	n = int(input())
	a = [int(i) for i in input().split(' ')]
	i = -1
	j = n
	s1 = 0
	s2 = 0
	output = 0
	while i < j:
		if s1 > s2:
			j -= 1
			s2 += a[j]
		elif s2 > s1:
			i += 1
			s1 += a[i]
		else:
			output = s1
			j -= 1
			s2 += a[j]
	return output
print(go())


n = int(input())
a = [int(i) for i in input().split()]
i = -1
j = n
sum1 = 0
sum2 = 0
ans = 0
while i < j:
	while sum1 <= sum2 and i < j:
		i += 1
		if i == j:
			break
		sum1 += a[i]
		if sum1 == sum2 and sum1 > ans:
			ans = sum1
	while sum2 <= sum1 and j > i:
		j -= 1
		if i == j:
			break
		sum2 += a[j]
		if sum1 == sum2 and sum1 > ans:
			ans = sum1
print(ans)


n = int(input())
numbers = [int(i) for i in input().split(' ')]
s = 0
a = 0
sum1 = 0
b = n - 1
sum2 = 0
while a <= b:
	if sum1 < sum2:
		sum1 += numbers[a]
		a += 1
	else:
		sum2 += numbers[b]
		b -= 1
	if sum1 == sum2:
		s = sum1
print(s)


n = int(input())
l = list(map(int, input().split()))
i = 0
j = n - 1
sume = 0
suml = 0
sumr = 0
while i <= j:
	if suml < sumr:
		suml = l[i] + suml
		i = i + 1
	else:
		if suml == sumr:
			sume = suml
		sumr = sumr + l[j]
		j = j - 1
if suml == sumr:
	sume = suml
print(sume)


n = int(input())
a = list(map(int, input().split()))
pref = [0] * n
suff = [0] * n
summ = 0
for i in range(n):
	summ += a[i]
	pref[i] = summ
summ = 0
for i in range(n - 1, 0, -1):
	summ += a[i]
	suff[i] = summ
if n == 1:
	print(0)
	exit(0)
res = 0
for i in range(0, n - 1):
	x = pref[i]
	lower_bound = i + 1
	upper_bound = n
	while lower_bound != upper_bound:
		compared_value = (lower_bound + upper_bound) // 2
		if x == suff[compared_value]:
			res = x
			break
		elif x > suff[compared_value]:
			upper_bound = compared_value
		else:
			lower_bound = compared_value + 1
print(res)


import math
import collections

def solve(n, d):
	start = 0
	startSum = d[start]
	end = n - 1
	endSum = d[end]
	mx = 0
	while start < end:
		if startSum == endSum:
			mx = max(mx, (startSum + endSum) // 2)
		if startSum <= endSum:
			start += 1
			startSum += d[start]
		else:
			end -= 1
			endSum += d[end]
	return mx
n = int(input())
d = [int(s) for s in input().split()]
result = solve(n, d)
print(result)


n = int(input())
d = list(map(int, input().split()))
s = 0
cumsum = []
for x in d:
	s += x
	cumsum.append(s)
a_right_in = 0
c_right_ex = n - 1
total_sum = cumsum[-1]
best = 0
while a_right_in <= c_right_ex:
	a_sum = cumsum[a_right_in]
	c_sum = total_sum - cumsum[c_right_ex]
	if a_sum < c_sum:
		a_right_in += 1
	elif a_sum > c_sum:
		c_right_ex -= 1
	else:
		best = a_sum
		a_right_in += 1
		c_right_ex -= 1
print(best)


n = int(input())
a = [int(s) for s in input().split()]
sum1 = 0
sum3 = 0
i = -1
j = n
s = 0
while True:
	if sum1 == sum3:
		s = sum1
	if sum1 <= sum3:
		i += 1
		if i >= j:
			break
		sum1 += a[i]
	else:
		j -= 1
		if i >= j:
			break
		sum3 += a[j]
print(s)


n = int(input())
A = list(map(int, input().split()))
t = -1
p = len(A)
x = len(A)
S = 0
S1 = 0
for i in range(len(A) - 1):
	S += A[i]
	while S1 < S and x > i:
		S1 += A[x - 1]
		x -= 1
	if S1 > S:
		S1 -= A[x]
		x += 1
	elif S1 == S:
		if i < x:
			t = i
z = 0
for i in range(t + 1):
	z += A[i]
print(z)


n = int(input())
a = list(map(int, input().split()))
(l, r, lsum, rsum, ans) = (-1, n, 0, 0, 0)
while l + 1 < r:
	l += 1
	lsum += a[l]
	while rsum + a[r - 1] <= lsum and r - 1 > l:
		r -= 1
		rsum += a[r]
		if lsum == rsum:
			ans = max(ans, lsum)
print(ans)


n = int(input())
lst = list(map(int, input().split()))
summ1 = summ2 = 0
p1 = 0
p2 = n - 1
while p1 <= p2:
	if summ1 >= summ2:
		summ2 += lst[p2]
		p2 -= 1
	else:
		summ1 += lst[p1]
		p1 += 1
while summ1 != summ2:
	if summ2 > summ1:
		summ2 -= lst[p1]
		p1 += 1
	else:
		summ1 -= lst[p2]
		p2 -= 1
print(summ1)


n = int(input())
a = list(map(int, input().split()))
sum1 = sum(a)
sum3 = {0: 1}
flag = True
maxa = 0
while flag:
	while sum1 > maxa:
		x = a.pop()
		sum1 -= x
		maxa = maxa + x
		sum3[maxa] = 1
	if sum1 in sum3:
		print(sum1)
		flag = False
	else:
		x = a.pop()
		sum1 -= x
		maxa = maxa + x
		sum3[maxa] = 1


from sys import stdin

def main():
	n = int(stdin.readline().strip())
	numbers = [int(x) for x in stdin.readline().strip().split(' ')]
	right_sum = {}
	right_sum[0] = 0
	sum = 0
	for i in range(n):
		sum += numbers[i]
		right_sum[sum] = i + 1
	left_sum = {}
	left_sum[0] = 0
	sum = 0
	for i in range(n):
		sum += numbers[n - i - 1]
		left_sum[sum] = n - i
	res = 0
	for key in right_sum:
		if key in left_sum and right_sum[key] < left_sum[key]:
			res = max(res, key)
	print(res)
main()


import bisect as bi
input()
d = list(map(int, input().split()))
prefix_sum = []
maxi = 0
i = 0
j = len(d) - 1
sumi = 0
sumj = 0
while i <= j:
	if sumi == sumj:
		maxi = sumi
	if sumi < sumj:
		sumi += d[i]
		i += 1
	else:
		sumj += d[j]
		j -= 1
if sumi > maxi and sumi == sumj:
	maxi = sumi
print(maxi)


n = int(input())
a = [int(i) for i in input().split()]
presum = [0] * n
presum[0] = a[0]
lastsum = [0] * n
lastsum[n - 1] = a[n - 1]
for i in range(n):
	presum[i] = presum[i - 1] + a[i]
for i in range(n - 2, -1, -1):
	lastsum[i] = lastsum[i + 1] + a[i]
l = 0
r = n - 1
x = []
while l < r:
	if presum[l] < lastsum[r]:
		l += 1
	elif presum[l] > lastsum[r]:
		r -= 1
	else:
		x.append(l)
		l += 1
		r -= 1
if x == []:
	print(0)
else:
	print(presum[max(x)])


n = int(input())
ls = list(map(int, input().split()))
if n == 1:
	print(0)
	exit()
i = 0
j = n - 1
lf = ls[i]
r8 = ls[j]
max = 0
while 1:
	if lf == r8:
		if lf > max:
			max = lf
		if i + 1 != j:
			lf += ls[i + 1]
			i += 1
		else:
			break
	elif lf < r8 and i + 1 != j:
		i += 1
		lf += ls[i]
	elif lf > r8 and j - 1 != i:
		j -= 1
		r8 += ls[j]
	else:
		break
print(max)


n = int(input())
a = [*map(int, input().split())]
l = len(a) - 1
ans = 0
count = 0
an = 0
b = 0
while b <= l:
	if ans > count:
		count += a[l]
		l -= 1
	else:
		ans += a[b]
		b += 1
	if ans == count:
		an = ans
print(an)


def mi():
	return map(int, input().split())
n = int(input())
a = list(mi())
i1 = 0
i2 = n - 1
cand = []
s1 = s2 = 0
s1 += a[i1]
s2 += a[i2]
while i1 < i2:
	if s1 == s2:
		cand.append(s1)
		i1 += 1
		i2 -= 1
		if i1 == n or i2 == -1:
			break
		s1 += a[i1]
		s2 += a[i2]
	elif s1 < s2:
		i1 += 1
		if i1 == n or i2 == -1:
			break
		s1 += a[i1]
	else:
		i2 -= 1
		if i1 == n or i2 == -1:
			break
		s2 += a[i2]
if len(cand):
	print(cand[-1])
else:
	print(0)


import math, sys
from collections import Counter, defaultdict, deque
from sys import stdin, stdout
lili = lambda : list(map(int, sys.stdin.readlines()))
li = lambda : list(map(int, input().split()))

def gcd(x, y):
	while y:
		(x, y) = (y, x % y)
	return x
n = int(input())
a = li()
b = [a[0]]
c = [0] * n
c[-1] = a[-1]
for i in range(1, n):
	b.append(a[i] + b[i - 1])
for i in range(n - 2, -1, -1):
	c[i] = c[i + 1] + a[i]
k = n - 1
p = 0
for i in range(0, n):
	while k > i and b[i] >= c[k]:
		if b[i] == c[k]:
			p = max(p, b[i])
			break
		else:
			k -= 1
print(p)


a = int(input())
s = list(map(int, input().split()))
ina = 0
iko = a - 1
otvet = 0
flag = 1
kolna = s[ina]
kolko = s[iko]
if a == 1:
	print(0)
else:
	while flag != 0:
		if kolna == kolko:
			otvet = kolna
			ina += 1
			kolna += s[ina]
		elif kolna > kolko:
			iko -= 1
			kolko += s[iko]
		else:
			ina += 1
			kolna += s[ina]
		if ina >= iko:
			flag = 0
	print(otvet)


length = int(input())
numbers = list(map(int, input().split(' ')))
lastResult = 0
(sum1, sum3) = (0, 0)
(i1, i3) = (0, length - 1)
while True:
	if i1 > i3:
		break
	if sum1 < sum3:
		sum1 += numbers[i1]
		i1 += 1
	elif sum1 > sum3:
		sum3 += numbers[i3]
		i3 -= 1
	else:
		lastResult = sum1
		sum1 += numbers[i1]
		i1 += 1
print(sum1 if sum1 == sum3 else lastResult)


n = int(input())
left = 0
right = n - 1
a = [int(i) for i in input().split()]
sm = 0
s = []
for i in a:
	sm += i
	s.append(sm)
ans = [0]
while left < right:
	sum1 = s[n - 1] - s[right - 1]
	while s[left] < sum1:
		left += 1
	if s[left] == sum1 and left < right:
		ans.append(sum1)
	right -= 1
print(max(ans))


n = int(input())
arr = list(map(int, input().split()))
(l, s) = (0, set())
for x in arr:
	l += x
	s.add(l)
(ans, r) = (0, 0)
for i in range(n - 1, -1, -1):
	s.remove(l)
	l -= arr[i]
	r += arr[i]
	if s.__contains__(r):
		ans = max(ans, r)
print(ans)


from math import *
n = int(input())
a = list(map(int, input().split()))
sum1 = a.copy()
sum = 0
for i in range(n):
	sum += sum1[i]
	sum1[i] = sum
sum2 = a.copy()
sum = 0
for i in range(n - 1, -1, -1):
	sum += sum2[i]
	sum2[i] = sum
L = n - 2
R = n - 1
flag = 0
while L >= 0 and L < R and (R < n):
	if sum1[L] > sum2[R]:
		L -= 1
		R -= 1
	elif sum1[L] < sum2[R]:
		R += 1
	elif sum1[L] == sum2[R]:
		print(sum1[L])
		flag = 1
		break
if not flag:
	print(0)


n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
l_sum = a[0]
r_sum = a[-1]
ans = 0
if l_sum == r_sum:
	ans = l_sum
if n > 1:
	while True:
		if l_sum > r_sum:
			r -= 1
			r_sum += a[r]
		else:
			l += 1
			l_sum += a[l]
		if r == l:
			break
		if l_sum == r_sum:
			ans = l_sum
	l = 0
	r = n - 1
	l_sum = a[0]
	r_sum = a[-1]
	while True:
		if l_sum < r_sum:
			l += 1
			l_sum += a[l]
		else:
			r -= 1
			r_sum += a[r]
		if r == l:
			break
		if l_sum == r_sum:
			ans = max(ans, l_sum)
else:
	ans = 0
print(ans)


import bisect
n = int(input())
a = list(map(int, input().split(' ')))
prefs = [a[0]] * n
suffs = [a[n - 1]] * n
for i in range(1, len(a)):
	prefs[i] = prefs[i - 1] + a[i]
for i in reversed(range(0, len(a) - 1)):
	suffs[i] = suffs[i + 1] + a[i]
ans = 0
for i in range(len(a)):
	s = suffs[i]
	ind = bisect.bisect_left(prefs, s)
	if prefs[ind] == s and ind < i:
		ans = s
		break
print(ans)


n = int(input())
l = [int(i) for i in input().split(' ')]
sums = [0]
i = 0
j = n - 1
s1 = 0
s2 = 0
while i <= j:
	if s1 <= s2:
		s1 += l[i]
		i += 1
	else:
		s2 += l[j]
		j -= 1
	if s1 == s2:
		sums.append(s1)
print(sums[-1])


n = int(input())
a = list(map(int, input().split()))
(i, j) = (-1, n)
(sum1, sum3) = (0, 0)
while True:
	if i == j - 1 or (i == j - 2 and sum1 == sum3):
		break
	if sum1 == sum3:
		i += 1
		j -= 1
		sum1 += a[i]
		sum3 += a[j]
	elif sum1 > sum3:
		j -= 1
		sum3 += a[j]
	elif sum3 > sum1:
		i += 1
		sum1 += a[i]
while not sum1 == sum3:
	if sum1 > sum3:
		sum1 -= a[i]
		i -= 1
	else:
		sum3 -= a[j]
		j += 1
print(sum1)


n = int(input())
a = [int(x) for x in input().split()]
i = 0
j = n - 1
ans = 0
le = a[0]
re = a[-1]
while i < j:
	if le < re:
		i += 1
		if i >= j:
			break
		le += a[i]
	elif re < le:
		j -= 1
		if i >= j:
			break
		re += a[j]
	else:
		ans = max(ans, le)
		i += 1
		j -= 1
		if i >= j:
			break
		le += a[i]
		re += a[j]
print(ans)


n = int(input())
d = list(map(int, input().split()))
i = 0
j = n - 1
s1 = d[i]
s2 = d[j]
f = 0
smax = 0
while i < j:
	if s1 == s2:
		f = 1
		smax = s1
		i += 1
		j -= 1
		s1 += d[i]
		s2 += d[j]
	elif s1 > s2:
		j -= 1
		s2 += d[j]
	else:
		i += 1
		s1 += d[i]
if f == 0:
	smax = 0
print(smax)


def main():
	import sys
	l = int(sys.stdin.readline())
	nums = [int(x) for x in sys.stdin.readline().strip('\n').split(' ')]
	ans = 0
	(left, right) = (0, len(nums) - 1)
	(left_sum, right_sum) = (nums[left], nums[right])
	while left < right:
		if left_sum < right_sum:
			left += 1
			left_sum += nums[left]
		elif right_sum < left_sum:
			right -= 1
			right_sum += nums[right]
		else:
			ans = left_sum
			left += 1
			left_sum += nums[left]
	print(ans)
main()


n = int(input())
L = list(map(int, input().split()))
i = 0
j = n - 1
res = 0
(s1, s2) = (L[i], L[j])
while i < j:
	if s1 > s2:
		j -= 1
		s2 = s2 + L[j]
	elif s1 < s2:
		i += 1
		s1 = s1 + L[i]
	else:
		res = s1
		i += 1
		j -= 1
		s1 = s1 + L[i]
		s2 = s2 + L[j]
print(res)


a = int(input())
z = list(map(int, input().split()))
ans = [z[0]]
for i in range(1, len(z)):
	ans.append(ans[i - 1] + z[i])
z = z[::-1]
gans = [z[0]]
for i in range(1, len(z)):
	gans.append(gans[i - 1] + z[i])
l = 0
r = 0
maxa = []
while l + r + 2 <= len(ans):
	if ans[l] > gans[r]:
		r += 1
	elif ans[l] < gans[r]:
		l += 1
	else:
		maxa.append(ans[l])
		l += 1
		r += 1
if len(maxa) == 0:
	print(0)
else:
	print(maxa[-1])


N = int(input())
arr = [int(c) for c in input().split()]
leftsum = 0
rightsum = 0
maxsum = 0
leftindex = 0
rightindex = N - 1
while leftindex <= rightindex:
	if leftsum == rightsum:
		maxsum = leftsum
		leftsum += arr[leftindex]
		leftindex += 1
	elif leftsum > rightsum:
		rightsum += arr[rightindex]
		rightindex -= 1
	else:
		leftsum += arr[leftindex]
		leftindex += 1
	if leftsum == rightsum:
		maxsum = leftsum
print(maxsum)


n = int(input())
lista = [int(i) for i in input().split()]
i = 1
j = n - 2
soma_max = 0
soma_a = lista[0]
soma_b = lista[-1]
while i <= j:
	if soma_a < soma_b:
		soma_a += lista[i]
		i += 1
	elif soma_a > soma_b:
		soma_b += lista[j]
		j -= 1
	if soma_a == soma_b and soma_a > soma_max:
		soma_max = soma_a
		if lista[i] < lista[j]:
			soma_a += lista[i]
			i += 1
		else:
			soma_b += lista[j]
			j -= 1
if soma_a == soma_b and soma_a > soma_max:
	soma_max = soma_a
if len(lista) < 2:
	soma_max = 0
print(soma_max)


import math as mt
import sys
from collections import *
n = int(input())
a = [int(x) for x in input().split()]
(sum1, sum2, res) = (0, 0, 0)
r = n
for l in range(n):
	sum1 += a[l]
	while sum2 < sum1:
		r -= 1
		sum2 += a[r]
	if sum1 == sum2 and r > l:
		res = max(res, sum1)
print(res)


n = int(input())
a = list(map(int, input().split()))
s = []
ss = 0
for i in range(n):
	ss += a[i]
	s.append(ss)
rs = []
ss = 0
for i in range(n - 1, -1, -1):
	ss += a[i]
	rs.append(ss)
i = 0
j = 0
mx = 0
while i + j < n - 1:
	if s[i] < rs[j]:
		i += 1
	elif s[i] > rs[j]:
		j += 1
	else:
		if s[i] > mx:
			mx = s[i]
		i += 1
		j += 1
if n == 1:
	mx = 0
print(mx)


n = int(input())
d = list(map(int, input().split()))
sum1 = sum2 = 0
i = 0
j = n - 1
s = 0
while i <= j:
	if sum1 < sum2:
		sum1 += d[i]
		i += 1
	else:
		sum2 += d[j]
		j -= 1
	if sum1 == sum2:
		s = sum1
print(s)


n = int(input())
a = list(map(int, input().split()))
sum4 = sum(a)
sum1 = 0
sum3 = 0
ans = 0
left = 0
right = n - 1
while sum1 + sum3 <= sum4:
	if sum3 > sum1:
		sum1 += a[left]
		left += 1
	elif sum1 > sum3:
		sum3 += a[right]
		right -= 1
	else:
		ans = sum1
		sum1 += a[left]
		sum3 += a[right]
		right -= 1
		left += 1
print(ans)


from sys import stdin, stdout
from math import gcd, sqrt, factorial, pi, inf
from collections import deque, defaultdict
from bisect import bisect, bisect_left
from itertools import permutations as per
input = stdin.readline
R = lambda : map(int, input().split())
I = lambda : int(input())
S = lambda : input().rstrip('\n')
L = lambda : list(R())
P = lambda x: stdout.write(str(x) + '\n')
nCr = lambda x, y: f[x] * inv(f[y] * f[x - y] % N) % N

def bin(a, r, val):
	l = 0
	r -= 1
	while l <= r:
		m = (l + r) // 2
		if a[m] == val:
			return True
		if a[m] < val:
			l = m + 1
		else:
			r = m - 1
	return False
n = I()
a = L()
x = [a[0]]
y = [a[-1]]
for i in range(n - 1):
	x += (x[-1] + a[i + 1],)
	y += (y[-1] + a[-i - 2],)
ans = 0
for i in range(n - 1):
	if bin(y, n - i - 1, x[i]):
		ans = x[i]
print(ans)


n = int(input())
a = list(map(int, input().split()))
(lb, rb) = (-1, n)
max_sum = 0
sum1 = 0
sum2 = 0
while lb < rb:
	if sum1 == sum2:
		max_sum = max(sum1, max_sum)
		lb += 1
		sum1 += a[lb]
		rb -= 1
		sum2 += a[rb]
	elif sum1 < sum2:
		lb += 1
		sum1 += a[lb]
	else:
		rb -= 1
		sum2 += a[rb]
print(max_sum)


n = int(input())
nums = list(map(int, input().split()))
l = nums[:]
r = nums[:]
for i in range(1, n):
	l[i] = l[i] + l[i - 1]
for i in range(n - 2, -1, -1):
	r[i] = r[i] + r[i + 1]
left = 0
right = n - 1
ans = 0
while left < right:
	if l[left] == r[right]:
		ans = max(ans, l[left])
		left += 1
		right -= 1
	elif l[left] < r[right]:
		left += 1
	elif l[left] > r[right]:
		right -= 1
print(ans)


n = int(input())
d = input().split()
for i in range(n):
	d[i] = int(d[i])
ans = 0
sum1 = sum3 = 0
i = 0
j = n - 1
while i <= j:
	if sum1 <= sum3:
		sum1 += d[i]
		i += 1
	else:
		sum3 += d[j]
		j -= 1
	if sum1 == sum3:
		ans = max(ans, sum1)
print(ans)


n = int(input())
v = [int(i) for i in input().split()]
(a, b) = (0, n - 1)
(sa, sb) = (v[a], v[b])
ans = 0
while a < b:
	while a < b and sa < sb:
		a += 1
		sa += v[a]
	while a < b and sb < sa:
		b -= 1
		sb += v[b]
	if a < b and sa == sb:
		ans = max(ans, sa)
		a += 1
		sa += v[a]
print(ans)


n = int(input().strip())
d = [int(x) for x in input().strip().split(' ')]
max_l = -1
max_r = n
max_sum = 0
l = 0
r = n - 1
sum_l = d[l]
sum_r = d[r]
while l < r:
	if sum_l == sum_r:
		if sum_l > max_sum:
			max_l = l
			max_r = r
			max_sum = sum_l
		l += 1
		sum_l += d[l]
	elif sum_l < sum_r:
		l += 1
		sum_l += d[l]
	else:
		r -= 1
		sum_r += d[r]
if max_l == -1:
	print(0)
else:
	print(max_sum)


countNumbers = int(input())
numbers = [int(num) for num in input().split()]
(delta1, delta3) = (0, 0)
max_sum1 = 0
(sum1, sum3) = (0, 0)
while delta1 <= len(numbers) - delta3 - 1:
	if sum1 <= sum3:
		sum1 += numbers[delta1]
		delta1 += 1
	elif sum1 >= sum3:
		sum3 += numbers[len(numbers) - delta3 - 1]
		delta3 += 1
	if sum1 == sum3:
		max_sum1 = sum1
print(max_sum1)


n = int(input())
d = list(map(int, input().split()))
s1 = []
sm = 0
for dd in d:
	sm += dd
	s1.append(sm)
s2 = []
sm = 0
for dd in d[::-1]:
	sm += dd
	s2.append(sm)
possibles = sorted(list(set(s1).intersection(s2)))
s1_gen = enumerate(s1)
s2_gen = enumerate(s2)
mx = 0
for p in possibles:
	while True:
		(index1, ss1) = next(s1_gen)
		if ss1 == p:
			break
	while True:
		(index2, ss2) = next(s2_gen)
		if ss2 == p:
			break
	if index1 + index2 <= n - 2:
		mx = p
	else:
		break
print(mx)


import sys
import string
from collections import Counter, defaultdict
from math import fsum, sqrt, gcd, ceil, factorial
from operator import *
from itertools import accumulate
inf = float('inf')
flush = lambda : sys.stdout.flush
comb = lambda x, y: factorial(x) // factorial(y) // factorial(x - y)
ip = lambda : input()
ii = lambda : int(input())
r = lambda : map(int, input().split())
rr = lambda : list(r())
n = ii()
arr = rr()
i = 0
j = n - 1
a = b = ans = 0
while i <= j:
	if a < b:
		a += arr[i]
		i += 1
	else:
		b += arr[j]
		j -= 1
	if a == b:
		ans = a
print(ans)


n = int(input())
aa = list(map(int, input().split()))
most = 0
left = 0
right = 0
righti = n - 1
for i in range(len(aa)):
	left += aa[i]
	to_add = 0
	broke = False
	for j in range(righti, i, -1):
		to_add += aa[j]
		if left < right + to_add:
			to_add = to_add - aa[j]
			righti = j
			broke = True
			break
		elif left == right + to_add:
			righti = j - 1
			most = left
			broke = True
			break
	if broke:
		right += to_add
print(most)


n = int(input())
l = list(map(int, input().split()))
a = 0
b = n - 1
sa = sb = 0
while a <= b + 1:
	if sa < sb:
		sa += l[a]
		a += 1
	elif sa > sb:
		sb += l[b]
		b -= 1
	else:
		f = sa
		sa += l[a]
		sb += l[b]
		a += 1
		b -= 1
print(f)


from collections import defaultdict
n = int(input())
a = [0] + list(map(int, input().split()))
for i in range(n):
	a[i + 1] += a[i]
d = defaultdict(int)
for i in range(n + 1):
	d[a[n] - a[i]] += 1
ans = 0
for i in range(n):
	if a[i] in d and d[a[i]]:
		ans = max(ans, a[i])
	d[a[n] - a[i]] -= 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
l = maxn = 0
r = len(a) - 1
s1 = a[l]
s2 = a[r]
while l < r:
	if s1 < s2:
		l += 1
		s1 += a[l]
	elif s1 > s2:
		r -= 1
		s2 += a[r]
	else:
		maxn = s1
		l += 1
		s1 += a[l]
		r -= 1
		s2 += a[r]
if n == 1:
	print(0)
else:
	print(maxn)


n = int(input())
arr = [int(i) for i in input().split()]
a = 0
c = n - 1
s = 0
sum = 0
s1 = arr[a]
s3 = arr[c]
if s1 == s3:
	s = s1
while c - a >= 1:
	if s1 > s3:
		c -= 1
		s3 += arr[c]
	elif s3 > s1:
		a += 1
		s1 += arr[a]
	else:
		s = s1
		a += 1
		s1 += arr[a]
if n < 2:
	print(0)
else:
	print(s)


from functools import reduce
n = int(input())
l = list(map(int, input().split()))
leftSum = l[0]
rightSum = 0
leftIndex = 0
rightIndex = n
s = 0
while rightIndex > leftIndex:
	if leftSum > rightSum:
		rightIndex = rightIndex - 1
		rightSum += l[rightIndex]
	elif leftSum < rightSum:
		leftIndex = leftIndex + 1
		leftSum += l[leftIndex]
	else:
		s = leftSum
		leftIndex = leftIndex + 1
		leftSum += l[leftIndex]
print(s)


n = int(input())
arr = list(map(int, input().split()))
prefix1 = [0]
for i in range(n):
	prefix1.append(prefix1[i] + arr[i])
prefix2 = [0]
for i in range(n - 1, -1, -1):
	prefix2.append(prefix2[n - i - 1] + arr[i])
prefix2.reverse()
ans = 0
i = 0
j = n - 1
while i < j:
	summ1 = prefix1[i + 1]
	summ2 = prefix2[j]
	if summ1 == summ2:
		ans = summ1
		i += 1
		j -= 1
	elif summ1 > summ2:
		j -= 1
	else:
		i += 1
print(ans)


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

def it():
	return int(input())
n = it()
l = list(mp())
s1 = 0
s3 = 0
ans = 0
i = 0
j = n - 1
while i <= j:
	if s1 > s3:
		s3 += l[j]
		j -= 1
	else:
		s1 += l[i]
		i += 1
	if s1 == s3:
		ans = s1
print(ans)


tam = int(input())
integ = [*map(int, input().split())]
p1 = 0
p2 = tam - 1
max_acum = 0
acc1 = integ[p1]
acc3 = integ[p2]
while p1 < p2:
	if acc1 < acc3:
		p1 += 1
		acc1 += integ[p1]
	elif acc1 > acc3:
		p2 -= 1
		acc3 += integ[p2]
	else:
		if acc1 > max_acum:
			max_acum = acc1
		p1 += 1
		p2 -= 1
		acc1 += integ[p1]
		acc3 += integ[p2]
print(max_acum)


n = int(input())
a = list(map(int, input().split(' ')))
i = 0
j = n - 1
l = a[i]
h = a[j]
ans = []
while i < j:
	if l == h:
		ans.append(l)
	if l <= h:
		i += 1
		l = l + a[i]
	if l > h:
		j -= 1
		h = h + a[j]
if ans == []:
	print(0)
else:
	print(max(ans))


n = int(input())
a = list(map(int, input().split()))
(i, j, si, sj, r) = (-1, len(a), 0, 0, 0)
while i < j:
	if si == sj:
		r = si
	if si < sj:
		i += 1
		si += a[i]
	else:
		j -= 1
		sj += a[j]
print(r)


def solution(arr):
	s = sum(arr)
	i = 0
	j = len(arr) - 1
	sum1 = arr[0]
	sum3 = arr[j]
	mx = 0
	while i < j:
		if sum1 == sum3:
			i = i + 1
			j = j - 1
			mx = sum1
			sum1 = sum1 + arr[i]
			sum3 = sum3 + arr[j]
		elif sum1 > sum3:
			j = j - 1
			sum3 = sum3 + arr[j]
		elif sum3 > sum1:
			i = i + 1
			sum1 = sum1 + arr[i]
	return mx
n = int(input())
arr = [int(x) for x in input().split()]
print(solution(arr))


from sys import stdin, stdout
import math
I = lambda : map(int, stdin.readline().split())
n = int(stdin.readline())
a = list(I())
b = set()
(x, i, z, ans) = (0, n - 1, 0, 0)
for y in a:
	x += y
	b.add(x)
while i >= 0:
	b.remove(x)
	x -= a[i]
	z += a[i]
	if z in b:
		ans = max(ans, z)
	i -= 1
print(ans)


n = int(input())
l = list(map(int, input().split()))
s = c = p = q = m = 0
for i in range(n):
	s += l[i]
	c += 1
	while s > p and c + q < n:
		p += l[n - 1 - q]
		q += 1
	if s == p:
		m = max(m, s)
print(m)


n = int(input())
l = [int(i) for i in input().split()]
lefts = 0
maxi = 0
rights = 0
i = 0
j = n - 1
while i <= j:
	if lefts == rights:
		maxi = max(maxi, lefts)
		lefts += l[i]
		i += 1
	elif lefts < rights:
		lefts += l[i]
		i += 1
	else:
		rights += l[j]
		j -= 1
if lefts == rights:
	maxi = max(maxi, lefts)
print(maxi)


n = int(input())
a = list(map(int, input().split()))
(i, j, si, sj) = (0, n - 1, a[0], a[-1])
o = 0
while i != j:
	if si == sj:
		o = si
		i += 1
		si += a[i]
	elif sj > si:
		i += 1
		si += a[i]
	else:
		j -= 1
		sj += a[j]
print(o)


n = int(input())
a = [int(x) for x in input().split()]
s = 0
a1 = []
for i in range(n):
	s += a[i]
	a1.append(s)
a = a[::-1]
s = 0
a2 = []
for i in range(n):
	s += a[i]
	a2.append(s)
a2 = a2[::-1]
d = {}
for i in a2:
	d[i] = []
for i in range(n):
	d[a2[i]].append(i)
ss = set(a2)
ans = 0
for i in range(n):
	if a1[i] in ss:
		if d[a1[i]][-1] > i:
			ans = a1[i]
print(ans)


length = int(input())
numbers = list(map(int, input().split(' ')))
maxTotal = 0
totalLeft = 0
indexLeft = 0
totalRight = 0
indexRight = length - 1
while indexLeft <= indexRight:
	if totalLeft > totalRight:
		totalRight += numbers[indexRight]
		indexRight -= 1
	else:
		totalLeft += numbers[indexLeft]
		indexLeft += 1
	if totalRight == totalLeft:
		maxTotal = max(maxTotal, totalLeft)
print(maxTotal)


n = int(input())
arr = list(map(int, input().split()))
(left, right) = (arr[0], arr[-1])
(i, j) = (0, n - 1)
Max = 0
while i < j:
	if left == right:
		Max = left
		(i, j) = (i + 1, j - 1)
		left += arr[i]
		right += arr[j]
	elif left < right:
		i += 1
		left += arr[i]
	else:
		j -= 1
		right += arr[j]
print(Max)


def f(n, array):
	if n == 1:
		return 0
	MAX = 0
	i_1 = 0
	i_3 = n - 1
	sum_1 = 0
	sum_3 = 0
	while i_1 <= i_3:
		if sum_3 >= sum_1:
			sum_1 += array[i_1]
			i_1 += 1
		else:
			sum_3 += array[i_3]
			i_3 -= 1
		if sum_1 == sum_3:
			MAX = sum_1
	return MAX
n = int(input())
array = [int(i) for i in input().split()]
print(f(n, array))


n = int(input())
d = [int(x) for x in input().split()]
if n == 1:
	print('0')
else:
	i = 1
	j = n - 2
	sl = d[0]
	sr = d[n - 1]
	while i <= j:
		if sl > sr:
			sr += d[j]
			j -= 1
		else:
			sl += d[i]
			i += 1
	temp = i
	i = j
	j = temp
	if sl == sr:
		print(sl)
	else:
		while sl != sr and i > -1 and (j < n):
			if sl > sr:
				sl -= d[i]
				i -= 1
			else:
				sr -= d[j]
				j += 1
		if i > -1 and j < n and (sl == sr):
			print(sl)
		else:
			print('0')


x = int(input())
v = list(map(int, input().strip().split()))[:x]
i = 0
j = x - 1
s1 = 0
s2 = 0
ans = 0
while i <= j:
	if s2 < s1:
		s2 += v[j]
		j = j - 1
	else:
		s1 += v[i]
		i = i + 1
	if s1 == s2:
		ans = s1
print(ans)


n = int(input().strip())
arr = list(map(int, input().strip().split(' ')))
left = 0
right = len(arr) - 1
sum_left = arr[left]
sum_right = arr[right]
answer = 0
while left < right:
	if sum_left == sum_right:
		answer = sum_left
		left += 1
		right -= 1
		sum_left += arr[left]
		sum_right += arr[right]
	elif sum_left < sum_right:
		left += 1
		sum_left += arr[left]
	else:
		right -= 1
		sum_right += arr[right]
print(answer)


s = i = x = y = 0
n = int(input()) - 1
a = list(map(int, input().split()))
while i < n:
	x += a[i]
	y += a[n]
	if x > y:
		n -= 1
		x -= a[i]
	elif y > x:
		i += 1
		y -= a[n]
	else:
		s = x
		i += 1
		n -= 1
print(s)


n = int(input())
l = list(map(int, input().split()))
t1 = l[0]
(s1, s3) = (sum(l), 0)
(b, c, i) = ([], [], n - 1)
while len(l) > 0:
	t1 = l.pop()
	s1 -= t1
	s3 += t1
	c.append(t1)
	if s3 > s1:
		break
	if s3 == s1:
		break
if s1 == s3:
	print(s1)
else:
	while len(c) > 0:
		while s3 > s1:
			t1 = c.pop()
			s3 -= t1
			if s3 == s1:
				break
		if s1 == s3:
			break
		while s1 > s3:
			t1 = l.pop()
			s1 -= t1
			if s3 == s1:
				break
		if s3 == s1:
			break
	print(s1)


import itertools

def f(n, arr):
	d = dict(((j, i) for (i, j) in enumerate(itertools.accumulate(reversed(arr)))))
	res = 0
	for (i, j) in enumerate(itertools.accumulate(arr)):
		if j in d and i + d[j] < n - 1:
			res = max(res, j)
	return res
n = int(input())
arr = [int(i) for i in input().split()]
print(f(n, arr))


n = int(input())
a = [int(x) for x in input().split()]
ans = 0
i = 0
j = n - 1
(p, q) = (0, 0)
while i <= j:
	if p == q and i + 1 <= j:
		p += a[i]
		q += a[j]
		i += 1
		j -= 1
	elif p == q:
		i += 1
	elif p > q:
		q += a[j]
		j -= 1
	elif p < q:
		p += a[i]
		i += 1
	if p == q:
		ans = max(ans, p)
print(ans)


n = int(input())
a = list(map(int, input().split()))
ans = 0
si = 0
sj = 0
i = 0
j = n - 1
while True:
	while si <= sj:
		si += a[i]
		if i > j:
			print(ans)
			exit()
		i += 1
		if si == sj:
			ans = si + 0
	while sj <= si:
		sj += a[j]
		if i > j:
			print(ans)
			exit()
		j -= 1
		if si == sj:
			ans = si + 0


def splitArray(n, arr):
	a = -1
	b = n
	match_found = False
	(suma, sumb) = (0, 0)
	max_sum = 0
	while a < b:
		if suma == sumb:
			max_sum = suma
			a += 1
			suma += arr[a]
		elif suma > sumb:
			b -= 1
			sumb += arr[b]
		else:
			a += 1
			suma += arr[a]
	return max_sum
n = int(input())
arr = list(map(int, input().split()))
print(splitArray(n, arr))


length = int(input())
data = list(map(int, input().split(' ')))
idx_sum3_start = length - 1
s = 0
sum1 = 0
sum3 = 0
for idx in range(length):
	sum1 += data[idx]
	if sum1 == sum3:
		s = sum1
	while sum1 > sum3:
		if idx >= idx_sum3_start:
			print(s)
			exit(0)
		sum3 += data[idx_sum3_start]
		idx_sum3_start -= 1
		if sum1 == sum3:
			s = sum1
print(s)


n = int(input())
s = [int(i) for i in input().split()]
p = [0] * (n + 1)
for i in range(n):
	p[i + 1] = p[i] + s[i]
last = p[-1] // 2
(L, R) = (0, n + 1)
while R - L > 1:
	m = (R + L) // 2
	if p[m] > last:
		R = m
	else:
		L = m
last = L
while last > 0:
	now = p[last]
	proper_rest = p[-1] - now
	(L, R) = (0, n + 1)
	while R - L > 1:
		m = (R + L) // 2
		if p[m] > proper_rest:
			R = m
		else:
			L = m
	if p[L] == proper_rest:
		break
	last -= 1
print(p[last])


n = int(input())
ai = list(map(int, input().split()))
(a, c) = (0, 0)
ans = 0
(r, l) = (len(ai) - 1, 0)
while r >= l:
	if a <= c:
		a += ai[l]
		l += 1
	else:
		c += ai[r]
		r -= 1
	if a == c:
		ans = max(ans, a)
print(ans)


n = int(input())
l = list(map(int, input().split()))
l_sum = sum(l)
c_sum = [0 for _ in range(n)]
total = 0
mid = None
for (i, x) in enumerate(l):
	total += x
	c_sum[i] = total
	if mid is None and total >= l_sum // 2:
		mid = i
point_left = mid
point_right = mid + 1
sum_left = c_sum[mid]
sum_right = total - c_sum[mid]
while sum_left != sum_right:
	if point_left < 0:
		break
	if point_right >= n:
		break
	if sum_left > sum_right:
		sum_left -= l[point_left]
		point_left -= 1
	else:
		sum_right -= l[point_right]
		point_right += 1
print(min(sum_left, sum_right))


(n, a) = (int(input()), list(map(int, input().split())))
suma = sumc = maxsum = 0
i = -1
j = n
while i < j - 1:
	if suma < sumc:
		i += 1
		suma += a[i]
	else:
		j -= 1
		sumc += a[j]
	if suma == sumc:
		maxsum = suma
print(maxsum)


q = int(input())
m = [int(i) for i in input().split()]
a = 0
b = 0
c = 0
vm = 0
ini = 0
fim = len(m) - 1
while ini != fim + 1:
	if a == c:
		if vm < a:
			vm = a
		a += m[ini]
		ini += 1
	if ini == fim + 1:
		break
	if a > c:
		c += m[fim]
		fim -= 1
	else:
		a += m[ini]
		ini += 1
	if a == c:
		if vm < a:
			vm = a
print(vm)


n = int(input())

def LowerBound(A, key):
	left = -1
	right = len(A)
	while right > left + 1:
		middle = (left + right) // 2
		if A[middle] >= key:
			right = middle
		else:
			left = middle
	return right
prefsums = [0]
suffsums = [0]
nums = list(map(int, input().split()))
for x in range(1, n + 1):
	prefsums.append(prefsums[x - 1] + nums[x - 1])
	suffsums.append(suffsums[x - 1] + nums[-1 * x])
res = 0
for i in range(1, n + 1):
	k = LowerBound(suffsums, prefsums[i])
	if prefsums[i] == suffsums[k]:
		if i + k <= n:
			res = max(res, prefsums[i])
print(res)


n = int(input())
array = list(map(int, input().split()))
i = 0
j = len(array) - 1
s1 = array[i]
s3 = array[j]
result = []
while i < j:
	if s1 < s3:
		i += 1
		s1 += array[i]
	elif s1 > s3:
		j -= 1
		s3 += array[j]
	else:
		result.append(s1)
		i += 1
		j -= 1
		s1 += array[i]
		s3 += array[j]
if len(result) == 0:
	print(0)
else:
	print(max(result))


n = int(input())
l = [int(x) for x in input().split()]
sumf = l[0]
sumb = l[len(l) - 1]
i = 0
j = len(l) - 1
sum_max = []
while i < j:
	if sumf < sumb:
		i += 1
		sumf += l[i]
	elif sumf > sumb:
		j -= 1
		sumb += l[j]
	else:
		sum_max.append(sumb)
		i += 1
		j -= 1
		if i < j:
			sumf += l[i]
			sumb += l[j]
if len(sum_max) == 0:
	print(0)
else:
	print(max(sum_max))


n = int(input())
a = list(map(int, input().split()))
b = a[::-1]
sa = [0] * n
sb = [0] * n
sa[0] = a[0]
sb[0] = b[0]
for i in range(1, n):
	sa[i] = sa[i - 1] + a[i]
	sb[i] = sb[i - 1] + b[i]
(i, j) = (1, 1)
rec = []
while i + j <= n:
	if sa[i - 1] == sb[j - 1]:
		rec.append(sa[i - 1])
		i += 1
	elif sa[i - 1] < sb[j - 1]:
		i += 1
	else:
		j += 1
if len(rec) == 0:
	print(0)
else:
	print(max(rec))


n = int(input())
l = [int(x) for x in input().split()]
ki = 0
b = 0
j = 1
s1 = 0
s2 = 0
while b + j <= n:
	if s1 < s2:
		s1 += l[b]
		b += 1
	else:
		s2 += l[-j]
		j += 1
	if s1 == s2:
		ki = s1
print(ki)


n = int(input())
ls = [int(i) for i in input().split()]
if n == 1:
	exit(print(0))
(l, r) = (0, n - 1)
(suml, sumr) = (ls[l], ls[r])
ans = 0
while r > l:
	while suml != sumr and r - l > 1:
		if suml < sumr:
			l += 1
			suml += ls[l]
		else:
			r -= 1
			sumr += ls[r]
	if suml == sumr:
		ans = suml
	else:
		exit(print(ans))
	l += 1
	suml += ls[l]
print(ans)


def binsearch(a, n):
	s = 0
	e = n - 1
	s1 = a[s]
	ans = 0
	s2 = a[e]
	while s < e:
		if s1 > s2:
			e -= 1
			s2 += a[e]
		elif s1 == s2:
			ans = s1
			s += 1
			s1 += a[s]
		else:
			s += 1
			s1 += a[s]
	return ans
n = int(input())
a = list(map(int, input().split()))
ans = binsearch(a, n)
print(ans)


input()
x = list(map(int, input().split()))
l = 0
r = len(x) - 1
r_sum = x[r]
l_sum = x[l]
maxx = 0
while l < r:
	if l_sum > r_sum:
		r -= 1
		r_sum += x[r]
	elif r_sum > l_sum:
		l += 1
		l_sum += x[l]
	else:
		maxx = max([r_sum, maxx])
		r -= 1
		r_sum += x[r]
print(maxx)


n = int(input())
a = list(map(int, input().split()))
l = 0
s = set()
for x in a:
	l += x
	s.add(l)
(i, r, ans) = (n - 1, 0, 0)
while i >= 0:
	s.remove(l)
	l -= a[i]
	r += a[i]
	if r in s:
		ans = max(r, ans)
	i -= 1
print(ans)


n = int(input())
a = list(map(int, input().split()))
l = 0
r = n - 1
sl = 0
sr = 0
p = [0]
sl = a[0]
sr = a[n - 1]
while l < r:
	if sl == sr:
		p.append(sl)
		l += 1
		sl += a[l]
	elif sl < sr:
		l += 1
		sl += a[l]
	else:
		r -= 1
		sr += a[r]
print(p[len(p) - 1])


n = int(input())
nums = list(map(int, input().split()))
(l, r) = (-1, n)
(suma, sumb) = (0, 0)
res = 0
while l < r:
	if suma < sumb:
		l += 1
		suma += nums[l]
	elif suma > sumb:
		r -= 1
		sumb += nums[r]
	else:
		l += 1
		r -= 1
		res = suma
		suma += nums[l]
		sumb += nums[r]
print(res)


from sys import stdin
n = int(stdin.readline())
a = [int(x) for x in stdin.readline().split()]
max_sum = sum1 = sum3 = 0
l = -1
r = n
while l < r:
	if sum1 == sum3:
		max_sum = sum1
		l += 1
		r -= 1
		if l < r:
			sum1 += a[l]
			sum3 += a[r]
	elif sum1 < sum3:
		l += 1
		if l < r:
			sum1 += a[l]
	elif sum1 > sum3:
		r -= 1
		if l < r:
			sum3 += a[r]
print(max_sum)


n = int(input())
a = list(map(int, input().split()))
(i, j) = (-1, n)
sumI = sumJ = ans = 0
while i < j:
	if sumI == sumJ:
		i += 1
		j -= 1
		ans = sumI
		sumI += a[i]
		sumJ += a[j]
	elif sumI < sumJ:
		i += 1
		sumI += a[i]
	else:
		j -= 1
		sumJ += a[j]
print(ans)


n = int(input())
array = list(map(int, input().split()))
p1 = 0
p2 = len(array) - 1
maxs = 0
s1 = array[p1]
s2 = array[p2]
while p1 < p2:
	if s1 < s2:
		p1 += 1
		s1 += array[p1]
	elif s1 > s2:
		p2 -= 1
		s2 += array[p2]
	else:
		if s1 > maxs:
			maxs = s1
		p1 += 1
		p2 -= 1
		s1 += array[p1]
		s2 += array[p2]
print(maxs)


n = int(input())
m = input()
m = m.split()
k = [int(i) for i in m]
p = [k[len(k) - i] for i in range(1, len(k) + 1)]
cont = 0
(a, b) = (k[0], p[0])
(c, d) = (1, 1)
resp = 0
for i in k:
	cont += i
cont = cont - a - b
while True and c + d <= len(k):
	if a < b:
		a += k[c]
		c += 1
	elif b < a:
		b += p[d]
		d += 1
	elif a == b and c < len(k) and (d < len(k)):
		resp = a
		(a, b) = (a + k[c], b + p[d])
		(c, d) = (c + 1, d + 1)
	elif c + d > len(k):
		break
print(resp)


n = int(input())
a = [*map(int, input().split())]
b = [0] * n
c = [0] * (n + 1)
b[0] = a[0]
m = {b[0]: 0}
for i in range(1, len(a)):
	b[i] = b[i - 1] + a[i]
	m[b[i]] = i
ans = 0
for i in reversed(range(len(a))):
	c[i] = c[i + 1] + a[i]
	if c[i] in m.keys() and m[c[i]] < i:
		ans = c[i]
print(ans)


n = int(input())
li = list(map(int, input().split()))
from itertools import accumulate
l = list(accumulate(li))
r = list(reversed(list(accumulate(reversed(li)))))
il = 0
ir = n - 1
ma = 0
while il < ir:
	if l[il] < r[ir]:
		il += 1
	elif l[il] > r[ir]:
		ir -= 1
	else:
		ma = l[il]
		il += 1
		ir -= 1
print(ma)


def solve(n, a):
	if n == 1:
		print(0)
		return
	bestl = 0
	(l, r) = (0, n - 1)
	(sl, sr) = (0, 0)
	while l < r:
		if sl == sr:
			bestl = max(bestl, l)
		if sl + a[l] < sr + a[r]:
			sl += a[l]
			l += 1
		elif sl + a[l] > sr + a[r]:
			sr += a[r]
			r -= 1
		else:
			sl += a[l]
			l += 1
			sr += a[r]
			r -= 1
			bestl = max(bestl, l)
	print(sum(a[:bestl]))
solve(int(input()), list(map(int, input().split())))


input()
num = list(map(int, input().split()))
maxn = 0
(l, r) = (0, len(num) - 1)
(j1, j2) = (num[l], num[r])
while l < r:
	if j1 == j2:
		maxn = max(j1, maxn)
		l += 1
		j1 += num[l]
	elif j1 < j2:
		l += 1
		j1 += num[l]
	else:
		r -= 1
		j2 += num[r]
print(maxn)


import sys
import math
import bisect

def solve(A):
	n = len(A)
	max_val = 0
	l = 0
	r = n - 1
	left_sum = A[0]
	right_sum = A[-1]
	while l < r:
		if left_sum == right_sum:
			val = left_sum
			max_val = max(max_val, val)
			l += 1
			r -= 1
			left_sum += A[l]
			right_sum += A[r]
		elif left_sum < right_sum:
			l += 1
			left_sum += A[l]
		elif left_sum > right_sum:
			r -= 1
			right_sum += A[r]
	return max_val

def main():
	n = int(input())
	A = list(map(int, input().split()))
	ans = solve(A)
	print(ans)
main()


n = int(input())
a = list(map(int, input().split(' ')))
i = 0
j = n - 1
sl = a[0]
sr = a[n - 1]
ar = [0]
while j > i:
	if sl > sr:
		j = j - 1
		sr = sr + a[j]
	elif sl < sr:
		i = i + 1
		sl = sl + a[i]
	else:
		ar += [sr]
		i = i + 1
		j = j - 1
		sl = sl + a[i]
		sr = sr + a[j]
print(max(ar))


n = int(input())
nums = [int(i) for i in input().split()]
(front, end) = (0, n - 1)
(sum1, sum2) = (nums[front], nums[end])
max_sum = 0
while front < end:
	if sum1 < sum2:
		front += 1
		sum1 += nums[front]
	elif sum1 > sum2:
		end -= 1
		sum2 += nums[end]
	else:
		if sum1 > max_sum:
			max_sum = sum1
		front += 1
		end -= 1
		sum1 += nums[front]
		sum2 += nums[end]
print(max_sum)


import sys
from itertools import accumulate

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

def list2d(a, b, c):
	return [[c] * b for i in range(a)]

def list3d(a, b, c, d):
	return [[[d] * c for j in range(b)] for i in range(a)]

def list4d(a, b, c, d, e):
	return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]

def ceil(x, y=1):
	return int(-(-x // y))

def INT():
	return int(input())

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

def LIST(N=None):
	return list(MAP()) if N is None else [INT() for i in range(N)]

def Yes():
	print('Yes')

def No():
	print('No')

def YES():
	print('YES')

def NO():
	print('NO')
INF = 10 ** 18
MOD = 10 ** 9 + 7

def bisearch_min(mn, mx, func):
	ok = mx
	ng = mn
	while ng + 1 < ok:
		mid = (ok + ng) // 2
		if func(mid):
			ok = mid
		else:
			ng = mid
	return ok

def check(m):
	return acc[N] - acc[m] <= sm1
N = INT()
A = LIST()
acc = [0] + list(accumulate(A))
ans = 0
for i in range(N):
	sm1 = acc[i]
	res = bisearch_min(i - 1, N, check)
	if res < 0:
		break
	sm3 = acc[N] - acc[res]
	if sm1 == sm3:
		ans = max(ans, sm1)
print(ans)


n = int(input())
lst = [int(x) for x in input().split()]
(a_end, b_start) = (0, n - 1)
(max_sum, sum1, sum3) = (0, lst[a_end], lst[b_start])
while a_end < b_start:
	if sum1 == sum3:
		max_sum = sum1
		a_end = a_end + 1
		sum1 = sum1 + lst[a_end]
	elif sum1 > sum3:
		b_start = b_start - 1
		sum3 = sum3 + lst[b_start]
	else:
		a_end = a_end + 1
		sum1 = sum1 + lst[a_end]
print(max_sum)


n = int(input().strip())
d = list(map(int, input().strip().split()))
(i, j) = (0, n)
(l_sum, r_sum) = (0, 0)
last_idx = i
while i <= j:
	if l_sum < r_sum:
		l_sum += d[i]
		i += 1
	elif l_sum > r_sum:
		j -= 1
		r_sum += d[j]
	else:
		last_idx = i
		l_sum += d[i]
		i += 1
		j -= 1
		r_sum += d[j]
print(sum(d[:last_idx]))


n = int(input())
arr = list(map(int, input().split()))
(s1, s2) = (0, 0)
(i, j) = (0, n - 1)
res = 0
while i < n:
	s1 += arr[i]
	while s2 < s1 and j > i:
		s2 += arr[j]
		j -= 1
	if s1 == s2:
		res = s1
	i += 1
print(res)


n = int(input())
if n == 1:
	print(0)
else:
	d = [int(i) for i in input().split()]
	l = 0
	r = n - 1
	leftsum = d[0]
	rightsum = d[-1]
	ans = 0
	while l < r:
		if leftsum <= rightsum:
			if leftsum == rightsum:
				ans = leftsum
			if l + 1 == r:
				break
			else:
				leftsum += d[l + 1]
				l += 1
		elif leftsum > rightsum:
			if r - 1 == l:
				break
			else:
				rightsum += d[r - 1]
				r -= 1
	print(ans)


n = int(input())
d = list(map(int, input().split()))
l = -1
r = n
lsum = 0
rsum = 0
answer = 0
while l < r - 1:
	if lsum <= rsum:
		l += 1
		lsum += d[l]
	else:
		r -= 1
		rsum += d[r]
	if lsum == rsum:
		answer = lsum
print(answer)


n = int(input())
arr = [int(x) for x in input().split()]
a = 0
b = 0
c = 0
pref = arr.copy()
for i in range(1, n):
	pref[i] += pref[i - 1]
ii = 0
jj = n - 2
while ii <= jj:
	if pref[ii] == pref[n - 1] - pref[jj]:
		b = pref[ii]
		ii += 1
	elif pref[ii] < pref[n - 1] - pref[jj]:
		ii += 1
	elif pref[ii] > pref[n - 1] - pref[jj]:
		jj -= 1
print(b)


n = int(input())
lis = list(map(int, input().split()))
vali = 0
valj = 0
ans = 0
j = n * 1
for i in range(n):
	vali += lis[i]
	while valj < vali and j > i:
		j -= 1
		valj += lis[j]
	if i == j:
		break
	if vali == valj:
		ans = vali * 1
print(ans)


import sys
reader = (tuple(map(int, line.split())) for line in sys.stdin)
n = next(reader)
n = int(n[0])
spisok = []
spisok = list(next(reader))
max = -1
i = 0
j = n - 1
sumbegin = sum(spisok[0:i + 1])
sumend = sum(spisok[j:n])
while i < j:
	if sumbegin == sumend:
		if sumbegin > max:
			max = sumbegin
		j -= 1
		sumend += spisok[j]
	elif sumbegin > sumend:
		j -= 1
		sumend += spisok[j]
	else:
		i += 1
		sumbegin += spisok[i]
if max == -1:
	print(0)
else:
	print(max)


n = int(input())
lst = [int(x) for x in input().split()]
i = 0
j = len(lst) - 1
l = 0
r = 0
ans = 0
while i <= j:
	if r == l:
		ans = r
		l += lst[i]
		i += 1
	elif l > r:
		r += lst[j]
		j -= 1
	else:
		r > l
		l += lst[i]
		i += 1
	if l == r:
		ans = r
print(ans)


import sys
n = int(sys.stdin.readline())
s = sys.stdin.readline().split(' ')
array = list(map(int, s))
slice = [0, n]
sum = [array[0], 0]
bestSum = 0
while slice[0] < slice[1] - 1:
	i = 0 if sum[0] < sum[1] else 1
	slice[i] += 1 - 2 * i
	sum[i] += array[slice[i]]
	if sum[0] == sum[1]:
		bestSum = sum[0]
print(bestSum)


n = int(input())
d = list(map(int, input().split(' ')))
total = 0
pr = dict()
for i in range(0, n):
	total += d[i]
	pr.update({total: 1})
r = 0
result = 0
for i in range(n - 1, -1, -1):
	r += d[i]
	del pr[total]
	total -= d[i]
	if r in pr:
		result = max(result, r)
print(result)


n = int(input())
A = [int(_) for _ in input().split()]
c = 0
(i, j) = (0, n - 1)
(x, y) = (0, 0)
while i <= j:
	if x < y:
		x += A[i]
		i += 1
	elif x > y:
		y += A[j]
		j -= 1
	else:
		c = max(x, y)
		x += A[i]
		i += 1
if x == y:
	print(y)
else:
	print(c)


sum = int(input())
numberList = list(map(int, input().split()))
pos = 1
left = 0
right = 0
total = 0
while pos <= sum and sum >= 0:
	if left <= right:
		left += numberList[pos - 1]
		pos += 1
	else:
		right += numberList.pop()
		sum -= 1
	if left == right:
		total = left
print(total)


n = int(input())
d = [int(i) for i in input().split()]
dp1 = [d[0]]
dp3 = [d[-1]]
for i in range(1, n):
	dp1.append(d[i] + dp1[-1])
for i in range(n - 2, -1, -1):
	dp3.append(dp3[-1] + d[i])
res = 0
(i, j) = (0, 0)
while i + j <= n - 2:
	if dp1[i] < dp3[j]:
		i += 1
	elif dp1[i] > dp3[j]:
		j += 1
	elif dp1[i] == dp3[j]:
		res = max(res, dp1[i])
		i += 1
		if not i + j <= n - 2:
			break
print(res)


n = int(input())
l = list(map(int, input().split()))
l = [0] + l
i = 0
j = n + 1
zi = 0
zj = 0
solidx = 0
while i < j:
	if zi < zj:
		i += 1
		zi += l[i]
	elif zi > zj:
		j -= 1
		zj += l[j]
	else:
		solidx = i
		i += 1
		j -= 1
		zi += l[i]
		zj += l[j]
s = sum(l[:solidx + 1])
print(s)


n = int(input())
s = list(map(int, input().split()))
m = 0
x = 0
y = n - 1
a = s[x]
b = s[y]
sx = a
sy = b
while y - x > 0:
	if sx == sy:
		m = sx
		x += 1
		y -= 1
		a = s[x]
		b = s[y]
		sx += a
		sy += b
	elif sx < sy:
		x += 1
		a = s[x]
		sx += a
	else:
		y -= 1
		b = s[y]
		sy += b
print(m)


import re
import time
totalInts = int(input())
fullString = input()
startTime = time.time()
fullSet = [int(x) for x in re.split('\\s', fullString)]
x = 0
y = 0
xloc = 0
yloc = len(fullSet) - 1
maxTie = 0
while xloc <= yloc:
	if x <= y:
		x += fullSet[xloc]
		xloc += 1
	else:
		y += fullSet[yloc]
		yloc -= 1
	if x == y:
		maxTie = x
print(maxTie)


from math import *
from collections import *
from itertools import *
from functools import *
from bisect import *
from heapq import *
from operator import *
from sys import *
setrecursionlimit(100000000)
n = int(input())
l = list(map(int, input().split()))
(i, j) = (0, n - 1)
(left, right) = (0, 0)
ans = 0
while i <= j:
	if left == right:
		ans = max(ans, left)
		left += l[i]
		i += 1
	elif left < right:
		left += l[i]
		i += 1
	else:
		right += l[j]
		j -= 1
if left == right:
	ans = max(ans, left)
print(ans)


n = int(input())
a = list(map(int, input().split()))
x = 0
y = 0
z = sum(a)
pos = -1
for i in range(n):
	x += a[i]
	z -= a[i]
	if x >= z:
		pos = i
		break
(l, r) = (pos, pos + 1)
while True:
	if x > z and l >= 0:
		x -= a[l]
		l -= 1
	elif x < z and r < n:
		z -= a[r]
		r += 1
	elif x == z:
		print(x)
		exit()
	elif l < 0 or r >= n:
		print(0)
		exit()


def read_tokens():
	return input().strip().split(' ')

def read_ints():
	return [int(s) for s in read_tokens()]
(n,) = read_ints()
arr = read_ints()

def fast(a) -> int:
	s1 = 0
	s2 = 0
	r = n
	max_size = 0
	for l in range(n):
		s1 += a[l]
		while s1 > s2:
			r -= 1
			s2 += a[r]
		if s1 == s2 and r > l:
			max_size = max(max_size, s1)
	return max_size
print(fast(arr))


n = int(input())
l = list(map(int, input().split()))
sum1 = int(0)
sum3 = int(0)
i = int(0)
j = int(n - 1)
ans = int(0)
while i <= j:
	if sum1 <= sum3:
		sum1 += l[i]
		i += 1
	elif sum1 > sum3:
		sum3 += l[j]
		j -= 1
	if sum1 == sum3:
		ans = max(ans, sum1)
print(ans)


t = 1
for test in range(t):
	n = int(input())
	arr = list(map(int, input().split()))
	l = -1
	h = n
	curMax = 0
	sum1 = 0
	sum3 = 0
	while l < h:
		if sum1 == sum3:
			curMax = max(curMax, sum1)
			l += 1
			sum1 += arr[l]
		elif sum1 < sum3:
			l += 1
			sum1 += arr[l]
		else:
			h -= 1
			sum3 += arr[h]
	print(curMax)


n = int(input())
arr = list(map(int, input().split()))
c_max = 0
ls = 0
rs = 0
lp = 0
rp = n - 1
while lp <= rp:
	if ls <= rs:
		ls += arr[lp]
		lp += 1
	else:
		rs += arr[rp]
		rp -= 1
	if ls == rs:
		c_max = ls
print(c_max)


n = int(input())
data = list(map(int, input().split()))
index1 = 0
index2 = len(data) - 1
sum1 = data[index1]
sum2 = data[index2]
max_s = 0
while abs(index1 - index2) > 1:
	if sum1 == sum2:
		max_s = sum1
		index1 += 1
		sum1 += data[index1]
	elif sum1 > sum2:
		index2 -= 1
		sum2 += data[index2]
	else:
		index1 += 1
		sum1 += data[index1]
if sum1 == sum2:
	max_s = sum1
if n == 1:
	max_s = 0
print(max_s)


n = int(input())
a = [int(x) for x in input().split()]
l = 0
r = n
gmax = 0
s1 = 0
s3 = 0
while l <= r:
	if s1 == s3:
		gmax = s1
		s1 += a[l]
		l += 1
	elif s1 < s3:
		s1 += a[l]
		l += 1
	else:
		r -= 1
		s3 += a[r]
print(gmax)


n = int(input())
d = [int(s) for s in input().split()]
lsum = [d[0]]
rsum = [d[-1]]
for i in range(1, n):
	lsum.append(lsum[-1] + d[i])
for i in range(n - 2, -1, -1):
	rsum.append(rsum[-1] + d[i])
ans = 0
pl = -1
pr = -1
i = 0
j = 0
while i < n:
	while i + j < n - 1 and rsum[j] < lsum[i]:
		j += 1
	if rsum[j] == lsum[i] and i + j < n - 1:
		ans = lsum[i]
	i += 1
print(ans)


def solve(n, seq):
	pointer1 = 0
	pointer2 = n - 1
	lastEqualSum = 0
	sum1 = 0
	sum3 = 0
	while pointer1 < pointer2:
		if sum1 == sum3:
			lastEqualSum = sum1
			sum1 += seq[pointer1]
			sum3 += seq[pointer2]
			pointer1 += 1
			pointer2 -= 1
		elif sum1 > sum3:
			sum3 += seq[pointer2]
			pointer2 -= 1
		else:
			sum1 += seq[pointer1]
			pointer1 += 1
	if pointer1 == pointer2:
		if sum1 < sum3:
			sum1 += seq[pointer1]
		elif sum3 < sum1:
			sum3 += seq[pointer1]
	if sum1 == sum3:
		lastEqualSum = sum1
	return lastEqualSum
n = int(input())
seq = list(map(int, input().split()))
print(solve(n, seq))


n = int(input())
a = list(map(int, input().split()))
i = 0
j = len(a)
sumi = 0
sumj = 0
ans = 0
while i < j:
	if sumi >= sumj:
		sumj += a[j - 1]
		j -= 1
	else:
		sumi += a[i]
		i += 1
	if sumi == sumj:
		if sumi > ans:
			ans = sumi
print(ans)


int_inp = lambda : int(input())
strng = lambda : input().strip()
strl = lambda : list(input().strip())
mul = lambda : map(int, input().strip().split())
mulf = lambda : map(float, input().strip().split())
seq = lambda : list(map(int, input().strip().split()))
k = int_inp()
m = seq()
l = 0
g = 0
p = []
x = -1
y = k
for j in range(0, k + 1):
	if l == g:
		p.append(l)
		x += 1
		l += m[x]
	elif l > g:
		y -= 1
		g += m[y]
	else:
		x += 1
		l += m[x]
print(max(p))


n = int(input())
x = [int(i) for i in input().split()]
(S1, S3, L, R) = (0, 0, -1, n)
MaxS = 0
while L < R:
	if S1 == S3:
		MaxS = S1
		L += 1
		S1 += x[L]
	elif S1 > S3:
		R -= 1
		S3 += x[R]
	else:
		L += 1
		S1 += x[L]
print(MaxS)


a = int(input())
n = [int(x) for x in input().split()]
s1 = 0
s3 = 0
i = 0
j = a - 1
m = 0
pi = -1
pj = -1
while i < j:
	if i != pi:
		s1 += n[i]
		pi = i
	if j != pj:
		s3 += n[j]
		pj = j
	if s1 == s3 and s1 > m:
		m = s1
		j -= 1
		i += 1
	if s1 < s3:
		i += 1
	if s3 < s1:
		j -= 1
print(m)


import atexit, io, sys, collections, math, heapq, fractions, copy, os, functools
import sys
import random
import collections
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')
n = int(input())
ais = list(map(int, input().split()))
inf = -10 ** 9
inf *= 10
h = {}
suf = 0
for j in range(len(ais) - 1, -1, -1):
	suf += ais[j]
	if suf not in h:
		h[suf] = j
ans = 0
pre = 0
for i in range(len(ais)):
	pre += ais[i]
	if pre in h and h[pre] > i:
		ans = max(ans, pre)
print(ans)


nums_count = int(input())
nums = [int(x) for x in input().split()]
(left_pointer, right_pointer) = (0, nums_count - 1)
(left_sum, right_sum) = (nums[left_pointer], nums[right_pointer])
sum_1 = 0
while left_pointer != right_pointer:
	if left_sum == right_sum:
		sum_1 = left_sum
		left_pointer += 1
		left_sum += nums[left_pointer]
	elif left_sum < right_sum:
		left_pointer += 1
		left_sum += nums[left_pointer]
	else:
		right_pointer -= 1
		right_sum += nums[right_pointer]
print(sum_1)


n = int(input())
a = list(map(int, input().split()))
curright = n
curleft = 0
(suml, sumr, ans) = (0, 0, 0)
while curright != curleft:
	if sumr > suml:
		suml += a[curleft]
		curleft += 1
	else:
		curright -= 1
		sumr += a[curright]
	if suml == sumr:
		ans = sumr
print(ans)


import sys
input = lambda : sys.stdin.readline().rstrip('\r\n')
inp = lambda : list(map(int, sys.stdin.readline().rstrip('\r\n').split()))
mod = 10 ** 9 + 7
Mod = 998244353
INF = float('inf')
import math
from bisect import *
from heapq import *
from collections import defaultdict as dd
from collections import OrderedDict as odict
from collections import Counter as cc
from collections import deque
from itertools import groupby
sys.setrecursionlimit(20 * 20 * 20 * 20 + 10)

def solve():
	n = takein()
	arr = takeiar()
	i = -1
	sum1 = sum2 = 0
	j = n
	index = 0
	while i < j:
		if sum1 > sum2:
			j -= 1
			sum2 += arr[j]
		elif sum1 < sum2:
			i += 1
			sum1 += arr[i]
		else:
			i += 1
			j -= 1
			index = i
			sum1 += arr[i]
			sum2 += arr[j]
	print(sum(arr[:index]))

def main():
	global tt
	if not ONLINE_JUDGE:
		sys.stdin = open('input.txt', 'r')
		sys.stdout = open('output.txt', 'w')
	t = 1
	for tt in range(1, t + 1):
		solve()
	if not ONLINE_JUDGE:
		print('Time Elapsed :', time.time() - start_time, 'seconds')
		sys.stdout.close()

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

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

def takeiar():
	return list(map(int, sys.stdin.readline().rstrip('\r\n').split()))

def takesar():
	return list(map(str, sys.stdin.readline().rstrip('\r\n').split()))

def takeivr():
	return map(int, sys.stdin.readline().rstrip('\r\n').split())

def takesvr():
	return map(str, sys.stdin.readline().rstrip('\r\n').split())

def ispalindrome(s):
	return s == s[::-1]

def invert(bit_s):
	temp = int(bit_s, 2)
	inverse_s = temp ^ 2 ** (len(bit_s) + 1) - 1
	rslt = bin(inverse_s)[3:]
	return str(rslt)

def counter(a):
	q = [0] * max(a)
	for i in range(len(a)):
		q[a[i] - 1] = q[a[i] - 1] + 1
	return q

def counter_elements(a):
	q = dict()
	for i in range(len(a)):
		if a[i] not in q:
			q[a[i]] = 0
		q[a[i]] = q[a[i]] + 1
	return q

def string_counter(a):
	q = [0] * 26
	for i in range(len(a)):
		q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
	return q

def factorial(n, m=1000000007):
	q = 1
	for i in range(n):
		q = q * (i + 1) % m
	return q

def factors(n):
	q = []
	for i in range(1, int(n ** 0.5) + 1):
		if n % i == 0:
			q.append(i)
			q.append(n // i)
	return list(sorted(list(set(q))))

def prime_factors(n):
	q = []
	while n % 2 == 0:
		q.append(2)
		n = n // 2
	for i in range(3, int(n ** 0.5) + 1, 2):
		while n % i == 0:
			q.append(i)
			n = n // i
	if n > 2:
		q.append(n)
	return list(sorted(q))

def transpose(a):
	(n, m) = (len(a), len(a[0]))
	b = [[0] * n for i in range(m)]
	for i in range(m):
		for j in range(n):
			b[i][j] = a[j][i]
	return b

def power_two(x):
	return x and (not x & x - 1)

def ceil(a, b):
	return -(-a // b)

def seive(n):
	a = [1]
	prime = [True for i in range(n + 1)]
	p = 2
	while p * p <= n:
		if prime[p] == True:
			for i in range(p ** 2, n + 1, p):
				prime[i] = False
		p = p + 1
	for p in range(2, n + 1):
		if prime[p]:
			a.append(p)
	return a
ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
	input = sys.stdin.readline
main()


n = int(input())
a = list(map(int, input().split()))
c = int()
l = int(0)
r = int(n - 1)
x = int(a[0])
y = int(a[n - 1])
while l != r:
	if x == y:
		c = x
	if x < y:
		l += 1
		if l == r:
			break
		x += a[l]
	else:
		r -= 1
		if l == r:
			break
		y += a[r]
if x == y:
	c = x
if n == 1:
	c = 0
print(c)


n__ = int(input())
x = list(map(int, input().split()))
mx = 0
i = 1
j = len(x) - 2
sl = x[0]
sr = x[-1]
while i <= j + 1:
	if sl == sr:
		mx = max(mx, sl)
	if sl > sr:
		sr += x[j]
		j -= 1
	else:
		sl += x[i]
		i += 1
print(mx)


n = int(input())
array = list(map(int, input().split()))
maxx = 0
leftIndex = 0
left = array[0]
right = array[n - 1]
ptr1 = 0
ptr2 = n - 1
while ptr1 < ptr2:
	if left > right:
		ptr2 -= 1
		right += array[ptr2]
	elif right > left:
		ptr1 += 1
		left += array[ptr1]
	else:
		ptr1 += 1
		ptr2 -= 1
		maxx = left
		leftIndex = ptr1 - 1
		left += array[ptr1]
		right += array[ptr2]
print(maxx)


n = int(input())
A = list(map(int, input().split()))
S = [0] * n
T = [0] * n
t = sum(A)
s = 0
for (i, a) in enumerate(A):
	s += a
	S[i] = s
	T[i] = t
	t -= a
ans = 0
j = n - 1
for i in range(n):
	while i < j and S[i] > T[j]:
		j -= 1
	if i < j and S[i] == T[j]:
		ans = max(ans, S[i])
print(ans)


def call(l):
	(x, y) = (0, len(l) - 1)
	n = len(l)
	(s1, s2) = (0, 0)
	yo = 0
	while x <= y:
		if s1 == s2:
			yo = s1
			s1 += l[x]
			x += 1
		elif s1 > s2:
			s2 += l[y]
			y -= 1
		else:
			s1 += l[x]
			x += 1
	if s1 == s2:
		return s1
	return yo
n = int(input())
l = list(map(int, input().split()))
n = len(l)
x = call(l)
print(x)


n = int(input())
d = list(map(int, input().split()))
summa1 = [0]
summa2 = [0]
for i in range(0, n):
	summa1.append(summa1[-1] + d[i])
for i in range(n - 1, -1, -1):
	summa2.append(summa2[-1] + d[i])
i = 0
j = 0
ans = 0
while i <= n and j <= n:
	if i + j > n:
		break
	el1 = summa1[i]
	el2 = summa2[j]
	if el1 == el2:
		ans = max(ans, el1)
		i += 1
	elif el1 < el2:
		i += 1
	else:
		j += 1
print(ans)


n = int(input(''))
arr = list(map(int, input().split()))
lsum = [arr[0]]
for i in range(1, n):
	lsum.append(lsum[i - 1] + arr[i])
rsum = [arr[n - 1]]
k = 0
for i in range(n - 2, -1, -1):
	rsum.append(rsum[k] + arr[i])
	k += 1
ls = {}
rs = {}
for i in range(n):
	try:
		ls[lsum[i]] = i
	except:
		ls[lsum[i]] = i
	try:
		rs[rsum[i]] = i
	except:
		rs[rsum[i]] = i
ans = 0
for i in ls:
	try:
		rs[i]
		if n - rs[i] - 1 > ls[i]:
			ans = max(ans, i)
	except:
		continue
print(ans)


n = int(input())
values = list(map(int, input().split()))
i = 0
j = n - 1
sum_left = values[i]
sum_right = values[j]
max_sum = 0
while i < j:
	if sum_left == sum_right:
		max_sum = sum_left
		i += 1
		j -= 1
		sum_left += values[i]
		sum_right += values[j]
	elif sum_left < sum_right:
		i += 1
		sum_left += values[i]
	else:
		j -= 1
		sum_right += values[j]
print(max_sum)


n = int(input())
a = [int(i) for i in input().split(' ')]
N = n
sum1 = 0
sum3 = 0
i1 = -1
i2 = n
answer = 0
while N > 0:
	if sum1 >= sum3:
		i2 -= 1
		sum3 += a[i2]
	else:
		i1 += 1
		sum1 += a[i1]
	if sum1 == sum3:
		answer = sum1
	N -= 1
print(answer)


for _ in range(1):
	n = int(input())
	l = list(map(int, input().split()))
	i = 0
	j = n - 1
	sumi = 0
	sumj = 0
	max1 = 0
	while i <= j:
		if sumi <= sumj:
			sumi = sumi + l[i]
			i = i + 1
		else:
			sumj = sumj + l[j]
			j = j - 1
		if sumi == sumj:
			if sumi > max1:
				max1 = sumi + 0
	print(max1)


import sys
n = int(input())
arr = list(map(int, input().strip().split()))
ans = sum1 = sum2 = 0
i = -1
j = n
while i < j:
	if sum1 > sum2:
		j -= 1
		sum2 += arr[j]
	elif sum2 > sum1:
		i += 1
		sum1 += arr[i]
	else:
		ans = sum1
		j -= 1
		sum2 += arr[j]
print(ans)


from queue import deque

def main():
	input()
	q = deque(map(int, input().split()))
	r = s1 = s3 = 0
	while q:
		if s1 < s3:
			s1 += q.popleft()
		else:
			s3 += q.pop()
		if s1 == s3:
			r = s1
	print(r)
main()


n = int(input())
a = list(map(int, input().split()))
s = 0
s1 = 0
s2 = 0
ss1 = 0
ss2 = 0
for i in range(n):
	s1 += a[i]
	ss1 += 1
	while s1 > s2 and ss1 + ss2 + 1 <= n:
		s2 += a[n - ss2 - 1]
		ss2 += 1
	if s1 == s2:
		s = s1
print(s)


n = int(input())
a = list(map(int, input().split()))
(s1, s2) = (0, 0)
max_s = 0
(start, en) = (0, n - 1)
while start <= en:
	if s1 > s2:
		s2 += a[en]
		en -= 1
	else:
		s1 += a[start]
		start += 1
	if s1 == s2:
		max_s = s1
print(max_s)


n = int(input())
arr = list(map(int, input().split()))
cum = [0] * (n + 1)
for i in range(n - 1, -1, -1):
	cum[i] = cum[i + 1] + arr[i]
ma = 0
s = {0}
ss = 0
for i in range(n - 1):
	ss += arr[i]
	s.add(ss)
	if cum[i + 1] in s:
		ma = max(ma, cum[i + 1])
print(ma)


n = int(input())
m = list(map(int, input().split()))
s = 0
s1 = m[0]
s2 = m[n - 1]
i = 0
j = n - 1
while i < j:
	if s1 == s2:
		s = s1
		i += 1
		s1 += m[i]
	elif s1 > s2:
		j -= 1
		s2 += m[j]
	else:
		i += 1
		s1 += m[i]
print(s)