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 get_gcd(a, b):
    if a<b:a,b=b,a
    if b == 0 :return a
    else:return get_gcd(b,a%b)

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
m = min(A)
n = 0
while m != n:
    m = min(A)
    a = [m]
    for i in A:
        i %= m
        if i != 0:
            a.append(i)
    A = a
    n = min(A)
print(n)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    before = A
    after = []
    for _ in range(pow(10, 9)):
        x = before[0]
        if len(before) == 1:
            print(x)
            return
        after.append(x)
        for i in range(1, len(before)):
            y = before[i]%x
            if y != 0:
                after.append(y)
        after.sort()
        before = after
        after = []

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
from functools import reduce
from math import gcd

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

Submission status: Accepted

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

def gcd(x,y):
    if y > x:
        x,y = y,x
    if x%y == 0:
        return y
    else:
        return gcd(y,x%y)
        
from functools import reduce
ans = reduce(gcd,L)
print(ans)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
if max(a) != min(a):
    while a.count(0) != len(a)-1:
        a.sort()
        b = [a[0]]
        for i in a[1:]:
            if i%a[0] != 0:
                b.append(i%a[0])
        a = b
    print(max(a))
else:
    print(a[0])

Submission status: Accepted

Solution code:
import bisect,collections,copy,itertools,math,string
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
def main():
    from functools import reduce
    def gcd(*numbers):
        return reduce(math.gcd, numbers)
    n = I()
    lst = LI()
    ans = gcd(*lst)
    print(ans)
main()

Submission status: Accepted

Solution code:
import math

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

print(ans)

Submission status: Accepted

Solution code:
import functools
def euclid(a, b):
    if b == 0:
        return a
    else:
        return euclid(b, a%b)

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



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

print(gcd(a))

Submission status: Accepted

Solution code:
import math

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

ans = math.gcd(al[0], al[1])

for i in range(2, n):
    ans = math.gcd(ans, al[i])

print(ans)

Submission status: Accepted

Solution code:
import math
from functools import reduce
N = int(input())
A = list(map(int, input().split()))

print(reduce(math.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:
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
print(gcd_list(A))

Submission status: Accepted

Solution code:
import sys
import math


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

n = inint()
A = inintl()

m = min(A)

mod_min = 10**9

for a in A:
    if a % m == 0:
        continue
    mod_min = min(mod_min, a % m)

if mod_min == 10**9:
    print(m)
else:
    print(math.gcd(m, mod_min))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
N = input()

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

print(reduce(gcd, List))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# https://atcoder.jp/contests/abc118/tasks/abc118_c

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

ans = A[0]
for a in A[1:]:
    if ans > a:
        ans, a = a, ans  # ansが常に小さくなるようにする。
    while a % ans != 0:
        a = a % ans
        a, ans = ans, a
    if ans == 1:
        print(1)
        quit()

print(ans)

Submission status: Accepted

Solution code:
from math 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()))

g = A[0]
import math
for i in range(1, N):
    g = math.gcd(g, A[i])

print(g)

Submission status: Accepted

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

x = a[0]
for i in range(1,n):
    x,y = max(x,a[i]),min(x,a[i])
    while y!=0:x,y=y,x%y
print(x)

Submission status: Accepted

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

Submission status: Accepted

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

x = a[0]
for i in range(1,n):
    y = a[i]
    x,y = max(x,y),min(x,y)
    while y!= 0:
        x,y = y,x%y
print(x)

Submission status: Accepted

Solution code:
N=int(input())
mns=list(map(int,input().split()))
atk=min(mns)
while 1:
    mns=list(filter(lambda x: x!=0, map(lambda x: x%atk, mns)))
    if not mns:
        break
    mns+=[atk]
    atk=min(mns)
print(atk)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

print(gcd_list(l))

Submission status: Accepted

Solution code:
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
import sys
INF = float('inf')
mod = 10**9+7


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

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    n = I()
    lst = LI()
    ans = lst[0]
    for i in range(1, n):
        ans = gcd(ans, lst[i])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

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

print(gcd_list(a))

Submission status: Accepted

Solution code:
import math

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

Submission status: Accepted

Solution code:

from math import gcd
from functools import reduce

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

print(reduce(gcd, X))

Submission status: Accepted

Solution code:
N=int(input())
A=map(int,input().split())
import math
from functools import reduce

