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 (Python):

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


def lcm(a, b):
    return a * b // gcd(a, b)


def gcds(l):
    if len(l) == 1:
        return l[0]
    elif len(l) == 2:
        return gcd(l[0], l[1])
    else:
        n = len(l) // 2
        L = l[:n]
        R = l[n:]
        return gcd(gcds(L), gcds(R))


def lcms(l):
	if len(l) == 1:
		return l[0]
	elif len(l) == 2:
		return lcm(l[0], l[1])
	else:
		n = len(l) // 2
		L = l[:n]
		R = l[n:]
		return lcm(lcms(L), lcms(R))

n = input()
a = [int(i) for i in input().split()] 
print(gcds(a))

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

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

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

while 1:
    minimam = min(li)
    maximam = max(li)
    temp = li.copy()
    li = [i % minimam if i% minimam != 0 else i for i in li]
    if temp == li:
        print(minimam)
        break

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

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

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

Solution (Python):
import sys
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(a, b):
    if a == 0:
        return b
    if b == 0:
        return a

    if a > b:
        return gcd(b, a % b)
    else:
        return gcd(a, b % a)


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

    ret = gcd(nums.pop(), nums.pop())
    while len(nums) > 0:
        ret = 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)

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

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

ans = Lifes[N-1]








update = True
while update:
    min_num = ans
    for i in range(N):
        life_mod = Lifes[i]%ans
        if life_mod > 0:
            Lifes[i] = life_mod
            if min_num > life_mod:
                min_num = life_mod
    if ans == min_num:
        update=False
    else:
        ans = min_num
print(ans)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
while True:    
  a = set(a)-{0}
  a = sorted(list(a))  
  if (a[0]==sum(a)) or (a[0]==1):    
    print(a[0])
    break
  a = [ai%a[0] for ai in a[1:]] + [a[0]]

Solution (Python):
def euc(x, y):
	if y == 0:
		return x
	return euc(y, x%y)

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

Solution (Python):
from functools import reduce


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


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

print(reduce(gcd, a))

Solution (Python):
from fractions import gcd


def main():
    _ = int(input())
    *a, = map(int, input().split())
    ans = a[0]
    for aa in a[1:]:
        ans = gcd(ans, aa)
    print(ans)


main()

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

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

Solution (Python):
import functools
def gcd(a,b):
    m=max(a,b)
    n=min(a,b)
    return n if m%n==0 else gcd(n,m%n)

def resolve():
    n=int(input())
    a=list(map(int,input().split()))
    print(functools.reduce(gcd,a))

resolve()

Solution (Python):
def gcd(a, b) -> int:
    return gcd(b % a, a) if a != 0 else b


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

if len(set(A)) == 1:
    print(A[0])
    exit()

ret = A[0]

for a in A[1:]:
    ret = gcd(ret, a)

print(ret)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
 
def gcd(a, b):
  while b > 0:
    a, b = b, a % b
  return a
  
ans = A[0]
for i in range(1, N):
  ans = gcd(ans, A[i])
    
print(ans)

Solution (Python):
import fractions
n = int(input())
l = list(map(int,input().split()))

gcd = l[0]
for i in range(1,n):
    gcd = fractions.gcd(l[i],gcd)
print(gcd)

Solution (Python):
a = int(input())
b = list(map(int, input().split()))
b.sort()
while True:
    c = []
    c.append(b[0])
    for i in range(1, len(b)):
        if b[i] % b[0] != 0:
            c.append(b[i] % b[0])
    if len(b) == 1:
        print(b[0])
        exit()
    else:
        b = c
        b.sort()

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


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


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

print(ans)

Solution (Python):



n = int(input())
a = list(map(int,input().split()))
a.sort()
c = a.count(0)
mi = 10**9
while 1:
    for i in range(c+1,n):
        a[i] = a[i] % a[c]
    a.sort()
    c = a.count(0)
    if a[-2] == 0:
        break
print(a[-1])

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

Solution (Python):
n = input()

monster = [int(x) for x in input().split()]

