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


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


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


def main():
    N, *A = map(int, open(0).read().split())
    print(gcd_n(A))
    return


main()

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

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

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def count_zero(arr):
    cnt = 0
    for a in arr:
        if a == 0:
            cnt += 1

    return cnt
def main():
    N = I()
    a = LI()
    min_element = inf
    min_ix = -1
    while True:
        prev_min = min_element
        for i in range(N):
            if 0 < a[i] < min_element:
                min_element = a[i]
                min_ix = i
        if count_zero(a) == N-1:
            break
        for i in range(N):
            if i == min_ix:
                continue
            a[i] %= min_element
    print(prev_min)
main()

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

Solution (Python):


import fractions as math
N = int(input())
monsters = list(map(int, input().split()))
for i in range(N):
    if i != 0:
        monsters[i] = math.gcd(monsters[i - 1], monsters[i])
print(monsters[N - 1])

Solution (Python):
def gcd(x, y):
    a = x
    b = y
    while True:
        r = a % b
        if r == 0:
            break
        a = b
        b = r
    return b


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

B = sorted(A)
b = B[0]

for i in range(1, N):
    b = gcd(b, B[i])

print(b)

Solution (Python):
n = int(input())
A = list(map(int,input().split()))
def gcd(a,b):
  if b == 0:
    return a
  return gcd(b,a % b)
cur = A[0]
for i in range(1,len(A)):
  cur = gcd(cur,A[i])
print(cur)

Solution (Python):
import fractions

def main():
    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)

if __name__ == '__main__':
    main()

Solution (Python):
N = int(input())
li = list(map(int,input().split()))
HPmin = 0
sum = 0
while sum != N-1 :
    li.sort()
    for i in range(sum + 1,N) :
        li[i] %= li[sum]
    HPmin = li[0]
    sum = 0
    for i in range(N) :
        if li[i] == 0 :
            sum+=1
li.sort()
print(li[N-1])

Solution (Python):
N = int(input())
li = list(map(int,input().split()))
HPmin = 0
sum = 0
while sum != N-1 :
    li.sort()
    for i in range(sum + 1,N) :
        li[i] %= li[sum]
    HPmin = li[0]
    sum = 0
    for i in range(N) :
        if li[i] == 0 :
            sum+=1
li.sort()
print(li[N-1])

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

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

print(A[0])

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

Solution (Python):
import math
n = int(input())
hp = [int(x) for x in input().split()]
for i in range(n-1):
  a = hp[i]
  b = hp[i+1]
  r = a % b
  if r == 0:
    ans = b
    continue
  while r != 0:
    ans = r
    a = b
    b = r
    r = a % b
  hp[i+1] = ans
print(ans)
a = b * i + r

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

Solution (Python):
import fractions
N=int(input())
ls=[int(s) for s in input().split()]
a=0
for e in ls:
  a=fractions.gcd(a,e)
print(a)

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

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

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
def gcdcheck(a, b):
    return fractions.gcd(a, b)

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

ans = monster_list[0]
for i in range(1, n):
    ans = gcdcheck(ans, monster_list[i])

print(ans)

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

Solution (Python):
N = int(input())
lista = sorted(list(map(int, input().split())))
length = 2
while length>1:
    
    
    for n in range(1, length):
        lista[n] = lista[n]%lista[0]
    
    lista = list(set(lista))
    lista.sort()
    if lista[0] == 0:
        lista.remove(0)
    
    length = len(lista)
print(lista[0])

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):
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b


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

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

Solution (Python):
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
A = [int(x) for x in input().rstrip().split()]
A = np.array(A, np.int64)
while len(A) > 1:
    A = A[np.nonzero(A)]
    A = np.sort(A)
    minA = A[0]
    A %= minA
    A[0] = minA
A = A[np.nonzero(A)]
print(A[0])

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A, np.int64)
while len(A) > 1:
    A = A[np.nonzero(A)]
    A = np.sort(A)
    minA = A[0]
    A %= minA
    A[0] = minA
A = A[np.nonzero(A)]
print(A[0])

Solution (Python):
import fractions

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

Solution (Python):
from fractions import gcd

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

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

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
gcd = a[0]
def Euclid(n1,n2):
    if n1 % n2 == 0:
        return n2
    return Euclid(n2,n1%n2)
