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

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

print(reduce(gcd, a))

Solution (Python):
from __future__ import print_function


import sys
import math
import string
import fractions
import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop



import random

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


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

    eprint("=======================")
    while True:
        xx = min([x for x in l if x > 0])
        
        eprint("xx: "+str(xx))
        flag = 0
        for i in range(len(l)):
            if l[i] == xx and flag == 0:
                flag=1
            else:
                l[i] = l[i]%xx

        
        if all(x==l[0] for x in l):
            
            print(l[0])
            return 0
        if 1 in l:
            print(1)
            return 0
        if sum(l)==xx:
            print(xx)
            return 0
        eprint("=======================")

    print(xx)
    return 0


if __name__ == '__main__':
    main()

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

while len(A) > 1:
    A = sorted(A)
    min_A = A[0]
    next_A = [min_A]
    for i in range(1, len(A)):
        A[i] %= min_A
        if A[i] != 0:
            next_A.append(A[i])
    A = next_A

print(A[0])

Solution (Python):
def sub():
    N = int(input())
    As = [int(e) for e in input().split()]
    ans = None
    while True:
        
        a_min = min(As)
        As = [a % a_min for a in As]
        As = [a for a in As if a != 0]
        if len(As) == 0:
            ans = a_min
            break
        else:
            As.append(a_min)
    print(ans)

sub()

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

dp = [0] * n
dp[0] = a[0]

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

for i in range(n - 1):
    dp[i + 1] = gcd(dp[i], a[i + 1])

print(dp[n - 1])

Solution (Python):
from fractions import gcd

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

print(g)

Solution (Python):
from fractions import gcd

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

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

print(g[-1])

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

n=int(input())
hoge=list(map(int,input().split()))
hoge.sort()
for i in range(n-1):
  hoge[i+1]=gcd(hoge[i],hoge[i+1])
  
print(hoge[-1])

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

    return gcd(b % a, a)


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

g = gcd(xs[0], xs[1])
for x in xs[2:]:
    g = gcd(g, x)

print(g)

Solution (Python):
n = int(input())
data = [int(s) for s in input().split()]

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


x = gcd(data[0], data[1])
for i in range(2,n-1):
    x = gcd(x,data[i])
print(x)

Solution (Python):
N = int(input())
A = [int(a) for a in input().split()]
while len(A) >= 2:
  mn = min(A)
  A = [a % mn for a in A]
  A = [a for a in A if a != 0]
  A.append(mn)
print(A[0])

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

Solution (Python):

import sys
import math

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

def solve(N: int, A: "List[int]"):
    res = A[0]
    B = A[1:]
    for a in B:
        res = gcd(res,a)

    print(res)


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):
from functools import reduce

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

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

def main():
    ans = reduce(calc, A)    
    print(ans)

if __name__ == '__main__':
    main()

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()))
num = 0

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

print(num)

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

monsters.sort()  
minnum = monsters[0]

cnt = len(monsters)
minidx = 0
while cnt > 1:
    for i in range(cnt - 1, 0, -1):
        monsters[i] = monsters[i] % monsters[0]

        if monsters[i] == 0:
            del monsters[i]

        elif monsters[i] == 1:
            print('1')
            quit()

    workmin = min(monsters)
    minidx = monsters.index(min(monsters))
    monsters[minidx] = monsters[0]
    monsters[0] = workmin

    cnt = len(monsters)

print(monsters[0])

Solution (Python):
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b



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



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


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

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


if __name__ == '__main__':
    main()

Solution (Python):
from itertools import combinations

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

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

ans=A[0]
for i in range(1,len(A)):
    ans=min(ans,gcd(ans,A[i]))
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):
from fractions import gcd
from functools import reduce

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

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()))
num = 0

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

print(num)

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



import fractions
import functools

print(functools.reduce(fractions.gcd, A))

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

while True :
    if len(mon_life) == 1 :
        break
    else : 
        min_val = min(mon_life)
        mon_life = [i % min_val for i in mon_life if i % min_val != 0 ]
        mon_life.append(min_val)

print(mon_life[0])

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

