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



Sample input:
4
2 10 8 40


Sample output:
2

Submission status: Runtime Error

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

import math
from functools import reduce

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

print(gcd(*A))

Submission status: Runtime Error

Solution code:
import fraction
n = int(input())
a = list(map(int,input().split()))
ans = a[0]
for x in a:
    ans = fraction.gcd(x,ans)
print(ans)

Submission status: Runtime Error

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

print(N)
print(HPs)

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

print(HPs[0])

Submission status: Runtime Error

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

l = sorted(l)

sema = True
for i in range(len(l)):
    for j in range(i + 1,len(l)):
        if not l[j] % l[i] == 0:
            sema = False
            break
pre = min(l)
if sema == True:
    print(pre)
else:
    m = l[1] % l[0]
    for i in range(2, len(l)):
        a = l[i] % m
        if a < m and a >= 1:
            m = a
        else:
            print(m)

Submission status: Runtime Error

Solution code:
import math

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

n = int(input())
li = list(map(int,input().split()))
li2 = list(set(li))
li2.sort()
li3 = [li2[0]]

for i in range(n-1):
    li3.append(abs(li[i+1]-li[i]))

a = math.gcd(li3[i],li3[i+1])
li4 = [a]

for i in li3:
    a = math.gcd(li4[-1],i)
    li4.append(a)

print(li4[-1])

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int,input().split()))
ans = a[0]
for x in a:
    ans = math.gcd(x,ans)
print(ans)

Submission status: Runtime Error

Solution code:
import math

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

ans = 10 ** 9
for ai in a:
    ans = math.gcd(ans, ai)

print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
aarr = list(map(int,input().split()))

ans = float('inf')
for i in range(n):
    for j in range(n):
        barr += [aarr[j] % aarr[i]]
    tmp = aarr[i] - max(barr)
    ans = min(ans,tmp)
    barr = []
print(ans)

Submission status: Runtime Error

Solution code:
N=int(input())
a_list=[]
a_list = list(map(int, input().split())) # "1 2 3"と入力
min_num=min(a_list)
nokori_list=[i%min_num for i in a_list if i%min_num!=0]
answer=0
if len(nokori_list)==0:
    print(min_num)
else:
    can_min=min(nokori_list)
    futuer_min=min_num%can_min
    while futuer_min>0:
        big=max(can_min,futuer_min)
        small=min(can_min,futuer_min)
        futuer_min=big%small
        if futuer_min==0:
            answer=small
            break
    	answer=small
    print(answer)

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input()) 
#n=4
lst = [int(input()) for i in range(n)]
#lst = [2, 10, 8, 40]
#lst = [5, 13, 8, 1000000000]
hps = np.array(lst)
while(1):
    hps = sorted(hps)
    print(hps)
    if(hps[0]==0): break
    if(hps[0]==hps[n-1]): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

Submission status: Runtime Error

Solution code:
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]
    HPs.remove(0)

print(HPs[0])

Submission status: Runtime Error

Solution code:
N=int(input())
a_list=[]
a_list = list(map(int, input().split())) # "1 2 3"と入力
min_num=min(a_list)
nokori_list=[i%min_num for i in a_list if i%min_num!=0]
answer=0
if len(nokori_list)==0:
    print(min_num)
else:
    can_min=min(nokori_list)
    futuer_min=min_num%can_min
    while futuer_min>0:
        big=max(can_min,futuer_min)
        small=min(can_min,futuer_min)
        futuer_min=big%small
        if futuer_min==0:
            answer=small
            break
    answer=small
    print(answer)

Submission status: Runtime Error

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

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

print(HPs[0])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

import itertools


if __name__ == '__main__':
    N = int(input())
    As = [int(c) for c in input().split(' ')]

    As = set(As)

    dp = {}
    while True:
        As_next = [0] * (len(As) ** 2)
        for index, (a, b) in enumerate(itertools.product(As, repeat=2)):
            if (a, b) in dp:
                As_next[index] = dp[(a, b)]
            else:
                v = a % b
                dp[(a, b)] = v
                As_next[index] = v

        As_next = set(filter(lambda x: x > 0, As_next))
        if len(As_next) < 1:
            break

        As = As_next

    print(min(As))

Submission status: Runtime Error

Solution code:
n = int(input())
li = list(map(int,input().split()))
while len(li) > 1:
    i = n
    while i > 0:
        if li[i] <= 0:
            del li[i]
        i = i - 1
    n = len(li)
    for j in range(n):
        li[j] = li[j] - min(li)
    minn = li.index(min(li))
    li[minn] = li[minn] + min(li)
print(li[0])

