atcoder#ARC105B. [ARC105B] MAX-=min
[ARC105B] MAX-=min
Score : points
Problem Statement
Snuke had cards numbered through . Each card has an integer written on it; written on Card is .
Snuke did the following procedure:
- Let and be the maximum and minimum values written on Snuke's cards, respectively.
- If , terminate the procedure. Otherwise, replace each card on which is written with a card on which 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.
Input
Input is given from Standard Input in the following format:
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 .- Since and , he replaces each card on which is written with a card on which is written.
- Since and , he replaces each card on which is written with a card on which is written.
- Now, the numbers written on Snuke's cards are .- Since and , he replaces each card on which is written with a card on which is written.
- Since and , he replaces each card on which is written with a card on which is written.
- Now, the numbers written on Snuke's cards are .- Since and , he terminates the procedure.
- Since and , he terminates the procedure.
15
546 3192 1932 630 2100 4116 3906 3234 1302 1806 3528 3780 252 1008 588
42