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:
from fractions import gcd

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

dp = [0] * (N + 1)
dp[0] = AAA[0]

for i, A in enumerate(AAA):
    if i == N:
        break
    dp[i + 1] = gcd(dp[i], A)

print(dp[N])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#最大公約数
def gcd(a, b):
    if a < b:
        a, b = b, a
    while a % b != 0:
        a, b = b, a % b
    return b

#最小公倍数
def lcm(a, b):
    return a * b // gcd(a, b)

#最大公約数（複数）
def gcds(l):
    if len(l) == 1:
        return l[0]
    elif len(l) == 2:
        return gcd(l[0], l[1])
    else:
        n = len(l) // 2
        L = l[:n]
        R = l[n:]
        return gcd(gcds(L), gcds(R))

#最小公倍数(複数)
def lcms(l):
	if len(l) == 1:
		return l[0]
	elif len(l) == 2:
		return lcm(l[0], l[1])
	else:
		n = len(l) // 2
		L = l[:n]
		R = l[n:]
		return lcm(lcms(L), lcms(R))

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

Submission status: Accepted

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

input()
a = sorted((map(int, 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())
li = list(map(int, input().split()))

while 1:
    minimam = min(li)
    maximam = max(li)
    temp = li.copy()
    li = [i % minimam if i% minimam != 0 else i for i in li]
    if temp == li:
        print(minimam)
        break

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

if N == 1:
    print(A[0])
else:
    res = gcd(A[0], A[1])
    for i in range(2, N):
        res = gcd(res, A[i])
    print(res)

Submission status: Accepted

Solution code:
import sys
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


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

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


def gcd_multi(nums):
    if len(nums) == 0:
        return 0
    if len(nums) == 1:
        return nums[0]

    ret = gcd(nums.pop(), nums.pop())
    while len(nums) > 0:
        ret = gcd(ret, nums.pop())
    return ret


def solve(inputs):
    monsters = string_to_int(inputs[0])
    return gcd_multi(monsters)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)

Submission status: Accepted

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

Lifes.sort(key=lambda x:-x)

ans = Lifes[N-1]

# for i in range(N):
#   for j in range(i, N):
#     life = Lifes[i]%Lifes[j]
#     if life > 0:
#       ans = min(ans, life)
# print(ans)

update = True
while update:
    min_num = ans
    for i in range(N):
        life_mod = Lifes[i]%ans
        if life_mod > 0:
            Lifes[i] = life_mod
            if min_num > life_mod:
                min_num = life_mod
    if ans == min_num:
        update=False
    else:
        ans = min_num
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
while True:    
  a = set(a)-{0}
  a = sorted(list(a))  
  if (a[0]==sum(a)) or (a[0]==1):    
    print(a[0])
    break
  a = [ai%a[0] for ai in a[1:]] + [a[0]]

Submission status: Accepted

Solution code:
def euc(x, y):
	if y == 0:
		return x
	return euc(y, x%y)

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

Submission status: Accepted

Solution code:
from functools import reduce


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


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

print(reduce(gcd, a))

Submission status: Accepted

Solution code:
from fractions import gcd


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


main()

Submission status: Accepted

Solution code:
import fractions
N = int(input())
A = list(map(int, input().split()))
ans = A[0]
for ai in A:
        ans = fractions.gcd(ans,ai)
print(ans)

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()))
ans = a[0]
for i in range(n):
    ans = gcd(ans,a[i])
print(ans)

Submission status: Accepted

Solution code:
import functools
def gcd(a,b):
    m=max(a,b)
    n=min(a,b)
    return n if m%n==0 else gcd(n,m%n)

def resolve():
    n=int(input())
    a=list(map(int,input().split()))
    print(functools.reduce(gcd,a))

resolve()

Submission status: Accepted

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


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

if len(set(A)) == 1:
    print(A[0])
    exit()

ret = A[0]

for a in A[1:]:
    ret = gcd(ret, a)

