Vasya has an array a consisting of positive integer numbers. Vasya wants to divide this array into two non-empty consecutive parts (the prefix and the suffix) so that the sum of all elements in the first part equals to the sum of elements in the second part. It is not always possible, so Vasya will move some element before dividing the array (Vasya will erase some element and insert it into an arbitrary position).

Inserting an element in the same position he was erased from is also considered moving.

Can Vasya divide the array after choosing the right element to move and its new position?


-----Input-----

The first line contains single integer n (1 ≤ n ≤ 100000) — the size of the array.

The second line contains n integers a_1, a_2... a_{n} (1 ≤ a_{i} ≤ 10^9) — the elements of the array.


-----Output-----

Print YES if Vasya can divide the array after moving one element. Otherwise print NO.


-----Examples-----
Input
3
1 3 2

Output
YES

Input
5
1 2 3 4 5

Output
NO

Input
5
2 2 3 4 5

Output
YES



-----Note-----

In the first example Vasya can move the second element to the end of the array.

In the second example no move can make the division possible.

In the third example Vasya can move the fourth element by one position to the left.

Difficulty: HARD

Solutions:
import sys
from collections import Counter
n = int(input())
a = [int(x) for x in input().split()]
s = sum(a)
c1 = Counter(a)
c2 = Counter()
cur = 0
for x in a:
	c1[x] -= 1
	c2[x] += 1
	cur += x
	s1 = cur
	s2 = s - s1
	if s1 == s2:
		print('YES')
		sys.exit()
	if (s2 - s1) % 2 == 1:
		continue
	if s2 > s1:
		if c1[(s2 - s1) // 2] > 0:
			print('YES')
			sys.exit()
	elif c2[(s1 - s2) // 2] > 0:
		print('YES')
		sys.exit()
print('NO')


a = int(input())
nums = [int(i) for i in input().split()]
tot = sum(nums)

def runner(lpr):
	total = 0
	used = {}
	for i in range(*lpr):
		used[nums[i]] = 1
		total += nums[i]
		distance = 2 * total - tot
		if distance % 2 == 0 and used.get(distance // 2, -1) != -1:
			print('YES')
			exit(0)
runner((0, a))
runner((a - 1, -1, -1))
print('NO')


def divider(a):
	t = sum(a)
	d = []
	d.append(-t)
	for i in range(len(a)):
		t -= 2 * a[i]
		d.append(-t)
		if t == 0:
			return 'YES'
	for i in range(len(a)):
		s = 2 * a[i]
		j = binary(d, s)
		if j > i and j != -1:
			return 'YES'
		j = binary(d, -s)
		if i >= j and j != -1:
			return 'YES'
	return 'NO'

def binary(a, value):
	hi = len(a)
	lo = -1
	while lo + 1 < hi:
		mi = (lo + hi) // 2
		if a[mi] == value:
			return mi
		if a[mi] < value:
			lo = mi
		else:
			hi = mi
	return -1
n = input()
a = [int(i) for i in input().split()]
print(divider(a))


n = int(input())
a = list(map(int, input().split()))
d = {}
for i in range(n):
	if a[i] in d:
		d[a[i]] += 1
	else:
		d[a[i]] = 1
if sum(a) % 2 == 1:
	print('NO')
else:
	i = 0
	lim = sum(a) // 2
	tot = 0
	ans = 'NO'
	d2 = {}
	while i < n:
		tot += a[i]
		d[a[i]] -= 1
		if a[i] in d2:
			d2[a[i]] += 1
		else:
			d2[a[i]] = 1
		if tot < lim:
			x = lim - tot
			if x in d:
				if d[x] > 0:
					ans = 'YES'
					break
		elif tot == lim:
			ans = 'YES'
			break
		else:
			x = tot - lim
			if x in d2:
				if d2[x] > 0:
					ans = 'YES'
					break
		i += 1
	print(ans)


n = int(input())
b = list(map(int, input().split()))
d = dict()
e = dict()
for j in range(n):
	if b[j] in d.keys():
		d[b[j]] += 1
		e[b[j]] += 1
	else:
		d[b[j]] = 1
		e[b[j]] = 1
if sum(b) % 2 != 0:
	print('NO')
else:
	p = sum(b) // 2
	j = 0
	s = 0
	f = 0
	while j < n:
		if s == p:
			f = 1
			break
		if p - s in d.keys() and d[p - s] > 0:
			f = 1
			break
		s += b[j]
		d[b[j]] += -1
		j += 1
	j = 0
	s = 0
	b.reverse()
	while j < n:
		if s == p:
			f = 1
			break
		if p - s in e.keys() and e[p - s] > 0:
			f = 1
			break
		s += b[j]
		e[b[j]] += -1
		j += 1
	if f == 1:
		print('YES')
	else:
		print('NO')


n = int(input())
A = list(map(int, input().split()))
d = dict()
acc = 0
for (i, j) in enumerate(A):
	acc += j
	d[acc] = i
if acc % 2 == 1:
	print('NO')
	exit()
for (i, j) in enumerate(A):
	v = acc // 2 - j
	if v in d and d[v] < i:
		print('YES')
		exit()
	v = acc / 2 + j
	if v in d and d[v] >= i:
		print('YES')
		exit()
print('NO')


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
prefix_sum = [a[0]]
postfix_sum = [a[-1]]
for i in range(1, n):
	prefix_sum.append(prefix_sum[-1] + a[i])
	postfix_sum.append(postfix_sum[-1] + a[-(i + 1)])
if prefix_sum[-1] & 1 or n == 1:
	print('NO')
	sys.exit()
target = prefix_sum[-1] // 2
if target in prefix_sum:
	print('YES')
	sys.exit()
seen_pre = {a[0]}
seen_post = {a[-1]}
for i in range(1, n):
	post_i = -(i + 1)
	seen_pre.add(a[i])
	seen_post.add(a[post_i])
	if prefix_sum[i] > target and prefix_sum[i] - target in seen_pre:
		print('YES')
		sys.exit()
	if postfix_sum[i] > target and postfix_sum[i] - target in seen_post:
		print('YES')
		sys.exit()
print('NO')


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

def helper(b):
	total = sum(b)
	target = total / 2
	s = set()
	if total % 2 != 0:
		return False
	else:
		ans = 0
		for i in b:
			ans += i
			s.add(i)
			if ans == target or (ans - target > 0 and ans - target in s):
				return True
		return False
if helper(a) or helper(a[::-1]):
	print('YES')
else:
	print('NO')


import sys
input = sys.stdin.readline
n = int(input())
a = list(map(int, input().split()))
s = sum(a)
if s % 2:
	print('NO')
	exit()
pre = 0
used = set()
flag = False
for rep in range(2):
	for i in range(n):
		pre += a[i]
		used.add(a[i])
		if pre - s // 2 in used:
			flag = True
	a.reverse()
	used = set()
	pre = 0
if flag:
	print('YES')
else:
	print('NO')


from collections import Counter

def good(a):
	total = sum(a)
	if total % 2 == 1:
		return False
	pref = Counter()
	suff = Counter(a)
	s = 0
	for e in a:
		s += e
		pref[e] += 1
		suff[e] -= 1
		if 2 * s == total:
			return True
		elif 2 * s > total:
			if pref[(2 * s - total) // 2] > 0:
				return True
		elif suff[(total - 2 * s) // 2] > 0:
			return True
	return False
n = int(input())
a = list(map(int, input().split()))
print('YES' if good(a) else 'NO')


from collections import Counter
n = int(input())
a = list(map(int, input().split()))
acc = 0
total = sum(a)
if total % 2 == 1:
	print('NO')
	exit()
half = total // 2
cnt_left = Counter({0: 1})
cnt_right = Counter({0: 1})
acc_r = 0
for i in range(n - 1, -1, -1):
	acc_r += a[i]
	cnt_right[acc_r] += 1
acc_l = 0
for i in range(n):
	cnt_right[acc_r] -= 1
	acc_r -= a[i]
	if cnt_right[half - a[i]] or cnt_left[half - a[i]]:
		print('YES')
		exit()
	acc_l += a[i]
	cnt_left[acc_l] += 1
print('NO')


import sys
import bisect
from bisect import bisect_left as lb
input_ = lambda : sys.stdin.readline().strip('\r\n')
from math import log
from math import gcd
from math import atan2, acos
from random import randint
sa = lambda : input_()
sb = lambda : int(input_())
sc = lambda : input_().split()
sd = lambda : list(map(int, input_().split()))
sflo = lambda : list(map(float, input_().split()))
se = lambda : float(input_())
sf = lambda : list(input_())
flsh = lambda : sys.stdout.flush()
mod = 10 ** 9 + 7
mod1 = 998244353
gp = []
cost = []
dp = []
mx = []
ans1 = []
ans2 = []
special = []
specnode = []
a = 0
kthpar = []

def dfs(root, par):
	if par != -1:
		dp[root] = dp[par] + 1
	for i in range(1, 20):
		if kthpar[root][i - 1] != -1:
			kthpar[root][i] = kthpar[kthpar[root][i - 1]][i - 1]
	for child in gp[root]:
		if child == par:
			continue
		kthpar[child][0] = root
		dfs(child, root)
ans = 0
b = []

def hnbhai(tc):
	n = sb()
	a = sd()
	s = sum(a)
	if s % 2 != 0 or n == 1:
		print('NO')
		return
	s //= 2
	for t in range(2):
		d = {}
		tot = 0
		for i in a:
			d[i] = True
			tot += i
			if d.get(tot - s):
				print('YES')
				return
		a.reverse()
	print('NO')
for _ in range(1):
	hnbhai(_ + 1)


n = int(input())
a = list(map(int, input().strip().split()))
if sum(a) % 2 != 0:
	print('NO')
else:
	b = set([])
	f = sum(a) // 2
	s = 0
	c = 1
	for i in range(n):
		b.add(a[i])
		s = s + a[i]
		if s == f:
			print('YES')
			c = 0
			break
		elif s - f in b:
			print('YES')
			c = 0
			break
	if c == 1:
		a = a[::-1]
		b = set([])
		f = sum(a) // 2
		s = 0
		c = 1
		for i in range(n):
			b.add(a[i])
			s = s + a[i]
			if s == f:
				print('YES')
				c = 0
				break
			elif s - f in b:
				print('YES')
				c = 0
				break
	if c == 1:
		print('NO')


from sys import exit
n = int(input().strip())
ais = list(map(int, input().strip().split()))
iais = [0 for _ in range(n + 1)]
for i in range(n):
	iais[i + 1] = iais[i] + ais[i]
s = iais[-1]
if s % 2 == 1:
	print('NO')
	exit()
s2 = s // 2
if s2 in iais:
	print('YES')
	exit()
ia = list(range(n))
ia.sort(key=lambda i: ais[i], reverse=True)
j = 0
for i in ia:
	while j < n and s2 - iais[j] > ais[i]:
		j += 1
	if s2 - iais[j] == ais[i] and i >= j:
		print('YES')
		exit()
	if s2 - iais[j] < 0:
		break
for i in reversed(ia):
	while j < n and s2 - iais[j] > -ais[i]:
		j += 1
	if s2 - iais[j] == -ais[i] and i < j:
		print('YES')
		exit()
print('NO')


class Dick:

	def __init__(self):
		self.s = 0
		self.m = dict()

	def add(self, x):
		self.s += x
		if x in self.m:
			self.m[x] += 1
		else:
			self.m[x] = 1

	def rm(self, x):
		self.s -= x
		if self.m[x] > 1:
			self.m[x] -= 1
		else:
			self.m.pop(x)

	def shasei(self):
		return self.s

	def ininder(self, x):
		return x in self.m

def ok(a, n):
	w = sum(a)
	if w & 1:
		return 0
	f = Dick()
	s = Dick()
	for x in a:
		s.add(x)
	w //= 2
	for i in range(n):
		if s.ininder(w - f.shasei()) or f.ininder(w - s.shasei()):
			return 1
		f.add(a[i])
		s.rm(a[i])
	return 0
n = int(input())
a = list(map(int, input().split()))
print('YES' if ok(a, n) else 'NO')


def read_ints():
	return list(map(int, input().split()))
n = int(input())
a = [0] + read_ints()
s = a.copy()
for i in range(1, n + 1):
	s[i] += s[i - 1]
total = s[n]
found = False
for x in s:
	if x << 1 == total:
		found = True
		break
else:
	for (i, x) in enumerate(s[1:], 1):

		def search(lo, hi, target):
			while lo <= hi:
				m = lo + hi >> 1
				cur = s[m] << 1
				if cur == target:
					return True
				elif cur < target:
					lo = m + 1
				else:
					hi = m - 1
			return False
		if search(i, n, total + 2 * a[i]) or search(1, i - 1, total - 2 * a[i]):
			found = True
print('YES' if found else 'NO')


n = int(input())
a = list(map(int, input().split()))
sum = [0] * n
sum[0] = a[0]
for i in range(1, n):
	sum[i] = sum[i - 1] + a[i]
s = sum[n - 1]
found = 0
if s % 2 == 0:
	half = s // 2
	u = 0
	l = n - 1
	while u <= l:
		mid = (u + l) // 2
		if sum[mid] == half:
			print('YES')
			exit()
		elif sum[mid] > half:
			l = mid - 1
		else:
			u = mid + 1
for i in range(0, n):
	u = i
	l = n - 1
	if (2 * a[i] + s) % 2 == 0:
		check = (s + 2 * a[i]) // 2
		while u <= l:
			mid = (u + l) // 2
			if sum[mid] == check:
				found = 1
				break
			elif sum[mid] > check:
				l = mid - 1
			else:
				u = mid + 1
		if found == 1:
			break
if found == 0 and n < 10000:
	for i in range(n - 1, -1, -1):
		u = 0
		l = i - 1
		if (s - 2 * a[i]) % 2 == 0 and s - 2 * a[i] > 0:
			check = (s - 2 * a[i]) // 2
			while u <= l:
				mid = (u + l) // 2
				if sum[mid] == check:
					found = 1
					break
				elif sum[mid] > check:
					l = mid - 1
				else:
					u = mid + 1
			if found == 1:
				break
if found == 1:
	print('YES')
else:
	print('NO')


import sys
input = sys.stdin.readline
from collections import defaultdict as dc
from collections import Counter
from bisect import bisect_right, bisect_left, bisect
import math
from operator import itemgetter
from heapq import heapify, heappop, heappush
from queue import PriorityQueue as pq
n = int(input())
l = list(map(int, input().split()))
x = dc(list)
y = dc(int)
p = [0] * n
p[0] = l[0]
x[l[0]].append(0)
y[l[0]] += 1
for i in range(1, n):
	p[i] = p[i - 1] + l[i]
	x[l[i]].append(i)
	y[l[i]] += 1
if p[-1] % 2:
	print('NO')
elif y[p[-1] // 2] > 0:
	print('YES')
else:
	f = 0
	for i in range(n - 1):
		if p[i] == p[-1] - p[i]:
			f = 1
			break
		if i != 0:
			if p[i] > p[-1] // 2:
				t = p[i] - p[-1] // 2
				if y[t] > 0:
					if x[t][0] <= i:
						f = 1
						break
	if f:
		print('YES')
	else:
		l = l[::-1]
		p = [0] * n
		f = 0
		x = dc(list)
		p[0] = l[0]
		x[l[0]].append(0)
		for i in range(1, n):
			p[i] = p[i - 1] + l[i]
			x[l[i]].append(i)
		for i in range(n - 1):
			if p[i] == p[-1] - p[i]:
				f = 1
				break
			if i != 0:
				if p[i] > p[-1] // 2:
					t = p[i] - p[-1] // 2
					if y[t] > 0:
						if x[t][0] <= i:
							f = 1
							break
		if f:
			print('YES')
		else:
			print('NO')


n = int(input())
z = list(map(int, input().split()))
s = sum(z)
c = s
if c % 2 != 0:
	f = 1
elif z[0] == s / 2 or z[-1] == s / 2:
	f = 0
else:
	f = 1
	for k in range(2):
		d = set()
		c = 0
		for i in range(n):
			d.add(z[i])
			c += z[i]
			if c - s / 2 in d:
				f = 0
				break
		if f == 0:
			break
		z.reverse()
print(['YES', 'NO'][f])


import os, io
from sys import stdout
import collections
import random
import math
from operator import itemgetter
input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
from collections import Counter

def binomial_coefficient(n, k):
	if 0 <= k <= n:
		ntok = 1
		ktok = 1
		for t in range(1, min(k, n - k) + 1):
			ntok *= n
			ktok *= t
			n -= 1
		return ntok // ktok
	else:
		return 0

def powerOfK(k, max):
	if k == 1:
		return [1]
	if k == -1:
		return [-1, 1]
	result = []
	n = 1
	while n <= max:
		result.append(n)
		n *= k
	return result

def prefixSum(arr):
	for i in range(1, len(arr)):
		arr[i] = arr[i] + arr[i - 1]
	return arr

def divisors(n):
	i = 1
	result = []
	while i * i <= n:
		if n % i == 0:
			if n / i == i:
				result.append(i)
			else:
				result.append(i)
				result.append(n / i)
		i += 1
	return result
n = int(input())
l = list(map(int, input().split()))
rs = Counter(l)
ls = collections.defaultdict(int)
left = prefixSum(l[:])
right = prefixSum(l[::-1])[::-1]
found = False
for i in range(0, n):
	rs[l[i]] -= 1
	ls[l[i]] += 1
	if left[i] == right[i] - l[i]:
		found = True
		print('YES')
		break
	if left[i] > right[i] - l[i]:
		diff = left[i] - (right[i] - l[i])
		if diff % 2 != 0:
			continue
		if diff // 2 in ls and ls[diff // 2] > 0:
			found = True
			print('YES')
			break
	else:
		diff = right[i] - l[i] - left[i]
		if diff % 2 != 0:
			continue
		if diff // 2 in rs and rs[diff // 2] > 0:
			found = True
			print('YES')
			break
if not found:
	print('NO')


def solve(n, a):
	tot = 0
	for i in range(n):
		tot += a[i]
	diffs = []
	diffs.append(-tot)
	for i in range(n):
		tot -= 2 * a[i]
		diffs.append(-tot)
		if tot == 0:
			return 'YES'
	for i in range(n):
		diffmake = 2 * a[i]
		j = binary(diffs, diffmake)
		if j > i and j != -1:
			return 'YES'
		j = binary(diffs, -diffmake)
		if i >= j and j != -1:
			return 'YES'
	return 'NO'

def binary(a, value):
	hi = len(a)
	lo = -1
	while lo + 1 < hi:
		mi = (lo + hi) // 2
		if a[mi] == value:
			return mi
		if a[mi] < value:
			lo = mi
		else:
			hi = mi
	return -1
n = int(input())
a = input().split()
for i in range(n):
	a[i] = int(a[i])
print(solve(n, a))


import math
import sys

def main(arr):
	left = {}
	right = {}
	for e in arr:
		if e not in right:
			right[e] = 0
		right[e] += 1
	prefix = [arr[0]]
	for i in range(1, len(arr)):
		prefix.append(arr[i] + prefix[-1])
	s = prefix[-1]
	for i in range(len(arr)):
		if arr[i] not in left:
			left[arr[i]] = 0
		left[arr[i]] += 1
		right[arr[i]] -= 1
		a = prefix[i]
		b = s - prefix[i]
		if prefix[i] == s - prefix[i]:
			return 'YES'
		elif a > b:
			if (a - b) / 2 in left and left[(a - b) / 2] != 0:
				return 'YES'
		elif (b - a) / 2 in right and right[(b - a) / 2] != 0:
			return 'YES'
	return 'NO'
n = int(input())
arr = list(map(int, input().split()))
print(main(arr))


import sys
from itertools import accumulate

def solve():
	n = int(input())
	a = [int(i) for i in input().split()]
	S = sum(a)
	if S & 1:
		print('NO')
		return
	f_a = dict()
	l_a = dict()
	for i in range(n):
		if a[i] not in f_a:
			f_a[a[i]] = i
	for i in range(n - 1, -1, -1):
		if a[i] not in l_a:
			l_a[a[i]] = i
	ps = [0] + list(accumulate(a))
	S //= 2
	for k in range(1, n + 1):
		x = S - ps[k]
		if x == 0:
			print('YES')
			return
		elif x > 0:
			if x in l_a and k <= l_a[x]:
				print('YES')
				return
		else:
			x *= -1
			if x in f_a and f_a[x] < k:
				print('YES')
				return
	print('NO')
solve()


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

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

def map_string():
	return input().split()
n = int(input())
a = list_input()
k = sum(a)
cur = 0
s = set([0])
pref = [0]
for i in a:
	pref.append(pref[-1] + i)
	s.add(pref[-1])
for i in range(n):
	s.remove(pref[i])
	if k / 2 + a[i] in s:
		print('YES')
		break
else:
	a.reverse()
	cur = 0
	s = set([0])
	pref = [0]
	for i in a:
		pref.append(pref[-1] + i)
		s.add(pref[-1])
	for i in range(n):
		s.remove(pref[i])
		if k / 2 + a[i] in s:
			print('YES')
			break
	else:
		print('NO')


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

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

def pt(x):
	print(x)

def ip():
	return input()

def it():
	return int(input())

def sl(x):
	return [t for t in x]

def spl(x):
	return x.split()

def aj(liste, item):
	liste.append(item)

def bin(x):
	return '{0:b}'.format(x)

def listring(l):
	return ' '.join([str(x) for x in l])

def ptlist(l):
	print(' '.join([str(x) for x in l]))
n = it()
a = lt()
k = 0
left = 0
right = sum(a)
bl = False
dict = {}
for i in range(n):
	if a[i] in dict:
		(ma, mi) = dict[a[i]]
		dict[a[i]] = (max(ma, i), min(mi, i))
	else:
		dict[a[i]] = (i, i)
while k < n and (not bl):
	if right == left:
		bl = True
	elif right > left:
		x = (right - left) / 2
		if x == int(x) and int(x) in dict and (dict[int(x)][0] >= k):
			bl = True
		else:
			right -= a[k]
			left += a[k]
			k += 1
	else:
		x = (left - right) / 2
		if x == int(x) and int(x) in dict and (dict[int(x)][1] <= k - 1):
			bl = True
		else:
			right -= a[k]
			left += a[k]
			k += 1
if bl:
	pt('YES')
else:
	pt('NO')


import sys

class BIT_RSQ(object):
	__slots__ = ['nodes', 'size']

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

	def add(self, index: int, value: int):
		while index < self.size:
			self.nodes[index] += value
			index += index & -index

	def sum(self, right: int):
		result = 0
		while right:
			result += self.nodes[right]
			right -= right & -right
		return result

	def lower_bound(self, value: int):
		(k, result) = (1 << self.size.bit_length() - 1, 0)
		while k:
			if k + result < self.size and self.nodes[k + result] < value:
				value -= self.nodes[k + result]
				result += k
			k >>= 1
		return result + 1
n = int(input())
a = list(map(int, input().split()))
total = sum(a)
if total & 1:
	print('NO')
	exit()
half = total >> 1
for _ in range(2):
	bit = BIT_RSQ(n + 10)
	(l, r) = (0, total)
	for i in range(n):
		l += a[i]
		r -= a[i]
		try:
			if l == r or (half > r and bit.sum(bit.lower_bound(half - r)) == half - r):
				print('YES')
				exit()
		except Exception:
			pass
		bit.add(n - i + 5, a[i])
	a.reverse()
print('NO')


from functools import reduce

def solve():
	sum_ = a[:]
	for i in range(1, n):
		sum_[i] += sum_[i - 1]
	if sum_[n - 1] % 2:
		return False
	half = int(sum_[n - 1] / 2)
	st = set([0])
	for i in range(n):
		if sum_[i] >= half and sum_[i] - half in st:
			return True
		st.add(a[i])
	sum_ = a[:]
	for i in range(n - 2, -1, -1):
		sum_[i] += sum_[i + 1]
	st = set([0])
	for i in range(n - 1, -1, -1):
		if sum_[i] >= half and sum_[i] - half in st:
			return True
		st.add(a[i])
	return False
while True:
	try:
		n = int(input())
	except:
		break
	a = [int(x) for x in input().split(' ')]
	print('YES' if solve() else 'NO')


def process(A):
	S = sum(A)
	d1 = {}
	for x in A:
		if x not in d1:
			d1[x] = 0
		d1[x] += 1
	if S % 2 == 1:
		return 'NO'
	S1 = 0
	d2 = set([])
	for x in A:
		S1 += x
		d1[x] -= 1
		d2.add(x)
		y = S1 - S // 2
		if y == 0:
			return 'YES'
		if y in d2:
			return 'YES'
		y2 = S // 2 - S1
		if y2 in d1 and d1[y2] > 0:
			return 'YES'
	return 'NO'
n = int(input())
A = [int(x) for x in input().split()]
print(process(A))


def func():
	n = int(input())
	array = []
	sum = 0
	for (index, number) in enumerate(input().split()):
		num = int(number)
		array.append(num)
		sum += num
	if sum % 1 == 1:
		print('NO')
		return
	setn = set()
	sumSub = 0
	indexdict = {}
	for (indexm, number) in enumerate(array):
		sumSub += number
		sum2 = sumSub * 2 - sum
		if sum2 % 2 == 1:
			continue
		sum2 /= 2
		setn.add(sum2)
		indexdict[sum2] = indexm
	i = 0
	if 0 in setn:
		print('YES')
		return
	while i < n:
		num = array[i]
		if num in setn and num in indexdict and (i < indexdict[num]):
			print('YES')
			return
		if -num in setn and -num in indexdict and (i > indexdict[-num]):
			print('YES')
			return
		i += 1
	print('NO')
func()


import sys
import os
from io import BytesIO, IOBase

def cel(a, b):
	return (a + b - 1) // b

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

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

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

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

def prr(a, sep=' '):
	print(sep.join(map(str, a)))

def ddi():
	return defaultdict(int)

def ddl():
	return defaultdict(list)

def ddd():
	return defaultdict(defaultdict(int))
BUFSIZE = 8192

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
from collections import defaultdict
from math import gcd, pi, inf
from bisect import bisect_left as bl
from heapq import *

def is_present(a, v):
	idx = bl(a, v)
	return idx < len(a) and a[idx] == v

def solve():
	n = ii()
	a = li()
	d = ddl()
	sorted_list = list(set(a))
	sorted_list.sort()
	a = [0] + a + [0]
	n = len(a)
	pref = [0 for i in range(n)]
	suff = [0 for i in range(n)]
	for i in range(n):
		pref[i] = (pref[i - 1] if i else 0) + a[i]
		if a[i] not in d:
			d[a[i]].extend([i, -1])
	for i in range(n - 1, -1, -1):
		suff[i] = (suff[i + 1] if i < n - 1 else 0) + a[i]
		if d[a[i]][1] == -1:
			d[a[i]][1] = i
	for i in range(1, n):
		(p_sum, s_sum) = (pref[i - 1], suff[i])
		if p_sum == s_sum:
			print('YES')
			return
		to_find = []
		if p_sum > s_sum:
			tmp = p_sum - s_sum
			if not tmp & 1:
				to_find = [tmp // 2]
			for v in to_find:
				if is_present(sorted_list, v):
					(l, r) = d[v]
					if l <= i - 1:
						print('YES')
						return
		else:
			tmp = s_sum - p_sum
			if not tmp & 1:
				to_find = [tmp // 2]
			for v in to_find:
				if is_present(sorted_list, v):
					(l, r) = d[v]
					if r >= i:
						print('YES')
						return
	print('NO')
	return
solve()


n = int(input())
a = list(map(int, input().split()))
s = sum(a)

def solve(a):
	rtn = False
	tmp = 0
	dic = {}
	for i in range(n):
		tmp += a[i]
		dic[a[i]] = True
		if tmp == s // 2:
			rtn = True
			break
		elif s // 2 < tmp and tmp - s // 2 in dic:
			rtn = True
			break
	return rtn
if n == 1 or s % 2 == 1:
	print('NO')
elif solve(a) or solve(list(reversed(a))):
	print('YES')
else:
	print('NO')


import os
import sys
from math import *
from collections import *
from fractions import *
from bisect import *
from heapq import *
from io import BytesIO, IOBase

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

class FastIO(IOBase):
	newlines = 0

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

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

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

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

class IOWrapper(IOBase):

	def __init__(self, file):
		self.buffer = FastIO(file)
		self.flush = self.buffer.flush
		self.writable = self.buffer.writable
		self.write = lambda s: self.buffer.write(s.encode('ascii'))
		self.read = lambda : self.buffer.read().decode('ascii')
		self.readline = lambda : self.buffer.readline().decode('ascii')
(sys.stdin, sys.stdout) = (IOWrapper(sys.stdin), IOWrapper(sys.stdout))
input = lambda : sys.stdin.readline().rstrip('\r\n')
ALPHA = 'abcdefghijklmnopqrstuvwxyz'
M = 10 ** 9 + 7
EPS = 1e-06

def value():
	return tuple(map(int, input().split()))

def array():
	return [int(i) for i in input().split()]

def Int():
	return int(input())

def Str():
	return input()

def arrayS():
	return [i for i in input().split()]
n = Int()
a = array()
tot = sum(a)
C = Counter(a)
cur = defaultdict(int)
cur[a[0]] += 1
s1 = 0
ok = False
for i in range(n):
	s2 = tot - s1
	dif = abs(s2 - s1)
	if s1 == s2 and s1 != 0:
		ok = True
		break
	if s1 > s2 and cur[dif // 2] > 0 and (not dif % 2):
		ok = True
		break
	if s2 > s1 and C[dif // 2] - cur[dif // 2] > 0 and (not dif % 2):
		ok = True
		break
	cur[a[i]] += 1
	s1 += a[i]
if ok:
	print('YES')
else:
	print('NO')


from sys import stdin
from collections import defaultdict as dd
n = int(stdin.readline())
a = list(map(int, stdin.readline().split()))
tot = sum(a)
curs = 0
encntrd = dd(lambda : 0)
flg = False
if tot % 2 == 0:
	tot //= 2
	for i in range(n):
		curs += a[i]
		encntrd[a[i]] = 1
		if encntrd[curs - tot] or curs == tot:
			flg = True
	curs = 0
	encntrd = dd(lambda : 0)
	for i in range(n - 1, -1, -1):
		curs += a[i]
		encntrd[a[i]] = 1
		if encntrd[curs - tot] or curs == tot:
			flg = True
if flg:
	print('YES')
else:
	print('NO')


import sys
n = int(input())
a = [int(i) for i in input().split()]
total = sum(a)
if total % 2 == 1:
	print('NO')
	sys.exit()
part_sum = total // 2
seen = set([0])
sum_so_far = 0
for x in a:
	sum_so_far += x
	seen.add(x)
	if sum_so_far - part_sum in seen:
		print('YES')
		sys.exit()
seen = set([0])
sum_so_far = 0
for x in a[::-1]:
	sum_so_far += x
	seen.add(x)
	if sum_so_far - part_sum in seen:
		print('YES')
		sys.exit()
print('NO')


n = int(input())
a = list(map(int, input().split()))
rev_a = a[::-1]

def main():
	bag = set()
	target = sum(a) / 2
	s = 0
	for i in a:
		bag.add(i)
		s += i
		if s == target:
			print('YES')
			return
		if s > target and s - target in bag:
			print('YES')
			return
	bag = set()
	s = 0
	for i in rev_a:
		bag.add(i)
		s += i
		if s == target:
			print('YES')
			return
		if s > target and s - target in bag:
			print('YES')
			return
	print('NO')
main()


n = int(input())
l = [int(i) for i in input().split()]
tot = sum(l)
if tot & 1:
	print('NO')
	exit()
sm = 0
mid = tot // 2
for i in l:
	sm += i
	if sm == tot - sm:
		print('YES')
		exit()
from collections import defaultdict

def check(l):
	d = defaultdict(int)
	sm = 0
	for i in range(n - 1):
		d[l[i]] += 1
		sm += l[i]
		add = l[i + 1]
		curr = sm + add
		rem = tot - curr
		if d[mid - rem]:
			print('YES')
			exit()
if check(l):
	pass
l = l[::-1]
if check(l):
	pass
print('NO')


def possible(a):
	if len(a) == 1:
		return False
	if len(a) == 2:
		return a[0] == a[1]
	total = sum(a)
	vals = set([a[0]])
	running = a[0]
	for el in a[1:]:
		running += el
		vals.add(el)
		if running == total - running:
			return True
		if (running - (total - running)) % 2 == 0 and (running - (total - running)) // 2 in vals:
			return True
	return False
n = int(input())
a = list(map(int, input().split()))
if possible(a) or possible(a[::-1]):
	print('YES')
else:
	print('NO')


n = int(input())
a = list(map(int, input().split()))
if n == 1:
	print('NO')
	exit(0)
p = 0
left = dict()
right = dict()
s = 0
for i in a:
	right[i] = right.get(i, 0) + 1
	s += i
if s % 2 != 0:
	print('NO')
	exit(0)
s //= 2
for i in range(n + 1):
	if right.get(s - p, 0) > 0 or left.get(p - s, 0) > 0:
		print('YES')
		exit(0)
	if i < n:
		p += a[i]
		right[a[i]] -= 1
		left[a[i]] = left.get(a[i], 0) + 1
print('NO')


def bs(a, be, en, v):
	if be + 1 >= en:
		return False
	while be + 1 < en:
		mid = (be + en) // 2
		if a[mid] == v:
			return True
		elif a[mid] < v:
			be = mid
		else:
			en = mid
	if a[be] == v:
		return True
	return False

def solve(inp, ps, n):
	su = ps[-1]
	if su % 2:
		return False
	su //= 2
	if bs(ps, 0, n, su):
		return True
	for i in range(n):
		if bs(ps, i, n, su + inp[i]):
			return True
	for i in range(n):
		if bs(ps, 0, i, su - inp[i]):
			return True
	return False
n = int(input())
inp = list(map(int, input().split()))
ps = [0] * n
for i in range(n):
	ps[i] = ps[i - 1] + inp[i]
print('YES' if solve(inp, ps, n) else 'NO')


import sys
from bisect import bisect_left as lb
from collections import deque
from queue import PriorityQueue as pq
from math import *
input_ = lambda : sys.stdin.readline().strip('\r\n')
ii = lambda : int(input_())
il = lambda : list(map(int, input_().split()))
ilf = lambda : list(map(float, input_().split()))
ip = lambda : input_()
fi = lambda : float(input_())
ap = lambda ab, bc, cd: ab[bc].append(cd)
li = lambda : list(input_())
pr = lambda x: print(x)
prinT = lambda x: print(x)
f = lambda : sys.stdout.flush()
inv = lambda x: pow(x, mod - 2, mod)
mod = 10 ** 9 + 7
n = ii()
a = il()
s = sum(a)
s1 = s
fl = 0
if s1 % 2 == 1:
	fl = 1
elif a[0] == s1 // 2 or a[-1] == s1 // 2:
	fl = 0
else:
	fl = 1
	for j in range(2):
		d = {}
		t = 0
		for i in range(n):
			d[a[i]] = True
			t += a[i]
			if d.get(t - s1 // 2):
				fl = 0
				break
		if fl == 0:
			break
		a.reverse()
if fl:
	print('NO')
else:
	print('YES')


NO = 'NO'
YES = 'YES'
n = int(input())
if n == 1:
	print(NO)
	exit()
A = list(map(int, input().split()))
if n <= 2:
	if A[0] == A[1]:
		print(YES)
		exit()
	else:
		print(NO)
		exit()
s = sum(A)
if s % 2 == 1:
	print(NO)
	exit()
p = s // 2
o_list = set(A[:2])
o_sum = sum(A[:2])
o_max = max(o_list)
for x in range(2, n):
	o_list.add(A[x])
	o_sum = o_sum + A[x]
	o_max = A[x] if o_max < A[x] else o_max
	if o_sum - p in o_list:
		print(YES)
		exit()
A.reverse()
o_list = set(A[:2])
o_sum = sum(A[:2])
o_max = max(o_list)
for x in range(2, n):
	o_list.add(A[x])
	o_sum = o_sum + A[x]
	o_max = A[x] if o_max < A[x] else o_max
	if o_sum - p in o_list:
		print(YES)
		exit()
print(NO)