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:
n = int(input())
arr = list(map(int,input().split()))

while True:
    t = max(arr) % min(arr)
    if t == 0:
        arr.pop(arr.index(max(arr)))
    else:
        arr[arr.index(max(arr))] = t
    
    if len(arr) == 1:
        print(min(arr))
        break

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

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

mi = min(A)

def mak(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list
    
P = mak(mi)[::-1]
lenp = len(P)

Q = np.array(A)

an = 1
for i in range(lenp):
    R = Q % P[i]
    if any(R) == 0:
        an = P[i]
        break
    else:
        Q = R

print(an)

Submission status: Time Limit Exceeded

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

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

        a = new

        #while True:
        #    try:
        #        a.remove(0)
        #    except:
        #        break

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



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

print(life[0])

Submission status: Time Limit Exceeded

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[0])

Submission status: Time Limit Exceeded

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 = set()
        for a, b in itertools.product(As, repeat=2):
            if (a, b) in dp:
                As_next.add(dp[(a, b)])
            else:
                v = a % b
                dp[(a, b)] = v
                As_next.add(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: Time Limit Exceeded

Solution code:
N = int(input())

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

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

print(A[0])

Submission status: Time Limit Exceeded

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

while len(A) >= 2:
    x = A.pop(A.index(max(A)))
    n = x
    for i in range(len(A)):
        if x % A[i] > 0:
            n = min(n, x % A[i])

    if n == x:
        pass
    else:
        A.append(n)

print(A[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
aA=[int(_) for _ in input().split()]
iMin = min(aA)
iMax = max(aA)


def ggg(i,j):
    if i < j :
        i,j = j,i
    i %= j
    if i == 0:
        return j
    else:
        return ggg(j,i)

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

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

while True:
    if len(A) == 1:
        break
    max_i = A.index(max(A))
    min_i = A.index(min(A))
    life = A[max_i] % A[min_i]
    if life == 0:
        A.pop(max_i)
    else:
        A[max_i] = life

print(A[0])

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
l = list(map(int, input().split()))
while len(l) > 1:
  m = max(l)
  l.remove(m)
  sub_m = max(l)
  a = m % sub_m
  if a != 0:
    l.append(a)
print('{}'.format(l.pop(0)))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
while min(a)!=1 and len(a)!=1:
    a = sorted(a)
    a = [i%min(a) for i in a[1:]]+[min(a)]
    a = [i for i in a if i!=0]
print(min(a))

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a = list(map(int, input().split()))
l=min(a)
b=True
c=a
while b==True:
    c=[a[i]%l for i in range(n)]
    if max(c)==0:
        print(l)
        break
    else:
        l=max(c)

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort

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

def solve():
    c = A[-1]%A[-2]
    del(A[-1])
    if c>0:
        insort(A, c)
    return A

def solve2():
    m = min(A)
    for i in range(len(A)):
        if A[i]!=m:
            tmp = A[i]%m
            if tmp in A:
                A[i] = 0
            else:
                A[i] = tmp
    while 0 in A:
        A.remove(0)


while(len(A)>1):
    solve2()
    #print(A)
print(A[0])

Submission status: Time Limit Exceeded

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

import itertools


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

    As = set(As)

    while True:
        As_next = set()
        for a, b in itertools.product(As, repeat=2):
            As_next.add(a % b)

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

        As = As_next

    print(min(As))

Submission status: Time Limit Exceeded

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

while len(A) >= 2:
    x = A.pop(A.index(max(A)))
    n = x
    for i in range(len(A)):
        if x % A[i] > 0:
            n = min(x, x % A[i])

    if n == x:
        pass
    else:
        A.append(n)

print(A[0])

Submission status: Time Limit Exceeded

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

# print(aa)
def mod(xx):
    bb=[]
    minX = min(xx)
    for i in range(len(xx)):
        b = xx[i] % minX if xx[i]>min(xx) else xx[i]
        if b>0:
            bb.append(b)
    return list(set(bb))

while True:
    bb = mod(aa)
    # print(bb)
    if min(aa)==min(bb) or min(bb)==1:
        break
    aa=bb
print(min(bb))

Submission status: Time Limit Exceeded

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:
            try:
                a.remove(0)
            except:
                break

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



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

box.sort()

while(1):

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

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

Submission status: Time Limit Exceeded

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(min(a))
            exit()



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

print(life[0])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
enemy=(list(map(int,input().split())))
enemy.sort()
enemy.reverse()
while len(enemy)>1:
    enemy[0]=enemy[0]%enemy[1]
    if enemy[0]==0:
        del enemy[0]
    elif enemy[0]==1:
        break
    enemy.sort()
    enemy.reverse()
print(enemy[0])

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
while not all(a==0 for a in A[0:-1]):
    A.sort()
    A[-1] = A[-1] - A[-2]
print(A[-1])

Submission status: Time Limit Exceeded

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

# print(aa)
def mod(xx):
    bb=[]
    for i in range(len(xx)):
        b = xx[i] if (0<xx[i] and xx[i] <= min(xx)) else xx[i] % min(xx)
        if b>0:
            bb.append(b)
    return list(set(bb))

while True:
    bb = mod(aa)
    # print(bb)
    if min(aa)==min(bb):
        break
    aa=bb
print(min(bb))

Submission status: Time Limit Exceeded

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

A = list(set(A))
A.sort(reverse=True)

while True:
    if len(A) == 1:
        break
    A[0] = A[0] % A[1]
    if A[0] == 0:
        A.pop(0)
    A = list(set(A))
    A.sort(reverse=True)

print(A[0])

Submission status: Time Limit Exceeded

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())
A = [int(i) for i in input().split()]
#N = 4
#A = [2, 10, 8, 40]
print(slv(N, A))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
A = list(map(int,input().split()))
while True:
    if A.count(0) == n - 1:
        print(max(A))
        exit()
    else:
        B = [ _  for _ in A if _ != 0  ]
        attack = min(B)
        sn = A.index(attack)
        
        for i in range(n):
            if A[i] == 0:
                pass
            else:
                if i != sn:
                    A[i] = A[i] - attack
                else:
                    pass

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
a_s=list(map(int,input().split()))
while True:
    a_s=set(a_s)
    a_s.discard(0)
    a_s=list(a_s)
    index=a_s.index(min(a_s))
    for i in range(len(a_s)):
        if i!=index and min(a_s)!=0:
            a_s[i]=a_s[i]%min(a_s)
    if len(a_s)==1:
        break
print(sum(a_s))

Submission status: Time Limit Exceeded

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



def f(l, s):
    return s if l % s == 0 else f(s, l % s)
    
z = f(max(L), min(L))

for i in L:
    z=f(i,z)

for i in range(1,10**6):
    if max(L)>=i and i%z==0:
        print(i)
        exit()
print(z)

Submission status: Time Limit Exceeded

Solution code:
import copy
n = int(input())
A = list(map(int,input().split()))
while True:
    if A.count(0) == n - 1:
        print(max(A))
        exit()
    else:
        B = [ _  for _ in A if _ != 0  ]
        attack = min(B)
        sn = A.index(attack)
        
        for i in range(n):
            if A[i] == 0:
                pass
            else:
                if i != sn:
                    A[i] = A[i] - attack
                else:
                    pass

Submission status: Time Limit Exceeded

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

A.sort(reverse=True)

while True:
    if len(A) == 1:
        break
    A[0] = A[0] % A[1]
    if A[0] == 0:
        A.pop(0)
    A.sort(reverse=True)

print(A[0])

Submission status: Time Limit Exceeded

Solution code:
from bisect import insort

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

def solve():
    c = A[-1]%A[-2]
    del(A[-1])
    if c>0:
        insort(A, c)
    return A


while(len(A)>1):
    solve()
    #print(A)
print(A[0])

Submission status: Time Limit Exceeded

Solution code:
n=int(input())
enemy=(list(map(int,input().split())))
enemy.sort()
enemy.reverse()
while len(enemy)>1:
    enemy[0]=enemy[0]%enemy[1]
    if enemy[0]==0:
        del enemy[0]
    enemy.sort()
    enemy.reverse()
print(enemy[0])

Submission status: Time Limit Exceeded

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

Submission status: Time Limit Exceeded

Solution code:
# #A
# a,b = map(int,input().split())

# print((a+b) if b%a==0 else (b-a))

#B
# n,m = map(int,input().split())
# aa = []
# kk=[]
# for i in range(n):
#     tmp = list(map(int,input().split()))
#     kk.append(tmp[0])
#     aa.append(tmp[1:])

# aaa = []
# for a in aa:
#     for ai in a:
#         aaa.append(ai)
# ans=0
# for i in range(m):
#     if aaa.count(i+1)==n:
#         ans+=1
# print(ans)

#C
n = int(input())
aa = list(map(int,input().split()))

# print(aa)
def mod(xx):
    bb=[]
    for i in range(len(xx)):
        b = xx[i] if (0<xx[i] and xx[i] <= min(xx)) else xx[i] % min(xx)
        if b>0:
            bb.append(b)
    return bb

while True:
    bb = mod(aa)
    # print(bb)
    if min(aa)==min(bb):
        break
    aa=bb
print(min(bb))

Submission status: Time Limit Exceeded

Solution code:
N = int(input())
A = list(map(int, input().split()))
sort = sorted(A)
amari = []
while len(amari) != 1:
  amari.clear()
  if 0 in sort: sort.remove(0)
  for item in sort:
    if item%sort[0] not in amari:
      amari.append(item%sort[0])
  last_sort0 = sort[0]
  sort = sorted(amari[:])
  sort.append(last_sort0)

print(last_sort0-amari[0])

Submission status: Time Limit Exceeded

Solution code:

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

    while True:
        m = find_min(a)
        zero = 0
        for i in range(n):
            if a.index(m) != i:
                a[i] = a[i] % m
                if a[i] == 0:
                    zero += 1

        if zero == n -1:
            print(find_min(a))
            exit()



def find_min(a):
    a.sort()
    for i in a:
        if i >0:
            return i




if __name__ == "__main__":
        main()

Submission status: Time Limit Exceeded

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

A.sort(reverse=True)

while True:
    if A.count(0) == N-1:
        break
    A[0] = A[0] % A[1]
    A.sort(reverse=True)

print(max(A))

Submission status: Time Limit Exceeded

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

while len(A) > 1:
    A = set([a % b for b in A for a in A if a % b != 0])

print(min(A))

Submission status: Time Limit Exceeded

Solution code:
n = int(input())
a = list(map(int,input().split()))
def f(a,b):
    if b==0:
        return a
    else:
        return f(b,a%b)
a = sorted(a)
ans = float('inf')
for i in range(len(a)-1):
    for j in range(i+1,len(a)):
        ans = min(ans,f(a[i],a[j]))
print(ans)

Submission status: Time Limit Exceeded

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

def solve(A):
    A.sort()
    #b = A[-1]//A[-2]
    c = A[-1]%A[-2]
    if c==0:
        del(A[-1])
    else:
        A[-1] = c
    return A


while(len(A)>1):
    solve(A)
print(A[0])

Submission status: Time Limit Exceeded

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import bisect

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    al.sort()
    while len(al) > 1:
        p = al[-1] % sum(al[:-1])
        q = al[-1]
        al = al[:-1]
        if p == 0:
            continue
        if p == q:
            q -= al[-1]
            if q <= 0:
                continue
            p = q
        bisect.insort(al, p)
    print(al[0])

if __name__=="__main__":
    solve()

Submission status: Time Limit Exceeded

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools


sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    N = I()
    A = LI()
    #  print(N, A)


    # 余りを活用する
    A.sort(reverse=True)
    #  print(A)
    while len(A) > 1:
        A[0] = A[0] % A[1]
        if A[0] == 0:
            del A[0]
        A.sort(reverse=True)

    print(A[0])

main()

Submission status: Time Limit Exceeded

Solution code:
#!venv/bin/python

import math
import numpy as np
import random
import copy
import statistics 
import bisect

#N,M = [int(x) for x in input().split()]

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

alives = N
A = sorted(A)

while alives > 1:
    biggest = A.pop(-1)
    second = A[-1]
    times = int(math.floor(biggest / second))
    new_hp = biggest - second * times
    if new_hp <= 0:
        alives -= 1
    bisect.insort_left(A, new_hp)

for a in A:
    if a > 0:
        print (a)
        break

Submission status: Accepted

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

import math

def gcd_list(nums):
  gcd = nums[0]
  for i in range(1,len(nums)):
    gcd = math.gcd(gcd,nums[i])
  return gcd

print(gcd_list(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

ans = A_list[0]
for i in range(N-1):
    ans = math.gcd(A_list[i+1], ans)

print(ans)

Submission status: Accepted

Solution code:
from math import gcd

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

res = 0

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

print(res)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

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

Submission status: Accepted

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

g = A[0]

for i in range(1, N):
	g = math.gcd(g, A[i])
	
print(g)

Submission status: Accepted

Solution code:
import math

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

ans = 10**10
for i in range(1, n):
    ans = min(ans, math.gcd(a[0], a[i]))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# 62 C - Monsters Battle Royale
import math
import functools
N = int(input())
A = list(map(int,input().split()))

# すべての要素の GCD
ans = functools.reduce(math.gcd,A)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

#import
#import math
#import numpy as np
N = int(input())
A = list(map(int, input().split()))

def gcd(x, y):
    if x < y:
        t = x
        x = y
        y = t

    if y == 0:
        return x

    else:
        return gcd(y, x % y)

a = gcd(A[0], A[1])

for i in range(2, N):
    a = gcd(a, A[i])

print(a)

Submission status: Accepted

Solution code:
n = int(input())

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

import math

temp = al[0]

for i in range(1,n):
    temp = math.gcd(temp,al[i])
    
print(temp)

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    # n, m = map(int, input().split())
    a = list(map(int, input().split()))
    # s = input()
    # h = [int(input()) for _ in rane(n)]

    while True:
        currentmin = 10**10
        currentminIndex = 0
        for i in range(n):
            if currentmin > a[i] and a[i] != 0:
                currentmin = a[i]
                currentminIndex = i
        for i in range(n):
            if i != currentminIndex:
                a[i] = a[i] % currentmin
        count = 0
        for i in range(n):
            if a[i] != 0:
                count += 1
        if count == 1:
            break

    print(max(a))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A_list = [float('inf')] * N

ans = min(A)
while max(A_list) > 0:
    mi = ans
    for i,a in enumerate(A):
        amari = a % mi
        A_list[i] = amari
        if amari != 0:
            ans = min(ans,amari)

print(ans)

Submission status: Accepted

Solution code:
from math import gcd

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

g = a[0]
for i in a:
    g = gcd(i, g)

print(g)

Submission status: Accepted

Solution code:
import math

def main():
    _ = input()
    A = list(map(int, input().split()))
    ans = A[0]
    for a in A[1:]:
        ans = math.gcd(ans, a)
    print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# author:  Taichicchi
# created: 14.09.2020 22:18:44

import sys
from math import gcd

N = int(input())

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

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

print(ans)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 14 17:37:26 2020

@author: liang
"""
N = int(input())
A = [int(x) for x in input().split()]

from math import gcd

A.sort()
g = A[0]
for i in range(1,N):
    g = gcd(g,A[i]) 
    #print(g)
print(g)

Submission status: Accepted

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

Submission status: Accepted

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

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

print(gcd(a))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

ans = math.gcd(A[0],A[1])
for i in range(2,n):
    ans = math.gcd(ans, A[i])
    
print(ans)

Submission status: Accepted

Solution code:
from math import *
n = int(input())
a = sorted(map(int, input().split()))
g = a[0]
for i in range(1,n):
  g = gcd(g, a[i])
print(g)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b

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

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

    print(gcd(*A))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import gcd

N = int(input())
A = list(map(int, input().split()))
min_ = 0
gcd_ = A[0]
for i in range(1, N):
    gcd_ = gcd(A[i], gcd_)
print(gcd_)

Submission status: Accepted

Solution code:
import numpy as np

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

gcd = np.frompyfunc(np.gcd,2,1)

print(gcd.reduce(a))

Submission status: Accepted

Solution code:
import numpy as np
from functools import reduce
_ = input()
print(reduce(np.gcd, map(int,input().split())))

Submission status: Accepted

Solution code:
import numpy as np

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

ans = a[0]

for i in range(1,len(a)):
    ans = np.gcd(a[i],ans)

print(ans)

Submission status: Accepted

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


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

tmp = gcd(l[0],l[1])
for i in range(2,len(l)):
    tmp = gcd(tmp,l[i])

print(tmp)

Submission status: Accepted

Solution code:
import math

N = int(input())
A = list(map(int, input().split()))
ans = A[0]

for a in A[1:]:
    ans = math.gcd(ans, a)
print(ans)

Submission status: Accepted

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

a.sort()

def mod():
    for i in range(1, len(a)):
        # print("--------")
        # print(a[i])
        # print(a[i] % a[0])
        # print("--------")
        if(a[i] % a[0] != 0):
            a[i] = a[i] % a[0]
        else:
            a[i] = a[0]
        # print(a[i])
    a.sort()
    return a

# for i in range(4):
#     a = mod()
#     print(a)

while(a.count(a[0]) != len(a)):
    a = mod()
    # print(a)

print(a[0])

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

n = int(input())
*a, = map(int, input().split())
print(gcd(*a))

Submission status: Accepted

Solution code:
from math import *

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

ans=A[0]

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations, product
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

N,A = ilint()
# ans = A[0]
# for a in A[1:]:
#     ans = gcd(ans,a)
# print(ans)
from functools import reduce
def lgcd(l):
    return reduce(gcd, l)
print(lgcd(A))

Submission status: Accepted

Solution code:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from itertools import combinations, permutations, product
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

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

Submission status: Accepted

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

Submission status: Accepted

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

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


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

Submission status: Accepted

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

def gcd(a,b):
    while True:
        r=a%b
        if r==0:
            break
        a=b
        b=r
    return b

ans=A[0]
for n in range(N):
    ans=gcd(ans,A[n])

print(ans)

Submission status: Accepted

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