print(ret)

Submission status: Accepted

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

Submission status: Accepted

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

gcd = l[0]
for i in range(1,n):
    gcd = fractions.gcd(l[i],gcd)
print(gcd)

Submission status: Accepted

Solution code:
a = int(input())
b = list(map(int, input().split()))
b.sort()
while True:
    c = []
    c.append(b[0])
    for i in range(1, len(b)):
        if b[i] % b[0] != 0:
            c.append(b[i] % b[0])
    if len(b) == 1:
        print(b[0])
        exit()
    else:
        b = c
        b.sort()

Submission status: Accepted

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


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


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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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])
	monster = [x for x in monster if x != 0]
	if len(monster) == 1:
		print(monster[0])
		break

Submission status: Accepted

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

def gcd2(array):
    t = array[0]
    for i in array:
        t = gcd(t,i)
    return t

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

print(g)

Submission status: Accepted

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

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 fractions import gcd

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 fractions import gcd

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:
import fractions
#ABC用にfractionsを使っているが、今はmathを使うべき
N = int(input())
monster = [int(x) for x in input().split()]
ans = monster[0]
for i in range(1, N):
    ans = fractions.gcd(ans, monster[i])


print(ans)

Submission status: Accepted

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


n = int(input())
hs = sorted(list(map(int, input().split())))

ret = hs[0]
for h in hs[1:]:
    ret = gcd(ret, h)
print(ret)

Submission status: Accepted

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

while len(li) > 1:
  a = min(li)
  for i in range(len(li)):
    if li[i] != a:
      li[i] %= a
  li = list(set(li))
  if 0 in li:
    li.remove(0)
      
