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

for a in alist:
  gcd=fractions.gcd(gcd,a)
  
print(gcd)

Submission status: Accepted

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

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

Submission status: Accepted

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

print(reduce(gcd, a))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

def gcdli(xl):
    #xlはlist
    return reduce(gcd , xl)

def monsters_battle_royale(n, al):

    ans = gcdli(al)

    return ans

def main():
    n = int(input())
    al = list(map(int, input().split()))
    print(monsters_battle_royale(n, al))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()
import numpy as np
def main():
    n=int(input())
    A=np.array([int(_) for _ in input().split()])
    while A.size>1:
        min_A=np.min(A)
        A=np.fmod(A,min_A)
        A=A[A>0]
        A=np.append(A,min_A)
    print(A[0])
    

if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
n = int(input())
ais = list(map(int, input().split()))
for i in range(n-1):
  a = ais[i]
  b = ais[i+1]
  if a < b:
    a, b = b, a
  while a > 0 and b > 0:
    a = a % b
    a,b = b,a
  ais[i+1] = a
  ais[i] = b
print(max(ais))

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

#最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

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

print(gcd_list(A))

Submission status: Accepted

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

from functools import reduce
from fractions import gcd

#最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

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

print(gcd_list(A))

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
#from itertools import combinations # (string,3) 3回
#from collections import deque
#import collections.defaultdict
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    from fractions import gcd
    n = int(input())
    A = readInts()
    g = 0
    for i in range(n):
        g = gcd(g,A[i])
    print(g)
if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
from fractions import gcd

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N = ir()
A = lr()
g = A[0]
for a in A:
    g = gcd(g, a)
print(g)

Submission status: Accepted

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

min_A = min(A)
prev_answer = None
answer = min_A
while True:
    if answer == prev_answer: break

    next_answer = answer
    for Ai in A:
        remainder = Ai % answer
        if remainder == 0: continue

        next_answer = min(remainder, next_answer)

    prev_answer = answer
    answer = next_answer

print(answer)

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:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
def gcdl(l):
    from functools import reduce
    return reduce(lambda x, y: gcd(x, y), l)
n=input()
print(gcdl(list(map(int,input().split()))))

Submission status: Accepted

Solution code:
# solution

import fractions

data=int(input())
array=list(map(int,input().split()))
array1=[]
for i in range(1,data):
    array1.append(fractions.gcd(array[0],array[i]))
print(min(array1))

Submission status: Accepted

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


n = int(input())

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

Submission status: Accepted

Solution code:
import sys
from io import StringIO
import unittest
from fractions import gcd
# from math import gcd
from functools import reduce

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

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

    gcd_num = gcd_list(a)

    print(gcd_num)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """4
2 10 8 40"""
        output = """2"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """4
5 13 8 1000000000"""
        output = """1"""
        self.assertIO(input, output)
    def test_入力例_3(self):
        input = """3
1000000000 1000000000 1000000000"""
        output = """1000000000"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Accepted

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

ifContinue = True
while ifContinue:
    ifContinue = False
    counter = 0
    for i in range(N):
        if not A[i] == 0:
            counter += 1
            if counter == 2:
                ifContinue = True
                break
    min = 10**9+1
    index = -1
    for i in range(N):
        if A[i] < min and not A[i] == 0:
            min = A[i]
            index = i

    for i in range(N):
        if i == index or A[i] == 0:
            continue
        else:
            A[i] = A[i] % min

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

import fractions
from functools import reduce

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()))
# aの最大公約数を求めればいい
def gcd(a, b):
    while b:
        a, b = b, a%b
    return a
# n個の数字の最大公約数
import functools
def gcdn(nums):
    return functools.reduce(gcd, nums)

print(gcdn(a))

Submission status: Accepted

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

ans = 0

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
 
A = list(map(int, input().split()))
 
t = max(A)
 
from fractions import gcd
 
for i in A:
    t = gcd(t, i)
print(t)

Submission status: Accepted

Solution code:
from fractions import gcd


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

A.sort()
ans = int(1e9)
for i in range(0, N - 1):
    if A[i] < A[i + 1]:
        ans = min(ans, gcd(A[i], A[i + 1]))
    else:
        ans = min(ans, A[i])

print(ans)

Submission status: Accepted

Solution code:
n = int(input())

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

t = max(A)

from fractions import gcd

for i in A:
    t = gcd(t, i)
print(t)

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    while len(A) > 1:
        m = min(A)
        A = [a % m for a in A if a % m != 0]
        A.append((m))

    print(m)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from heapq import heapify, heappush, heappop

