#C9325. Arithmetic Progression Rearrangement
Arithmetic Progression Rearrangement
Arithmetic Progression Rearrangement
You are given a sequence of integers. Your task is to determine whether the sequence can be rearranged to form an arithmetic progression. An arithmetic progression is a sequence in which the difference between consecutive elements is constant. Formally, a sequence a1, a2, ..., an is an arithmetic progression if there exists a constant d such that
$$a_{i+1} - a_i = d \quad \text{for all } 1 \leq i < n. $$You will be given multiple test cases. For each test case, first an integer N is provided indicating the size of the sequence, followed by N integers representing the sequence. Print "YES" if the sequence can be rearranged into an arithmetic progression, otherwise print "NO".
inputFormat
The input begins with a single integer T (T \ge 1) representing the number of test cases. Each test case consists of two lines. The first line of each test case contains an integer N (N \ge 2), the number of elements in the sequence. The second line contains N space-separated integers.
outputFormat
For each test case, output a single line with either "YES" if the sequence can be rearranged to form an arithmetic progression or "NO" if it cannot.
## sample3
3
3 1 2
4
1 2 4 5
5
5 1 3 2 4
YES
NO
YES
</p>