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: Accepted)

/// ========== 入力用マクロ ====================================================
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
/// FromStr型, Vec<T: FromStr>, Vec<char>, に対応
/// 入力と平行して処理したいときには使えない
#[macro_export]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[macro_export]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

#[macro_export]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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


// ========== 常用関数 =======================================================


// 10^9 + 7 で割ったあまりを出力してください
pub const MOD: i64 = 1_000_000_007;

/// 標準入力から
/// 空白文字で囲まれた1つのトークンを
/// 指定の型に変換する
pub fn read<T: std::str::FromStr>() -> T {
    use std::io::Read;
    let stdin = std::io::stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

/// 標準入力から1行読み取り
/// 空白文字で区切って
/// 指定の型のVecに格納する
pub fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

/// ユークリッドの互除法より
/// 2数の最大公約数を求める
pub fn gcd(arg1: usize, arg2: usize) -> usize {
    let mut u = if arg1 > arg2 { arg1 } else { arg2 };
    let mut v = if arg1 > arg2 { arg2 } else { arg1 };

    let mut r: usize;
    while v != 0 {
        r = u % v;
        u = v;
        v = r;
    }
    u
}

/// Vec<usize>に対して順にgcd()を適用して
/// 配列全体の最大公約数を求める
pub fn gcd_vec(v: &[usize]) -> usize {
    let mut r = v[0];
    for i in &v[1..] {
        r = gcd(r, *i);
    }
    r
}

/// gcd()を利用して2数の最小公倍数を求める
pub fn lcm(arg1: usize, arg2: usize) -> usize {
    arg1 * arg2 / gcd(arg1, arg2)
}

/// Vec<usize>に対して順にlcm()を適用して
/// 配列全体の最小公倍数を求める
pub fn lcm_vec(v: &[usize]) -> usize {
    let mut r = v[0];
    for i in &v[1..] {
        r = lcm(r, *i);
    }
    r
}

/// プログラムを終了
pub fn exit() {
    std::process::exit(0)
}


// Rustの言語アップデートありがたいです
// 頑張ってください！


// ========== main() ==========================================================


fn main() {
    input!{
        n: usize,
        a: [usize; n],
    }
    let ans = gcd_vec(&a);
    println!("{}", ans);
}


// ========== 以下使い捨て関数 ===================================================