#P10444. Equal Range Subsequence Partition

    ID: 12453 Type: Default 1000ms 256MiB

Equal Range Subsequence Partition

Equal Range Subsequence Partition

Given a sequence of integers \( a_1, a_2, \ldots, a_n \), define the range of a subsequence \( c \) as \( \max(c)-\min(c) \). Determine if it is possible to partition the entire sequence into at least two subsequences, where:

  • Each subsequence has at least 2 elements.
  • Each subsequence has the same range (i.e. if the common range is \( r \) then every subsequence \( c \) must satisfy \( \max(c)-\min(c)=r \)).
  • Every element of the original sequence must belong to exactly one subsequence.

The formula for the range is given by:

\( \text{range}(c) = \max(c) - \min(c) \).

Output YES if such a partition exists, otherwise output NO.

inputFormat

The first line contains a single integer \( n \) (the length of the sequence).

The second line contains \( n \) space-separated integers \( a_1, a_2, \ldots, a_n \).

outputFormat

Output a single line containing YES if it is possible to partition the sequence in the required way; otherwise, output NO.

sample

4
1 3 2 4
YES