for i in range(1,n):
    gcd = Euclid(gcd,a[i])
print(gcd)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
gcd = a[-1]
def Euclid(n1,n2):
    if n1 % n2 == 0:
        return n2
    return Euclid(n2,n1%n2)
for i in range(n-1):
    gcd = Euclid(gcd,a[(-1)*(i+2)])
print(gcd)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
a.sort()
gcd = a[-1]
def Euclid(n1,n2):
    if n1 % n2 == 0:
        return n2
    return Euclid(n2,n1%n2)
for i in range(n-1):
    gcd = Euclid(gcd,a[(-1)*(i+2)])
print(gcd)

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 heapq

n = int(input())
A = [-int(i) for i in input().split()]
heapq.heapify(A)

def battle(a,b):
    
    x, y = min(a,b),max(a,b)
    x -= y * (x // y)
    return x,y

while len(A) != 1:
    a = heapq.heappop(A)
    b = heapq.heappop(A)
    
    while a != 0 and b != 0: a,b = battle(a,b)
    heapq.heappush(A, a) if a != 0 else heapq.heappush(A, b)

print(-A[0])

Solution (Python):

import sys
input = sys.stdin.readline

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


import fractions
temp = a[0]
for i in a[1::]:
    temp = fractions.gcd(temp,i)
    if temp==1:
        break
print(temp)

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

Solution (Python):
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

while True:
	min_a = min(A)
	cnt = 0
	for i in range(N):
		if A[i] % min_a != 0:
			cnt += 1
			A[i] %= min_a
		elif A[i] % min_a == 1:
			break
	if cnt==0: break
print(min_a)

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

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


print(reduce(gcd, a))

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

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

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

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

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

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

l=[0]
for i in range(n):
    l.append(gcd(l[-1],a[i]))

print(l[-1])

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

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

l=[a[0]]
for i in range(n):
    l.append(gcd(l[-1],a[i]))

print(l[-1])

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

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

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

print(l[n])

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

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

ans = min(A)
for a in A:
    ans = fractions.gcd(ans, a)

print(ans)

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

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

Solution (Python):
import fractions
from functools import reduce

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


if __name__ == '__main__':
    main()

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

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

a.sort()
prev = gcd(a[0], a[1])

for i in range(2, n):
    g = gcd(a[i], prev)
    if g < prev:
        prev = g

print(prev)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
import fractions as f
mini=float('inf')
for i in range(n-1):
    x=f.gcd(a[i],a[i+1])
    mini=min(mini,x)
print(mini)

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

Solution (Python):


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

while len(a)!=1:
    b=a[0]
    for i in range(1,n):
        a[i]-=b*(a[i]//b)
    a=sorted([i for i in a if i!=0])
    n=len(a)
    

print(a[0])

Solution (Python):
N = int(input())
A = sorted(list(map(int,input().split())))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
array = []
if N == 1:
    print(A[0])
else:
    t = gcd(A[0],A[1])
    if N ==2:
        print(t)
    else:
        for i in range(2,N):
            t = gcd(t,A[i])
        print(t)

Solution (Python):
import fractions
N = int(input())
A = list(map(int, input().split()))
ans = 1000000000000000000
for i in range(N-1):
  ans = min(ans, fractions.gcd(A[i], A[i+1]))
  if ans == 1:
    break
print(ans)

Solution (Python):

import sys

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

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

A.sort()

a = make_divisors(A[0])

a.sort(reverse = True)

for i in a:
    for j in range(N):
        if A[j] % i != 0:
            break
        if j == N - 1:
            print(i)
            sys.exit()

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

def gcd(a,b):
  return a if b == 0 else gcd(b,a%b)
P=A[0]
for i in range(N):
  P=gcd(P,A[i])
print(P)

Solution (Python):
import fractions
from functools import reduce

n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)
print(reduce(fractions.gcd, a))

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

Solution (Python):
import functools,fractions
n=input()
a=list(map(int,input().split()))
print(functools.reduce(fractions.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
from functools import reduce
N=int(input())
A=list(map(int,input().split()))
def gcd(*num):
    return reduce(fractions.gcd, num)
print(gcd(*A))

Solution (Python):
import os, sys, re, math

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

while True:
    min_a = min(A)
    for i in range(len(A)):
        if A[i] % min_a > 0:
            A[i] = A[i] % min_a
        else:
            A[i] = min_a

    if len(set(A)) == 1:
        break

print(min_a)

Solution (Python):
from functools import reduce

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


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


print(reduce(gcd, lst))

Solution (Python):
import os, sys, re, math

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

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

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

print (result)

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


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

Solution (Python):
from functools import reduce

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

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

Solution (Python):
n = int(input())
l = list(map(int, input().split(' ')))
def gcd(a, b):
    return b if a % b == 0 else gcd(b, a%b)
r = l[0]
for a in l[1:]:
  r = gcd(a, r)
print (r)

Solution (Python):
from fractions import gcd

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

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

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

Solution (Python):


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

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
while len(a)>1:
  m=min(a)
  b=[m]
  for i in range(len(a)):
    x=a[i]%m
    if x!=0:
      b.append(x)
  a=list(set(b))
print(*a)

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 = sorted(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


def solve(n, ax):
    g = ax[0]
    for ai in ax[1:]:
        g = gcd(g, ai)

    return g


if __name__ == '__main__':
    n = int(input())
    ax = list(map(int, input().split()))
    print(solve(n, ax))

Solution (Python):
import fractions





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

    good(A, N)


if __name__ == '__main__':
    main()

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

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

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

print(gcd_list(list_aaa))

Solution (Python):
import fractions

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

Solution (Python):
import fractions
N = int(input())
A = list(map(int,input().split()))
gcd = 10**9
for i in range(N-1):
    tmp = fractions.gcd(A[i],A[i+1])
    if tmp < gcd:
        gcd = tmp
print(gcd)

Solution (Python):
import fractions
N = int(input())
A = sorted(list(map(int,input().split())),reverse = 1)
gcd = 10**9
for i in range(N-1):
    tmp = fractions.gcd(A[i],A[i+1])
    if tmp < gcd:
        gcd = tmp
print(gcd)

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

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

print(reduce(gcd, A))

Solution (Python):
n = int(input())
list1 = list(map(int,input().split()))
import fractions as math
gcd = 10**9
for i in range(n-1):
    gcd = min(gcd,math.gcd(list1[i],list1[i+1]))
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)

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

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a = list(sorted(set(a)))
if len(a) == 1:
    print(a[0])
    exit()

flag = True
while flag:
    if a[0] != 0:
        for i in range(1, len(a)):
            a[i] = (a[i] % a[0])
    else:
        for i in range(2, len(a)):
            a[i] = (a[i] % a[1])
    a = list(sorted(set(a)))
    if len(a) == 2 and a[0] == 0:
        break
print(a[1])

Solution (Python):
import sys

readline = sys.stdin.buffer.readline


def sss(A, N):
    A.sort()
    while A[0] == 0:
        A.remove(0)
    for i in range(1, len(A)):
        A[i] = A[i] % A[0]
    if A[0] == sum(A):
        print(sum(A))
    else:
        return sss(A, N)


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

    sss(A, N)


main()

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

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

while len(a)>=2:
  for i in range(1,len(a)):
    a[i]=a[i]%a[0]
  if 0 in a:
    for j in range(a.count(0)):
      a.remove(0)
  a.sort()
    

print(a[0])

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

Solution (Python):
from functools import reduce
def gcd(a, b):
    if a < b:
        return gcd(b, a)
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
input()
Ai = list(map(int, input().split()))
print(reduce(gcd, Ai))

Solution (Python):
import math
import functools
from fractions import gcd
from functools import reduce
import numpy as np

n = int(input())

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

print(ans)

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

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


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

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


if __name__ == '__main__':
    main()

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

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):
def gcd(n,m):
  a=min(n,m)
  b=max(n,m)
  while a!=0:
    b,a=a,b%a
  return b
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):
N = int(input())
A = sorted(list(map(int,input().split())))
while len(A) > 1: 
    for j in range(1,len(A)):
        A[j] = A[j] % A[0]
    A = [k for k in A if k != 0]
    A.sort()

print(A[0])

Solution (Python):
N = int(input())
A = sorted(list(map(int,input().split())))
while len(A) > 1:
    for j in range(1,len(A)):
        A[j] = A[j] % A[0]
    A = [k for k in A if k != 0]
    A.sort()

print(A[0])

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

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()))
v = fractions.gcd(a[0], a[1])
for i in range(2, n):
    v = fractions.gcd(v, a[i])
