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










mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    import fractions
    n = int(input())
    A = readInts()
    g = fractions.gcd(A[0],A[1])
    for i in range(2,n):
        g = fractions.gcd(g,A[i])
    print(g)


if __name__ == '__main__':
  main()

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
from functools import reduce

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

print(reduce(fractions.gcd,A))

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


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):
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 = list(map(int,input().split()))

from fractions import gcd
from functools import reduce

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

print(gcd_list(A))

Solution (Python):
def main():
    from functools import reduce

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

    N = int(input())
    *a, = map(int, input().split())

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


if __name__ == '__main__':
    main()

Solution (Python):
import fractions
from functools import reduce

def gcd_list(numbers):
    return 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()))
ans = a[0]
for i in range(1, n):
    ans = gcd(ans, a[i])
print(ans)

Solution (Python):
n,*a=map(int,open(0).read().split())
from fractions import gcd
from functools import reduce
print(reduce(gcd,a))

Solution (Python):
import math
def main():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    ans = a[0]
    tmp = 0
    while True:
        for i in range(1,n):

            a[i] %= ans
            if a[i] != 0:
                tmp = min(ans,a[i])
        if sum(a) == ans:
            print(ans)
            return
        a.sort()
        ans = tmp
        a[0] = tmp

if __name__=='__main__':
    main()

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

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 main():
    N = int(input())
    A = [int(i) for i in input().split()]
    minA = min(A)
    while any(a % minA for a in A):
        for i in range(N):
            if A[i] % minA:
                A[i] %= minA
        minA = min(A)
    print(minA)


if __name__ == '__main__':
    main()

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

common = fractions.gcd(A[0], A[1])

if N >= 2:
	for i in range (2, N):
		common = fractions.gcd(common, A[i])

print(common)

Solution (Python):
def resolve():
    import heapq
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a)
    while True:
        mini = a[0]
        others = a[1:]
        others = [x % mini for x in others]
        if sum (others) == 0:
            print(a[0])
            exit()
        a = [mini] + others
        a =[i for i in a if i!= 0]
        a = sorted(a)
resolve()

Solution (Python):
def main():
    input()
    a_list = list(set((map(int, input().split(' ')))))
    a_list.sort()
    small_a = a_list[0]
    for a in a_list:
        surplus = a % small_a
        if surplus != 0:
            while small_a - surplus >= 1:
                small_a = small_a - surplus
                if small_a < surplus:
                    small_a, surplus = surplus, small_a
            if small_a == 1:
                break
    print(small_a)


if __name__ == '__main__':
    main()

Solution (Python):
from fractions import gcd
N=int(input())
A=list(map(int, input().split()))
if len(set(A))==1:
  print(A[0])
  exit()
  

alleven=True


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

print(now)

Solution (Python):
from fractions import gcd

n=int(input())
a=list(map(int,input().split()))
ans=10**18
t=0
for i in range(1,n):
  if i==1:
    t=gcd(a[0],a[1])
    ans=min(ans,t)
    continue
  t=gcd(t,a[i])
  ans=min(t,ans)
print(ans)

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):
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

n = INT()
a = LIST()
g = a[0]
for i in range(1, n):
    g = gcd(g, a[i])
print(g)

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

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

next = []
while(1):

    A.sort()
    m = A[0]
    next = []
    for x in A:
        if x % m:
            next.append(x % m)
    next.append(m)
    if next[0] == next[-1]:
        break
    A = list(next)
print(next[0])

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):
import fractions
from functools import reduce

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

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

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

print(gcd_list(x))

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

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

from functools import reduce
print(reduce(gcd,A))

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
res = a[0]
for i in range(n-1):
    res = fractions.gcd(res,a[i+1])
print(res)

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

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

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


def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    print(reduce(gcd, a))


if __name__ == '__main__':
    main()

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

import fractions
tmp = a[0]
for num in a:
    tmp = fractions.gcd(tmp, num)           
print(tmp)

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

def euclid(num1,num2):
  if num1<num2: num1,num2 = num2,num1
  if num2 != 0: return euclid(num2,num1%num2)
  else: return num1
  
def euclid_list(l):
  ans = euclid(l[0],l[1])
  for i in range(2,n):
    ans = euclid(ans,l[i])
  return ans

ret = euclid_list(monster)
print(ret)

Solution (Python):
import fractions

N = int(input())

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

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

print(ret)

Solution (Python):
import fractions