lst = []
def Gcd(a , b):
    r =  b % a
    if r == 0:
        return a
    else:
        b = a
        return Gcd(r, a)

for i in range(N - 1):
    v = Gcd(A[i], A[i + 1])
    lst.append(v)

print(min(lst))

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


ans = fractions.gcd(A[0], A[1])

for a in A[2:]:
    ans = fractions.gcd(ans, a)
print(ans)

Solution (Python):
import fractions


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

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

Solution (Python):
import fractions
n=input()
a=list(map(int,input().split()))
if 1 in a:a=[1]
while len(a)>1:
    a.append(fractions.gcd(a.pop(),a.pop()))
    if a[-1]==1:break
print(a[-1])

Solution (Python):
import fractions
n=input()
a=list(map(int,input().split()))
while len(a)>1:
    a.append(fractions.gcd(a.pop(),a.pop()))
    if a[-1]==1:break
print(a[-1])

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

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

gcd_num = 0
for i in range(len(A_list)):
    gcd_num = gcd(gcd_num, A_list[i])
print(gcd_num)

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

def gcd(p,q):
    if q == 0: return p
    return gcd(q, p%q)

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

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

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

Solution (Python):

n = int(input())
a = [int(i) for i in input().split()]
min_HP = min(a) 
while True:
  for ni in range(n):
    if a[ni]%min_HP!=0:
      a[ni] = a[ni]%min_HP
  if min_HP > min(a):
    min_HP = min(a)
  else:
    break
print(min_HP)

Solution (Python):
import sys
import bisect
input = sys.stdin.readline

N = int(input())
L = [int(v) for v in input().split()]

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

p = L[0]
for v in range(N - 1):
    p = gcd(L[v + 1], p)
    
print(p)

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

from fractions import gcd

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

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

n = int(input())
x = list(map(int, input().split()))
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):
n = int(input())
a = list(map(int,input().split()))
while True:
  att = min(a)
  attin = a.index(att)
  a = [i % att for i in a]
  a = [i for i in a if i != 0]
  a.append(att)
  if len(a) == 1:
    break
print(a[0])

Solution (Python):
import fractions

n = int(input())
ms = list(map(int, input().split(" ")))
ans = ms[0]

for i in ms[1:]:
  ans = fractions.gcd(ans, i)
  
print(ans)

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

def battle(lis):
  while True:
    if len(lis) == 1: break
    lis = [i for i in lis if i != 0]
    lis.sort()
    for i in range(len(lis)-1):
      lis[i+1] %= lis[0]
  return lis[0]

print(battle(A))

Solution (Python):
from fractions import gcd

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

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

Solution (Python):
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(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)

N = int(input())
aa = inpl()
ans = aa[0]
for a in aa:
    ans = gcd(a,ans)
print(ans)

Solution (Python):
import fractions

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

gcd = A[0]

for i in range(1,len(A)):
    gcd = fractions.gcd(gcd,A[i])

print(gcd)

Solution (Python):
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
  
N = int(input())
li = [ int(it) for it in input().split() ]

w = li[0]
for i in range(N-1):
  w = gcd(w,li[i+1])
print (w)

Solution (Python):


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


def calc(monsters):
    if len(monsters) == 1:
        return monsters[0]

    min_monster = min(monsters)
    min_index = monsters.index(min_monster)
    new_monsters = []
    for i in range(len(monsters)):
        if i == min_index:
            new_monsters.append(monsters[i])

        remndr = monsters[i] % min_monster
        if remndr != 0:
            new_monsters.append(remndr)

    return calc(new_monsters)


ans = calc(A)
print(ans)

Solution (Python):

import fractions

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


def calc(monsters):
    if len(monsters) == 1:
        return monsters[0]

    min_monster = min(monsters)
    min_index = monsters.index(min_monster)
    new_monsters = []
    for i in range(len(monsters)):
        if i == min_index:
            new_monsters.append(monsters[i])

        remndr = monsters[i] % min_monster
        if remndr != 0:
            new_monsters.append(remndr)

    return calc(new_monsters)


