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: Time Limit Exceeded

Solution code:
#-*-coding:utf8;-*-
#qpy:3
#qpy:console
n = int(input())
hp = list(map(int, input().split()))
while len(hp) != 1:
    minhp = min(hp)
    hp = [i % minhp if not i == minhp else i for i in hp]
    hp = [i for i in hp if not i == 0]
    
print(minhp)

Submission status: Time Limit Exceeded

Solution code:
a = input()
list = input().split()
b = len(list)
for j in range(b):
	list[j] = int(list[j])
for k in range(b-1):
	l = k + 1
	while l < b:
		if list[k] > list[l]:
			temp = list[k]
			list[k] = list[l]
			list[l] = temp
		l += 1
gcd = int(list[0])
for i in range(b):
	m = list[i] 
	n = gcd
	while n != 0:
		m,n = n,m%n
	if(m<gcd):
		gcd = m
print(gcd)

Submission status: Time Limit Exceeded

Solution code:
n = input()
list = input().split()
for j in range(len(list)):
	list[j] = int(list[j])
for k in range(len(list)-1):
	l = k + 1
	while l < len(list):
		if list[k] > list[l]:
			temp = list[k]
			list[k] = list[l]
			list[l] = temp
		l += 1
gcd = list[0]
for i in range(len(list)):
	m = list[i] 
	n = gcd
	while n != 0:
		m,n = n,m%n
	if(m<gcd):
		gcd = m
print(gcd)

Submission status: Time Limit Exceeded

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

init = min(A)
min_divis = init
for i in range(init, 0, -1) :
    flg_ok = True
    for j in A :
        if j % min_divis != 0 :
            flg_ok = False

    if flg_ok == True :
        min_divis = i
        break
        
if flg_ok == False :
    print(1)
else :
    print(min_divis)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
# print(A)
while len(A) > 1:
    a, b = A[0], A[1]
    c = b % a
    if c == 0:
        A = [a] + A[2:]
    else:
        A = [c,  a] + A[2:]
print(A[0])

Submission status: Time Limit Exceeded

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

def calc(a, b):
    while(a != b):
        largeNum = max(a, b)
        smallNum = min(a, b)
        largeNum -= smallNum
        a = largeNum
        b = smallNum
    return a

ans = 1
for i in range(0, N - 1):
    a = calc(A[i], A[i+1])
    A[i], A[i+1] = a, a
    if a == 1:
        break
else:
    ans = min(A)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
from math import *
N=int(input())
A=[int(i) for i in input().split(" ")]

while len(A)>1:
    A.sort(reverse=True)
    A[0]-=min(A)*(floor((A[0]-A[1])/min(A))+1)
    if A[0]<1:
        del A[0]
print(A[0])

Submission status: Time Limit Exceeded

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

def yakusuu(p):
	A.reverse()
	for i in range(1,p):
		if A[0] % A[i] == 0:
			A.pop(0)
			return
	else:
		return
def syou(k):
	A.sort()
	if A[0] == 0:
		A.pop(0)
		if len(A) > 1:
			A[k-1] = A[k-1] % A[0]
	else:
		A[k] = A[k] % A[0]
	return A
for i in range(N):
	if len(A) >= 1:
		yakusuu(len(A))
while	len(A) > 1:
	syou(len(A)-1)
print(A[0])

Submission status: Time Limit Exceeded

Solution code:
import math

def process(number_list):
    left, point = number_list[0], number_list[-2]
    if left == 1:
        print(1)
        return 0
    yojo = number_list[-1] % left
    point -= yojo
    right = left * (math.ceil(point / left) - 1) + yojo
    if right == 0:
        number_list.pop(-1)
        if len(number_list) == 1:
            print(number_list[0])
            return 0
    else:
        number_list[-1] = right
        number_list.sort()
    return number_list

def main():
    num = int(input())
    number_list = list(map(int, input().split()))
    number_list.sort()
    while 1:
        number_list = process(number_list)
        if number_list == 0:
            break


