#ARC147A. [ARC147A] Max Mod Min

[ARC147A] Max Mod Min

Score : 300300 points

Problem Statement

You are given a sequence of NN positive integers: A=(A1,A2,,AN)A=(A_1,A_2,\dots,A_N).

You will repeat the following operation until the length of AA becomes 11.

  • Let kk be the length of AA before this operation. Choose integers ii and jj such that $\max(\{A_1,A_2,\dots,A_{k}\})=A_i,\min(\{A_1,A_2,\dots,A_{k}\})=A_j$, and iji \neq j. Then, replace AiA_i with (AimodAj)(A_i \bmod A_j). If AiA_i becomes 00 at this moment, delete AiA_i from AA.

Find the number of operations that you will perform. We can prove that, no matter how you choose i,ji,j in the operations, the total number of operations does not change.

Constraints

  • 2N2×1052 \le N \le 2 \times 10^5
  • 1Ai1091 \le A_i \le 10^9
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

NN

A1A_1 A2A_2 \dots ANA_N

Output

Print the answer.

3
2 3 6
3

You will perform 33 operations as follows:

  • Choose i=3,j=1i=3,j=1. You get A3=0A_3=0, and delete A3A_3 from AA. Now you have A=(2,3)A=(2,3).
  • Choose i=2,j=1i=2,j=1. You get A2=1A_2=1. Now you have A=(2,1)A=(2,1).
  • Choose i=1,j=2i=1,j=2. You get A1=0A_1=0, and delete A1A_1 from AA. Now you have A=(1)A=(1), and terminate the process because the length of AA becomes 11.
6
1232 452 23491 34099 57341 21488
12