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 main():
    import sys
    input = sys.stdin.readline
    sys.setrecursionlimit(10**7)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations, accumulate, groupby
    #from itertools import product
    from bisect import bisect_left,bisect_right
    from heapq import heapify, heappop, heappush
    from math import floor, ceil
    #from operator import itemgetter

    #inf = 10**17
    #mod = 10**9 + 7

    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    while a[-2] > 0:
        x = 0
        for i in range(n):
            if x==0:
                x = a[i]
            else:
                a[i] %= x
        a.sort()
    print(a[-1])

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions

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

now=A[0]
for a in A:
    now=fractions.gcd(now,a)
    if now==1:
        break
print(now)

Submission status: Accepted

Solution code:
import sys
import math
from fractions import gcd
readline = sys.stdin.readline
INF = 10**9


def main():
  n = int(readline())
  A = list(map(int, readline().split()))
  ans = gcd(A[0], A[1])
  for i in A:
    ans = gcd(ans, i)
  print(ans)
  
  
  
  
if __name__ == "__main__":
  main()

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:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def gcd(n,m):
    if m == 0:
        return n
    else:
        return gcd(m,n%m)
n = I()
a = LI()
g = a[0]
for i in a[1:]:
    g = gcd(g,i)
print(g)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    from functools import reduce
    from fractions import gcd
    
    n, *a = map(int, open(0).read().split())
    g = reduce(gcd, a)
    print(g)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

# 答えは最大公約数
A.sort()
ans = A[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()))

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from heapq import heapify, heappop, heappush
N = int(input())
Alist = list(map(int, input().split()))
heapify(Alist)
while len(Alist) > 1:
    atk = heappop(Alist)
    Alist = [A % atk for A in Alist if (A % atk != 0)]
    heapify(Alist)
    heappush(Alist, atk)
print(Alist[0])

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

print(reduce(gcd,A))

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
inf = float('inf')
ninf = -float('inf')
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？

from fractions import gcd
from functools import reduce

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

n=ii()
arr=limii()
print(gcd_list(arr))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

Submission status: Accepted

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

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:
from fractions import gcd
def GCD(a):
    x = a[0]
    for i in range(1, len(a)):
        x = gcd(x, a[i])
    return x
n = int(input())
a = list(map(int, input().split()))
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 i in range(1,n):
    G = gcd(G,a[i])
print(G)

Submission status: Accepted

Solution code:
from functools import reduce

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

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

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

print(gcd_list(a_l))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

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

print(gcd_list(a_l))

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:

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

def attack(lst):
    attacker=min(lst)
    position=lst.index(attacker)
    temp=[]
    for i in range(len(lst)):
        if i!=position:
            if lst[i] % attacker!=0:
                temp.append(lst[i]%attacker)
        else:
            temp.append(lst[i])
    return temp

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

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(list(map(int,input().split())))
cnt = [a[1],a[0]]
for i in range(1,n):
  a[i] %= cnt[-1]
  if (a[i] != 0) and (a[i] < cnt[-1]):
    cnt.append(a[i])
    cnt.pop(0)
if a[1] == 0:
  print(a[0])
else:
  while cnt[1] != 0:
    cnt.append(cnt[0]%cnt[1])
    cnt.pop(0)
  else:
    print(cnt[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# GCD: greatest common divisor
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))

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

Submission status: Accepted

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

while len(A) > 1:
  A.sort()
  #print(A)
  for i in range(1,len(A)):
    #print(A[i],A[0])
    A[i] = A[i] % A[0]
  A = list(filter(lambda x: x != 0,A))

print(A[0])

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

Submission status: Accepted

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

N = int(input())
A = list(map(int, input().split()))
ans = functools.reduce(lambda x,y:fractions.gcd(x,y), A)
print(ans)

Submission status: Accepted

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


if __name__ == "__main__":
    N, *A = map(int, open(0).read().split())
    g = 0
    for i in range(N):
        g = GCD(g, A[i])
    print(g)

Submission status: Accepted

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

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

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

    return a

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