while(True):
	minIndex = monster.index(min(monster))
	for i in range(len(monster)): 
		if i == minIndex or monster[i] == 0:
			continue
		if monster[i] % monster[minIndex] == 0:
			monster[i] = 0
		else:
			monster[i] -= monster[minIndex] * (monster[i]//monster[minIndex])
	monster = [x for x in monster if x != 0]
	if len(monster) == 1:
		print(monster[0])
		break

Solution (Python):
def gcd(x,y):
    while y:
        x,y = y , x % y 
    return x

def gcd2(array):
    t = array[0]
    for i in array:
        t = gcd(t,i)
    return t

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

Solution (Python):
from fractions import gcd

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

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

print(g)

Solution (Python):
def gcd(a, b):
    if a < b:
        a, b = b, a
    while(b != 0):
        a, b = b, a%b
    return a

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)

Solution (Python):
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)

Solution (Python):
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)

Solution (Python):
import fractions

N = int(input())
monster = [int(x) for x in input().split()]
ans = monster[0]
for i in range(1, N):
    ans = fractions.gcd(ans, monster[i])


print(ans)

Solution (Python):
def gcd(a, b):
    while b >= 1:
        a, b = b, a % b
    return a


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

ret = hs[0]
for h in hs[1:]:
    ret = gcd(ret, h)
print(ret)

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

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

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

Solution (Python):
from functools import reduce

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

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

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

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

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

Solution (Python):
def gcd(a,b):
  while b!=0:
    a,b=b,a%b
  return a

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

Solution (Python):

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

As = sorted(A)
As = [a%As[0] if a%As[0] != 0 else As[0] for a in As]
As = sorted(As)

def judge(tmp_one, tmp_two):
    flg = 1

    while flg:
        if tmp_two%tmp_one == 0:
            tmp_two = tmp_one
        else:
            tmp_two = tmp_two%tmp_one

        if tmp_one%tmp_two == 0:
            tmp_one = tmp_two
        else:
            tmp_one = tmp_one%tmp_two
        if tmp_one == tmp_two:
            flg = 0

    return tmp_one

tmp_one = As[0]
for i in range(1, N):
    if i == N - 1:
        tmp_two = As[i]
    elif As[i] != As[0]:
        tmp_two = As[i]
        break

ans = judge(tmp_one, tmp_two)
print(ans)

Solution (Python):
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

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

n=int(input())
l=list(intinput())
ans=0
for i in l:
    ans=gcd(ans,i)
print(ans)

Solution (Python):
import fractions

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

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


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


ans = float("Inf")
for i in range(n - 1):
    ans = min(ans, gcd(a[i], a[i + 1]))
print(ans)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))


def remainder(a):
    a.sort()
    for i in range(1, len(a)):
        a[i] = a[i] % a[0]
    count = a.count(0)
    for i in range(count):
        a.remove(0)
    if len(a) == 1:
        return a
    return remainder(a)


print(remainder(a)[0])

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

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

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

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

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

ans = a[0]
for i in range(n):
  ans = gcd(ans, a[i])
print(ans)

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

def uplow(a,b):
    if a<b:up=b;low=a
    else:up=a;low=b
    return up,low

def euclid(a,b):
    up,low=uplow(a,b)
    while 1:
        up,low=low,up%low
        if low==0:return up

ans=A[0]
for i in range(1,N):
    ans=euclid(ans,A[i])
print(ans)

Solution (Python):
import fractions

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

Solution (Python):
from functools import reduce
from fractions import gcd

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

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

Solution (Python):
import fractions

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

ans = A[0]
for i in range(N-1):
  ans = fractions.gcd(ans, A[i+1])
print(ans)

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

def gcd(a, b):
	if not a % b:
		return b
	return gcd(b, a % b)

gcd_num = A[0]
for n in range(1, N):
	gcd_num = gcd(gcd_num, A[n])

print(gcd_num)

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

n = int(input())
lst = list(map(int,input().split()))
ans = lst.pop(0)
for i in range(n-1):
    b = lst.pop(0)
    ans = gcd(ans,b)
print(ans)

Solution (Python):
import functools
N = int(input())
n_lis = sorted(list(map(int, input().split())), reverse=True)

