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



Sample input:
4
2 10 8 40


Sample output:
2

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>



typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)
#define sz(x) int(x.size())


template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;

int gcd(int a,int b){
    if (a==0) return b;
    else return gcd(b%a,a);
}
int inf=1001001001;

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n) {
        int a;
        cin>>a;
        v[i]=a;
    }
    sort(v.begin(),v.end());
    int tmp=gcd(v[0],v[1]);
    //cout<<tmp<<endl;
    //int ans=inf;
    for (int i=2;i<n;i++){
        tmp=gcd(tmp,v[i]);
    }
    cout<<tmp;
    return 0;
}

Submission status: Runtime Error

Solution code:
#include <iostream>
#include <algorithm>
#include <vector> //動的配列
#include <string>
#include <list> //双方向リスト
#include <map> //連想配列
#include <set> //集合
#include <stack>
#include <queue>
#include <deque>
#include <cmath>
#include <bitset>
#include <numeric>
#include <tuple>



typedef long long ll;


using namespace std;

typedef pair<int, int> P;
#define FOR(i,a,b) for(int i=(int)(a) ; i < (int) (b) ; ++i )
#define rep(i,n) FOR(i,0,n)
#define sz(x) int(x.size())


template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

//小さい順から取り出すヒープ
//priority_queue<ll, vector<ll>, greater<ll> > pque1;

int gcd(int a,int b){
    if (a==0) return b;
    else return gcd(a%b,a);
}
int inf=1001001001;

int main(){
    int n;
    cin>>n;
    vector<int> v(n);
    rep(i,n) cin>>v[i];
    sort(v.begin(),v.end());
    int tmp=gcd(v[0],v[1]);
    int ans=inf;
    for (int i=1;i+1<n;i++){
        ans=min(ans,gcd(tmp,gcd(v[i],v[i+1])));
    }
    cout<<ans;
    return 0;
}

Submission status: Runtime Error

Solution code:
import fractions
n = int(input())
a = list(map(int,input().split()))
gcd_a = fractions.gcd(a[0],[1])
for i in range(2,n):
  gcd_a = fractions.gcd(gcd_a,gcd[i])
  if gcd_a == 1:
    break
print(gcd_a)

Submission status: Runtime Error

Solution code:
import math

N = int(input())

A = list(map(int,input().split()))

A = sorted(A)[0:2]

print(math.gcd(A[0],A[1]))

Submission status: Runtime Error

Solution code:
from sys import stdin
from math import gcd
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()

n = int(input())
arr = lmi()
for i in range(1, n):
    arr[i] = gcd(arr[i], arr[i-1])
print(arr[n-1])

Submission status: Runtime Error

Solution code:
import math
n = int(input())
arr = list(map(int,input().split()))
ans = arr[0]
for i in arr[1:]:
    ans = math.gcd(ans, i)
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin, exit
from math import factorial, gcd
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()

n = int(input())
arr = lmi()
for i in range(1, n):
    arr[i] = gcd(arr[i], arr[i-1])
print(arr[n-1])

Submission status: Runtime Error

Solution code:
from sys import stdin, exit
from math import factorial, gcd
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()

n = int(input())
arr = lmi()
for i in range(1, n):
    arr[i] = gcd(arr[i], arr[i-1])
print(arr[-1])

Submission status: Runtime Error

Solution code:
from fractions import gcd
from functools import reduce
n=int(input())
A=list(map(int,input().split()))
print(reduce(gcd, A)

Submission status: Runtime Error

Solution code:
from math import gcd
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in range(1,n):
    ans=gcd(a[i],a[i-1])
    a[i]=ans
print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, len(a)):
    ans = math.gcd(ans, a[i])
    
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
import math
ans = A[0]
for i in range(1, N):
    ans = math.gcd(ans, A[i])
print(ans)

Submission status: Runtime Error

Solution code:
from fractions import gcd
from math import gcd
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in A[1:]:
    ans = gcd(ans,i)
    if ans ==1:
        break
print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math
from functools import reduce

N=int(input())
A=list(map(int,input().split()))

a=min(A)
ans=0


def gcd_list(numbers):
    return reduce(math.gcd, numbers)

print(gcd_list(A))
#きれた

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int, input().split()))

import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

print(gcd_list(A))