ans = calc(A)
print(ans)

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

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


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


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().strip().split()))


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


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

print(ever_gcd)

Solution (Python):
N = int(input())
A = [int(c) for c in input().split()]
A.sort()
while True:
    pivot = A.pop(0)
    A = [a % pivot for a in A if a % pivot != 0]
    if len(A) == 0:
        print(pivot)
        break
    A.append(pivot)
    A.sort()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
b = A[0]
def gcm(x,y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    return gcm(y,x%y)
for a in A:
    b = gcm(b,a)
print(b)

Solution (Python):
N = int(input())
monsters = list(map(int,input().split()))
monsters.sort()
while len(monsters)>1:
    for i in range(1,len(monsters)):

        monsters[i] = monsters[i] % monsters[0]
    monsters = [i for i in monsters if i != 0]
    monsters.sort()
print(monsters[0])

Solution (Python):

def euclid_gcd(a, b):
    if a < b:
        tmp = a
        a = b
        b = tmp
    if b == 0:
        return a
    else:
        return euclid_gcd(b, a % b)

def gcd(n_list):
    ans = n_list[0]
    for n in n_list:
       ans = euclid_gcd(ans, n)
    return ans



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

    answer = gcd(A)

    print(answer)

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


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


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

print(A[N-1])

Solution (Python):
def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    tmp = x%y
    while not tmp == 0:
        x = y
        y = tmp
        tmp = x%y
    return y
N = int(input())
A = list(map(int,input().split()))
hp = A[0]
for i in A:
    hp = gcd(hp,i)
print(hp)

Solution (Python):
n = int(input())
a = list(map(int,input().split()))
ans = []
def chr(a,b):
  
    if a >= b:
        a = a%b
    else:
        b = b%a
    if a == 0 or b == 0:
        return(max(a,b))
    else:
        return(chr(a,b))

ans.append(chr(a[0],a[1]))


for i in range(1,n):
    ans.append(chr(ans[-1],a[i]))
print(ans[-1])

Solution (Python):
def gcd(x,y):
    if y>x:
        a=y
        y=x
        x=a
    a=1
    while a*y:
        a=x%y
        x=y
        y=a
    return x
a=int(input())
b=[int(i) for i in input().split()]
c=b[0]
for i in range(a-1):
    c=gcd(c,b[i+1])
print(c)

Solution (Python):
n = int(input())
a = sorted(map(int, input().split()))
while not len(a) == 1:
    b = []
    for hp in a:
        hp %= a[0]
        if hp > 0:
            b.append(hp)
    b.append(a[0])
    a = sorted(b)
print(*a)

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

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

from fractions import gcd

M = a[0]
         
for x in a[1:]:
    M = gcd(M, x)

print(M)

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)

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

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

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

def gcd(x,y):
    if x<y:
        x,y=y,x
    
    if y==0:
        return x
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)
      
x = l[0]
for i in range(1,n):
  x = gcd(x,l[i])
  
print(x)

Solution (Python):
from fractions import gcd

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

mini = min(A)
ans = min(A)
for a in A:
    amari = a % mini
    if amari != 0:
        if amari < ans:
            ans = amari            
if mini - ans == 0:
    print(ans)
else:
    print(gcd(mini, ans))

Solution (Python):
from fractions import gcd

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

a = sorted(A)
B = [a[0]]
C = []
for i in range(1,N):
    x = a[i]%a[0]
    if x != 0:
        B.append(x)
b =sorted(B)
for i in range(len(b)-1):
    y = gcd(b[i],b[-1])
    C.append(y)
    
if len(b) == 1:
    print(b[0])
else:
    print(min(C))

Solution (Python):
from fractions import gcd
from functools import reduce
N = int(input())
A = [int(a) for a in input().split(" ")]
print(reduce(lambda acc, c: gcd(acc, c), A, A[0]))

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)

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

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

print(g)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
INF = 10**9
mod = a[::]
previous_min = min(a)

while True:
    if sum(mod) == 0:
        ans = previous_min
        break
    current_min = min(filter(lambda x: x > 0, mod))
    mod = [a[i] % current_min for i in range(len(a))]
    previous_min = current_min

