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

res=fractions.gcd(A[0],A[1])
for i in range(2,N):
  res = fractions.gcd(res,A[i]);
print(res)

Submission status: Accepted

Solution code:
# C - Monsters Battle Royale

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

N = int(input())
A = list(int(x) for x in 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:
import functools
import fractions
n=int(input())
a=list(map(int,input().split()))
print(functools.reduce(fractions.gcd,a))

Submission status: Accepted

Solution code:
def ngcd(lista):
    from fractions import gcd
    res = lista[0]
    for i in range(1,len(lista)):
        if res != 1:
            res = gcd(lista[i],res)
    return res

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(g)

Submission status: Accepted

Solution code:
from fractions import gcd  # use math.gcd for python 3.5~


def main():
    N = int(input())
    A = list(map(int, input().split(' ')))
    A.sort()
    print(min([gcd(A[0], a) for a in A[1:]]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()
A = LIST()

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

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

print(ans)

Submission status: Accepted

Solution code:
num = (int)(input())
mons = list(map(int, input().split(" ")))
while(sum(mons) != len(mons) * min(mons)):
  wari = min([e for e in mons if e != 0])
  for i in range(len(mons)):
    if mons[i] != wari:
      mons[i] %= wari
  mons = [e for e in mons if e != 0]
print(max(mons))

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:
import fractions
n=int(input())
a=list(map(int,input().split()))
ans=[0]*(n+1)
ans[1]=a[0]
for i in range(2,n+1):
    ans[i]=fractions.gcd(ans[i-1],a[i-1])
print(ans[-1])

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

N = int(input())
l = map(int, input().split())

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

print(gcd_list(l))

Submission status: Accepted

Solution code:
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
import math
import collections

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
n = int(input())
a = sorted(list(map(int,input().split())))
d = a[0]
for i in range(n):
    d = gcd(d,a[i])
print(d)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): return k.join(list(map(str, lst)))
INF = float('inf')

from fractions import gcd
def solve():
    n = II()
    A = LI()

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


if __name__ == '__main__':
    solve()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
int1 = lambda x: int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def printlist(lst, k='\n'): return k.join(list(map(str, lst)))
INF = float('inf')

def solve():
    n = II()
    A = LI()
    A = sorted(A)
    # print(A)
    # for _ in range(10):
    while 1:
        if len(set(A)) == 1:
            print(A[0])
            return

        a0 = A[0]
        for i in range(1, n):
            ai = A[i]
            if ai % a0 == 0:
                A[i] = a0
            else:
                A[i] = ai % a0
        A = sorted(A)
        # print(A)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

import heapq
while len(a)>1:
    heapq.heapify(a)
    s=heapq.heappop(a)
    an=[s]
    for i in range(len(a)):
        m=a[i]%s
        if m>0:
            an.append(m)
    a.clear()
    a=an
print(s)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from functools import reduce
import sys
try:
    from typing import List
except ImportError:
    pass


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


def solve(N: int, A: "List[int]"):
    print(reduce(gcd, A))


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:
import itertools
import math
import fractions
import functools
n = int(input())
a = list(map(int, input().split()))

def gcd(numbers):
    return functools.reduce(fractions.gcd, numbers)
print(gcd(a))

Submission status: Accepted

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

def gcd(a,b):
  aa=max(a,b)
  bb=min(a,b)
  cc=aa%bb
  return gcd(bb,cc) if cc else bb
  
p=gcd(a[0],a[1])
for i in range(2,n):
  p=gcd(p,a[i])
print(p)

Submission status: Accepted

Solution code:

#ユークリッドの互除法( A < B　とし, O(logA))
def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b, a%b)

N = int(input())

#3個以上の最大公約数を求める必要がある
# res=0 と初期化して、res=gcd(res,x[i])と更新する
# gcd(a,b,c,....) → gcd(gcd(gcd(a,b),c),...) 
res = 0
x = list(map(int,input().split()))

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

print(res)

Submission status: Accepted

Solution code:
from fractions import gcd

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

lisA.sort()
ans = 10**9 + 1

for num in lisA[1:]:
    tmp = gcd(lisA[0],num)
    ans = min(ans,tmp)
    if ans == 1:
        print(ans)
        exit()

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

res=A[0]

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

print(res)

Submission status: Accepted

Solution code:
def resolve():
    '''
    code here
    '''

    N = int(input())
    A_list = [int(item) for item in input().split()]

    is_flag = True
    temp_list = A_list[:]
    prev_list = A_list[:]
    while is_flag:
        temp_min = min(temp_list)
        for i in range(N):
            if temp_list[i] % temp_min >= 1:
                temp_list[i] = temp_list[i] % temp_min

        if prev_list == temp_list:
            is_flag = False

        prev_list = temp_list[:]

    print(temp_min)

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

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

# -------------------------------------------------------------
# main
# -------------------------------------------------------------
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()))
flag = True
b = gcd(a[0], a[1])
for i in range(2, n):
    b = gcd(a[i], b)