print(reduce(math.gcd, A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd

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

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import heapq

input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))
    heapq.heapify(A)
    while True:
        m1 = heapq.heappop(A)
        try:
            m2 = heapq.heappop(A)
        except IndexError:
            print(m1)
            break
        m2 %= m1
        heapq.heappush(A, m1)
        if m2 > 0:
            heapq.heappush(A, m2)


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import gcd

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


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

Submission status: Accepted

Solution code:
from math import *
n=int(input())
l=list(map(int,input().split()))
g=l[0]
for i in range(1,n):
    g=gcd(g,l[i])
print(g)

Submission status: Accepted

Solution code:
import math
from math import gcd
INF = float("inf")

import sys
input=sys.stdin.readline
sys.setrecursionlimit(500*500)
import itertools
from collections import Counter,deque

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


if __name__=="__main__":
    main(
    )

Submission status: Accepted

Solution code:
import math 
from functools import reduce

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

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

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

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

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

n = int(input())
a = [int(i) for i in input().split()]
if 1 in a:
    ans = 1
else:
    ans = gcd_list(a)
print(ans)

Submission status: Accepted

Solution code:
from math 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:
import math
n= int(input())
a_list = list(map(int, input().split()))
gcd = a_list[0]
for i in range(1,n):
    gcd = math.gcd(gcd,a_list[i])
    
    
print(gcd)

Submission status: Accepted

Solution code:
from math import gcd
def readinput():
    n=int(input())
    a=list(map(int,input().split()))
    return n,a

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

if __name__=='__main__':
    n,a=readinput()
    ans=main(n,a)
    print(ans)

Submission status: Accepted

Solution code:
from math import gcd


def lgcd(l):
    res = l[0]
    for i in range(1, len(l)):
        res = gcd(res, l[i])

    return res


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

Submission status: Accepted

Solution code:
def gcd(x, y):
    if(y > x):
        tmp = y
        y = x
        x = tmp

    while(int(x%y)>0):
        r = x%y
        x = y
        y = r

    return y
        


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

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

print(ans)

Submission status: Accepted

Solution code:
from heapq import heappop,heappush
N = int(input())
A = list(map(lambda x: -1*int(x),input().split()))

now = -1 * heappop(A)
while(A):
    next = -1 * heappop(A)
    if now % next != 0:
        heappush(A,-1*(now%next))
    now = next
print(now)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

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

Submission status: Accepted

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

def gcd(p, q):
    if q == 0:
        return p
    else:
        return gcd(q, p % q)

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

print(g)

Submission status: Accepted

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

import math
g = math.gcd(a[0], a[1])
for i in range(2, n):
    g = math.gcd(g, a[i])

print(g)

Submission status: Accepted

Solution code:
import sys
from math import gcd
from functools import reduce

readline = sys.stdin.buffer.readline


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

    print(reduce(gcd, A))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from math import gcd
from functools import reduce

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, *A = map(int, read().split())

    print(reduce(gcd, A))
    return


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
a.sort()
#print(a)
ans=10**10
for i in range(n-1):
    GCD=math.gcd(a[i],a[i+1])
    if ans>GCD:
        ans=GCD
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
from math import gcd


n = int(input())

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

print(reduce(gcd, A))

Submission status: Accepted

Solution code:
import math
from functools import reduce

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


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

answer = gcd(*A)
print(answer)

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 python
import sys 
import math
input = sys.stdin.readline

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

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

print(ans)

Submission status: Accepted

Solution code:
import math

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

ans = aL[0]
for a in aL:
    ans = min(math.gcd(aL[0], a), ans)

print(ans)

Submission status: Accepted

Solution code:
from math 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 math

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

d = a[0]

for i in range(1, n):
    d = math.gcd(a[i], d)

print(d)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
from functools import reduce

# 0がある場合はもう片方を出力
def gcd(a, b):  
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    r = a % b
    return gcd(b, r)

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

N = ii()
A = li()

print(gcd_list(A))

Submission status: Accepted

Solution code:
from math import gcd
from functools import reduce

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from math import gcd
N = int(input())
A = list(map(int, input().split()))
k = 0
for i in A:
  k = gcd(i,k)
print(k)

Submission status: Accepted

Solution code:
import math
N = int(input())
A = list(map(lambda a: int(a), input().split(" ")))

gcd = A[0]
for i in range(len(A)):
  gcd = math.gcd(gcd, A[i])
  
print(gcd)

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

from math import gcd
g = 0
for a in As:
	g = gcd(g, a)
