#P1152. Happy Jump
Happy Jump
Happy Jump
Given an array of n integers, the array is said to exhibit a "Happy Jump" if the absolute differences between every pair of consecutive elements form a complete set of integers from \(1\) to \(n-1\). Mathematically, for an array \(\{a_1, a_2, \ldots, a_n\}\), define the differences as \(|a_2 - a_1|, |a_3 - a_2|, \ldots, |a_n - a_{n-1}|\). The array is a Happy Jump if: \[ \{ |a_2 - a_1|, |a_3 - a_2|, \ldots, |a_n - a_{n-1}| \} = \{1, 2, \ldots, n-1\} \] For example, the array \(\{1, 4, 2, 3\}\) is a Happy Jump because its differences are \(\{|4-1|, |2-4|, |3-2|\} = \{3, 2, 1\}\), which exactly equals \(\{1,2,3\}\).
inputFormat
The input consists of two lines. The first line contains an integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers.
outputFormat
Output a single line containing "Yes" if the array is a Happy Jump; otherwise, output "No".
sample
4
1 4 2 3
Yes