#K1631. Arithmetic Progression Rearrangement

    ID: 24550 Type: Default 1000ms 256MiB

Arithmetic Progression Rearrangement

Arithmetic Progression Rearrangement

Given an array of integers, determine whether it is possible to rearrange its elements to form an arithmetic progression. An arithmetic progression is defined as a sequence \(a_1, a_2, \dots, a_n\) such that \(a_{i+1} - a_i = d\) for every valid \(i\), where \(d\) is a constant. The most straightforward method to check this is to sort the array and then verify that the difference between consecutive elements remains constant.

inputFormat

The input is read from stdin and has the following format:

  • The first line contains a single integer \(T\), representing the number of test cases.
  • For each test case, the first line contains an integer \(n\), the number of elements in the array.
  • The next line contains \(n\) space-separated integers.

outputFormat

For each test case, output a single line to stdout containing YES if the given array can be rearranged to form an arithmetic progression; otherwise, output NO.

## sample
3
3
1 3 2
4
4 8 5 1
5
7 7 7 7 7
YES

NO YES

</p>