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



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


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

 


print(kari)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))   
if len(b)==1:
    print(b[0])
    exit()
else:
    c=sorted(b)
    x=1
    while x>0:
        v=c[0]
        for i in range(len(c)):
            if i!=0:
                c[i]=c[i]%v
        while 0 in c:
            c.remove(0)
        c=sorted(list(set(c)))
        if len(c)==1:
            print(c[0])
            exit()
        if c[0]==1:
            x=0
print(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())
a = list(map(int, input().split()))

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

print(b)

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

Solution (Python):

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

N = int(input())
aA = sorted(set(int(_) for _ in input().split()))
b = aA[0]
for a in aA[1:]:
    b = fgcd(a,b)
print(b)

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

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

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

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

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

Solution (Python):
import copy
N = int(input())
a = list(map(int,input().split()))
b = copy.deepcopy(a)
while max(a) != min(a):
    mina = min(a)
    for i in range(N):
        if a[i] % mina == 0:
            a[i] = mina
        else:
            a[i] = a[i] % mina
print(min(a))

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()]
m = min(A)
while m > 0:
    for i in range(0,len(A)):
        if A[i] != m:
            A[i] = A[i]%m
    z = A.count(0)
    A = sorted(A)[z:]
    m = A[0]
    if m == 1:
        break
    else:
        if [_%m for _ in A] == [0]*len(A):
            break
print(m)

Solution (Python):
n = int(input())
x = 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)

while len(x) > 1:
    i = 0
    next = []
    while i < len(x) - 1:
        next.append(gcd(x[i], x[i+1]))
        i += 2

    x = [] + next

print(x[0])

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

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


def gcd_multi(*numbers):
    return reduce(gcd, numbers)


print(gcd_multi(*monsters))

Solution (Python):
import fractions
from functools import reduce

def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
n = int(input())
listA=list(map(int, input().split()))
print(gcd_list(listA))

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


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

cand = A[0]

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

    if cand == 1:
        break

print(cand)

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




def check(a,b):
  while True:
    r = b % a
    if r != 0:

      
      b = a
      a = r
    else:
      res = a
      
      break

  
  return res

mval = -1
for i in range(N-1):
  a,b=p[i],p[1]
  m = check(a,b)
  if mval == -1:
    mval = m
  else:
    if m < mval:
      mval = m
      
print(mval)

Solution (Python):

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


def LCM(a, b):
    a, b = max(a, b), min(a, b)
    while True:
        a, b = b, a % b
        if b == 0:
            break
    return a
res = A_list[0]
for i in range(N):
    res = LCM(res, A_list[i])
print(res)

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

Solution (Python):
import fractions
from functools import reduce

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

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

print(gcd_list(A))

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

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

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

print(a)

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

def GCD(x,y):
    x,y=min(x,y),max(x,y)
    if y%x==0: return x
    return GCD(y%x,x)
ans=A[0]
for a in A[1:]:
    ans = GCD(ans,a)
print(ans)

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

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

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

print(ans)

Solution (Python):
from fractions import gcd 

n = int(input())
a_set = set(map(int, input().split()))
max_a = max(a_set)
min_sub = max_a

for val in a_set:
    min_sub = min(gcd(max_a, val), min_sub)
    if min_sub == 1:
        print(1)
        exit()
print(min_sub)

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

Solution (Python):
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
list = [min(A)]
A = sorted(A)
iii = 0
while True:
    iii += 1
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
    elif N >= 3 and A[N-1] % A[N-3] != 0:
        A[N-1] = A[N-1] % A[N-3]

    A = sorted(A)
    list.append(min(A))
    if iii > 32:
        break       

for i in range(N-1):
    if A[i+1]-A[i] > 0:
        list.append(A[i+1]-A[i])

print(min(list))

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

Solution (Python):


import sys


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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x) - 1 for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def II(): return int(sys.stdin.readline())
def SI(): return input()



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


n = II()
A = LI()

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

print(ans)

Solution (Python):
import fractions
from functools import reduce

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

print(reduce(fractions.gcd, al))