Submission status: Runtime Error

Solution code:
n = int(input())
aarr = list(map(int,input().split()))

ans = float('inf')
for i in range(n):
    for j in range(n):
        barr += [aarr[j] % aarr[i]]
    tmp = aarr[i] - max(barr)
    ans = min(ans,tmp)
    barr = []
print(ans)

Submission status: Runtime Error

Solution code:
import math
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,math.gcd(enemy[i],enemy[i+1]))
    print(min_n)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
 
def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
  
def gcdlist(a):
  if len(a)==2:
    return gcd(a[0],a[1])
  else:
    return gcd(a[0],gcdlist(a[1:]))
  
print(gcdlist(a))

Submission status: Runtime Error

Solution code:
n = int(input()) 
lst = [int(i) for i in input().split()]
while(1):
    hps = sorted(hps)
    #print(hps)
    if(hps[0]==0): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
# a.sort()
# now = a[0]
# for i in range(1, n):
#     if (a[i] % now != 0):
#         now = a[i] % now
# print(now)
import math
from functools import reduce
print(reduce(math.gcd,a))

Submission status: Runtime Error

Solution code:
import math
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(n-1):
        min_n = min(min_n,math.gcd(enemy[i],enemy[i+1]))
    print(min_n)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

Submission status: Runtime Error

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

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

while len(ALL) > 1:
  ALL.append(gcd(ALL[0],ALL[1]))
  del ALL[0]
  del ALL[0]
  print(ALL)
  
print(ALL[0])

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

Submission status: Runtime Error

Solution code:
n = int(input()) 
lst = [int(input()) for i in range(n)]
while(1):
    hps = sorted(hps)
    #print(hps)
    if(hps[0]==0): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

Submission status: Runtime Error

Solution code:
import fileinput


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


def gcdl(l):
    if len(l) > 1:
        r = gcdl([gcd(l[0], l[1])] + l[2:])
    else:
        r = l
    return r


def algorithm(n, a):
    return gcdl(a)[0]


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

Submission status: Runtime Error

Solution code:
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.sort()
    print(a)
    if a[0] == 1 :
        break
print(a[0])

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

n = int(input())
li = list(map(int,input().split()))
li2 = list(set(li))
li2.sort()
li3 = [li2[0]]

for i in range(n-1):
    li3.append(abs(li[i+1]-li[i]))

print(gcd_list(li2))

Submission status: Runtime Error

Solution code:
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):
    if len(l)>=2:
        m = l[0]
        n = l[1]
        g = gcd(m,n)
        l_new = [g] + l[2:]
        return (gcd_list(l_new))
    else:
        return l[0]
    
N = int(input())
A_list = [int(i) for i in input().split()]
ans = gcd_list(A_list)
print(ans)

Submission status: Runtime Error

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

import math
from functools import reduce

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

print(gcd(a))

Submission status: Runtime Error

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

def gcd(A, B):
    # fast return
    if B == 1 or A == 1:
        return 1

    # normal gcd logic
    if A != B:
        return gcd(min(A, B), abs(A - B))
    else:
        return A

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)

Submission status: Runtime Error

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

while True:
    X = sorted(list(A))
    N = len(X)
    A = set()
    for i in range(N):
        for j in range(N):
            x = X[j] % X[i]
            if x != 0:
                A.add(x)
    if A <= set(X):
        break

print(min(A))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
s = sum(a)
c = []
for i in a:
  c.append(s%a[i])
if min(c) == 0:
  print(min(a))
else:
  print(min(c))

Submission status: Runtime Error

Solution code:
N = int(input())
aA=list(set(int(_) for _ in input().split()))
def ggg(i,j):
    if i < j :
        i,j = j,i
    i %= j
    if i == 0:
        return j
    else:
        return ggg(j,i)

if len(aA) == 1:
    print(aA[0])
else:
    iMin = min(aA)
    iMax = max(aA)
    if iMin  == 1:
        print(1)
    else:
        iDm = [i % iMin for i in aA]
        if max(iDm) == 0:
            print(iMin)
            exit()
        else:
            iM = iMax
            for i in range(N):
                iA = aA[i]
                for j in range(i+1,N):
                    iMt = ggg(iA,aA[j])
                    if 0 < iMt and iMt < iM:
                        iM = iMt
                    if iM == 1:
                        print(1)
                        exit()
            print(iM)

Submission status: Runtime Error

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

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
  
def gcdlist(a):
  if len(a)==2:
    return gcd(a[0],a[1])
  else:
    return gcd(a[0],gcdlist(a[1:]))
  
print(gcdlist(a))

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
n = int(input())
l = map(int, input().split())
le = sorted(l)


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

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



