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: Accepted

Solution code:
def euclid_devider(num_devided, num_devider):
    while num_devided % num_devider != 0:
        temp = num_devided % num_devider
        num_devided = num_devider
        num_devider = temp
    return num_devider

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

Submission status: Accepted

Solution code:
from fractions import gcd

N = int(input())

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

d = As[0]
for a in As[1:]:
    d = gcd(d, a)

print(d)

Submission status: Accepted

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


def solve(L):
    L.sort()
    j = 0
    while L[j] == 0:
        j += 1
    if j == N - 1 or L[j] == 1:
        return L[j]
    for i in range(j + 1, N):
        L[i] %= L[j]
    return solve(L)


print(solve(A))

Submission status: Accepted

Solution code:
import fractions as frac
from functools import reduce

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


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

print(gcd_list(A))

Submission status: Accepted

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

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

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

print(res)

Submission status: Accepted

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

N = int(input())
A = [int(i) for i in input().split()]
ans = A[0]
for i in range(1, len(A)):
  ans = gcd(ans, A[i])
print(ans)

Submission status: Accepted

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


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

    return x


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

for e in a[2:]:
    ret = gcd(ret, e)

print(ret)

Submission status: Accepted

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

def gcd(tmp_1,tmp_2):
    if tmp_2 == 0:
        return tmp_1
    else:
        return gcd(tmp_2, tmp_1%tmp_2)

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

print(tmp_3)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
input()
print(reduce(gcd,list(map(int,input().split()))))

Submission status: Accepted

Solution code:
from fractions import gcd

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

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
input = sys.stdin.readline

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

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

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
input = sys.stdin.readline

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from bisect import bisect_right

def main():
	N = int(input())
	A = input().split(" ")
	A = [int(s) for s in A]
	
	A.sort()
	ai = -1
	tmp = -1
	for i in range(N-1):
		tmptmp = abs(A[i] - A[i+1])
		if tmptmp == 0:
			continue
		if tmp == -1 or tmp > tmptmp:
			tmp = tmptmp
			ai = i
			
	if tmp == -1:
		print(A[0])
		sys.exit()
		
	a = A[ai]		
	b = A[ai+1]
	
	while True:
		#print("{} {}".format(a, b))
		tmp_min = min(a, b)
		tmp_max = max(a, b)
		tmp = tmp_max % tmp_min
		if tmp == 0:
			print(tmp_min)
			sys.exit()
		else:
			if a < b:
				b = tmp
			else:
				a = tmp
	
if __name__ == "__main__":
	main()

Submission status: Accepted

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


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


print(gcd_list(a_li))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
import functools

n = input()
A = map(int, input().split())
print(functools.reduce(fractions.gcd, A))

Submission status: Accepted

Solution code:
from fractions import gcd 

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

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

print(G)

Submission status: Accepted

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


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


N = int(input())
A = [int(_) for _ in input().split()]
GCD = gcd(A[0], A[1])

for i in range(1, N-1):
    GCD = gcd(GCD, A[i+1])

print(GCD)

Submission status: Accepted

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

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

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

if len(a) == 1:
    ans = a[0]
else:
    ans = gcd(a[0],a[1])
    for i in range(2,n):
        ans = gcd(ans,a[i])

print(ans)

Submission status: Accepted

Solution code:
N = int(input())

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

#0の数がN-1になった時点で終了
#Aの中のminを割り出しそれのmodをA内でとるを繰り返す

mina = 0
while(1):
    if(len(A)==1):break
    mina = min(A)
    minaind = A.index(mina)
    delind =[]
    for i in range(0,len(A)):
        # print(A,minaind)
        if i == minaind:continue
        # print(i)
        A[i]%=mina
        # if A[i] <= 0: delind.append(i)
    B=[]
    for i in range(0,len(A)):
        if(A[i]>0):
            B.append(A[i])
            
    A = B

print(A[0])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A) # とりあえず並び替えておく
tmp = 0
for i in range(N-1):
    while A[i]>0:
        tmp = A[i]
        A[i] = A[i+1] % A[i]
        A[i+1] = tmp
