A mountain research station operates n weather beacons. Every beacon reports a distinct raw reading (a positive integer). Before the readings appear on the station's shared display board, each beacon's DISPLAYED value must be produced by exactly one of two calibration rules, chosen independently per beacon:
The display board is only trusted when every beacon's displayed value has the same parity: either all displayed values end up even, or all of them end up odd. Given the n raw readings, determine whether some choice of calibration rules -- one independent choice per beacon -- can make every displayed value share a single parity.
Line 1: an integer n. Line 2: n distinct positive integers, the raw readings of the beacons, space-separated.
Print YES if some assignment of calibration rules makes all displayed values share one parity, or NO otherwise.
Example 1
Input
2 2 3
Expected
NO
Explanation
The smaller reading, 2, has no beacon smaller than it, so it can only display 2 (even) -- this fixes the target parity to even. The other beacon's raw reading is 3 (odd); its only options are to display 3 unchanged (odd) or 3 - 2 = 1 (odd) -- both options are odd, so it can never display an even value. Since the two beacons can never agree on a shared parity, the answer is NO.
Example 2
Input
3 1 4 7
Expected
YES
Explanation
The smallest reading, 1, fixes the target parity to odd (it can only display 1). Beacon 4 can display 4 - 1 = 3, which is odd, matching the target. Beacon 7 can simply display its own raw reading, 7, which is already odd. Every beacon can be made to display an odd value, so the answer is YES.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →