#K69137. Equalizing Array Elements with One Operation

    ID: 33020 Type: Default 1000ms 256MiB

Equalizing Array Elements with One Operation

Equalizing Array Elements with One Operation

You are given a sequence of n integers, represented as \(a_1, a_2, \dots, a_n\). You are allowed to perform at most one operation. In one operation, you can choose one of the distinct integer values in the sequence and replace all its occurrences with the other distinct value present in the array.

The goal is to determine if it is possible to make all the elements in the array equal by performing at most one such operation. Note that if the array already consists of the same number, no operation is needed.

Constraints:

  • If \(n \leq 1\), the answer is trivially "YES".
  • If there is exactly one distinct number, output "YES".
  • If there are exactly two distinct numbers, it is always possible with one operation, so output "YES".
  • If there are more than two distinct numbers, output "NO".
  • inputFormat

    The first line contains a single integer \(n\) representing the number of elements in the array. The second line contains \(n\) space-separated integers \(a_1, a_2, \dots, a_n\) representing the array.

    Input is read from standard input (stdin).

    outputFormat

    Output a single line containing either "YES" if it is possible to make all the elements equal by performing at most one operation, or "NO" otherwise. The output should be written to standard output (stdout).

    ## sample
    4
    4 4 4 4
    
    YES
    

    </p>