if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
Flag = [0 for i in range(N)]
A = list(map(int,input().split()))
while len(A) != 1:
    A.sort()
    mi = min(A)
    for _ in range(1,len(A)):
        if A.count(1) > 1:
            del A[1:]
            break
        try:
            A[_] -= mi
            if A[_] <= 0:
                A.pop(_)
        except:
            pass
print(A[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int,input().split()))
while True:
  minnum = As.index(min(As))
  for i in range(len(As)):
    if not i == minnum:
      As[i] -= As[minnum] 
      if As[i] <= 0:
        As[i] = 0
  while True:
    if 0 in As:
      As.remove(0)
    else:
      break
  if len(As) <= 1 or As[minnum] == 1:
    print(As[minnum])
    break

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int,input().split()))
while True:
  minnum = As.index(min(As))
  for i in range(len(As)):
    if not i == minnum:
      As[i] -= As[minnum] 
      if As[i] < 0:
        As[i] = 0
  while True:
    if 0 in As:
      As.remove(0)
    else:
      break
  if len(As) <= 1 or As[0] == 1:
    print(As[0])
    break

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int,input().split()))
As.sort()
while True: 
  end = False
  As.sort()
  for i in range (1,len(As)):
    As[i] -= As[0] 
    if As[i] < 0:
      As[i] = 0
      break
  while True:
    if 0 in As:
      As.remove(0)
    else:
      break
  if len(As) <= 1 or As[0] == 1:
    print(As[0])
    break

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int,input().split()))
while True:
    As.sort()
    for i in range (1,len(As)):
        As[i] -= As[0] 
        if As[i] <= 0:
            As[i] = 0
    while True:
        if 0 in As:
            As.remove(0)
        else:
            break
    if len(As)== 1 or As[0] == 1:
        print(As[0])
        break

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int,input().split()))
while True:
    end = False
    As.sort()
    for i in range (1,len(As)):
        As[i] -= As[0] 
        if As[i] <= 0:
            As[i] = 0
    while True:
        if 0 in As:
            As.remove(0)
        else:
            break
    if end == True or As[0] == 1:
        print(As[0])
        break

Submission status: Time Limit Exceeded

Solution code:
import fractions
import itertools
# print(math.gcd(1000000000, 1000000000))

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

result = 10 ** 9 + 1

for comb in list(itertools.combinations(monsters,2)):
    gcd = fractions.gcd(comb[0], comb[1]) 
    if gcd < result:
        result = gcd

print(result)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=sorted(map(int,input().split()))[::-1]
ans=A[0]
while True:
    M=A[0]
    m=A[1]
    del A[0]
    if m==0:break
    A.append(M%m)
    A=sorted(A)[::-1]
    ans=min(ans,A[0])
print(ans)

Submission status: Time Limit Exceeded

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

while len(A) > 1:
    m = A[0]
    for n in range(1, len(A)):
        A[n] = A[n] % m
    A = list(set(A))
    if A[0] == 0:
        A = A[1:]
print(A[0])

Submission status: Time Limit Exceeded

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

while len(A) > 1:
    b = [0] * len(A)
    m = A[0]
    b[0] = m
    for n in range(1, len(A)):
        b[n] = A[n] % m
    A = list(set(b))
    if A[0] == 0:
        A = A[1:]
print(A[0])

Submission status: Time Limit Exceeded

Solution code:
def gcd(a, b):
  if a > b:
    min1, min2 = a, b
  else:
    min1, min2 = b, a
  if min2 == 0:
    return min1
  else:
    return gcd(min2, min1%min2)
N = int(input())
monster = list(map(int, input().split()))
monster.sort()
while len(monster) > 1:
  monster = [gcd(monster[i], monster[i+1]) for i in range(len(monster)-1)]
print(monster[0])

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
import sys
import collections

N = int(sys.stdin.readline())

monster = [int(a) for a in sys.stdin.readline().strip().split()]
monster.sort()