def main():
    N = int(input())
    A = list(map(int, input().split()))
    heapify(A)
    while len(A) > 1:
        m = heappop(A)
        A = [a % m for a in A if a % m != 0]
        A.append((m))

    print(m)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from functools import reduce

def gcd(a, b): return gcd(b, a % b) if b else abs(a)
def lcm(a, b): return abs(a // gcd(a, b) * b)

n, *a = map(int, sys.stdin.read().split())

def main():
    print(reduce(gcd, a))

if __name__ ==  '__main__':
    main()

Submission status: Accepted

Solution code:
def gcd2(x,y):
  if y==0: return x
  return gcd2(y,x%y)
def gcd(a):
  ans = a[0]
  for i in range(1,len(a)):
    ans = gcd2(ans,a[i])
  return ans
N = int(input())
a = list(map(int,input().split()))
print(gcd(a))

Submission status: Accepted

Solution code:
n = int(input()) # 入力が1つ
# map(int, input().split()) # 入力が複数
monster = [int(i) for i in input().split()] # 配列で数字

def gcd(x, y): #GCD
    # greatest_common_divisor
    if x < y:
        x, y = y, x
    if y == 0:
        return 0
    if x % y == 0:
        return y
    return gcd(y, x % y)


l = monster[0]
for m in monster:
    l = gcd(l, m)
print(l)

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    import fractions
    n = int(input())
    A = readInts()
    g = fractions.gcd(A[0],A[1])
    for i in range(2,n):
        g = fractions.gcd(g,A[i])
    print(g)


if __name__ == '__main__':
  main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

print(reduce(fractions.gcd,A))

Submission status: Accepted

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


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

Submission status: Accepted

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

from fractions import gcd
from functools import reduce

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

print(gcd_list(A))

Submission status: Accepted

Solution code:
def main():
    from functools import reduce

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

    N = int(input())
    *a, = map(int, input().split())

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


if __name__ == '__main__':
    main()

# import sys
#
# sys.setrecursionlimit(10 ** 7)
#
# input = sys.stdin.readline
# rstrip()
# int(input())
# map(int, input().split())

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

Submission status: Accepted

Solution code:
import math
def main():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    ans = a[0]
    tmp = 0
    while True:
        for i in range(1,n):

            a[i] %= ans
            if a[i] != 0:
                tmp = min(ans,a[i])
        if sum(a) == ans:
            print(ans)
            return
        a.sort()
        ans = tmp
        a[0] = tmp

if __name__=='__main__':
    main()

Submission status: Accepted

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

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:
def main():
    N = int(input())
    A = [int(i) for i in input().split()]
    minA = min(A)
    while any(a % minA for a in A):
        for i in range(N):
            if A[i] % minA:
                A[i] %= minA
        minA = min(A)
    print(minA)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

common = fractions.gcd(A[0], A[1])

if N >= 2:
	for i in range (2, N):
		common = fractions.gcd(common, A[i])

print(common)

Submission status: Accepted

Solution code:
def resolve():
    import heapq
    n = int(input())
    a = list(map(int, input().split()))
    a = sorted(a)
    while True:
        mini = a[0]
        others = a[1:]
        others = [x % mini for x in others]
        if sum (others) == 0:
            print(a[0])
            exit()
        a = [mini] + others
        a =[i for i in a if i!= 0]
        a = sorted(a)
resolve()

Submission status: Accepted

Solution code:
def main():
    input()
    a_list = list(set((map(int, input().split(' ')))))
    a_list.sort()
    small_a = a_list[0]
    for a in a_list:
        surplus = a % small_a
        if surplus != 0:
            while small_a - surplus >= 1:
                small_a = small_a - surplus
                if small_a < surplus:
                    small_a, surplus = surplus, small_a
            if small_a == 1:
                break
    print(small_a)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import gcd
N=int(input())
A=list(map(int, input().split()))
if len(set(A))==1:
  print(A[0])
  exit()
  
#A=sorted(A, reverse=True)
alleven=True


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

print(now)

Submission status: Accepted

Solution code:
from fractions import gcd

n=int(input())
a=list(map(int,input().split()))
ans=10**18
t=0
for i in range(1,n):
  if i==1:
    t=gcd(a[0],a[1])
    ans=min(ans,t)
    continue
  t=gcd(t,a[i])
  ans=min(t,ans)
print(ans)

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 sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = True

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

Submission status: Accepted

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

next = []
while(1):

    A.sort()
    m = A[0]
    next = []
    for x in A:
        if x % m:
            next.append(x % m)
    next.append(m)
    if next[0] == next[-1]:
        break
    A = list(next)
print(next[0])

Submission status: Accepted

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

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

print(gcd_list(x))

Submission status: Accepted

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

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

from functools import reduce
print(reduce(gcd,A))

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
res = a[0]
for i in range(n-1):
    res = fractions.gcd(res,a[i+1])
print(res)

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce


def main():
    n = int(input())
    a = [int(x) for x in input().split()]
    print(reduce(gcd, a))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

import fractions
tmp = a[0]
for num in a:
    tmp = fractions.gcd(tmp, num)           #最大公約数
print(tmp)

Submission status: Accepted

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

def euclid(num1,num2):
  if num1<num2: num1,num2 = num2,num1
  if num2 != 0: return euclid(num2,num1%num2)
  else: return num1
  
def euclid_list(l):
  ans = euclid(l[0],l[1])
  for i in range(2,n):
    ans = euclid(ans,l[i])
  return ans

ret = euclid_list(monster)
print(ret)

Submission status: Accepted

Solution code:
import fractions

N = int(input())

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

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

print(ret)

Submission status: Accepted

Solution code:
import fractions

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

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

print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce


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


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

g = gcd_list(A)
print(g)

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
f=True
X=[A]
c=0
while f:
  B=sorted(X[c])
  while 0 in B:
    B.remove(0)
  mod=B[0]
  for i in range(1,len(B)):
    B[i]%=mod
  X.append(B)
  c+=1
  if X[c]==X[c-1]:
    f=False
print(min(X[c]))

Submission status: Accepted

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

Submission status: Accepted

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

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

    v = A[0]
    for i in range(1, N):
        v = lcm(v, A[i])

    print(v)


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

Submission status: Accepted

Solution code:
from functools import reduce

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

def gcd(num):
    return reduce(gcd_base,num)

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

Submission status: Accepted

Solution code:
import sys
input = lambda: sys.stdin.readline().rstrip()

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

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

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

g = gcd(A[0], A[1])
for i in range(2, len(A)):
    g = gcd(g, A[i])

print(g)

Submission status: Accepted

Solution code:
"""
keywords: 最大公約数、ユークリッドの互除法
"""
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
from functools import reduce

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

def main():
    n = II()
    a_lst = MII()
    print(reduce(gcd, a_lst))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))