def gcd(a,b):
    '''
    3 個以上の値の最大公約数を求めるためには、
    res = 0 と初期化
    各 i に対して res = GCD(res, x[i]) と更新する
    '''
    while b!=0:
        a,b = b,a%b
    return a

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

print(ans)

Submission status: Accepted

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

def gcd(a,b):
    '''
    3 個以上の値の最大公約数を求めるためには、
    res = 0 と初期化
    各 i に対して res = GCD(res, x[i]) と更新する
    '''
    while b!=0:
        a,b = b,a%b
    return a

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

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from sys import stdin
from fractions import gcd

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

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

print(GCD)

Submission status: Accepted

Solution code:
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *
from math import *
from fractions import *

sys.setrecursionlimit(100000000)
input = lambda: sys.stdin.readline().rstrip()

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

main()

Submission status: Accepted

Solution code:
N=int(input())
A=sorted(list(map(int,input().split(' '))))
l_tmp=A[1:]
tmp = A[0]
ans = A[0]
while True:
    l_tmp_tmp=[]
    for i in l_tmp:
        if i%tmp:
            l_tmp_tmp.append(i%tmp)
            ans = min(ans,i%tmp)
    l_tmp_tmp.append(tmp)
    if len(l_tmp_tmp)>1:
        tmp = ans
        l_tmp=l_tmp_tmp
    else:
        break
print(ans)

Submission status: Accepted

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

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

    A = [a for a in A if a != 0]

print(A[0])

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

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

Submission status: Accepted

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

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

Submission status: Accepted

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


def find(A):
    if len(A) == 1:
        return A.pop()

    if min(A) <= 1000:
        while 1 < len(A):
            m = min(A)
            s = {m}
            for x in A:
                v = x % m
                if 0 < v:
                    s.add(v)
            A = s
        return A.pop()

    for _ in range(10):
        m = min(A)
        s = {m}
        for x in A:
            v = x % m
            if 0 < v:
                s.add(v)
        A = s
    return find(A)


print(find(A))

Submission status: Accepted

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

from fractions import gcd

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

