#ARC105B. [ARC105B] MAX-=min

[ARC105B] MAX-=min

Score : 300300 points

Problem Statement

Snuke had NN cards numbered 11 through NN. Each card has an integer written on it; written on Card ii is aia_i.

Snuke did the following procedure:

  1. Let XX and xx be the maximum and minimum values written on Snuke's cards, respectively.
  2. If X=xX = x, terminate the procedure. Otherwise, replace each card on which XX is written with a card on which XxX-x is written, then go back to step 1.

Under the constraints in this problem, it can be proved that the procedure will eventually terminate. Find the number written on all of Snuke's cards after the procedure.

Constraints

  • All values in input are integers.
  • 1N1051 \leq N \leq 10^{5}
  • 1ai1091 \leq a_i \leq 10^9

Input

Input is given from Standard Input in the following format:

NN

a1a_1 a2a_2 \cdots aNa_N

Output

Print the number written on all of Snuke's cards after the procedure.

3
2 6 6
2
  • At the beginning of the procedure, the numbers written on Snuke's cards are (2,6,6)(2,6,6).- Since x=2x=2 and X=6X=6, he replaces each card on which 66 is written with a card on which 44 is written.
  • Since x=2x=2 and X=6X=6, he replaces each card on which 66 is written with a card on which 44 is written.
  • Now, the numbers written on Snuke's cards are (2,4,4)(2,4,4).- Since x=2x=2 and X=4X=4, he replaces each card on which 44 is written with a card on which 22 is written.
  • Since x=2x=2 and X=4X=4, he replaces each card on which 44 is written with a card on which 22 is written.
  • Now, the numbers written on Snuke's cards are (2,2,2)(2,2,2).- Since x=2x=2 and X=2X=2, he terminates the procedure.
  • Since x=2x=2 and X=2X=2, he terminates the procedure.
15
546 3192 1932 630 2100 4116 3906 3234 1302 1806 3528 3780 252 1008 588
42