#P10830. Reduce Blackboard to One Number
Reduce Blackboard to One Number
Reduce Blackboard to One Number
Given a blackboard with \(N\) non-negative integers. In one operation, you can select two integers \(a\) and \(b\) from the blackboard such that \(2\mid(a+b)\) (i.e. \(a+b\) is even), erase them, and write \(\frac{a+b}{2}\) on the blackboard. Note that after each operation, all numbers on the blackboard remain integers.
Your task is to determine whether it is possible to reduce the board to a single number using a sequence of such operations. If it is possible, you must also output one valid sequence of operations.
Operation: Choose two numbers \(a\) and \(b\) with \(a+b\) even, erase them, and append \(\frac{a+b}{2}\) to the board.
inputFormat
The first line contains an integer \(N\) representing the number of integers on the blackboard.
The second line contains \(N\) non-negative integers separated by spaces.
outputFormat
If it is impossible to reduce the board to one number, output NO
.
If it is possible, output YES
on the first line, then an integer \(K\) (which will be \(N-1\), the number of operations performed), and finally \(K\) lines, each containing two integers representing the two numbers chosen in that operation (in the order they were selected).
sample
2
1 2
NO
</p>