Submission status: Runtime Error

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
ans=10**7
m=a[-1]
for i in range(len(a)-1):
    t=m%(a[i+1]-a[i])
    s=a[i+1]%a[i]
    if t!=0:
        ans=min(ans,t)
    if s!=0:
        ans=min(ans,s)
print(ans)

Submission status: Runtime Error

Solution code:
import math 

n = int(input())
monsters = list(map(int, input().split()))

for i in range(1,n):
    monsters[i] = math.gcd(monsters[i],monsters[i-1])
print(monsters[n-1])

Submission status: Runtime Error

Solution code:
import fractions
n = int(input())
a = list(map(int, input()))
ans = a[0]
for i in range(n):
  ans = fractions.gcd(ans, a[i])
print(ans)

Submission status: Runtime Error

Solution code:
import sys, fractions
sys.setrecursionlimit(5 * 10**5)
input = sys.stdin.readline

N = int(input())

A = list(map(int, input().split()))

gcds = []

for i in range(N - 2):
    for j in range(i + 1, N - 1):
        gcds.append(fractions.gcd(A[i], A[j]))

print(min(gcds))

Submission status: Runtime Error

Solution code:
import fractions
n = int(input())
A = list(map(int, input().split()))
min_A = min(A)
for i in range(n):
  A[i] = A[i]%min_A
if all(A[i] == 0 for i in range(n)):
  print(min_A)
else:
  print(fractions.gcd(A[j] for j in range(n)))

Submission status: Runtime Error

Solution code:
import math
n=int(input())
lists=list(map(int,input().split()))
gcds=lists[0]
for x in range(n-1):
    if x==0:
        gcds=math.gcd(lists[0],lists[1])
    else:
        add=math.gcd(lists[x],lists[x+1])
        gcds=math.gcd(gcds,add)
print(gcds)

Submission status: Runtime Error

Solution code:
import math
n=int(input())
lists=list(map(int,input().split()))
gcds=lists[0]
for x in range(n-1):
    if n==0:
        gcds=math.gcd(lists[0],lists[1])
    else:
        add=math.gcd(lists[x],lists[x+1])
        gcds=math.gcd(gcds,add)
print(gcds)

Submission status: Runtime Error

Solution code:
import fractions
n = int(input())
l = [int(i) for i in input().split()]
ans = l[0]
for i in range(n):
    ans = fractions.gcd(ans,a[i])

print(ans)

Submission status: Runtime Error

Solution code:
#best
N=int(input())
a=list(map(int, input().split()))
import fractions
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, N):
    ans = fractions.gcd(ans, a[i])
    if ans==1:
        break
print(ans)

Submission status: Runtime Error

Solution code:
#best
import fractions
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, N):
    ans = fractions.gcd(ans, a[i])
    if ans==1:
        break
print(ans)

Submission status: Runtime Error

Solution code:
import fractions
N = int(input())
array = list(map(int, input().split()))
array.sort()
ans = array[0]
for i in range(1,ans):
	ans = fractions.gcd(ans,array[i])
print(ans)

Submission status: Runtime Error

Solution code:
import math

def test():
    n = int(input())
    a = list(map(int,input().split()))
    ans = a[0]
    for i in a:
        ans = math.gcd(ans,i)
    print(ans)


if __name__ == "__main__":
    test()

Submission status: Runtime Error

Solution code:
import numpy as np