N = int(input())
A = list(sorted(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 fractions import gcd
from functools import reduce


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


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

g = gcd_list(A)
print(g)

Solution (Python):
N=int(input())
A=list(map(int,input().split()))
f=True
X=[A]
c=0
while f:
  B=sorted(X[c])
  while 0 in B:
    B.remove(0)
  mod=B[0]
  for i in range(1,len(B)):
    B[i]%=mod
  X.append(B)
  c+=1
  if X[c]==X[c-1]:
    f=False
print(min(X[c]))

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

Solution (Python):
def main():
    N = int(input())
    A = sorted([int(v) for v in input().split()])

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

    v = A[0]
    for i in range(1, N):
        v = lcm(v, A[i])

    print(v)


main()

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

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

Solution (Python):
from functools import reduce

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

def gcd(num):
    return reduce(gcd_base,num)

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

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

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

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

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

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

print(g)

Solution (Python):
"""
keywords: 最大公約数、ユークリッドの互除法
"""
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from functools import reduce

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

def main():
    n = II()
    a_lst = MII()
    print(reduce(gcd, a_lst))

if __name__ == '__main__':
    main()

Solution (Python):
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    n = II()
    a_lst = sorted(MII(), reverse=True)
    while True:
        minv = a_lst[-1]
        a_lst = [a%minv for a in a_lst[:-1] if a%minv != 0]
        a_lst.append(minv)
        a_lst.sort(reverse=True)
        if len(a_lst) == 1: break
    print(a_lst[0])

if __name__ == '__main__':
    main()

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

    while len(lst) > 1:
        mi = lst[0]
        attacked = [lst[i]%mi for i in range(1, len(lst)) if lst[i]%mi != 0]
        lst = [mi] + attacked
        lst.sort()
    print(lst[0])
main()

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

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

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

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

Solution (Python):
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
from functools import reduce

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

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

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

N = i_i()
A = i_l()

print(gcd_list(A))

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

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):
n = int(input())
s = list(map(int,input().split()))
un = 0
un_1 = 0


while un < n-1:
  s.sort()
  sign = 0
  for i in range(un_1,n):
    if s[i] == 0:
      un = i+1
      continue

    if i == un:
      continue
    
    temp = s[i] - (s[i]//s[un])*s[un]
    
    if 0 <= temp:
      s[i] = temp
    elif temp < 0:
      s[i] = 0
    
  un_1 = un
    
print(s[un])

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

import fractions

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

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

Solution (Python):
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

_NUMINT_ALL = list(range(10))


def main():
    ans = solve()
    if ans is not None:
        print(ans)


def solve():
    N = iip(False)
    A = iip()
    l = len(A)

    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m










def iip(listed=True, num_only=True):  
    if num_only:
        ret = [int(i) for i in input().split()]
    else:
        ret = [int(i) if i in _NUMINT_ALL else i for i in input().split()]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret


def saidai_kouyakusuu(a, b):  
    for i in soinsuu_bunkai(a):
        if b % i == 0:
            b //= i
    return a * b


def sort_tuples(l, index):  
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  
    if index >= len(l):                      
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def iipt(l, listed=False, num_only=True):  
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed, num_only=num_only))
    return ret


def sortstr(s):  
    return "".join(sorted(s))


def iip_ord(startcode="a"):  
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  
    for i in s:
        print(i)


def bitall(N):  
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        
        pass
    return ret


def inv(n, mod):  
    return power(n, mod - 2)


def power(n, p, mod_=mod):  
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

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

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

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

def euclid(a, b):
  while True:
    r = a % b
    a, b = b, r
    if r == 0:
  	  return(a)
    
List.sort(reverse = True)
res = euclid(List[0], List[1])
for i in range(1, n):
  res = euclid(res, List[i])
  if res == 1:
    break
    
print(res)

Solution (Python):
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
n = int(input())
l = list(map(int, input().split()))
print(gcd_list(l))

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)

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

Solution (Python):
def main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    
    from itertools import combinations, permutations, accumulate, groupby
    
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    

    
    

    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    while a[-2] > 0:
        x = 0
        for i in range(n):
            if x==0:
                x = a[i]
            else:
                a[i] %= x
        a.sort()
    print(a[-1])

if __name__ == '__main__':
    main()

Solution (Python):
import fractions

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

now=A[0]
for a in A:
    now=fractions.gcd(now,a)
    if now==1:
        break
print(now)

Solution (Python):
import sys
import math
from fractions import gcd
readline = sys.stdin.readline
INF = 10**9


def main():
  n = int(readline())
  A = list(map(int, readline().split()))
  ans = gcd(A[0], A[1])
  for i in A:
    ans = gcd(ans, i)
  print(ans)
  
  
  
  
if __name__ == "__main__":
  main()

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


import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def gcd(n,m):
    if m == 0:
        return n
    else:
        return gcd(m,n%m)
n = I()
a = LI()
g = a[0]
for i in a[1:]:
    g = gcd(g,i)
print(g)

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

Solution (Python):
def main():
    from functools import reduce
    from fractions import gcd
    
    n, *a = map(int, open(0).read().split())
    g = reduce(gcd, a)
    print(g)

if __name__ == '__main__':
    main()

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


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

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

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

print(ans)

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

Solution (Python):
from heapq import heapify, heappop, heappush
N = int(input())
Alist = list(map(int, input().split()))
heapify(Alist)
while len(Alist) > 1:
    atk = heappop(Alist)
    Alist = [A % atk for A in Alist if (A % atk != 0)]
    heapify(Alist)
    heappush(Alist, atk)
print(Alist[0])

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

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

print(reduce(gcd,A))

Solution (Python):
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 