Solution (Python):

import sys

import heapq
import re
import bisect
import random
import math
import fractions
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *
 
n = int(input())
a = list(map(int, input().split()))
a = deque(sorted(a))
ans = 0
for i in a:
    ans = fractions.gcd(ans, i)
print(ans)

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

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

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

print(a)

Solution (Python):
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
list = [min(A)]
A = sorted(A)
iii = 0
while True:
    iii += 1
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
    elif N >= 3 and A[N-1] % A[N-3] != 0:
        A[N-1] = A[N-1] % A[N-3]
    elif N >= 4 and A[N-1] % A[N-4] != 0:
        A[N-1] = A[N-1] % A[N-4]
    elif N >= 5 and A[N-1] % A[N-5] != 0:
        A[N-1] = A[N-1] % A[N-5]

    A = sorted(A)
    list.append(min(A))
    if iii > 64:
        break       

for i in range(N-1):
    if A[i+1]-A[i] > 0:
        list.append(A[i+1]-A[i])

print(min(list))

Solution (Python):
n = int(input())
b = list(map(int,input().split()))
b.sort()
     
d = b[0] + 0
 
while len(b) > 1 :
    for i in range(1,len(b)) :
        b[i] = b[i] % b[0]
    if b.count(0) == len(b)-1 :
        d = b[0]
        break
    else :
        b.sort()
        for j in range(b.count(0)) :
            b.remove(0)
print(d)

Solution (Python):
import numpy as np

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

A=np.sort(A)
s=A[0]
for i in range(max([n, s])):
    c = A[0]
    A = A % c
    A[0] = c
    z=len(A) - np.count_nonzero(A)
    A=np.sort(A)[z:]
    if len(A) == 1:
        break
print (A[0])

Solution (Python):
input()
A=set(map(int,input().split()))
R=max(A)
while 1:
 r=min(A)
 if r==R:break
 A=set(i%r for i in A)-{0}|{r};R=r
print(R)

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

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


ans = 0
for ai in a:
    ans = gcd(ans, ai)

print(ans)

Solution (Python):
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
list = [min(A)]
A = sorted(A)
iii = 0
while True:
    iii += 1
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
    elif N >= 3 and A[N-1] % A[N-3] != 0:
        A[N-1] = A[N-1] % A[N-3]
    elif N >= 4 and A[N-1] % A[N-4] != 0:
        A[N-1] = A[N-1] % A[N-4]
    elif N >= 5 and A[N-1] % A[N-5] != 0:
        A[N-1] = A[N-1] % A[N-5]
    elif N >= 6 and A[N-1] % A[N-6] != 0:
        A[N-1] = A[N-1] % A[N-6]
    elif N >= 7 and A[N-1] % A[N-7] != 0:
        A[N-1] = A[N-1] % A[N-7]
    elif N >= 8 and A[N-1] % A[N-8] != 0:
        A[N-1] = A[N-1] % A[N-8]
    elif N >= 9 and A[N-1] % A[N-9] != 0:
        A[N-1] = A[N-1] % A[N-9]
    elif N >= 10 and A[N-1] % A[N-10] != 0:
        A[N-1] = A[N-1] % A[N-10]

    A = sorted(A)
    list.append(min(A))
    if iii > 96:
        break       

for i in range(N-1):
    if A[i+1]-A[i] > 0:
        list.append(A[i+1]-A[i])

print(min(list))

Solution (Python):

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

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

N = len(a_list)
min_last_hp = 10**10

f = min(a_list)
a_list.remove(f)

for i in a_list:
    last_hp = gcd(f, i)
    if last_hp < min_last_hp:
        min_last_hp = last_hp

s = min(a_list)
kouho=gcd(f,s)
if kouho < min_last_hp:
    print(kouho)
else:
    print(min_last_hp)

Solution (Python):
N = int(input())
A = [int(_) for _ in input().split()]
m = min(A)
while m > 0:
    for i in range(0,len(A)):
        if A[i] != m:
            A[i] = A[i]%m
    z = A.count(0)
    A = sorted(A)[z:]
    m = A[0]
    if m == 1:
        break
    else:
        if [_%m for _ in A] == [0]*len(A):
            break
