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

Solution code:
from collections import Counter


def factor(N):
    ret = []
    i = 2
    while N > 1:
        if N % i == 0:
            ret.append(i)
            N //= i
        else:
            i += 1
    return ret


def solve(N, As):
    iter = Counter(factor(min(As)))

    for a in As:
        for k, v in iter.items():
            if a % k != 0:
                iter[k] = 0
            else:
                count = 0
                kk = k
                while a % kk == 0:
                    kk *= k
                    count += 1
                iter[k] = min(v, count)
    d = 1
    for k, v in iter.items():
        if v != 0:
            d *= k ** v
    return d

if __name__ == "__main__":
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(solve(N, As))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

ans = A[0]
tmp = []
for i in range(1,N):
  tmp.append(gcd(ans,A[i]))
print(min(tmp))

Submission status: Accepted

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

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

from functools import reduce

print(reduce(gcd, aa))

Submission status: Accepted

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

#print(A)

def gcd(a,b):
    if a!=1 and b!=1 :
        while a!=b:
            if a>b :
                m=a%b
                if m==0 :
                    a=b
                else :
                    a=m
                        
                    
                
            else :        
                m=b%a
                if m==0 :
                    b=a
                else :
                    b=m
        return a
    return 1

aa=A[0]
for i in range(n) :
    aa=gcd(aa,A[i])
    #print(i)
print(aa)

Submission status: Accepted

Solution code:
from fractions import gcd
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: Accepted

Solution code:
def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x


assert gcd(12, 4) == 4
assert gcd(5, 8) == 1


def solve():
    N = int(input())
    A = [int(x) for x in input().split()]
    ans = A[0]
    for i in range(1, N):
        ans = gcd(ans, A[i])
    return ans


def main():
    print(solve())


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z 
        
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: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
ans=0
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)
if n==1:
    ans=l[0]
else:
    element = gcd(l[0], l[1])
    if n==2:
      ans=element
    else:
        for i in range(2,n):
            element=gcd(element,l[i])
        ans=element
print(ans)

Submission status: Accepted

Solution code:
import fractions


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

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

print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

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


def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


print(reduce(gcd, A))

Submission status: Accepted

Solution code:
def gcd(a,b):
  while b:
    a,b=b,a%b
  return a
N=int(input())
l=list(map(int,input().split()))
c=gcd(l[0],l[1])
for i in range(1,N-1):
  c=gcd(l[i],c)
print(c)

Submission status: Accepted

Solution code:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
    
N = int(input())
lst = list(map(int, input().split(' ')))

v = sorted(lst)[-1]

for x in lst:
    v = gcd(v, x)
    
print(v)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
from functools import reduce
def gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a
def gcd_list(numbers):
    return reduce(gcd, numbers)
print(gcd_list(a))

Submission status: Accepted

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

def gcd(a,b):
    if (b == 0) :
        return a
    else:
        return gcd(b, a%b)

num = gcd(a[0],a[1])

for i in range(n):
    num = gcd(num,a[i])
    if num == 1:
        break
print(num)

Submission status: Accepted

Solution code:
#coding:utf-8
from functools import reduce
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
N = input()
A = list(map(int,input().split()))
print (reduce(gcd,A))

Submission status: Accepted

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

def euclid(a, b):
    if a>b:
        tmp = a
        a = b
        b = tmp
    while a>0:
        c = b%a
        b = a
        a = c
    return b

def sub_gcd(X):
    Y = []
    P, Q = len(X)//2, len(X)%2
    for p in range(P):
        y = euclid(X[2*p], X[2*p+1])
        Y.append(y)
    if Q!=0:
        Y.append(X[-1])
    return Y

def gcd(X):
    Y = sub_gcd(X)
    while len(Y)>1:
        Y = sub_gcd(Y)
    return Y[0]

print(gcd(A))

Submission status: Accepted

Solution code:
from functools import reduce
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return gcd(b, a % b)

N = int(input())
A = [int(x) for x in input().split()]
print(reduce(gcd, A))

Submission status: Accepted

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

def gcd(*num):
    return reduce(fractions.gcd, num)

