#K9021. Arithmetic Progression Check

    ID: 37702 Type: Default 1000ms 256MiB

Arithmetic Progression Check

Arithmetic Progression Check

In this problem, you are given an array of integers. Your task is to determine if the distinct elements of the array can be arranged to form an arithmetic progression. An arithmetic progression is a sequence (a, a+d, a+2d, \ldots, a+(n-1)d), where (d) is a constant difference and (n) is the number of terms. Note that if the number of distinct elements in the array is less than 2, then it cannot form a valid arithmetic progression.

For example, consider the array [4, 8, 6, 2, 10, 4]. After removing duplicates and sorting, we obtain [2, 4, 6, 8, 10], which forms an arithmetic progression with (a=2) and (d=2). Therefore, the output should be YES.

inputFormat

The first line contains an integer (N), representing the number of elements in the array. The second line contains (N) space-separated integers.

outputFormat

Output a single line: "YES" if the distinct elements of the array can be arranged to form an arithmetic progression, and "NO" otherwise.## sample

6
4 8 6 2 10 4
YES