PHƯỚC HƯNG OJ · THỬ THÁCH THUẬT TOÁN

#GL0000035. Máu cuối cùng của quái vật (Monsters Battle Royale)

HỌC THEO LỘ TRÌNH

Bài tập thuộc lộ trình

1 lộ trình

Máu cuối cùng của quái vật (Monsters Battle Royale)

Monsters Battle Royale

Source: AtCoder

Version: Phuoc Hung OJ Extended

Problem Statement

There are NN monsters with initial positive health values AiA_i. In each move, one living monster attacks another; the target loses health equal to the attacker's current health. Monsters with nonpositive health disappear. Find the minimum attainable health of the final survivor.

Input

The first line contains NN; the second contains A1,…,ANA_1,\ldots,A_N.

Output

Print the minimum attainable final health.

Subtasks

  • Subtask 1 (20 points): 2≤N≤72 \le N \le 7; 1≤Ai≤1001 \le A_i \le 100
  • Subtask 2 (30 points): 2≤N≤10002 \le N \le 1000; 1≤Ai≤1061 \le A_i \le 10^{6}
  • Subtask 3 (50 points): 2≤N≤1052 \le N \le 10^{5}; 1≤Ai≤1091 \le A_i \le 10^{9}

Examples

Input

4
2 10 8 40

Output

2

Explanation

The GCD of 2,10,8,402,10,8,40 is 22, and health changes preserve multiples of this value. A survivor with health 22 is attainable.