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):
import functools, fractions
n=input()
a=list(map(int,input().split()))
print(functools.reduce(fractions.gcd,a))

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

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

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

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

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 sys
from fractions import gcd
def input(): return sys.stdin.readline().rstrip()

def main():
    _ = int(input())
    A = tuple(map(int, input().split()))

    ans = A[0]
    for a in A[1:]:
        ans = gcd(ans, a)
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
import sys
from functools import lru_cache
def input(): return sys.stdin.readline().rstrip()

@lru_cache(maxsize=None)
def gcd(m, n):
    if n == 0:
        return m
    else:
        return gcd(n, m % n)

def main():
    _ = int(input())
    A = tuple(map(int, input().split()))

    ans = A[0]
    for a in A[1:]:
        ans = gcd(ans, a)
    print(ans)
    
if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()

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

def main():
    _ = int(input())
    A = tuple(map(int, input().split()))

    ans = A[0]
    for a in A[1:]:
        ans = gcd(ans, a)
    print(ans)
    
if __name__ == '__main__':
    main()

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

print(functools.reduce(fractions.gcd, Q))

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

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

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

print(gcd_2(a))

Solution (Python):
def solve(n, A):

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

    l = A.pop()
    for a in A:
        l = gcd(l, a)
    return l

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))

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

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

n, *a = map(int, open(0).read().split())
g = 0
for i in a: g = gcd(g, i)
print(g)

Solution (Python):
n, *a = map(int, open(0).read().split())
a.sort()
ans = 1e10
for i in range(1, n):
    x, y = a[0], a[i]
    while y%x:
        y -= y//x*x
        x, y = y, x
    ans = min(ans, x)
print(ans)

Solution (Python):
def gcdf(a):
    a.sort()
    a0=a[0]
    a=[int(x%a0) for x in a if x%a0 != 0]
    if len(a)==0:
        return a0
    else:
        a.append(a0)
        a0=min(a)
        return gcdf(a) 

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

gcdx=gcdf(a)
print(gcdx)

Solution (Python):
import sys
sys.setrecursionlimit(10**7)

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

N = int(input())

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

x = X[0]

for i in range(1, N):
    x = gcd(x, X[i])
print(x)

Solution (Python):
def GCD(x, y):
    if y != 0:
        return GCD(y, x % y)
    else:
        return x

N = input()
monsters = [int(s) for s in input().split()]

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

print(gcd)

Solution (Python):



def get_input():
    n = int(input())
    a = [int(i) for i in input().split()]
    return n, a

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

if __name__ == "__main__":
    n, a = get_input()
    
    GCD = a[0]
    for idx in range(1, n):
        GCD = gcd(GCD, a[idx])
        if GCD <= 1: break
        
    print(GCD)

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

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

gcd_a = A[0]

for i in A:
    gcd_a = gcd(gcd_a,i)

print(gcd_a)

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

while len(a) > 1:
    res=[]
    a.sort()
    a_mn = a[0]
    res.append(a_mn)
    for i in range(1,len(a)):
        hp = a[i] % a_mn
        if hp!=0:
            res.append(hp)
    a=res
print(a[0])

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

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

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

Solution (Python):
import fractions

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

t = []
t.append(li[0])

for index, i in enumerate(li):
  if index == 0:
    continue

  k = fractions.gcd(t[index-1], li[index])
  t.append(k)

print(t[-1])

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):
def euclid(a, b):
  if b == 0:
    gcdr = a
  else:
    gcdr = euclid(b, a%b)
  return gcdr

N = int(input())
A ,*B= map(int,input().split())
for i in B:
    A = euclid(A,i)
print(A)

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


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


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

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

minA=min(A)
while len(A)!=1:
    B=[]
    for i in range(len(A)):
        if A[i]%minA!=0:
            B.append(A[i]%minA)
    B.append(minA)
    A=B
    minA=min(A)
print(minA)

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

Solution (Python):
import fractions
import functools

_gcd = fractions.gcd
def gcd(n):
    return functools.reduce(_gcd, n)

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

print(gcd(a))

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

while (len(a) > 1):
   a.sort()
   a = [a[i] if i==0 else a[i]%a[0] for i in range(len(a))]
   a = [x for x in a if x != 0]

print(a[0])

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


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

Solution (Python):
import fractions

n = int(input())
a = [int(_) for _ in input().split()]

a = sorted(a)
aa = [i % a[0] for i in a][1:]
aaa = []

