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

from functools import reduce
import sys
try:
    from typing import List
except ImportError:
    pass


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


def solve(N: int, A: "List[int]"):
    print(reduce(gcd, A))


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


if __name__ == '__main__':
    main()

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

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

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

def gcd(a,b):
  aa=max(a,b)
  bb=min(a,b)
  cc=aa%bb
  return gcd(bb,cc) if cc else bb
  
p=gcd(a[0],a[1])
for i in range(2,n):
  p=gcd(p,a[i])
print(p)

Solution (Python):


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

N = int(input())




res = 0
x = list(map(int,input().split()))

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

print(res)

Solution (Python):
from fractions import gcd

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

lisA.sort()
ans = 10**9 + 1

for num in lisA[1:]:
    tmp = gcd(lisA[0],num)
    ans = min(ans,tmp)
    if ans == 1:
        print(ans)
        exit()

print(ans)

Solution (Python):
from fractions import gcd

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

res=A[0]

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

print(res)

Solution (Python):
def resolve():
    '''
    code here
    '''

    N = int(input())
    A_list = [int(item) for item in input().split()]

    is_flag = True
    temp_list = A_list[:]
    prev_list = A_list[:]
    while is_flag:
        temp_min = min(temp_list)
        for i in range(N):
            if temp_list[i] % temp_min >= 1:
                temp_list[i] = temp_list[i] % temp_min

        if prev_list == temp_list:
            is_flag = False

        prev_list = temp_list[:]

    print(temp_min)

if __name__ == "__main__":
    resolve()

Solution (Python):

import sys
input = sys.stdin.readline




def gcd(a,b):
    return a if b == 0 else gcd(b,a%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):
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
flag = True
b = gcd(a[0], a[1])
for i in range(2, n):
    b = gcd(a[i], b)
print(b)

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

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

ans = gcd(a[0], a[1])
for i in range(2, 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()))

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

print(gcd_list(A))

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 collections import deque

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

while True:
	a = list(a)
	a.sort()
	a = deque(a)
	while True:
		A = a.popleft()
		if A != 0:
			a.appendleft(A)
			break
	for i in range(1,len(a)):
		a[i] %= a[0]
	if sum(a) - a[0] == 0:
		print(a[0])
		break

Solution (Python):
n = int(input())
a = sorted(set(map(int, input().split())))
while len(a) != 1:
    for i in range(1, len(a)):
        a[i] %= a[0]
    a = sorted(set(a))
    if 0 in a:
        a = a[1:]
print(a[0])

Solution (Python):
from fractions import gcd

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

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

Solution (Python):
import fractions
N = int(input())
A = [int(x) for x in 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_base(a, b):
    while b!=0:
        a, b = b, a%b
    return a

def gcd(num_list):
    ans = 0
    for i in num_list:
        ans = gcd_base(ans, i)
    return ans

print(gcd(a))

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



import math
import sys
sys.setrecursionlimit(2000000)



n = int(input())

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



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


print(gcd_list(a))

Solution (Python):
import fractions

a=int(input())
li = list(map(int,input().split()))
cnt = li[0]
for i in li:
    cnt = fractions.gcd(cnt, i)
print(cnt)

Solution (Python):
import sys
import os
import math
import bisect
import collections
import itertools
from fractions import gcd

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()
    A = il()
    sm = sum(A)
    print(min([gcd(sm, a) for a in A]))


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

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

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

print(gcd_A)

Solution (Python):
import fractions
from functools import reduce

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

print(reduce(fractions.gcd,a))

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

"""
Created on Mon May  4 20:56:08 2020
"""

import sys
import numpy as np

sys.setrecursionlimit(10 ** 9)


mod = 10**9+7

N = int(input())

A = list(map(int,input().split()))
A1 = np.array(A)

m = np.min(A)
pre = m
while len(A1) > 1:
    pre = m
    A1 %= m
    A1 = A1[A1 != 0]
    A1 = np.append(A1, m)
    m = np.min(A1)
print(pre)

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

while len(a) != 1:
  m=min(a)
  t = [m]
  for i in a:
    if i % m == 0: continue
    t.append(i % m)
  if not t: break
  a = t
  
print(m)

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


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

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


if __name__ == "__main__":
    main()

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


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

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

Solution (Python):
n=int(input())
A=list(map(int,input().split()))
def gcd(x,y):
    while y:
        x,y=y,x%y
    return x 
ans=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()))
g = gcd(A[0], A[1])
for a in A[2:]:
    g = gcd(g, a)

