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 math

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

Solution (Python):



from math import gcd
from functools import reduce



def solve(n,a):
  ans = reduce(gcd,a)
  return ans



def main():
  N = int(input())
  
  a = list(map(int,input().split()))
  print(solve(N,a))
  return

if __name__ == '__main__':
  main()

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

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N = ii()
    A = list(mi())

    A.sort()
    if A[0] == 1:
        print(1)
        exit()
    
    ini = A[0]
    while len(A) > 1:
        x = A[0]
        B = set([x])
        for a in A:
            b = a%x
            if b > 0:
                B.add(b)

        A = list(B)
        A.sort()

    if len(A) > 0:
        print(A[0])
    else:
        print(ini)
            

            
        



if __name__ == "__main__":
    main()

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

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

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

gcd = a[0]
for i in range(1, n):
    gcd = math.gcd(a[i], gcd)
    if gcd == 1:
        print(1)
        break
else:
    print(gcd)

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

def agcd(l):
    a=math.gcd(l[0],l[1])
    for i in range(2,len(l)):
        a=math.gcd(a,l[i])
    return a

print(agcd(A))

Solution (Python):
from math import gcd
def multi_gcd(A):
  g = A[0]
  for a in A:
    g = gcd(g,a)
  return g

def solve():
  N = int(input())
  A = list(map(int, input().split()))
  ans = multi_gcd(A)
  return ans
print(solve())

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

Solution (Python):
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial

from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

def I():
    return int(input())

def MI():
    return map(int,input().split())

def RI():
    return list(map(int,input().split()))

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

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

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

def LS(n):
    return [ list(input().split()) for _ in range(n) ]







n = I()
a = RI()

if 1 in a:
    print(1)
    exit()

while len(a)!=1:
    m = min(a)
    ind = a.index(m)
    for i in range(len(a)):
        if i==ind:
            pass
        else:
            a[i] = a[i] % m
    a = list(set(a))
    if 0 in a:
        a.remove(0)
    elif 1 in a:
        print(1)
        exit()
    

print(a[0])
exit()

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
from math import gcd

g = 0
for a in As:
    g = gcd(g, a)
print(g)

Solution (Python):
import math

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

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

print(g)

Solution (Python):
import math
from functools import reduce

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

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

print(gcd_list(a))

Solution (Python):
import sys
import math


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



g = A.pop(0)
for c in A:
    g = math.gcd(g,c)

print(g)

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

while not len(A) == 1:
    div = A[0]
    A = A[1:]
    A = list(map(lambda x:x%div, A))
    A.append(div)
    A = list(set([x for x in A if x != 0]))
    A.sort()

print(A[0])

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

from functools import reduce
from fractions import gcd

max=0
min=10**9+1
for i in range(N):
    if max < hp_list[i]:
        max = hp_list[i]
        max_index = i
    if min > hp_list[i]:
        min = hp_list[i]
        min_index = i
    tmp_list=[max,min]
    hp_list[max_index]=reduce(gcd,tmp_list)


hp_list = sorted(hp_list, reverse=False)
print(hp_list[0])

Solution (Python):
import math
from functools import reduce

def gcd(*numbers):
    return reduce(math.gcd, numbers)
N = int(input())
A = list(map(int,input().split()))
print(gcd(*A))

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

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

print(A[0])

Solution (Python):
import sys
from collections import defaultdict
import math

def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort(reverse=True)
    g = A[0]

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

    print(g)





if __name__ == "__main__":
    main()

Solution (Python):
import sys
from collections import defaultdict
import math

def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    g = A[0]

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

    print(g)





if __name__ == "__main__":
    main()

Solution (Python):
import sys
from collections import defaultdict
import math

def input():
    return sys.stdin.readline().rstrip()


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

    print(g)





if __name__ == "__main__":
    main()

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

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

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

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

Solution (Python):
n=int(input())
A=[]*n
A[:]=map(int,input().split())

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

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

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

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

print(ans)

Solution (Python):
import math


def main():
    n = int(input())
    As = sorted(list(map(int, input().split())))

    ans = math.gcd(As[0], As[1])
    for i in range(2, n):
        ans = math.gcd(ans, As[i])
    print(ans)


if __name__ == "__main__":
    main()

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

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

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

Solution (Python):




import math

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

ans = st_list[0]

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

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