print(gcd(*a))

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))
L = sorted(L)
while True:
    for i in range(1,len(L)):
        L[i] %= L[0]
    L= filter(lambda x:x!=0,L)
    L= sorted(L)
    if len(L) == 1:
        break
print(L[0])

Submission status: Accepted

Solution code:
#! usr/bin/env python
# -*- coding: utf-8 -*-

from collections import deque
import heapq
import math
import bisect


def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


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

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

    print(g)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import gcd
N=int(input())
A = list(map(int,input().split()))
r=A[0]

for i in A[1:]:
    r = gcd(r,i)
print(r)

Submission status: Accepted

Solution code:
def gcd(a, b):
    return a if b == 0 else gcd(b, a % b)

n = input()
aa = list(map(int, input().split()))
g = aa[0]
for a in aa:
    g = gcd(g, a)
print(g)

Submission status: Accepted

Solution code:
def GCD(x, y):
    if x < y:
        return GCD(y, x)
    if y == 0:
        return x
    return GCD(y, x % y)

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

Submission status: Accepted

Solution code:
from fractions import gcd


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

now = A[0]
for i in range(1, N):
    if gcd(now, A[i]) != 1:
        now = gcd(now, A[i])
    else:
        now = 1
print(now)

Submission status: Accepted

Solution code:
import math
import copy
import bisect







def nCast(number):
    if type(number)==str:
        return int(number)
    for idx in range(0,len(number)):
        if type(number[idx])==str:

            number[idx]=int(number[idx])
        else:
            nCast(number[idx])
    return number
    
def inputArr(w):
    l=list()
    for idx in range(0,w):
        l.append(input())
    return l
def inputArr1(w):
    l=list()
    for idx in range(0,w):
        l.append(input().split())
    return l

n=nCast(input())
m=nCast(input().split())



def func():
    s=set(m)
    while len(s)>1:
        l=list()
        for n in s:
            l.append(n)
        l.sort()
        s=set()
        s.add(l[0])
        for n in l:

            k=n%l[0]
     
            if k==1:
                return k
            if k!=0:
                s.add(n%l[0])
    for i in s:
        return i
    

print(func())

Submission status: Accepted

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

def kouyaku(a, b):
    if a % b == 0:
        return b
    else:
        return kouyaku(b, a % b)
a.sort()
tmpa = a[0]
for i in range(1, n):
    tmpa = kouyaku(tmpa, a[i])
print(tmpa)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
data=set()
for x in a:
    data|={x,}
while True:
    now=min(data)
    data-={now,}
    if now==1:
        ans=now
        break
    if len(data)==0:
        ans=now
        break
    for i in range(len(data)):
        check=data.pop()
        check%=now
        if check!=0:
            data|={check,now,}
            break
    data|={now,}
print(ans)

Submission status: Accepted

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

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

a = int(input())

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

print(gcd_list(b))

Submission status: Accepted

Solution code:
def gcd(x,y):
  if y==0:
    return x
  else:
    return gcd(y,x%y)

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

g=a[0]
for aa in a:
  g=gcd(g,aa)
print(g)

Submission status: Accepted

Solution code:
from fractions import gcd

n = int(input())
A = [int(i) for i in input().split()]

ans = gcd(A[0], A[1])

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

print(ans)

Submission status: Accepted

Solution code:
import math

def main():
    buf = input()
    N = int(buf)
    buf = input()
    buflist = buf.split()
    A = list(map(int, buflist))
    remaining = list(sorted(set(A)))
    while len(remaining) > 1:
        smallest = remaining[0]
        for i in range(1, len(remaining)):
            remaining[i] %= smallest
        new_remaining = []
        for i in remaining:
            if i > 0:
                new_remaining.append(i)
        remaining = list(sorted(set(new_remaining)))
    print(remaining[0])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import gcd

N = int(input())
A = [int(n) for n in input().split()]

g = A[0]

for i in range(N - 1):
    g = gcd(A[i + 1], g)

print(g)

Submission status: Accepted

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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
def gcd_list(numbers):
    return reduce(gcd, numbers)
n = int(input())
a = list(map(int, input().split()))
print(gcd_list(a))

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
while len(A) > 1:
  A.sort()
  _A = [A[0]]
  for a in A[1:]:
    a %= A[0]
    if a:
      _A.append(a)
  A = _A