print(g)

Submission status: Accepted

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

import math

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

Submission status: Accepted

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

while len(A) > 1:
    A.append(gcd(A.pop(), A.pop()))
print(A[0])

Submission status: Accepted

Solution code:

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

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

print(ans)

Submission status: Accepted

Solution code:
from math import gcd
N = int(input())
A = list(map(int,input().split()))
ans = 0
for a in A:
    ans = gcd(ans, a)
print(ans)

Submission status: Accepted

Solution code:
N,*A = map(int,open(0).read().split())
A.sort()
B = [[] for i in range(100)]
B[0]= A
#print(B)
for i in range(99):
  B[i+1].append(B[i][0])
  for j in range(1,len(B[i])):
    x = B[i][j]%B[i][0]
    if x!=0:
      B[i+1].append(x)
  B[i+1]=sorted(B[i+1])
  if len(B[i])<=1:
    break
print(B[i][0])

Submission status: Accepted

Solution code:
import math

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

res = math.gcd(a[0], a[1])

for x in a:
   res = math.gcd(res, x)

print(res)

Submission status: Accepted

Solution code:
import math

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
n,*a=map(int,open(0).read().split())
e=fractions.gcd(a[0],a[1])
for i in range(1,n):
    e=fractions.gcd(e,a[i])

print(e)

Submission status: Accepted

Solution code:
import math

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

ans = nums[0]
for n in nums[1:]:
    ans = math.gcd(ans, n)
print(ans)

Submission status: Accepted

Solution code:
from math import gcd
N = int(input())
A = list(map(int, input().split()))
for i, a in enumerate(A):
  if i == 0:
    g = a
    continue
  g = gcd(g, a)
print(g)

Submission status: Accepted

Solution code:
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

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

if __name__ == "__main__":
    solve()

Submission status: Accepted

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