print(g)

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

while True:
    if len(A) == 1:
        break
    while A[0] == 0:
        A.popleft()
    mod = A[0]
    for i in range(1, len(A)):
        A[i] = A[i]%mod
    A = deque(sorted(A))

print(A[0])

Solution (Python):
import fractions
N=int(input())
L=list(map(int,input().split()))
ans=float("inf")
for i in range(1,N):
	if i==1:
		ans=fractions.gcd(L[0],L[1])
	else:
		ans=fractions.gcd(ans,L[i])
print(ans)

Solution (Python):



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


count = 0
is_finished = True


while is_finished:
    min_hp = float('INF')
    min_index = 0
    for i in range(N):
        if a_nums[i]==0:
            continue
        if min_hp>a_nums[i]:
            min_hp = a_nums[i]
            min_index = i
    for i in range(N):
        if i==min_index:
            continue
        a_nums[i] = a_nums[i] - min_hp*(a_nums[i]//min_hp)
        if a_nums[i]<0:
            a_nums[i] = 0
    if len(set(a_nums))==2 and 0 in set(a_nums):
        is_finished = False


ans = max(a_nums)
print(ans)

Solution (Python):
n = int(input())
al = list(map(int, input().split()))
t = al[0]


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


for i in range(1, n):
    t = gcd(t, al[i])  


print(t)

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

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



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



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


ans = al[0]

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

print(ans)

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



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






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

Solution (Python):
from fractions import gcd

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

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

print (g)

Solution (Python):
from fractions import gcd

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

g = a[0]

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

print(g)

Solution (Python):

from fractions import gcd
from functools import reduce
print(reduce(gcd, map(int, open(0).read().split()[1:])))

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

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

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

print(G)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
N = [a[0]]
for i in range(1, n):
    if a[i] % a[0] != 0:
        N.append(a[i]%a[0])
N.sort()
while sum(N) > N[0]:
    N1 = N.copy()
    N = [N1[0]]
    for s in N1:
        if s == N[0]: continue
        if s%N[0] != 0: N.append(s%N[0])
    N.sort()
print(N[0])

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

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

print(G)

Solution (Python):
from fractions import gcd
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
flag = False
for i in range(1,n):
    if gcd(a[i],a[0])==1:
        flag = True
mn = 10**9
if not flag:
    for i in range(1,n):
        mn = min(mn,gcd(a[0],a[i]))
print(1 if flag else mn)

Solution (Python):


import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))

def resolve():
    N,=pin()
    A=tupin()
    
    from fractions import gcd

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

resolve()

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

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

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

Solution (Python):
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

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

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

Solution (Python):
N=int(input())
*A,=map(int, input().split())
def gcd(a,b):
    while b: a,b=b,a%b
    return a
ans=0
for a in A: ans=gcd(ans,a)
print(ans)

Solution (Python):
def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    while b:
        a, b = b, a % b
    return a


def lcm(a: int, b: int) -> int:
    """a, bの最小公倍数(least common multiple: LCM)を求める
    計算量: O(log(min(a, b)))
    """
    return (a * b) // gcd(a, b)


def multi_gcd(array: list) -> int:
    """arrayのGCDを求める"""
    n = len(array)
    ans = array[0]
    for i in range(1, n):
        ans = gcd(ans, array[i])
    return ans


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

print(multi_gcd(a))

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

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

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


if __name__ == '__main__':
    main()

Solution (Python):
def gcd(a,b):
  while b:a,b=b,a%b
  return a
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in a[1:]:ans=gcd(ans,i)
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):
n = int(input())
import sys
input = sys.stdin.readline
l = list(map(int,input().split()))
x = min(l)
flag = True
while flag:
  flag = False
  for i in l:
    p = i%x
    if  p != 0 and p < x:
      x = p
      flag = True
print(x)

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