print(m)

Solution (Python):
from fractions import gcd
print [input(),reduce(gcd,map(int,raw_input().split()))][1]

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

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

Alive = 0

for a in A:
	if a != 0:
		Alive += 1

while Alive > 1:
	for j in range(N):
		prevaj = A[j]
		if A[j] != 0:
			for k in range(N):
				A[k] = A[k] % A[j]
				A[j] = prevaj
	Alive = 0
	for a in A:
		if a != 0:
			Alive += 1


print(sum(A))

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

a = list(set(a))
a.sort()
while len(a) > 1:
    while (a[0] < a[1]):
        a[1] %= a[0]
    x = a[1]
    a[1] = a[0]
    a[0] = x
    if a[0] == 0:
        a.pop(0)
    if a[0] == 1:
        break
print(a[0])

Solution (Python):
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
list = [min(A)]
A = sorted(A)
iii = 0
while True:
    iii += 1
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
    elif N >= 3 and A[N-1] % A[N-3] != 0:
        A[N-1] = A[N-1] % A[N-3]
    elif N >= 4 and A[N-1] % A[N-4] != 0:
        A[N-1] = A[N-1] % A[N-4]
    elif N >= 5 and A[N-1] % A[N-5] != 0:
        A[N-1] = A[N-1] % A[N-5]
    elif N >= 6 and A[N-1] % A[N-6] != 0:
        A[N-1] = A[N-1] % A[N-6]
    elif N >= 7 and A[N-1] % A[N-7] != 0:
        A[N-1] = A[N-1] % A[N-7]
    elif N >= 8 and A[N-1] % A[N-8] != 0:
        A[N-1] = A[N-1] % A[N-8]
    elif N >= 9 and A[N-1] % A[N-9] != 0:
        A[N-1] = A[N-1] % A[N-9]
    elif N >= 10 and A[N-1] % A[N-10] != 0:
        A[N-1] = A[N-1] % A[N-10]
    elif N >= 11 and A[N-1] % A[N-11] != 0:
        A[N-1] = A[N-1] % A[N-11]
    elif N >= 12 and A[N-1] % A[N-12] != 0:
        A[N-1] = A[N-1] % A[N-12]
    elif N >= 13 and A[N-1] % A[N-13] != 0:
        A[N-1] = A[N-1] % A[N-13]
    elif N >= 14 and A[N-1] % A[N-14] != 0:
        A[N-1] = A[N-1] % A[N-14]
    elif N >= 15 and A[N-1] % A[N-15] != 0:
        A[N-1] = A[N-1] % A[N-15]
    elif N >= 16 and A[N-1] % A[N-16] != 0:
        A[N-1] = A[N-1] % A[N-16]
    elif N >= 17 and A[N-1] % A[N-17] != 0:
        A[N-1] = A[N-1] % A[N-17]
    elif N >= 18 and A[N-1] % A[N-18] != 0:
        A[N-1] = A[N-1] % A[N-18]
    elif N >= 19 and A[N-1] % A[N-19] != 0:
        A[N-1] = A[N-1] % A[N-19]

    A = sorted(A)
    list.append(min(A))
    if iii > 128:
        break       

for i in range(N-1):
    if A[i+1]-A[i] > 0:
        list.append(A[i+1]-A[i])

print(min(list))

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

Q = np.array(A)
an = 1
def toku(Q):
    mi = min(Q)
    R1 = Q % mi
    if any(R1) == 0:
        flag = 1
        an = mi
        return flag, an, R1
    else:
        flag = 0
        an = 1
        ind = np.argmin(Q)
        R1[ind] = mi
        R = R1[R1!=0]
        return flag, an, R

while flag == 0:
    flag,an,PP = toku(Q)
    Q = PP

print(an)

Solution (Python):
N=int(input())
a_list=[]
a_list = list(map(int, input().split())) 
min_num=min(a_list)
nokori_list=[i%min_num for i in a_list if i%min_num!=0]
if len(nokori_list)==0:
    print(min_num)
