#C2499. Rearrange to Form an Arithmetic Sequence
Rearrange to Form an Arithmetic Sequence
Rearrange to Form an Arithmetic Sequence
Given a list of integers, determine whether it is possible to rearrange the numbers to form an arithmetic sequence. An arithmetic sequence is defined by a constant difference between consecutive terms. In other words, for a sequence \(a_1, a_2, \ldots, a_n\), there exists a constant \(d\) such that for every \(1 \le i < n\), \(a_{i+1} - a_i = d\).
Your task is to read the input from stdin
and output to stdout
. The first input line contains an integer \(n\) indicating the number of elements, and the second line contains \(n\) space-separated integers. Output YES
if the numbers can be rearranged to form an arithmetic sequence, and NO
otherwise.
inputFormat
The input is read from stdin
and consists of two lines:
- The first line contains a single integer \(n\) ― the number of elements in the list.
- The second line contains \(n\) space-separated integers.
outputFormat
Print a single line to stdout
containing YES
if the numbers can be rearranged to form an arithmetic sequence; otherwise, print NO
.
3
3 1 2
YES
</p>