while len(monster)>1:
    monster[1] %= monster[0]
    if monster[1] == 0:
        monster.pop(1)
    monster.sort()


print(monster[0])

Submission status: Time Limit Exceeded

Solution code:
def gcd(m, n):
	if m > n:
		m, n = n, m

	return gcd(n % m, m) if n % m else m

def main():
	N = int(input())
	a = [int(x) for x in input().split()]
	result = []
	count = 0
	for i in a:
		if result == []:
			result.append(i)
			count += 1
			continue

		else:
			for j in range(count):
				if result[j] == 0: continue
			x = gcd(result[j], i)

			if x == 1:
				print(1)
				return 0

			else:
				result[j] = x
				result.append(i)
				count += 1
	print(min(result))

if __name__ == '__main__':
	main()

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
monster = sorted(list(map(int, input().split())))
cnt = len(monster)
while cnt > 0:
    for i in range(len(monster)):
        for j in range(len(monster)):
            if i != j and monster[i] != 0:
                monster[j] %= monster[i]
                if monster[j] == 0:
                    cnt -= 1

print(max(monster))

Submission status: Time Limit Exceeded

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

while len(set(A))!=1:
#for i in range(2):
    A.sort()
    for i in range(len(A)-1):
        if A.count(0):
            A.remove(0)
            break
        A[i+1]=A[i+1]%A[0]

print(max(A))

Submission status: Time Limit Exceeded

Solution code:
import sys