while len(set(n_lis)) > 1:
    n_lis = sorted(n_lis)
    n_lis = [n_lis[0]] + [n_lis[i] % n_lis[0] for i in range(0, len(n_lis))]
    
    n_lis = [item for item in n_lis if item > 0]

print(min(n_lis))

Solution (Python):
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)

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

def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)
		
res = A[0]

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

Solution (Python):
from functools import reduce
from fractions import gcd
input()
print(reduce(gcd,map(int,input().split())))

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()]
A.sort()
while len(A) != 1:
    k = 0
    for i in range(1,len(A)):
        if A[i-k]%A[0] == 0:
            del A[i-k]
            k += 1
        else:
            A[i-k] = A[i-k] % A[0]
    A.sort()
print(A[0])

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

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

print(ans)

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

def search_common_divisor(x,y):
    if x<y:
        x,y=y,x
    while y!=0:
        x,y=y,x%y
    return x

def search_list_common_divisor(*numbers):
    b=[search_common_divisor(numbers[0],numbers[1])]
    for i in numbers:
        b.append(search_common_divisor(b[-1],i))
    return b[-1]

print(search_list_common_divisor(*a))

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

def search_common_divisor(x,y):
    if x<y:
        x,y=y,x
    while y!=0:
        x,y=y,x%y
    return x

def search_list_common_divisor(*numbers):
    c=[numbers[0][i] for i in range(n)]
    b=[search_common_divisor(c[0],c[1])]
    for i in c:
        b.append(search_common_divisor(b[-1],i))
    return b[-1]

print(search_list_common_divisor(a))

Solution (Python):
N = int(input())
List = list(map(int, input().split()))

while len(List)!=1:
    m = min(List)
    List = [e%m for e in List]
    List = [e for e in List if e>0]
    List.append(m)
    
print(m)

Solution (Python):
import fractions

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

gcd = alist[0]
for i in range(1,N):
  gcd = fractions.gcd(gcd,alist[i])
  
print(gcd)

Solution (Python):
import fractions

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

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

Solution (Python):
n = int(input())
a = [int(x) for x in input().split()]

a = set(a)

from fractions import gcd
from functools import reduce
print(reduce(gcd,list(a)))

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

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
INF = 10**10
while True:
  num_alive = sum([1 if i>0 else 0 for i in A])
  
  
  if num_alive == 1:
    break
  else:
    min_A = INF
    for i in A:
      if i>0:
        min_A = min(i, min_A)
      else:
        pass
    min_A_idx = A.index(min_A)
    
    A = [ i % min_A if idx != min_A_idx else i for idx, i in enumerate(A)  ]
    
print(max(A))

Solution (Python):
import sys


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


if __name__ == '__main__':
    input = sys.stdin.readline
    n = int(input())
    a_list = list(map(int, input().split()))
    ans = a_list[0]
    for a in a_list[1:]:
        ans = gcd(ans, a)
    print(ans)

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()


def gcd(x,y):
  while y:
    x,y=y,x%y
  return x

def main():
  n=I()
  l=LI()

  a=l[0]
  for x in l[1:]:
    a=gcd(a,x)

  return a

print(main())

Solution (Python):
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]


def get_nums_l():
    return [ int(s) for s in input().split(" ")]


def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

def gcd(m, n):
    
    tmp = max(m,n)
    n = min(m,n)
    m = tmp
    
    if n == 0:
        return m
    
    return gcd(n, m % n)

n = int(input())
hps = get_nums_l()

print(reduce(gcd, hps))

Solution (Python):
from functools import reduce
n = int(input())
s = [int(i) for i in input().split()]
s.sort(reverse = True)

def saidaikouyakusuu(x, y):
    while x%y != 0:
        x, y = y, x%y
    return (y)

print(reduce(saidaikouyakusuu, s))

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

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

ans = A[0]

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

print(ans)

Solution (Python):
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=[i for i in a if not i==0]
  n=len(a)
print(a[0])

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

print(reduce(gcd,a))

Solution (Python):
import sys

n = int(input())
al = list(map(int, input().split()))
sys.setrecursionlimit(10 ** 5)


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


def gcdl(num, n):
    ans = num[0]
    for i in range(n):
        ans = gcd(ans, num[i])
    return ans


