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 roop_punch(list,num):
    while 1:
        list.sort()
        list=[i for i in list if i>0]
        min_hp=min(list)
        min_index=list.index(min(list))
        for x in range(len(list)):
            if x==0:
                continue
            if list[x]/min_hp>0:
                list[x]=list[x]%min_hp
            else:
                list[x]-min_hp
        if min(list)==max(list):
            break
    return min(list)
a =int(input())
input_list = list(map(int, input().split()))
s=roop_punch(input_list,a)
print(s)

Solution (Python):
import numpy as np

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

m = min(arr)
mi = np.argmin(arr)

while m != sum(arr):
  tmp = []
  for i, a in enumerate(arr):
    if mi == i:
      tmp.append(a)
    elif a%m != 0:
      tmp.append(a%m)
  arr = tmp
  m = min(arr)
  mi = np.argmin(arr)
print(m)

Solution (Python):
import numpy as np
N = int(input())
A = np.array(list(map(int,input().split())))
while len(A) > 1:
    min_A = min(A)
    A = A%min_A
    A = A[A>0]
    A = np.append(A,[min_A])
    answer = min_A
    if answer == 1:
        break
print(min_A)

Solution (Python):
from functools import reduce
n = int(input())
a = [int(m) for m in input().split()]
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b, a % b)
def gcd_list(numbers):
    return reduce(gcd, numbers)
a.sort()
new = [a[0]]
for i in range(1, n):
    new.append(a[i] % a[0])

new.sort()

k = gcd_list(new)
for i in range(n):
    if new[i] % k != 0:
        print(1)
        exit()
print(gcd_list(new))

Solution (Python):
def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z
def gcd_list(l):
    g = l[0]
    for i in l[1:]:
        g = gcd(g,i)


    return g
    
N = int(input())
A_list = [int(i) for i in input().split()]
ans = gcd_list(A_list)
print(ans)

Solution (Python):

import sys





"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        
        
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def d(self, p):
        re = 0
        for i in range(len(p) - 1):
            re += ((p[i][0] - p[i + 1][0]) ** 2 + (p[i][1] - p[i + 1][1]) ** 2) ** 0.5
        return re

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


"""ここからメインコード"""


def main():
    
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n = ip.I()
    a = ip.IL()
    res = max(a)

    for i in r(n):
        res = min(res, id.gcd(a[0], a[i]))

    print(res)


main()

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

mm = 0
while len(monsters) != 1:
    monsters.sort()
    mm = monsters[0]
    monsters = list(map(lambda x:x % mm, monsters))
    monsters[0] = mm
    monsters = list(filter(lambda x:x != 0, monsters))
print(mm)

Solution (Python):
def roop_punch(list,num):
    while 1:
        list.sort()
        list=[i for i in list if i>0]
        
        min_hp=min(list)
        min_index=list.index(min(list))
        for x in range(len(list)):
            if x==0:
                continue
            if list[x]/min_hp>0:
                list[x]=list[x]%min_hp
            else:
                list[x]-min_hp
        if min(list)==max(list):
            break

    return min(list)



a =int(input())

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

s=roop_punch(input_list,a)

print(s)

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

while len(l) > 1:
  for i in range(1,len(l)):
    l[i] = l[i] % l[0]
  while 0 in l:
    l.remove(0)
  l.sort()
print(l[0])

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


flag = True

while flag:
    flag = False
    minVal = min(A)
    

    for i in range(len(A)):
        x = A[i] % minVal
        if x != 0:
            A[i] = x
            flag = True

    

print(minVal)

Solution (Python):

import sys



def solve(lines):
    N = int(lines.pop(0))
    A = list(map(int, lines.pop(0).split(' ')))
    A.sort()
    min_a = A.pop(0)
    while(len(A) > 0):
        x = A.pop(0)
        y = x % min_a
        if y != 0:
            A.append(y)
        if y != 0 and min_a > y:
            A.append(min_a)
            min_a = y
    print(min_a)






lines = [x.strip() for x in sys.stdin.readlines()]