print(li[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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

As = sorted(A)
As = [a%As[0] if a%As[0] != 0 else As[0] for a in As]
As = sorted(As)

def judge(tmp_one, tmp_two):
    flg = 1

    while flg:
        if tmp_two%tmp_one == 0:
            tmp_two = tmp_one
        else:
            tmp_two = tmp_two%tmp_one

        if tmp_one%tmp_two == 0:
            tmp_one = tmp_two
        else:
            tmp_one = tmp_one%tmp_two
        if tmp_one == tmp_two:
            flg = 0

    return tmp_one

tmp_one = As[0]
for i in range(1, N):
    if i == N - 1:
        tmp_two = As[i]
    elif As[i] != As[0]:
        tmp_two = As[i]
        break

ans = judge(tmp_one, tmp_two)
print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(100000)

def intinput(): return map(int,sys.stdin.readline().split())

def gcd(x,y):  #最大公約数
    if x==0:
        return y
    else:
        return gcd(y%x,x)

n=int(input())
l=list(intinput())
ans=0
for i in l:
    ans=gcd(ans,i)
print(ans)

Submission status: Accepted

Solution code:
import fractions

N = int(input())
A = list(map(int, input().split()))
for i in range(N):
    if i == 0:
        ans = A[i]
    else:
        ans = fractions.gcd(ans, A[i])
        
print(ans)

Submission status: Accepted

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


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


ans = float("Inf")
for i in range(n - 1):
    ans = min(ans, gcd(a[i], a[i + 1]))
print(ans)

Submission status: Accepted

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


def remainder(a):
    a.sort()
    for i in range(1, len(a)):
        a[i] = a[i] % a[0]
    count = a.count(0)
    for i in range(count):
        a.remove(0)
    if len(a) == 1:
        return a
    return remainder(a)


print(remainder(a)[0])

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

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

Submission status: Accepted

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

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

ans = a[0]
for i in range(n):
  ans = gcd(ans, a[i])
print(ans)

Submission status: Accepted

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

def uplow(a,b):
    if a<b:up=b;low=a
    else:up=a;low=b
    return up,low

def euclid(a,b):
    up,low=uplow(a,b)
    while 1:
        up,low=low,up%low
        if low==0:return up

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

Submission status: Accepted

Solution code:
import fractions

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

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

ans = reduce(gcd, A)
print(ans)

Submission status: Accepted

Solution code:
import fractions

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

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

Submission status: Accepted

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

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

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

print(gcd_num)

Submission status: Accepted

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

n = int(input())
lst = list(map(int,input().split()))
ans = lst.pop(0)
for i in range(n-1):
    b = lst.pop(0)
    ans = gcd(ans,b)
print(ans)

Submission status: Accepted

Solution code:
import functools
N = int(input())
n_lis = sorted(list(map(int, input().split())), reverse=True)

while len(set(n_lis)) > 1:
    n_lis = sorted(n_lis)
    n_lis = [n_lis[0]] + [n_lis[i] % n_lis[0] for i in range(0, len(n_lis))]
    #print(n_lis)
    n_lis = [item for item in n_lis if item > 0]

print(min(n_lis))

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N = int(input())
A = list(map(int, input().split()))

def gcd(x, y):
	if y == 0:
		return x
	else:
		return gcd(y, x % y)
		
res = A[0]

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

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

def search_common_divisor(x,y):
    if x<y:
        x,y=y,x
    while y!=0:
        x,y=y,x%y
    return x

def search_list_common_divisor(*numbers):
    b=[search_common_divisor(numbers[0],numbers[1])]
    for i in numbers:
        b.append(search_common_divisor(b[-1],i))
    return b[-1]

print(search_list_common_divisor(*a))

Submission status: Accepted

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

def search_common_divisor(x,y):
    if x<y:
        x,y=y,x
    while y!=0:
        x,y=y,x%y
    return x

def search_list_common_divisor(*numbers):
    c=[numbers[0][i] for i in range(n)]
    b=[search_common_divisor(c[0],c[1])]
    for i in c:
        b.append(search_common_divisor(b[-1],i))
    return b[-1]

print(search_list_common_divisor(a))

Submission status: Accepted

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

while len(List)!=1:
    m = min(List)
    List = [e%m for e in List]
    List = [e for e in List if e>0]
    List.append(m)
    
print(m)

Submission status: Accepted

Solution code:
import fractions

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

gcd = alist[0]
for i in range(1,N):
  gcd = fractions.gcd(gcd,alist[i])
  
print(gcd)

Submission status: Accepted

Solution code:
import fractions

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

Submission status: Accepted

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

Submission status: Accepted

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

a = set(a)

from fractions import gcd
from functools import reduce
print(reduce(gcd,list(a)))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
INF = 10**10
while True:
  num_alive = sum([1 if i>0 else 0 for i in A])
  #print("A:" + str(A))
  #print("num_alive: " + str(num_alive))
  if num_alive == 1:
    break
  else:
    min_A = INF
    for i in A:
      if i>0:
        min_A = min(i, min_A)
      else:
        pass
    min_A_idx = A.index(min_A)
    #print("min_A:{}, min_A_idx: {}".format(str(min_A), str(min_A_idx)))
    A = [ i % min_A if idx != min_A_idx else i for idx, i in enumerate(A)  ]
    
print(max(A))

Submission status: Accepted

Solution code:
import sys


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


if __name__ == '__main__':
    input = sys.stdin.readline
    n = int(input())
    a_list = list(map(int, input().split()))
    ans = a_list[0]
    for a in a_list[1:]:
        ans = gcd(ans, a)
    print(ans)

Submission status: Accepted

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

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

# GCD
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x

def main():
  n=I()
  l=LI()

  a=l[0]
  for x in l[1:]:
    a=gcd(a,x)

  return a

print(main())

Submission status: Accepted

Solution code:
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

def gcd(m, n):
    # 入力を m, n (m ≧ n) とする。
    tmp = max(m,n)
    n = min(m,n)
    m = tmp
    # n = 0 なら、 m を出力してアルゴリズムを終了する。
    if n == 0:
        return m
    # m を n で割った余りを新たに n とし、更に 元のnを新たにm とし 2. に戻る。
    return gcd(n, m % n)

n = int(input())
hps = get_nums_l()

print(reduce(gcd, hps))

Submission status: Accepted

Solution code:
from functools import reduce
n = int(input())
s = [int(i) for i in input().split()]
s.sort(reverse = True)

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

print(reduce(saidaikouyakusuu, s))

Submission status: Accepted

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

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

ans = A[0]

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

print(reduce(gcd,a))

Submission status: Accepted

Solution code:
import sys

n = int(input())
al = list(map(int, input().split()))
sys.setrecursionlimit(10 ** 5)


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


def gcdl(num, n):
    ans = num[0]
    for i in range(n):
        ans = gcd(ans, num[i])
    return ans


print(gcdl(al, n))

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

print(ans)

Submission status: Accepted

Solution code:
import sys
n = int(input())
a = list(map(int, input().split()))
sys.setrecursionlimit(10 ** 5)


def cut(l):
    l.sort()
    nokori = [l[0]]
    for i in range(1, len(l)):
        b = l[i] % l[0]
        if b != 0:
            nokori.append(b)
    if len(nokori) != 1:
        return cut(nokori)
    return nokori[0]


print(cut(a))

Submission status: Accepted

Solution code:
def euc(x, y):
	if y == 0: return x
	return euc(y, x%y)

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

Submission status: Accepted

Solution code:
from fractions import gcd
N = int(input())
life_list = list(map(int, input().split()))
ans = life_list[0]
for A in life_list:
  ans = gcd(ans, A)
        
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import numpy as np

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

A = np.array(sorted(A))
ans = A[0]
np.delete(A, 0)

while True:
    B = A % ans
    C = B[B != 0]
    if len(C) == 0:
        break
    ans = min(C)
    B = C

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

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


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

ans = data[0]

for i in range(n - 1):
    ans = gcd(ans, data[i + 1])

print(ans)

Submission status: Accepted

Solution code:
import fractions

N = int(input())

A = []

tmp = input().split(" ")

for t in tmp:
    A.append(int(t))
    

gcd = A[0]

for n in range(1,N):
    gcd = fractions.gcd(gcd,A[n])

print(gcd)

Submission status: Accepted

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

while len(A) > 1:
    A.sort()
    for n in range(len(A)-1):
        A[n+1] = A[n+1]%A[0]
    A = [a for a in A if a != 0]
    
print(A[0])

Submission status: Accepted

Solution code:
def gcd(x, y): 
  
   while(y): 
       x, y = y, x % y 
  
   return x 
n = int(input())
a = list(map(int,input().split()))
g = 0
for i in range(len(a)):
    g = gcd(g,a[i])
print(g)

Submission status: Accepted

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

    while True:
        mina = min(A)
        mini = A.index(mina)
        A = A[:mini] + A[mini+1:]
        A = [a % mina for a in A if a % mina > 0]
        if not A:
            break
        A = A + [mina]
    print(mina)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect
import os
from collections import Counter, deque
from fractions import gcd
from functools import lru_cache
from functools import reduce
import functools
import heapq
import itertools
import math
import numpy as np
import re
import sys

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")


N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))

