Problem:
Score : 300 points

Problem Statement

There are N monsters, numbered 1, 2, ..., N.

Initially, the health of Monster i is A_i.

Below, a monster with at least 1 health is called alive.

Until there is only one alive monster, the following is repeated:

A random alive monster attacks another random alive monster.

As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking.

Find the minimum possible final health of the last monster alive.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible final health of the last monster alive.

Sample Input 1

4
2 10 8 40

Sample Output 1

2

When only the first monster keeps on attacking, the final health of the last monster will be 2, which is minimum.

Sample Input 2

4
5 13 8 1000000000

Sample Output 2

1

Sample Input 3

3
1000000000 1000000000 1000000000

Sample Output 3

1000000000

Solution in Rust (1.15.1) (judge verdict: Wrong Answer)

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        a_s: [usize; n],
    }
    let mut b_s = a_s;
    let mut min = 1000000000;
    let mut min2 = 1000000000;
    let mut min_index = 0;
    let mut min2_index = 0;
    for i in 0..b_s.len() {
        if b_s[i] <= min {
            min2 = min;
            min2_index = min_index;
            min = b_s[i].clone();
            min_index = i;
        } else if b_s[i] > min && b_s[i] <= min2 {
            min2 = b_s[i].clone();
            min2_index = i;
        }
    }
    loop {
        let x = min2 / (min * 2) + 1;
        for (i, b) in b_s.iter_mut().enumerate() {
            if i != min_index {
                *b -= x * min;
            }
        }
        if b_s[min2_index] <= 0 {
            println!("{:?}", b_s[min_index]);
            return;
        }
        else if b_s[min2_index] < b_s[min_index] {
            min = b_s[min2_index].clone();
            min2 = b_s[min_index].clone();

            let tmp = min2_index;
            min2_index = min_index;
            min_index = tmp;
        } else {
            println!("{:?}", b_s[min_index]);
            return;
        }
    }
}