#K73492. Fair Candy Distribution

    ID: 33987 Type: Default 1000ms 256MiB

Fair Candy Distribution

Fair Candy Distribution

You are given a collection of candies, each with a positive integer weight. Your task is to determine whether it is possible to split the candies into two non-empty groups such that the sum of the weights in each group is even. In other words, if the candies have weights (a_1, a_2, \dots, a_n), check if there exists a partition into two groups (each containing at least one candy) with sums (S_1) and (S_2) respectively, where both (S_1) and (S_2) are even numbers.

A key observation is that a group sum is even if it contains an even number or if it contains an even number of odd candies. Based on these insights, a valid partition exists if the total number of candies is at least 2 and either:

  1. The candy list contains both even and odd numbers, or
  2. All candies are even and there are at least 2 candies.

If all candies are odd, no valid partition exists even if their count is even, because a single odd candy has an odd weight and cannot form an even sum on its own.

inputFormat

The input begins with an integer (n) ((1 \le n \le 10^5)), representing the number of candies. The next line contains (n) space-separated integers, each representing the weight of a candy.

outputFormat

Print a single line containing either YES if a valid partition exists, or NO otherwise.## sample

4
1 3 5 7
NO

</p>