else:    
    while len(nokori_list)!=0:
        if len(nokori_list)==0:
            answer=min_num
            break
        else:
            nokori_list.append(min_num)
            min_num=min(nokori_list)
            new_list=[i%min_num for i in nokori_list if i%min_num!=0]
            nokori_list=new_list
        answer=min_num
    print(answer)

Solution (Python):
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
list = [min(A)]
A = sorted(A)
iii = 0
while True:
    iii += 1
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
    elif N >= 3 and A[N-1] % A[N-3] != 0:
        A[N-1] = A[N-1] % A[N-3]
    elif N >= 4 and A[N-1] % A[N-4] != 0:
        A[N-1] = A[N-1] % A[N-4]
    elif N >= 5 and A[N-1] % A[N-5] != 0:
        A[N-1] = A[N-1] % A[N-5]
    elif N >= 6 and A[N-1] % A[N-6] != 0:
        A[N-1] = A[N-1] % A[N-6]
    elif N >= 7 and A[N-1] % A[N-7] != 0:
        A[N-1] = A[N-1] % A[N-7]
    elif N >= 8 and A[N-1] % A[N-8] != 0:
        A[N-1] = A[N-1] % A[N-8]
    elif N >= 9 and A[N-1] % A[N-9] != 0:
        A[N-1] = A[N-1] % A[N-9]
    elif N >= 10 and A[N-1] % A[N-10] != 0:
        A[N-1] = A[N-1] % A[N-10]
    elif N >= 11 and A[N-1] % A[N-11] != 0:
        A[N-1] = A[N-1] % A[N-11]
    elif N >= 12 and A[N-1] % A[N-12] != 0:
        A[N-1] = A[N-1] % A[N-12]
    elif N >= 13 and A[N-1] % A[N-13] != 0:
        A[N-1] = A[N-1] % A[N-13]
    elif N >= 14 and A[N-1] % A[N-14] != 0:
        A[N-1] = A[N-1] % A[N-14]
    elif N >= 15 and A[N-1] % A[N-15] != 0:
        A[N-1] = A[N-1] % A[N-15]
    elif N >= 16 and A[N-1] % A[N-16] != 0:
        A[N-1] = A[N-1] % A[N-16]
    elif N >= 17 and A[N-1] % A[N-17] != 0:
        A[N-1] = A[N-1] % A[N-17]
    elif N >= 18 and A[N-1] % A[N-18] != 0:
        A[N-1] = A[N-1] % A[N-18]
    elif N >= 19 and A[N-1] % A[N-19] != 0:
        A[N-1] = A[N-1] % A[N-19]
    elif N >= 20 and A[N-1] % A[N-20] != 0:
        A[N-1] = A[N-1] % A[N-20]
    elif N >= 21 and A[N-1] % A[N-21] != 0:
        A[N-1] = A[N-1] % A[N-21]
    elif N >= 22 and A[N-1] % A[N-22] != 0:
        A[N-1] = A[N-1] % A[N-22]
    elif N >= 23 and A[N-1] % A[N-23] != 0:
        A[N-1] = A[N-1] % A[N-23]
    elif N >= 24 and A[N-1] % A[N-24] != 0:
        A[N-1] = A[N-1] % A[N-24]
    elif N >= 25 and A[N-1] % A[N-25] != 0:
        A[N-1] = A[N-1] % A[N-25]
    elif N >= 26 and A[N-1] % A[N-26] != 0:
        A[N-1] = A[N-1] % A[N-26]
    elif N >= 27 and A[N-1] % A[N-27] != 0:
        A[N-1] = A[N-1] % A[N-27]
    elif N >= 28 and A[N-1] % A[N-28] != 0:
        A[N-1] = A[N-1] % A[N-28]
    elif N >= 29 and A[N-1] % A[N-29] != 0:
        A[N-1] = A[N-1] % A[N-25]
    elif N >= 30 and A[N-1] % A[N-30] != 0:
        A[N-1] = A[N-1] % A[N-30]
    elif N >= 31 and A[N-1] % A[N-31] != 0:
        A[N-1] = A[N-1] % A[N-31]
    elif N >= 32 and A[N-1] % A[N-32] != 0:
        A[N-1] = A[N-1] % A[N-32]
    elif N >= 33 and A[N-1] % A[N-33] != 0:
        A[N-1] = A[N-1] % A[N-33]
    elif N >= 34 and A[N-1] % A[N-34] != 0:
        A[N-1] = A[N-1] % A[N-34]
    elif N >= 35 and A[N-1] % A[N-35] != 0:
        A[N-1] = A[N-1] % A[N-35]
    elif N >= 36 and A[N-1] % A[N-36] != 0:
        A[N-1] = A[N-1] % A[N-36]
    A = sorted(A)
    list.append(min(A))
    if iii > 128:
        break       