print(A[0])

Submission status: Accepted

Solution code:
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)

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

Submission status: Accepted

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

for n in range(N-1):
  r = -1
  while r!= 0:
    r = A[n] % A[n+1]
    A[n] = A[n+1]
    A[n+1] = r
  A[n+1] = A[n]

print(A[-1])

Submission status: Accepted

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

def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)

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

print(res)

Submission status: Accepted

Solution code:
N = int(input())
import math
#ユークリッド互除法の関数の定義
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)
x = list(map(int,input().split()))

if N==1:
    print(x[0])
else:
    element = gcd(x[0], x[1])
    if N==2:print(element)
    else:
        for i in range(2,N):
            element=gcd(element,x[i])
        print(element)

# print(gcd_list(numbers))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
mina = max(a)
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
a.sort()
for i in range(n-1):
    mina = min(mina,gcd(a[i],a[i+1]))
print(mina)

Submission status: Accepted

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
n=int(input())
li = list(map(int,input().split()))
a=li[0]
for i in range(n):
    a=gcd(li[i],a)
print(a)

Submission status: Accepted

Solution code:

from functools import reduce

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

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

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

print(gcd_list(a))

Submission status: Accepted

Solution code:
from fractions import gcd

n = int(input())
aaa = list(map(int, input().split()))
ans = aaa[0]
for a in aaa[1:]:
    ans = gcd(ans, a)
print(ans)

Submission status: Accepted

Solution code:
def gcd(a,b):
	if a == 0:
		return b
	if b == 0:
		return a
	if a < b:
		n = b//a
		return gcd(a,b-n*a)
	else:
		n = a//b
		return gcd(a-n*b,b)

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

ans = A[0]
for i in A[1:]:
	ans = gcd(ans,i)
print(ans)

Submission status: Accepted

Solution code:
def gcd(a,b): #最大公約数
    if b == 0:
        return abs(a)
    else:
        return gcd(b, a%b)

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

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

print(ans)

Submission status: Accepted

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

L = sorted(L)

while len(L) != 1 :
    L = sorted(L)
    while L[0] == 0 :
        L.pop(0)
    if len(L) >= 2 :
        for i in range(1,len(L)) :
            L[i] = L[i] % L[0]
print(L[0])

Submission status: Accepted

Solution code:
from sys import stdin

N, *A = map(int, stdin.read().split())

A_min = min(A)

k = 1
for i in range(int(A_min**0.5))[::-1]:
    if A_min % (i+1) != 0:
        continue
    k1, k2 = i+1, A_min//(i+1)
    if all(a % k2 == 0 for a in A):
        k = max(k, k2)
    elif all(a % k1 == 0 for a in A):
        k = max(k, k1)

print(k)

Submission status: Accepted

Solution code:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

def main():
    N=int(input())
    ary = list(map(int,input().split()))
    ans = ary[0]
    for elem in ary:
        ans = gcd(ans,elem)
    print(ans)

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
def gcd(a,b): 
    if(b==0): 
        return a 
    else: 
        return gcd(b,a%b)


N = int(input())

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

print(a)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)

def main(n):
	a = list(map(int, input().split()))
	a = list(set(a))
	while True:
		m = a[0]
		flg= True
		for k in a[1:]:
			if k % m == 0:
				continue
			if k % m < m:
				m = k%m
				a = [m]+a
				flg = False
		if flg:
			print(m)
			break
	return
main(int(input()))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y,x%y)
g = gcd(a[0],a[1])
for i in range(n):
    g = gcd(g,a[i])
print(g)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
a = int(input())

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


def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
ind = X[0]
for i in range(len(X)):
    ind = gcd(ind, X[i])
print(ind)

Submission status: Accepted

Solution code:
from statistics import mean, median,variance,stdev
import numpy as np
import sys
import math
import fractions

def j(q):
    if q==1: print("Yes")
    else:print("No")
    exit(0)


def ct(x,y):
    if (x>y):print("")
    elif (x<y): print("")
    else: print("")

def ip():
    return int(input())


n = ip()                              #入力整数1つ
#a,b= (int(i) for i in input().split())      #入力整数横2つ
#n,x,y = (int(i) for i in input().split())    #入力整数横3つ
#n,m,x,y= (int(i) for i in input().split())  #入力整数横4つ
a = [int(i) for i in input().split()]        #入力整数配列
#a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)


