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 = [int(i) for i in input().split()]


    
ans = a[0]

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

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

def gcd(a, b):
    if b != 0:
        return gcd(b, a%b)
    else:
        return a
ans = 10**10
for i in range(N-1):
    ans = min(ans, gcd(a[i], a[i+1]))
print(ans)

Solution (Python):
def gcd(a, b):
  if b == 0:
    return a
  else:
    return gcd(b, a%b)
N=int(input())
L=list(map(int,input().split()))
s=L[0]
for i in range(N-1):
  s=gcd(L[i+1],s)
print(s)

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


    
ans = a[0]

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

Solution (Python):
N=int(input())
M=list(map(int, input().split()))
ans=min(M)
mn=min(M)
from math import gcd
for m in M:
  if m%mn!=0:
    ans=min(ans, gcd(mn,m))
print(ans)

Solution (Python):


def func(A):
    
    
    
    A = sorted(A)
    m = min(A)
    B = [A[0]]
    
    for i in range(1,len(A)):
        if A[i]%m != 0:
            B.append(A[i]%m)
    
    if len(B) == 1:
        print(m)
        return len(B)
    else:
        func(B)
    
n = int(input())
A = list(map(int, input().split()))
func(A)

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

Solution (Python):
n = int(input())
min_ = 0
list_ = set(list(map(int, input().split())))

while True:
  tmp = min(list_)
  list_ = set([i%tmp for i in list_])
  if 0 in list_:
    list_.remove(0)
  list_.add(tmp)
  if tmp==min(list_):
    break
print(tmp)

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 sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0

N = i()
A = l()
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 = a[0]
for i in range(1,n):
    ans = math.gcd(a[i],ans)
print(ans)

Solution (Python):
N = int(input())
A = list(sorted(list(set(map(int, input().split())))))
while True:
    n = len(A)
    if n == 1 or A[0] == 1:
        break
    B = {A[0]}
    for j in range(1, n):
        m = A[j] % A[0]
        if m != 0:
            B.add(m)
    A = list(sorted(list(B)))
print(A[0])

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

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    A = sorted(in_nl())

    while True:
        B = []
        B.append(A[0])
        for i in range(1, len(A)):
            x = A[i] % A[0]
            if x:
                B.append(x)

        if len(B) == 1:
            break
        else:
            B.sort()
            A = copy.copy(B)

    print(B[0])


if __name__ == '__main__':
    main()

Solution (Python):
from math import gcd

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

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

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
x = min(a)
while True:
    for i in range(n):
        if a[i] % x == 0:
            a[i] = x
        else:
            a[i] = a[i] % x
    if x == min(a):
        print(x)
        break
    else:
        x = min(a)

Solution (Python):
import fractions

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

print(gcdans)

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

i = 0
while i < n-1:
    x = a[i+1] % a[i]
    a[i+1] = a[i]
    a[i] = x
    if a[i] == 0:
        i += 1
print(a[i])

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

i = 0
while i < n-1:
    x = a[i+1] % a[i]
    a[i+1] = a[i]
    a[i] = x
    if a[i] == 0:
        i += 1
print(a[i])

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

i = 0
while True:
    x = a[i+1] % a[i]
    if x < a[i]:
        a[i+1] = a[i]
        a[i] = x
        if a[i] == 0:
            i += 1
            if i == n-1:
                break
    else:
        break
print(a[i])

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

ans=A[0]
count=[0]*N
i=0
while i<N:
    count[i]=A[i]%ans
    i+=1

for c in count:
    if c>0:
        ans=min(ans,c)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

for a in A:
    if a%ans>0:
        ans=min(ans,a%ans)

print(ans)

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

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

while True:
    A_org = A[0:]
    min_A = max(A)
    min_index = A.index(min_A)
    for i in range(N):
        if A[i] < min_A and A[i] >= 1:
            min_A = A[i]
            min_index = i
    for i in range(N):
        if i == min_index:
            pass
        else:
            A[i] %= min_A
    if A == A_org:
        break

print(max(A))

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

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

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

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

n, *a = map(int, read().split())

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