print(b)

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 = gcd(a[0], a[1])
for i in range(2, 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()))

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

print(gcd_list(A))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from collections import deque

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

while True:
	a = list(a)
	a.sort()
	a = deque(a)
	while True:
		A = a.popleft()
		if A != 0:
			a.appendleft(A)
			break
	for i in range(1,len(a)):
		a[i] %= a[0]
	if sum(a) - a[0] == 0:
		print(a[0])
		break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

Submission status: Accepted

Solution code:
import fractions
N = int(input())
A = [int(x) for x in 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()))

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

def gcd(num_list):
    ans = 0
    for i in num_list:
        ans = gcd_base(ans, i)
    return ans

print(gcd(a))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
# from collections import deque
# from math import factorial
# import collections
import math
import sys
sys.setrecursionlimit(2000000)
# import itertools
# import statistics
# import numpy as np
n = int(input())
# n, m = list(map(int, input().split()))
a = list(map(int, input().split()))
# abc = [int(input()) for i in range(5)]


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


print(gcd_list(a))

Submission status: Accepted

Solution code:
import fractions

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

Submission status: Accepted

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools
from fractions import gcd

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()
    A = il()
    sm = sum(A)
    print(min([gcd(sm, a) for a in A]))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions #ターミナル上ではmathモジュールを使う。
N = int(input())
A = list(map(int, input().split()))
ans = A[0]
for i in range(1,N):
    ans = fractions.gcd(ans, A[i])
    #N個の最大公約数は逐次更新するのが鉄則。
print(ans)

Submission status: Accepted

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

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

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

print(gcd_A)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

print(reduce(fractions.gcd,a))

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:
# -*- coding: utf-8 -*-
"""
Created on Mon May  4 20:56:08 2020
"""

import sys
import numpy as np

sys.setrecursionlimit(10 ** 9)
#def input():
#    return sys.stdin.readline()[:-1]
mod = 10**9+7

N = int(input())
#X, Y = map(int,input().split())
A = list(map(int,input().split()))
A1 = np.array(A)

m = np.min(A)
pre = m
while len(A1) > 1:
    pre = m
    A1 %= m
    A1 = A1[A1 != 0]
    A1 = np.append(A1, m)
    m = np.min(A1)
print(pre)

Submission status: Accepted

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

while len(a) != 1:
  m=min(a)
  t = [m]
  for i in a:
    if i % m == 0: continue
    t.append(i % m)
  if not t: break
  a = t
  #print(a)
print(m)

Submission status: Accepted

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


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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


n = int(input())
a = list(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:
n=int(input())
A=list(map(int,input().split()))
def gcd(x,y):
    while y:
        x,y=y,x%y
    return x 
ans=0
for i in  range(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()))
g = gcd(A[0], A[1])
for a in A[2:]:
    g = gcd(g, a)

print(g)

Submission status: Accepted

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

while True:
    if len(A) == 1:
        break
    while A[0] == 0:
        A.popleft()
    mod = A[0]
    for i in range(1, len(A)):
        A[i] = A[i]%mod
    A = deque(sorted(A))

print(A[0])

Submission status: Accepted

Solution code:
import fractions
N=int(input())
L=list(map(int,input().split()))
ans=float("inf")
for i in range(1,N):
	if i==1:
		ans=fractions.gcd(L[0],L[1])
	else:
		ans=fractions.gcd(ans,L[i])
print(ans)

Submission status: Accepted

