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 functools import reduce

def gcd(a, b):
    x = max(a, b)
    y = min(a, b)
    if x % y == 0:
        return y
    else:
        while x % y != 0:
            z = x % y
            x = y 
            y = z
        else:
            return z

def main():
    _ = input()
    monsters = [int(n) for n in input().split(" ")]
    max_gcd = reduce(gcd, monsters)
    print(max_gcd)

if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from collections import Counter

def parse_line(line, type=int):
	return [type(x) for x in line.split(' ')]


def euklide(a, b):
	while a and b:
		if a > b:
			a = a % b
		else:
			b = b % a
	return a + b


def main():
	n = parse_line(input())[0]
	numbers = parse_line(input())

	a = numbers[0]
	for i in range(n - 1):
		a = euklide(a, numbers[i + 1])

	print(a)



	

if __name__ == '__main__':
	main()

Submission status: Accepted

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

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

ans = A[0]

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

print(ans)

Submission status: Accepted

Solution code:
class MathAlgorithm(object):
    @classmethod
    def gcd(cls, a: int, b: int) -> int:
        if b < 0 or (a == 0 and b == 0):
            raise ValueError

        if b > a:
            return cls.gcd(b, a)

        if b == 0:
            return 0

        if a % b == 0:
            return b

        return cls.gcd(b, a % b)


if __name__ == "__main__":
    N = int(input())
    A = [int(i) for i in input().split()]

    ans = A[0]
    for a in A[1:]:
        ans = MathAlgorithm.gcd(ans, a)

    print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# your code goes here


def main(array):
	
	mini = min(array)
	newarray = [mini]
	if mini ==1:
		return 1
	else:
		for a in array:
			if a%mini > 0:
				newarray.append(a%mini)
		if len(newarray) == 1:
			return mini
		else:
			return main(newarray)


n = input()
array = input().split(' ')
array = [int(c) for c in array]

print(main(array))

Submission status: Accepted

Solution code:


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

def gcd_array(someArray) :
    result = someArray[0]
    for i in someArray[1:] :
        result = gcd(i, result)
    return result

N = int(input())
AList = input().split(" ")
AList = [int(i) for i in AList]
AList.sort()
print(gcd_array(AList))

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

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

Submission status: Accepted

Solution code:
def main():
    #モンスター数
    n = int(input())

    #モンスターiの体力:mon[i]
    mon = list(map(int, input().split()))

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

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

    print(ans)

main()

Submission status: Accepted

Solution code:
import fractions
from functools import reduce


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

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

Submission status: Accepted

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


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


ans = a[0]

for i in a:
    x = gcd(ans, i)
    if x < ans:
        ans = x


print(ans)

Submission status: Accepted

Solution code:
def Gcd(a,b):
    if a < b:
        return Gcd(b,a)
    else:
        if a%b:
            return Gcd(b,a%b)
        else:
            return b

N = int(input())
arr = list(map(int,input().split()))
gcd = arr[0]
for i in arr:
    gcd = Gcd(gcd,i)
print(gcd)

Submission status: Accepted

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

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

ans = lst_a[0]
for a in lst_a:
    # 配列の最初からひとつずつ最大公約数を取っていけばよい。
    ans = gcd(ans, a)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

# coding: utf-8

# In[42]:


import numpy as np


# In[100]:


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


# In[104]:


sorted_A = np.sort(np.array(A))


# In[106]:


while len(sorted_A) != 1:
    tmp = sorted_A[1:] % sorted_A[0]
    sorted_A = np.sort(np.append(sorted_A[0], tmp[np.nonzero(tmp)[0]]))
print(sorted_A[0])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def gcd(a, b):
  if a == 0:
    return b
  return gcd(b%a, a)
n = int(raw_input())
lis = map(int, raw_input().strip().split())
if n == 1:
  print lis[0]
else:
  g = gcd(lis[0], lis[1])
  for i in range(2, n):
    g = gcd(g, lis[i])
  print g

Submission status: Accepted

Solution code:
import sys

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

def main():
  input = sys.stdin.readline
  N = int(input())
  A = list(map(int, input().split()))
  ans = A[0]
  for a in A:
    ans = gcd(ans, a)
  print(ans)


if __name__ == '__main__':
  main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

for i in range(1, len(a)):
    while 0 != a[i - 1]:
        r = a[i] % a[i - 1]
        a[i] = a[i - 1]
        a[i - 1] = r
print(a[-1])

Submission status: Accepted

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

while 1 < len(a):
    while 0 != a[0]:
        r = a[1] % a[0]
        a[1] = a[0]
        a[0] = r
    a.pop(0)
print(a[0])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from sys import stdin
# import numpy as np

s_in = lambda: stdin.readline()[:-1]  # s = s_in()
d_in = lambda: int(stdin.readline())  # N = d_in()
ds_in = lambda: list(map(int, stdin.readline().split()))  # List = ds_in()