print(res)

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):
def main():
    N = int(input())
    A = [int(a) for a in input().split()]
    mon1 = [a for a in A]
    mon2 = [a for a in A]

    for i in range(10**9):
        mon1 = sorted(mon2)
        mon2 = list()

        for j in range(1, len(mon1)):
            m_ = mon1[j] % mon1[0]
            if m_ != 0:
                mon2.append(m_)

        mon2.append(mon1[0])

        if len(mon2) == 1:
            break

    print(mon2[0])
    
if __name__ == "__main__":
    main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[]
while len(a)>1:
  c=min(a)
  b.append(c)
  for m in a:
    d= m % c
    if d>0:
      b.append(d)
  a=b[:]
  b.clear()
print(a[0])

Solution (Python):
from fractions import gcd

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

rlt = As[0]

for a in As[1:]:
  rlt = gcd(a,rlt)
  
print(rlt)

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

while(len(np.nonzero(A)[0]) != 1):
    devisor = np.min(A[np.nonzero(A)])
    devisor_i = np.where(A==devisor)[0][0]
    A = np.array([A[devisor_i], *(A%devisor)[:devisor_i], *(A%devisor)[devisor_i+1:]])
    
print(*A[np.nonzero(A)])

Solution (Python):
from copy import deepcopy
import math
import string
import collections
from collections import Counter
from collections import deque
from decimal import Decimal
import sys
import fractions
from operator import itemgetter
import itertools
import copy


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


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


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



dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
n = int(input())
a = readints()

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

Solution (Python):
from fractions import gcd

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

def ii():
    return int(input())

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

if __name__ == '__main__':
    main()

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

for e in A:
    ans = gcd(e,ans)
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):
from math import gcd
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for e in A:
    ans = gcd(e,ans)
print(ans)

Solution (Python):



from fractions import gcd
from itertools import combinations,permutations 

from collections import deque,defaultdict











import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7

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

Solution (Python):


import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

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

n=I()
lis=LI()
p=lis[0]
for i in range(n-1):
    p=gcd(p,lis[i+1])
print(p)

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

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

for Ai in A:
    G = gcd(G, Ai)

print(G)

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

import math
from functools import reduce

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

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

print(gcd(*a))

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

while len(A) > 1:
    A = sorted([i%A[0] for i in A if i%A[0]!=0] + [A[0]])
print(A[0])

Solution (Python):
import math
def computeGCD(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x 
n=int(input())
a=list(map(int,input().split()))
ans=computeGCD(a[0],a[1])
for i in range(2,n):
  ans=computeGCD(ans,a[i])
print(ans)

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()))
x = A[0]
for i in range(1,N):
    x = gcd(x,A[i])
print(x)

Solution (Python):
from math import gcd

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

g = A[0]

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

print(g)

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


import math
from functools import reduce

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

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

print(gcd_list(A))

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
from math import gcd
for i in range(N-1):
    a = A[i]
    b = A[i+1]
    a, b = 0, gcd(a,b)
    A[i] = a
    A[i+1] = b
print(A[N-1])

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

gcd=fractions.gcd(a[0],a[1])

for i in range(2,n):
    gcd=fractions.gcd(a[i],gcd)

print(gcd)

Solution (Python):
from fractions import gcd


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


if __name__ == "__main__":
    main()

Solution (Python):


import fractions 

N = int(input())

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

gcd = fractions.gcd(a[0],a[1])

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

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=gcd(A[0], A[1])

for i in range(2, 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):
from fractions import gcd
from functools import reduce
n = int(input())
a = list(map(int, input().split()))
def gcd_list(numbers):
    return reduce(gcd, numbers)
print(gcd_list(a))

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

def int1(x): return int(x) - 1
def II(): return int(input())
def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())
def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def MS(): return input().split()
def LS(): return list(input())
def LLS(rows_number): return [LS() for _ in range(rows_number)]
def printlist(lst, k=' '): print(k.join(list(map(str, lst))))
INF = float('inf')






from fractions import gcd

def solve():
    N = II()
    A = LI()

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