while len(A) > 1:
    not_zero = False
    my_min = heapq.heappop(A)
    A = np.array(A)
    A %= my_min
    A = list(A[A > 0])
    heapq.heapify(A)
    heapq.heappush(A, my_min)
print(A[0])

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

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

print(reduce(gcd, A))

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

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

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

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

Solution (Python):

import sys


def solve(N: int, A: "List[int]"):
    from fractions import gcd
    from functools import reduce
    return reduce(gcd, A)



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

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    
    main()

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


print(gcd_list(a))

Solution (Python):
import functools
import fractions

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

gcd = functools.reduce(fractions.gcd, a)
print(gcd)

Solution (Python):
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
n=int(input())
lis=list(map(int,input().split()))
i=0
while len(lis)-1>i:
  lis+=[gcd(lis[i],lis[i+1])]
  i+=2
print(lis[-1])

Solution (Python):
import fractions as f

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

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

res = A[N - 1]
print(res)

Solution (Python):
from collections import deque

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

while len(l) > 1:
  key = min(l)
  for i in range(len(l)):
    j = l.popleft()
    sup = j % key
    if sup > 0:
      l.append(sup)
  l.append(key)

print(l[0] if len(l) == 1 else 0)

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

Solution (Python):
import fractions

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

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


print(A[N-1])

Solution (Python):
import functools
import math
import fractions

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

Solution (Python):
from fractions import gcd


def solve():

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


if __name__ == "__main__":
    solve()

Solution (Python):
def gcd(a, b):
    
    big = max(a, b)
    small = min(a, b)
    
    r = small
    while r != 0:
        r = big % small
        big = small
        small = r
    
    return big

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

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

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

if len(list(set(li))) == 1:
    print(li[0])
else:
    if len(li) == 1:
        print(li[0])
        exit()
    tmp_gcd = fractions.gcd(li[0],li[1])
    if len(li)>2:
        for i,l in enumerate(li):
            if i == 0 or i == 1:
                continue
            gc = fractions.gcd(tmp_gcd,l)
            tmp_gcd = gc
    print(tmp_gcd)

Solution (Python):





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


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


def good(A, N):
    
    ans = A[0]
    
    
    for i in range(1, N):
        ans = lcm(ans, A[i])
    return ans


def my(A, N):
    A = sorted(A)

    while True:
        v = A[0]
        tmp = [v]
        for i in range(len(A)):
            if A[i] % v == 1:
                print(1)
                return
            if A[i] % v == 0:
                pass
            else:
                tmp.append(A[i] % v)

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

        A = sorted(tmp)
        


def main():
    N = int(input())
    A = list(map(int, input().split()))
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


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


def S(): return input()


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


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


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


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False


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

def main():
    N = I()
    A = LI()
    n = A[0]

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

    print(n)


if __name__ == '__main__':
    main()

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

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

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

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

Solution (Python):
import numpy as np

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

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

print(gcd.reduce(A))

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

def gcd(a,b):
    while(a%b!=0):
        a,b=b,a%b
    return b
a=list(sorted(a))
c=gcd(a[0],a[1])
for i in range(2,n):
    c=gcd(a[i],c)
print(c)

Solution (Python):
import fractions


N = int(input())
ans = 0
for a in map(int, input().split()):
    ans = fractions.gcd(ans, a)
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):

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


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


ans = arr[0]

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

print(ans)

Solution (Python):
import fractions
N=int(input())
gcd,*alist=map(int,input().split())

for a in alist:
  gcd=fractions.gcd(gcd,a)
  
print(gcd)

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

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

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

def gcdli(xl):
    
    return reduce(gcd , xl)

def monsters_battle_royale(n, al):

    ans = gcdli(al)

    return ans

def main():
    n = int(input())
    al = list(map(int, input().split()))
    print(monsters_battle_royale(n, al))

if __name__ == '__main__':
    main()

Solution (Python):
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
    n=int(input())
    A=np.array([int(_) for _ in input().split()])
    while A.size>1:
        min_A=np.min(A)
        A=np.fmod(A,min_A)
        A=A[A>0]
        A=np.append(A,min_A)
    print(A[0])
    

if __name__=='__main__':
    main()