Solution code:
# Problem C - Monsters Battle Royale

# input
N = int(input())
a_nums = list(map(int, input().split()))

# initialization
count = 0
is_finished = True

# count
while is_finished:
    min_hp = float('INF')
    min_index = 0
    for i in range(N):
        if a_nums[i]==0:
            continue
        if min_hp>a_nums[i]:
            min_hp = a_nums[i]
            min_index = i
    for i in range(N):
        if i==min_index:
            continue
        a_nums[i] = a_nums[i] - min_hp*(a_nums[i]//min_hp)
        if a_nums[i]<0:
            a_nums[i] = 0
    if len(set(a_nums))==2 and 0 in set(a_nums):
        is_finished = False

# output
ans = max(a_nums)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
al = list(map(int, input().split()))
t = al[0]


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


for i in range(1, n):
    t = gcd(t, al[i])  # a,bの最大公約数


print(t)

Submission status: Accepted

Solution code:
n = int(input())

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


# a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


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


ans = al[0]

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

print(ans)

Submission status: Accepted

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

#２整数の最大公約数を求める

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



#N 整数の最大公約数を求める
#A = [A[0],...,A[N]] とする

def gcd(A):
    ans = A[0]
    for i in range(1,N): #range(1,N)= 1,2,...,N-1
        ans = gcd2(ans, A[i])
    return ans
print(gcd(A))

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

print (g)

Submission status: Accepted

Solution code:
from fractions import gcd

n = int(input())
a = list(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
from fractions import gcd
from functools import reduce
print(reduce(gcd, map(int, open(0).read().split()[1:])))

Submission status: Accepted

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

def gcd(n, m):
    if m == 0:
        return n
    return gcd(m, n % m)

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

print(G)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
N = [a[0]]
for i in range(1, n):
    if a[i] % a[0] != 0:
        N.append(a[i]%a[0])
N.sort()
while sum(N) > N[0]:
    N1 = N.copy()
    N = [N1[0]]
    for s in N1:
        if s == N[0]: continue
        if s%N[0] != 0: N.append(s%N[0])
    N.sort()
print(N[0])

Submission status: Accepted

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

for i in range(N-1):
    if i==0:
        G=gcd(A[0],A[1])
    else:
        G=gcd(G,A[i+1])

print(G)

Submission status: Accepted

Solution code:
from fractions import gcd
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
flag = False
for i in range(1,n):
    if gcd(a[i],a[0])==1:
        flag = True
mn = 10**9
if not flag:
    for i in range(1,n):
        mn = min(mn,gcd(a[0],a[i]))
print(1 if flag else mn)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,=pin()
    A=tupin()
    
    from fractions import gcd

    temp=A[0]
    for i in range(N):
          temp=gcd(temp,A[i])
    print(temp)
#%%submit!
resolve()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():

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

resolve()

Submission status: Accepted

Solution code:
N=int(input())
*A,=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:
def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    while b:
        a, b = b, a % b
    return a


def lcm(a: int, b: int) -> int:
    """a, bの最小公倍数(least common multiple: LCM)を求める
    計算量: O(log(min(a, b)))
    """
    return (a * b) // gcd(a, b)


def multi_gcd(array: list) -> int:
    """arrayのGCDを求める"""
    n = len(array)
    ans = array[0]
    for i in range(1, n):
        ans = gcd(ans, array[i])
    return ans


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

print(multi_gcd(a))

Submission status: Accepted

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

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

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


if __name__ == '__main__':
    main()

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 a[1:]:ans=gcd(ans,i)
print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
#from math import gcd
from fractions import gcd

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

print(reduce(gcd,a))

Submission status: Accepted

Solution code:
n = int(input())
import sys
input = sys.stdin.readline
l = list(map(int,input().split()))
x = min(l)
flag = True
while flag:
  flag = False
  for i in l:
    p = i%x
    if  p != 0 and p < x:
      x = p
      flag = True
print(x)

Submission status: Accepted

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

while len(A) > 1:
    not_zero = False
    my_min = heapq.heappop(A)
    A = np.array(A)
    A %= my_min
    A = list(A[A > 0])
    heapq.heapify(A)
    heapq.heappush(A, my_min)
print(A[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:
import fractions
n = int(input())
a = list(map(int,input().split()))

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

Submission status: Accepted

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

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

Submission status: Accepted

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


def solve(N: int, A: "List[int]"):
    from fractions import gcd
    from functools import reduce
    return reduce(gcd, A)


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools
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]"
    print(solve(N, A))

def test():
    import doctest
    doctest.testmod()

if __name__ == '__main__':
    #test()
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

N = int(input())

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


print(gcd_list(a))

Submission status: Accepted

Solution code:
import functools
import fractions

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

gcd = functools.reduce(fractions.gcd, a)
print(gcd)

Submission status: Accepted

Solution code:
def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
n=int(input())
lis=list(map(int,input().split()))
i=0
while len(lis)-1>i:
  lis+=[gcd(lis[i],lis[i+1])]
  i+=2
print(lis[-1])

Submission status: Accepted

Solution code:
import fractions as f

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

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

res = A[N - 1]
print(res)

Submission status: Accepted

Solution code:
from collections import deque

n = int(input())
l = deque(map(int, input().split()))

while len(l) > 1:
  key = min(l)
  for i in range(len(l)):
    j = l.popleft()
    sup = j % key
    if sup > 0:
      l.append(sup)
  l.append(key)

print(l[0] if len(l) == 1 else 0)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions

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

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


print(A[N-1])

Submission status: Accepted

Solution code:
import functools
import math
import fractions

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

Submission status: Accepted

Solution code:
from fractions import gcd


def solve():

    N = int(input())
    A = [int(i) for i in input().split()]
    a = A[0]
    for i in range(1, N):
        # 先頭をとって、gcdを繰り返していく
        a = gcd(a, A[i])
    print(a)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
def gcd(a, b):
    
    big = max(a, b)
    small = min(a, b)
    
    r = small
    while r != 0:
        r = big % small
        big = small
        small = r
    
    return big

n = int(input())
a = [int(x) for x in 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:
import fractions
import math
n = int(input())
li = list(map(int,input().split()))

if len(list(set(li))) == 1:
    print(li[0])
else:
    if len(li) == 1:
        print(li[0])
        exit()
    tmp_gcd = fractions.gcd(li[0],li[1])
    if len(li)>2:
        for i,l in enumerate(li):
            if i == 0 or i == 1:
                continue
            gc = fractions.gcd(tmp_gcd,l)
            tmp_gcd = gc
    print(tmp_gcd)

Submission status: Accepted

Solution code:
# N個の最大公約数
# ユークリッド互除法
# Check


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


def lcm(a, b):
    return a*b // gcd(a, b)


def good(A, N):
    # A = sorted(A)
    ans = A[0]
    # for i in range(1, N):
    #     ans = fractions.gcd(A[i], ans)
    for i in range(1, N):
        ans = lcm(ans, A[i])
    return ans


def my(A, N):
    A = sorted(A)

    while True:
        v = A[0]
        tmp = [v]
        for i in range(len(A)):
            if A[i] % v == 1:
                print(1)
                return
            if A[i] % v == 0:
                pass
            else:
                tmp.append(A[i] % v)

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

        A = sorted(tmp)
        # print(A)


def main():
    N = int(input())
    A = list(map(int, input().split()))
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YNL = {False: 'No', True: 'Yes'}
YNU = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True

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

def main():
    N = I()
    A = LI()
    n = A[0]

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

    print(n)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

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[1:]:
  ans=gcd(ans,i)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

N = int(input())
A = np.array([int(x) for x in input().split()],dtype=object)
gcd = np.frompyfunc(gcd,2,1)

print(gcd.reduce(A))

Submission status: Accepted

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

def gcd(a,b):
    while(a%b!=0):
        a,b=b,a%b
    return b
a=list(sorted(a))
c=gcd(a[0],a[1])
for i in range(2,n):
    c=gcd(a[i],c)
print(c)

Submission status: Accepted

Solution code:
import fractions


N = int(input())
ans = 0
for a in map(int, input().split()):
    ans = fractions.gcd(ans, a)
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 math import gcd
def gcd(a,b):
    if b == 0 :return a
    return gcd(b,a%b)


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


ans = arr[0]

for i in range(1,n):
    ans = gcd(ans,arr[i])

print(ans)