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 yuk(a, b):
    ans = int(a / b)
    amari = a % b
    if amari != 0:
        ans = yuk(b, amari)
    else:
        ans = b
    return ans

N = int(input())
alst = list(map(int, input().split()))
ans = alst[0]
for i in range(1, N):
    if ans > alst[i]:
        ans = yuk(ans, alst[i])
    else:
        ans = yuk(alst[i], ans)
print(ans)

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


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


prev = None
for a in alist:
    if prev is None:
        prev = a
        continue
    prev =lcm(prev, a)

print(prev)

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

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

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

tmp = monster_list[0]

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

for i in range(len(monster_list)):
    if i == 0:
        continue
    else:
        tmp = gcd(tmp,monster_list[i])
 

print(tmp)

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

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

tmp = monster_list[0]

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

for i in range(len(monster_list)):
    if i == 0:
        continue
    else:
        if(tmp >= monster_list[i]):
            tmp = gcd(tmp,monster_list[i])
        else:
            tmp = gcd(monster_list[i],tmp)
print(tmp)

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

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

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

while N > 1:
    a = A[0]
    b = A[1] % a
    if b == 0:
        A.pop(1)
        N -= 1
    else:
        A[1] = a
        A[0] = b

print(A[0])

Solution (Python):
def main():
  if 'get_ipython' not in globals():  
    
    N = int(input())
    A = list(map(int, input().split()))
  else:
    
    
    
    
    
    N = 3
    A = [1000000000,1000000000,1000000000]

  while len(A)>1:
    minA = min(A)
    tempA = []
    tempA.append(minA)
    for row in A:
      wk = row % minA
      if wk > 0:tempA.append(wk)
    A = tempA
  print(A[0])
  
main()

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

while True:
    l = []
    for i in range(len(As)):
        if As[i] > smallest and As[i]%smallest > 0:
            l.append(As[i]%smallest)
        elif As[i]== smallest :
            l.append(As[i])
        
    if l == As:
        smallest = min(As)
        break
    else:
        As = l
        smallest = min(As)

print(smallest)

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


def euclid(v1, v2):
    if v2 == 0:
        return v1
    elif v1 > v2:
        return euclid(v2, v1 % v2)
    else:
        return euclid(v1, v2 % v1)


out = A[0]
for A_i in A[1:]:
    out = euclid(out, A_i)
print(out)

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

zombies = [int(c) for c in input().split()]


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


m = zombies[0]
for i in range(1, len(zombies)):
    m = gcd(m, zombies[i])

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)


def gcd_arr(a):
    ans = a[0]
    for i, a_i in enumerate(a):
        ans = gcd(ans, a_i)
    return ans

print(gcd_arr(A))

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

ans = 10 ** 10
while min(A) != ans:
    ans = min(A)
    for i, a_i in enumerate(A):
        if a_i > ans:
            A[i] = a_i % ans
            if A[i] == 0:
                del A[i]

print(ans)

Solution (Python):
input()

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

while len(A) != 1:
    A.sort()
    for i, a in enumerate(A):
        if i + 1 < len(A) and A[i + 1] >= a > 0:
            A[i + 1] %= a
    A = [a for a in A if a > 0]

print(min(A))

Solution (Python):
n = int(input())
hps = list(map(int, input().split()))
m = min(hps)
def gojo(a, b):
  if b == 0:
    return a
  else:
    return gojo(b, a % b)
res = m
for hp in hps:
  res = gojo(hp, res)
print(res)

Solution (Python):
n = int(input())
hps = list(map(int, input().split()))
m = min(hps)
def gojo(a, b):
  if b == 0:
    return a
  else:
    return gojo(b, a % b)
res = m
for hp in hps:
  res = gojo(max(res, hp),min(res, hp))
print(res)

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

Solution (Python):
class NC:
  """ 整数計算 """

  @staticmethod
  def gcd(x, y, *z):
    """ 最大公約数 """

    from fractions import gcd as _gcd

    if z:
      from functools import reduce
      return reduce(_gcd, (x, y) + z)
    else:
      return _gcd(x, y)

    @staticmethod
    def lcm(x, y, *z):
      """ 最小公倍数 """

      from fractions import gcd as _gcd

      def _lcm(a, b):
        return a * b // _gcd(a, b)
      if z:
        from functools import reduce
        return reduce(_lcm, (x, y) + z)
      else:
        return _lcm(x, y)
          