def main():
    n = II()
    a_lst = sorted(MII(), reverse=True)
    while True:
        minv = a_lst[-1]
        a_lst = [a%minv for a in a_lst[:-1] if a%minv != 0]
        a_lst.append(minv)
        a_lst.sort(reverse=True)
        if len(a_lst) == 1: break
    print(a_lst[0])

if __name__ == '__main__':
    main()

Submission status: Accepted

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

    while len(lst) > 1:
        mi = lst[0]
        attacked = [lst[i]%mi for i in range(1, len(lst)) if lst[i]%mi != 0]
        lst = [mi] + attacked
        lst.sort()
    print(lst[0])
main()

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

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

Submission status: Accepted

Solution code:
import fractions
import functools
n = int(input())
A = [int(x) for x in input().split()]
print(functools.reduce(fractions.gcd, A))

Submission status: Accepted

Solution code:
import sys
stdin = sys.stdin
sys.setrecursionlimit(10 ** 7)
from functools import reduce

i_i = lambda: int(i_s())
i_l = lambda: list(map(int, stdin.readline().split()))
i_s = lambda: stdin.readline().rstrip()

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

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

N = i_i()
A = i_l()

print(gcd_list(A))

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
import fractions
def multi_gcd(a):
    ans = a[0]
    for i in range(1, len(a)):
        ans = fractions.gcd(ans, a[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()))

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

print(ans)

Submission status: Accepted

Solution code:
n = int(input())
s = list(map(int,input().split()))
un = 0
un_1 = 0