def gcd(a, b):
    """ Greatest Common Divisor(最大公約数) """
    while b:
        a, b = b, a % b
    return a


N = d_in()
A_list = ds_in()

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

Submission status: Accepted

Solution code:
def gcd(a, b):
    a = max(a,b)
    b = min(a,b)
    r = a - b
    while(r):
        a = max(b,r)
        b = min(b,r)
        r = a % b
    return b    

N = int(input())
HPs = list(map(int, input().split(' ')))

HPs.sort()

r = HPs[0]
for i in range(1,N):
  r = gcd(HPs[i],r)

print(r)

Submission status: Accepted

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

a.sort()
a[0], a[len(a)-1] = a[len(a)-1], a[0]

while a != sorted(a):
  a.sort()
  for i in range(len(a)):
    if a[i] % a[0] == 0:
      a[i] = a[0]
    else:
      a[i] = a[i] % a[0]

print(a[0])

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
a=min(A)
S={n%a for n in A if n%a!=0}

while len(S)>0:
    tmp=a
    a=min(S)
    S={n%a for n in S if n%a!=0}
    if tmp%a!=0:
        S.add(tmp%a)
print(a)

Submission status: Accepted

Solution code:
import functools
import fractions
N = int(input())
monster = [int(i) for i in input().split()]
print(abs(functools.reduce(fractions.gcd,monster)))

Submission status: Accepted

Solution code:
def gcd(x, y):
    # ユークリッドの互除法で最大公約数を見つける
    if y == 0:
        return x
    else:
        return gcd(y, x % y)


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

# 最大公約数の1番小さい値を取る
# a[0]との最大公約数を全パターン取って、小さい方をansに入れる
ans = min(gcd(a[0], x) for x in a)

print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import fractions
import itertools
from functools import reduce
# print(math.gcd(1000000000, 1000000000))


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

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

result = 10 ** 9 + 1

print(gcd(*monsters))

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

def gcd(numbers):
    return reduce(fractions.gcd, numbers)
N=input()
print(gcd(list(map(int, input().split()))))

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

print(a)

Submission status: Accepted

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

# ユークリッドの互除法で最大公約数を求める
def gcd( a, b ):
    # print(a,b)
    if a == 0: return b
    return gcd( b%a, a )

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

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 = [int(i) for i in input().split()]

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

print(ans)

Submission status: Accepted

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

def gcd(n, m):
    if n > m: # require n <= m
        n, m = m, n
    o = m % n
    if o == 0:
        return n
    else:
        m = n
        n = o
        return gcd(n, m)

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

def solve(N: int, A: "List[int]"):
    print(gcds(A))
    return

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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

def gcd(n, m):
    if n > m: # require n <= m
        n, m = m, n
    o = m % n
    if o == 0:
        return n
    else:
        m = n
        n = o
        return gcd(n, m)

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

def solve(N: int, A: "List[int]"):
    """
    [思考]
    体力最小のものを Amin とおく．
    すると，試行の結果体力が Amin より小さくなる可能性がある場合はそれが答え，さもなくば Amin が答え．
    問題はその可能性をどう探索するか．
    """
    print(gcds(A))
    return

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

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
mons = list(map(int,input().split()))
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
result = mons[0]
for i in range(n-1):
    result = gcd(result, mons[i+1])
print(result)

Submission status: Accepted

Solution code:
import math
import sys
from operator import itemgetter
input = sys.stdin.readline

# a = int(input().rstrip())
# a, b = map(int, input().rstrip().split())
# D = list(map(int, input().rstrip().split()))
# H = [int(input().rstrip()) for _ in range(L)]
# DD = [[0 for j in range(100)] for i in range(200)]
# dict = {} ## dictionary

# a = sorted(a, key=lambda x: x[1]))
# if __name__ == '__main__':

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

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

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

Submission status: Accepted

Solution code:
import sys

sys.setrecursionlimit(20000)


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


def gcd(a, b):
    la = max(a, b)
    sm = min(a, b)
    if la % sm == 0:
        return sm
    else:
        return gcd(sm, la - sm)


n = int(input())
A = inpl()
A.sort()
ans = gcd(A[0], A[1])
for a in A:
    ans = gcd(ans, a)
print(ans)

Submission status: Accepted

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

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

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

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

#モンスターiの体力:mon[i]
mon = list(map(int, input().split()))

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

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

print(ans)

Submission status: Accepted

Solution code:
# _*_ coding:utf-8 _*_
#  Atcoder_Beginners_Contest118-C
#  https://atcoder.jp/contests/abc118/tasks/abc118_c
#  ref https://note.nkmk.me/python-gcd-lcm/

def gcd(small,big):
	if big < small:
		big,small = small,big
	if small == 0:
		return big
	else:
		return gcd(big % small,small)

def solveProblem(PowerGauge):
	nowGcd = 0
	for i in range(0,len(PowerGauge),+1):
		nowGcd = gcd(nowGcd,PowerGauge[i])
	answer = nowGcd
	return answer