print(ans)

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


def gcd(x,y):
  if x < y:
    tmp = x
    x = y
    y = tmp
    
  while y:
    x, y = y, x % y
  return x  
    
ans = gcd(A[0], A[1])  
for i in range(2,N):
  ans = gcd(ans,A[i])
  
  
print(ans)

Solution (Python):
n=int(input())
a=[int(i) for i in input().split()]
b=a[0]
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x

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

Solution (Python):
import fractions
n = int(input())
a = list(map(int,input().split()))
d = min(a)
for t in a:
  d = fractions.gcd(d, t)
print(d)

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

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)


x = A[0]
for i in A[1:]:
	x = gcd(x,i)
print(x)

Solution (Python):
import functools
from fractions import gcd

n = int(input())
l = list(map(int, input().split()))
ans = functools.reduce(gcd, l)
print(ans)

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)

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

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

Solution (Python):
import fractions
from functools import reduce

_ = int(input())
ans = reduce(fractions.gcd, [int(i) for i in input().split()])
print(ans)

Solution (Python):



import fractions


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


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


print(wkgcd)

Solution (Python):
N = int(input())
A = sorted(list(map(int,input().split())))
m = min(A)
def gcd(a, b):
    r = a%b
    while r != 0:
        a = b
        b = r
        r = a%b
    return b
g = A[0]
for i in range(N):
    g = gcd(g, A[i])
print(min(g,m))

Solution (Python):
n = int(input())
A = list(map(int, input().split()))
def gcd(i, j):
    a = max(i, j)
    b = min(i, j)
    r = a%b
    if r == 0:
        return b
    else:
        return gcd(b, r)
f = gcd(A[0], A[1])      
for i in range(2, n):
    f = gcd(f, A[i])
print(f)

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

min_g = fractions.gcd(A[0], A[1])
for i in A[2:]:
  min_g = fractions.gcd(min_g, i)
  
print(min_g)

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

Solution (Python):
from fractions import gcd

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

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

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

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


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

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

print (ans)

Solution (Python):
import math
N = int( input())
temp = list(map(int,input().split(" ")))
temp.sort()
def GCD( a,  b ):
    if b == 0:
        
        return a
    else:
        
        return GCD(b, a % b)
ans = [GCD(temp[0],temp[1])]
for i,num in enumerate(temp[2:]):
    ans.append(GCD(ans[i],num))

print(ans[-1])

Solution (Python):

import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, A: "List[int]"):
    while len(A) != 1:
        A.sort(reverse=True)
        while A[-1] == 0:
            A.pop()
        for i in range(len(A) - 1):
            A[i] %= A[-1]
    return A[0]


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) ]  
    result = solve(N, A)
    print(result)

if __name__ == '__main__':
    main()

Solution (Python):

input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

import functools,fractions
import numpy as np
gcd = lambda a:functools.reduce(fractions.gcd,a) 
lcm_base = lambda a,b:(a*b)//fractions.gcd(a,b) 
lcm = lambda a:functools.reduce(lcm_base,a,1) 

def solution():
    N = input_int()
    As = input_ints()
    ans = gcd(As)
    print(ans)

if __name__ == '__main__':
    solution()

Solution (Python):
import numpy as np
from copy import deepcopy

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





def ABC118(lst):
  if len(lst) == 1:
    return lst[0]
  new_lst = deepcopy(list(set(lst)))
  min_idx = new_lst.index(min(new_lst))
  min_var = new_lst[min_idx]
  new_lst = [(new_lst[i] % min_var) for i in range(len(new_lst)) if i != min_idx]
  new_lst.append(min_var)
  new_lst = [x for x in new_lst if x != 0]
  return(ABC118(new_lst))
  
ans = ABC118(A)
print(ans)

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

result = A
while True:
    result = list(set(result))
    result.sort()
    if min(result) == 0:
        result.remove(0)
    tmp_min = min(result)
    
    if len(result) == 1:
        break
    result =[r % tmp_min for r in result[1:]]
    
    if max(result) == 0:
        result.append(tmp_min)
        break
    result.append(tmp_min)
    