a = reduce(gcd, A)
print(a)

Submission status: Accepted

Solution code:
N = input()
A = {int(x) for x in input().split()}

while len(A) != 1:
    mn = min(A)
    A = {x % mn for x in A if x % mn != 0}
    A.add(mn)
print(A.pop())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = input()
A = {int(x) for x in input().split()}

while True:
    if len(A) == 1:
        break
    tmp = list(A)
    mn = min(tmp)
    for idx in range(len(tmp)):
        if tmp[idx] != mn:
            tmp[idx] = tmp[idx] % mn if tmp[idx] % mn != 0 else mn
    A = set(tmp)

print(A.pop())

Submission status: Accepted

Solution code:
def resolve():
    N = int(input())
    As = list(map(int, input().split(" ")))
    print(gcds(*As))

from fractions import gcd
from functools import reduce
def gcds(*numbers):
    return reduce(gcd, numbers)

if '__main__' == __name__:
    resolve()

Submission status: Accepted

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

Submission status: Accepted

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

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

i=1
while i<=N-1:
    ans.append(gcd(A[i],ans[-1]))
    i+=1

print(ans[-1])

Submission status: Accepted

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

Submission status: Accepted

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


memo = dict()

def euclidean_algorithm(a, b):
  while True:
    if a > b:
      a, b = b, a
    div, mod = divmod(b, a)
    if mod == 0:
      break
    b = mod
  return a