solve(lines)

Solution (Python):
N = int(input()) 
l = list(map(int,input().split()))
mini = max(l) +1
mini_idx = N+1
while mini != sum(l):
    for i, point in enumerate(l):
        if point < mini and point != 0:
            mini = point
            mini_idx = i

    for i, point in enumerate(l):
        if mini_idx != i:
            l[i] = l[i] % mini
print(mini)

Solution (Python):
n=int(input())
a=list(map(int,input().split()))
b=[a[0]]
def sks(a,b):
    if a == 0 or b == 0:
        return(max(a,b))
    else:
        c = min(a,b)
        d = max(a,b)
        return sks(c,d%c)
for i in range(n-1):
    b.append(sks(b[i],a[i+1]))
print(b[n-1])

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

n = int(input())
enemy = list(set(map(int,input().split())))
if len(enemy)==1:
    print(enemy[0])
else:
    enemy.sort()
    min_n = 10**10
    for i in range(len(enemy)-1):
        min_n = min(min_n,gcd(enemy[i],enemy[i+1]))
    print(min_n)

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

Solution (Python):


from fractions import gcd
from functools import reduce

N = int(input())
nums = sorted(list(map(int, input().split())), reverse=True)








def find_gcd(ls):
    x = reduce(gcd, ls)
    return x

def main():
    print(find_gcd(nums))
    return 0

if __name__ == "__main__":
    main()

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

monster = a[0]

while True:
    last = a.pop()
    attacked = last % monster
    if attacked == 0:
        pass
    elif attacked < monster:
        monster = attacked
        a.insert(0, attacked)

    if len(a) == 1:
        print(a[0])
        break

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

minHP = Mons[0]

if minHP == 1 or len(Mons) == 1:
    print(minHP)
    exit()
    
minSA = minHP

for a,b in zip(Mons[:],Mons[1:]):
    sa = b % a
    if sa and sa < minSA:
        minSA = sa

ans = minSA

while 1:
    hoge = [val % ans for val in Mons if val % ans]

    if hoge:
        if ans == min(hoge):
            break
        else:
            ans = min(hoge)
    else:
        break

print(ans)

Solution (Python):
n = int(input())
a = list(map(int, input().split()))
a.sort()
while len(a) >= 2 :
    k = a[1] % a[0]
    if k == 0 :
        a.pop(1)
    else :
        a[1] = k
        a[0], a[1] = a[1], a[0]
print(a[0])

Solution (Python):
n = input()

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


ans = 0
while True:
    
    if len(A)==1:
        break
    A.sort()

    c = 0
    for i in range(1, len(A)):
        
        res = A[i]% A[0]
        if res == 0:
            c+=1
        A[i]=res
    for i in range(c):
        A.remove(0)

print(A[0])

Solution (Python):
N = int(input())
l = list(map(int,input().split()))
def GCD(a,b): 
	x = max(a,b)
	y = min(a,b)
	if x % y == 0:
		return y
	else:
		while x % y != 0:
			z = x % y
			x = y
			y = z
		else:
			return y


ans = l[0]
for i in range(N):
	ans=GCD(ans,l[i])
print(ans)

Solution (Python):
j=input()
mst_str=input().split()
mst=list(map(int, mst_str))
n=len(mst)

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

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

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

A.sort()

num = 0

if N == A.count(A[0]):
    num = 1
else:
    l = A
    x = []

    while True:
        x = []
        x.append(l[0])
        for i in range(1, len(l)):
            if 0 < l[i] % l[0]:
                x.append(l[i] % l[0])

        if len(x) == 1:
            break

        x.sort()

        l = x

print(A[0] if num == 1 else x[0])

Solution (Python):

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

while len(A) >= 2:
    idx = A.index(min(A))
    x = A.pop(idx)
    B = list()
    for i in range(len(A)):
        if A[i] % x != 0:
            B.append(A[i] % x)
    B.append(x)
    A = B[:]

print(A[0])

Solution (Python):