for i in range(N-1):
    if A[i+1]-A[i] > 0:
        list.append(A[i+1]-A[i])

print(min(list))

Solution (Python):
import fractions

N = int(input())
Ai = list(map(int, input().split()))
if Ai == [Ai[0]] * len(Ai):
    print(Ai[0])
    quit()



i = 1
min = 1000000000
a = Ai[0]
for a2 in Ai[1:]:
    a_gcd = fractions.gcd(a, a2)
    if min > a_gcd:
        min = a_gcd
        if min <= 2:
            print(min)
            quit()

print(min)

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

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

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

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

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

while True:
    a.sort()
    if max(a) == 1 or a[n-2] == 0:
        break
    for i in a:
        if i != 0:
            t = a.index(i)
            break

    for i in range(n):
        if i == t:
            continue
        a[i] = a[i] % a[t]

print(max(a))

Solution (Python):
import numpy as np
i = input()
N = list(set(map(int, input().split(' '))))
def one_turn(l):
  l.sort()
  n = l[0]
  return np.array(list(set([n]+[ l[i]%n for i in range(1,len(l)) if ((l[i]%n != 0))])))

if len(set(N)) == 1 :
  print(N[0])
else :
  N = np.array(N)
  while True :
    N = one_turn(N)
    if N[0] == 1 :
      print(1)
      break
    if len(N) == 1 :
      print(N[0])
      break

Solution (Python):
import numpy as np

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

tmp = A
t_min = min(A)
while True:
    tmp = A % t_min
    if sum(tmp) == 0:
        break
    t_min = min(tmp[tmp > 0])

print(t_min)

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

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

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

A.sort(reverse=True)

denominator = 0
numerator = 1
while A[numerator] != 0:
    A[denominator] = A[denominator] % A[numerator]
    if A[denominator] == 0:
        denominator += 1
        numerator += 1
        if denominator >= N or numerator >= N:
            break
    else:
        denominator, numerator = numerator, denominator
print(min([a for a in A if a > 0]))

Solution (Python):
s = input()
m = list(map(int, input().split()))

while True:
    minimum = min(m)
    temp_m = [i % minimum for i in m if i % minimum != 0]
    if len(temp_m) == 0:
        ans = minimum
        break
    m = temp_m + [minimum]
        
print(ans)

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

b = a.copy()
d = b[0] + 0

while len(b) > 1 :

    for i in range(1,len(b)) :
        b[i] = b[i] % b[0]

    if b.count(0) == len(b)-1 :
        d = b[0]
        break
    else :
        b.sort()
        for j in range(b.count(0)) :
            b.remove(0)

print(d)

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 = input()
A = input().split()
for i in range(len(A)):
    A[i] = int(A[i])
answer = gcd_list(A)
print("{}".format(answer))

Solution (Python):
n=int(input())
a=list(map(int,input().strip().split()))
min1=min(a)
min2=min1

for i in a:
    amari=i%min1
    if amari!=0:
        if amari<min1:
            min1=amari
lop=True
while lop:
    if min1==min2:
        ans=min1
        lop=False
    elif min1<min2:
        min2=min2%min1
        if min2==0:
            ans=min1
            lop=False
    elif min1>min2:
        min1=min1%min2
        if min1==0:
            ans=min2
            lop=False