def main():
  _ = int(input())
  ts = list(map(int, input().split()))
  nc = NC()
  g = nc.gcd(*ts)
  print(g)
main()

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
min_ans=0
nxt=a
while len(nxt)!=0:
    min_ans=min(nxt)
    nxt=[]
    for v in a:
        if v%min_ans!=0:
            nxt.append(v%min_ans)
print(min_ans)

Solution (Python):


from fractions import gcd
from functools import reduce

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

print(reduce(gcd, A))

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

Solution (Python):


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


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


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

print(ans)

Solution (Python):
import fractions
from functools import reduce

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

print(reduce(fractions.gcd, As))

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


def mod_2(num,mod):
    a = num%mod 
    if a ==0:
        a = mod
    return a
m = min(A)
def min_mod(minimum,A_list):
    if all([A_list[j]==minimum for j in range(len(A_list))]):
        return minimum
        
    A_list = [mod_2(A_list[i],minimum) for i in range(len(A_list)) ]
    minimum = min(A_list)
    return min_mod(minimum,A_list)
    
print(min_mod(m,A))

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

while True:
    A.sort()
    B=[A[0]]


    for i in range(len(A)):
        b = A[i]%B[0]
        if b != 0:
            B.append(b)

    if len(B)==1:
        print(B[0])
        break
    else :
        A = B

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

a.sort()
a = np.array(a)
min_index = a.argmin()

while True:
    damaged = a % a[min_index]
    nonzero_index = damaged.nonzero()
    nonzero = damaged[nonzero_index]
    if nonzero.size == 0:
        break
    target = nonzero.argmin()
    min_index = nonzero_index[0][target]
    a[min_index] = nonzero[target]
print(a[min_index])

Solution (Python):

N=int(input())
A=sorted(map(int,input().split()))
while len(A) != 1:
	B_nonzeros=[A[0]]
	for n in range(len(A)):
		i = A[n]%A[0]
		if i != 0:
			B_nonzeros.append(i)
	B_nonzeros.sort()
	A=B_nonzeros
print(A[0])

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

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

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

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

def battle(s):
  tmp = [i for i in s if i > 0]
  if len(tmp) == 1:
    return tmp[0]
  p = min(tmp)
  f = False
  for i in range(N):
    if not f and s[i] == p:
      f = True
    else:
      s[i] = s[i] % p
  return battle(s)

print(battle(S))

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

while True:
    A = list(set(A))
    A.sort()
    if 0 in A:
        A.remove(0)
    if len(A) == 1:
        print(A[0])
        exit()

    A0 = A[0]
    i = 1
    for a in A[1:]:
        A[i] = a % A0
        i += 1

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

ans = 2 ** 30

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

tmp = A[0]
for a in A[1:]:
    tmp = GCD(a,tmp)
    
print(tmp)

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

ans = 2 ** 30

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

tmp = A[0]
for a in A[1:]:
    tmp = GCD(a,tmp)
    
print(tmp)

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


def gcd(n, m):
    if n < m:
        temp = n
        n = m
        m = temp
    
    def ecd(n, m):
        if n % m == 0:
            return m
        else:
            temp = n % m
            a = ecd(m, temp)
        return a
           
    return ecd(n, m)

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

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

As = sorted(A)
As = [a%As[0] if a%As[0] != 0 else As[0] for a in As]
As = sorted(As)

def judge(tmp_one, tmp_two):
    flg = 1

    while flg:
        if tmp_two%tmp_one == 0:
            tmp_two = tmp_one
        else:
            tmp_two = tmp_two%tmp_one

        if tmp_one%tmp_two == 0:
            tmp_one = tmp_two
        else:
            tmp_one = tmp_one%tmp_two
        if tmp_one == tmp_two:
            flg = 0

    return tmp_one

tmp_one = As[0]
for i in range(1, N):
    if i == N - 1:
        tmp_two = As[i]
    elif As[i] != As[0]:
        tmp_two = As[i]
        break

