We are asked: Given four positive integers a1..a4, each between 1 and 100. We need to partition the set of bags into two subsets (each bag goes to one of two friends) such that the sum of candies in each subset is equal. That is a classic partition problem with 4 items; we can simply check all possible assignments: each bag can go to friend 0 or friend 1, but note that the two friends are not distinguished (i.e., swapping the subsets yields the same distribution, but we just need equality). However we can check if any subset sum equals total/2. Since there are only 4 items, we can check all 2^4 = 16 assignments, but we can reduce by symmetry: check if there exists any subset S of {1,2,3,4} such that sum_{i in S} a_i = total_sum/2. That's simpler.
Condition: total_sum must be even. Then we need to see if any subset sums to half. Since there are only 4 items, we can check all subsets (excluding empty and full maybe) but we can also enumerate: single elements, pairs, triples (which correspond to complement of a single). Actually if a subset of size 3 has sum half, then its complement (single) also sums to half, so we only need to check subsets of size 0,1,2. But we can just loop from 1 to 2^4-1 and check sum. Since it's tiny, it's fine.
Thus solution: read four ints, compute total. If total % 2 != 0 -> print NO. Else half = total//2. Then check if any non-empty subset sum equals half. Since we need both friends to receive the same, we must allocate all bags. So we need a partition; that is a subset summing to half, and the rest automatically sum to half. So we need to check existence of subset sum half. If yes -> YES else NO.
Edge: total/2 could be 0? Not possible because all a_i >=1, total>=4, half >=2.
Thus implementation straightforward.
Examples: 1,7,11,5 => total=24, half=12. Subsets: {1,11}=12 => YES. 7,3,2,5 => total=17, odd => NO.
Thus done.
Now produce answer in correct format. I'll write code in Python.
Make sure to output "YES" or "NO" as per case.
Time complexity: O(2^4) = constant.
Now produce final answer.
But the user asked to "Dawid has four bags ..." So we need to provide solution. Since this is a typical Codeforces problem (probably 4A? Actually it's from CF 1738A? Not sure) but it's simple. So we'll respond with solution.
I think they want code. So output a Python script. ```python
def solve() -> None:
import sys
a = list(map(int, sys.stdin.read().split()))
total = sum(a)
if total % 2 != 0:
print("NO")
return
half = total // 2
n = 4
# Check all subsets except the empty set (0) and the full set (15)
# but the full set would give total, not half unless total=0, which cannot happen.
for mask in range(1, 1 << n):
s = 0
for i in range(n):
if mask & (1 << i):
s += a[i]
if s == half:
print("YES")
return
print("NO")
if name == "main":
solve()