print(v)

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

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


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

Solution (Python):

import sys





from functools import reduce




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

def main():
    n, *a = (int(x) for x in sys.stdin.read().split())
    
    ans = reduce(gcd, a)
    print(ans)



if __name__ == "__main__":
    main()

Solution (Python):
import math
from functools import reduce

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

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

print(reduce(gcd, A))

Solution (Python):
n=int(input())
l=[int(i) for i in input().split()]
def gcd(a,b):
    if b==0:
        return a 
    return gcd(b,a%b)
g=0 
for i in l:
    g=gcd(g,i)
print(g)

Solution (Python):


from functools import reduce
from fractions import gcd
import sys
n = int(sys.stdin.readline())
H = list(map(int,sys.stdin.readline().split()))
print(reduce(gcd,H))

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

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

Solution (Python):
from fractions import gcd  

n = int(input())
a = sorted([int(i) for i in input().split()])
ans = gcd(a[0],a[1])
for i in range(2,len(a)):
    ans = min(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 range(1,n):
    ans=fractions.gcd(ans,a[i])
print(ans)

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

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

for i in range(1,n):
    ans = gcd(ans,li[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):
import fractions
n,*a=map(int,open(0).read().split())
b=list(set(a))
c=b[0]
for i in b:
    c=fractions.gcd(i,c)
print(c)

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

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

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

ans = a[0]

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

Solution (Python):
from sys import stdin
import bisect

n = int(stdin.readline().rstrip())
li = list(map(int,stdin.readline().rstrip().split()))

li.sort()

while True:
    if len(li) < 2:
        break
    for i in range(1,len(li)):
        li[i] %= li[0]
    li.sort()
    li = li[bisect.bisect_right(li,0):]
print(li[0])

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

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

Solution (Python):

n = int(input())

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

a.sort()
while 1:
	lst = []
	lst.append(a[0])
	for i in range(1, len(a)):
		if a[i] % a[0] != 0:
			lst.append(a[i]%a[0])
	if len(lst) == 1:
		break
	a = []
	a = lst
	a.sort()
print(lst[0])

Solution (Python):





def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)
def lcm(a, b):
    return((a*b)//gcd(a,b))
def div(x):
    div=[1]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        if(x%check==0):
            div.append(check)
            while(x%check==0):
                x=x//check
        check+=1
    if x != 1:
      div.append(x)
    return div
def div2(x):
    div2=[]
    check=2
    while(x!=1 and check <= int(x**0.5)+2):
        while x%check==0:
            div2.append(check)
            x/=check
        check+=1
    if x != 1:
      div2.append(x)
    return div2

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

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

while len(A) > 1:
    min_A = min(A)
    A = [x % min_A for x in A]
    A = [x for x in A if x != 0]
    A.append(min_A)

print(A[0])

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

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

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 = [int(x) for x in input().split()]
from fractions import gcd
ans = A[0]
for a in A:
    ans = gcd(ans, a)
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):
def GCD(x,y):
    x,y=max(x,y),min(x,y)
    if x%y==0:
        return y
    else:
        return GCD(y,x%y)

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 vs(A):
    A = sorted(A)
    pA = list(map(lambda x: x % A[0], A))
    pA[0] = A[0]
    return list(filter(lambda x: x != 0, pA))


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


spA = -1
sA = -2
while spA != sA:
    sA = sum(A)
    pA = vs(A)
    spA = sum(pA)
    A = pA

print(sum(A))

Solution (Python):
def solve():
    n = input()
    l = list(map(int, input().split()))
    a = l.pop()
    for b in l:
        a = gcd(a,int(b))
    return a

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

if __name__ == '__main__':
    print(solve())

Solution (Python):
def solve():
    n = input()
    l = input().split()
    a = int(l.pop())
    for b in l:
        a = gcd(a,int(b))
    return a

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

if __name__ == '__main__':
    print(solve())