print(gcdl(al, n))

Solution (Python):
from fractions import gcd

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

ans = a[0]
for i in a:
    ans = gcd(i, ans)

print(ans)

Solution (Python):
import sys
n = int(input())
a = list(map(int, input().split()))
sys.setrecursionlimit(10 ** 5)


def cut(l):
    l.sort()
    nokori = [l[0]]
    for i in range(1, len(l)):
        b = l[i] % l[0]
        if b != 0:
            nokori.append(b)
    if len(nokori) != 1:
        return cut(nokori)
    return nokori[0]


print(cut(a))

Solution (Python):
def euc(x, y):
	if y == 0: return x
	return euc(y, x%y)

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

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

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

Solution (Python):
import numpy as np

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

A = np.array(sorted(A))
ans = A[0]
np.delete(A, 0)

while True:
    B = A % ans
    C = B[B != 0]
    if len(C) == 0:
        break
    ans = min(C)
    B = C

print(ans)

Solution (Python):


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


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

ans = data[0]

for i in range(n - 1):
    ans = gcd(ans, data[i + 1])

print(ans)

Solution (Python):
import fractions

N = int(input())

A = []

tmp = input().split(" ")

for t in tmp:
    A.append(int(t))
    

gcd = A[0]

for n in range(1,N):
    gcd = fractions.gcd(gcd,A[n])

print(gcd)

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

while len(A) > 1:
    A.sort()
    for n in range(len(A)-1):
        A[n+1] = A[n+1]%A[0]
    A = [a for a in A if a != 0]
    
print(A[0])

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

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

    while True:
        mina = min(A)
        mini = A.index(mina)
        A = A[:mini] + A[mini+1:]
        A = [a % mina for a in A if a % mina > 0]
        if not A:
            break
        A = A + [mina]
    print(mina)

if __name__ == '__main__':
    main()

Solution (Python):
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")


N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

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

Solution (Python):
N = input()
A = {int(x) for x in input().split()}

while len(A) != 1:
    mn = min(A)
    A = {x % mn for x in A if x % mn != 0}
    A.add(mn)
print(A.pop())

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

Solution (Python):
N = input()
A = {int(x) for x in input().split()}

while True:
    if len(A) == 1:
        break
    tmp = list(A)
    mn = min(tmp)
    for idx in range(len(tmp)):
        if tmp[idx] != mn:
            tmp[idx] = tmp[idx] % mn if tmp[idx] % mn != 0 else mn
    A = set(tmp)

print(A.pop())

Solution (Python):
def resolve():
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(gcds(*As))

from fractions import gcd
from functools import reduce
def gcds(*numbers):
    return reduce(gcd, numbers)

if '__main__' == __name__:
    resolve()

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

Solution (Python):
from fractions 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)

Solution (Python):
import fractions
from functools import reduce

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

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

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

i=1
while i<=N-1:
    ans.append(gcd(A[i],ans[-1]))
    i+=1

print(ans[-1])

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

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


memo = dict()

def euclidean_algorithm(a, b):
  while True:
    if a > b:
      a, b = b, a
    div, mod = divmod(b, a)
    if mod == 0:
      break
    b = mod
  return a

N = len(A)
ans = A[0]
for i in A[1:]:
  ans = euclidean_algorithm(ans, i)

print(ans)

Solution (Python):
n = int(input())
A = [int(_) for _ in input().split()]

def gcd(x,y):
    if x < y:
        return gcd(y,x)
    else:
        if x % y == 0:
            return y
        else:
            return gcd(y,x%y)
ans = A[0]
for i in range(1,n):
    ans = gcd(ans,A[i])
print(ans)

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

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
        
def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a

print(gcdlist(A))

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

while len(A) > 1:
    m = min(A)
    B = [m]
    for a in A:
        mod = a % m
        if mod > 0:
            B.append(mod)
    A = B
print(A[0])

Solution (Python):
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)

Solution (Python):
import fractions as fr

N = int(input())

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

ans = A[0]

for i in range(1,N) :
    ans = fr.gcd(ans,A[i])
    if ans == 1 :
        break

print(ans)