print(ans)

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 = 1001001001
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()))
from fractions import gcd
ans = A[0]
for a in A[1:]:
  ans = gcd(ans,a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

n = int(input())
a = [int(x) for x in input().split()]
ans = reduce(fractions.gcd,a)

print(ans)

Submission status: Accepted

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

    while True:
        mi = min(A)
        A = [a % mi for a in A if a % mi != 0]
        A.append(mi)

        if len(A) == 1:
            print(mi)
            exit()

if __name__ == "__main__":
    main()

Submission status: Accepted

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

res = a[0]

while True:
    base = res
    total = 0
    for i in a:
        if  i % base > 0:
            res = min( res, i % base)
        total +=  i % base
    if total == 0:
        break

print(base)

Submission status: Accepted

Solution code:
import fractions
N=int(input())
A=list(map(int,input().split()))
A.sort()
minhp=0
mi=float("inf")
for i in range(N-1):
    minhp=fractions.gcd(A[0],A[i+1])
    if mi>minhp:
        mi=minhp
print(mi)

Submission status: Accepted

Solution code:
def count_section_by_zero(data):
  count = 0
  flg = False
  start = 0
  for i, d in enumerate(data):
    if flg is False and d != 0:
      count += 1
      flg = True
      
    if d == 0:
      flg = False
  return count

def input_list():
  return list(map(int, input().split()))

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

def lcm_base(x, y):
    return (x * y) // fractions.gcd(x, y)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)

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

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

# 2で割り切れる回数
def divide_two(arg):
  c = 0
  while True:
    if c >= 2:
      break
    if arg % 2 != 0:
      break
    arg //= 2
    c += 1
  return c

# 素因数分解
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

def main():
  n = int(input())
  a = input_list()
  g = gcd_list(a)
  print(g)
  
import math
import fractions
import collections
from functools import reduce
main()

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:
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 = list(map(int,input().split()))
print(functools.reduce(fractions.gcd,A))

Submission status: Accepted

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

ans=A[0]
for item in A:
  ans=gcd(ans,item)
  
print(ans)

Submission status: Accepted

Solution code:
import functools

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

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

def gcd(nums):
    return functools.reduce(euclid, nums)

print(gcd(A))

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline

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:
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


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

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

print(res)

Submission status: Accepted

Solution code:
import fractions

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

print(ans)

Submission status: Accepted

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

def LCM(a, b):
    return a // GCD(a, b) * b

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

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

    return 0


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#118c
#最小公倍数
N = int(input())
A_list = [int(e) for e in input().split()]

#######################################
#https://note.nkmk.me/python-gcd-lcm/
#import math
import fractions
from functools import reduce

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

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

print(gcd(*A_list))

Submission status: Accepted

Solution code:
from functools import reduce
import fractions 
N = int(input())
L = [i for i in map(int,input().split())]
def gcd_list(numbers):
  return reduce(fractions.gcd,numbers)
print(gcd_list(L))

Submission status: Accepted

Solution code:
n=int(input())
#n,m=map(int,input().split())
al=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

import fractions
#gcd=fractions.gcd(a,b)#最大公約数
#lcm=(a*b)/fractions.gcd(a,b)#最小公倍数
gcd=al[0]
for i in range(1,n):
    gcd=fractions.gcd(gcd,al[i])

print(gcd)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
while len(A)>1:
  A.sort()
  tmp = [A[0]]
  for i in range(1,len(A)):
    if A[i]-A[0]>0 and A[i]%A[0]!=0:
      tmp.append(A[i]%A[0])
  A = tmp
print(A[0])

Submission status: Accepted

Solution code:
import fractions

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

base=A[0]

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

print(base)

Submission status: Accepted

Solution code:
n = int(input()) 
a = list(map(int, input().split()))
y = a[0]
for i in range(1,n):
    x = a[i]
    if(x < y):
        c = x
        x = y
        y = c
    while(y != 0):
        c = x % y
        x = y
        y = c
    y = x
    if(y == 1):
        break
print(y)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
nums = n
nin = a[0]
next_nin = a[0]
while nums != 1:
    for i in range(n - nums + 1,n):
        a[i] %= nin
        if a[i] != 0:
            next_nin = min(next_nin, a[i])
        else:
            nums -= 1
    a.sort()
    nin = next_nin
print(nin)

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 heapq
N = int(input())
h = list(map(int, input().split()))
heapq.heapify(h)

while len(h) > 1:
  monster = heapq.heappop(h)
  tmp = [monster]
  heapq.heapify(tmp)
  while len(h) > 0:
    num = heapq.heappop(h) % monster
    if num != 0:
      heapq.heappush(tmp, num) 
  h = tmp
print(heapq.heappop(h))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-


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

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

    print(A[0])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from sys import stdin
from fractions import gcd
def main():
    #入力
    readline=stdin.readline
    N=int(readline())
    A=list(map(int,readline().split()))

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

if __name__=="__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import heapq

n = int(input())
A = list(map(lambda x: int(x) * (-1), input().split()))

heapq.heapify(A)

while len(A) > 1:
    Amax1 = heapq.heappop(A) * (-1)
    Amax2 = heapq.heappop(A) * (-1)
    pushA = Amax1 % Amax2
    if pushA == 0:
        heapq.heappush(A, Amax2 * (-1))
    else:
        heapq.heappush(A, pushA * (-1))
        heapq.heappush(A, Amax2 * (-1))

print(A[0] * (-1))

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:

import numpy as np


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


def submit():
    n = int(input())
    alist = list(map(int, input().split()))

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

    print(g)
    

if __name__ == "__main__":
    submit()

Submission status: Accepted

Solution code:

import numpy as np


def submit():
    n = int(input())
    alist = list(map(int, input().split()))

    while True:
        curr_idx = np.argmin(alist)
        curr_min = alist[curr_idx]

        surplus_sum = 0
        for i in range(len(alist)):
            if i == curr_idx:
                continue
            alist[i] %= curr_min
            surplus_sum += alist[i]

        if surplus_sum == 0:
            print(curr_min)
            break

        alist = [a for a in alist if a]
    

if __name__ == "__main__":
    submit()

Submission status: Accepted

Solution code:
from functools import reduce

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

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

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd, numbers)
def main():
    n = int(input())
    num_list = list(map(int, input().split()))

    print(gcd_list(num_list))

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