for i in aa:
    if i != 0:
        aaa.append(fractions.gcd(i, a[0]))

if len(aaa) == 0:
    print(a[0])
else:
    print(min(aaa))

Solution (Python):
import sys
from fractions import gcd as gcd_base
from functools import reduce

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    _ = INT()
    A = LIST()

    gcd = lambda *numbers: reduce(gcd_base, numbers)
    print(gcd(*A))


if __name__ == '__main__':
    main()

Solution (Python):
import fractions
import functools


def gcd_list(numbers):
    return functools.reduce(fractions.gcd, numbers)


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

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

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


n = int(input())
a = list(map(int, input().split()))
ans = 0
for x in a:
    ans = gcd(ans, x)
print(ans)

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

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

def lcm(x,y):
	return (x * y) // gcd(x,y)

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

Solution (Python):
import sys
def gcd(c,d):
    a = max(c,d)
    b = min(c,d)
    if b == 0:
        return a
    return gcd(b,a%b)
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = a[0]
for i in a[1:]:
    ans = gcd(ans,i)
print(ans)

Solution (Python):
import sys
input = sys.stdin.buffer.readline

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

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

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

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

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

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

Solution (Python):
from fractions import gcd

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

Solution (Python):

import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    N = cin.int()
    A = cin.mapInt()
    ans = A[0]
    for i in range(1,N):
        ans = Math.gcd(ans,A[i])
    print(ans)
    return

if __name__ == "__main__":
    main()

Solution (Python):


import fractions
from functools import reduce
def pin(type=int):
    return map(type,input().split())


N, =pin()
m = list(pin())




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

print(gcd_list(m))

Solution (Python):

from fractions import gcd
from functools import reduce

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

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

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

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

while l.count(0) != n-1:
    m = max(l)
    for i in l:
       if (i < m) and i != 0:
           m = i
         
    index = l.index(m)
    
    for i in range(n):
        if i == index:
            pass
        
        else:
            l[i] = l[i] % m

print(max(l))

Solution (Python):
from fractions import gcd

N = int(input())
A = sorted([int(n) for n in input().split()], reverse=True)

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

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

Solution (Python):
from fractions import gcd


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

ans = next(A)

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

print(ans)

Solution (Python):

from fractions import gcd
from functools import reduce


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


def main():
    N = int(input())
    monsters = list(map(int, input().split(" ")))
    print(get_gcd(monsters))


if __name__ == '__main__':
    main()

Solution (Python):

import math
import heapq
import bisect
import numpy as np
import fractions


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

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

for i in range(n - 1):
    a[i + 1] = gcb(a[i], a[i + 1])
    
print(a[n - 1])

Solution (Python):
from fractions import gcd

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

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

print(a)

Solution (Python):
from fractions import gcd
def list_gcd(list):
    c=list[0]
    for i in list:
        c=gcd(c,i)
    return c
n=int(input())
print(list_gcd(list(map(int,input().split()))))

Solution (Python):
import sys
 
stdin = sys.stdin
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()
nas = lambda: stdin.readline().split()

n = ni()
a = na()

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

res = 0
for i in a:
    res = gcd(i, res)

print(res)

Solution (Python):
import fractions

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

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

g = []
for index, a in enumerate(A):
  if index == len(A) - 1:
    break
  g.append(fractions.gcd(a, A[index+1]))
  
  
print(min(g))

Solution (Python):
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
def lcm(a,b):
    g=gcd(a,b)
    return a/g*b

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

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

Solution (Python):
def gcd(A, B):
    while B != 0:
        A, B = B, A%B
    return A

N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse = True)
ans = A[0]
if N == 1:
    print(ans)
    exit()
for i in range(1,N):
    A[i] = gcd(A[i-1], A[i])

print(A[N-1])

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

Solution (Python):
import functools

def gcd(num1, num2):
    r = num1 % num2
    while (r > 0):
        num1 = num2
        num2 = r
        r = num1 % num2
    return num2

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

max_koyaku_num = functools.reduce(gcd, a)

print(max_koyaku_num)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
minhp = -1
while 1:
  minhp = min(a)
  minhpi = a.index(minhp)
  for i in range(len(a)):
    if i == minhpi:
      continue
    a[i] = a[i] % minhp
  a = list(filter(lambda x:x!=0, a))
  if min(a) == minhp:
    break
print(minhp)

Solution (Python):
import fractions 

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

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

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