Solution (Python):
n = int(input())
ais = list(map(int, input().split()))
for i in range(n-1):
  a = ais[i]
  b = ais[i+1]
  if a < b:
    a, b = b, a
  while a > 0 and b > 0:
    a = a % b
    a,b = b,a
  ais[i+1] = a
  ais[i] = b
print(max(ais))

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


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

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

print(gcd_list(A))

Solution (Python):


from functools import reduce
from fractions import gcd


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

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

print(gcd_list(A))

Solution (Python):

















mod = 10**9 + 7

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

Solution (Python):

import sys
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
g = A[0]
for a in A:
    g = gcd(g, a)
print(g)

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

min_A = min(A)
prev_answer = None
answer = min_A
while True:
    if answer == prev_answer: break

    next_answer = answer
    for Ai in A:
        remainder = Ai % answer
        if remainder == 0: continue

        next_answer = min(remainder, next_answer)

    prev_answer = answer
    answer = next_answer

print(answer)

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):
    while b:
        a, b = b, a % b
    return a
def gcdl(l):
    from functools import reduce
    return reduce(lambda x, y: gcd(x, y), l)
n=input()
print(gcdl(list(map(int,input().split()))))

Solution (Python):


import fractions

data=int(input())
array=list(map(int,input().split()))
array1=[]
for i in range(1,data):
    array1.append(fractions.gcd(array[0],array[i]))
print(min(array1))

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


n = int(input())

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

Solution (Python):
import sys
from io import StringIO
import unittest
from fractions import gcd

from functools import reduce

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

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

    gcd_num = gcd_list(a)

    print(gcd_num)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """4
2 10 8 40"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4
5 13 8 1000000000"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """3
1000000000 1000000000 1000000000"""
        output = """1000000000"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

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

ifContinue = True
while ifContinue:
    ifContinue = False
    counter = 0
    for i in range(N):
        if not A[i] == 0:
            counter += 1
            if counter == 2:
                ifContinue = True
                break
    min = 10**9+1
    index = -1
    for i in range(N):
        if A[i] < min and not A[i] == 0:
            min = A[i]
            index = i

    for i in range(N):
        if i == index or A[i] == 0:
            continue
        else:
            A[i] = A[i] % min

print(max(A))

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

import fractions
from functools import reduce

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

print (gcd_list(A))

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

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

import functools
def gcdn(nums):
    return functools.reduce(gcd, nums)

print(gcdn(a))

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

ans = 0

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

print(ans)

Solution (Python):
n = int(input())
 
A = list(map(int, input().split()))
 
t = max(A)
 
from fractions import gcd
 
for i in A:
    t = gcd(t, i)
print(t)

Solution (Python):
from fractions import gcd


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

A.sort()
ans = int(1e9)
for i in range(0, N - 1):
    if A[i] < A[i + 1]:
        ans = min(ans, gcd(A[i], A[i + 1]))
    else:
        ans = min(ans, A[i])

print(ans)

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

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

t = max(A)

from fractions import gcd

for i in A:
    t = gcd(t, i)
print(t)

Solution (Python):
def main():
    N = int(input())
    A = list(map(int, input().split()))
    while len(A) > 1:
        m = min(A)
        A = [a % m for a in A if a % m != 0]
        A.append((m))

    print(m)


if __name__ == "__main__":
    main()

Solution (Python):
from heapq import heapify, heappush, heappop

def main():
    N = int(input())
    A = list(map(int, input().split()))
    heapify(A)
    while len(A) > 1:
        m = heappop(A)
        A = [a % m for a in A if a % m != 0]
        A.append((m))

    print(m)


if __name__ == "__main__":
    main()

Solution (Python):
def gcd(a,b):
    return gcd(b, a % b) if b else abs(a)
N = int(input())
a = list(map(int,input().split()))
import math
ans = a[0]
for i in range(1,N):
    ans = gcd(ans,a[i])
print(ans)

Solution (Python):
import sys
from functools import reduce

def gcd(a, b): return gcd(b, a % b) if b else abs(a)
def lcm(a, b): return abs(a // gcd(a, b) * b)

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

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

if __name__ ==  '__main__':
    main()

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

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

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

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


l = monster[0]
for m in monster:
    l = gcd(l, m)
print(l)

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

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

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


l = monster[0]
for m in monster:
    l = gcd(l, m)
print(l)