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:
from collections import deque
N = int(input())
A = list(map(int, input().split()))

A.sort()
A = deque(A)
while len(A) > 1:
  s = []
  for i in range(len(A)-1):
    div = A[-1] % A[0]
    A.pop()
    if (div != 0) and (div not in s):
      s.append(div)
  s.append(A[0])
  s.sort()
  A = deque(s)
print(*A)

Submission status: Time Limit Exceeded

Solution code:
from collections import deque
N = int(input())
A = list(map(int, input().split()))

A.sort()
A = deque(set(A))
while len(A) > 1:
  s = []
  for i in range(len(A)-1):
    div = A[-1] % A[0]
    A.pop()
    if (div != 0) and (div not in s):
      s.append(div)
  s.append(A[0])
  s.sort()
  A = deque(s)
print(*A)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n=int(input())
a_=list(map(int,input().split()))
a=np.array(a_)
#print(a)
s=min(a)
for i in range(s,0,-1):
  if np.all(a%i==0):
    print(i)
    exit()

Submission status: Time Limit Exceeded

Solution code:
n = int(raw_input())
ais = map(int, raw_input().split())
def gcd(a,b):
	return gcd(b, a % b ) if b else a
m = min(ais)
for a in ais:
	for b in ais:
		a,b = min(a,b), max(a,b)
		if b% a:
			m = min(m, gcd(a,b))
print m

#6 = 3 * 2 +

Submission status: Time Limit Exceeded

Solution code:
import math
def computeGCD(x, y): 
  
    if x > y: 
        small = y 
    else: 
        small = x 
    for i in range(1, small+1): 
        if((x % i == 0) and (y % i == 0)): 
            gcd = i 
              
    return gcd 
n=int(input())
a=list(map(int,input().split()))
ans=computeGCD(a[0],a[1])
for i in range(2,n):
  ans=computeGCD(ans,a[i])
print(ans)

Submission status: Time Limit Exceeded

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



while len(S)!=1:
    
    S.sort()
    
    if S[1]%S[0]==0:
        S.pop(1)
    
    else:
        S[1]=S[1]%S[0]

    if S[0]==1:
        print(1)
        exit()
print(S[0])

Submission status: Time Limit Exceeded

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



while len(S)!=1:
    S.sort()
    
    
    if S[1]%S[0]==0:
        S.pop(1)
    
    else:
        S[1]=S[1]%S[0]
    if S[0]==1:
        print(1)
        exit()
print(S[0])

Submission status: Time Limit Exceeded

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

while a[-2] != 0:
    for i in range(n):
        if a[i] != 0:
            w = a[i]
            wi = i
            break
    
    for i in range(n):
        if i != wi:
            a[i] %= w
            
        a = sorted(a)
        
print(a[-1])

Submission status: Time Limit Exceeded

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

while a[-2] != 0:
    w = 10**9+1
    
    for i in range(n):
        a[i] %= w
        
        if a[i]!=0 and w==10**9+1:
            w = a[i]
            
        a = sorted(a)
        
print(a[-1])

Submission status: Time Limit Exceeded

Solution code:
def divisor(n): 
    i = 1
    table = []
    while i * i <= n:
        if n%i == 0:
            table.append(i)
            table.append(n//i)
        i += 1
    table = list(set(table))
    return table

def main():
    n = int(input())
    a = list(map(int, input().split()))
    
    ans = set(divisor(a[0]))
    for i in range(1, n):
        tmp = set(divisor(a[i]))
        ans = ans & tmp
    
    print(max(ans))

    
if __name__ == '__main__':
    main()

Submission status: Time Limit Exceeded

Solution code:
import itertools
import fractions
n=int(input())
a=list(map(int,input().split()))
ans = 10**18
for i,j in itertools.combinations(a,2):
	ans = min(ans, fractions.gcd(i, j))
print(ans)

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
def f(a,*b):
    if len(b)>1:
        return f(a,f(*b))
    b=b[0]
    if b:
        return f(b,a%b)
    return a
n=int(input())
a=list(map(int,input().split()))
print(f(*a))

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**6)
def f(a,*b):
    if len(b)>1:
        return f(a,f(*b))
    b=b[0]
    if b:
        return f(b,a%b)
    return a