Solution (Python):
from functools import reduce
from fractions import gcd

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

print(reduce(gcd,A))

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


N = int(input())

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

hoge = [A[0]]

for i in range(1, len(A)):
    hoge.append(gcd(hoge[-1], A[i]))

print(hoge[-1])

Solution (Python):


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

Solution (Python):

from fractions import gcd

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

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

Solution (Python):
import functools, fractions

n = input()
a = list(map(int, input().split()))
print(functools.reduce(fractions.gcd, a))

Solution (Python):
import numpy as np

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

N = int(input())
A = np.array([int(x) for x in input().split()],dtype=object)
gcd = np.frompyfunc(gcd,2,1)

print(gcd.reduce(A))

Solution (Python):
import fractions

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

Solution (Python):


import math

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

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

res = a[-1]
for i in a[:-1]:
  res = gcd(res, i)

print(res)

Solution (Python):
import fractions

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

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

Solution (Python):
def f(a, b):
    if a < b:
        d = a
        a = b
        b = d
    if a % b == 0:
        return b
    else:
        return f(b, a % b)

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

main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
cnt=0
while(1):
     a.sort()
     if a[1]==10**9+1:
          print(a[0])
          break
     m0=a[0]
     for i in range(n-1-cnt):
          m1=a[i+1]
          m1-=m0*(m1//m0)
          if m1==0:
               cnt+=1
               a[i+1]=10**9+1
          else:
               a[i+1]=m1

Solution (Python):
from sys import stdin
import fractions
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 = fractions.gcd(ans, A[k])
print(ans)

Solution (Python):
import sys

input = sys.stdin.readline

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

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y == 0:
        return y
    else:
        while y != 0:
            x, y = y, x%y
        else:
            return x

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

Solution (Python):
import sys

input = sys.stdin.readline

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

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

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

Solution (Python):
import functools
import fractions

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

Solution (Python):
n = int(input())
mons = sorted(list(map(int, input().split())))

while(len(mons) > 1):
    mons = sorted([mons[0]] + list(map(lambda x:x%mons[0], mons[1:])))
    while mons[0]==0: del mons[0]
print(mons[0])

Solution (Python):
from fractions import gcd

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

g = 0

for i in range(n):
    g = gcd(g,x[i])

print(g)

Solution (Python):
from fractions import gcd

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

g=0

for i in range(n):
    g=gcd(g,x[i])

print(g)

Solution (Python):
import fractions
N = int(input())
A = list(map(int,input().split()))  

A.sort()

mins = A[-1]
for i in range(N):
    s = fractions.gcd(A[i], A[0])
    if s > 0 and s < mins:
        mins = s
print(min(mins,A[0]))

Solution (Python):
def gcd(x, y):
    if x < y:
        x = x ^ y
        y = x ^ y
        x = x ^ y
    div = x % y
    while div != 0:
        x = y
        y = div
        div = x % y
    return y

N=int(input())
As = list(map(int,input().split()))
As.sort()

res = As[0]
for i in range(1, N):
    res = gcd(res, As[i])

print(res)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
def gcd(a, b):
    if a > b:
        while a % b != 0:
            a, b = b, a % b
        return b
    else:
        while b % a != 0:
            b, a = a, b % a
        return a
x = gcd(A[0], A[1])
for i in range(2, N):
    x = gcd(x, A[i])
print(x)

Solution (Python):
from functools import reduce

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

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

print(reduce(gcd, A))

Solution (Python):
N = int(input())

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

def gcd(a, b):
    if a < b: return gcd(b, a)
    elif b > 0: return gcd(b, a % b)
    else:
        return a

a = A[0]

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

print(a)

Solution (Python):
from fractions import gcd

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

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

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
while len(a)>1:
    c=[]
    d=min(a)
    for i in range(len(a)):
        if a[i]!=d:
            div=a[i]%d
            if div!=0:
                c.append(div)
    c.append(d)        
    a=c
print(a[0])

Solution (Python):
N = int(input())
S = [int(x) for x in input().split()]

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

g = 0
for x in S:
  g = gcd(g, x)

print(g)

Solution (Python):
from functools import reduce

N=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
print(reduce(gcd,A))