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):
def gcd(m, n):
    while n:  
        m, n = n, m % n
    return m


N = int(input())  

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

g = gcd(A[0], A[1])

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

print(g)

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


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

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

print(g)

Solution (Python):
def gcd(a, b):
    if b > a:
        a,b = b,a
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
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):
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
a = A[0]
for i in range(1,N):
    a = gcd(a,A[i])
print(a)

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

A_min = min(A)
while(True):
    amin = max(A)
    for i in range(N):
        if A_min == A[i]:
            continue
        A[i] %= A_min
        if A[i] > 0 and A[i] <= amin:
            amin = A[i]
    A_min = amin
    if max(A) == A_min:
        break

print(max(A))

Solution (Python):

from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007


def A():
    a,b = LI()
    if b%a == 0:
        print(a+b)
    else:
        print(b-a)
    return


def B():
    n,m = LI()
    d = defaultdict(int)
    for i in range(n):
        l = LI()
        for j in range(1,len(l)):
            d[l[j]] += 1
    ans = 0
    for i in d.values():
        if i == n:
            ans += 1
    print(ans)
    return


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


def D():
    return


def E():
    return


def F():
    return


def G():
    return


def H():
    return


if __name__ == "__main__":
    C()

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

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

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

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

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

print(A[N-1])

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

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

  while 0 in A:
    A.remove(0)

print(A[0])

