A regional monitoring network runs n seismographs, each producing a single integer amplitude reading for the current tremor. Readings can be negative (a waveform recorded in inverted phase), zero (no motion detected), or positive. The network's alert system should fire whenever it finds two different seismographs — anywhere in the report, not necessarily adjacent — where one station's reading is exactly twice the other's. Given the n readings, determine whether such a pair exists.
Line 1: an integer n, the number of seismographs. Line 2: n space-separated integers arr_1 ... arr_n, the amplitude reading of each seismograph.
Print "YES" if there exist two distinct positions i != j such that arr_i = 2 * arr_j, otherwise print "NO".
2 <= n <= 2000 -1000 <= arr_i <= 1000
Example 1
Input
4 10 2 5 3
Expected
YES
Explanation
The reading 10 (first station) is exactly twice the reading 5 (third station), so the alert condition is met and the answer is YES.
Example 2
Input
4 3 1 7 11
Expected
NO
Explanation
Doubling each reading gives 6, 2, 14, and 22, none of which appears elsewhere in the list, so no pair satisfies the condition and the answer is NO.
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 →