if __name__ == '__main__':
	_ = int(input().strip())
	An = list(map(int,input().strip().split(' ')))
	solution = solveProblem(An)
	print("{}".format(solution))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
def gcd(x,y):
 if x%y: return gcd(y,x%y)
 else: return y
m = a[0]
for i in range(n): m = gcd(m,a[i])
print(m)

Submission status: Accepted

Solution code:
def get_int(): return int(input())
def get_float(): return float(input())
def get_line(): return input().split()
def get_lines(v): return [get_line() for _ in range(v)]
def get_int_line(): return list(map(int, get_line()))
def get_int_lines(v): return [get_int_line() for _ in range(v)]
def get_float_line(): return list(map(float, get_line()))
def get_float_lines(v): return [get_float_line() for _ in range(v)]

import functools
import math

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


N = get_int()
A = get_int_line()

print(functools.reduce(gcd, A))

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)

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())
s = list(map(int,input().split(" ")))
g=s[0]
for i in range(1,n):
  a=fractions.gcd(g,s[i])
  if a<g:
    g=a
print(g)

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

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

Submission status: Accepted

Solution code:
from fractions import gcd 


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

print(num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions


n = int(input())
l = list(map(int, input().split()))
num = 0
for i in range(len(l)):
    num = fractions.gcd(num, l[i])

print(num)

Submission status: Accepted

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


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

print(num)

Submission status: Accepted

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

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

min_g = 10 ** 9 + 1
for n in range(N-1):
    g = euclid(a_list[n], a_list[n+1])
    min_g = min(min_g, g)

print(min_g)

Submission status: Accepted

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

import array
from bisect import *
from collections import *
import fractions
import heapq
from itertools import *
import math
import random
import re
import string
import sys

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

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

ans = None
for a in As:
    if ans is None:
        ans = a
    else:
        ans = gcd(ans, a)
print(ans)

Submission status: Accepted

Solution code:
import numpy as np
import math
import sys

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

while True:
    tmpmin = np.min(a[a!=0])
    a[a!=tmpmin] %= tmpmin
    #print(a,tmpmin)
    if tmpmin == np.min(a[a!=0]):break
    if np.sum(a) == 0: break

print(tmpmin)

Submission status: Accepted

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

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

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


def main():
    n = I()
    a = LI()
    r = a[0]
    for c in a[1:]:
        r = fractions.gcd(r,c)

    return r



print(main())

Submission status: Accepted

Solution code:
N = int(input())
As = [int(i) for i in input().split()]
while True:
    As = sorted(As)
    if len(As) == 1:
        break
    As = [As[0]] + [i % As[0] for i in As[1:] if i % As[0] > 0]
print(As[0])

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)

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

print(ans)

Submission status: Accepted

Solution code:
#abc118c
import functools

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

n=int(raw_input())
l=map(int,raw_input().split())
print functools.reduce(gcd,l)

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

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

Submission status: Accepted

Solution code:
import heapq

N=int(input())
A=sorted(map(int,input().split()))[::-1]
que = []
for x in A:
    heapq.heappush(que, -x)

ans=A[0]
while len(que) > 1:
    v1 = abs(heapq.heappop(que))
    v2 = abs(heapq.heappop(que))
    if v2 == 0:
        print (v1)
        break
    heapq.heappush(que, -(v1 % v2))
    heapq.heappush(que, -(v2))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

# import bisect
# import math
# import itertools

# import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

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


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n = ip.I()
    a = ip.IL()
    res = 1000000010

    for i in r(1, n):
        res = min(res, id.gcd(a[0], a[i]))

    print(res)


main()

Submission status: Accepted

Solution code:
# coding: utf-8
import sys

# import bisect
# import math
# import itertools

# import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x // y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

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


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n = ip.I()
    a = ip.IL()
    res = max(a)

    for i in r(1, n):
        res = min(res, id.gcd(a[0], a[i]))

    print(res)


main()

Submission status: Accepted

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


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


ans = a_list[0]

for i in range(N):
    ans = gcd(ans, a_list[i])
print(ans)

Submission status: Accepted

Solution code:
import numpy as np

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

while A.size > 1:
    A[1:] = A[1:] % A[0]
    A = np.unique(A)
    if A[0] == 0:
        A = A[1:]

print(A[0])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import numpy as np

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

N = int(input())
monster_list = list(map(int, input().split()))
monster_list.sort(reverse=True)

for i in range(len(monster_list) - 1):
    monster_list[i + 1] = gcd(monster_list[i + 1], monster_list[i])

print(monster_list[-1])

Submission status: Accepted

Solution code:
def gcd(a, b):
    return gcd(b % a, a) if a and b else max(a, b)
    
n = int(input())
arr = sorted(list(map(int, input().split(' '))))
maxi = arr[-1]
gc = maxi
for num in arr[:-1]:
    if gcd(num, maxi) < gc:
        gc = gcd(num, maxi)

print(gc)