print(gcd(*le))

Submission status: Runtime Error

Solution code:
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
        print(a_li)
    a_li = list(set(a_li))
    try:
        a_li.remove(0)
    except:
        pass
    print(a_li)
    if len(a_li) == 0:
        print(res)
        break
    if len(a_li) == 1:
        print(a_li[0])
        break

Submission status: Runtime Error

Solution code:
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]

    # そのループでまだmin_HPが更新されていない
    min_flag = False
    while(True):
        for a in A:
            if ((a % min_HP) < min_HP and (a % min_HP) > 0):
                min_HP = tmp_min
                min_flag = True
        if( min_HP > 0 and min_flag ):
            continue
        else:
            break
    print(min_HP)

Submission status: Runtime Error

Solution code:
# C
n = int(input()) 
a = list(map(int, input().split()))

import functools
import math

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

Submission status: Runtime Error

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

while True:
  if len(data) == 1:
    break
  min_data = min(data)
  n_min_d  = min([d for d in data if d != min_data])
  min_idx = data.index(n_min_d )
  n_min_d_idx = data.index(n_min_d)
  data[n_min_d_idx] = data[n_min_d_idx] - data[min_idx]
  data = [d for d in data if d != 0]
  
print(data[0])

Submission status: Runtime Error

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

def gcd(A, B):
    if A * B <= 0:
        # at least one is positive
        return max(A, B)
    # fast return
    if B == 1 or A == 1:
        return 1

    # normal gcd logic
    if A != B:
        return gcd(min(A, B), abs(A - B))
    else:
        return A

A.sort()
res = A[0]
for a in A:
    if a <= 0:
        continue
    res = gcd(a, res)
    if res == 1:
        break

print(max(res, 0))

Submission status: Runtime Error

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

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

ans = gcd_list(arr)
print(ans)

Submission status: Runtime Error

Solution code:
import fraction
N = int(input())
A = list(map(int, input().split()))
import math
A.sort()
ans = 10000000000000000000000000000000000000000000

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

print(ans)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

print(reduce(math.gcd, monsters))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	while(len(A) != 1):
		A.sort()
		mini = A[0]
		for i in range(1, len(A)):
			if i >= len(A):
				continue
			if A[i] % mini == 0:
				A.pop(i)
			else:
				A[i] = A[i] % mini
		A = QUICKSORT(A)
		piv = A[0]
		for i in range(1, len(A)):
			if i >= len(A):
				continue
			if A[i] == piv:
				A.pop(i)
	print(A[0])

if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
N = int(input())
monsters = sorted(map(int, input().split()), reversed=True)

while True:
  a, b = monsters[-2:]
  c = a - b
  if c > 0:
    monsters.append(c)
  break

remain = monsters[0] % monsters[-1]
if remain == 0:
  remain = monsters[-1]
print(remain)

Submission status: Runtime Error

Solution code:
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)
      
if __name__ == "__main__":
  _ = int(input())
  print(calc(list(map(int, input().split()))))

Submission status: Runtime Error

Solution code:
n = int(input())
monster = sorted(list(map(int,input().split())))
min_HP = min(monster)
cnt=0
while True:
  tmp = int(monster[-1]/monster[-2])
  monster[-1]-=monster[-2]*tmp
  if monster[-1]<=0:
    monster.pop(-1)
  monster = sorted(monster)
  if min_HP==monster[0]:
    cnt+=1
    if cnt>=2:
      print(min_HP)
      exit()
  else:
    min_HP = monster[0]
    cnt=0

Submission status: Runtime Error

Solution code:
Keita [9:48 PM]
import numpy as np

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

minA = min(listA)

while True:
   minA = min(listA)
   minApos = np.argmin(listA)
   listA = [x % minA for x in listA]
   listA[minApos] = minA
   listA= [x for x in listA if x >0]
   if len(set(listA))==1:
       print(minA)
       break

Submission status: Runtime Error

Solution code:
n = int(input())
monster = sorted(list(map(int,input().split())))
min_HP = min(monster)
cnt=0
while True:
  tmp = int(monster[-1]/monster[-2])
  monster[-1]-=monster[-2]*tmp
  if monster[-1]<=0:
    monster.pop(-1)
  monster = sorted(monster)
  if min_HP==monster[0]:
    cnt+=1
    if cnt>=2:
      print(min_HP)
      exit()
  else:
    min_HP = monster[0]
    cnt=0
  print(monster)

Submission status: Runtime Error

Solution code:
n = int(input())
box = list(map(int,input().split()))