def get_minidx(a):
    minval = sys.maxsize
    minidx = -1
    idx = 0
    for i in a:
        if (i < minval) and (0 < i):
            minval = i
            minidx = idx
        idx += 1
    return minidx

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

    # Greedyだけど
    alive = n
    minidx = get_minidx(a)
    while 1 < alive:
        for i in range(n):
            if (i != minidx) and (0 < a[i]):
                a[i] -= a[minidx] * (a[i] // a[minidx])
                if a[i] == 1:
                    print(1)
                    return
                elif a[i] <= 0:
                    alive -= 1
                else:
                    minidx = i
                break
    print(a[minidx])

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys

def get_minidx(a):
    minval = sys.maxsize
    minidx = -1
    idx = 0
    for i in a:
        if (i < minval) and (0 < i):
            minval = i
            minidx = idx
        idx += 1
    return minidx

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

    # Greedyだけど
    alive = n
    minidx = get_minidx(a)
    while 1 < alive:
        for i in range(n):
            if (i != minidx) and (0 < a[i]):
                a[i] -= a[minidx] * (a[i] // a[minidx])
                if a[i] <= 0:
                    alive -= 1
                else:
                    minidx = i
                break
    print(a[minidx])

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
i=1
while len(a)>=2:
    if i>=len(a)-1:
        i=1
    a[i]-=a[0]
    if a[i]<=0:
        del a[i]
    i+=1
    a.sort()

print(a[0])

Submission status: Time Limit Exceeded

Solution code:
import sys

def get_minidx(a):
    minval = sys.maxsize
    minidx = -1
    idx = 0
    for i in a:
        if (i < minval) and (0 < i):
            minval = i
            minidx = idx
        idx += 1
    return minidx

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

    # Greedyだけど
    alive = n
    while 1 < alive:
        minidx = get_minidx(a)
        for i in range(n):
            if (i != minidx) and (0 < a[i]):
                a[i] -= a[minidx] * (a[i] // a[minidx])
                if a[i] <= 0:
                    alive -= 1
                break
    print(a[minidx])

main()

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

while len(A)!=1:
#for i in range(2):
    A.sort()
    for i in range(len(A)-1):
        if A.count(0):
            A.remove(0)
            break
        A[i+1]=A[i+1]%A[0]

print(max(A))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
i=1
while len(a)>=2:
    if i>=len(a):
        i=1
    if a[i] % a[0]==0:
        del a[i]
    else:
        a[i]-=a[0]
        if a[i]<=0:
            del a[i]
    i+=1
    a.sort()

print(a[0])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
As=[int(x) for x in input().split()]
As.sort()
As.reverse()
LL=[]

def ret_factor(num):
    while num % 2 == 0:
        num /= 2
        yield 2

    i = 3
    while num != 1:
        if num % i == 0:
            num /= i
            yield i
        else:
            i += 2


def intersect_list(lst1, lst2):
    arr = []
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            pass
        else:
            arr.append(element)
    return arr

cr=As[0] 
for A in As:
    LL.append(list(ret_factor(A)))

rL=[]
for L in LL:
    for L2 in LL:
        r=1
        for k in intersect_list(L,L2):
           r*=k
        rL.append(r)

print(min(rL))

Submission status: Time Limit Exceeded

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

while(1):
    
    for i in range(len(A)-1):
        A[i+1] = A[i+1]%A[0]
        if(A[i+1] ==0):
            del A[i+1]
            A.sort()
            break
    if(len(A)==1):
        break
    A.sort()
print(A[0])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))   
if len(b)==1:
    print(b[0])
    exit()
else: 
    x=1
    while x>0:
        c=sorted(b)
        if c[1]%c[0]!=0:
            c[1]=c[1]%c[0]
        else:
            c[1]=c[0]
        c=sorted(list(set(c)))
        if c[0]==1:
            x=0
        if len(c)==1:
            print(2)
            exit()
print(1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
monster = set(map(int,input().split()))
monster = sorted(list(monster))
if len(monster)==1:
  print(monster[0])
  exit()

while True:
  tmp = int(monster[-1]/monster[-2])
  monster[-1]-=monster[-2]*tmp
  monster = sorted(monster)
  if monster[-2]==0:
    print(monster[-1])
    exit()

Submission status: Time Limit Exceeded

Solution code:

n=int(input())
a=[int(i) for i in input().split()]
a.sort()
i=1
while True:
    if len(a)<=1:
        break
    else:
        if i>=len(a):
            i=1
        if a[i] % a[0]==0:
            del a[i]
        else:
            a[i]-=a[0]
            if a[i]<=0:
                del a[i]
    a.sort()
    i+=1
print(a[0])

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
from functools import reduce
from fractions import gcd
import numpy as np
arr = np.array(list(set(map(int, input().split()))))

from collections import deque
q = deque([arr])
ans = arr.min()
mi = reduce(gcd, arr)
while len(q) > 0:
    ar = q.popleft()
    ans = min(ar.min(), ans)
    if ans <= mi:
        break
    if ans <= reduce(gcd, ar):
        continue
    for mon in ar:
        tmp = (ar - 1) % mon + 1
        if np.any(ar != tmp):
            q.append(np.sort(np.unique(tmp)))

print(ans)

Submission status: Time Limit Exceeded

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

while(1):
    
    for i in range(len(A)-1):
        A[i+1] = A[i+1]-A[0]
        if(A[i+1] <=0):
            del A[i+1]
            break
    if(len(A)==1):
        break
    A.sort()
print(A[0])

Submission status: Time Limit Exceeded

Solution code:
N = input()

monsters_list = list(map(int, input().split()))
monsters_list.sort(reverse=True)

while len(monsters_list) >= 2:
    if monsters_list[1] == 0:
        break
    for i in range(len(monsters_list[:])):
        if 0 in monsters_list:
            monsters_list.remove(0)
        try:
            monsters_list[i] %= monsters_list[i+1]
        except IndexError:
            continue
        monsters_list.sort(reverse=True)

print(monsters_list[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
An = [int(n) for n in input().split()]
M = sorted(set(An))
mini=M[0]
            
while len(M) > 1:
    M = [mini] + [x-mini for x in M[1:] if x % mini != 0]
    M.sort()
    if 1 in M:
        mini=1
        break
    mini = min(mini,M[0])
print(mini)

Submission status: Time Limit Exceeded

Solution code:
#ABC118C-MonstersBattleRoyale.py

from sys import stdin
import numpy as np

input = stdin.readline

N = int(input())

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

A = set(A)
A = list(A)

def countzero(list):
    i = 0
    for a in list:
        if a == 0:
            i += 1
    return i

while len(A) != 1:
    a = countzero(A)
    A.sort()
    for i in range(a+1,len(A)):
        A[i] = A[i] % A[a]
    if a >= N-1:
        break

i = 0
while True:
    if A[i] != 0:
        print(A[i])
        break
    i += 1

Submission status: Time Limit Exceeded

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

m=min(a)
c=1
s=1
while(s):
    if m==1:
        print(c)
        s=0
    else:
        for j in range(m,1,-1):
            for v in a:
                if v%j!=0:
                    break
            else:
                c*=j
                for i in range(n):
                    a[i]/=j
                break
        else:
            s=0
            print(c)

Submission status: Time Limit Exceeded

Solution code:

n=int(input())
a=[int(i) for i in input().split()]
a.sort()
i=1
while True:
    if len(a)<=1:
        break
    else:
        if i>=len(a):
            i=1
        if a[i] % a[0]==0:
            del a[i]
        else:
            a[i]-=a[0]
            if a[i]==0:
                del a[i]
    a.sort()
    i+=1
print(a[0])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
An = [int(n) for n in input().split()]
M = sorted(set(An))
mini=M[0]
            
while len(M) > 1:
    for i,x in enumerate(M):
        M = [mini] + [x for x in M[1:] if x % mini != 0]
    M = list(map(lambda x:x-mini,M))
    M[0] = mini
    M.sort()
    if 1 in M:
        mini=1
        break
    mini = min(mini,M[0])
print(mini)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
a.sort()
i=1
while True:
    if len(a)==1:
        break
    else:
        if i>=len(a):
            i=1
        if a[i] % a[0]==0:
            del a[i]
        else:
            a[i]-=a[0]
            if a[i]==0:
                del a[i]
    a.sort()
    i+=1
print(a[0])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))   
if len(b)==1:
    print(b[0])
    exit()
else: 
    x=1
    while x>0:
        c=sorted(b)
        c[1]=c[1]-c[0]
        c=sorted(list(set(c)))
        if c[0]==1:
            x=0
        if len(c)==1:
            print(2)
            exit()
print(1)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = set(a)
t = []

while not len(ans) < 2:
    t = [s%min(a) for s in a if s%min(a) != 0]
    t.append(min(a))
    a = t
    ans = set(t)

d = list(ans)
print(d[0])

Submission status: Time Limit Exceeded

Solution code:
N = input()

monsters_list = list(map(int, input().split()))
monsters_list.sort(reverse=True)

while len(monsters_list) >= 2 and monsters_list[1] != 0:
    for i in range(len(monsters_list[:])):
        if 0 in monsters_list:
            monsters_list.remove(0)
        try:
            monsters_list[i] %= monsters_list[i+1]
        except IndexError:
            continue
        monsters_list.sort(reverse=True)

print(monsters_list[0])

Submission status: Time Limit Exceeded

Solution code:
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
    A=np.sort(A)
    for j in range(len(A)):
        if A[0] != 0:
            break
        A = np.delete(A, 0)
    if len(A) == 1:
        break
print (A[0])

Submission status: Time Limit Exceeded

Solution code:
import itertools
import copy

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

    com0 = None
    while True:
        com = list(itertools.combinations(A,2))
        if com0 == com:
            break
        com0 = copy.copy(com)
        for q in com:
            if q[0] != 0 and q[1] != 0:
                if q[0] > q[1]:
                    a1 = q[1]
                    a2 = q[0]
                else:
                    a1 = q[0]
                    a2 = q[1]
                a = a2 % a1
                if a == 1:
                    print(1)
                    return
                elif a == 0:  # a2はa1の倍数
                    if a2 in A:
                        A.remove(a2)
                else:
                    A.add(a)
        #print(A)
    print(min(A))

main()

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
An = [int(n) for n in input().split()]
M = sorted(set(An))
mini=M[0]
for i,x in enumerate(M):
    M = [mini] + [x for x in M[1:] if x % mini != 0]
            
while len(M) > 1:
    M = list(map(lambda x:x-mini,M))
    M[0] = mini
    M.sort()
    if 1 in M:
        mini=1
        break
#    while M[0]<1:
#        M.pop(0)
    mini = min(mini,M[0])
print(mini)

Submission status: Time Limit Exceeded

Solution code:
N = input()

monsters_list = list(map(int, input().split()))
monsters_list.sort(reverse=True)

while len(monsters_list) >= 2 and monsters_list[1] != 0:
    if 0 in monsters_list:
        monsters_list.remove(0)
    for i in range(len(monsters_list[:])):
        try:
            if monsters_list[i + 1] != 0:
                monsters_list[i] %= monsters_list[i+1]
        except IndexError:
            continue
        monsters_list.sort(reverse=True)

print(monsters_list[0])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
while True:
    if len(A) == 1:
        print(A[0])
        break
    A[A.index(max(A))] %= min(A)
    if 0 in A:
        A.remove(0)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[i for i in map(int,input().split())]
k=0
while len(A)!=1:
    if A[1]%A[0]!=0:
        A[1]=A[1]%A[0]
        k+=1
    else:
        A.remove(A[1])
    A.sort()
    if A[0]==1:
        break
print(A[0])

Submission status: Time Limit Exceeded

Solution code:
# import math
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
for start in range(N):
    for c in range(start+1, N):
        if a_list[start] % a_list[c] == 0:
            last_hp = a_list[c]
        elif a_list[c] % a_list[start] == 0:
            last_hp = a_list[start]
        else:
            continue
        # if min_last_hp == None:
        #     min_last_hp = last_hp
        if last_hp < min_last_hp:
            min_last_hp = last_hp

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

Submission status: Time Limit Exceeded

Solution code:
num_monster = int(input())
hplist = sorted(list(set(map(int, input().split()))))
if not hplist:
  print(0)
while len(hplist) != 1:
  new_hp = hplist[-1] % hplist[-2]
  del hplist[-1]
  if new_hp != 0:
    hplist.append(new_hp)
    hplist = list(set(hplist))
  hplist.sort()
print(hplist[0])

Submission status: Time Limit Exceeded

Solution code:
def sol(inp=input):
    n=int(inp())
    hps=sorted(map(int,inp().split()))

    while(len(hps)>1):
        maxhp=hps.pop()
        newhps=[maxhp%hp for hp in hps[:1] if maxhp%hp>0]
        hps=sorted(set(hps+newhps))
    return hps[0]
print(sol())

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
An = [int(n) for n in input().split()]
M = sorted(set(An))
mini=M[0]
for i,x in enumerate(M):
    M = [mini] + [x for x in M[1:] if x % mini != 0]
            
while len(M) > 1:
    if 1 in M:
        mini=1
        break
    M = list(map(lambda x:x-mini,M))
    M[0] = mini
    M.sort()
    while M[0]<1:
        M.pop(0)
    mini = min(mini,M[0])
print(mini)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
while True:
    if len(A) == 1:
        print(A[0])
        break
    A[A.index(max(A))] %= min(A)
    A = list(set(A))
    if 0 in A:
        A.remove(0)

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

Solution code:
def sol(inp=input):
    n=int(inp())
    hps=sorted(map(int,inp().split()))

    while(len(hps)>1):
        maxhp=hps.pop()
        newhps=[maxhp%hp for hp in hps if maxhp%hp>0]
        hps=sorted(set(hps+newhps))
    return hps[0]
print(sol())

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
i = input()
N = list(map(int, input().split(' ')))
def one_turn(l):
  l.sort()
  n = l[0]
  n2 = l[1]
  
  return np.array([n,n2]+[ i-n for i in l[2:] if ((i%n != 0)or(i%n2 != 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