n=int(input())
a = list(map(int, input().split()))
a.sort()
r=a.pop(0)
while len(a)>0:
  x = a.pop(0)
  if x%r!=0:
    a.append(r)
    a.append(x%r)
    a.sort()
    r=a.pop(0)
    
    

print(r)

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


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

Solution (Python):
import sys

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

a.sort()
answer = a[0]
for i in range(1, n):
    if a[i] % a[0] == 0: continue

    x, y = a[0], a[i] 
    while x != 0:
        x, y = y % x, x
    answer = min(answer, y)

print(answer)

Solution (Python):
import sys
stdin = sys.stdin
def li(): return map(int, stdin.readline().split())
N = li()
A = list(li())

def gcd(A, B):

    
    while B not in (1, 0):
        A, B = (A, B) if A > B else (B, A)
        _, mod = divmod(A, B)
        A, B = B, mod
    if B == 0:
        return A
    elif B == 1:
        return 1

A = list(filter(lambda x:x>0, A))
A.sort()
if len(A) == 0:
    print(0)
else:
    res = A[0]
    for a in A:
        res = gcd(a, res)
        if res == 1:
            break

    print(res)

Solution (Python):
import fileinput


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


def gcdl(l):
    r = gcd(l[0], l[1])
    for i in range(2, len(l)):
        r = gcd(r, l[i])
    return r


def algorithm(n, a):
    return gcdl(a)


def pass_inputs(input_lines):
    n = input_lines[0][0]
    return algorithm(n, input_lines[1])


def convert_int(s):
    try:
        r = int(s)
    except ValueError:
        r = s
    return r


def run():
    out = pass_inputs([[convert_int(v) for v in l.strip().split(" ")] for l in fileinput.input()])
    print(out)


if __name__ == "__main__":
    run()

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

def sakujo(a_list):
    for i in range(len(a_list)):
        if a_list[i]!=0:
            end=i
            break
    return a_list[i:]

while True:
    a_s.sort()
    a_s=sakujo(a_s)
    if len(a_s)==1:
        break
    for i in range(1,len(a_s)):
        a_s[i]=a_s[i]%a_s[0]

print(sum(a_s))

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






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

Solution (Python):
from functools import reduce

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

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

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




while(True):
    A.sort()
    min_A=A[0]
    c=0
    for i in range(len(A)):
        tmp=A[i]%min_A
        if(tmp==0):
            c+=1
            A[i]=min_A
        else:
            A[i]=tmp
    if(c==len(A)):
        break

A.sort()
print(A[0])

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

A = list(map(int,input().split()))
i = 0
while True:
    A.sort()
    for a in range(len(A)-1):
        if not(A[a] == 0) and A[a+1] % A[a] == 0:
                A[a+1] = A[a+1] % A[a]
        else:
            A[a+1] = A[a+1] - A[a]

    A = [i for i in A if  i > 0]
    if len(A) == 1:
        break

print(A[0])

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

Solution (Python):
N=int(raw_input())
M=map(int,raw_input().split())

while min(M) != sum(M):
    M.sort()
    m =  M[0]

    for i, a in enumerate(M):
        if i == 0:
            continue
        else:
            M[i] = a % m
            



    M = [i for i in M if i != 0]


print sum(M)

Solution (Python):
def calc(a):
    m = min(a)
    b = [i % m for i in a if i % m != 0]
    if b:
        return calc(b+[m])
    else:
        return min(a)
      
_ = int(input())
print(calc(list(map(int, input().split()))))

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

tmp=A[0]
for a in A[1:]:
  if a%tmp!=0:
    tmp=a%tmp
    
while 1:
  A_tmp=[a%tmp for a in A if a%tmp!=0]
  if sum(A_tmp)!=0:
    tmp=min(A_tmp)
  else:
    break
print(tmp)

Solution (Python):
input()
*s, = map(int, input().split())
base = min(s)

while True:
  s = [i%base for i in s]
  s.append(base)
  s = list(set(s))
  s.remove(0)

  if base > min(s):
    base = min(s)
    continue
  else:
    break