def test():
    n = int(input())
    a = np.array(list(map(int,input().split())))
    if all(x%a.min() == 0 for x in a):
        print(a.min())
    else:
        a = sorted(list(set(a//a.min())))
        print(a[1]-a[0])


if __name__ == "__main__":
    test()

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
g = math.gcd(a[0],a[1])
for i in range(n-2):
    g = math.gcd(g,a[i+2])
print(g)

Submission status: Runtime Error

Solution code:
from functools import gcd

n = int(input())
A = list(map(int, input().split()))

a = A[0]
for i in range(1, n):
    a = gcd(a, A[i])

print(a)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

_ = int(input())
A = list(map(int, input().split()))

print(reduce(math.gcd, A))

Submission status: Runtime Error

Solution code:
N=int(input())
A=list([map(int,input().split()) for i in range(N)])
B=sorted(A)
print(A[N]-A[N-1])

Submission status: Runtime Error

Solution code:
import fractions

N = int(input())
A = list(map(int, input().split()))
ans = A[0]
for i in range(1, N):
    ans = gcd(ans, A[i])
    
print(ans)

Submission status: Runtime Error

Solution code:
import math
N=int(input())
A=[int(x) for x in input().split()]
ans=A[0]
for a in A[1:]:
  ans=math.gcd(ans,a)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input()) # the num of monster
 
ls = list(map(int, input().split()))
n = len(ls)
ans = math.gcd(ls[0], ls[1])

for i in range(n):
    ans = math.gcd(ans, ls[i])
    
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input()) # the num of monster

ls = list(map(int, input().split()))

ls.sort()

for i in range(len(ls)-1):
  if(len(ls)==1):
    print(len[0])
  for j in range(1, len(ls)):
    if(ls[j] % ls[i] == 0):
      ls.remove(ls[j])

Submission status: Runtime Error

Solution code:
def MAP(): return list(map(int,input().split()))
import math

n = int(input())
A = MAP()

tmp=A[0]
for i in range(1,n):
    tmp = math.gcd(tmp,A[i])
print(tmp)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
N = int(input())
a = list(map(int, input().split()))
print(reduce(math.gcd, a))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def g(n):
    return reduce(math.gcd,n)
n=int(input())
print(g(list(map(int,input().split()))))

Submission status: Runtime Error

Solution code:
from functools import*
d=lambda x,y:d(x,y%x)if y%x else x
_,a=open(0)
print(reduce(d,map(int,a.split())))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))

import math
g = 0
for x in a:
  g = math.gcd(g, x)
print(g)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))

import math
g=0
for x in a:
  g=math.gcd(g,x)
print(g)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import math

n = int(input())
a = list(map(int, input().split()))

ans = a[0]
for a_val in a:
    ans = math.gcd(ans, a_val)

print(ans)

Submission status: Runtime Error

Solution code:
import functools
import math


def solve():
    n = int(input())
    a = list(map(int, input().split()))
    return functools.reduce(math.gcd, a)


if __name__ == "__main__":
    print(solve())

Submission status: Runtime Error

Solution code:
def solve():
    n = int(input())
    a = list(map(int, input().split()))
    while sum([True for i in a if i > 1]) > 1:
        min_mon = min(a)
        idx = a.index(min_mon)
        a = [mon if i == idx else mon % min_mon for i, mon in enumerate(a)]
    print(sum(a))


if __name__ == "__main__":
    solve()

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))

x = [a[1],a[0],a[1] % a[0]]
a.sort()
for i in range(1,n+1):
    while x[2] > 0:
        x[0] = x[1]
        x[1] = x[2]
        x[2] = x[0] % x[1]
    x[0] = a[i+1]
    x[2] = x[0] % x[1]

print(x[1])

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcds(*numbers):
    return reduce(math.gcd, numbers)

def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    print(gcds(*A))

resolve()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    print(gcd(*A))

resolve()

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)

def resolve():
    N = int(input())
    A = list(map(int,input().split()))
    print(gcd(*A))

resolve()

Submission status: Runtime Error

Solution code:
from math import gcd
N=int(input())
A=list(map(int,input().split()))
g=gcd(A[0],A[1])
for i in range(2,N):
        g=gcd(g,A[i])
print(g)

Submission status: Runtime Error

Solution code:
from fractions import gcd

n =int(input())
a_lis = list(map(int,input().split()))
g = 0
for i in range(a_lis):
	g = gcd(g,i)

print(g)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

n = int(input())
a = list(map(int, input().split()))

print(reduce((lambda x, y: math.gcd(x, y)), a))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

n = int(input())
a = list(map(int, input().split()))

print(reduce(lambda x, y: math.gcd(x, y), a))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

n = int(input())
a = list(map(int, input().split()))

print(reduce(lambda x, y: math.gcd(x, y), a))

Submission status: Runtime Error

Solution code:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e50)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def main():
    H, M = l_inpl()
    A = l_inpl()
    d = {
        "1": 2,
        "2": 5,
        "3": 5,
        "4": 4,
        "5": 5,
        "6": 6,
        "7": 3,
        "8": 7,
        "9": 6
    }

    new_d = {}
    for Ai in A:
        new_d[Ai] = d[str(Ai)]

    dp = [-INF] * (H+1) # ちょうどi本のマッチ棒を使って，条件を満たす整数を作るときの最大桁数
    dp[0] = 0

    for i in range(1, H+1):
        tmp = []
        for k, v in new_d.items():
            if i-v < 0:
                tmp.append(-INF)
            else:
                tmp.append(dp[i-v]+1)
        dp[i] = max(tmp)

    s = sorted(new_d.items(), key=lambda x:-x[0])

    ans = ""
    remain = H

    while remain != 0:
        for k, v in s:
            if dp[remain-v] == dp[remain] - 1: # 一桁だけ減少している
                ans += str(k)
                remain -= v
                break
    print(ans)
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = map(int, input().split())

