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:
# coding: utf-8
import fractions

n = int(input())

monsters = list(map(int, input().rstrip().split(" ")))

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

from fractions import gcd
ans = A[0]
for a in A:
  ans = gcd(a, ans)
print(ans)

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

Submission status: Accepted

Solution code:
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


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

    ans = a[0]

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

    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
ans = A[N-1]

update = True
while update == True:
    update = False
    n = len(A)
    for i in range(1,n):
        A[i] %= A[0]
    C = []
    for a in A:
        if 1 <= a:
            C.append(a)
    C.sort()
    A = C
    if A[0] < ans:
        ans = A[0]
        update = True

print(ans)

Submission status: Accepted

Solution code:
# coding: utf-8

n = int(input().rstrip())

monster = [int(i) for i in input().rstrip().split(" ")]

def get_dev(num1:int, num2:int):
    if num1 % num2 == 0:
        return num2
    return get_dev(num2, num1 % num2)

cur = monster[0]
for i in range(1,n):
    cur = get_dev(cur, monster[i])

print(cur)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

def gcd(a):
    return reduce(fractions.gcd, a)

answer = gcd(A)
print(answer)

Submission status: Accepted

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

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(math.gcd, numbers)
    return reduce(fractions.gcd, numbers)

print(gcd_list(A))

Submission status: Accepted

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

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

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()))
A = sorted(A,reverse = False) 

B = [A[0]]
for i in range(N):
    if A[i]%A[0] != 0:
        B.append(A[i]%A[0])
B = set(B)
#B = sorted(B,reverse = False) 

#import math
import fractions
from functools import reduce

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

print(gcd_list(B))

Submission status: Accepted

Solution code:
from functools import reduce


def gcd(a, b):
    if b > a:
        a, b = b, a
    dp = [a, b]
    for i, v in enumerate(dp, start=2):
        dp.append(dp[i - 2] % dp[i - 1])
        if dp[i] == 0:
            break
    return dp[i - 1]


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

Submission status: Accepted

Solution code:
def gcd(x,y):
  return y if x%y==0 else gcd(y,x%y)
N=input();A=list(map(int,input().split()));
g=A[0];
for a in A:
  g=gcd(g,a)
print(g)

Submission status: Accepted

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

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

def gcd2(number):
    return reduce(gcd, number)

print(gcd2(a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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()))
b = min(A)
s = A.index(b)
while True:
	c = 0
	for i in range(len(A)):
		if i == s: continue
		else: 
			A[i] %= b
			if A[i] == 0:
				c += 1
			elif A[i] < b:
				b = A[i]
				s = A.index(b)
	if c == n-1:
		print(max(A))
		break

Submission status: Accepted

Solution code:
import fractions

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

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

Submission status: Accepted

Solution code:
import fractions

n=int(input())

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

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

Submission status: Accepted

Solution code:
from fractions import gcd
_, *A = map(int, open(0).read().split())
F = A[0]
for a in A:
  F = gcd(F, a)
print(F)

Submission status: Accepted

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

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

for _ in range(10**5+1):
    new_lst = []
    min_b = b_lst[0]
    new_lst.append(min_b)

    for i in range(1, len(b_lst)):
        x = b_lst[i]
        tmp = x//min_b
        b = x- min_b*tmp
        if b!=0:
            new_lst.append(b)

    if len(new_lst)==1:
        print(new_lst[0])
        break
    else:
        b_lst = new_lst.copy()
        b_lst.sort()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from functools import reduce


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


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

