We need to parse the problem: We have n apples each weight either 100 or 200. We need to partition them into two subsets with equal total weight. Is it possible?
We need to check if sum of all weights is even? That's necessary. Also because each apple weight is either 100 or 200, we need to see if we can split.
Let c1 = count of 100-weight apples, c2 = count of 200-weight apples. Total sum = 100c1 + 200c2 = 100*(c1 + 2c2). For sum to be even, 100(c1+2c2) is always a multiple of 100, but need sum/2 to be integer? Actually sum must be even so sum/2 is integer. Since sum = 100*(c1+2c2), sum is divisible by 100. For sum to be divisible by 2? But sum/2 must be integer; sum is always divisible by 100, so it's divisible by 2 as long as (c1+2c2)50 is integer? Wait: sum/2 = 50(c1+2c2). For sum/2 to be integer, 50*(c1+2c2) is integer. But that requires (c1+2c2) integer which it is. So sum is always divisible by 2? Actually 100 is even, so 100 * integer is even. So sum is always even? 100 is even, multiply any integer gives even. So sum is always even. But wait: 100 is even, even*any integer = even. So sum is always even. So condition sum even always holds. However, we cannot split apples if we cannot achieve exactly sum/2 with available apples. So need to check if there's a subset with total sum = sum/2.
Given small constraints n <= 100, we could do DP, but we can also reason combinatorially.
Let total = 100c1 + 200c2. Half = 50(c1+2c2). Since apples are multiples of 100, but half may be multiple of 50, not 100. But we can only sum apples of 100 and 200, which are multiples of 100. So half must be a multiple of 100? Actually if we take a set of apples, each apple weight is a multiple of 100, so sum of any subset is a multiple of 100. So half must be a multiple of 100. Therefore we need 50(c1+2c2) % 100 == 0 => (c1+2c2) must be even. That is, c1+2c2 even. Since 2c2 is even, c1 must be even. So condition: number of 100-weight apples must be even. But is that sufficient? Let's check.
If c1 is even, then half = 50(c1+2c2) = 100*(c1/2 + c2) maybe? Actually compute: half = (100c1+200c2)/2 = 50c1 + 100c2 = 100*(c1/2) + 100c2 = 100*(c1/2 + c2) if c1 even. So half is integer multiple of 100. So we need to form subset summing to half = 100*(c1/2 + c2). We have c1 apples of 100 and c2 apples of 200. Each 200 apple is 2*100. So we can think in units of 100: total units = c1 + 2c2. We need to select exactly half of these units: (c1+2c2)/2 units. But we cannot split a 200 apple into separate 100s? Actually we cannot split an apple, but 200 apple contributes 2 units if taken wholly. So the question reduces to: we have c1 items of weight 1 (in 100 units) and c2 items of weight 2. Can we select a subset with total weight exactly (c1+2c2)/2? This is like partition problem with small numbers.
If c1 is even, is it always possible? Not always? Let's test cases.
Case: c1=0, c2=1. Then total sum=200, half=100. But we have only a 200 apple, can't split to get 100. So not possible. c1=0 is even, but impossible because we need exactly 100, but no 100 apple. So additional condition: if c1=0, then we need to be able to sum to half using 200 apples only. Half = 100c2 (since sum=200c2, half=100c2). With only 200 apples, we can only get multiples of 200? Actually if we take k apples of 200, sum = 200k. To get 100c2, we need 200k = 100c2 => 2k = c2 => k = c2/2. So possible only if c2 is even. So if c1=0, we need c2 even.
Case: c1=2, c2=0. Then sum=200, half=100. We have two 100 apples, can take one 100 to get half. Works.
Case: c1=2, c2=1. Sum = 100*2 + 200 = 400, half=200. Can we get 200? Options: one 200; or two 100s. Both possible. So works.
Case: c1=4, c2=1. Sum = 400+200=600, half=300. Need subset sum 300. Options: 200+100? That's 300. So works if at least one 100 and one 200. But if c1=4, c2=1, we have one 200, we can do 200+100. Works. Could there be case where c1 even but impossible? Consider c1=0, c2 odd => half = 100*c2, but c2 odd => half is odd multiple of 100 (like 100,300,...). With only 200 apples, we can only get even multiples of 100 (200,400,...). So impossible. So condition: if c1=0, then c2 must be even.
What about c1=2, c2=2? Sum=200+400=600, half=300. Possible: 200+100, or 100+100+100? But we have only two 100s? Actually c1=2 means two 100s. So possible: take one 200 and one 100 =300, yes.
c1=4, c2=0? half=200, take two 100s or? Actually we have only 100s, need sum 200, so need two 100s. Yes possible.
c1=6, c2=0? half=300, need three 100s, yes possible.
c1=8, c2=0? half=400, need four 100s, yes.
So if c1>0, does it always work? Let's test borderline: c1=2, c2=0 works. c1=2, c2=1 works. c1=2, c2=2 works. c1=2, c2=3? Sum=200+600=800, half=400. Can we make 400? Options: two 200s? That's 400, we have 3 of 200. So yes. Also 200+2*100=400. So yes. c1=2, any c2 works? Possibly yes because we can adjust using 200s. But need to confirm if there is a counterexample where c1 even and >0 but impossible. Suppose c1=2, c2=0 we saw works. Suppose c1=2, c2=0? fine. Suppose c1=2, c2=0? done.
What about c1=4, c2=0? works. c1=4, c2=1 works. c1=4, c2=2 works. So seems if c1>0, we can always achieve? But consider c1=2, c2=0, that's okay. Maybe c1=2, c2=0 is okay. But what about c1=2, c2=0 is the smallest positive even.
What about c1=6, c2=0? half=300, need three 100s, we have six, okay.
What about c1=2, c2=1 we already checked.
But is there case where half requires an odd number of 100 units? Because each 100 apple gives 1 unit, each 200 gives 2. We need to select exactly H = (c1+2c2)/2 units. Since c1 is even, H is integer. We have c1 items of size 1 and c2 items of size 2. We want to know if we can select subset sum H. This is always possible if c1 >= 2? Let's examine parity constraints: The total sum H. Since we have 2-size items, we need to consider modulo something. Actually we can always use 200 apples as pairs of 100s? But we cannot split a 200 apple into two 100s; we either take it or not. However, we can treat the selection as: choose x 200-apples and y 100-apples, then total = 200x + 100y = 100(2x+y). We need 100(2x+y) = half = 100*(c1/2 + c2). So 2x + y = c1/2 + c2.
We have constraints: 0 <= x <= c2, 0 <= y <= c1, and x,y integers. So we need to find integer solution to 2x + y = S where S = c1/2 + c2. Since we can always set y = S - 2x. Need y between 0 and c1 inclusive, and integer. So we need to find x such that 0 <= S - 2x <= c1 and S - 2x integer (automatically if S, x integers). Also x integer between 0 and c2.
So problem reduces to existence of x in [0, c2] such that S - 2x ∈ [0, c1].
Since S = c1/2 + c2.
We need to find x such that: 0 <= c1/2 + c2 - 2x <= c1.
=> lower bound: c1/2 + c2 - 2x >= 0 => 2x <= c1/2 + c2 => x <= (c1/2 + c2)/2 = c1/4 + c2/2.
Upper bound: c1/2 + c2 - 2x <= c1 => -2x <= c1 - (c1/2 + c2) = c1/2 - c2 => 2x >= c2 - c1/2 => x >= (c2 - c1/2)/2 = c2/2 - c1/4.
So we need an integer x satisfying max(0, ceil(c2/2 - c1/4)) <= x <= min(c2, floor(c1/4 + c2/2)). Since x integer, we need that lower bound <= upper bound.
Simplify conditions:
We need existence of integer x in that range.
Let's test edge cases:
Case c1 = 0: then S = 0/2 + c2 = c2. Condition: 0 <= c2 - 2x <= 0 (since c1=0, so y must be exactly 0, because y ≤ c1=0, so y=0). So we need c2 - 2x = 0 => 2x = c2 => x = c2/2 must be integer and between 0 and c2. So c2 must be even. That matches.
Case c1 > 0: Let's see if always possible. Consider c1 = 2, c2 = 0: S = 1 + 0 = 1. Need y = S - 2x. With c2=0, x must be 0. Then y=1, which is ≤ c1=2 and >=0. So works.
c1=2, c2=1: S = 1 + 1 = 2. Need y = 2 - 2x. x can be 0 or 1. For x=0 => y=2, but y must be ≤ c1=2, OK. Also x=1 => y=0, also OK. So works.
c1=2, c2=2: S=1+2=3. x can be 0..2. x=0 => y=3 > c1=2 invalid; x=1 => y=1 valid; x=2 => y=-1 invalid. So x=1 works.
c1=2, c2=3: S=1+3=4. x=0-> y=4 invalid; x=1-> y=2 valid; x=2-> y=0 valid; x=3-> y=-2 invalid. So works.
c1=2, c2=4: S=1+4=5. x=0 y=5 invalid; x=1 y=3 invalid; x=2 y=1 valid; x=3 y=-1 invalid; x=4 y=-3 invalid. So works.
Seems always possible if c1>0? Let's test c1=4, c2=0: S=2+0=2. x=0 -> y=2 valid. works.
c1=4, c2=1: S=2+1=3. x=0-> y=3 valid (<=4) works. x=1-> y=1 also works.
c1=4, c2=2: S=2+2=4. x=0-> y=4 valid; x=1-> y=2; x=2-> y=0. works.
c1=4, c2=3: S=2+3=5. x=0-> y=5 invalid; x=1-> y=3 valid; x=2-> y=1 valid; x=3-> y=-1 invalid. works.
c1=4, c2=4: S=2+4=6. x=0-> y=6 invalid; x=1-> y=4 valid; x=2-> y=2; x=3-> y=0; all fine.
c1=6, c2=0: S=3+0=3. x=0-> y=3 <=6 works.
c1=6, c2=1: S=3+1=4. x=0-> y=4 <=6 works.
c1=6, c2=2: S=3+2=5. x=0-> y=5 <=6; x=1-> y=3; x=2-> y=1; works.
c1=6, c2=3: S=3+3=6. x=0-> y=6 <=6; x=1-> y=4; x=2-> y=2; x=3-> y=0; works.
c1=6, c2=4: S=3+4=7. x=0-> y=7 >6 invalid; x=1-> y=5 <=6; x=2-> y=3; x=3-> y=1; x=4-> y=-1; works.
c1=6, c2=5: S=3+5=8. x=0 y=8 invalid; x=1 y=6 valid; x=2 y=4; x=3 y=2; x=4 y=0; x=5 y=-2 invalid. works.
c1=6, c2=6: S=3+6=9. x=0 y=9 invalid; x=1 y=7 invalid; x=2 y=5 valid; x=3 y=3; x=4 y=1; x=5 y=-1; x=6 y=-3. works.
So far always possible.
But is there any case with c1>0 even that fails? Let's check extremes: c1 very large, c2=0: works if c1 >= half requirement which is c1/2, obviously we can take that many 100s.
c1=2, c2 huge? We already saw that with c2=2 works, c2=3 works, etc. The condition we derived is that we need an integer x between lower and upper bounds. Let's see if there always exists an integer in that interval for c1>0 even.
Let's analyze interval: L = max(0, ceil(c2/2 - c1/4)), U = min(c2, floor(c1/4 + c2/2)). We need L <= U.
Simplify: Let's denote a = c1/4, b = c2/2. Then L = max(0, ceil(b - a)), U = min(2b, floor(a + b)) because c2 = 2b? Actually c2 is integer, but b = c2/2 may not be integer if c2 odd. But careful: c2/2 could be fractional. Let's treat directly with integers.
Better approach: We can prove necessary and sufficient condition is: c1 > 0 or (c1 == 0 and c2 even). Actually, I recall a known Codeforces problem (Kitahara Haruki's Gift) - I think solution is: count number of 100 and 200. If total sum not divisible by 200? Wait, typical solution: If sum % 200 != 0 -> NO? But sum always divisible by 200? Actually sum = 100*(c1+2c2). For equal division, half must be integer and achievable. I remember the solution: count 100 and 200. If sum % 200 != 0 -> No? But sum%200 = (100*(c1+2c2)) %200 = 0 if (c1+2c2) even? Because 100even = multiple of 200? Actually 100 * k is multiple of 200 iff k is even. So sum % 200 = 0 iff (c1+2c2) even => c1 even. So sum divisible by 200 is equivalent to c1 even. But is that necessary? Actually half = sum/2 = 100(c1+2c2)/2 = 50*(c1+2c2). For half to be representable as sum of 100 and 200, half must be a multiple of 100? Not necessarily: if we have both types, the sum of apples is multiple of 100, but could half be 50 mod 100? No, because each apple is 100 or 200, sum of any subset is multiple of 100. So half must be multiple of 100. Hence 50*(c1+2c2) % 100 == 0 => (c1+2c2) even => c1 even. So indeed c1 must be even. That's necessary.
But also we need to be able to form half. So c1 even is necessary but not sufficient when c1=0? Actually c1=0 => c1 even, but we need also c2 even? Wait if c1=0, then c1 even holds, but half = 100*c2 (since sum=200c2, half=100c2). Can we get 100c2 with c2 apples of weight 200? To get 100c2, we need to use a combination of 200 apples. The total sum we can get from 200 apples is multiples of 200. So to get 100c2, we need 100c2 to be multiple of 200 => c2 even. So if c1=0, need c2 even. If c1>0, does c1 even guarantee existence? Let's try to find a counterexample. Consider c1=2, c2=0 we already did, works. c1=2, c2=1 works. c1=2, c2=2 works. c1=2, c2=3 works. c1=2, c2=4 works. So seems okay.
But what about c1=4, c2=1? Works. c1=4, c2=0? Works. c1=4, c2=2 works. So maybe indeed the condition is: If c1 == 0, then answer YES iff c2 % 2 == 0. If c1 > 0, then answer YES iff c1 % 2 == 0? But wait: what about c1=0 and c2=0? That is n=0? But n>=1, so ignore. But if n=1, c1=1, c2=0: c1 odd, sum=100, half=50, not possible because cannot get 50. So answer NO. So that's consistent: c1 odd => NO.
But what about c1 even but large c2? Should always work. Let's try to find a potential failure: Suppose c1=2, c2=0 works. c1=2, c2=1 works. c1=2, c2=100 works? S = 1+100=101. Need y = 101 - 2x with 0<=x<=100, 0<=y<=2. So we need to find x such that 101 - 2x is 0,1,2. That is, 2x = 101 - y. For y=1, 2x=100 => x=50, valid. So works. So indeed we can always find an x such that y=1 or 0 or 2. Because the parity: S and c1 even? Actually c1 even gives S integer. The equation y = S - 2x. Since S and 2x have same parity? 2x even, so y has same parity as S. S = c1/2 + c2. c1/2 integer, c2 integer, so S integer. Parity of S? Not needed. y must be between 0 and c1. We can vary x to adjust y. Essentially we need to find x such that S - 2x ∈ [0, c1]. That is equivalent to: 2x ∈ [S - c1, S]. Since x integer 0..c2. So we need an integer x in that interval (divided by 2). This is always possible if the interval length is at least 1? Actually the interval [S - c1, S] length = c1. So as long as there exists some even number (multiple of 2) in that interval that is twice an integer between 0 and c2. But we need x integer such that 2x ∈ [S - c1, S]. So we need the set {2x : x = 0..c2} to intersect [S - c1, S]. Since the step size is 2, the set of possible 2x values is all even numbers from 0 to 2c2. So we need an even number in [S - c1, S] that is also ≤ 2c2. Since S = c1/2 + c2, then S - c1 = c1/2 + c2 - c1 = c2 - c1/2. So interval is [c2 - c1/2, c1/2 + c2]. That is symmetric around c2? Actually length c1. So lower bound = c2 - c1/2, upper = c2 + c1/2. So we need an even integer in [c2 - c1/2, c2 + c1/2] that is also between 0 and 2c2 inclusive.
Since c1 > 0 even, c1/2 is integer. So the interval is from c2 - d to c2 + d where d = c1/2 (integer). So it's centered at c2, length 2d = c1. We need an even integer within ±d of c2. Also note that c2 itself may be integer. If c2 is integer, then c2 is an integer. But we need an even integer, i.e., multiple of 2. So if c2 is even, then c2 is even and lies in the interval, and also 2x = c2? But 2x must equal some even number; if we set x = c2/2, then 2x = c2. But is x ≤ c2? Yes, c2/2 ≤ c2 if c2 >=0. Also x>=0. So that gives y = S - c2 = (c1/2 + c2) - c2 = c1/2, which is between 0 and c1? Since c1/2 <= c1 obviously (c1>=2 => c1/2 <= c1). Also y>=0. So if c2 is even, we can set x = c2/2, y = c1/2. That works! Because y = c1/2 ≤ c1. And x = c2/2 ≤ c2. So that's a valid solution.
If c2 is odd, then c2 is odd. Then c2 is not even. But we can try x = (c2-1)/2 or (c2+1)/2? Let's check: If we take x = floor(c2/2) = (c2-1)/2 (since odd), then 2x = c2-1, which is even. Then y = S - (c2-1) = (c1/2 + c2) - (c2-1) = c1/2 + 1. That y must be ≤ c1, so we need c1/2 + 1 ≤ c1 => 1 ≤ c1/2 => c1 >= 2. Also y >= 0. So if c1 >= 2, then y = c1/2+1 is within [0, c1]? Need also y <= c1, which holds if c1/2+1 <= c1 => 1 <= c1/2 => c1 >= 2. So for c1 >= 2, this works. What if c1 = 0? Then we are in the case c1=0 and c2 odd, but we already said need c2 even. So for c1>0, c1 even, c2 odd, we can set x = (c2-1)/2, y = c1/2+1, provided y ≤ c1. Since c1/2+1 ≤ c1 iff c1 ≥ 2. If c1 = 2, then y = 2/2+1 = 2, which equals c1, ok. So works. If c1=2, c2 odd, we get y=2. But note y cannot exceed c1=2, okay. So indeed for any even c1 >= 2, we can always find a solution: if c2 even, x = c2/2, y = c1/2; if c2 odd, x = (c2-1)/2, y = c1/2 + 1 (provided c1/2+1 <= c1, which holds for c1>=2). But what about c1=0? Then even but need separate case.
Thus, the answer: YES if (c1 % 2 == 0 and (c1 > 0 or c2 % 2 == 0)). Actually if c1 == 0, need c2 even. If c1 > 0 and c1 even, answer YES. If c1 odd, answer NO. But is there any case where c1 even but c1 == 0? That's already covered: c1 == 0 => even, but need c2 even. So overall: If c1 == 0: answer YES iff c2 % 2 == 0; Else (c1 > 0): answer YES iff c1 % 2 == 0? Let's test c1=2, c2=0 works -> c2 even? But we said if c1>0 and c1 even, answer YES. c2=0 even, but even if c2 odd, we said works. So condition for c1>0 is simply c1 even. But what about c1=0 and c2 even -> YES; c1=0 and c2 odd -> NO. So we can combine: The answer is YES if (c1 % 2 == 0) and (c1 > 0 or c2 % 2 == 0). However note: when c1>0 and c1 even, the second condition (c1>0) automatically true regardless of c2 parity. So we can simplify: answer YES if (c1 % 2 == 0) and (c1 != 0 || c2 % 2 == 0). But if c1==0, then c2%2==0 must hold. So yes.
But can we also have c1 odd but possible? If c1 odd, sum = 100*(odd + 2c2) = 100*(odd+even) = 100odd, sum/2 = 50odd, which is not multiple of 100, so cannot be achieved because any subset sum is multiple of 100. So NO when c1 odd. So condition is necessary.
So final solution: Count number of 100-weight apples = count100, number of 200-weight apples = count200. If count100 % 2 == 1, print "NO". Else (count100 even): if count100 == 0: if count200 % 2 == 0 print "YES" else "NO"; else print "YES". Because if count100 even and >0, always YES. This matches known editorial.
Double-check borderline: n=1, weight 100: count100=1 odd => NO. Correct (can't split into two equal sums). n=1, weight 200: count100=0 even, count200=1 odd => count100==0 and count200%2 !=0 => NO. Indeed can't split one 200 apple into two equal parts.
n=2, both 200: count100=0, count200=2 even => YES? Two apples of 200 each, total 400, half 200, can give one apple to each -> YES. So condition yields YES.
n=2, both 100: count100=2 even, count100>0 => YES (give one each). n=2, one 100 and one 200: count100=1 odd => NO? total 300, half 150, impossible. So NO.
n=3: 100,200,100 => count100=2 even>0 => YES. That's sample.
n=4: 100,100,100,200 => count100=3 odd => NO. That's sample.
All consistent.
Thus implementation: read n, read list, count100 = number of 100, count200 = number of 200. Then if count100 % 2 != 0: print NO; else: if count100 == 0 and count200 % 2 != 0: print NO; else print YES.
Alternative: print YES if (count100 % 2 == 0 and (count100 > 0 or count200 % 2 == 0)) else NO.
Now we'll code accordingly.
Now to produce answer: We'll write Python solution with input reading.
Edge cases: n up to 100, but that's fine.
Let's craft final answer.
Will produce solution with function solve() that reads from sys.stdin.
Now produce final output.
But we must be careful: The problem statement says "Kitahara Haruki has bought n apples ... Now he wants to divide all the apples between the friends." So all apples must be used? Yes, we must allocate all apples to the two friends. So we need partition into two subsets (not necessarily covering all apples? Actually "divide all the apples between his friends" suggests each apple goes to one friend, so partition of the set. So yes, all apples must be assigned, and total weight of each friend must be equal. So our reasoning stands.
Thus final answer.
Now I'll produce final. ```python
import sys
def solve() -> None:
data = sys.stdin.read().strip().split()
if not data:
return
n = int(data[0])
weights = list(map(int, data[1:1 + n]))
cnt100 = weights.count(100)
cnt200 = weights.count(200)
if cnt100 % 2 == 1:
print("NO")
else:
if cnt100 == 0 and cnt200 % 2 == 1:
print("NO")
else:
print("YES")
if name == "main":
solve()