Solution (Python):
import math

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

for i in range(1,n):
    if i == 1:
        ans = math.gcd(a[0],a[i])
    else:
        ans = math.gcd(ans,a[i])

print(ans)

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

MIN= min(A)
while 1:
  newA = []
  MIN0 = MIN
  for i in range(len(A)):
    a = A[i] % MIN
    if a == 0:
      newA.append(a)
    else:
      if a < MIN:
        MIN = a
      newA.append(a)
  if MIN==1:break
  if MIN0 == MIN:break

print(MIN)

Solution (Python):

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

f = A[0]
for i in range(1,N):
    a,b=f, A[i]
    f=math.gcd(a,b)

print(f)

Solution (Python):

from functools import reduce
from math import gcd

n, *a = map(int, open(0).read().split())
print(reduce(gcd, a))

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

Solution (Python):
import math
from functools import reduce

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

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

print(gcd(an))

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int,input().split()))
print(np.gcd.reduce(A))

Solution (Python):
def main():
    n = int(input())
    inlis = list(map(int, input().split()))
    inlis = set(inlis)
    inlis = list(inlis)
    inlis.sort()

    while len(inlis) > 1:
        tmp = 0
        i = 1
        while tmp < len(inlis):
            
            if inlis[i] % inlis[0] != 0:
                inlis[i] %= inlis[0]
                i += 1
                if i >= len(inlis):
                    break
            else:
                inlis.remove(inlis[i])
            tmp += 1
        inlis = set(inlis)
        inlis = list(inlis)
        inlis.sort()
        
    print(inlis[0])


if __name__ == "__main__":
    main()

Solution (Python):
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, 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()))

m = 0
tmp = min(a)
while m != tmp:
    m = tmp
    for i in range(n):
        if a[i] != m:
            a[i] = a[i] % m
        if a[i] < m and a[i] != 0:
            tmp = a[i]
print(m)

Solution (Python):
from math 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 math
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in range(n):
  ans=math.gcd(ans,a[i])
print(ans)

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

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

Solution (Python):
import sys
N = int(input())
A = list(map(int, input().split()))
a = min(A)
b = a
while True:
    for _a in A:
        _b = _a % a
        if _b > 0 and _b < a:
            b = _b
    if b == a:
        print(a)
        sys.exit()
    a = b

Solution (Python):
n = int(input())
A = tuple(map(int, input().split()))
ma = min(A)
while True:
    ra = set([a%ma for a in A if a%ma > 0])
    if len(ra) == 0:
        print(ma)
        break
    minra = min(ra)
    if ma == minra:
        print(ma)
        break
    ma = minra

Solution (Python):
import math
n = int(input())
A = tuple(map(int, input().split()))
g = A[0]
for a in A[1:]:
    g = math.gcd(g, a)
print(g)

Solution (Python):
from math import gcd

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

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

Solution (Python):
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
d = a.min()
while True:
    a1 = a % d
    if all(a1 == 0):
        ans = d
        break
    d = min(a1[a1 != 0])    
print(ans)

Solution (Python):
import numpy
N = int(input())
L = numpy.array(list(map(int, input().split())))

m = numpy.inf

while True:
    if numpy.min(L) == m:
        break

    m = numpy.min(L)
    mi = numpy.argmin(L)

    L = L % m
    L[mi] = m
    L = L[L != 0]

print(numpy.sum(L))

Solution (Python):
from math 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 math
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=a[n-1]
for i in range(n-1):
    b=math.gcd(a[i],b)
print(b)

Solution (Python):
from functools import reduce
import math


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


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


if __name__ == "__main__":
    main()

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

mn = min(A)
while True:
    ok = False
    for a in A:
        x = a % mn
        if x != 0 and x < mn:
            mn = x
            ok = True
    if not ok:
        break
print(mn)

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

a=sorted(a)

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
  
c=make_divisors(a[0])


d=sorted(c)
f=[]
for y in range(len(d)):
  e=d[y]
  ch=0
  for x in range(1,n):
    if not a[x]%e==0:
      continue
    ch+=1
  if ch==n-1:
    f.append(e)
    
print(max(f))

Solution (Python):
import math
from functools import reduce

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

print(reduce(math.gcd, a))

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