A_set = set(A)
if len(A_set) == 1:
    print(A_set[0])
else:
    A = list(A_set)
    A = sorted(A)
    if (A[0] % 2 == 0) and (A[1] % 2 ==0):
        print("2")
    else:
        print("1")

Submission status: Runtime Error

Solution code:
from  math import gcd
from functools import reduce
n = int(input())
li = list(map(int,input().split()))
print(reduce(gcd,li))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
n = int(input())
li = list(map(int,input().split()))
print(reduce(math.gcd,li))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
n = int(input())
li = list(map(int,input().split())
print(reduce(math.gcd,li))

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = list(map(int, input().split()))
x = A[0]
for i in range(len(A)-1):
    x= math.gcd(x,A[i+1])
print(x)

Submission status: Runtime Error

Solution code:
import sys
from fractions import gcd
from collections import deque

input = sys.stdin.readline

N = int(input())
a = [int(x) for x in input().rstrip("\n").split()]
q = deque(a)

while len(q) > 1:
    x = q.popleft()
    y = q.popleft()
    z =  fractions.gcd(x, y)
    q.append(z)

ans = q.popleft()
print(ans)

Submission status: Runtime Error

Solution code:
import sys
from fractions import math
from collections import deque

input = sys.stdin.readline

N = int(input())
a = [int(x) for x in input().rstrip("\n").split()]
q = deque(a)

while len(q) > 1:
    x = q.popleft()
    y = q.popleft()
    z =  math.gcd(x, y)
    q.append(z)

ans = q.popleft()
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import deque

input = sys.stdin.readline

N = int(input())
a = [int(x) for x in input().rstrip("\n").split()]
q = deque(a)

while len(q) > 1:
    x = q.popleft()
    y = q.popleft()
    z =  math.gcd(x, y)
    q.append(z)

ans = q.popleft()
print(ans)

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import deque

input = sys.stdin.readline

N = int(input())
a = [int(x) for x in input().split()]
q = deque(a)

while len(q) > 1:
    x = q.popleft()
    y = q.popleft()
    z =  math.gcd(x, y)
    q.append(z)

ans = q.popleft()
print(ans)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
A = list(map(int,input().split()))

# ユークリッドの互除法
# 全体の最小公約数 = 最小値
min_life = math.gcd(A[0],A[1])

for i in range(1,N):
    min_life = math.gcd(min_life,A[i])

print(min_life)

Submission status: Runtime Error

Solution code:
import sys
import fractions

sys.setrecursionlimit(10**5+1)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return [int(x) for x in input().split()]
MOD = 10**9 + 7

N = INT()

A = LIST()

def gcd_all(n):
    if len(n) == 1:
        return n[0]

    tail = n.pop(-1)
    return fractions.gcd(tail, gcd_all(n))

print(gcd_all(A))

Submission status: Runtime Error

Solution code:
import sys
import fractions

sys.setrecursionlimit(10**5)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return [int(x) for x in input().split()]
MOD = 10**9 + 7

N = INT()

A = LIST()

def gcd_all(n):
    if len(n) == 1:
        return n[0]

    tail = n.pop(-1)
    return fractions.gcd(tail, gcd_all(n))

print(gcd_all(A))

Submission status: Runtime Error

Solution code:
import sys
import fractions

sys.setrecursionlimit(1000)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def LIST(): return [int(x) for x in input().split()]
MOD = 10**9 + 7

N = INT()

A = LIST()

def gcd_all(n):
    if len(n) == 1:
        return n[0]

    tail = n.pop(-1)
    return fractions.gcd(tail, gcd_all(n))

print(gcd_all(A))

Submission status: Runtime Error

Solution code:
import math
n=int(input())
a=list(map(int, input().split()))
ans = a[0]
for i in range(1, n):
    ans = math.gcd(ans, a[i])
print(ans)

Submission status: Runtime Error

Solution code:
import math

input()
a = sorted((map(int, input().split())))
ans = a[0]
for i in range(1, len(a)):
    ans = math.gcd(ans, a[i])
print(ans)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
A = list(map(int, input().split()))

if N == 1:
    print(A[0])
else:
    res = math.gcd(A[0], A[1])
    for i in range(2, N):
        res = math.gcd(res, A[i])
    print(res)

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def gcd_multi(nums):
    if len(nums) == 0:
        return 0
    if len(nums) == 1:
        return nums[0]

    ret = math.gcd(nums.pop(), nums.pop())
    while len(nums) > 0:
        ret = math.gcd(ret, nums.pop())
    return ret


def solve(inputs):
    monsters = string_to_int(inputs[0])
    return gcd_multi(monsters)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Runtime Error

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def gcd_multi(nums):
    if len(nums) == 0:
        return 0
    if len(nums) <= 2:
        return min(nums)

    ret = math.gcd(nums.pop(), nums.pop())
    while len(nums) > 0:
        ret = math.gcd(ret, nums.pop())
    return ret


def solve(inputs):
    monsters = string_to_int(inputs[0])
    return gcd_multi(monsters)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Runtime Error

Solution code:
N = int(input())
Lifes = map(int, input().split())

Lifes.sort(key=lambda x:-x)

ans = Lifes[N-1]

for i in range(N):
  for j in range(i, N):
    life = Lifes[i] - Lifes[j]
    if life > 0:
      ans = min(ans, life)
print(ans)

Submission status: Runtime Error

Solution code:
N = int(input())
Lifes = map(int, input().split())

Lifes.sort(key=lambda x:-x)

ans = Lifes[N-1]

for i in range(N):
  for j in range(i, N):
    life = Lifes[i] - Lifes[j]
    if life > 0:
	  ans = min(ans, life)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
li = list(map(int,input().split()))

while len(li) > 1:
  a = min(li)
  for i in range(len(li)):
    li[i] %= a
    if li[i] == 0:
      li.pop(i)
      
print(li[0])

Submission status: Runtime Error

Solution code:
import math

N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    if i == 0:
        ans = A[i]
    else:
        ans = math.gcd(ans, A[i])
        
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
A=list(map(int,input().split()))


A.sort()

mini=A[0]
flag=0

for i in range(1,N-1):
    if A[i]%mini!=0:
        mini=min(mini,A[i+1]%mini)
        flag=1

if flag==0:
    print(A[0])
else:
    print(mini)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int, input().split()))
