We need to determine whether through a sequence of operations we can reduce N integers to a single integer. The operation: select two integers with same parity (both even or both odd), erase them, and write their sum. So we replace two numbers with their sum, which is even+even=even, odd+odd=even. So the parity of the sum: if both are even, sum is even; if both are odd, sum is even (since odd+odd=even). So after any operation, the new number is always even. So the parity of the new number is always even. But note: we could later use that even number with another even number to produce an even sum, etc. So eventually all numbers become even? Not necessarily, because we might still have odd numbers left that haven't been paired. But to pair odd numbers, they must be paired with another odd number. After pairing two odds, we get an even. So odds can be eliminated by pairing them together. But the number of odds must be even to pair them all. However, there may be more complicated sequences: we might combine odds together to produce evens, then combine evens with evens, etc. The operation is associative in some sense, but we need to see if we can reduce to one number regardless of order. Let's analyze.
We have multiset of integers. Each operation reduces count by 1 (since we remove two and add one). So after N-1 operations we have one number. The order matters: we need to be able to perform operations such that at each step we can find two numbers with same parity.
We can think about parity constraints. Since the operation always produces an even number, the parity of numbers changes. Initially we have some count of odds and evens. Let O = number of odds, E = number of evens.
When we combine two odds: O decreases by 2 (since we remove two odds), and we add an even, so E increases by 1. So O → O-2, E → E+1.
When we combine two evens: E decreases by 2, and we add an even (since even+even=even), so E → E-1? Actually: remove two evens, add one even, so net change: E decreases by 1 (since we lost two and gained one: -2+1 = -1). O unchanged.
Thus the parity count dynamics:
- odd-odd operation: (O, E) → (O-2, E+1)
- even-even operation: (O, E) → (O, E-1)
Can we combine odd with even? Not allowed because parity must be same. So only those two operations.
Goal: to reach (O,E) = (0,1) or (1,0) or maybe (anything,1) but with one number left, we have one number. If we end with one number, its parity could be even or odd? Wait: can we end with an odd? The only way to produce an odd number is if the final number was originally odd and never paired? But if we have a single odd initially, we could never pair it because we need same parity pair. However, we could combine two odds to get an even, which is even. So the only way to have a final odd number is if we never modify that odd number and end with it alone. But can that happen? For a single odd to survive, we must eliminate all other numbers. But to eliminate others, we need to pair numbers. If there is at least one odd left, to pair it we need another odd. So if we have exactly one odd at some point, it cannot be paired; we would need to combine it with something else. But can we combine it with an even? No, not allowed. So the odd would remain alone only if we can eliminate all other numbers and the odd remains. But eliminating all other numbers means we combine them into one number. Then we would have two numbers: the odd and the combined other (which might be even). Then we cannot pair them because parity differ. So we cannot reduce to one. Therefore, final number must be even. Unless N=1? But N>=2. So final number must be even. But is it possible that we have an odd final number from some combination? Let's see: operations always output even, so any number created by operation is even. The only odd numbers are those initially odd and never used. So if we ever use an odd number in an operation, it is removed (paired with another odd). So if we have any odd number in the final single number, that means that odd was never used and all other numbers were combined into something (maybe even) and then we attempted to combine that odd with something else but can't. So not possible. Hence final number must be even. So the condition for possibility is that we can reduce to a single even number.
Now, we need to determine if there exists a sequence of operations to reduce to one number. This is similar to a game where we manipulate counts.
Observation: The operation reduces total count by 1. So we will perform N-1 operations. The parity transitions are as above.
We can view the process as building a binary tree of sums, where each internal node corresponds to sum of its two children, and we require that the two children have same parity. The root is the final number.
Given the leaves are initial numbers. We need to decide if there exists a full binary tree (with N leaves) such that at each internal node, the two children have same parity, and the value at the node is the sum of children (but value is determined by sum of leaves, not just parity). However, the parity condition only depends on the parity of the children values. As we combine, the values become large, but parity is determined solely by the sum of parities: sum of two evens is even; sum of two odds is even. So the parity of any internal node is even if both children are same parity (since either both even => even, both odd => even). Wait, both odd produce even, so all internal nodes are even. So the only nodes that can be odd are leaves that never get combined? But all leaves get combined eventually. Actually, in the tree, all leaves are initial numbers. They may be odd or even. Internal nodes are sums, hence even. So the root is even. So the tree must have the property that at each internal node, the two children have the same parity (both even or both odd). Since all internal nodes are even, it means that for any internal node, its two children can be either both even or both odd. But if a child is an internal node, it's even; so the other child must also be even. So for any internal node that has an internal node as a child, the other child must be even as well. That means that if we ever combine an internal (even) node with another node, that other node must be even. So after the first operation, we have an even node. Thereafter, we can only combine that even node with other even nodes. Because if we combine an even node with an odd node, parity differs => not allowed. So once we create an even number (which happens in the first operation, since any operation produces even), from that point onward, we cannot pair that even number with an odd number. So all further operations must involve even numbers only, or odd-odd pairings among remaining odds that haven't been used.
Thus the process can be described: Initially we have O odds, E evens. We can repeatedly do one of two operations: combine two odds (producing an even) or combine two evens (producing an even). But note: after we produce an even from odds, that even can then be used in even-even operations.
Important: The even numbers from odds are indistinguishable from original evens for parity purposes. So the process is like: we have a pool of evens (including those generated from odd-odd merges), and odds. We can only combine evens with evens, and odds with odds.
Goal: Reduce to 1 even.
This is similar to checking if we can reduce the count to 1 using these moves.
We need to see if there's an order that avoids getting stuck (i.e., no two numbers of same parity exist when more than 1 number left).
One necessary condition: The total number of odds must be even? Because to eliminate all odds, we need to pair them up. Each odd-odd operation consumes 2 odds and produces 1 even. So if O is odd, we will end up with at least 1 odd left after pairing all possible odds (since we can pair odds only in pairs). If O is odd, after using all pairs we have 1 odd remaining. At that point, all other numbers are even (since we may have evens from original and from pairings). Then we would have at least one odd and some evens. Since odd can't pair with even, we cannot eliminate that odd. However, could we have avoided creating that situation by merging odds with evens? Not allowed. Could we combine the odd with something else by first converting some evens into something odd? But operations always produce evens, so we cannot produce odd. So the odd remains odd forever. So we cannot have final single number if O is odd. Therefore, O must be even.
Is that sufficient? Let's test: Example 1: N=3, numbers 1,2,3 -> O=2 (odd? actually 1 and 3 are odd, 2 is even: O=2 even), E=1. Output YES. Example 2: N=5, 1,2,3,4,5 -> O=3 (odd), E=2 => NO, matches.
But consider other cases: N=2: both numbers. If both have same parity, we can combine them and get one number. So O even? For two odds, O=2 even => YES. For two evens, O=0 even => YES. For one odd one even: O=1 odd => NO. So for N=2, is it always YES when parity same? Yes. And our condition O even? If O=0 (both even) => even; O=2 => even; O=1 => odd => NO. So matches.
But is there any case where O even but still impossible? Let's test with N=4. Suppose we have 4 odds: O=4, E=0. We can pair two odds -> even, then we have: 1 even (from pair) + 2 odds left = total numbers: 3 (2 odds, 1 even). Now we have 2 odds and 1 even. Can we reduce to one? Options: we can pair the two odds -> even, then we have 2 evens (the previous even and the new even) -> then pair the two evens -> even, final one. So yes. So O=4 works.
Now O=2, E=2? Example: odds: 1,3; evens: 2,4. Can we? Options: we could pair odds -> even (4). Then we have evens: 2,4,4 (three evens). Then we can pair two evens -> even (e.g., 2+4=6), then we have two evens (6 and 4) -> pair them -> 10. So yes.
O=2, E=1? N=3 we saw works.
O=0, all evens: always works? Let's test: all evens, we can repeatedly pair evens. Since evens combine to even, we can always reduce to one even. So yes.
O=2, E=0? That's N=2, works.
O=6, E=1? N=7. Let's test: O=6, E=1. Steps: Pair odds repeatedly. After pairing 2 odds -> even, left O=4, E=2 (original even + new even). Pair another two odds -> even, left O=2, E=3. Pair another two odds -> even, left O=0, E=4. Then pair evens down to one. So works.
Seems O even always works? But need to be cautious: there might be a scenario where after some operations, we get stuck with one odd and one even, but O was even initially. Could that happen? Suppose O=2, E=1. Steps: If we first pair the two odds -> even, then we have evens: E becomes 2 (original even + new even). Then we have two evens, can combine to one even. So works. If we first pair evens? But we have only one even, so can't pair evens. So only move is pair odds. So always can.
What about O=2, E=2? We can do many orders. Could we get stuck? Suppose we pair evens first: combine two evens -> even, then we have odds: 2 odds, evens: 1 (from pair) + 1 original? Wait, initially evens: two evens, after pairing them we get one even. So state: O=2, E=1 (since one even from original? Actually careful: initial: E=2, O=2. If we pair evens, we remove 2 evens, add 1 even, so net: E=1, O=2. Then we have 2 odds, 1 even. Then we can pair odds -> even, then state: E becomes 2 (original even + new even) -> then pair evens -> one. So okay.
If we pair an odd with an even? Not allowed.
Thus O even seems sufficient.
But is there any subtlety regarding the count of numbers? Let's think about the process more formally. We have multiset of numbers. Define the parity vector. The operation reduces total count by 1. At any time, if there is at least two numbers of same parity, we can perform an operation. We need to see if we can eventually reduce to one. This is essentially a game where we need to avoid a deadlock where there is more than one number but no two share the same parity. That deadlock state would be: some numbers, but all numbers have distinct parity? Actually parity only has two types: even and odd. So deadlock occurs when we have exactly one even and one odd, and no other numbers. Because then the two numbers have different parity, cannot combine. Also could be state with 1 number only (success). If we have more than 2 numbers, could there be a situation where no two have same parity? Since there are only two parities, if we have at least 3 numbers, by pigeonhole principle, at least two share the same parity (if we have at least 3, either at least two evens or at least two odds). Because if we have at least 3 numbers, it's impossible to have at most one of each parity: that would max 2 numbers. So deadlock can only occur when exactly 2 numbers of opposite parity. So the only failure mode is ending with exactly 1 even and 1 odd.
Thus the question reduces to: can we avoid ending with 1 even and 1 odd after performing N-1 operations? Because if we succeed, we have one number; if we get stuck earlier, we cannot proceed. But the process is not forced; we can choose operations. So we need to know if there exists a sequence of N-1 operations that never gets stuck. Since we can choose order, the only obstacle is if it's inevitable that we eventually have 1 even and 1 odd.
Let's analyze necessary and sufficient condition.
Observation: The parity of the total sum? Not directly.
Let O and E be initial counts.
Each operation:
- odd-odd: reduces O by 2, increases E by 1. Total count decreases by 1.
- even-even: reduces E by 1 (since -2+1). Total count decreases by 1.
The process stops when count=1. We need to avoid the state (O=1, E=1) at any point with count=2. But could we encounter (O=1, E=1) earlier when count >2? Actually count=2 is the only case where we might have (1,1). At larger counts, we always have at least 2 of same parity, so we can continue.
So the question is: can we perform a series of operations such that when we reach count=2, we have either (O=2, E=0) or (O=0, E=2)? Because (2,0) both odds -> can combine to even -> final one; (0,2) both evens -> combine to even -> final one; also (O=0, E=2) is fine. Actually (2,0) yields both odds, which can combine (since both odd) to even, giving final one. So the allowed terminal states for count=2 are both same parity. And after that operation we get one number. So we need to ensure that we can end with two numbers of same parity.
Now, can we ever end with (O=2, E=0) if initially O is even? Possibly.
But also note: after operations, all numbers become even eventually? Let's simulate: If we end with two odds, they will combine to even. So final single is even.
Thus condition seems to be that O is even.
But consider a case where O is even but E is 0? Then we start with all odds. We can pair odds, producing evens, and eventually we can reduce. But what about N=2 with O=2 works. For N=4 O=4 works. So yes.
But is there any scenario where O even but we might be forced into (1,1) because of the order? Let's see if we can construct a sequence that leads to (1,1) despite O even. That would imply some choice leads to deadlock, but we can avoid that by making different choices. Since we can choose operations, we want to know if there exists at least one sequence that avoids deadlock. So we need to see if it's always possible to avoid (1,1) when O is even.
We can attempt to prove sufficiency: If O is even, we can always reduce to one.
Strategy: While there is more than 1 number:
- If there are at least 2 odds, pair two odds.
- Else (i.e., O <= 1), then there must be at least 2 evens (since total count >=2). Pair two evens.
We need to verify that this strategy never gets stuck and terminates with one number. Let's simulate.
Start with O even.
Case: If O >= 2, we pair two odds. This reduces O by 2 and increases E by 1. Since O is even, after each odd-odd operation, O remains even? Initially O even. After subtracting 2, O stays even. So O parity remains even throughout as long as we only do odd-odd operations when O>=2. When O becomes 0, we have only evens, then we just pair evens until one remains. But what if after some odd-odd operations O becomes 2, and then we have many evens. The strategy says: if O >=2, still pair odds. So if O=2, we pair those two odds. This will turn them into an even, making O=0, E increases by 1. Then all evens, proceed.
Now, what about scenario where O=0 initially? Then all evens, trivial.
What about scenario where O=0 but later? Fine.
What about scenario where O=1 at some point? Can that happen under this strategy? Since we only pair odds when O>=2, and we start with O even, O will always be even after each odd-odd operation. So O remains even throughout. Thus O never becomes 1. So we never have a situation with exactly 1 odd. When O eventually becomes 0, we have only evens. When we get down to 2 numbers, if O=0 and E=2, we can combine them. If O=2 and E=0? But O would be 2 only if we haven't paired them yet; but if O=2 and E=0, that's N=2 case; we can combine them. So the strategy works.
But is it always possible to pair evens when needed? When O < 2, we rely on there being at least 2 evens to pair. Could it happen that O=0 and E=1 but count>1? No, because total count >=2, if O=0 and E=1, count=1. So not. If O=0 and total count >=2, then E >=2, so we can pair evens. If O=1? Under the strategy, we avoid O=1. So safe.
Thus sufficiency: if O is even, it's possible.
Now consider O odd. Is it always impossible? Let's try to see if there could be a tricky sequence that results in one number despite O odd. For instance, could we combine evens in such a way that an odd number becomes even? No, because only way to change parity of a number is to combine it with another same parity to produce even. But an odd alone cannot change parity; it must be paired with another odd. So if O is odd, at least one odd will remain forever. Since final number must be even, we must eliminate all odds. But if O is odd, it's impossible to eliminate all odds because each operation consumes odds in pairs. So at least one odd will remain. Could that odd be the final single number? No, because final number must be even (since if it's odd, there would be an odd left, but could it be the only one? Possibly, if we end with just that odd. But can we end with a single odd? The final number is the result of operations, but if we never use that odd in any operation, we would have to combine all other numbers into one number, and then we would have two numbers: that odd and the combined even. Then we cannot combine them, so we can't reduce to one. So we cannot end with a single odd unless N=1 initially. Since N>=2, we must perform N-1 operations, meaning all numbers must be involved in operations; every number must eventually be erased and replaced by sums. Actually is it possible that an odd number is never erased? In the process, we start with N numbers. We perform operations that replace two numbers with one. Over N-1 operations, the final number is some combination (sum) of all initial numbers. Therefore, every initial number contributes to the final sum. So every number is used at some point. So an odd number will be included in some sum. But when it's used, it must be paired with another odd (since odd+even not allowed). So that uses two odds. So if total number of odds is odd, one odd must be left unpaired? But eventually all numbers are used because the final sum includes all numbers. However, the final sum is the result of repeatedly adding numbers with the rule that each addition is between two numbers of same parity. So the final sum is the sum of all numbers, but the order of addition must respect parity constraints. So if O is odd, can we still arrange the additions such that all odds are paired? Let's think about constructing a binary tree where leaves are numbers. The condition at each internal node is that its two children have same parity. The root's value is sum of all leaves (the total sum). The parity of root is even (since sum of odds if O odd? Actually total sum parity = parity of number of odds (since sum of odds mod 2 = O mod 2). If O is odd, total sum is odd. But earlier we argued root must be even because any internal node is even. Wait contradiction! Let's re-evaluate: internal node is sum of its two children. If both children are even, sum is even; if both children are odd, sum is even. So indeed any internal node (non-leaf) is even. That means the root (final number) must be even. But the total sum of all numbers is the sum of all leaves. The root is the sum of all leaves. So the root's parity equals the parity of the total sum. Therefore, if the total sum is odd, root would be odd, which is impossible under the parity constraints. Therefore, a necessary condition is that the total sum of all numbers is even. Since sum parity = O mod 2, this implies O must be even. So indeed O even is necessary.
Thus the necessary and sufficient condition is: O is even.
But wait, is there any additional nuance? Could there be a scenario where total sum is even but O is odd? No, because O mod 2 determines sum parity. So O even iff total sum even. So condition is exactly that total sum is even.
But is total sum even sufficient? Let's test with a counterexample perhaps: N=3, numbers 2,4,6 (all evens). O=0 even, total sum even. Works. N=3, numbers 1,1,2: O=2 even, total sum 4 even. Works? Let's try: odds: 1,1; even:2. Pair odds -> 2; now we have evens: 2,2 -> pair ->4. Works. N=4, numbers 1,1,1,1: O=4 even, sum=4 even. Pair odds -> 2,2 -> pair ->4. Works.
Now consider N=5, numbers 1,1,1,1,2: O=4 even, sum=6 even. Should be YES according to condition. Let's test: odds: 4 odds; evens:1. Strategy: pair odds repeatedly. Pair two odds -> even (2). Now state: O=2, E=2 (original even 2 and new even 2). Pair odds -> even (2). Now state: O=0, E=3 (two evens from earlier? Let's track: After first pair: O=2 (remaining odds), E=2 (original 2 + new 2). After second pair: we pair the two odds -> even (2). Then O=0, E becomes previous E=2 plus 1 = 3? Actually careful: before second odd-odd, we had numbers: two odds (1,1), and two evens (2,2). After pairing the two odds, we remove the two odds and add their sum 2, so we now have evens: the previous two evens (2,2) plus new even (2) = three evens. So yes O=0, E=3. Then we can pair two evens -> even (4), then we have two evens (4 and the remaining 2) -> pair ->6. So works.
Now consider N=5, numbers 1,1,2,2,4? O=2 even, sum=10 even. Works.
What about N=5, numbers 1,3,5,7,9: O=5 odd, sum=25 odd => NO.
Thus condition seems correct.
But wait, are there any constraints about the values being too large? No.
Edge case: N large, O even.
Thus answer: print YES if number of odd numbers is even, else NO.
But we must double-check that the total sum even is indeed necessary from the parity argument of the root. Let's formalize: Each operation selects two numbers of same parity and replaces with their sum. We claim by induction that after any number of operations, the parity of the sum of all numbers on the blackboard is invariant. Because initially sum S = sum of all A_i. Operation: remove A_i and A_j, add A_i+A_j. The sum remains same. So total sum is invariant. At the end, when there is one number X, we have X = S. So X = S. But also we argued that X must be even? Actually we argued that X must be even because it's the result of operations. But is it necessarily even? Let's check: If we have one number left, it could be odd if we never performed any operation? But we performed N-1 operations, each operation produces a number that is sum of two numbers of same parity. As argued, sum of two evens is even; sum of two odds is even. So every number produced by an operation is even. However, the final number is the result of the last operation, which is a sum of two numbers of same parity, so it's even. Therefore X must be even. So we have S = X even. Therefore S must be even. So necessary condition: total sum even.
Thus answer is YES iff total sum is even.
But is it possible that the final number is odd? Could there be a scenario where we have one odd number left without performing an operation on it? But we have to perform exactly N-1 operations to reduce from N to 1. Each operation reduces count by 1. If we ever have an odd number that is never used as an operand in any operation, then it must survive to the final number. But then the final number is that odd number itself (or maybe it gets summed later?). Wait: Suppose we have a leaf that never gets combined? But in the process of reducing to one number, every initial number must be included in some operation. Because we start with N numbers. Each operation merges two numbers into one, so after k operations we have N-k numbers. To have one number, we need N-1 operations. The set of numbers at each step are either original numbers that haven't been merged yet or sums. Each original number either remains unmerged until it eventually gets merged in some operation. There's no way to have an original number survive to the end without being merged, because then the final number would be that original number alone, but that would imply that all other numbers were merged into something else, leaving two numbers: the original number and the merged sum, and then we would need one more operation to combine them, but that operation would involve the original number. So it would be used. So every original number is used in some operation. So the final number is a sum of all original numbers, possibly with some grouping. So it's the total sum S. So final number is S.
Now, consider an operation where we combine two odds to get an even. So after that operation, the result is even. So any number created by operation is even. The original numbers may be odd or even. So as we build the binary tree, the leaves are original numbers, internal nodes are even. The root is the sum of all leaves, which is even because all internal nodes are even? Actually careful: The root is the final sum of all leaves, but it is also an internal node (unless N=1). Since it's an internal node, it must be even (by the argument that any sum of two same-parity numbers is even). So root must be even. But is it possible that root is even even if total sum is odd? No, because root equals total sum. So total sum must be even. So condition is necessary.
Now, is total sum even sufficient? We gave a constructive strategy: always combine two odds if possible, else combine two evens. This will succeed if total sum even (i.e., O even). But does it always work when O even? Let's prove more formally:
We have O even. We maintain invariant that the number of odds remains even after each operation. Initially O even. Operation types:
- odd-odd: O → O-2 (even if O even)
- even-even: O unchanged (since O unchanged). So O remains even throughout.
When count > 1, we need to show there exists a legal move. If O >= 2, we can do odd-odd. If O = 0, then all numbers are even, and since count > 1, there are at least 2 evens, so we can do even-even. If O = 0 is even. Could O be 0 when count>1? Yes. So we always have a move as long as count>1. The only potential problematic case is O=2 and count=2? That is (O=2, E=0). Then we can do odd-odd, which reduces to one number. So fine. O=0 and count=2: even-even works. So the process can always continue until count=1. Therefore, we can reduce to one number.
Thus sufficiency holds.
So answer is simply check if number of odd integers is even.
Implementation: read N, read list, count odds, if count % 2 == 0 print YES else NO.
But wait, there's a nuance: The operation says "select a pair of integers, A_i and A_j, that have the same parity and erase them. Then write a new integer equal to the sum." It doesn't say we cannot select the same integer twice? Obviously they must be distinct indices. So it's fine.
Thus solution is straightforward.
But before finalizing, let's check sample inputs:
Sample 1: 1 2 3 -> odds: 1,3 => count 2 even => YES.
Sample 2: 1 2 3 4 5 -> odds: 1,3,5 => 3 odd => NO.
Matches.
Now consider a tricky case: N=2: 2,4 (both even) => odds=0 even => YES. Operation: 2+4=6 => one number. Yes.
N=2: 1,3 (both odd) => odds=2 even => YES: 1+3=4 => one even. Yes.
N=2: 1,2 => odds=1 odd => NO. Indeed cannot combine because parities differ.
Another case: N=3: 2,4,6 => all even => YES.
N=3: 1,4,7 => odds:1,7? Actually 1 and 7 odd, 4 even => O=2 even => YES. Can we? Pair odds: 1+7=8 (even). Now have 8 and 4 -> both even, combine ->12. Yes.
N=3: 1,3,5 => all odd, O=3 odd => total sum=9 odd => according to condition NO. Let's test: we have three odds. Pair any two odds: say 1+3=4 (even). Now we have 4 and 5 (odd). Parities differ, cannot combine. So stuck with two numbers. So indeed NO. So condition holds.
But what about N=4: 1,1,1,3? O=4 even, sum=6 even => YES? Let's test: Pair 1+1=2; now have 2,1,3 -> odds:1,3; even:2. Pair odds 1+3=4; now have 2 and 4 -> both even, combine ->6. Yes. Works.
What about N=4: 1,1,2,4? O=2 even, sum=8 even => YES.
Now consider N=5: 1,1,1,1,1? O=5 odd, sum=5 odd => NO. Indeed, five odds: can we do? Pair two odds -> even; left 3 odds and 1 even. Pair two odds -> even; left 1 odd and 2 evens. Then cannot pair odd with even, but we have two evens can pair -> even, then left 1 odd and 1 even -> stuck. So NO.
But what if we pair differently? Pair two odds -> even, then we have 3 odds, 1 even. Could we instead pair the even with an odd? Not allowed. So stuck. So NO.
Thus condition is correct.
However, wait: what about the possibility that we combine three odds in some way? But we can only combine two at a time. So effectively we need to partition odds into pairs, each pair combined to even, and then combine all evens. So if odd count is odd, we have one odd left after pairing all possible pairs; then we end with odd + some evens; after combining evens, we'll have one odd and one even, stuck. So indeed impossible.
Thus answer is simply based on parity of odd count.
But hold on: Could we combine an even with an even to produce an even, and then combine that even with an odd? Not allowed because parity must match at time of operation. So no.
Thus solution is trivial.
But perhaps there is a twist: The numbers can be large, but we only need parity.
Thus final answer: print "YES" if the number of odd integers is even, else "NO".
But wait, the problem statement: "Takahashi will repeatedly perform the following operation on these numbers: Select a pair of integers, A_i and A_j, that have the same parity (that is, both are even or both are odd) and erase them. Then, write a new integer on the blackboard that is equal to the sum of those integers, A_i+A_j." So the new integer is placed on the blackboard, and we continue. It doesn't say we can't select numbers that were just written, obviously we can.
Thus solution stands.
Let's double-check with some random brute force for small N to ensure no hidden condition. But since I can't run code now, let's think: For N=2, condition works. For N=3, condition works. For N=4, condition works. For N=5, condition works. But is there any scenario where O even but sum even, yet impossible due to something else? Consider maybe the numbers being zero? But A_i >= 1, so positive.
What about large numbers causing something else? Not relevant.
But maybe the operation's result could be odd if we sum two numbers of same parity? No, odd+odd=even, even+even=even. Always even.
Thus all created numbers are even. So the only odd numbers are the initial odds. So the process reduces to pairing odds.
Thus condition is exactly that we can pair all odds, i.e., O is even.
So answer: count odd mod 2 == 0.
Thus code: read N, read list A, count = sum(1 for a in A if a%2==1). Print "YES" if count%2==0 else "NO".
Let's check if there is any subtlety about N=0? N>=2.
Thus solution done.
But I recall a similar AtCoder problem? Possibly "Blackboard" or something. It's from AtCoder? It might be ABC something. But anyway.
Thus answer.
But wait: There is an alternative perspective: total sum even is condition. But is it equivalent to O even? Yes.
Thus final.
But before finalizing, I'll re-read the problem: "Determine whether it is possible to have only one integer on the blackboard." It doesn't ask to output sequence, just yes/no.
Thus solution.
Now, I'll write the answer in the required format.
I should include explanation.
But the instruction says: "You are an AI assistant." Not required to output code, but we can provide solution. The user asked: "There are N integers ... Determine whether it is possible ..." So we need to output answer? Actually the user gave the problem statement, likely expecting solution. Usually on these platforms, they want the answer code. But as ChatGPT, we should provide explanation and final solution code.
Given the format: "Input" "Output" "Examples", it's typical competitive programming problem. So we can provide a solution in Python.
Thus final response: Explanation plus code.
I'll produce the final answer. The problem reduces to checking whether the number of odd integers is even.
- Each operation combines two numbers of the same parity; the result is always even.
- Therefore, odd numbers can only disappear by being paired together (each pair consumes two odds and produces one even).
- If the total number of odds is odd, one odd will remain, and eventually we will be left with one odd and one even, unable to combine further.
- If the number of odds is even, we can repeatedly pair odds until none remain, then pair evens until only one number is left.
Equivalently, the total sum of all numbers must be even (since the final number equals the total sum and must be even). This is the same condition.
Hence, answer is YES if the count of odd numbers is even, else NO.
import sys
def main():
data = sys.stdin.read().strip().split()
if not data:
return
n = int(data[0])
a = list(map(int, data[1:]))
odd_cnt = sum(1 for x in a if x & 1)
print("YES" if odd_cnt % 2 == 0 else "NO")
if __name__ == "__main__":
main()