#K42037. Equal Book Spacing

    ID: 26998 Type: Default 1000ms 256MiB

Equal Book Spacing

Equal Book Spacing

You are given n books with unique ID numbers. Your task is to determine if these books can be arranged such that the difference between any two consecutive books is identical. In other words, if the books are sorted in increasing order, then the differences between consecutive books should be equal.

If there is only one book, the answer is trivially YES.

The condition can be formally expressed as follows: if the sorted sequence is \(a_1, a_2, \ldots, a_n\), then for a constant difference \(d\) it must hold that \(a_i - a_{i-1} = d\) for all \(i = 2, 3, \dots, n\).

inputFormat

The input consists of two lines. The first line contains an integer (n) (the number of books). The second line contains (n) space-separated integers representing the unique ID numbers of the books.

outputFormat

Output a single line with the string "YES" if the books can be arranged with equal spacing, and "NO" otherwise.## sample

1
7
YES

</p>