gcd = a[0]
for i in range(n):
    gcd = math.gcd(gcd,a[i])

print(gcd)

Submission status: Runtime Error

Solution code:
import math

N = int(input())
A = list(map(int, input().split()))
B = 0
for i in range(N):
    B = math.gcd(B, A[i])
print(B)

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))

def progress():
    for i in range(N):
        hp = A[i]
        for j in range(N):
            if i == j:
                continue
            if A[i] > A[j]:
                A[i] -= A[j]
                progress()
            if min(A) == 1:
                break
        if min(A) == 1:
            break
    return min(A)

ans = progress()
print(ans)

Submission status: Runtime Error

Solution code:
def progress():
    for i in range(N):
        hp = A[i]
        for j in range(N):
            if i == j:
                continue
            if A[i] > A[j]:
                A[i] -= A[j]
                progress()
            if min(A) == 1:
                break
        if min(A) == 1:
            break
    return min(A)

ans = progress()
print(ans)

Submission status: Runtime Error

Solution code:
import math
import functools

n = int(input())
monsters = list(map(int, input().split()))

print(functools.reduce(math.gcd, monsters))

Submission status: Runtime Error

Solution code:
N = int(input())
lst = list(map(int, input().split()))
boolean = False
updated_lst = []
minimum = min(lst)
min_num = 0
for i in lst:
  num = i % minimum
  if (i != minimum):
    updated_lst.append(num)
  else:
    updated_lst.append(minimum)
    min_num += 1
  if (num % 2 == 1):
    boolean = True

if (min_num == len(lst)):
  print(minimum)