print(base)

Solution (Python):
input()

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

while len(living_monsters) > 1:
    living_monsters.sort()
    weakest_monster = living_monsters.pop(0)
    attacked_monsters = []
    for monster in living_monsters:
        attacked_monster = monster % weakest_monster
        if attacked_monster != 0:
            attacked_monsters.append(attacked_monster)
    living_monsters = [weakest_monster] + attacked_monsters

print(living_monsters[0])

Solution (Python):

"""
Created on Sat Feb 16 20:52:40 2019

@author: Owner
"""


import collections
import scipy.misc
import sys
import numpy as np
import math
from operator import itemgetter
import itertools
import copy


def prime_decomposition(n):
  i = 2
  table = []
  while i * i <= n:
    while n % i == 0:
      n /= i
      table.append(int(i))
    i += 1
  if n > 1:
    table.append(int(n))
  return table   

def digit(i):
    if i > 0:
        return digit(i//10) + [i%10]
    else:
        return []
    
def getNearestValueIndex(list, num):
    """
    概要: リストからある値に最も近い値のインデックスを取得する関数
    @param list: データ配列
    @param num: 対象値
    @return 対象値に最も近い値
    """

    
    idx = np.abs(np.asarray(list) - num).argmin()
    return idx

"""
N, X = map(int, input().split())

x = [0]*N
x[:] = map(int, input().split())

P = [0]*N
Y = [0]*N
for n in range(N):
    P[n], Y[n] = map(int, input().split())
    
all(nstr.count(c) for c in '753')

ABT = zip(A, B, totAB)
result = 0

sorted(ABT,key=itemgetter(2))



(x >> i) & 1

"""
N = int(input())

A = [0]*N
A[:] = map(int, input().split())

A.sort()
while len(A) != 1:
    for n in range(len(A)-1):
        A[n+1] = A[n+1] % A[0]
    A = [e for e in A if e != 0]
    A.sort()
print(A[0])

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

while True:
    index_list = [i for i, v in enumerate(monster) if v >0]
    mini = monster[index_list[0]]
    for i in range(1, len(index_list)):
        if mini > monster[index_list[i]]:
            mini =  monster[index_list[i]]

    miniindex_list = [i for i, v in enumerate(monster) if v ==mini]
    min_index = miniindex_list[0]

    for i in range(len(monster)):
        if not i == min_index:
            monster[i] = monster[i] % monster[min_index]
            
    non_zeroindex_list = [i for i, v in enumerate(monster) if v >0] 
    non_zeroindex = non_zeroindex_list[0]
    if len(non_zeroindex_list) == 1:
        break
print(monster[non_zeroindex])

Solution (Python):

import sys

def io_generator():
	while True:
		yield raw_input()



def gojo(i,j):
	a=max(i,j)
	b=min(i,j)
	while b > 0:
		t=b
		c=a/b
		b=a%b
		a=t
	return a
		

def main(io):
	a=int(io.next())
	l= list(map(int, io.next().split()))
	
	a=l[0]
	for i in l[1:]:
		a=gojo(a,i)
	return a




if __name__ == "__main__":
	io=io_generator()
	print main(io)

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

N = int(input())

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

print(int(reduce(gcd,A)))

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

def chkprint(a):
	a_name = ''
	for k, v in globals().items():
		if id(v) == id(a):
			a_name = k
			break
	print(a_name+' = '+str(a), file=sys.stderr)

def mt(f):
	import time
	def wrap(*args, **kwargs):
		s = time.time()
		ret = f(*args, **kwargs)
		e = time.time()
		print(e - s, 'sec', file=sys.stderr)
		return ret
	return wrap

@mt
def slv(N, A):
	flag = True
	while len(A) > 1:
		m = min(A)
		A = [a % m for a in A if a % m != 0]
		A.append(m)
		print(A, file=sys.stderr)
	return m


N = int(input())
A = [int(i) for i in input().split()]
'''
N = 5
A = [13, 5, 18, 100000000]
'''
print(slv(N, A))

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

while len(list_HP)!=1:
	new_list = []
	smallest = min(list_HP)

	for i in range(len(list_HP)):
		temp = int(list_HP[i]/smallest)
		list_HP[i] = list_HP[i] - (smallest*temp)
		if list_HP[i] != 0:
				new_list.append(list_HP[i])
	list_HP = new_list
	list_HP.append(smallest)

print(list_HP[0])

Solution (Python):
N = int(input())
A= []

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


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


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

Solution (Python):
def main():
	N = int(input())
	A = list(map(int, input().split()))
	while(len(A) != 1):
		A.sort()
		mini = A[0]
		i = 1
		while(True):
			if A[i] % mini == 0:
				A.pop(i)
			else:
				A[i] = A[i] % mini
				i += 1
			if i == len(A):
				break
		A = list(set(A))
	print(A[0])

if __name__ == '__main__':
	main()

Solution (Python):
def attack(H):
    
    H.sort()
    H_min = H[0]
    for i in range(1,len(H)):
        H[i]  = H[i] % H_min
    
    new_H = [i for i in H if i != 0]
    return new_H

N = int(input())
HP_str = input().split()
HP = [0 for i in range(N)]
for j in range(N):
    HP[j] = int(HP_str[j])

while(True):
    HP = attack(HP)
    if len(HP) == 1:
        break

HP.sort()
HP.reverse()
print(HP[0])

Solution (Python):


N = int(input())

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

def royale(An):

    tmp = An
    while True:
        n_tmp = []
        
        if len(tmp) == 1:
            return tmp[0]

        
        min_hp = min(tmp)
        n_tmp.append(min_hp)
        min_num = tmp.index(min_hp)

        
        if min_hp == 1:
            return 1

        
        for i in range(len(tmp)):
            
            if i != min_num:
                tmp[i] = tmp[i] % min_hp
                if tmp[i] != 0:
                    n_tmp.append(tmp[i])
        tmp = n_tmp

print(royale(A))

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

monster.sort(reverse = True)

while sum(monster[1:N]) != 0:
    monster.sort(reverse = True)
    for i in range(N-1):
        if monster[i+1] != 0:
            monster[i] = monster[i] % monster[i+1]

print(monster[0])

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

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

attacker = 0

def attack(attacker, monsters_hp):
    for i in range(len(monsters_hp)):
        if i == attacker:
            continue
        else:
            monster_hp = monsters_hp[i]
            if monsters_hp[attacker] == 0:
                continue
            hp_mod = monster_hp % monsters_hp[attacker]
            monsters_hp[i] = hp_mod
    return monsters_hp

def calc_zero(monsters_hp):
    count = 0
    for monster_hp in monsters_hp:
        if monster_hp == 0:
            count += 1
    return count

def change_attacker(monsters_hp):
    minimum = calc_minimum(monsters_hp)
    for i in range(len(monsters_hp)):
        if monsters_hp[i] == minimum:
            return i
def calc_minimum(monsters_hp):
    minimum = monsters_hp[0]
    for i in range(len(monsters_hp)):
        if monsters_hp[i] == 0:
            continue
        elif minimum >= monsters_hp[i]:
            minimum = monsters_hp[i]
    if minimum == 0:
        minimum += 1
    return minimum

while True:
    attack(attacker, monsters_hp)
    attacker = change_attacker(monsters_hp)
    count = calc_zero(monsters_hp)
    if count == (len(monsters_hp) - 1):
        break

print(max(monsters_hp))

Solution (Python):
from functools import reduce
n = int(input())
arr = list(map(int, input().split()))
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

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

ans = gcd_list(arr)
print(ans)

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

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

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

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

A.sort()


if((A[1] - A[0]) == 0):
    min_HP = A[0]
    print(min_HP)
else:
    min_HP = A[1] - A[0]
    while((A[1] - A[0]) > 0):
        A.insert(0, A[1] - A[0])
        A.sort()
        if((A[1] - A[0]) == 0):
            break
        min_HP = A[1] - A[0]

    
    while(True):
        min_flag = False
        for a in A:
            if ((a % min_HP) < min_HP and (a % min_HP) > 0):
                min_HP = a % min_HP
                min_flag = True
        if( min_HP > 0 and min_flag ):
            continue
        else:
            break
    print(min_HP)

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

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

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

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


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


zero = 0
while mon.count(0) != (n-1):
    mon.sort()
    min = mon[zero]
    tei = zero + 1
    for i in range(tei,n):
        mon[i] = mon[i] % min
        if mon[i] == 0:
            zero += 1
mon.sort()
print(mon[zero])

Solution (Python):
input();a=set(map(int,input().split()))
while(len(a)>1):
 m=min(a)
 a={e%m for e in a-{m}if e%m>0}|(a&{m})
print(*a)

Solution (Python):
import fractions
N = int(input())
A = list(map(int, input().split()))
import math
A.sort()
ans = A[0]

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

print(ans)

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

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

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

a=sorted(a)
mi=a[0]
g=0
k=0
t=0
gset=set()
loopnum=len(a)-1
i=1
while i<=loopnum:
    if(0<a[i]%mi<mi):
        a.append(mi)
        mi=a[i]%mi
        loopnum+=1
    i+=1
        
if(t==N-1):
    print(mi)
else:
    print(mi)

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

Solution (Python):
from functools import reduce
import fractions

n = int(input())
l = [int(i) for i in input().split()]
exgcd = reduce(fractions.gcd, l)

print(exgcd)

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

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

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

Solution (Python):


import sys

def main():
    n = int(input())

    HP = [int(e) for e in input().split(" ")]

    while True:
        
        min_idx = HP.index(min([e for e in HP if e > 0]))

        died = 0
        for i in range(n):
            if i == min_idx:
                continue
            if HP[i] <= 0:
                died += 1
                continue
            HP[i] %= HP[min_idx]
        if died == len(HP)-1:
            break

    for m in HP:
        if m > 0:
            print(m)

main()

Solution (Python):
n = int(input())
a_li = list(set(int(x) for x in input().split()))

while 1:
    res = a_li[-1]
    a_li.sort(reverse = True)
    cou = 0
    for i in a_li[:-1]:
        a_li[cou] = i % a_li[-1]
        cou += 1
    a_li = list(set(a_li))
    try:
        a_li.remove(0)
    except:
        pass
    if len(a_li) == 0:
        print(res)
        break
    if len(a_li) == 1:
        print(a_li[0])
        break

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)

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