print(ans)

Solution (Python):

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

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

for i in k:
    c=regcd(max(c,i),min(c,i))

    
print(c)

Solution (Python):



def main():
    n = int(input())
    a = sorted(list(map(int, input().split())))
    mod_a = a
    mod = min(a)
    index = 0

    while True:
        for idx, ai in enumerate(a):
            if idx != index:
                mod_a[idx] %= mod

                if 0 < mod_a[idx] < mod:
                    mod = mod_a[idx]
                    index = idx

        if mod_a.count(0) >= n - 1:
            break

    print(max(min(a), max(mod_a)))


if __name__ == '__main__':
    main()

Solution (Python):
n = int(input())
mon = list(map(int, input().split()))
g = min(mon)
div = []
for i in range(1, g + 1):
  if (g % i == 0):
    div.append(i)
    div.append(g // i)
  if (i * i > g):
    break
div.sort(reverse=True)
for d in div:
  mod = []
  for m in mon:
    mod.append(m % d)
  if (list(set(mod)) == [0]):
    print(d)
    break

Solution (Python):
def saigo(data):
	count = 0
	for d in data:
		if d == 0:
			count += 1
	return count == len(data)-1

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


while(saigo(data) == False):
	min_val = 10e9
	min_idx = 0
	for i,d in enumerate(data):
		if min_val > d and d != 0:
			min_val = d
			min_idx = i
	for i in range(n):
		if i != min_idx:
			data[i] = data[i] % min_val

for i,d in enumerate(data):
	if d != 0:
		print(d)

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

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

p = None
for i in range(N):
    m = A[i]

    if p == None:
        p = m
        continue

    p = f(p, m)
    




print(p)

Solution (Python):
import numpy as np

N = int(input())

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

min_amari = min(A)
while 0==0:
  amari = A%min_amari
  amari = amari[amari!=0]
  if len(amari)==0:
    print(min_amari)
    break
  else:
    min_amari = min(amari)

Solution (Python):
N = int(input())
A = list(map(int, input().split()))
A.sort()
m = A[0]
A = A[1:]
while True:
  l = len(A)
  A = [A[i]%m for i in range(l) if A[i]%m != 0]
  A.append(m)
  A.sort()
  m = A[0]
  A = A[1:]
  if A == []:
    break
print(m)

Solution (Python):
from functools import reduce
def g(a,b):
	return g(b,a%b) if b else a
print((lambda n,a:reduce(g,a))(int(input()),list(map(int,input().split()))))

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

a.sort()

while True:
    for i in range(n):
        if i == 0:
            continue
        else:
            a[i] %= a[0]
    a.sort()
    t = 0
    for t in range(n):
        if a[t]!=0:
            break
    a = a[t:]
    n = len(a)
    if n==1:
        break;
print(a[n-1])

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

def gcd(X):
    if len(X) == 1:
        return X[0]
    X.sort()
    residue = set(map(lambda x: x % X[0], X[1:]))
    if 0 in residue:
        residue.remove(0)

    if len(residue) == 0:
        return X[0]
    elif len(residue) == 1:
        return gcd([X[0], residue.pop()])
    return gcd(list(residue))

print(gcd(A))

Solution (Python):
"""
Monsters Battle Royale
"""


def solve():
    pass
    '''データインプット'''
    monster_num = int(input())
    monster_hp = [int(i) for i in input().split()]
    '''れっつろわいある'''
    while True:
        
        minmum = min(monster_hp)
        
        monster_hp = [i % minmum for i in monster_hp]
        monster_hp = [i for i in monster_hp if i != 0]
        
        if sum(monster_hp) == 0:
            break
        else:
            monster_hp.append(minmum)
    print(minmum)


if __name__ == '__main__':
    solve()

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

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

ans=f(a[1],a[0])

for i in range(2,len(a)):
    ans=f(a[i],ans)
    
print(ans)

Solution (Python):
import numpy as np
N = int(input())
lst=input().split(" ")

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

for i in range(N-1):
    lst[i+1]= gojo(int(lst[i]),int(lst[i+1]))
    
print(lst[N-1])

Solution (Python):
import numpy as np
N = int(input())
list_A = list(map(int,input().split()))
for _ in range(100):
    min_A = min(list_A)
    list_A.remove(min_A)
    l = np.array([list_A]) % min_A
    lr = list(l.ravel())
    lr.append(min_A)
    list_A = [x for x in lr if x != 0]
    if len(list_A) <= 1:
        break
print(list_A[0])

Solution (Python):
from itertools import accumulate
from sys import stdin

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

    a = sorted(A)
    while 1:
        ans = a[0]
        a = [i % ans for i in a]
        a[0] = ans
        if len(a) == 1:
            break
        a = [i for i in a if i > 0]
        a.sort()
    print(ans)

input = lambda: stdin.readline()
main()

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 x in a:
    ans = gcd(x,ans)
print(ans)

Solution (Python):
import fractions
from functools import reduce

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

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

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

print(gcd_list(A))

Solution (Python):
import sys

def parse(inp):
    N=int(next(inp).split()[0])
    A=list(map(int,next(inp).split()))
    
    return N,A

def gcd(a,b):
    if(b==0): return a
    return gcd(b,a%b)
  
def main(inp):
    N,A=parse(inp)
    
    for i in range(len(A)-1):
        A[1]=gcd(A[0],A[1])
        del A[0]
        
    return A[0]

  
print(main(sys.stdin))

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

while len(HPs) > 1:
    HPs.sort()
    for i in range(len(HPs)-1):
        HPs[i+1] = HPs[i+1] % HPs[0]
    while 0 in HPs:
        HPs.remove(0)

print(HPs[0])

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

while True:
    if len(A) == 1:
        break
    pop_i = []
    A.sort()
    for i in range(1, len(A)):
        life = A[i] % A[0]
        if life == 1:
            print(life)
            exit()
        else:
            A[i] = life
    A = [n for n in A if n > 0]

print(A[0])

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


while(1):
    count=0
    mina=1000000000+1
    for j in range(len(a)):
        if mina>a[j] and a[j]!=0:
            mina=a[j]
            

    for i in range(len(a)):
        if a[i]==mina and count==0:
            count+=1
        else:
            a[i]=a[i]%mina
    
    maxa=max(a)
    if sum(a)==maxa:
        print(maxa)
        break

Solution (Python):
import numpy as np
N = int(input())
A = list(map(int,input().split()))
A.sort()
lenA = len(A)
while(True):
    minA = 1000000001
    for i in range(lenA):
        if A[i] != 0:
            if minA > A[i]:
                minA = A[i]
                idx = i

    for i in range(lenA):
        if i != idx:
            A[i] %= minA
    
    if A.count(0) == N-1:
        break

A.sort()
print(A[-1])

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

while 1:
  pick = min(temp)
  diff = list(filter(lambda x: 0 < x, map(lambda x: x % pick, temp)))

  if len(diff) == 0:
    print(pick)
    break

  diff.append(pick)
  temp = diff

Solution (Python):
n = int(input())
a = sorted(list(map(int, input().split())))
while True:
    a = sorted(list(set(a)))
    tmp = sorted(a[:])
    for i in tmp:
        if i == a[0]:
            continue
        elif i % a[0] == 0:
            a.remove(i)
        else:
            a.append(i % a[0])
            if i % a[0] == 1:
                print(1)
                exit()
            a.remove(i)
    if len(a) == 1:
        break
print(a[0])

Solution (Python):
import numpy as np
import fractions
from functools import reduce
from sys import stdin
N=int(stdin.readline().rstrip())
data=[int(x) for x in stdin.readline().rstrip().split()]
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

if len(set(data))==1 or len(data)==1:
    print(data[0])
else:
    print(gcd_list(data))

Solution (Python):
from fractions import gcd

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

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

print(b)

Solution (Python):

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

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

max_gcd = L[0]

for i in range(1, N):
    max_gcd = gcd(max_gcd, L[i])

print(max_gcd)