Solution (Python):
import sys
from functools import reduce

def gcd(a, b):
    while b:
        a, b = b, a % b
    return abs(a)
    
n, *a = map(int, sys.stdin.read().split())

def main():
    return reduce(gcd, a)

if __name__ == '__main__':
    ans = main()
    print(ans)

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


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

Solution (Python):
from functools import reduce


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


def lcm(x, y):
    return (x * y) // gcd(x, y)


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


def lcm_list(numbers):
    return reduce(lcm, numbers)


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

print(gcd_list(a))

Solution (Python):
from functools import reduce


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


def lcm(x, y):
    return (x * y) // gcd(x, y)


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


def lcm_list(numbers):
    return reduce(lcm, numbers)


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

print(gcd_list(a))

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

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

ans = a[0]
for i in range(n-1):
    ans = gcd(ans,a[i+1])
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):
def examA():
    A, B = LI()
    if B%A==0:
        ans = A+B
    else:
        ans = B-A
    print(ans)
    return

def examB():
    N, M = LI()
    Flag = [0]*M
    for i in range(N):
        K = LI()
        for j in range(1,K[0]+1):
            Flag[K[j]-1] +=1
    ans = 0
    for i in Flag:
        if i==N:
            ans +=1
    print(ans)
    return

def gcd(x,y):
    if y==0:
        return x
    while(y!=0):
        x, y = y,x%y
    return x
def examC():
    N = I()
    A = LI()
    cur = A[0]
    for i in range(N-1):
        cur = gcd(cur,A[i+1])
    ans = cur
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

Solution (Python):
import fractions

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

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

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

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


n = int(input().strip())
a = list(map(int, input().split()))
ans = a[0]
for i in range(1, n, 1):
    ans = gcd(ans, a[i])
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()))
num=A[0]
for i in range(1,N):
    num=gcd(num,A[i])
print(num)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
while len(A)>=2:
    A=sorted(A,reverse=True)
    while 1:
        if not A[-1]:
            A.pop()
        else:
            for i in range(len(A)-1):
                A[i]%=A[-1]
            break
print(A[0])

Solution (Python):
from fractions import gcd
from functools import reduce
n = int(input())
a = [int(i) for i in input().split()]
print(reduce(gcd, a))

Solution (Python):
"""
import math
n=int(input())
a=list(map(int,input().split()))
m1=min(a)

def a_gcd(t,y):
    return math.gcd(t,y)

if m1==1:
    print(m1)
    exit()
for i in range(n):
    m1=a_gcd(m1,a[i])
    if m1==1:
        break

print(m1)
"""
import fractions
n=int(input())
a=list(map(int,input().split()))
m1=min(a)

def a_gcd(t,y):
    return  fractions.gcd(t,y)

if m1==1:
    print(m1)
    exit()
for i in range(n):
    m1=a_gcd(m1,a[i])
    if m1==1:
        break

print(m1)

Solution (Python):
import sys
import math
import itertools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]

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


n = ni()
a = na()

ans = a[0]

for ai in a[1:]:
    ans = gcd(ans, ai)
print(ans)

Solution (Python):

import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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


def solve(l):
    m = min(l)
    nl = list()
    for i in l:
        if i % m != 0:
            nl.append(i % m)
    nl.append(m)
    
    if len(nl) == 1:
        return m
    return solve(nl)


print(solve(a))

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

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

A.sort()

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

print(ans)

Solution (Python):
import sys
from fractions import gcd
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

Solution (Python):
import sys
input = sys.stdin.readline
import fractions


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    ans = A[0]
    for a in A:
        ans = fractions.gcd(ans, a)
    print(ans)

    
    

if __name__ == '__main__':
    main()

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

import functools
import fractions
gcd=functools.reduce(fractions.gcd,A)
print(gcd)

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

N=int(input())

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

m=0
for a in A:
    m=gcd(a,m)
print(m)

Solution (Python):
import numpy as np
N=int(input())

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

while np.any(A[:-1]>0):
    try:
        m=sorted(list(A[A>0]))[0]
        A=list(A[1:]%m)
        A.append(m)
        A=np.array(A)

    except:
        continue
print(m)

Solution (Python):
import fractions, functools
input()
print(functools.reduce(fractions.gcd, (int(i) for i in input().split())))

Solution (Python):
import fractions, functools
input()
print(functools.reduce(fractions.gcd, (int(i) for i in input().split())))

