A diagnostic device streams a log of numeric sensor readings. Engineers examine every window of two consecutive readings — the one starting at position 0, the one starting at position 1, and so on — and call the sum of each such window its "pulse". Two windows are considered different as soon as they start at different positions, even if the values inside happen to be identical.
Given the full log, determine whether there exist two different starting positions whose pulses are equal.
Line 1: an integer n, the number of readings.
Line 2: n space-separated integers, the readings in order.
2 <= n <= 2000-1000 <= reading <= 1000Print YES if two different starting positions produce equal pulses, otherwise print NO.
Example 1
Input
3 4 2 4
Expected
YES
Explanation
The window starting at position 0 is (4,2) with pulse 6, and the window starting at position 1 is (2,4) with pulse 6. Two different starting positions share the same pulse, so the answer is YES.
Example 2
Input
5 1 2 3 4 5
Expected
NO
Explanation
The pulses starting at positions 0,1,2,3 are 3,5,7,9 respectively — all distinct, so no two different positions match 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 →