print(max(result))

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

Solution (Python):
from fractions import gcd

N = input()
ans = 0
for a in map(int, input().split()):
    ans = gcd(ans, a)
print(ans)

Solution (Python):
from fractions import gcd

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

current = A[0]
for index in range(1, N):
    current = gcd(current, A[index])

print(current)

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

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

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

Solution (Python):

input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

import functools,fractions
import numpy as np
gcd = lambda a:functools.reduce(fractions.gcd,a) 
lcm_base = lambda a,b:(a*b)//fractions.gcd(a,b) 
lcm = lambda a:functools.reduce(lcm_base,a,1) 

def solution():
    N = input_int()
    As = input_ints()
    ans = gcd(As)
    print(ans)

if __name__ == '__main__':
    solution()

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
while True:
  min_A = min(A)
  A = list(map(lambda x: x % min_A, A))
  A = [x for x in A if x != 0]
  A.append(min_A)
  if len(A)==1:
    break

print(min_A)

Solution (Python):



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

while len(A) != 1:

    
    minA = min(A)

    
    nA = set()
    nA.add(minA)

    for Ai in A:
        if Ai == minA: continue
        if Ai % minA != 0:
            nA.add(Ai%minA)

    
    A = nA

print '{}'.format( list(A)[-1])

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

while len(A) != 1:
    minA = min(A)

    nextA = set()
    for Ai in A:
        if Ai == minA:
            nextA.add(Ai)
            continue
        if Ai % minA != 0:
            nextA.add(Ai%minA)

    A = nextA

A = list(A)
print '{}'.format(A[0])

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

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

Solution (Python):
_ = input()
A = list(map(int, input().strip().split(' ')))

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

now_gcd = A[0]
for a in A[1:]:
  now_gcd = gcd(now_gcd, a)
  if now_gcd == 1:
    break
print(now_gcd)

Solution (Python):
import functools

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

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

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

Solution (Python):
import fractions
from functools import reduce


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


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

print(gcd_list(a))

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

while len(A) >= 2: 
  if A[0] == 1: break
  
  rem = A[1] % A[0] 
  if rem != 0: A[0], A[1] = rem, A[0]
  
  else: del A[1]

print(A[0])

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

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

Solution (Python):
N=int(input())
A = list(map(int, input().split()))
A.sort()
sa = []
for i in range(N-1):
    diff = A[i+1]-A[i]
    if diff > 0:
        sa.append(diff)
sa.sort()

if len(sa)>=2:
    score = sa[1] - sa[0]
    if score <= 0:
        print(sa[0])
    else:
        dai = max(score, sa[0])
        sho = min(score, sa[0])
        while dai-sho > 0:
            dai, sho = sho, dai-sho
            if dai <= sho:
                dai, sho = sho, dai
        print(dai-sho if dai-sho > 0 else sho)
elif len(sa) == 1:
    dai = max(A[0], sa[0])
    sho = min(A[0], sa[0])
    while dai-sho > 0:
        dai, sho = sho, dai-sho
        if dai <= sho:
            dai, sho = sho, dai
    print(dai-sho if dai-sho > 0 else sho)
else:
    print(A[0])

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

Solution (Python):
import fractions
from functools import reduce

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

input()

print(gcd_list(list(map(int, input().split()))))

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

while len(A) > 1:
    minA = min(A)
    tempA = []
    tempA.append(minA)
    for a in A:
        mod = a % minA
        if mod > 0:
            tempA.append(mod)
    A = tempA

print(A[0])

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

while len(A) > 1:
    minA = min(A)
    tempA = set()
    tempA.add(minA)
    for a in A:
        mod = a % minA
        if mod != 0:
            tempA.add(mod)
    A = tempA

print(list(A)[0])

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

while len(A) > 1:
    minA = min(A)
    tempA = []
    tempA.append(minA)
    for a in A:
        mod = a % minA
        if mod != 0:
            tempA.append(mod)
    A = tempA

print(A[0])