#jの変数はしようできないので注意
#全足しにsum変数使用はsum関数使用できないので注意
s = a[0]
for i in range(1,n):
    s = fractions.gcd(s,a[i])
print(s)

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)

N = int(input())
A = [int(i) for i in input().split()]

result = 0
for ai in A:
    result = gcd(result, ai)

print(result)

Submission status: Accepted

Solution code:
from fractions import gcd
def  inpl(): return list(map(int, input().split()))

N = int(input())
A = inpl()

a = A[0]
for b in A[1:]:
    a = gcd(a, b)
print(a)

Submission status: Accepted

Solution code:
def c_monsters_battle_royale(N, A):
    from fractions import gcd
    from functools import reduce
    ans = reduce(gcd, A)
    return ans

N = int(input())
A = [int(i) for i in input().split()]
print(c_monsters_battle_royale(N, A))

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    elif b == 1:
        return 1
    return gcd(b, a % b)

if __name__ == "__main__":
    N = int(input())
    li = input().split()
    g = int(li[0])
    for i in range(N):
        g = gcd(g, int(li[i]))
    print(g)

Submission status: Accepted

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


def gcd(a, b):
    if b > a:
        a, b = b, a
    while b > 0:
        a, b = b, a % b
    return a


print(reduce(gcd, A))

Submission status: Accepted

Solution code:
def gcd(a,b):
    if a < b:
        return gcd(b,a)
    else:
        if a%b == 0:
            return b
        else:
            return gcd(b,a%b)
N = int(input())
src = sorted(list(map(int,input().split())))
ans = src[0]
for i in range(1,N)[::-1]:
    ans = gcd(ans,src[i])
print(ans)

Submission status: Accepted

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

A.sort()

def gcd(n,m):
	if n%m==0:
		return(m)
	else:
		return(gcd(m,n%m))

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

Submission status: Accepted

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

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