Solution (Python):
import functools

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


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


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

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

Solution (Python):
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 n in a:
    g = gcd(g, n)

print(g)

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

while True:
    min_num = min(a)
    min_ind = a.index(min_num) 
    a = [n % min_num for n in (a[:min_ind] + a[min_ind+1:]) if n % min_num != 0]
    if a == []:
        print(min_num)
        exit()
    a.append(min_num)

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

min_ind = a.index(min(a))

while True:
    min_num = min(a)
    min_ind = a.index(min_num) 
    a = [n % min_num for n in (a[:min_ind] + a[min_ind+1:]) if n % min_num != 0]
    if a == []:
        print(min_num)
        exit()
    a.append(min_num)

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


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


monster_count = int(input())
monsters = [int(i) for i in input().rstrip().split(" ")]

ans = monsters[0]
for i in range(1, monster_count):
    ans = get_kouyaku(ans, monsters[i])

print(ans)

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

while True:
    m=min(A)
    A=[i%m for i in A]
    A.append(m)
    A=[i for i in A if i!= 0]
    if len(A)==1:
        break

print(max(A))

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

while True:
    MOD = min(A)
    for i in range(N):
        A[i] = A[i]%MOD if A[i]%MOD != 0 else A[i]
    if MOD == min(A):
        break
print(MOD)

Solution (Python):
import fractions
from functools import reduce

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

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

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

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

a = A[0]
for i in range(1, N):
  b = A[i]
  while b != 0:
    a, b = b, a%b
    
print(a)

Solution (Python):
from fractions import gcd

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

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

print(ans)

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

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

print(x)

Solution (Python):
def main():
	
	n = int(input())
	
	h = list(map(int,input().split()))
	
	
	
	from fractions import gcd

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


if __name__ == '__main__':
	main()

Solution (Python):
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

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

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7


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

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

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):
from fractions import gcd
n = int(input())
A = list(map(int, input().split()))
ans = A.pop()
for a in A:
	ans = gcd(ans, a)
print(ans)

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

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

print(reduce(gcd,A))

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

for i in range(1,n):
    while a[i]%a[0] != 0:
        a[0],a[i] = a[i]%a[0],a[0]
else:
    ans = a[0]

print(ans)

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

a.sort()
for i in range(1,n):
    while a[i]%a[0] != 0:
        a[0],a[i] = a[i]%a[0],a[0]
else:
    ans = a[0]

print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
a = A[0]
for i in range(N - 1):
  b = A[i+1]
  while b != 0:
    a, b = b, a % b
print(a)

Solution (Python):
from fractions import gcd


def solve():
    N, *A = map(int, open(0).read().split())
    
    ans = A[0]
    for i in range(1, N):
        ans = gcd(ans, A[i])
    print(ans)


if __name__ == '__main__':
    solve()

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):
N = int(input().strip())
A = [int(str) for str in input().strip().split()]

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

A = sorted(A)[::-1]

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

print(ans)

Solution (Python):

import sys

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

def solve(N: int, A: "List[int]"):
    print(gcd_list(A))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  
    A = [int(next(tokens)) for _ in range(N)]  
    solve(N, A)

if __name__ == '__main__':
    main()

Solution (Python):

from functools import reduce
from fractions import gcd

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

print(reduce(gcd, A))

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
amin=min(a)
while len(a)>1:
    s=min(a)
    a = list(map(lambda x:x%s, a))
    a = [i for i in a if i > 0]+[s]
print(a[0])

Solution (Python):
from fractions import gcd as a
n=int(input())
f=1
for i in map(int,input().split()):
  if f:
    g=i
    f=0
  else:
    g=a(g,i)
print(g)

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

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

while True:
  num = sorted(num)
  for j in range(N):
    min = num[j]
    if min != 0:
      break
  for i in range(j+1,N):
    num[i] -= (num[i]//min)*min

  if num[N-1] == sum(num):
    break

print(sum(num))

Solution (Python):
n, *a = map(int, open(0).read().split())

def gcd(p, q):
    if p % q == 0:
        return q
    else:
        return gcd(q, p % q)
cd = a[0]
for i in range(n - 1):
    cd = gcd(cd, a[i + 1])
print(cd)

Solution (Python):
def main():
    N, *A = map(int, open(0).read().split())
    b = None
    for a in A:
        if b is None:
            b = a
            continue
        while b:
            a, b = b, a % b
        b = a
    print(a)
    return


main()