while un < n-1:
  s.sort()
  sign = 0
  for i in range(un_1,n):
    if s[i] == 0:
      un = i+1
      continue

    if i == un:
      continue
    
    temp = s[i] - (s[i]//s[un])*s[un]
    
    if 0 <= temp:
      s[i] = temp
    elif temp < 0:
      s[i] = 0
    
  un_1 = un
    
print(s[un])

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

Submission status: Accepted

Solution code:
mod = 10 ** 9 + 7
mod2 = 2 ** 61 + 1
from collections import deque
import heapq
from bisect import bisect_left, insort_left, bisect_right

_NUMINT_ALL = list(range(10))


def main():
    ans = solve()
    if ans is not None:
        print(ans)


def solve():
    N = iip(False)
    A = iip()
    l = len(A)

    while True:
        m = min(A)
        mx = max(A)
        if m == mx:
            return m

        for i in range(l):
            if A[i] % m == 0:
                A[i] = m
            else:
                A[i] %= m








#####################################################ライブラリ集ここから

def iip(listed=True, num_only=True):  # 数字のinputをlistで受け取る
    if num_only:
        ret = [int(i) for i in input().split()]
    else:
        ret = [int(i) if i in _NUMINT_ALL else i for i in input().split()]

    if len(ret) == 1 and not listed:
        return ret[0]
    return ret


def saidai_kouyakusuu(a, b):  # 最大公約数
    for i in soinsuu_bunkai(a):
        if b % i == 0:
            b //= i
    return a * b


def sort_tuples(l, index):  # タプルのリストを特定のインデックスでソートする
    if isinstance(l, list):
        l.sort(key=lambda x: x[index])
        return l
    else:
        l = list(l)
        return sorted(l, key=lambda x: x[index])


def count_elements(l):  # リストの中身の個数を種類分けして辞書で返す
    d = {}
    for i in l:
        if i in d:
            d[i] += 1
        else:
            d[i] = 1
    return d


def safeget(l, index, default="exception"):  # listの中身を取り出す時、listからはみ出たり
    if index >= len(l):                      # マイナスインデックスになったりするのを防ぐ
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。配列の長さは", len(l), "です"]))
        else:
            return default
    elif index < 0:
        if default == "exception":
            raise Exception("".join(["safegetに不正な値 ", index, "が渡されました。負の値は許可されていません"]))
        else:
            return default
    else:
        return l[index]


def iipt(l, listed=False, num_only=True):  # 縦向きに並んでいるデータをリストに落とし込む(iip利用)
    ret = []
    for i in range(l):
        ret.append(iip(listed=listed, num_only=num_only))
    return ret


def sortstr(s):  # 文字列をソートする
    return "".join(sorted(s))


def iip_ord(startcode="a"):  # 文字列を数字の列に変換する(数字と文字は1:1対応)
    if isinstance(startcode, str):
        startcode = ord(startcode)
    return [ord(i) - startcode for i in input()]


def YesNo(s):  # TrueFalseや1, 0をYesNoに変換する
    if s:
        print("Yes")
    else:
        print("No")


def fprint(s):  # リストを平たくしてprintする(二次元リストを見やすくしたりとか)
    for i in s:
        print(i)


def bitall(N):  # ビット全探索用のインデックスを出力
    ret = []
    for i in range(2 ** N):
        a = []
        for j in range(N):
            a.append(i % 2)
            i //= 2
        ret.append(a)
    return ret

def split_print_space(s):  # リストの中身をスペース区切りで出力する
    print(" ".join([str(i) for i in s]))


def split_print_enter(s):  # リストの中身を改行区切りで出力する
    print("\n".join([str(i) for i in s]))


def soinsuu_bunkai(n):  # 素因数分解
    ret = []
    for i in range(2, int(n ** 0.5) + 1):
        while n % i == 0:
            n //= i
            ret.append(i)
        if i > n:
            break
    if n != 1:
        ret.append(n)
    return ret


def conbination(n, r, mod, test=False):  # nCrをmodを使って計算する
    if n <= 0:
        return 0
    if r == 0:
        return 1
    if r < 0:
        return 0
    if r == 1:
        return n
    ret = 1
    for i in range(n - r + 1, n + 1):
        ret *= i
        ret = ret % mod

    bunbo = 1
    for i in range(1, r + 1):
        bunbo *= i
        bunbo = bunbo % mod

    ret = (ret * inv(bunbo, mod)) % mod
    if test:
        # print(f"{n}C{r} = {ret}")
        pass
    return ret


def inv(n, mod):  #  modnにおける逆元を計算
    return power(n, mod - 2)


def power(n, p, mod_=mod):  # 繰り返し二乗法でn**p % modを計算
    if p == 0:
        return 1
    if p % 2 == 0:
        return (power(n, p // 2, mod_) ** 2) % mod_
    if p % 2 == 1:
        return (n * power(n, p - 1, mod_)) % mod_


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

def euclid(a, b):
  while True:
    r = a % b
    a, b = b, r
    if r == 0:
  	  return(a)
    
List.sort(reverse = True)
res = euclid(List[0], List[1])
for i in range(1, n):
  res = euclid(res, List[i])
  if res == 1:
    break
    
print(res)

Submission status: Accepted

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

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)

res = 0
for i in a:
    res = gcd(res, i)
print(res)