Today, hedgehog Filya went to school for the very first time! Teacher gave him a homework which Filya was unable to complete without your help.
Filya is given an array of non-negative integers _a_1, _a_2, ..., _a__n_. First, he pick an integer _x_ and then he adds _x_ to some elements of the array (no more than once), subtract _x_ from some other elements (also, no more than once) and do no change other elements. He wants all elements of the array to be equal.
Now he wonders if it's possible to pick such integer _x_ and change some elements of the array using this _x_ in order to make all elements equal.
## Input
The first line of the input contains an integer _n_ (1 ≤ _n_ ≤ 100 000) — the number of integers in the Filya's array. The second line contains _n_ integers _a_1, _a_2, ..., _a__n_ (0 ≤ _a__i_ ≤ 109) — elements of the array.
## Output
If it's impossible to make all elements of the array equal using the process given in the problem statement, then print "_NO_" (without quotes) in the only line of the output. Otherwise print "_YES_" (without quotes).
[samples]
## Note
In the first sample Filya should select _x_ = 1, then add it to the first and the last elements of the array and subtract from the second and the third elements.
今天,刺猬 Filya 首次去上学了!老师给他布置了一道作业,Filya 在没有你的帮助下无法完成。
Filya 被给定一个非负整数数组 #cf_span[a1, a2, ..., an]。首先,他选择一个整数 #cf_span[x],然后将 #cf_span[x] 加到数组的某些元素上(每个元素最多加一次),从另一些元素中减去 #cf_span[x](每个元素最多减一次),其余元素保持不变。他希望数组中的所有元素都相等。
现在他想知道,是否能选出这样一个整数 #cf_span[x],并使用它对数组中的某些元素进行操作,使得所有元素相等。
输入的第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 100 000]) —— Filya 数组中整数的个数。第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2, ..., an] (#cf_span[0 ≤ ai ≤ 109]) —— 数组的元素。
如果使用题目中描述的过程无法使数组中所有元素相等,则在输出的唯一一行中打印 "_NO_"(不含引号)。否则打印 "_YES_"(不含引号)。
在第一个样例中,Filya 应选择 #cf_span[x = 1],然后将其加到数组的第一个和最后一个元素上,并从第二个和第三个元素中减去它。
## Input
输入的第一行包含一个整数 #cf_span[n] (#cf_span[1 ≤ n ≤ 100 000]) —— Filya 数组中整数的个数。第二行包含 #cf_span[n] 个整数 #cf_span[a1, a2, ..., an] (#cf_span[0 ≤ ai ≤ 109]) —— 数组的元素。
## Output
如果使用题目中描述的过程无法使数组中所有元素相等,则在输出的唯一一行中打印 "_NO_"(不含引号)。否则打印 "_YES_"(不含引号)。
[samples]
## Note
在第一个样例中,Filya 应选择 #cf_span[x = 1],然后将其加到数组的第一个和最后一个元素上,并从第二个和第三个元素中减去它。
Let $ A = \{a_1, a_2, \dots, a_n\} $ be a multiset of non-negative integers.
We are to determine whether there exists an integer $ x \geq 0 $ and a partition of $ A $ into three disjoint subsets $ S_+, S_-, S_0 $ such that:
- $ S_+ \cup S_- \cup S_0 = A $,
- $ S_+ \cap S_- = \emptyset $, $ S_+ \cap S_0 = \emptyset $, $ S_- \cap S_0 = \emptyset $,
- For all $ a_i \in S_+ $: $ a_i + x = c $,
- For all $ a_i \in S_- $: $ a_i - x = c $,
- For all $ a_i \in S_0 $: $ a_i = c $,
for some common target value $ c $.
Equivalently, define the set of distinct values in $ A $ as $ D = \{ d_1, d_2, \dots, d_k \} $, sorted such that $ d_1 < d_2 < \dots < d_k $.
Then, the problem reduces to checking whether there exists $ x \geq 0 $ and $ c \in \mathbb{Z} $ such that every element $ d_i \in D $ satisfies one of:
- $ d_i = c $,
- $ d_i = c + x $,
- $ d_i = c - x $.
This implies that the set $ D $ can have at most three distinct values, and if it has three, they must form an arithmetic progression with common difference $ x $, i.e., $ D = \{ c - x, c, c + x \} $.
**Formal Conditions:**
Let $ D $ be the set of distinct elements in $ A $, with $ |D| = k $.
- If $ k = 1 $: YES (take $ x = 0 $).
- If $ k = 2 $: YES (take $ x = |d_2 - d_1| $, $ c = d_1 $ or $ c = d_2 $).
- If $ k = 3 $: YES if and only if $ d_2 - d_1 = d_3 - d_2 $ (i.e., $ d_1, d_2, d_3 $ form an arithmetic sequence); then $ x = d_2 - d_1 $, $ c = d_2 $.
- If $ k > 3 $: NO.
**Output:**
$$
\boxed{
\begin{cases}
\text{YES} & \text{if } |D| \leq 3 \text{ and if } |D| = 3 \text{ then } 2d_2 = d_1 + d_3 \\
\text{NO} & \text{otherwise}
\end{cases}
}
$$