#C2714. Arithmetic Sequence Formation
Arithmetic Sequence Formation
Arithmetic Sequence Formation
You are given a list of n integers. Your task is to determine whether the list can be rearranged to form an arithmetic sequence.
An arithmetic sequence is a sequence of numbers in which the difference between any two consecutive terms is constant. In mathematical notation, a sequence \(a_1, a_2, \ldots, a_n\) is called arithmetic if there exists a constant \(d\) such that \(a_{i+1} - a_i = d\) for all \(1 \le i < n\). Note that any pair of numbers (when \(n = 2\)) always forms an arithmetic sequence.
Rearrange the given list in any order to decide if it is possible to form an arithmetic progression.
inputFormat
The input is read from standard input (stdin) and has the following format:
- The first line contains an integer n representing the number of elements in the list.
- The second line contains n space-separated integers denoting the elements of the list.
outputFormat
Output to standard output (stdout) a single line: "YES" if the list can be rearranged to form an arithmetic sequence, otherwise "NO".
## sample5
3 6 9 12 15
YES