n=int(input())
a=list(map(int,input().split()))
print(f(*a))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
i = 0
while i < N-1:
  
  if A[-1]%A[i]==0:
    A[-1] = 0
    i += 1
    A.sort()
  else:
    A[-1] = A[-1]%A[i]
    A.sort()
ans = A[-1]
print(ans)

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

    while max(a) - min(a) > 0:
        a.sort()
        a[-1] = a[-1]%a[0]
        if a[-1] == 0:
            del a[-1]

    print(min(a))

main()

Submission status: Time Limit Exceeded

Solution code:
import sys
input = sys.stdin.readline

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

    while max(a) - min(a) > 0:
        a.sort()
        a[-1] = a[-1]%a[0]
        if a[-1] == 0:
            del a[-1]

    print(min(a))

main()

Submission status: Time Limit Exceeded

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

while max(a) - min(a) > 0:
    a.sort()
    a[-1] = a[-1]%a[0]
    if a[-1] == 0:
        del a[-1]

print(min(a))

Submission status: Time Limit Exceeded

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

  if min(A)==1:
    print(1)
    exit()

  while len(A)>1:
    monster_min = A.pop(A.index(min(A)))
    for i in range(len(A)):
      A[i] %= monster_min
    A.sort()
    for i in A[:]:  
      if i == 0: A.remove(i)
      else: continue
    A.append(monster_min)

  print(A[0])

if __name__ == "__main__":
  main()

Submission status: Time Limit Exceeded

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

if min(A)==1:
  print(1)
  exit()

while len(A)>1:
  monster_min = A.pop(A.index(min(A)))
  for i in range(len(A)):
    A[i] %= monster_min
  A.sort()
  for i in A[:]:  
    if i == 0: A.remove(i)
    else: continue
  A.append(monster_min)

print(A[0])

Submission status: Time Limit Exceeded

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

if min(A)==1:
  print(1)
  exit()

while len(A)>1:
  monster_min = A.pop(A.index(min(A)))
  for i in range(len(A)):
    A[i] %= monster_min
  A.sort()
  for i in A[:]:  
    if i == 0: A.remove(i)
    else: continue
  A.append(monster_min)

print(A[0])

Submission status: Time Limit Exceeded

Solution code:
import fractions
n=int(input())
a=list(map(int,input().split()))
for _ in range(n-1):
    a1=a.pop(0)
    a2=a.pop(0)
    a.append(fractions.gcd(a1,a2))
print(a[0])

Submission status: Time Limit Exceeded

Solution code:
import bisect
import collections

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

s.sort()

while len(s) > 1:#最も体力のあるのが攻撃を受ける
    temp = s.pop()
    for j in s:
        damege = (temp//j)*j
    if temp != 0 and temp != damege:
        index = bisect.bisect_left(s,temp-damege)
        s.insert(index,temp-damege)

print(s[0])

Submission status: Time Limit Exceeded

Solution code:
import bisect
import collections

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

s.sort()

while len(s) > 1:#最も体力のあるのが攻撃を受ける
    temp = s.pop()
    for j in s:
        temp -= (temp//j)*j
    if temp != 0:
        index = bisect.bisect_left(s,temp)
        s.insert(index,temp)

print(s[0])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
import copy
for i in range(10**4):
  a.sort()
  wari=a[-2]
  if wari==0:
    print(a[-1])
    break
  a[-1]=a[-1]%wari

Submission status: Time Limit Exceeded

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


n = int(input())
li = list(map(int, input().split()))
r = 10000000000
for i in range(n):
    for j in range(i + 1, n):
        x = gcd(li[i], li[j])
        if r > x:
            r = x
print(r)

Submission status: Time Limit Exceeded

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


n = int(input())
li = list(map(int, input().split()))
li.sort()
r = 10000000000
for i in range(n):
    for j in range(i + 1, n):
        x = gcd(li[i], li[j])
        if r > x:
            r = x
print(r)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
# n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]
a.sort()
for i in range(1, n):
    a[i] %= a[0]
a.sort(reverse=True)
while a[1] != 0:
    min_idx = a.index(min(a))
    m = min(a[0:min_idx])
    for i in range(min_idx-1):
        a[i] %= m
    a.sort(reverse=True)
    
print(a[0])

Submission status: Time Limit Exceeded

Solution code:
import fractions
import math
n = int(input())
li = list(map(int,input().split()))

if len(list(set(li))) == 1:
    print(li[0])
else:
    all_li = []
    while len(li)>1:
        all_li = []
        for i,l in enumerate(li):
            if i == 0:
                continue
            else:
                all_li.append(fractions.gcd(l,li[i-1]))
        li = all_li
        #print(li,len(li))
    print(all_li[0])

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import heapq
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a)
    while True:
        mini = a[0]
        for i in range(1, len(a)):
            a[i] %= mini
            if sum(a[1:]) == 0:
                print(a[0])
                exit()

        a =[i for i in a if i!= 0]
        a = sorted(a)
resolve()

Submission status: Time Limit Exceeded

Solution code:
def resolve():
    import heapq
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a)
    while True:
        mini = a[0]
        for i in range(1, len(a)):
            a[i] %= mini
            if sum(a[1:]) == 0:
                print(a[0])
                exit()
        
        a =[i for i in a if i!= 0]
        a = sorted(a)