def main():
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(1, n):
        if i == 1:
            ans = math.gcd(a[i-1], a[i])
        else:
            ans = math.gcd(ans, a[i])
    print(ans)
        
if __name__ == '__main__':
    main()

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

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

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

Solution (Python):
import math
from functools import reduce
 
def gcd(numbers):
    return reduce(math.gcd, numbers)
 
n=int(input())
A=tuple(map(int,input().split()))
print(gcd(A))

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

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

Solution (Python):
import math
from functools import reduce

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

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

print(gcd(*a))

Solution (Python):
import math
n = int(input())
l = list(map(int, input().split()))
def multiGCD(l):
    ans = 0
    for i in l:
        ans = math.gcd(ans, i)
    return ans
print(multiGCD(l))

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

Solution (Python):
from math import gcd
N = int(input())
A = list(map(int, input().split()))
k = 0
for i in A:
  k = gcd(i,k)
print(k)

Solution (Python):
import math
from functools import reduce


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


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

print(gcd_list(A))

Solution (Python):
import sys
from fractions import gcd

sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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):
import sys
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

heapify(a)

while len(a) != 1:
    f = heappop(a)
    s = heappop(a)
    s %= f
    if s != 0:
        heappush(a, s)
    heappush(a, f)

print(heappop(a))

Solution (Python):

import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd





def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    mn = min(a)
    while True:
        b = set()
        for e in a:
            if e % mn:
                b.add(e%mn)
            else:
                b.add(mn)
        a = list(b)
        mn = min(a)
        if len(a) == 1:
            print(mn)
            return
    

t = 1

for case in range(1,t+1):
    ans = solve()


"""

2 3 4 4
3 4 4
2 3 4
2 3 4
2 4 4


"""

Solution (Python):
import math
from functools import reduce

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

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

Solution (Python):





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

    def gcd(n, m):
        """
        2020/05/22
        """
        while True:
            if m == 0:
                return n
            n, m = m, n % m

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

    return A[i+1]


print(main())

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

import math
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

ans_list = sorted(make_divisors(arr[0]),reverse=True)

for i in ans_list:
    flg =True
    for j in arr:
        if j%i != 0:
            flg =False
            break
    if flg:
        print(i)
        exit()

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

Solution (Python):
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
A_l = LI()
ans = A_l[0]
for i in range(1, N):
    ans = math.gcd(ans, A_l[i])
print(ans)

Solution (Python):
import math
def main():
    n = (int)(input())
    k = list(map(int,input().split()))
    ans = k[0]
    for i in k:
        ans = math.gcd(ans,i)
    print(ans)

main()

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

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

  print(ans)
  return

if __name__ == "__main__":
  resolve()

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

Solution (Python):

import math

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

x = A[0]
for a in A:
    x = math.gcd(x, a)

print(x)

Solution (Python):
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,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()
now = a[0]
for i in range(1,n):
    now = math.gcd(now, a[i])
print(now)

Solution (Python):

import sys
from math import gcd
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

Solution (Python):
from math import gcd
N = int(input())
A = list(map(int,input().split()))
g = 0
for a in A:
    g = gcd(a,g)
print(g)

Solution (Python):
import sys
from math import gcd
input = sys.stdin.readline
N = int(input())
res = 0
a = list(map(int, input().split()))
for x in a: res = gcd(res, x)
print(res)

Solution (Python):

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

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

def lcm(a, b):
    return a * b // gcd(a, b)
ans = a[0]
for i in range(1, n):
    ans = gcd(ans, a[i])
print(ans)

Solution (Python):
from math 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()))
ans = a[0]


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


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

Solution (Python):
import numpy as np
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    print(np.gcd.reduce(a))
main()

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

Solution (Python):
import math;input();a=list(map(int,input().split()));d=a[0]
for i in a:d=math.gcd(i,d)
print(d)

Solution (Python):
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n = readInt()
a = list(set(readInts()))

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

odd = []
even = []


from math import gcd


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

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

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

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

Solution (Python):
def INT():
    return int(input())

def MI():
    return map(int, input().split())

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

from math import gcd

N = INT()
A = LI()
A.sort()
ans = A[0]

all_can_div = True

for i in range(1, N):
    A[i] = gcd(A[i], ans)
    
    if A[i] != ans and all_can_div:
        all_can_div = False

print(ans if all_can_div else min(A))