def ii(): return int(sys.stdin.readline().rstrip()) 
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) 
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]

def ss(): return sys.stdin.readline().rstrip() 
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) 
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]





from fractions import gcd
from functools import reduce


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

n=ii()
arr=limii()
print(gcd_list(arr))

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

n = int(input())
a = 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= list(map(int,input().split()))

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

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

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):
from functools import reduce

n, *a_l = map(int, open(0).read().split())

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

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

print(gcd_list(a_l))

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

n, *a_l = map(int, open(0).read().split())

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

print(gcd_list(a_l))

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

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):
N=int(input())
A=list(map(int, input().split()))

def attack(lst):
    attacker=min(lst)
    position=lst.index(attacker)
    temp=[]
    for i in range(len(lst)):
        if i!=position:
            if lst[i] % attacker!=0:
                temp.append(lst[i]%attacker)
        else:
            temp.append(lst[i])
    return temp

while len(A)>1:
    A=attack(A)
    
print(A[0])

Solution (Python):
n = int(input())
a = sorted(list(map(int,input().split())))
cnt = [a[1],a[0]]
for i in range(1,n):
  a[i] %= cnt[-1]
  if (a[i] != 0) and (a[i] < cnt[-1]):
    cnt.append(a[i])
    cnt.pop(0)
if a[1] == 0:
  print(a[0])
else:
  while cnt[1] != 0:
    cnt.append(cnt[0]%cnt[1])
    cnt.pop(0)
  else:
    print(cnt[0])

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a = sorted(list(set(a)))
while len(a) > 1:
  b = a.pop(0)
  d = []
  for i in a:
    c = i%b
    if c != 0:
      d.append(c)
  a = sorted(list(set(d+[b])))
print(a[0])

Solution (Python):

from fractions import gcd
N = int(input())
A = list(map(int, input().split()))

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

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

while len(A) > 1:
  A.sort()
  
  for i in range(1,len(A)):
    
    A[i] = A[i] % A[0]
  A = list(filter(lambda x: x != 0,A))

print(A[0])

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(n):
    ans=gcd(ans,a[i])
print(ans)

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

N = int(input())
A = list(map(int, input().split()))
ans = functools.reduce(lambda x,y:fractions.gcd(x,y), A)
print(ans)

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


if __name__ == "__main__":
    N, *A = map(int, open(0).read().split())
    g = 0
    for i in range(N):
        g = GCD(g, A[i])
    print(g)

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

def gcd_step(a, b):
    return b, a % b

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

    return a

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

print(g)

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

def gcd(a,b):
    '''
    3 個以上の値の最大公約数を求めるためには、
    res = 0 と初期化
    各 i に対して res = GCD(res, x[i]) と更新する
    '''
    while b!=0:
        a,b = b,a%b
    return a

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

print(ans)

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

def gcd(a,b):
    '''
    3 個以上の値の最大公約数を求めるためには、
    res = 0 と初期化
    各 i に対して res = GCD(res, x[i]) と更新する
    '''
    while b!=0:
        a,b = b,a%b
    return a

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

print(ans)

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

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

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

Solution (Python):
from sys import stdin
from fractions import gcd

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

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

print(GCD)

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):
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

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

main()

Solution (Python):
N=int(input())
A=sorted(list(map(int,input().split(' '))))
l_tmp=A[1:]
tmp = A[0]
ans = A[0]
while True:
    l_tmp_tmp=[]
    for i in l_tmp:
        if i%tmp:
            l_tmp_tmp.append(i%tmp)
            ans = min(ans,i%tmp)
    l_tmp_tmp.append(tmp)
    if len(l_tmp_tmp)>1:
        tmp = ans
        l_tmp=l_tmp_tmp
    else:
        break
print(ans)

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

while len(A) > 1:
    m = min(A)
    m_i = A.index(m)
    for i in range(len(A)):
        if i != m_i:
            A[i] = A[i] % m

    A = [a for a in A if a != 0]

print(A[0])

Solution (Python):
import fractions
from functools import reduce

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

print(reduce(fractions.gcd, A))

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

while len(A) > 1:
    a = min(A)
    A = set(x % a if x % a != 0 else a for x in A)
print(list(A)[0])

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

while len(A) > 1:
    a = min(A)
    A = set(x % a if x % a != 0 else a for x in A)
    if 1 in A:
        A = {1}
print(list(A)[0])

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


def find(A):
    if len(A) == 1:
        return A.pop()

    if min(A) <= 1000:
        while 1 < len(A):
            m = min(A)
            s = {m}
            for x in A:
                v = x % m
                if 0 < v:
                    s.add(v)
            A = s
        return A.pop()

    for _ in range(10):
        m = min(A)
        s = {m}
        for x in A:
            v = x % m
            if 0 < v:
                s.add(v)
        A = s
    return find(A)


print(find(A))

Solution (Python):





from fractions import gcd

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

print(ans)

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()))
ans = 1001001001
for i in range(n-1):
    ans = min(ans,gcd(a[i],a[i+1]))

print(ans)