resolve()

Submission status: Time Limit Exceeded

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

tmp = A[0]
while True:
    if(len(A) == 1):
        break
    for i in range(len(A)-1,0,-1):
        A[i] = A[i] - (A[i]//tmp)*tmp
        if 0 in A:
            A.remove(0)
    else:
        A.sort()
        tmp = A[0]
print(A[0])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = sorted(list(set(a)))
while len(a) > 1:
  b = a.pop()
  d = []
  for i in a:
    c = b%i
    if c != 0:
      d.append(c)
  a = sorted(list(set(d+a)))
print(a[0])

Submission status: Time Limit Exceeded

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

while len(A) > 1:
    a = min(A)
    A = set(x - a if x != a else a for x in A)
    if 1 in A:
        A = {1}
print(list(A)[0])

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))

ans = []
for i in range(n):
  for j in range(i+1):
    ans.append(gcd(a[i], a[j]))
print(min(ans))

Submission status: Time Limit Exceeded

Solution code:
from fractions import gcd

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

ans = 10 ** 20

for i in range(N):
    for j in range(N):
        ans = min(ans, gcd(A[i], A[j]))

print(ans)

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python3
# 基本的には結果は１になるはず。例外は全てKの倍数である時のみ
# minで割って行ってあまりが1ならそれで終了、それ以外は、あまりが異なるものをひいていって、1になったら終了
# あまりのminで更新することができるかどうか
n = int(input())
a = list(map(int,input().split()))
div = min(a)
while True:
    cnt = 0
    for i in range(n):
        if a[i] % div== 0:
            cnt += 1
            a[i] = div
        a[i] = a[i] % div
    if cnt == n: break
print(div)

Submission status: Time Limit Exceeded

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

while len(a)>1:
  a.sort()
  a=[i%a[0] for i in a if a.index(i) != 0] + [a[0]]
  a=[i for i in a if i > 0]

print(a[0])

Submission status: Time Limit Exceeded

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

while len(a)>1:
  a.sort()
  a=[i%a[0] for i in a if a.index(i) != 0] + [a[0]]
  a=[i for i in a if i > 0]