if __name__ == '__main__':
    solve()

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

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())
A = list(map(int,input().split()))
ans = gcd_list(A)
print(ans)

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

def gcd(x,y):
    if y==0: return x
    return gcd(y,x%y)
ans = A[0]
for a in A:
    ans = gcd(ans,a)
print(ans)

Solution (Python):
N = int(input())
A = set(map(int,input().split()))
def helper(A):
    v = min(A)
    ans = set()
    for a in A:
        if a%v!=0:
            ans.add(a%v)
    ans.add(v)
    return ans

while len(A)>1:
    A = helper(A)
print(min(A))

Solution (Python):
import fractions

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

last = a[0]

for i in range(1, n):
    last = fractions.gcd(last, a[i])

print(last)

Solution (Python):

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

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

def gcd(l):
    ans = l[0]
    for i in l:  ans = gcd_(ans, i)
    return ans

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

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

l = a[:]
while len(l) > 1:
    midx = l.index(min(l))
    r = []
    for i in range(len(l)):
        if i != midx:
            l[i] = l[i] % l[midx]
        if l[i] != 0:
            r.append(l[i])
    l = r[:]
print(l[0])

Solution (Python):
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
A.sort()
T = [A[0]]
for i in range(1,len(A)):
  if A[i]//A[0] != 0:
    T.append(A[i])
  else:
    pass

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

Solution (Python):


import fractions



from collections import deque




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 gcd(x,y):
    if y==0:
        return x
    return gcd(y,x%y)

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

Solution (Python):
from fractions import gcd

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

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

print(ans)

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

Solution (Python):


import fractions

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

for i in range(n-1):
    monsters[i + 1] = fractions.gcd(monsters[i], monsters[i + 1])

print(monsters[-1])

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

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

while len(a) > 2:
    for i in range(2,n):
        a[i] %= a[1]
        
    a = sorted(set(a))
    n = len(a)
    
print(a[1])

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

while len(a)!=1:
    if a[0]==0:
        a=a[1:]
    for i in range(1,len(a)):
        a[i]%=a[0]
    a=sorted(set(a))

print(a[0])

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

A.sort()
stack = A[1:]
m = A[0]

while stack:
  stack = list(stack)
  l = []
  for x in stack:
    if x % m == 0:
      continue
    l.append(x % m)
  
  if not l:
    break
  l.append(m)
  m = min(l)
  stack = set(l)

print(m)

Solution (Python):
from fractions import gcd

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

tmp = gcd(lis[0], lis[1])

for i in range(1, n-1):
    tmp = gcd(tmp,lis[i+1])
    
print(tmp)

Solution (Python):
def gcd(_a, _b):
	if _a%_b==0:return _b
	else:return gcd(_b, _a%_b)

n=int(input())
a=sorted(map(int,input().split()))
INF=2*10**9
ans=INF
for i in range(len(a)-1):
	tmp=gcd(a[i],a[i+1])
	if tmp!=0 and tmp<ans:
		ans=tmp
print(ans)

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

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

def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a
print(gcdlist(ls))

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

Solution (Python):
from fractions import gcd


def main():
    n = int(input())
    a = list(map(int, input().split()))
    ans = a[0]
    for aa in a:
        ans = gcd(ans, aa)
        
    print(ans)
    
    
if __name__ == '__main__':
    main()

Solution (Python):
def main():
    n = int(input())
    a = list(map(int, input().split()))
    m = min(a)
    next_m = m
    count = 0
    while count != n:
        m = next_m
        count = 0
        pre = a[0]
        for i in range(n):
            if a[i] == pre:
                count += 1
            a[i] %= m
            if a[i] != 0:
                next_m = min(next_m, a[i])
            else:
                a[i] = m
            pre = a[i]
    print(m)
    
if __name__ == '__main__':
    main()

Solution (Python):
def solve(a, b):
    mod = 1
    while mod != 0:
        mod = b%a
        b = a
        a = mod
    return b

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

minA = min(A)
B = [a%minA for a in A]
print(solve(minA, max(B)))

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

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

minA = min(A)
B = [a%minA for a in A]
print(solve(minA, max(B)))