N = len(A)
ans = A[0]
for i in A[1:]:
  ans = euclidean_algorithm(ans, i)

print(ans)

Submission status: Accepted

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

def gcd(x,y):
    if x < y:
        return gcd(y,x)
    else:
        if x % y == 0:
            return y
        else:
            return gcd(y,x%y)
ans = A[0]
for i in range(1,n):
    ans = gcd(ans,A[i])
print(ans)

Submission status: Accepted

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

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
        
def gcdlist(l):
    a = l[0]
    for i in range(len(l)):
        a = gcd(a,l[i])
    return a

print(gcdlist(A))

Submission status: Accepted

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

while len(A) > 1:
    m = min(A)
    B = [m]
    for a in A:
        mod = a % m
        if mod > 0:
            B.append(mod)
    A = B
print(A[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions as fr

N = int(input())

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

ans = A[0]

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

print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

print(reduce(gcd,A))

Submission status: Accepted

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


N = int(input())

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

hoge = [A[0]]

for i in range(1, len(A)):
    hoge.append(gcd(hoge[-1], A[i]))

print(hoge[-1])

Submission status: Accepted

Solution code:
# PROXY

import functools
import fractions
N = int(input())
Nlist = [int(i) for i in input().split()]
gcd = functools.reduce(fractions.gcd, Nlist)
print(gcd)

Submission status: Accepted

Solution code:
# ABC118C - Monsters Battle Royale
from fractions import gcd

n = int(input())
arr = list(map(int, input().rstrip().split()))
ans = arr[0]
for i in arr[1:]:
    ans = gcd(ans, i)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import functools, fractions

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

Submission status: Accepted

Solution code:
import fractions

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

Submission status: Accepted

Solution code:
#!/usr/bin/python
# coding: UTF-8
import math

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

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

res = a[-1]
for i in a[:-1]:
  res = gcd(res, i)

print(res)

Submission status: Accepted

Solution code:
import fractions

n = int(input())
m = list(map(int,input().split()))
ans = 0

for i in range(n):
	ans = fractions.gcd(ans,m[i])
print(ans)

Submission status: Accepted

Solution code:
def f(a, b):
    if a < b:
        d = a
        a = b
        b = d
    if a % b == 0:
        return b
    else:
        return f(b, a % b)

def main():
    n = int(input())
    A = list(map(int, input().split()))
    ans = int(1e9)
    for i in range(1, n):
        ans = min(ans, f(A[i], A[i - 1]))
    print(ans)

main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
cnt=0
while(1):
     a.sort()
     if a[1]==10**9+1:
          print(a[0])
          break
     m0=a[0]
     for i in range(n-1-cnt):
          m1=a[i+1]
          m1-=m0*(m1//m0)
          if m1==0:
               cnt+=1
               a[i+1]=10**9+1
          else:
               a[i+1]=m1

Submission status: Accepted

Solution code:
from sys import stdin
import fractions
N = int(stdin.readline().rstrip())
A = [int(x) for x in stdin.readline().rstrip().split()]
ans = A[0]
for k in range(N)[1:]:
    ans = fractions.gcd(ans, A[k])
print(ans)