import math
from functools import reduce
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
print(gcd_list(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from functools import reduce


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

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

Submission status: Accepted

Solution code:
from functools import reduce
import math
def main():
    n = int(input())
    A = list(map(int, input().split()))
    print(reduce(math.gcd, A))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from math import gcd
from itertools import product
def inpl(): return list(map(int, input().split()))

N = int(input())
A = inpl()
a = A[0]
for b in A[1:]:
    a = gcd(a, b)
print(a)

Submission status: Accepted

Solution code:
import sys

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

def solve():
    input = sys.stdin.readline
    N = int(input())
    A = [int(i) for i in input().split()]
    gcdA = A[0]
    for a in A: gcdA = gcd(gcdA, a)
    print(gcdA)

    return 0

if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
from math import gcd

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

Submission status: Accepted

Solution code:
import sys


stdin = sys.stdin
def ns(): return stdin.readline().rstrip()
def ni(): return int(stdin.readline().rstrip())
def nm(): return map(int, stdin.readline().split())
def nl(): return list(map(int, stdin.readline().split()))


def get_min_without_0(A):
    A = [a for a in A if a != 0]
    return min(A)


def attack(A):
    a = get_min_without_0(A)
    A.remove(a)
    return list(map(lambda x: x % a, A)) + [a]


def check(A):
    cnt = 0
    for a in A:
        if a == 0:
            cnt += 1
    if cnt == len(A) - 1:
        return False
    else:
        return True


def main():
    n = ni()
    A = nl()

    while check(A):
        A = attack(A)
    print(max(A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from math import gcd
N = int(input())
A = tuple(map(int, input().split()))
ans = A[0]
for a in A[1:]:
    ans = gcd(ans, a)
print(ans)

Submission status: Accepted

Solution code:
import math

N = int(input())
A = list(map(int, input().split()))
g = [math.gcd(A[0], A[1])]
for i in range(2, N):
    g.append(math.gcd(g[-1], A[i]))
print(g[-1])

Submission status: Accepted

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

# from numba import njit
from math import gcd
from functools import reduce
# input = stdin.readline

# @njit
def solve(n,a):
  ans = reduce(gcd,a)
  return ans



def main():
  N = int(input())
  # N,M = map(int,input().split())
  a = list(map(int,input().split()))
  print(solve(N,a))
  return

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N = ii()
    A = list(mi())

    A.sort()
    if A[0] == 1:
        print(1)
        exit()
    
    ini = A[0]
    while len(A) > 1:
        x = A[0]
        B = set([x])
        for a in A:
            b = a%x
            if b > 0:
                B.add(b)

        A = list(B)
        A.sort()

    if len(A) > 0:
        print(A[0])
    else:
        print(ini)
            

            
        



if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

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

gcd = a[0]
for i in range(1, n):
    gcd = math.gcd(a[i], gcd)
    if gcd == 1:
        print(1)
        break
else:
    print(gcd)

Submission status: Accepted

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

def agcd(l):
    a=math.gcd(l[0],l[1])
    for i in range(2,len(l)):
        a=math.gcd(a,l[i])
    return a

print(agcd(A))

Submission status: Accepted

Solution code:
from math import gcd
def multi_gcd(A):
  g = A[0]
  for a in A:
    g = gcd(g,a)
  return g

def solve():
  N = int(input())
  A = list(map(int, input().split()))
  ans = multi_gcd(A)
  return ans
print(solve())

Submission status: Accepted

Solution code:
from math import gcd
n = int(input())
a = list(map(int,input().split()))
c = gcd(a[0], a[1])
for i in range(2, len(a) - 1):
    c = gcd(c, a[i])
print(c)

Submission status: Accepted

Solution code:
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import product,permutations,combinations,combinations_with_replacement
from collections import defaultdict,Counter
from bisect import bisect_left,bisect_right
from math import gcd,ceil,floor,factorial
# from fractions import gcd
from functools import reduce
from pprint import pprint
from statistics import mean,median,mode

INF = float("inf")

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col,reverse_flag):
    data.sort(key=lambda x:x[col],reverse=reverse_flag)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

def mycount(ls,x):
    # lsはソート済みであること
    l = bisect_left(ls,x)
    r = bisect_right(ls,x)
    return (r-l)

def myoutput(ls,space=True):
    if space:
        if len(ls)==0:
            print(" ")
        elif type(ls[0])==str:
            print(" ".join(ls))
        elif type(ls[0])==int:
            print(" ".join(map(str,ls)))
        else:
            print("Output Error")
    else:
        if len(ls)==0:
            print("")
        elif type(ls[0])==str:
            print("".join(ls))
        elif type(ls[0])==int:
            print("".join(map(str,ls)))
        else:
            print("Output Error")

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

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

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

def CI(n):
    return [ int(input()) for _ in range(n) ]

def LI(n):
    return [ list(map(int,input().split())) for _ in range(n) ]

def S():
    return input()

def MS():
    return input().split()

def RS():
    return list(input().split())

def CS(n):
    return [ input() for _ in range(n) ]

def LS(n):
    return [ list(input().split()) for _ in range(n) ]

# ddict = defaultdict(lambda: 0)
# ddict = defaultdict(lambda: 1)
# ddict = defaultdict(lambda: int())
# ddict = defaultdict(lambda: list())
# ddict = defaultdict(lambda: float())

n = I()
a = RI()

if 1 in a:
    print(1)
    exit()

while len(a)!=1:
    m = min(a)
    ind = a.index(m)
    for i in range(len(a)):
        if i==ind:
            pass
        else:
            a[i] = a[i] % m
    a = list(set(a))
    if 0 in a:
        a.remove(0)
    elif 1 in a:
        print(1)
        exit()
    # print(a)

print(a[0])
exit()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
As = list(mapint())
from math import gcd

g = 0
for a in As:
    g = gcd(g, a)
print(g)

Submission status: Accepted

Solution code:
import math

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

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

print(g)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

print(gcd_list(a))

Submission status: Accepted

Solution code:
import sys
import math


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



g = A.pop(0)
for c in A:
    g = math.gcd(g,c)

print(g)

Submission status: Accepted

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

while not len(A) == 1:
    div = A[0]
    A = A[1:]
    A = list(map(lambda x:x%div, A))
    A.append(div)
    A = list(set([x for x in A if x != 0]))
    A.sort()

print(A[0])

Submission status: Accepted

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

from functools import reduce
from fractions import gcd

max=0
min=10**9+1
for i in range(N):#O(10**5)
    if max < hp_list[i]:
        max = hp_list[i]
        max_index = i
    if min > hp_list[i]:
        min = hp_list[i]
        min_index = i
    tmp_list=[max,min]
    hp_list[max_index]=reduce(gcd,tmp_list)
#print(max,min)
#print(max_index,min_index)
hp_list = sorted(hp_list, reverse=False)
print(hp_list[0])

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

Submission status: Accepted

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

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

print(A[0])