Solution (Python):
def INT():
    return int(input())

def MI():
    return map(int, input().split())

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

from collections import deque
N = INT()
A = LI()
A.sort()

while True:
    mod = A[0]
    flg = True
    ans = A[0]
    tmp = deque([A[0]])
    
    if ans == 1:
        print(ans)
        break
    
    for i in range(1, len(A)):
        A[i] %= mod

        if A[i] != 0 and flg:
            flg = False
        
        if A[i] == 0:
            continue
        tmp.append(A[i])
        
    if flg:
        print(ans)
        break
    
    A = sorted(tmp)

Solution (Python):
import math
N = int(input())
A = sorted([int(X) for X in input().split()])
GCDA = A[0]
for T in range(1,N):
    GCDA = math.gcd(GCDA,A[T])
    if GCDA==1: break
print(GCDA)

Solution (Python):
import math

N=int(input())
S=list(map(int,input().split()))
F=S[0]
for i in range(N-1):
    F=math.gcd(F,S[i+1])

print(F)

Solution (Python):
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
N = int(input())
L = list(map(int,input().split()))

print(gcd_list(L))

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

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

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

g = gcd_list(A)
print(g)

Solution (Python):
import math
from functools import reduce
N = int(input())
A = list(map(int,input().split()))
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
print(gcd_list(A))

Solution (Python):
import math
from functools import reduce

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

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    ans = gcd(sorted(A,reverse=True))
    print(ans)

if __name__ == '__main__':
    main()

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

n=int(input())
arr=list(map(int,input().split()))
ans=1
if n>2:
	ans=gcd(arr[0],arr[1])
	for i in range(2,n):
		ans=gcd(ans,arr[i])
else:
	ans=gcd(arr[0],arr[1])
print(ans)

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

A.sort()
A = deque(A)
while len(A) > 1:
  s = []
  for i in range(len(A)-1):
    div = A[-1] % A[0]
    A.pop()
    if div != 0:
      s.append(div)
  s.append(A[0])
  s.sort()
  A = deque(s)
print(*A)

Solution (Python):
import math

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

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

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

import functools
print(functools.reduce(gcd, a))

Solution (Python):
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import heapq

ans = 0
heapq.heapify(a)
while a:
    t = heapq.heappop(a)
    if ans == 0:
        ans = t
        continue
    else:
        big = max(ans, t)
        small = min(ans, t)
        if big % small != 0:
            ans = big % small
            heapq.heappush(a, small)

print(ans)

Solution (Python):
import math

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

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

Solution (Python):
import math

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

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

Solution (Python):
import numpy as np

N= int(input())

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

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

r = 0
for i in A:
  r = gcd(i,r)
print(r)

Solution (Python):
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    A = LI()
    while True:
        ans = min(A)
        A = [x%ans for x in A if x%ans != 0]
        if not A:
            print(ans)
            break
        A.append(ans)


if __name__ == '__main__':
    main()

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

rem=-1
while True:
    a=sorted(a)
    if a[0]==rem:
        print(a[0])
        break
    rem=a[0]
    for i in range(1,n):
        a[i]%=rem
        if a[i]==0:
            a[i]+=rem

Solution (Python):

import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)
def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

N = z()
A = zz()

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






print(ans)

Solution (Python):
import sys
read = sys.stdin.read
from math import gcd
def main():
    n, *a = map(int, read().split())
    r = gcd(a[0], a[1])
    if n == 2:
        print(r)
        sys.exit()
    for i1 in range(2, n):
        r = gcd(r, a[i1])
    print(r)

if __name__ == '__main__':
    main()

Solution (Python):
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()

x = a[0]
for y in a:
        x = gcd(x, y)
print(x)

Solution (Python):

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

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
  
m=a_[0]
for i in range(n):
  m=gcd(m,a_[i])
  
print(m)

Solution (Python):

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

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


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

ans =gcd_list(A)
print(ans)

Solution (Python):
n = int(raw_input())
ais = map(int, raw_input().split())
def gcd(a,b):
	return gcd(b, a % b ) if b else a
print reduce(gcd, ais)

Solution (Python):
import math
n=int(input())
a=list(map(int,input().split()))
num=a[0]
def g(num1,num2):
    return math.gcd(num1,num2)
for i in range(n-1):
    num=g(num,a[i+1])
print(num)