#C1654. Equalizing Array Elements via Subtraction

    ID: 44883 Type: Default 1000ms 256MiB

Equalizing Array Elements via Subtraction

Equalizing Array Elements via Subtraction

Given an array of n integers, determine whether it is possible to make all elements equal by repeatedly applying the following operation:

Select two distinct indices i and j, and update a[i] to a[i] - a[j].

An important invariant of this operation is that the greatest common divisor (gcd) of the elements remains unchanged (except possibly when negative numbers are involved, in which case the absolute values are considered). Hence, the array elements can be equalized if and only if the gcd of all elements is not 1. In other words, if gcd(a[1], a[2], ..., a[n]) ≠ 1, then by repeated operations, the array can be transformed so that all its elements are equal.

The answer should be YES if it is possible to equalize the elements, and NO otherwise.

inputFormat

The input consists of two lines:

  • The first line contains a single integer n (1 ≤ n ≤ 105), the number of elements in the array.
  • The second line contains n space-separated integers, which are the elements of the array.

outputFormat

Output a single line containing YES if it is possible to equalize the array elements using the given operation; otherwise, output NO.

## sample
3
2 4 8
YES

</p>