print(reduce(gcd, A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
N = int(input())
mons = tuple(map(int, input().split()))

ans = mons[0]
for m in mons:
    ans = fractions.gcd(ans, m)

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#118_C
N=int(input())
A=list(map(int,input().split()))
while A.count(0)<N-1:
    A.sort()
    i=0
    while A[i]==0: i+=1
    min_A=A[i]
    A=[min_A if j==i else A[j]%min_A for j in range(N)]
print(max(A))

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
miner = 0
while sum(a) != miner:
    flag = 0
    miner = min(a)
    for i in range(len(a)):
        if a[i] == miner and flag == 0:
            flag += 1
        else:
            a[i] = a[i]%miner
    a = [i for i in a if i != 0]
print(miner)

Submission status: Accepted

Solution code:
def gcd(n,m):
    n,m = max(n,m),min(n,m)
    r = n % m
    while r > 0:
        n,m = m,r
        r = n % m
    return m
N = int(input())
A = list(map(int,input().split()))
ans = A[0]
for i in range(1,N):
    ans = gcd(ans,A[i])
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

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


print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

def extd_gcd(numbers):
    from functools import reduce
    return reduce(gcd,numbers)

if __name__ == '__main__':
    N=int(input())
    Monsters=list(map(int,input().split()))
    print(extd_gcd(Monsters))

Submission status: Accepted

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

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

Submission status: Accepted

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

res = A[0]

def f(n, m):
    while m != 0:
        n, m = m, n%m
    return n

for a in A:
    res = f(res, a)

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

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

Submission status: Accepted

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

m = min(A)

for i in range(N):
    if A[i] % m != 0:
        print(fractions.gcd(m, A[i]))
        exit()
print(m)

Submission status: Accepted

Solution code:
from fractions import gcd

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

def monsters_battle_royal(n, a):
    gcd = a[0]
    for i in range(1, n):
        gcd = fractions.gcd(gcd, a[i])
    return gcd

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

ans = monsters_battle_royal(n, a)
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

x = 0
for i in range(n):
    x = gcd(x,l[i])

print(x)

Submission status: Accepted

Solution code:
from fractions import gcd
n=int(input())
*a,=map(int,input().split())
a.sort()
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()))

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce 
N,*A=map(int,open(0).read().split())
print(reduce(fractions.gcd,A))

Submission status: Accepted

Solution code:
import fractions

n = int(input())

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

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

Submission status: Accepted