ans = judge(tmp_one, tmp_two)
print(ans)

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

n = int(input())
a = [int(i) for i in input().split()]
a.sort()
out = gcd(a[0], a[1])
for i in a[2:]:
    out = gcd(out, i)
print(out)

Solution (Python):
import fractions
from functools import reduce
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
print(gcd_list(A))

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

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

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

print(ans)

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

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

ans = alist[0]
for a in alist[1:]:
  if a <= ans:
    ans = gcd(ans, a)
  else:
    ans = gcd(a, ans)
print(ans)

Solution (Python):
from fractions import gcd

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

for i in k:
    ans = gcd(ans, i)

print(ans)

Solution (Python):
N=int(input())
A=[int(i) for i in input().split()]
def euclid(a,b):
  x=max(a,b)
  y=min(a,b)
  z=x%y
  if z!=0:
    return euclid(y,z)
  else:
    return y
g=euclid(A[0],A[1])
for i in range(2,len(A)):
  g=euclid(A[i],g)
print(g)

Solution (Python):
n=int(input())
l=list(map(int,input().split()))
ans=l[0]
for a in l:
  while a>0:
    ans%=a
    a,ans=ans,a
print(ans)

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


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


def list_lcm(number_list):
    lcm_number = 1
    for j in number_list:
        lcm_number = lcm(lcm_number, j)

    return lcm_number


def list_gcd(number_list):
    gcd_number = number_list[0]
    for i in number_list:
        gcd_number = gcd(gcd_number, i)

    return gcd_number


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

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

monsters = A[:]
while True:
    a_min = min(monsters)
    monsters = [m % a_min for m in monsters if m % a_min != 0]
    if len(monsters) == 0:
        print(a_min)
        break
    else:
        monsters.append(a_min)

Solution (Python):
import fractions
from functools import reduce

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

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

print(gcd(A))

Solution (Python):
import fractions
import functools


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

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

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

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

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

for i in range(1,N):
  GCD = alg_gcd(GCD,A[i])
print(GCD)

Solution (Python):
from fractions import gcd
from functools import reduce
def get_gcd(*numbers):
    return reduce(gcd, numbers)

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

Solution (Python):
import fractions

N =int(input())
lives = [int(i) for i in input().split()]
gcd_value = lives[0]

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

print(gcd_value)

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

m = min(A)

while True:
  flag = False
  temp = m
  for i in range(len(A)):
    if A[i] % m > 0 and (A[i] % m) < temp:
      temp = A[i] % m
      flag = True
  if flag == False:
    break
  else:
    m = temp
print(m)

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

min_idx = None
for i, a in enumerate(A):
    if min_idx is None or A[min_idx] > a:
        min_idx = i

while 1:
    next_min_idx = None

    for i, a in enumerate(A):
        if min_idx == i: continue
        A[i] = a % A[min_idx]

        if A[i] > 0:
            if next_min_idx is None or A[next_min_idx] > A[i]:
                next_min_idx = i

    if next_min_idx is None:
        print(A[min_idx])
        exit()

    min_idx = next_min_idx

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

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

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

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


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 solve(m_list):
    m_val = m_list[0]
    for i in m_list:
        m_val = min(m_val,gcd(m_val,i))
    return m_val

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

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

    ans = solve(m_list)
    print(ans)

main()

Solution (Python):
def solve(m_list):
    min_val = m_list[0]
    
    for m in m_list:
        min_val = min(min_val, gcd(min_val, m))
    return min_val


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


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

    ans = solve(m_list)
    print(ans)


main()

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

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

Solution (Python):

import sys


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


def solve(N: int, A: "List[int]"):
    lastGCD = A[0]
    for i in range(1, N):
        lastGCD = euclid_gcd(lastGCD, A[i])
    print(lastGCD)
    return



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

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

print(g)

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

for i in range(N-1):
    a = [A[i], A[i+1]]
    a.sort(reverse=True)
    while True:
        tmp = a[0] % a[1]
        if tmp == 0:
            A[i+1] = a[1]
            break
        a[0], a[1] = a[1], tmp

print(a[1])

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in a[1:]:
	if ans > i:
		ans,i=i,ans
	while i%ans!=0:
		i,ans=ans,i%ans
	if ans ==1:
		print(1)
		break