Solution (Python):

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

from functools import reduce
def gcd(a,b):
    if a<b:a,b=b,a
    if a%b==0:return b
    return gcd(b,a%b)

gcd=reduce(gcd,a)
print(gcd)

Solution (Python):
import fractions
from functools import reduce

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

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

print(gcd(*A))

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

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

Solution (Python):


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

pm = min(A)
m = pm
while True:
    na = [a % m for a in A if a % m != 0]
    if len(na) == 0:
        break
    pm, m = m, min(na)
    if pm == m:
        break

print(m)

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

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

print(a[0])

Solution (Python):
import numpy as np
N = input()
N = int(N)
A = input()
A = A.split()
for i in range(len(A)):
    A[i] = int(A[i])
A = np.array(A)
while True:
    min = np.min(A)
    A = A%min
    B = np.where(A==0)
    C = np.delete(A,B)
    C = np.unique(C)
    A = np.append(C,[min])
    if len(A) == 1:
        break
print(A[0])

Solution (Python):
import numpy as np
n=int(input())
hp = list(map(int, input().split()))
hp = np.array(hp)
m = min(hp)
while 1:
  temp = hp%m
  temp = temp[temp!=0]
  if len(temp):
    M = min(temp)
    if M < m:
      m = M
    else:
      break
  else:
    break
print(m)

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

N = int(input())

a = [int(x) for x in input().split()]
ans = a[0]
for i in a:
    ans = lcm(ans,i)

print(ans)