while(1):

    for index,item in enumerate(box):
        if index != 0 and item != 0:
            if item % min(box) == 0:
                box[index] = 0
                box.remove(0)
            else:
                box[index] = item % box[0]
        
    #print(box)
    if len(box) == 1:
        break

print(box[0],end='')

Submission status: Runtime Error

Solution code:

def is_include_0(x):
  if 0 in x:
    x.remove(0)


  if 0 in x:
    return is_include_0(x)
  else:
    return x
  

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

  monsters = sorted(monsters)
  # print(monsters)

  last = 10000
  while True:
    # print('==============================')
    # print(monsters)
    for i in range(1, len(monsters)):
      monsters[i] = monsters[i] % monsters[0]

    # print(monsters)
    if 0 in monsters:
      # monsters.remove(0)
      monsters = is_include_0(monsters)
      monsters = sorted(monsters)

    # print(monsters)
    if len(monsters) == 2:
      # print('a')
      last = int(abs(monsters[1] - monsters[0]))
      monsters[0] = last
      monsters.remove(monsters[1])
      # print(monsters)

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

main()

Submission status: Runtime Error

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

A.sort()


if((A[1] - A[0]) == 0):
    min_HP = A[0]
else:
    min_HP = 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]

tmp_min = min_HP
for a in A:
    if ((a % tmp_min) < min_HP and (a % tmp_min) > 0):
        min_HP = tmp_min

print(min_HP)

Submission status: Runtime Error

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

while True:
  if len(data) == 1:
    break
  min_idx = data.index(min(data))
  n_d = min([d for d in range(len(data)) if d != min_idx])
  n_min_idx = data.index(min(n_data))
  data[n_min_idx] = data[n_min_idx] - data[min_idx]
  data = [d for d in data if != 0]
  
print(data[0])

Submission status: Runtime Error

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

A.sort()


if((A[1] - A[0]) == 0):
    min_HP = A[0]
else:
    min_HP = 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]

tmp_min = min_HP
for a in A:
    if ((a % tmp_min) < min_HP):
        min_HP = tmp_min

print(min_HP)

Submission status: Runtime Error

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

smallest = min(list_HP)
list_HP.remove(smallest)
second = min(list_HP)
list_HP.remove(second)

while (0<smallest) & (0<second):
	if smallest < second:
		second = second - smallest
	else:
		smallest = smallest - second

if (0<second):
	smallest = second

third = min(list_HP)

while (0<smallest) & (0<third):
	if smallest < third:
		third = third - smallest
	else:
		smallest = smallest - third

if (0<smallest):
	print(smallest)
else:
	print(third)

Submission status: Runtime Error

Solution code:
import fraction

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

sortedA = sorted(A)
answer = A[0]

for x in range(0,N):
        answer = gcd(answer,A[x])
        if answer == 1:
            break

print(answer)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

n = int(input())
arr = list(map(int, input().split()))
def gcd_list(numbers):
    return reduce(math.gcd, numbers)

print(gcd_list(arr))

Submission status: Runtime Error

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

def gcd(A, B):
    if B == 1 or A == 1:
        return 1
    if A > B:
        return gcd(B, A - B)
    elif A < B:
        return gcd(A, B - A)
    else:
        return A

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

Submission status: Runtime Error

Solution code:

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

    while True:
        m = min(a)
        for i in range(len(a)):
            if a.index(m) != i:
                a[i] = a[i] % m

        while True:
            if min(a) == 0:
                a.remove(0)
            else:
                break

        if len(a) == 1:
            print(find_min(a))
            exit()



if __name__ == "__main__":
        main()

Submission status: Runtime Error

Solution code:
import math

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

min_last_hp = 10 ** 10

for start in range(N):
    for c in range(start+1, N):
        last_hp = math.gcd(a_list[start], a_list[c])
        # if min_last_hp == None:
        #     min_last_hp = last_hp
        if last_hp < min_last_hp:
            min_last_hp = last_hp

print(min_last_hp)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = list(map(int, input().split()))
lsize = len(a)
bef = a[0]
for i in range(1, lsize):
  bef = math.gcd(bef,a[i])
print(bef)

Submission status: Runtime Error

Solution code:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	while(len(A) != 1):
		A = QUICKSORT(A)
		mini = A[0]
		for i in range(1, len(A)):
			if i >= len(A):
				continue
			if A[i] % mini == 0:
				A.pop(i)
			else:
				A[i] = A[i] % mini
		A = list(set(A))
	print(A[0])

def QUICKSORT(A):
	if len(A) < 1:
		return A
	pivot = A[0]
	left = []
	right = []
	for x in range(1, len(A)):
		if A[x] <= pivot:
			left.append(A[x])
		else:
			right.append(A[x])
	left = QUICKSORT(left)
	right = QUICKSORT(right)
	foo = [pivot]
	return left + foo + right