Solution (Python):
n=int(input())
l=sorted(list(map(int,input().split())))
m=min(l)
l2=[]
l3=[]
for i in range(1,int(m**(1/2)+1)):
  if m%i==0:                   
    l2.append(i)
    if i!=m//i:
      l2.append(m//i)
for i in l2:
  b=True
  for j in l:
    if j%i==0:
      pass
    else:
      b=False
  if b:
    l3.append(i)
print(max(l3))

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

Solution (Python):
N = int(input())
monster = [int(i) for i in input().split()]
while(len(monster) != 1):
    Min = min(monster)
    index = monster.index(min(monster))
    index2 = 0
    for i in monster:
        monster[index2] = i % Min
        index2 += 1
    monster[index] = Min

    for i in reversed(range(0,len(monster))):
        if monster[i] == 0:
            del monster[i]

print(monster[0])

Solution (Python):
from sys import stdin
import numpy as np

N = int(stdin.readline().rstrip().split()[0])
A = [int(x) for x in stdin.readline().rstrip().split()]


def G(_a, _b):
  if _a>=_b:
    a, b = _a, _b
  else:
    a, b = _b, _a
  
  while True:
    c = a%b
    if c == 0:
      break
    a,b = b,c
  
  return b

L = np.array(list(set(A)))
mini = np.min(L)
yaku = [1]
i=2
r_mini = np.sqrt(mini)
while i<=r_mini:
  if mini%i==0:
    yaku.append(i)
  i+=1
yaku2 = list(map(lambda x: int(mini/x), yaku))
yaku = yaku[::-1]
yaku2.extend(yaku)
for y in yaku2:
  if np.sum(L%y)==0:
    ans = y
    break

print(ans)

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

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

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

def ea(a,b):
    s=0
    while True:
        c=a%b
        if c==0:
            break
        a=b
        b=c
        
    return b

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

print(A[N-1])

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

solved = False
while not solved:
    solved = True
    mod = min(A)
    new_A = [mod]

    for i, v in enumerate(A[:]):
        hp = v % mod
        if solved and hp != 0:
            solved = False
            new_A.append(hp)

    if solved:
        print(mod)
        exit()
    else:
        A = new_A

Solution (Python):


N = int(input())

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

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

if len(monsters) == 1:
    print(monsters[0])

else:
    elm = gcd(monsters[0], monsters[1])
    if len(monsters) != 2:
        for i in range(2, N):
            elm = gcd(elm, monsters[i])
print(elm)

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

  N = int(input().strip())
  o = 0
  for i in map(int, input().split()):
    o = gcd(i,o)
  print(o)

if __name__=="__main__":
  solve()

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


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



if len(a) == 1:
    print(a[0])
else:
    element = gcd(a[0], a[1])
    if len(a) == 2:
        print(element)
    else:
        for i in range(2, n):
            element = gcd(element, a[i])
        print(element)

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

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

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

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


    An = sorted(An)
    An = [gcd(a_n, An[0]) for a_n in An]
    print(min(An))

main()

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

Solution (Python):
import sys

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

a=HP[0]
b=HP[1]

(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
    q = a // b
    (a, b) = (b, a % b)
    (x, lastx) = (lastx - q * x, x)
    (y, lasty) = (lasty - q * y, y)
        
tmp=a

for i in range(1,N-1):
    a=tmp
    b=HP[i+1]
    
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
        
    tmp=a
    if tmp==1:
        print(tmp)
        sys.exit()
    
print(tmp)

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

a=HP[0]
b=HP[1]

(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
    q = a // b
    (a, b) = (b, a % b)
    (x, lastx) = (lastx - q * x, x)
    (y, lasty) = (lasty - q * y, y)
        
tmp=a

for i in range(1,N-1):
    a=tmp
    b=HP[i+1]
    
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
        
    tmp=a
    
print(tmp)

Solution (Python):
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    gcd=a
    return gcd

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

tmp=egcd(HP[0],HP[1])

for i in range(1,N-1):
    a=tmp
    b=HP[i+1]
    
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
        
    tmp=a
    
print(tmp)

Solution (Python):
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    gcd=a
    return gcd

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

tmp=egcd(HP[0],HP[1])

for i in range(1,N-1):
    tmp=egcd(tmp,HP[i+1])
    
print(tmp)

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

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

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

Solution (Python):
N = int(input())
list = list(map(int,input().split()))
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

gcd_val = list[0]

for i in list[1::]:
    gcd_val = gcd(gcd_val,i)

print(gcd_val)

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

    divisors.sort()
    return divisors

n=int(input())
l=list(map(int,input().split()))
m=min(l)
div=make_divisors(m)
div.reverse()
for i in div:
    flg=0
    for j in l:
        if j%i!=0:
            flg=1
            break
    if flg==0:
        ans=i
        break
print(ans)

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

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

def gcd(arr):
    g = gcd_core(arr[0],arr[1])
    for i in range(2,len(arr)):
        g = gcd_core(g,arr[i])
    return g

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

print(gcd(a))

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a_min = min(a)
while True:
    flag = 0
    a_attacked = [10 ** 9, 0]
    for i in range(n):
        if 0 < a[i] % a_min < a_attacked[0]:
            a_attacked[0] = a[i] % a_min
            a_attacked[1] = i
            flag = 1
    if flag == 0:
        break
    else:
        a_min = a_attacked[0]
        a[a_attacked[1]] = a_attacked[0]
print(a_min)

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

Solution (Python):
from functools import reduce

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

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


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

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

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

print(reduce(gcd, a))

Solution (Python):
INFO=int(input())
DATA=list(map(int, input().split(" ")))
DATA=sorted(DATA)
def Euclidean(m,n):
    while n!=0:
        temp = n
        n = m%n
        m=temp
    return m
    
output=DATA[0]
for i in range(1,INFO):
    output = Euclidean(DATA[i], output)

print(output)

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

for i in range(len(A)):
 A[i] = int(A[i])

while(1):
 if(len(A) == 1):
  ans = A[0]
  break 
 A = list(set(A))
 A.sort()
 if(A[0] == 0):
  A.pop(0)
 min_monster = A[0]
 for i in range(len(A)):
   if(i != 0):
      tmp = A[i]//min_monster
      A[i] -= min_monster*tmp

print(ans)

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

for k in range(infa):
    mina = min(a)

    for i in range(len(a)):
       
        if a[i] == mina:
            a[i] = mina
        else:
            a[i] = a[i] % mina
    
    a = [j for j in a if not j == 0]

    if len(a) == a.count(mina):
        break

print(mina)

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

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

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

print(gh)

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

Solution (Python):
def euclid(n, a_list):
    a1, a2 = a_list[0:2]
    gcd_ = gcd(a1, a2)
    for i in range(2, n):
        gcd_ = gcd(gcd_, a_list[i])
    return gcd_

def gcd(a1, a2):
    r = 1
    while (r > 0):
        r = a1 % a2
        a1, a2 = a2, r
    return a1


n = int(input())
a_list = [int(i) for i in input().split()]
a_list = sorted(a_list)
ans = euclid(n, a_list)
print(ans)

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


flag = True

while(flag):
    As = sorted(As)
    for i in range(1,len(As)):
        As[i] %= As[0]

    As = list(filter(lambda  x: x > 0, As))
    if len(As) == 1:
        flag = False

print(As[0])

Solution (Python):
import numpy as np
N = int(input())
HPs = np.array([int(i) for i in input().split()])
np.sort(HPs)
while len(HPs) > 1:
    HPs[1:] %= HPs[0]
    HPs[HPs==0] = HPs[0]
    HPs=np.unique(HPs)
print(HPs[0])

Solution (Python):

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

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

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

while True:
    A.sort()
    if len(A) == 1:
        break
    a = A[0]
    tmp_A = [a]
    for b in A[1:]:
        b = gcd(a, b)
        if b != 0:
            tmp_A.append(b)
    A = tmp_A
print(A[-1])

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

while len(A) > 1:
  min_A = min(A)
  next_A = set([min_A])
  for i in A:
    B = i % min_A
    if B != 0:
      next_A.add(B)
  A = list(next_A)
print(list(A)[0])

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
def gcd(m,n):
    m,n = max(m,n), min(m,n)
    while n > 0:
        m, n = n, m%n
    return(m)
A.sort()
g = A[0]
for i in range(N):
    if g == 1:
        break
    else:
        g = gcd(g,A[i])

print(g)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
def gcd(m,n):
    m,n = max(m,n), min(m,n)
    while n > 0:
        m, n = n, m%n
    return(m)

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

print(g)

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

while len(HP) > 1:
    minHP = min(HP)
    nextHPs = set([minHP])
    for each_HP in HP:
        temp = each_HP % minHP
        if temp != 0:
            nextHPs.add(temp)
    HP = list(nextHPs)
print(list(HP)[0])

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

import numpy as np
A = np.array(sorted(A))

while(True):
    A[1:] %= A[0]
    A = np.unique(A)
    A = np.delete(A, np.where(A == 0))
    if len(A) == 1:
        break

    A.sort()

print(A[0])

Solution (Python):

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

for _ in range(10**12):
    if len(a)==1:
        print(a[0])
        exit()
    z=0
    for i in range(1,len(a)):
        tmp = a[i]%a[0]
        if tmp==0:
            z+=1
        a[i]=tmp
    a.sort()
    a=a[z:]

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

import math

s = []
m = a[0]

for i in range(math.floor(math.sqrt(m))+3):
	if m%(i+1)==0:
		if (i+1) not in s:
			s.append(i+1)
		if m//(i+1) not in s:
			s.append(m//(i+1))
s.sort()
s = reversed(s)

for i in s:
    for j in range(len(a)):
        if a[j]%i>0:
            break
    else:
        print(i)
        break

Solution (Python):
import fractions
N=int(input())
As=input().split()
As=[int(a) for a in As]
count=As[0]
for i in As:
    count=fractions.gcd(count,i)
print(str(count))

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

min_m = 10**10
while len(A)*min_m != sum(A):
    min_m = min(A)
    n_min_m = min_m
    for i,a in enumerate(A):
        if min_m != a:
            A[i] = min_m if a%min_m == 0 else a%min_m
            n_min_m = min(a,n_min_m)
    min_m = n_min_m

print(min_m)

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

Solution (Python):
import sys


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


fin = sys.stdin.readline
N = int(fin())
A = [int(elem) for elem in fin().split()]
assert len(A) == N

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

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


while True:
  if len(M_list)==1:
    break
    
  Min_M=min(M_list)
  M_list_temp = [x for x in M_list if x%Min_M!=0 or x == Min_M]
  mod_list=[Min_M]
  mod_list.extend([ x%Min_M for x in M_list if x%Min_M!=0 ])
  mod_list=list(set(mod_list))
  
  M_list=mod_list
  
print(M_list[0])

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

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

for i in range(1, len(MONSTER)):
  MONSTER[i] = euclidean(MONSTER[i-1], MONSTER[i])
print(MONSTER[len(MONSTER) - 1])

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

while(len(li)>1):
    li=sorted(li)
    min_num=li[0]
    li=[i%min_num for i in li]
    li.append(min_num)
    li=[j for j in li if j !=0]
print(li[0])

Solution (Python):

from functools import reduce

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


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

    return ans


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

    print(solve(n, a))


if __name__ == '__main__':
    main()

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

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

val = A[0]
for i in xrange(1, N, 1):
    val = gcd(val, A[i])

print val

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
def gcm(a, b) :
  while(b) :
    a, b = b, a%b
  return a

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

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
while len(A) > 1:
    A.sort()
    devided_num = int(A[0])
    devi_lis = [devided_num]
    As = A
    As.pop(0)
    A =[_%devided_num for _ in As if _%devided_num > 0]
    A += devi_lis
print(A[0])

Solution (Python):
from fractions import gcd

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

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

print(num)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
while len(A) > 1:
    a_ = A[0]
    for x in range(1,len(A)):
        A[x] %= a_
    A = [ans for ans in A if ans > 0]
    A.sort()
print(A[0])

Solution (Python):

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

while(len(set(A)) != 1):
    minA  = min(A)
    for i in range(N):
        if A[i] > minA:
            time = A[i] // minA
            if time == 1:
                A[i] =A[i] -  time * minA
            else:
                A[i] =A[i] -  (time - 1) * minA
                
print(min(A))

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

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

x = gcd(a[0],a[1])

if n != 2:
    for i in range(2,n):
        x = gcd(x,a[i])
        
print(x)

Solution (Python):
""" AtCoder """

from fractions import gcd

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

ans = A[0]

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

print(ans)

Solution (Python):
N=int(input())
a=list(map(int,input().split()))
while len(a)!=1:
    a.sort()
    for i in range(1,len(a)):
        a[i]%=a[0]
    while 0 in a:
        a.remove(0)
print(a[0])

Solution (Python):
def gcd(x, y):
  while y != 0:
      x, y = y, x%y
  return x
  
N = int(input())

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

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

print(ans)

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

def euclid(a, b):
    c,d = sorted([a, b])
    r = 1
    while (r > 0):
        r = d % c
        c,d = r,c
    return d

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

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

m = max(A)
while m != min(A):
    m = min(A)
    A = [(a%m)if a!=m else m for a in A if a==m or (a%m)>0]
print(m)

Solution (Python):
def gcd(a,b):
  if min(a,b)==a:
    if b%a==0:return a
    else:b%=a
  while 1:
    if a%b==0:break
    a%=b
    if b%a==0:break
    b%=a
  return min(a,b)
n=int(input())
a=list(map(int,input().split()))
for oAo in range(len(a)-1):
  a[0]=gcd(a[0],a[1])
  del a[1]
print(a[0])

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

while True:
    if len(A) == 1:
        print(A[0])
        break
    A.sort()
    A = [A[0]] + [x % A[0] for x in A[1:]]
    A = [x for x in A if x != 0]

Solution (Python):



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

while True:
    min_value = min(A)
    flag_update = False
    pop_indices = []
    for i, v in enumerate(A):
        if v != min_value:
            flag_update = True
            A[i] = v % min_value
            if A[i] == 0:
                pop_indices.append(i)
    
    for i in pop_indices[::-1]:
        A.pop(i)
            
    if flag_update == False:
        break

print(min_value)

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
a = A[0]

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

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

Solution (Python):
from fractions import*;input();a,*b=map(int,input().split())
for i in b:a=gcd(a,i)
print(a)

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

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

a = sorted(a)
zero_monster_indexes = []

while True:
    for monster_i in range(1, len(a)):
        if a[monster_i] == 0:
            zero_monster_indexes.append(monster_i)
        else:
            a[monster_i] %= a[0]

            if a[monster_i] == 0:
                zero_monster_indexes.append(monster_i)

    for zero_monster_index in reversed(zero_monster_indexes):
        a.pop(zero_monster_index)
    zero_monster_indexes.clear()

    a = sorted(a)
    if len(a) == 1:
        break

print(a[0])

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

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

def lcm(m, n):
  return (m*n)//gcd(m, n)

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

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

if N == 1:
	print(abs(x[0]))
else:
	a = x[0]
	for i in range(N - 1):
		b = x[i + 1]
		a, b = sorted([a, b])
		while True:
			if b % a == 0:
				break
			else:
				a, b = b % a, a
	print(abs(a))

Solution (Python):
N = int(input())
a = [int(i) for i in input().split()]
while len(a)>1:
    while 0 in a:
        a.remove(0)
    a.sort()
    for i in range(1,len(a)):
        a[i] = a[i] % a[0]
print(a[0])

Solution (Python):
def equ(a, b):
    while b > 0:
        a, b = b, a % b
    return a


N = int(input())

A = list(map(int, input().split()))
gcd = A[0]
for i in range(len(A)):
    gcd = equ(gcd, A[i])
print(gcd)

Solution (Python):
def gcm(a,b):
    while b != 0:
        a, b = b, a % b
    return a

def gcm_list(a):
    ans = a[0]
    l = len(a)
    for i in range(1, l):
        ans = gcm(ans, a[i])
    return ans

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

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)

E = gcd(A[0], A[1])
if n == 2: print(E)
else:
    for i in range(2, n):
        E = gcd(E, A[i])
    print(E)

Solution (Python):
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x % y == 0:
      return y
    else:
      while x % y != 0:
        z = x % y
        x = y
        y = z
      return y


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

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

mi = min(A)
while 1:
    for i in range(N):
        if A[i] != mi:
            A[i] %= mi
            if A[i] <= 0:
                A[i] = mi
    if min(A) == mi:
        break
    else:
        mi = min(A)

print(mi)

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

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

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

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

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

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

i = 0
def euq(x,y):
  a = max(x,y)
  b = min(x,y)
  if a % b == 0:
    return b
  else:
  	return euq(b, a % b)
  


while i < N-1:
  com =  euq(data[i],data[i + 1])
  data[i+1] = com
  i += 1
  
  

print(com)

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

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

if n==1:
    print(x[0])
else:
    element = gcd(x[0], x[1])
    if n==2:print(element)
    else:
        for i in range(2,n):
            element=gcd(element,x[i])
        print(element)

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

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

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
  
gcd = functools.reduce(gcd, m)
print(gcd)

Solution (Python):
N = int(input())
A = [int(i) for i in input().split()]
INF = 10**10
while True:
  num_alive = sum([1 if i>0 else 0 for i in A])
  
  
  if num_alive == 1:
    break
  else:
    min_A = INF
    for i in A:
      if i>0:
        min_A = min(i, min_A)
      else:
        pass
    min_A_idx = A.index(min_A)
    
    A = [ i % min_A if idx != min_A_idx else i for idx, i in enumerate(A)  ]
    
print(max(A))

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

while len(a) > 1:
    idx = 0
    m = a[0]
    for i in range(len(a)):
        aa = a[i]
        if aa > 0 and aa < m:
            idx = i
            m = a[idx]
    for i in range(len(a)):
        if i != idx:
            a[i] = a[i] % m
    a = [aa for aa in a if aa > 0]
print(a[0])

Solution (Python):
def gcd(a, b):
    """ 最大公約数。aはbより大きいこと """
    if b == 0:
        return a
    else:
        return gcd(b, a%b)


def solve():
    N = int(input())
    A = [int(x) for x in input().split(" ")]

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

    print(ans)


if __name__ == "__main__":
    solve()

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

print(A[0])

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



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

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

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

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

Solution (Python):
from functools import reduce

def gcd(x , y):
    while y != 0:
        x , y = y , x % y
    return x
    
N = int(input())
An = [ x for x  in  map(int, input().split()) ]
print(reduce(gcd, An))

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
while True:
  if len(L) == 1:
    print(L[0])
    quit()
  L = sorted(L)
  m = L[0]
  for i in range(1,len(L)):
    L[i] %= m
  L = list(filter(lambda x:x!=0,L))

Solution (Python):
def __gcd(a: int, b: int) -> int:
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return __gcd(b, a % b)


def monsters_battle_royale(N: int, A: list) -> int:
    a = A[0]
    for b in A[1:]:
        a = __gcd(a, b)

    return a


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = monsters_battle_royale(N, A)
    print(ans)

Solution (Python):
def take_mod(L):
	for i in range(1,len(L)):
		if L[i]%L[0] == 0:
			L[i] = L[0]
		else:
			L[i] = L[i]%L[0]
	L.sort()
	return L

N = int(input())
L = list(map(int, input().split()))
L.sort()

while True:
	L = take_mod(L)
	if len(set(L)) == 1:
		print(L[0])
		exit()