def gcd2(a_list):
    if len(a_list)==2:
        return gcd(a_list[0],a_list[1])
    elif len(a_list)==1:
        return a_list[0]
    else:
        return gcd(gcd2(a_list[:len(a_list)//2]),gcd2(a_list[len(a_list)//2:]))

print(gcd2(A))

Submission status: Accepted

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

while len(A) > 1:
    a = min(A)
    B = {a}
    for a2 in A:
        b = a2 % a
        if b != 0:
            B.add(b)
    A = B

print(A.pop())

Submission status: Accepted

Solution code:
from functools import reduce

def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)

def gcd_mult(numbers):
    return reduce(gcd, numbers)


N = int(input())
A = [int(a) for a in input().split()]

print(gcd_mult(A))

Submission status: Accepted

Solution code:
from fractions import gcd
N = int(input())
a = list(map(int, input().split()))
ans = a[0]
for ai in a:
    ans = gcd(ans, ai)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
n = int(input())
a = list(map(int,input().split()))
#入力

def gcd(a):
    ans = a[0]
    n = len(a)
    for i in range(1,n):
        ans = fractions.gcd(ans,a[i])
    return ans

print(gcd(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd(a,b):
    if b==0: return a
    return gcd(b,a%b)

n=int(input())
x=list(map(int,input().split()))
a=x[0]
for i in range(1,n):
    a=gcd(a,x[i])
print(a)

Submission status: Accepted

Solution code:
from fractions import gcd

n = input()
a = map(int, raw_input().strip().split())

g = a[0]
for i in xrange(1, n): g = gcd(g, a[i])

print g

Submission status: Accepted

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

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b:
        a, b = b, a % b
    return a

A.sort()

x = A[0]
for y in A[1:]:
    x = gcd(x, y)

print(x)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
a = int(input())
x = list(map(int, input().split()))
x.sort()
y = x[0]
for i in range(1,a):
    y = gcd(y,x[i])
print(y)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
n=int(input())
a=list(map(int,input().split()))
def gcd(x,y):
    while x != 0:
        x,y=y%x,x
    return y
def lcm(x,y):
    return (x * y)//gcd(x, y)
print(reduce(gcd,a))

Submission status: Accepted

Solution code:
def kouyaku(a,b):
    aa = max(a,b)
    bb = min(a,b)
    if bb == 0:
        return aa
    else:
        return kouyaku(bb,aa%bb)

N = int(input())
A = [int(i) for i in input().split()]
ans = A[0]
A.sort()
for i in range(N):
    ans = kouyaku(ans, A[i])
print(ans)

Submission status: Accepted

Solution code:
from fractions import *
n = int(input())
a = list(map(int, input().split()))
d = a[0]
for x in a:
	d = gcd(d, x)
print(d)

Submission status: Accepted

Solution code:
def gcd(a,b):
    x,y=max(a,b),min(a,b)
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)
N=int(input())
A=[int(i) for i in input().split()]
ans=A[0]
for i in range(1,N):
    ans=gcd(ans,A[i])
print(ans)

Submission status: Accepted

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

import fractions

num = a_list[0]

for i in range(N):
    a = a_list[i]
    num = fractions.gcd(num, a)
print(num)

Submission status: Accepted

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


# 最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


while len(A) > 1:
    A.append(gcd(A.pop(), A.pop()))

print(A[0])

Submission status: Accepted

Solution code:
def inpl(): return list(map(int, input().split()))

def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)

N = int(input())
A = inpl()
ans = gcd(A[0], A[1])
for a in A[2:]:
    ans = gcd(ans, a)
print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import fractions
import functools

input()
print(functools.reduce(fractions.gcd, [int(x) for x in input().split()]))

Submission status: Accepted

Solution code:
from fractions import gcd

N = int(input())

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

d = A[0]

for a in A:
  d = gcd(d,a)

print(d)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
a = A[0]


def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


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


print(a)

Submission status: Accepted

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

def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

ANS=A[0]

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

print(ANS)

Submission status: Accepted

Solution code:
#!/mnt/c/Users/moiki/bash/env/bin/python
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a

# N,M = map(int, input().split())
N = int(input())
from functools import reduce
A = list(map(int, input().split()))

a = reduce(gcd, A)
print(a)

Submission status: Accepted

Solution code:
def gcd(m, n):
    while n: m, n = n, m%n
    return m

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

Solution code:
def gcd(m, n):
    r = m % n
    return gcd(n, r) if r else n

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

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from functools import reduce

def gcd(a,b):
    if a%b == 0:
        return b
    else:
        return gcd(b, a%b)
    
n = ni()
a = list(li())
print(reduce(gcd, a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
def gcd(a,b):
	while b:
		a,b=b,a%b
	return a

g = A[0]
for a in A[1:]:
    g = gcd(g, a)
print(g)

Submission status: Accepted

Solution code:
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
g = A[0]
for a in A:
    g = gcd(g,a)
print(g)

Submission status: Accepted

Solution code:
from fractions import gcd

N = input()
A = map(int, raw_input().split())
ans = A[0]
for a in A:
  ans = gcd(ans, a)
print ans

Submission status: Accepted

Solution code:
from fractions import gcd

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

G = A[0]

for i in xrange(1, N):
    G = gcd(G, A[i])

print G

Submission status: Accepted

Solution code:
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)

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

Submission status: Accepted

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

#a,bの最大公約数
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)

#リスト l の最大公約数
def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a
print(gcdlist(li))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
import math
import bisect
import random
def LI(): return list(map(int, input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return list(input())
def IIR(n): return [II() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
mod = 1000000007

#A

#B

#C
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = II()
a = LI()
ans = a[0]
for i in range(1,n):
    ans = gcd(ans,a[i])
print(ans)
#D

#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sys
from collections import deque


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

m = min(A)

mod_min = 10**9

for a in A:
    if a % m == 0:
        continue
    mod_min = min(mod_min, a % m)

if mod_min == 10**9:
    print(m)
else:
    print(max(mod_min % (m % mod_min), 1))

Submission status: Runtime Error

Solution code:
import sys
from collections import deque


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

m = min(A)

mod_min = 10**9

for a in A:
    if a % m == 0:
        continue
    mod_min = min(mod_min, a % m)

if mod_min == 10**9:
    print(m)
else:
    print(mod_min % (m % mod_min))