print(a[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
HPs = list(map(int,input().split()))
while True:
    min_hp = min(HPs)
    for i in range(len(HPs)):
        if i == HPs.index(min_hp):
            continue
        HPs[i] = HPs[i] % min_hp
    for j in range(HPs.count(0)):
        if HPs.count(0)==len(HPs):
            print(HPs[0])
            exit()
        HPs.remove(0)
    if len(HPs)==1:
        break

print(HPs[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
HPs = list(map(int,input().split()))
while(True):
    min_hp = min(HPs)
    max_hp = max(HPs)
    HPs[HPs.index(max_hp)] = max_hp % min_hp
    try:
        while(True):
            HPs.remove(0)
            if len(HPs)==1:
                break
    except:
        continue
    if len(HPs) == 1:
        break
print(HPs[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
HPs = list(map(int,input().split()))
while(True):
    min_hp = min(HPs)
    max_hp = max(HPs)
    HPs[HPs.index(max_hp)] = max_hp % min_hp
    try:
        HPs.remove(0)
    except:
        continue
    if len(HPs) == 1:
        break
print(HPs[0])

Submission status: Time Limit Exceeded

Solution code:
def solve(a):
    a=sorted(a)
    ans=a[0]#暫定最小

    if len(set(a))!=1:
        for _ in range(a[0]):
            for i in range(n):
                amari=a[i]%ans
                
                if amari>0:
                    if amari<ans:
                        ans=amari
                    else:
                        exit()
            if ans==1:
                break
    print(ans)


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

Submission status: Time Limit Exceeded

Solution code:

def solve(a):
    a=sorted(a)
    ans=a[0]#暫定最小

    if len(set(a))!=1:
        for _ in range(a[0]):
            for i in range(n):
                amari=a[i]%ans
                
                if amari>0:
                    if amari<ans:
                        ans=amari
            if ans==1:
                break
    print(ans)

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

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
ans=a[0]#暫定最小

amari=[ans]
if len(set(a))!=1:
    for _ in range(a[0]):
        for i in range(n):
            if a[i]%ans>0:
                amari+=[a[i]%ans]
            ans=min(amari)
        if ans==1:
            break
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a=list(map(int,input().split()))
a=sorted(a)
ans=a[0]#暫定最小

amari=[ans]
if len(set(a))!=1:
    for _ in range(a[0]):
        for i in range(n):
            if a[i]%ans>0:
                amari+=[a[i]%ans]
            ans=min(amari)

print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
while(a[-2] != 0):
    a[-1] %= a[-2]
    if a[-1] == 1:
        break
    else:
        pass
    a.sort()
print(a[-1])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())

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

from fractions import gcd

m = max(A)
for i in A:
    for j in A:
        m = min(m, gcd(i, j))
print(m)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
lista = sorted(list(map(int, input().split())))
length = len(lista)
while length>1:
    #print(length)
    #print(lista)
    for n in range(1, length):
        lista[n] = lista[n]%lista[0]
    #print(lista)
    lista.sort()
    #print(lista)
    lista = list(set(lista))
    if lista[0] == 0:
        lista.remove(0)
    #print(lista)
    length = len(lista)
print(lista[0])

Submission status: Time Limit Exceeded

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

while len(a) >= 2:
    min_a = min(a)

    # 最小値が２つある場合に一回はskipする
    flag = False
    for i in range(len(a)):
        if a[i] == min_a and not flag:
            flag = True
            continue
        if flag or a[i] != min_a:
            a[i] = a[i] % min_a
    while True:
        if a.count(0) > 0:
            a.remove(0)
        else:
            break
print(a[0])

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
A=[int(x) for x in input().split()]
while len(A)>1:
  A.sort
  
  for i in range(1,len(A)):
    A[i]=A[i]%A[0]
  
  A.sort()
  
  while A[0]==0:
    A.sort()
    if A[0]==0:
      A.pop(0)
  
print(*A)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())), reverse=True)

#aの要素の最大公約数を求める
while len(a) != 1:
    j = a[0]
    k = a[1]
    p = 1 # 0以外である必要がある
    while p != 0:
        p = j % k
        if p != 0:
            j, k = k, p
    del a[:2]
    a.insert(0, k)
print(a[0])

Submission status: Time Limit Exceeded

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

m = min(a)
while any(map(lambda x: x%m, a)):
    m -= 1

print(m)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
m = [int(x) for x in input().split()]
min_diff = float('inf')
ii,jj = None,None
for i in range(n-1):
  for j in range(i+1,n):
    mm = m[i] % m[j]
    if mm != 0 and mm < min_diff:
      min_diff = mm
      ii,jj = i,j
    mm = m[j] % m[i]
    if mm != 0 and mm < min_diff:
      min_diff = mm
      ii,jj = j,i
if ii is None:
  ans = min(m)
else:
  mmin = min(m[ii],m[jj])
  mmax = max(m[ii],m[jj])
  while mmin > 0 and mmax > 0:
      f = mmax // mmin
      if f == 0:
        mmax -= mmin
      else:
        mmax -= mmin*f
      mmax, mmin = mmin, mmax
  some_ans = mmax
  ans = min(min(m), some_ans)
print(ans)

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
m = [int(x) for x in input().split()]
min_diff = float('inf')
ii,jj = None,None
for i in range(n-1):
  for j in range(i+1,n):
    mm = m[i] % m[j]
    if mm != 0 and mm < min_diff:
      min_diff = mm
      ii,jj = i,j
    mm = m[j] % m[i]
    if mm != 0 and mm < min_diff:
      min_diff = mm
      ii,jj = j,i
if ii is None:
  ans = min(m)
else:
  mmin = min(m[ii],m[jj])
  mmax = max(m[ii],m[jj])
  while mmin > 0 and mmax > 0:
      f = mmax // mmin
      mmax -= mmin*f
      mmax, mmin = mmin, mmax
  some_ans = mmax
  ans = min(min(m), some_ans)
print(ans)

Submission status: Time Limit Exceeded

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

if all([i % min(lst) == 0 for i in lst]):
    print(min(lst))
    exit()

gcm = 1
j = 2
lmt = int(min(lst) ** 0.5) + 1
while j <= lmt:
    if all([i % j == 0 for i in lst]):
        lst = [i / j for i in lst]
        gcm *= j
    else:
        j += 1

print(gcm)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int, input().split()))
As.sort()
min_a = max(As)
least = min(As)
mods_set = list()
while min_a > least:
    for a in As:
        mods = [b % a for b in As if b % a != 0]
        mods_set += mods
    #print(mods_set)
    if len(mods_set) == 0:
        break
    else:
        least = min(mods_set)
        As = mods_set
        mods_set = list()