else:
  if (boolean):
    print(1)
  else:
    print(min(updated_lst)

Submission status: Runtime Error

Solution code:
N = int(input())
lst = list(map(int, input().split()))
boolean = False
updated_lst = []
minimum = min(lst)
min_num = 0
for i in lst:
  num = i % minimum
  if (i != minimum):
    updated_lst.append(num)
  else:
    updated_lst.append(minimum)
    min_num += 1
  if (num % 2 == 1):
    boolean = True

sum = sum(updated_lst)

if (sum == minimum*min_num):
  print(minimum)
else:
  if (boolean):
    print(1)
  else:
    print(min(updated_lst)

Submission status: Runtime Error

Solution code:
N = int(input())
lst = list(map(int, input().split()))
boolean = False
updated_lst = []
min = min(lst)
min_num = 0
for i in lst:
  num = i % min
  if (i != min):
    updated_lst.append(num)
  else:
    updated_lst.append(min)
    min_num += 1
  if (num % 2 == 1):
    buulean = True

sum = sum(updated_lst)

if (sum == min*min_num):
  print(min)
else:
  if (boolean):
    print(1)
  else:
    print(min(updated_lst))

Submission status: Runtime Error

Solution code:
import math

N = int(input())
HP = input().split()

while True:
    a = math.gcd(int(HP[-1]),int(HP[0]))
    del HP[-1]
    del HP[0]
    HP.append(str(a))
    if len(HP) == 1:
        print(HP[0])
        break

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

N = int(input())
HP = input().split()

while True:
    a = math.gcd(int(HP[-1]),int(HP[0]))
    del HP[-1]
    del HP[0]
    HP.append(str(a))
    if len(HP) == 2:
        print(math.gcd(int(HP[-1]),int(HP[0])))
        break

Submission status: Runtime Error

Solution code:
import math
N = int(input())
A = [int(i) for i in input().split()]

ans = A[0]

for a in A:
  ans = math.gcd(ans,a)

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
while len(a)>1:
  a.sort()
  for i in range(1,n):
    a[i]=a[i]%a[0]
  a.replace(0,'')
  n=len(a)
print(a[0])

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)

n = int(input())
a = list(map(int, input().split()))

ans = gcd(*a)
print(ans)

Submission status: Runtime Error

Solution code:
import math
n = int(raw_input())
a = list(map(int,raw_input().split()))
g = 0
for i in range(len(a)):
    g = math.gcd(g,a[i])
print(g)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
g = 0
for i in range(len(a)):
    g = math.gcd(g,a[i])
print(g)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
g = 0
for _ in range(len(a)):
    g = math.gcd(g,a[_])
print(g)

Submission status: Runtime Error

Solution code:
import fractions
n = int(input())
a = list(map(int,input().split()))
for N in range(n - 1):
    a[N + 1] = math.gcd(a[N],a[N + 1])
print(a[n - 1])

Submission status: Runtime Error

Solution code:
from math import gcd
N = int(input())
A = list(map(int, input().split()))

ans = 0
for i in range(N):
    ans = gcd(ans, A[i])

print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

N =int(input())
A = list(map(int,input().split()))
print(reduce(math.gcd,A))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
input()
N=list(map(int,input().split()))
print(reduce(math.gcd,N))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
input()
N=list(map(int,input().split()))
reduce(math.gcd,N)

Submission status: Runtime Error

Solution code:
from fractions import gcd
n=int(input())
num=list(map(int,input().split()))
for i in range(len(num-1)):
  if i==0:
    ans=gcd(num[0],num[1])
  else:
    ans=gcd(ans,num[i+1])
print(ans)

Submission status: Runtime Error

Solution code:
# PROXY

import functools
import math
N = int(input())
Nlist = [int(i) for i in input().split()]
gcd = functools.reduce(math.gcd, Nlist)
print(gcd)

Submission status: Runtime Error

Solution code:
N=int(input())
A=map(int,input().split())
a=min(A)
for i in range(N):
    if A[i]%a == 0:
        pass
    else:
        a=A[i]%a
for i in range(N):
    if A[i]%a == 0:
        pass
    else:
        a=A[i]%a
print(a)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
m = list(map(int,input().split()))
ans = 0

for i in range(n):
	ans = math.gcd(ans,m[i])
print(ans)

Submission status: Runtime Error

Solution code:
import math

n = int(input())
A = list(map(int, input().split()))
ans = 1e9
for i in range(1, n):
    ans = min(ans, math.gcd(A[i], A[i - 1]))
print(ans)

Submission status: Runtime Error

Solution code:
from sys import stdin
import math
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
ans = A[0]
for k in range(N)[1:]:
    ans = math.gcd(ans, A[k])
print(ans)