else:
	print(ans)

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

b = min(A)
for i in A:
    a = i
    while True:
        if a%b == 0:
            break
        a,b = b,a%b
print(b)

Solution (Python):
N = int(input())
a = list(map(int, input().split()))
b = [1] * N
c = min(a)

while max(b) != 0:
    for i in range(N):
        b[i] = a[i] % c
    for i in range(N):
        if b[i] != 0:
            c = min(c, b[i])
print(c)

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

ans = 10**10
for i in range(N-1):
    ans = min(ans, fractions.gcd(A[i],A[i+1]))
print(ans)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
m = 10**9
while m >0:
    for i in A:
        if i != 0 and i <= m:
            m = i
    A = [k%m for k in A]
    if max(A) == 0:
        break
    A += [m]
print(m)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
m = 10**9
while m >0:
    for i in A:
        if i != 0 and i <= m:
            m = i
    A = [k%m for k in A]
    if max(A) == 0:
        break
    A += [m]
print(m)

Solution (Python):
def maxDivisor(divisor, divided):
    '''最大公約数を返す関数'''
    while(True):
        rest = divided % divisor
        if rest == 0:
            return divisor
        else:
            divided = divisor
            divisor = rest


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

inf = 1 * 10**9
ans = inf
for i in range(len(A)):
    if i == len(A) - 1:
        break
    else:
        ans = min(ans, maxDivisor(A[i], A[i+1]))

print(ans)

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

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

a.sort(reverse=1)

aa = a[0]
for i in range(1, N):
    aa = gcd(aa, a[i])
    if aa == 1:
        break
print(aa)

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

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

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

ans = tmp
print(ans)

Solution (Python):
import fractions
import functools

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

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

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

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

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

for i in A[2:]:
    x = gcd(x,i)

print(x)

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

def gojo(num1, num2):
	if num2 > num1:
		num1, num2 = num2, num1
	if num2 == 0:
		return num1
	else:
		num3 = num1 % num2
		return gojo(num2, num3)
counter = gojo(a[0], a[1])
for i in range(n - 1):
	checker = gojo(a[i], a[i + 1])
	if checker < counter:
		counter = checker

print(counter)

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

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
        
x = gcd(A[0], A[1])
for i in range(2, N):
    x = gcd(x, A[i])

print(x)

Solution (Python):
import math
N = int(input())
values = [int(i) for i in input().split()]
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
c = values[0]
for i in range(N):
    c = gcd(c,values[i])
print(c)

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

def gcd(x,y):
    d = 0
    if max(x,y) == x:
        x,y = y,x
    while True:
        if y%x == 0:
            return x
        else:
            d = y%x
            y,x = x,d

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

Solution (Python):
n=int(input())
X=list(map(int,input().split()))
x=X[0]
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a


for i in range(1,n):
    x=gcd(x,X[i])
if x!=1:
    print(x)
else:
    print(1)

Solution (Python):
def euclid_devider(num_devided, num_devider):
    while num_devided % num_devider != 0:
        temp = num_devided % num_devider
        num_devided = num_devider
        num_devider = temp
    return num_devider

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

Solution (Python):
from fractions import gcd

N = int(input())

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

d = As[0]
for a in As[1:]:
    d = gcd(d, a)

print(d)

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


def solve(L):
    L.sort()
    j = 0
    while L[j] == 0:
        j += 1
    if j == N - 1 or L[j] == 1:
        return L[j]
    for i in range(j + 1, N):
        L[i] %= L[j]
    return solve(L)


print(solve(A))

Solution (Python):
import fractions as frac
from functools import reduce

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


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

print(gcd_list(A))

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

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

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

print(res)

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

N = int(input())
A = [int(i) for i in input().split()]
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(x, y):
    while y != 0:
        x, y = y, x % y

    return x


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

for e in a[2:]:
    ret = gcd(ret, e)

print(ret)

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

def gcd(tmp_1,tmp_2):
    if tmp_2 == 0:
        return tmp_1
    else:
        return gcd(tmp_2, tmp_1%tmp_2)

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

print(tmp_3)

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

Solution (Python):
from fractions import gcd

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

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

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

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

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

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

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