Solution (Python):
from fractions import gcd

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

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

print(g)

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

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

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

Solution (Python):
import fractions
from functools import reduce
 
def gcd(*numbers):
    return reduce(fractions.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()))


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

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

print(gcd_calc)

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

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

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

print(ans)

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

ans = a[0]
for x in a:
  ans = fractions.gcd(ans, x)
print(ans)

Solution (Python):
from fractions import gcd

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

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

Solution (Python):
import fractions

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

ans = A[0]

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

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

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

p=gcd_list(a)

print(p)

Solution (Python):
import fractions

N = int(input())
A = list(input().split())
monster = list(sorted([int(A[i]) for i in range(N)]))
ans = float('inf')
MIN = monster[0]

for i in range(N):
    tmp = monster[i]
    ans = min(ans, int(fractions.gcd(tmp, MIN)))

print(ans)

Solution (Python):
import sys
input = sys.stdin.readline
def gdc(p, q):
    if q == 0:
        return p
    return gdc(q, p%q)

def main():
    N = int(input())
    A = list(map(int, input().split()))
    if N == 1:
        print(A[0])
        return
    res = A[0]
    for i in range(1,N):
        res = gdc(res, A[i])
    print(res)

if __name__ == '__main__':
    main()

Solution (Python):
import sys
from functools import lru_cache, cmp_to_key
from heapq import merge, heapify, heappop, heappush
from math import *

from collections import defaultdict as dd, deque, Counter as C
from itertools import combinations as comb, permutations as perm
from bisect import bisect_left as bl, bisect_right as br, bisect
from time import perf_counter
from fractions import Fraction



mod = int(pow(10, 9) + 7)
mod2 = 998244353
def data(): return sys.stdin.readline().strip()
def out(*var, end="\n"): sys.stdout.write(' '.join(map(str, var))+end)
def l(): return list(sp())
def sl(): return list(ssp())
def sp(): return map(int, data().split())
def ssp(): return map(str, data().split())
def l1d(n, val=0): return [val for i in range(n)]
def l2d(n, m, val=0): return [l1d(n, val) for j in range(m)]






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

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

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

Solution (Python):


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


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

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

    while True:
        A.sort()
        mod_max = 0
        for i in range(len(A)-1, 0, -1):
            tmp = A[i] % A[0]
            if tmp == 0:
                A.pop(i)
            else:
                A[i] = tmp
            if mod_max < tmp:
                mod_max = tmp
        if mod_max == 0:
            print(A[0])
            exit()
        elif mod_max == 1:
            print(1)
            exit()


if __name__ == "__main__":
    main()

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

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


input()
print(reduce(gcd, map(int, input().split())))

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


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

Solution (Python):
from fractions import gcd


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

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

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

def gcd(v1, v2):
    if v2 == 0:
        return v1
    return gcd(v2, v1%v2)

tmp = A_list[0]
for a in A_list:
    tmp = gcd(tmp, a)

print(tmp)

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

def gcd(v1, v2):
    if v2 == 0:
        return v1
    return gcd(v2, v1%v2)

tmp = A_list[0]
for a in A_list:
    tmp = gcd(tmp, a)

print(tmp)

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

def gcd(v1, v2):
    if v2 == 0:
        return v1
    return gcd(v2, v1%v2)

tmp = A_list[0]
for a in A_list:
    tmp = gcd(tmp, a)

print(tmp)

Solution (Python):
from fractions import gcd

n = int(input())
aa = tuple(map(int, input().split()))

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

Solution (Python):















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

g =a[0]

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

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

g =a[0]

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

Solution (Python):
import fractions
from functools import reduce

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

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

print(gcd_list(nums))

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

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

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):
import itertools
import fractions
n=int(input())
a=list(map(int,input().split()))
a.sort()
mina=a[0]
ans = 10**18
for i in range(n):
	ans = min(ans, fractions.gcd(a[i], mina))
print(ans)

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

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

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

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

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

print(gcd_list(a))

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

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

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

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

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

from fractions import gcd

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

print(ans)

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