print(A[N-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd(a,b):
    while b:
        a,b = b,a % b
    return a
def monsters(li,n):
    t = temp
    for i in range(n-1):
        t = gcd(li[i+1],t)
    return t

n = int(input())
li_a = list(map(int,input().split()))
temp = li_a[0]
print(monsters(li_a,n))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
def gcd(x,y):
  while y != 0:
    k = x
    x = y
    y = k%y
  return  x
cur = L[0]
for i in range(N):
  cur = gcd(cur,L[i])
print(cur)

Submission status: Accepted

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

def gcd(a, b):
  if b == 0:
    return a
  return gcd(b, a%b)
g = A[0]
for a in A[1:]:
  g = gcd(g, a)
print(g)

Submission status: Accepted

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

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

for i in range(1,n):
    monster[i] = gcd(monster[0], monster[i])

print(min(monster))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
C - Monsters Battle Royale
https://atcoder.jp/contests/abc118/tasks/abc118_c

"""
import sys


def solve(monsters):
    monsters = set(monsters)
    min_v = min(monsters)
    while len(monsters) > 1:
        monsters = set([m%min_v for m in monsters if m%min_v])
        monsters.add(min_v)
        min_v = min(monsters)
    return min(monsters)


def main(args):
    N = int(input())
    monsters = [int(m) for m in input().split()]
    ans = solve(monsters)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])

Submission status: Accepted

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

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

def solve(N: int, A: "List[int]"):
    A.sort()
    ret = A[0]
    for i in range(1, N):
        if A[i] % ret > 0:
            ret = gcd(ret, A[i])
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
monster = list(map(int, input().split()))
def gcd(a, b):
	if b > 0 :
		return gcd(b, a % b)
	else:
		return a
if len(monster) == 1 :
	print(monster[0])
else:
	mon = gcd(monster[0], monster[1])
	if len(monster) != 2 :
		for i in range(2, N) :
			mon = gcd(mon, monster[i])
print(mon)

Submission status: Accepted

Solution code:
# coding: utf-8

import sys
input = sys.stdin.readline

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

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

first_gcd = A[0]
for i in range(len(A)):
    first_gcd = gcd(first_gcd, A[i])

print(first_gcd)

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
from functools import reduce

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


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

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

Submission status: Accepted

Solution code:
def gcd(m, n):
    while n:  # nが0になるまで続ける
        m, n = n, m % n
    return m


N = int(input())  # モンスターの数

A = list(map(int, input().split()))  # モンスターのそれぞれの体力のリスト

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

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

print(g)

Submission status: Accepted

Solution code:
def gcd(m, n):
    while n:  # nが0になるまで繰り返す
        m, n = n, m % n
    return m


n = int(input())  # n体のモンスター
a = list(map(int, input().split()))  # それぞれの体力

g = gcd(a[0], a[1])  # 最大公約数を求める
for i in range(2, n):
    g = gcd(g, a[i])  # 最初のgは1つ目と2つ目の要素の最大公約数がすでに入っている

print(g)

Submission status: Accepted

Solution code:
def gcd(a, b):
    if b > a:
        a,b = b,a
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
N = int(input())
A = list(map(int,input().split()))
a = A[0]
for i in range(1,N):
    a = gcd(a,A[i])
print(a)

Submission status: Accepted

Solution code:
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
N = int(input())
A = list(map(int,input().split()))
A.sort(reverse=True)
a = A[0]
for i in range(1,N):
    a = gcd(a,A[i])
print(a)

Submission status: Accepted

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

A_min = min(A)
while(True):
    amin = max(A)
    for i in range(N):
        if A_min == A[i]:
            continue
        A[i] %= A_min
        if A[i] > 0 and A[i] <= amin:
            amin = A[i]
    A_min = amin
    if max(A) == A_min:
        break

print(max(A))

Submission status: Accepted

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    a,b = LI()
    if b%a == 0:
        print(a+b)
    else:
        print(b-a)
    return

#B
def B():
    n,m = LI()
    d = defaultdict(int)
    for i in range(n):
        l = LI()
        for j in range(1,len(l)):
            d[l[j]] += 1
    ans = 0
    for i in d.values():
        if i == n:
            ans += 1
    print(ans)
    return

#C
def C():
    def gcd(a,b):
        if a == 0:
            return b
        return gcd(b%a,a)
    n = I()
    a = LI()
    g = a[0]
    for i in range(1,n):
        g = gcd(g,a[i])
    print(g)
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Accepted

Solution code:
from fractions import gcd
n=int(input())
A=list(map(int,input().split()))
for i in range(n-1):
  A[i+1]=gcd(A[i],A[i+1])
print(A[n-1])

Submission status: Accepted

Solution code:
N=int(input())

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

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

for i in range(N-1):
    A[i+1]=ea(A[i],A[i+1])

print(A[N-1])

Submission status: Accepted

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

while len(A) > 1:
  min_num = min(A)
  min_index = A.index(min(A))
  for i in range(len(A)):
    if i != min_index:
      A[i] = A[i] % min_num

  while 0 in A:
    A.remove(0)

print(A[0])

Submission status: Accepted

Solution code:
n=int(input())
l=sorted(list(map(int,input().split())))
m=min(l)
l2=[]
l3=[]
for i in range(1,int(m**(1/2)+1)):
  if m%i==0:                   
    l2.append(i)
    if i!=m//i:
      l2.append(m//i)
for i in l2:
  b=True
  for j in l:
    if j%i==0:
      pass
    else:
      b=False
  if b:
    l3.append(i)
print(max(l3))

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
def gcdlist(numbers):
    return reduce(fractions.gcd,numbers)
n=int(input())
a=list(map(int,input().split()))
print(gcdlist(a))

Submission status: Accepted

Solution code:
N = int(input())
monster = [int(i) for i in input().split()]
while(len(monster) != 1):
    Min = min(monster)
    index = monster.index(min(monster))
    index2 = 0
    for i in monster:
        monster[index2] = i % Min
        index2 += 1
    monster[index] = Min

    for i in reversed(range(0,len(monster))):
        if monster[i] == 0:
            del monster[i]

print(monster[0])

Submission status: Accepted

Solution code:
from sys import stdin
import numpy as np

N = int(stdin.readline().rstrip().split()[0])
A = [int(x) for x in stdin.readline().rstrip().split()]
# N, X = [int(x) for x in stdin.readline().rstrip().split()]

def G(_a, _b):
  if _a>=_b:
    a, b = _a, _b
  else:
    a, b = _b, _a
  
  while True:
    c = a%b
    if c == 0:
      break
    a,b = b,c
  
  return b

L = np.array(list(set(A)))
mini = np.min(L)
yaku = [1]
i=2
r_mini = np.sqrt(mini)
while i<=r_mini:
  if mini%i==0:
    yaku.append(i)
  i+=1
yaku2 = list(map(lambda x: int(mini/x), yaku))
yaku = yaku[::-1]
yaku2.extend(yaku)
for y in yaku2:
  if np.sum(L%y)==0:
    ans = y
    break

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
N = int(input())
As = list(map(int,input().split()))
print(gcd_list(As))

Submission status: Accepted

Solution code:
N=int(input())

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

def ea(a,b):
    s=0
    while True:
        c=a%b
        if c==0:
            break
        a=b
        b=c
        
    return b

for i in range(N-1):
    A[i+1]=ea(A[i],A[i+1])

print(A[N-1])

Submission status: Accepted

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

solved = False
while not solved:
    solved = True
    mod = min(A)
    new_A = [mod]

    for i, v in enumerate(A[:]):
        hp = v % mod
        if solved and hp != 0:
            solved = False
            new_A.append(hp)

    if solved:
        print(mod)
        exit()
    else:
        A = new_A

Submission status: Accepted

Solution code:
#encoding: utf-8

N = int(input())

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

def gcd(x, y):
    if y > 0:
        return gcd(y, x % y)
    else:
        return x

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

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

Submission status: Accepted

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

  N = int(input().strip())
  o = 0
  for i in map(int, input().split()):
    o = gcd(i,o)
  print(o)

if __name__=="__main__":
  solve()

Submission status: Accepted

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


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


# リスト内の全要素の最大公約数
if len(a) == 1:
    print(a[0])
else:
    element = gcd(a[0], a[1])
    if len(a) == 2:
        print(element)
    else:
        for i in range(2, n):
            element = gcd(element, a[i])
        print(element)

Submission status: Accepted

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

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

Submission status: Accepted

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

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


    An = sorted(An)
    An = [gcd(a_n, An[0]) for a_n in An]
    print(min(An))

main()

Submission status: Accepted

Solution code:
from fractions import gcd
 
N=int(input())
HP=list(map(int,input().split()))
 
tmp=HP[0]
 
for i in range(0,N):
    tmp=gcd(tmp,HP[i])
    
print(tmp)

Submission status: Accepted

Solution code:
import sys

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

a=HP[0]
b=HP[1]

(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
    q = a // b
    (a, b) = (b, a % b)
    (x, lastx) = (lastx - q * x, x)
    (y, lasty) = (lasty - q * y, y)
        
tmp=a

for i in range(1,N-1):
    a=tmp
    b=HP[i+1]
    
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
        
    tmp=a
    if tmp==1:
        print(tmp)
        sys.exit()
    
print(tmp)

Submission status: Accepted

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

a=HP[0]
b=HP[1]

(x, lastx) = (0, 1)
(y, lasty) = (1, 0)
while b != 0:
    q = a // b
    (a, b) = (b, a % b)
    (x, lastx) = (lastx - q * x, x)
    (y, lasty) = (lasty - q * y, y)
        
tmp=a

for i in range(1,N-1):
    a=tmp
    b=HP[i+1]
    
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
        
    tmp=a
    
print(tmp)

Submission status: Accepted

Solution code:
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    gcd=a
    return gcd

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

tmp=egcd(HP[0],HP[1])

for i in range(1,N-1):
    a=tmp
    b=HP[i+1]
    
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
        
    tmp=a
    
print(tmp)

Submission status: Accepted

Solution code:
def egcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    gcd=a
    return gcd

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

tmp=egcd(HP[0],HP[1])

for i in range(1,N-1):
    tmp=egcd(tmp,HP[i+1])
    
print(tmp)

Submission status: Accepted

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

def gcd(m, n):
  while n:
    m, n = n, m%n
  return m

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

Submission status: Accepted

Solution code:
N = int(input())
list = list(map(int,input().split()))
def gcd(a,b):
    while b:
        a,b = b,a%b
    return a

gcd_val = list[0]

for i in list[1::]:
    gcd_val = gcd(gcd_val,i)

print(gcd_val)

Submission status: Accepted

Solution code:
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors

n=int(input())
l=list(map(int,input().split()))
m=min(l)
div=make_divisors(m)
div.reverse()
for i in div:
    flg=0
    for j in l:
        if j%i!=0:
            flg=1
            break
    if flg==0:
        ans=i
        break
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
def gcd(x,y):
    if y == 0:
        return x
    else:
        return gcd(y,x%y)
a = list(map(int,input().split()))
ans = a.pop()
for i in a:
    ans = gcd(i,ans)
print(ans)

Submission status: Accepted

Solution code:
def gcd_core(a,b):
    if b == 0:
        return a
    else:
        return gcd_core(b,a%b)

def gcd(arr):
    g = gcd_core(arr[0],arr[1])
    for i in range(2,len(arr)):
        g = gcd_core(g,arr[i])
    return g

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

print(gcd(a))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a_min = min(a)
while True:
    flag = 0
    a_attacked = [10 ** 9, 0]
    for i in range(n):
        if 0 < a[i] % a_min < a_attacked[0]:
            a_attacked[0] = a[i] % a_min
            a_attacked[1] = i
            flag = 1
    if flag == 0:
        break
    else:
        a_min = a_attacked[0]
        a[a_attacked[1]] = a_attacked[0]
print(a_min)

Submission status: Accepted

Solution code:
n=int(input())
def gcd(x,y):
  if y==0:
    return x
  else:
    return gcd(y,x%y)
a=list(map(int,input().split()))
stack=a.pop()
for i in a:
  stack=gcd(i,stack)
print(stack)

Submission status: Accepted

Solution code:
from functools import reduce

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

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


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

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

print(reduce(gcd, a))

Submission status: Accepted

Solution code:
INFO=int(input())
DATA=list(map(int, input().split(" ")))
DATA=sorted(DATA)
def Euclidean(m,n):
    while n!=0:
        temp = n
        n = m%n
        m=temp
    return m
    
output=DATA[0]
for i in range(1,INFO):
    output = Euclidean(DATA[i], output)

print(output)

Submission status: Accepted

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

for i in range(len(A)):
 A[i] = int(A[i])

while(1):
 if(len(A) == 1):
  ans = A[0]
  break 
 A = list(set(A))
 A.sort()
 if(A[0] == 0):
  A.pop(0)
 min_monster = A[0]
 for i in range(len(A)):
   if(i != 0):
      tmp = A[i]//min_monster
      A[i] -= min_monster*tmp

print(ans)

Submission status: Accepted

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

for k in range(infa):
    mina = min(a)

    for i in range(len(a)):
       
        if a[i] == mina:
            a[i] = mina
        else:
            a[i] = a[i] % mina
    
    a = [j for j in a if not j == 0]

    if len(a) == a.count(mina):
        break

print(mina)

Submission status: Accepted

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

n,*h=map(int,open(0).read().split())

gh=gcd(h[0],h[1])
for i in range(2,n):
    gh=gcd(h[i],gh)

print(gh)

Submission status: Accepted

Solution code:
import fractions
N=int(input())
A=[int(i) for i in input().split()]
d=A[0]
for x in A[1:]:
  d=fractions.gcd(d,x)
print(d)

Submission status: Accepted

Solution code:
def euclid(n, a_list):
    a1, a2 = a_list[0:2]
    gcd_ = gcd(a1, a2)
    for i in range(2, n):
        gcd_ = gcd(gcd_, a_list[i])
    return gcd_

def gcd(a1, a2):
    r = 1
    while (r > 0):
        r = a1 % a2
        a1, a2 = a2, r
    return a1


n = int(input())
a_list = [int(i) for i in input().split()]
a_list = sorted(a_list)
ans = euclid(n, a_list)
print(ans)

Submission status: Accepted

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


flag = True

while(flag):
    As = sorted(As)
    for i in range(1,len(As)):
        As[i] %= As[0]

    As = list(filter(lambda  x: x > 0, As))
    if len(As) == 1:
        flag = False

print(As[0])

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
HPs = np.array([int(i) for i in input().split()])
np.sort(HPs)
while len(HPs) > 1:
    HPs[1:] %= HPs[0]
    HPs[HPs==0] = HPs[0]
    HPs=np.unique(HPs)
print(HPs[0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from fractions import gcd
n = int(input())
a = list(map(int, input().split()))
d = a[0]
for x in a[1:]:
	d = gcd(d, x)
print(d)

Submission status: Accepted

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

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

while True:
    A.sort()
    if len(A) == 1:
        break
    a = A[0]
    tmp_A = [a]
    for b in A[1:]:
        b = gcd(a, b)
        if b != 0:
            tmp_A.append(b)
    A = tmp_A
print(A[-1])

Submission status: Accepted

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

while len(A) > 1:
  min_A = min(A)
  next_A = set([min_A])
  for i in A:
    B = i % min_A
    if B != 0:
      next_A.add(B)
  A = list(next_A)
print(list(A)[0])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
def gcd(m,n):
    m,n = max(m,n), min(m,n)
    while n > 0:
        m, n = n, m%n
    return(m)
A.sort()
g = A[0]
for i in range(N):
    if g == 1:
        break
    else:
        g = gcd(g,A[i])

print(g)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
def gcd(m,n):
    m,n = max(m,n), min(m,n)
    while n > 0:
        m, n = n, m%n
    return(m)

g = A[0]
for i in range(N):
    if g == 1:
        break
    else:
        g = gcd(g,A[i])

print(g)

Submission status: Accepted

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

while len(HP) > 1:
    minHP = min(HP)
    nextHPs = set([minHP])
    for each_HP in HP:
        temp = each_HP % minHP
        if temp != 0:
            nextHPs.add(temp)
    HP = list(nextHPs)
print(list(HP)[0])

Submission status: Accepted

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

import numpy as np
A = np.array(sorted(A))

while(True):
    A[1:] %= A[0]
    A = np.unique(A)
    A = np.delete(A, np.where(A == 0))
    if len(A) == 1:
        break

    A.sort()

print(A[0])

Submission status: Accepted

Solution code:

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

for _ in range(10**12):
    if len(a)==1:
        print(a[0])
        exit()
    z=0
    for i in range(1,len(a)):
        tmp = a[i]%a[0]
        if tmp==0:
            z+=1
        a[i]=tmp
    a.sort()
    a=a[z:]

Submission status: Accepted

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

import math

s = []
m = a[0]

for i in range(math.floor(math.sqrt(m))+3):
	if m%(i+1)==0:
		if (i+1) not in s:
			s.append(i+1)
		if m//(i+1) not in s:
			s.append(m//(i+1))
s.sort()
s = reversed(s)

for i in s:
    for j in range(len(a)):
        if a[j]%i>0:
            break
    else:
        print(i)
        break

Submission status: Accepted

Solution code:
import fractions
N=int(input())
As=input().split()
As=[int(a) for a in As]
count=As[0]
for i in As:
    count=fractions.gcd(count,i)
print(str(count))

Submission status: Accepted

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

min_m = 10**10
while len(A)*min_m != sum(A):
    min_m = min(A)
    n_min_m = min_m
    for i,a in enumerate(A):
        if min_m != a:
            A[i] = min_m if a%min_m == 0 else a%min_m
            n_min_m = min(a,n_min_m)
    min_m = n_min_m

print(min_m)

Submission status: Accepted

Solution code:
def gcd(a,b):
    if b == 0:
        return a
    return gcd(b,a%b)
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for k in range(1,N):
    ans = gcd(ans,A[k])
print(ans)

Submission status: Accepted

Solution code:
import sys


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


fin = sys.stdin.readline
N = int(fin())
A = [int(elem) for elem in fin().split()]
assert len(A) == N

g = gcd(A[0], A[1])
for item in A[2:]:
    g = gcd(g, item)
print(g)

Submission status: Accepted

Solution code:
N=int(input())
M_list = [int(x) for x in input().split()]


while True:
  if len(M_list)==1:
    break
    
  Min_M=min(M_list)
  M_list_temp = [x for x in M_list if x%Min_M!=0 or x == Min_M]
  mod_list=[Min_M]
  mod_list.extend([ x%Min_M for x in M_list if x%Min_M!=0 ])
  mod_list=list(set(mod_list))
  
  M_list=mod_list
  
print(M_list[0])

Submission status: Accepted

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

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

for i in range(1, len(MONSTER)):
  MONSTER[i] = euclidean(MONSTER[i-1], MONSTER[i])
print(MONSTER[len(MONSTER) - 1])

Submission status: Accepted

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

while(len(li)>1):
    li=sorted(li)
    min_num=li[0]
    li=[i%min_num for i in li]
    li.append(min_num)
    li=[j for j in li if j !=0]
print(li[0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from functools import reduce

def gcd(a, b):
    a, b = max(a, b), min(a, b)
    while 0 < b:
        a, b = b, a % b
    return a


def solve(n, a):
    ans = reduce(gcd, a)

    return ans


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

    print(solve(n, a))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

N = int(raw_input())
A = map(int, raw_input().split())

val = A[0]
for i in xrange(1, N, 1):
    val = gcd(val, A[i])

print val