Solution code:
def main():
  n=int(input())
  num=[int(i) for i in input().split()] 
  from fractions import gcd
  
  def gcd2(num,n):
    if n==1:
      return num[0]
    else:
      return gcd2([gcd(num[i],num[-i-1]) for i in range((n+1)//2)],(n+1)//2)
    
  print(gcd2(num,n))

if __name__=='__main__':
  main()

Submission status: Accepted

Solution code:
n = int(input())

S = input().split(" ")

arr = [int(s) for s in S]

def calculate(m,n):
    if m == n:
        return m
    elif m > n:
        s = m % n
        if s == 0:
            return n
        else:
            return calculate(n,s)
    else:
        s = n % m
        if s == 0:
            return m
        else:
            return calculate(m,s)

v = arr[0]

for index in range(1,n):
    v = calculate(v,arr[index])

print(v)

Submission status: Accepted

Solution code:
from collections import Counter

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

if len(Counter(A)) == 1:
    print(A[0])
else:
    while sum(a > 0 for a in A) > 1:
        m = min((abs(A[i+1]-A[i]), i) for i in range(N-1) if (A[i+1] != A[i]))
        if A[m[1]+1] > A[m[1]]:
            j = m[1] + 1
            A[j] -= A[j-1]
        else:
            j = m[1]
            A[j] -= A[j+1]
        for i in range(N):
            if i != j:
                A[i] %= A[j]
    print(A[j])

Submission status: Accepted

Solution code:
from functools import reduce
import fractions


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


N =int(input())
monster = [int(i) for i in input().split()]
print(gcd_list(monster))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import fractions

N = int(input())

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

A = sorted(A)

a = A.pop(0)
for i in A:
    a = fractions.gcd(a, i)
    
print(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 fractions
N = int(input())
*A, = map(int, input().split())
chk = [0] * (N+1)
for i in range(N):
    chk[i+1] = fractions.gcd(chk[i], A[i])
print(chk[N])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
n = int(input())
a = [int(x) for x in input().split()]

ans = a[0]

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

print(ans)

Submission status: Accepted

Solution code:
import sys
import fractions
import functools
f = sys.stdin
n = int(f.readline())
a = list(map(int, f.readline().split()))
gcd = functools.reduce(fractions.gcd, a)
print(gcd)

Submission status: Accepted

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

def gcd(a, b):
    mod = 1

    while (mod > 0):
        mod = a % b
        a = b
        b = mod
    
    return (a)

gc = HP[0]

for i in range(1, N):
    gc = gcd(gc, HP[i])
    # print(gc)

print(gc)

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:
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
    
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:
from fractions import gcd
n = int(input())
A = list(map(int,input().split()))
g = A[0]
for a in A:
  g = gcd(g,a)
print(g)

Submission status: Accepted

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

Submission status: Accepted

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


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


# 初期値の設定
ans = A[0]
for i in range(1, n):
    ans = gcd(ans, A[i])
print(ans)

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
def input(): return sys.stdin.readline().rstrip()

def main():
    _ = int(input())
    A = tuple(map(int, input().split()))

    ans = A[0]
    for a in A[1:]:
        ans = gcd(ans, a)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
from functools import lru_cache
def input(): return sys.stdin.readline().rstrip()

@lru_cache(maxsize=None)
def gcd(m, n):
    if n == 0:
        return m
    else:
        return gcd(n, m % n)

def main():
    _ = int(input())
    A = tuple(map(int, input().split()))

    ans = A[0]
    for a in A[1:]:
        ans = gcd(ans, a)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().rstrip()

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

def main():
    _ = int(input())
    A = tuple(map(int, input().split()))

    ans = A[0]
    for a in A[1:]:
        ans = gcd(ans, a)
    print(ans)
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

print(functools.reduce(fractions.gcd, Q))

Submission status: Accepted

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

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

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

print(gcd_2(a))

Submission status: Accepted

Solution code:
def solve(n, A):

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

    l = A.pop()
    for a in A:
        l = gcd(l, a)
    return l

_n = int(input())
_A = list(map(int, input().split()))
print(solve(_n, _A))

Submission status: Accepted

Solution code:
from fractions import gcd
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:
def gcd(a, b):
    if(a==0): return b
    if a<b: a,b=b,a
    while b: a,b=b,a%b
    return a

n, *a = map(int, open(0).read().split())
g = 0
for i in a: g = gcd(g, i)
print(g)

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())
a.sort()
ans = 1e10
for i in range(1, n):
    x, y = a[0], a[i]
    while y%x:
        y -= y//x*x
        x, y = y, x
    ans = min(ans, x)
print(ans)

Submission status: Accepted

Solution code:
def gcdf(a):
    a.sort()
    a0=a[0]
    a=[int(x%a0) for x in a if x%a0 != 0]
    if len(a)==0:
        return a0
    else:
        a.append(a0)
        a0=min(a)
        return gcdf(a) 

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

gcdx=gcdf(a)
print(gcdx)

Submission status: Accepted

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

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

N = int(input())

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

x = X[0]

for i in range(1, N):
    x = gcd(x, X[i])
print(x)

Submission status: Accepted

Solution code:
def GCD(x, y):
    if y != 0:
        return GCD(y, x % y)
    else:
        return x

N = input()
monsters = [int(s) for s in input().split()]

x = monsters[0]
for y in monsters[1:]:
    gcd = GCD(x, y)
    x = gcd

print(gcd)

Submission status: Accepted

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


def get_input():
    n = int(input())
    a = [int(i) for i in input().split()]
    return n, a

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

if __name__ == "__main__":
    n, a = get_input()
    
    GCD = a[0]
    for idx in range(1, n):
        GCD = gcd(GCD, a[idx])
        if GCD <= 1: break
        
    print(GCD)

Submission status: Accepted

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

Submission status: Accepted

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

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

gcd_a = A[0]

for i in A:
    gcd_a = gcd(gcd_a,i)

print(gcd_a)

Submission status: Accepted

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

while len(a) > 1:
    res=[]
    a.sort()
    a_mn = a[0]
    res.append(a_mn)
    for i in range(1,len(a)):
        hp = a[i] % a_mn
        if hp!=0:
            res.append(hp)
    a=res
print(a[0])

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import fractions

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

t = []
t.append(li[0])

for index, i in enumerate(li):
  if index == 0:
    continue

  k = fractions.gcd(t[index-1], li[index])
  t.append(k)

print(t[-1])

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

N = int(input())
A ,*B= map(int,input().split())
for i in B:
    A = euclid(A,i)
print(A)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce


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


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

Submission status: Accepted

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

minA=min(A)
while len(A)!=1:
    B=[]
    for i in range(len(A)):
        if A[i]%minA!=0:
            B.append(A[i]%minA)
    B.append(minA)
    A=B
    minA=min(A)
print(minA)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
while len(a)>1:
    l=len(a)
    a.sort()
    b=[a[0] if i==0 else a[i]%a[0] for i in range(l)]
    a=[b[i] for i in range(l) if b[i]!=0]
print(a[0])

Submission status: Accepted

Solution code:
import fractions
import functools

_gcd = fractions.gcd
def gcd(n):
    return functools.reduce(_gcd, n)

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

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

print(a[0])

Submission status: Accepted

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


N = int(input())
A = [int(i) for i in input().split()]
ans = A[N - 1]
for i in range(N - 1):
    ans = gcd(ans, A[i])
print(ans)

Submission status: Accepted

Solution code:
import fractions

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

a = sorted(a)
aa = [i % a[0] for i in a][1:]
aaa = []

for i in aa:
    if i != 0:
        aaa.append(fractions.gcd(i, a[0]))

if len(aaa) == 0:
    print(a[0])
else:
    print(min(aaa))

Submission status: Accepted

Solution code:
import sys
from fractions import gcd as gcd_base
from functools import reduce

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    _ = INT()
    A = LIST()

    gcd = lambda *numbers: reduce(gcd_base, numbers)
    print(gcd(*A))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions
import functools


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


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

Submission status: Accepted

Solution code:
def gcd(x, y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    return gcd(x % y, y)


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

Submission status: Accepted

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

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

def lcm(x,y):
	return (x * y) // gcd(x,y)

c = a[0]
for i in a:
	c = gcd(c,i)
print (c)

Submission status: Accepted

Solution code:
import sys
def gcd(c,d):
    a = max(c,d)
    b = min(c,d)
    if b == 0:
        return a
    return gcd(b,a%b)
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = a[0]
for i in a[1:]:
    ans = gcd(ans,i)
print(ans)

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.buffer.readline

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

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import _collections
import string

class cin():
    def int():
        return int(sys.stdin.readline().rstrip())
    def string():
        return sys.stdin.readline().rstrip()
    def mapInt():
        return [int(x) for x in cin.string().split()]
    def stringList(n):
        return [input() for i in range(n)]
    def intListList(n):
        return [cin.mapInt() for i in range(n)]
    def intColsList(n):
        return [int(input()) for i in range(n)]

class Util():
    def roundUp(a,b):
        return -(-a // b)
    def toUpperMultiple(a,x):
        return Util.round_up(a,x) * x
    def toLowerMultiple(a,x):
        return (a // x) * x
class Math():
    def gcd(a,b):
        if b == 0:
            return a
        return Math.gcd(b,a % b)

def main():
    N = cin.int()
    A = cin.mapInt()
    ans = A[0]
    for i in range(1,N):
        ans = Math.gcd(ans,A[i])
    print(ans)
    return

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
import fractions
from functools import reduce
def pin(type=int):
    return map(type,input().split())


N, =pin()
m = list(pin())




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

print(gcd_list(m))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

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

while l.count(0) != n-1:
    m = max(l)
    for i in l:
       if (i < m) and i != 0:
           m = i
         
    index = l.index(m)
    
    for i in range(n):
        if i == index:
            pass
        
        else:
            l[i] = l[i] % m

print(max(l))

Submission status: Accepted

Solution code:
from fractions import gcd

N = int(input())
A = sorted([int(n) for n in input().split()], reverse=True)

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

Submission status: Accepted

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