if __name__ == '__main__':
	main()

Submission status: Runtime Error

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

A.sort(reverse=True)
maxi = A[0]
a = maxi

for i in range(1,len(A)):
	while True:
      a = a - A[i]
      if a <= 0:
        break
        
print(a)

Submission status: Runtime Error

Solution code:
from fraction import gcd

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

sortedA = sorted(A)
answer = A[0]

for x in range(0,N):
        answer = gcd(answer,A[x])
        if answer == 1:
            break

print(answer)

Submission status: Runtime Error

Solution code:
def main():
  N = int(input())
  monsters = list(map(int, input().split()))

  monsters = sorted(monsters)
  # print(monsters)

  last = 10000
  while True:
    # print('==============================')
    # print(monsters)
    for i in range(1, len(monsters)):
      monsters[i] = monsters[i] % monsters[0]

    # print(monsters)
    if 0 in monsters:
      monsters.remove(0)
      monsters = sorted(monsters)

    # print(monsters)
    if len(monsters) == 2:
      last = int(abs(monsters[1] - monsters[0]))
      monsters.remove(monsters[1])

    if len(monsters) == 1:
      break
  print(last)

  

main()

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
import math
GCD_i=A[0]
for i in range(len(A)):
  GCD_i = math.gcd(GCD_i,A[i])
print(GCD_i)

Submission status: Runtime Error

Solution code:
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):
	a = min(A)
	flag = False
	while not flag:
		flag = True
		for i in A:
			if i % a == 0:
				i = a
			else:
				i = i % a
				flag = False
		a = min(A)
	return a
	
N = int(input().split())
A = [int(i) for i in input().split())]
#N = 4
#A = [2, 10, 8, 40]
print(slv(N, A))

Submission status: Runtime Error

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
newA = np.array(A)
num = np.gcd.reduce(newA)
print(num)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

print(gcd_list(lst))

Submission status: Runtime Error

Solution code:
import math
N = int(input())
monsterlist = list(map(int,input().split()))
monsterlist.sort()
minnum = monsterlist[0]
count = 0
for i in range(1,N):
    if monsterlist[i] % minnum != 0:
        count += 1
        comparenum = monsterlist[i]
        break
if count == 0:
    print(minnum)
else:
    print(math.gcd(minnum,comparenum))

Submission status: Runtime Error

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

def gcd(A, B):
    if B == 1 or A == 1:
        return 1
    if A > B:
        return gcd(B, A - B)
    elif A < B:
        return gcd(A, B - A)
    else:
        return A

A.sort()
A.append(None)
res = A[0]
for i, a in enumerate(A):
    if not a:
        break
    res = gcd(a, res)
    if res == 1:
        break
print(res)

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce

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

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

print(gcd(*a))

Submission status: Runtime Error

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

l = sorted(l)


sema = True
mod_list = []
for i in range(len(l)):
    for j in range(i + 1,len(l)):
        if not l[j] % l[i] == 0:
            sema = False
            mod_list.append(l[j] % l[i])
mod_list = set(mod_list)
if sema == True:
    print(min(l))
else:
    ans = min(l)
    print(min([i % m for i in l for m in mod_list if i % m != 0]))

Submission status: Runtime Error

Solution code:
# C Monsters Battle Royale
N = int(input())
Monsters = list(map(int, input().split()))
Monsters.sort()

ans = Monsters[0]
for i in range(len(Monsters) - 1):
    tempList = [val % Monsters[i] for val in Monsters[i+1:] if not val % Monsters[i] == 0]
    if tempList:
        if min(tempList) < ans:
            ans = a
        
print(ans)

Submission status: Runtime Error

Solution code:
from fractions import Fraction

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

A.sort()

res = A[0]
for aa in A:
    res = Fraction.gcd(res, aa)

print(res)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

print(gcd(*a))

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
def gcd(a,b):
  c = a%b
  if c == 0:
    return b
  0else:
    return gcd(b,c)
c = 0
for i in a[1:]:
  c_ = gcd(i,a[0])
  if c_ == 1:
    c = 1
    break
  else:
    if c_ < c or c == 0:
      c = c_
print(c)

Submission status: Runtime Error

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

flag = 0
i = 1
while flag == 0:
    if A[i] % A[0] != 0:
        A[i] = A[i] % A[0]
        A[i],A[0] = A[0],A[i]
        i = 1
    else:
        i += 1
    if i == N-1:
        flag = 1
        print(A[0])
        exit()