Submission status: Accepted

Solution code:
from fractions import gcd
 
n = int(input())
aaa = list(map(int, input().split()))
ans = aaa[0]
for a in aaa[1:]:
    ans = gcd(ans, a)
print(ans)
'''
最大公約数。
2匹の状態を考える。A1=22,A2=14とする。
常にHPの低い方を、高い方に攻撃させる。
phase  A1  A2
    1  22←14
    2   8→14
    3   8← 6
    4   2→ 6
    5   2→ 4
    6   2→ 2
    7   2   0    Ans:2
このプロセスは、2数の最大公約数を求めるユークリッドの互除法と
同じ操作になる。残る1匹のモンスターのHPは2数の最大公約数となる。
逆に、この2数同士の引き算だけで、最大公約数以下の値は作れない。
（最大公約数gの倍数同士の引き算では、gの倍数しか作れない）
最大公約数は必ず作れる＆最大公約数未満は作れない→答えは最大公約数。
3匹以上の場合も同じことが言える。 
N個の数の最大公約数は、3匹目は1匹目と2匹目で生き残った方、
4匹目はさらにそこで生き残った方…と闘わせれば作れる。
逆にこれらの数の引き算では最大公約数の倍数しか作れない。
'''

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

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

while len(a) > 1:
    a.append(gcd(a.pop(), a.pop()))

print(a.pop())

Submission status: Accepted

Solution code:
import fractions
n = int(input())

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

Submission status: Accepted

Solution code:
import fractions
INF = 100000000000

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

min_gcd = INF

for a in range(len(lists) - 1):
  min_gcd = min(min_gcd, fractions.gcd(lists[a], lists[a+1]))

print(min_gcd)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
def input():
    return sys.stdin.readline()[:-1]

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

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


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

if __name__ == "__main__":
    main()

Submission status: Accepted

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

N = int(input().strip())
a_list = [int(i) for i in input().rstrip().split()]
#-----

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

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

print(ans)

Submission status: Accepted

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

N = int(input().strip())
a_list = [int(i) for i in input().rstrip().split()]
#-----

def gcd(a,b):
    x = max(a,b)
    y = min(a,b)

    while y != 0:
        r = x % y
        
        x = y
        y = r
    
    return x

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

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

num = a[0]

for i in range(1,n):
    num = gcd(num, a[i])

print(num)

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

def gcd(a: int, b: int) -> int:
    """a, bの最大公約数(greatest common divisor: GCD)を求める
    計算量: O(log(min(a, b)))
    """
    if b == 0:
        return a
    return gcd(b, a%b)


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


print(multi_gcd(a))

Submission status: Accepted

Solution code:
from fractions import gcd

n = int(input())
a = list(map(int,input().split()))
res = 0
for i in a:
    res = gcd(i, res)
print(res)

Submission status: Accepted

Solution code:
import fractions
import functools

def gcd_list(nums):
    return functools.reduce(fractions.gcd, nums)


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

Submission status: Accepted

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

import fractions

ans = A[0]
for i in A :
    ans = fractions.gcd(ans, i)

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/python3
# -*- coding:utf-8 -*-

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

def main():
  n = int(input())
  As = list(map(int, input().split()))
  As.sort()
  min = 10**9 + 1
  num = As[0]
  for A in As[1:]:
    num = gcd(num, A)
  print(num)
  
if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
def main():
  import sys
  import fractions
  input = sys.stdin.readline
  n=int(input())
  a=list(map(int,input().split()))
  ans=a[0]
  for i in range(n):
    ans=fractions.gcd(a[i],ans)
  print(ans)
if __name__=='__main__':
  main()