print(least)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
As = list(map(int, input().split()))
As.sort()
min_a = max(As)
least = min(As)
mods_set = set()
while min_a > least:
    for a in As:
        mods = set(b % a for b in As if b % a != 0)
        mods_set |= mods
    #print(mods_set)
    if len(mods_set) == 0:
        break
    else:
        least = min(mods_set)
        As = mods_set
        mods_set = set()
print(least)

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
N = int(input())
Alist = np.array(list(map(int, input().split())))
while len(Alist) != 1:
    min_index = np.argmin(Alist)
    min_num = Alist[min_index]
    Alist = np.where(Alist % min_num == 0, 0, Alist)
    Alist[min_index] = min_num
    Alist = Alist[Alist.nonzero()]

print(Alist[0])

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:
n = int(input())
*a, = sorted(map(int, input().split()))

m = a[0]
while any(map(lambda x: x%m, a)):
    a = sorted([m] + list(map(lambda x: x-m, a[1:])))
    m = a[0]
    if m == 0:
        a = a[1:]
        m = a[0]

print(m)

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
m = A[0]
for i in range(m-1):
    for j in range(1,len(A)):
        A[j] = A[j] % A[0]
    A = [k for k in A if k != 0]
    A.sort()

print(A[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
 
A = list(map(int,input().split()))
 
A = sorted(A)[0:2]
 
INF = 10 ** 9

for i in range(0,INF):
	A[1] % A[1] - A[0]
	if A[1] < A[0]:
		A[1],A[0] = A[0],A[1]
	if A[0] <= 0:
		break
		
if A[0] == 1:
	print(1)
else:print(A[1])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())

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

A = sorted(A)[0:2]

INF = 10 ** 9

for i in range(0,INF):
	A[1] = A[1] - A[0]
	if A[1] < A[0]:
		A[1],A[0] = A[0],A[1]
	if A[0] < 0:
		break
	
print(A[1])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
A=[]*n
A[:]=map(int,input().split())

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

ans=10**9
for i in range(n-1):
  for j in range(i+1,n):
    ans=min(ans,gcd(A[i],A[j]))
print(ans)

Submission status: Time Limit Exceeded

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

# 体力最小のモンスターが他全員に攻撃することを繰り返す。ただし体力0にはしない
# 全員同じ体力になったら終了

while len(set(A)) >= 2:
    A = list(set(A))
    A = [x%min(A) if x%min(A) != 0 else min(A) for x in A]
    
print(A[0])

Submission status: Time Limit Exceeded

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

# 体力最小のモンスターが他全員に攻撃することを繰り返す。ただし体力0にはしない
# 全員同じ体力になったら終了

while len(set(A)) >= 2:
    A = [x%min(A) if x%min(A) != 0 else min(A) for x in A]

print(A[0])

Submission status: Time Limit Exceeded

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

a=min(A)
ans=0

for i in range(1,int(a**0.5)//1+1):
    judge=True
    for item in A:
        if item%i!=0:
            judge=False
    if judge:
        ans=max(ans,i)

    judge=True
    for item in A:
        if item%(a//i)!=0:

            judge=False
    if judge:
        ans=max(ans,(a//i))
        
print(ans)

Submission status: Time Limit Exceeded

Solution code:

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

while True:
    if min(A) == sum(A):
        break
    minA = A.index(min(A))
    maxA = A.index(max(A))
    A[maxA] = max(A)%min(A)
    if A[maxA]==0:
        A.pop(maxA)
print(min(A))

Submission status: Time Limit Exceeded

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

if N%2==1:
    A.append(A[-1])

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

P=[]
for i in range(len(A)//2):
    P.append(gcd(A[2*i],A[2*i+1]))

ans=1
for i in range(1,min(P)+1):
    g=1
    for j in range(len(P)):
        if P[j]%i!=0:
            g-=1
            break
    if g==1:
        ans=i

print(ans)

Submission status: Time Limit Exceeded

Solution code:
import fractions
import itertools
n = int(input())
l = [int(i) for i in input().split()]

m = list(itertools.combinations(l,2))

m = [fractions.gcd(i[0],i[1]) for i in m]

print(min(m))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort(reverse=True)
isContinue = True
while isContinue:
  for j in range(1,n):
    temp = a[0]
    a[0] = a[0]%a[j] if a[0]%a[j] > 0 else temp
    if a[0] != temp:
      a.sort(reverse=True)
      break
    if j == n-1 and a[0]%a[j] == 0:
      isContinue = False
print(min(a))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
flg=1
while flg>0:
  flg=0
  for i in range(n):
    j = a.index(max(a))
    if a[j] % a[i] > 0:
      a[j] = a[j] % a[i]
      flg=1
print(min(a))

Submission status: Time Limit Exceeded

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

while len(a) > 1:
    mina = min(a)
    for i in a:
        if i == mina:
            continue
        elif i % mina == 0:
            a.remove(i)
        else:
            a[a.index(i)] = i % mina
            
print(a[0])

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
num_ls = sorted([x for x in map(int, input().split(' '))])
while True:
    dam = []
    searchMin = [ x for x in num_ls if x != 1 ]
    for x in num_ls:
        div = x % min(searchMin)
        if div == 0:
            dam.append(x)
        else:
            dam.append(div)

    if num_ls == dam:
        break
    else:
        num_ls = dam

print(min(num_ls))

Submission status: Time Limit Exceeded

Solution code:
num = int(input())
num_ls = sorted([x for x in map(int, input().split(' '))])
while True:
    dam = []
    for x in num_ls:
        div = x % min(num_ls)
        if div == 0:
            dam.append(x)
        else:
            dam.append(div)
    if num_ls == dam:
        break
    else:
        num_ls = dam

print(min(num_ls))

Submission status: Time Limit Exceeded

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

while True:
    a = sorted(a)
    while a[0] <= 0:
        a.pop(0)
        if len(a) == 1:
            print(a[0])
            exit(0)
    if a[1] % a[0] == 0:
        m = a[1]
    else:
        m = a[1] - (a[1] % a[0])
    a = list(map(lambda x: x-m, a))
    a[0] += m

Submission status: Time Limit Exceeded

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

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

Submission status: Time Limit Exceeded

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

m = len(l)
ans = 0
while m > 1:
    former = [0]*m
    for i in range(m):
        former[i] = l[i]
    l = []#初期化
    for i in range(1,m):
        num = former[0]
        l.append(num)
        if former[i]%num != 0:
            l.append(former[i]%num)
    l.sort()
    if l[0] == 1:
        ans = 1
        break
    m = len(l)
if ans == 1:
    print(ans)
else:
    print(l[0])

Submission status: Time Limit Exceeded

Solution code:
n = input()

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

while(True):
	minIndex = monster.index(min(monster))
	for i in range(len(monster)): 
		if i == minIndex or monster[i] == 0:
			continue
		if monster[i] % monster[minIndex] == 0:
			monster[i] = 0
		else:
			monster[i] -= monster[minIndex] * (monster[i]//monster[minIndex])
	while(monster.count(0) > 0):
		monster.pop(monster.index(0))
	if len(monster) == 1:
		print(monster[0])
		break

Submission status: Time Limit Exceeded

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

#print(len(a))
a.sort()
while len(a)!=1 and (1 in a )==False:
    i=0
    while i!=n:
        #print(a[i]%a[0])
        #print (a[i]%a[0] in a)
        if i==a.index(min(a)):
            i+=1
            #print("suru-")


        elif (a[i]%min(a) in a) ==False and a[i]%min(a)!=0:
            a[i]=a[i]%min(a)
            i+=1
            #print (a)
        else:
            del a[i]
            n-=1
            #print(a,"del",i)
#print(a)
print(min(a))

Submission status: Time Limit Exceeded

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

#print(len(a))
while len(a)!=1 and (1 in a )==False:
    i=0
    while i!=n:
        #print(a[i]%a[0])
        #print (a[i]%a[0] in a)
        if i==a.index(min(a)):
            i+=1
            #print("suru-")


        elif (a[i]%min(a) in a) ==False and a[i]%min(a)!=0:
            a[i]=a[i]%min(a)
            i+=1
            #print (a)
        else:
            del a[i]
            n-=1
            #print(a,"del",i)
#print(a)
print(min(a))

Submission status: Time Limit Exceeded

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

#print(len(a))
while len(a)!=1 and (1 in a )==False:
    i=1
    a.sort()
    while i!=n:
        #print(a[i]%a[0])
        #print (a[i]%a[0] in a)
        if (a[i]%a[0] in a) ==False and a[i]%a[0]!=0:
            a[i]=a[i]%a[0]
            i+=1
            #print (a)
        else:
            del a[i]
            n-=1
            #print(a,"del")
a.sort()
print(a[0])

Submission status: Time Limit Exceeded

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

#print(len(a))
while len(a)!=1:
    i=1
    a.sort()
    while i!=n:
        #print(a[i]%a[0])
        #print (a[i]%a[0] in a)
        if (a[i]%a[0] in a) ==False and a[i]%a[0]!=0:
            a[i]=a[i]%a[0]
            i+=1
            #print (a)
        else:
            del a[i]
            n-=1
            #print(a,"del")

print(a[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 10 ** 12


def progress():
    for i in range(N):
        for j in range(N):
            if i == j:
                continue
            if (A[j] % A[i] != 0) and (A[j] // A[i]):
                A[j] %= A[i]
                progress()
            if min(A) == 1:
                break
        if min(A) == 1:
            break
    return min(A)

ans = progress()
print(ans)

Submission status: Time Limit Exceeded

Solution code:
N=int(input())
L=list(map(int,input().split()))
while len(L)>1:
	m=L.index(max(L))
	L[m]=max(L)-min(L)
	if L[m]<=0:
		L.pop(m)
print(L[0])

Submission status: Time Limit Exceeded

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

def attack(A):
  A = list(set(A))
  A.sort()
  if A[0] ==0:
    A.pop(0)
  attack_mons = A[0]
  new_A = [A[0]]
  for i in range(1,len(A)):
    new_A.append(A[i]%min(A))
  return new_A

new_A = attack(A)
while A!=new_A:
  A = new_A
  new_A = attack(new_A)

print(min(new_A))