#K15476. Equalize Array Elements via Doubling and Discarding
Equalize Array Elements via Doubling and Discarding
Equalize Array Elements via Doubling and Discarding
You are given a list of n positive integers. You may perform the following two operations any number of times:
- Doubling: Multiply any element by 2.
- Discarding: Remove any one element from the list.
Your task is to determine whether it is possible to end up with a non-empty array in which all the remaining elements are equal.
Hint: It is always possible to double an element to match the magnitude of a larger number. However, the key observation is that repeatedly doubling only affects the factor of 2. Therefore, if you reduce each number by dividing it by 2 until it becomes odd (i.e. extract its odd part), then all numbers must have the same odd part for them to be eventually equal (after possibly discarding some elements).
Formally, for each number \(a_i\), let \(o_i\) be the odd number obtained by repeatedly dividing \(a_i\) by 2. The answer is "YES" if and only if all \(o_i\) (for the remaining numbers) are the same; otherwise, the answer is "NO".
inputFormat
The input is read from standard input and consists of two lines:
- An integer \(n\) representing the number of elements in the array.
- \(n\) space-separated positive integers representing the elements of the array.
outputFormat
Output a single line to standard output containing either "YES" if it is possible to make all the remaining elements equal by performing the allowed operations, or "NO" if it is not possible.
Note: The output should not contain any extra characters or spaces.
## sample5
2 4 8 16 32
YES