Solution (Python):

import sys
from bisect import bisect_right

def main():
	N = int(input())
	A = input().split(" ")
	A = [int(s) for s in A]
	
	A.sort()
	ai = -1
	tmp = -1
	for i in range(N-1):
		tmptmp = abs(A[i] - A[i+1])
		if tmptmp == 0:
			continue
		if tmp == -1 or tmp > tmptmp:
			tmp = tmptmp
			ai = i
			
	if tmp == -1:
		print(A[0])
		sys.exit()
		
	a = A[ai]		
	b = A[ai+1]
	
	while True:
		
		tmp_min = min(a, b)
		tmp_max = max(a, b)
		tmp = tmp_max % tmp_min
		if tmp == 0:
			print(tmp_min)
			sys.exit()
		else:
			if a < b:
				b = tmp
			else:
				a = tmp
	
if __name__ == "__main__":
	main()

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


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


print(gcd_list(a_li))

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

Solution (Python):
import fractions
import functools

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

Solution (Python):
from fractions import gcd 

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

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

print(G)

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


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


N = int(input())
A = [int(_) for _ in input().split()]
GCD = gcd(A[0], A[1])

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

print(GCD)

Solution (Python):


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

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

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

print(ans)

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

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




mina = 0
while(1):
    if(len(A)==1):break
    mina = min(A)
    minaind = A.index(mina)
    delind =[]
    for i in range(0,len(A)):
        
        if i == minaind:continue
        
        A[i]%=mina
        
    B=[]
    for i in range(0,len(A)):
        if(A[i]>0):
            B.append(A[i])
            
    A = B

print(A[0])

Solution (Python):
N = int(input())
A = list(map(int,input().split()))
A = sorted(A) 
tmp = 0
for i in range(N-1):
    while A[i]>0:
        tmp = A[i]
        A[i] = A[i+1] % A[i]
        A[i+1] = tmp
print(A[N-1])

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

Solution (Python):
def gcd(a,b):
    while b:
        a,b = b,a % b
    return a
def monsters(li,n):
    t = temp
    for i in range(n-1):
        t = gcd(li[i+1],t)
    return t

n = int(input())
li_a = list(map(int,input().split()))
temp = li_a[0]
print(monsters(li_a,n))

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

Solution (Python):
N = int(input())
L = list(map(int,input().split()))
L.sort()
def gcd(x,y):
  while y != 0:
    k = x
    x = y
    y = k%y
  return  x
cur = L[0]
for i in range(N):
  cur = gcd(cur,L[i])
print(cur)

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

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)
g = A[0]
for a in A[1:]:
  g = gcd(g, a)
print(g)

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

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

for i in range(1,n):
    monster[i] = gcd(monster[0], monster[i])

print(min(monster))

Solution (Python):

"""
C - Monsters Battle Royale
https://atcoder.jp/contests/abc118/tasks/abc118_c

"""
import sys


def solve(monsters):
    monsters = set(monsters)
    min_v = min(monsters)
    while len(monsters) > 1:
        monsters = set([m%min_v for m in monsters if m%min_v])
        monsters.add(min_v)
        min_v = min(monsters)
    return min(monsters)


def main(args):
    N = int(input())
    monsters = [int(m) for m in input().split()]
    ans = solve(monsters)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Solution (Python):

import sys

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

def solve(N: int, A: "List[int]"):
    A.sort()
    ret = A[0]
    for i in range(1, N):
        if A[i] % ret > 0:
            ret = gcd(ret, A[i])
    print(ret)
    return


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):
N = int(input())
monster = list(map(int, input().split()))
def gcd(a, b):
	if b > 0 :
		return gcd(b, a % b)
	else:
		return a
if len(monster) == 1 :
	print(monster[0])
else:
	mon = gcd(monster[0], monster[1])
	if len(monster) != 2 :
		for i in range(2, N) :
			mon = gcd(mon, monster[i])
print(mon)

Solution (Python):


import sys
input = sys.stdin.readline

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

first_gcd = A[0]
for i in range(len(A)):
    first_gcd = gcd(first_gcd, A[i])

print(first_gcd)

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

Solution (Python):
from functools import reduce

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


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

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