#K63607. Original Sequence Verification
Original Sequence Verification
Original Sequence Verification
You are given a sequence of n integers. Your task is to verify if the sequence can form an "original sequence" when sorted in ascending order such that every element (after the first) is exactly double its preceding element.
More formally, let the sorted sequence be \(a_1, a_2, \ldots, a_n\). The sequence is valid if and only if for every \(i\) (\(2 \le i \le n\)), the condition \(a_i = 2 \times a_{i-1}\) holds. For a sequence with a single element, it is always considered valid.
For example:
- For the sequence [1, 2, 4, 8, 16], after sorting the check \(2=2\times1, 4=2\times2, \ldots\) holds, so the output is "YES".
- For the sequence [3, 6, 9, 12], the condition fails (\(9 \ne 2 \times 6\)), so the output is "NO".
inputFormat
The input consists of two lines. The first line contains a single integer \(n\) (the number of elements in the sequence). The second line contains \(n\) space-separated integers representing the sequence.
Note: The sequence may be given in unsorted order.
outputFormat
Output a single line containing either "YES" if the sequence can be rearranged to form an original sequence, or "NO" otherwise.
## sample5
1 2 4 8 16
YES
</p>