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 C# (Mono 4.6.2.0) (judge verdict: Accepted)

using System;
using System.Numerics;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Collections;

namespace debug
{
    class main
    {
        static void Main(string[] args)
        {
            //問題クラスを展開
            ProgramC a = new ProgramC();
            a.main();//実行する

        }

    }

    class ProgramA
    {
        public void main()
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            int sound = int.Parse(s[1]) / int.Parse(s[0]);

            if (sound < int.Parse(s[2]))
                Console.WriteLine(sound);
            else
                Console.WriteLine(int.Parse(s[2]));

        }
    }

    class ProgramB
    {
        public void main()
        {
            //入力
            string[] s = Console.ReadLine().Split(' ');
            int a = int.Parse(s[0]);
            int b = int.Parse(s[1]);
            int k = int.Parse(s[2]);

            int count = 0;

            for (int i = 100; i > 0; i--)
            {
                if (a % i == 0 && b % i == 0)
                    count++;

                if (count == k)
                {
                    Console.WriteLine(i);
                    return;
                }


            }
        }

        
    }

    class ProgramC
    {
        public void main()
        {

            //入力（decimal型だと桁精度が27桁ぐらいまである
            int n = int.Parse(Console.ReadLine());
            string[] s = Console.ReadLine().Split(' ');

            long temp = gcd(long.Parse(s[0]), long.Parse(s[1]));
           
            for(int i = 2;i < s.Length;i++)
            {
                temp = gcd(temp, long.Parse(s[i]));
                
            }

            Console.WriteLine(temp);

        }

        /*最大公約数を求める関数*/
        static long gcd(long p, long q)
        {
            if (p < q)
            {
                long temp = p;
                p = q;
                q = temp;
            }

            long r = 1;

            while (r != 0)
            {
                r = p % q;
                p = q;
                q = r;
            }

            return p;
        }
    }



    class ProgramD
    {
        public void main()
        {

            //入力
            string[] s = Console.ReadLine().Split(' ');
            long n = long.Parse(s[0]);
            long m = long.Parse(s[1]);
            List<Path> path = new List<Path>();
            long[] ans = new long[m];

            ans[m - 1] = n * (n - 1) / 2;

            //入力
            for (int i = 0; i < m; i++)
            {
                string[] t = Console.ReadLine().Split(' ');
                path.Add(new Path(long.Parse(t[0]) - 1, long.Parse(t[1]) - 1));
            }

            UnionFind tree = new UnionFind();//UnionFindクラスを設定
            tree.par = new long[n];
            tree.temp = new long[n];
            tree.reset(n);

            for (int i = 0; i < m - 1; i++)
            {
                if (tree.same(path[(int)m - 1 - i].a, path[(int)m - 1 - i].b) == false)
                    ans[m - 2 - i] = ans[m - 1 - i] - tree.size(path[(int)m - 1 - i].a) * tree.size(path[(int)m - 1 - i].b);
                else
                    ans[m - 2 - i] = ans[m - 1 - i];
                tree.unite(path[(int)m - 1 -i].a, path[(int)m - 1 - i].b); // xの木とyの木を併合する
                if (ans[m - 2 - i] == 0)
                    break;
            }
            //答え出力
            for (int i = 0;i < m;i++)
                Console.WriteLine(ans[i]);
        }
    }

    /*UnionFind法のクラス*/
    class UnionFind
    {

        public long[] par;
        public long[] temp;


        //マイナスは根を示す。
        public void reset(long n)
        {
            for (int i = 0; i < n; i++)
                par[i] = -1;
        }

        //マイナスならそれはまだ属していないので根である。そうでないならさかのぼる
        public long root(long x)
        {
            if (par[x] < 0)
                return x;
            else
                return root(par[x]);
        }

        //根の併合を行い、根には要素数を足す（マイナスの値）
        public void unite(long x, long y)
        { // xとyの木を併合
            long rx = root(x); //xの根をrx
            long ry = root(y); //yの根をry
            if (rx == ry)
                return; //xとyの根が同じ(=同じ木にある)時はそのまま
            if (par[ry] > par[rx])
            {
                long temp = ry;
                ry = rx;
                rx = temp;
            }
            par[ry] += par[rx];
            par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
        }

        // 2つのデータx, yが属する木が同じならtrueを返す
        public bool same(long x, long y)
        {
            long rx = root(x);
            long ry = root(y);
            return rx == ry;
        }


        //根の元に入っている
        public long size(long x)
        {
            return -par[root(x)];
        }
    }

    class Path
    {
        public long a;
        public long b;
        public Path(long a, long b)
        {
            this.a = a;
            this.b = b;
        }
    }
}