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

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

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

print(gcd_list(List))

Submission status: Accepted

Solution code:
n = int(input())
a = [int(x) for x in input().split()]
while True:
    a.sort()
    b = [i % a[0] for i in a[1:]]
    b.insert(0, a[0])
    b = [i for i in b if i != 0]
    if len(b) == 1: break
    else: a = b
print(b[0])

Submission status: Accepted

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

# 体力最小のモンスターが他全員に攻撃することを繰り返す。ただし体力0にはしない
# 全員同じ体力になったら終了

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

Submission status: Accepted

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

while True:
    A.sort()
    t = sum(A)
    for i in range(1, N):
        if A[i] % A[0] == 0:
            A[i] = A[0]
        else:
            A[i] = A[i] % A[0]
    if sum(A) == t:
        break
print(A[0])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!
N=int(input())
A=list(map(int,input().split()))

a=min(A)
ans=0
l=[]

def gcd(lis,num):
    temp=[]
    for item in lis:
        if num%item!=0:
            pass
        else:
            temp.append(item)
    return temp

for i in range(1,int(a**0.5)//1+1):
    if a%i==0:
        l.append(i)
        l.append(a//i)

for item in A:
    l=gcd(l,item)

print(max(l))

Submission status: Accepted

Solution code:
def slove():
    import sys
    import fractions
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    gcd = 0
    for i in range(n):
        gcd = fractions.gcd(gcd, a[i])
    print(gcd)


if __name__ == '__main__':
    slove()

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


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


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

print(gcd_list(A))

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:
from fractions import gcd
from math import ceil,floor,sqrt
n = int(input())
a = list(map(int, input().split()))

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

Submission status: Accepted

Solution code:

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

def result(monstar, n): 
	new = s(monstar[0], monstar[1]) 
	for i in range(2, n): 
		new = s(new,monstar[i]) 
	return new

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

Submission status: Accepted

Solution code:

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

def result(monstar_h, n): 
	new = s(monstar_h[0], monstar_h[1]) 
	for i in range(2, n): 
		new = s(new,monstar_h[i]) 
	return new

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

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
count = 1
while count>0:
    count=0
    mod = min(A)
    for i in range(n):
        if A[i]==mod:
            continue
        elif A[i]%mod ==0:
            A[i]=mod
            count +=1
        else:
            A[i] = A[i]%mod
            count +=1
print(A[0])

Submission status: Accepted

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

def gcd_list(L):
    b=min(L)
    for i in L:
        while True:
            if i%b==0:
                break
            c=b
            b=i%b
            i=c
    return(b)

print(gcd_list(A))

Submission status: Accepted

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from datetime import *
from heapq import *
from itertools import *
# from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

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

def main():
    """ main """
    N = int(input())
    AS = list(map(int, input().split()))
    ans = AS[0]
    for i in range(1,N):
        ans = gcd(ans,AS[i])
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def calculate(a, b):
    if a < b :
        a, b = b, a
    
    while b > 0:
        a, b = b, a%b

    return a

N = int(input())
A_list = list(map(int, input().split()))
gcd_num = A_list[0]
for i in range(1, N):
    gcd_num = calculate(gcd_num, A_list[i])
print(gcd_num)

Submission status: Accepted

Solution code:
def calculate(a, b):
    if a < b :
        a, b = b, a
    
    while b > 0:
        a, b = b, a%b

    return a

N = int(input())
A_list = list(map(int, input().split()))
gcd_num = A_list[0]
for i in range(1, N):
    gcd_num = calculate(gcd_num, A_list[i])
print(gcd_num)

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 collections import deque

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

while len(A)>1:
    a=A.popleft()
    for _ in range(len(A)):
        aa=A.popleft()
        if aa%a>0:
            A.append(aa%a)
    A.append(a)

print(A[0])

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
ans=10**10
for i,j in zip(a,a[1:]):
    ans=min(ans,gcd(i,j))
print(ans)

Submission status: Accepted

Solution code:
import fractions 

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions

n = int(input())
x = list(map(int,input().split()))
res = fractions.gcd(x[0],x[1])

for i in range(2,n):
    res = fractions.gcd(res,x[i])

print(res)

Submission status: Accepted

Solution code:
import sys 
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : map(int, stdin.readline().split())

n = ni()
a = list(na())

def gcd(n, m):
  while m:
    n, m = m, n%m
  return n

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, fractions
sys.setrecursionlimit(5 * 10**5)
input = sys.stdin.readline

N = int(input())

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

ans = A[0]

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

print(ans)

Submission status: Accepted

Solution code:
import fractions
n = int(input())
A = list(map(int, input().split()))
min_A = min(A)
B = []
for i in range(n):
  B.append(A[i]%min_A)
if all(B[i] == 0 for i in range(n)):
  print(min_A)
else:
  m = A[0]
  for i in range(1,n):
    m = fractions.gcd(m, A[i])
  print(m)

Submission status: Accepted

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

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

Submission status: Accepted

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

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[i]%A[0]
    A=[i for i in A if i!=0]

    A.sort()

print(A[0])

Submission status: Accepted

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

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

mini = min(A)
div = 10**9
for a in A:
    div = min(div,gcd(mini,a))

print(div)

Submission status: Accepted

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

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

v=a[0]
for i in range(1,n):
  v=lcd(v,a[i])

print(v)

Submission status: Accepted

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


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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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

n = int(input().split()[0])
n = int(n)

hp_list = list(map(int, input().split()))
hp_list = [int(hp) for hp in hp_list]

hp = hp_list[0]

for h in hp_list[1:]:
    hp = fractions.gcd(hp, h)

print(hp)

Submission status: Accepted

Solution code:
import fractions
n=int(input())
lists=list(map(int,input().split()))
gcds=lists[0]
for x in range(n-1):
    if n==0:
        gcds=fractions.gcd(lists[0],lists[1])
    else:
        add=fractions.gcd(lists[x],lists[x+1])
        gcds=fractions.gcd(gcds,add)
print(gcds)

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

Solution code:
import heapq

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

heapq.heapify(A)
flag = True

while flag:
    minA = heapq.heappop(A) # 最小値を取り出す
    if len(A) == 0: # 要素がなかったら終わり
        break
    if minA == 0: # 0だったら除外したまま続ける
        continue
    A = list(map(lambda x: x % minA, A))
    heapq.heappush(A, minA)

print(minA)

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

ans = A.pop()
while A:
  ans = gcd(ans, A.pop())
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:
n=int(input())
a=[int(i) for i in input().split()]

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

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

Submission status: Accepted

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

def Ans(ans):
    lst = []
    small = min(ans)
    for i in ans:
        if i%small != 0:
            lst.append(i%small)
    lst.append(small)
    if len(lst) == 1:
        print(lst[0])
    else:
        ans = lst
        Ans(ans)
Ans(A)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

Submission status: Accepted

Solution code:
from heapq import heapify, heappop, heappush

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

while len(a) > 1:
    a1, a2 = heappop(a), heappop(a)
    m = a2 % a1
    heappush(a, a1)
    if m:
        heappush(a, m)
print(heappop(a))

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

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

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:
import numpy as np
N=int(input())
A=np.array(list(map(int, input().split())))
A=np.sort(A)
while A.shape[0]>1:
  A[1:]%=A[0]
  A=A[A>0]
  A=np.sort(A)
print(A[0])

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])
    if ans==1:
        break
print(ans)

Submission status: Accepted

Solution code:
#C - Monsters Battle Royale(ABC118)
N=int(input())
A=list(map(int, input().split()))
B=min(A)
i=0
n=1
while i<N:
    a=A[i]%B
    i+=1
    if 0<a<B:
        B=a
        i=0
    elif 0<a:
        i-=1
        A[i]=a
    elif B==1:
        break
print(B)

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())
array = list(map(int, input().split()))
array.sort()
min = array[0]
while True:
	tmp2 = min
	for item in array:
		tmp = item % min
		if tmp != 0 and tmp < min:
			min = tmp
	if min == tmp2:
		break
print(min)

Submission status: Accepted

Solution code:
import fractions

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


if __name__ == "__main__":
    test()

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

cm = A[0]

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

print(cm)

Submission status: Accepted

Solution code:

import sys
input = sys.stdin.readline
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
##############################

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:
def gcd(x,y):
    if x<y:
        x,y = y,x
    while y>0:
        x,y = y,x%y
    return x
N = int(input())
A = list(map(int,input().split()))
x = A[0]
for i in range(1,N):
    y = A[i]
    x = gcd(x,y)
print(x)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=sys.stdin.readline
def resolve():
    n=int(input())
    A=map(int,input().split())
    from fractions import gcd
    from functools import reduce
    print(reduce(gcd,A))
resolve()

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:
# ABC118 C - Monsters Battle Royale
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
ans = 10**10

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

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int, input().split()))
f=A[0]
g=A[1]
while f%g!=0:
  f,g=[g, f%g]
for i in range(2,N):
  f=A[i]
  while f%g!=0:
    f,g=[g, f%g]
print(g)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

print(a)

Submission status: Accepted

Solution code:
import numpy as np

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

B = list(set(A))
B.sort()
C = np.asarray(B)

while(len(C)>1):
    t = C[0]
    C = np.append(C[1:]%t,t)
    C = list(set(C))
    C.sort()
    if C[0]==0:
        C = np.asarray(C[1:])
    else:
        C = np.asarray(C)

print(C[0])

Submission status: Accepted

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

N=int(input())
A=list(map(int,input().split()))
g=A[0]

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

print(g)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    mod = A[0]
    flag = True
    while flag:
        for i in range(0, N):
            if A[i]%mod == 0:
                if i == N -1:
                    flag = False
                continue
            else:
                mod = A[i]%mod
                A[i] = mod
                break 
    print(mod)

Submission status: Accepted

Solution code:
import fractions

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions

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

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

print(res)

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

import heapq

N = int(input())
a = list(map(int, input().split()))
heapq.heapify(a)
tmp = 0
tmp2 = 0

for i in range(pow(10,5)):
    tmp = heapq.heappop(a)
    if tmp == 1:
        print(tmp)
        exit()
    a = list(map(lambda x: x % tmp, a))
    if sum(a) == 0:
        print(tmp)
        exit()
    else:
        a = [j for j in a if j != 0]
        heapq.heappush(a, tmp)

Submission status: Accepted

Solution code:
from functools import reduce
try:
	from math import gcd
except:
	from fractions import gcd

def GCD(n):
	return reduce(gcd, n)

input()
print(GCD(list(map(int, input().split()))))

Submission status: Accepted

Solution code:
from fractions import gcd
n=int(input())
a=[int(i) for i in 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()) # the num of monster
 
ls = list(map(int, input().split()))
n = len(ls)

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

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

Submission status: Accepted

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

Submission status: Accepted

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

while len(a) > 1:
    for i in range(1, len(a)):
        a[i] %= a[0]
    a = sorted(set(a))

    if a[0] == 0:
        a = a[1::]

print(*a)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def MAP(): return list(map(int,input().split()))
import fractions

n = int(input())
A = MAP()

tmp=A[0]
for i in range(1,n):
    tmp = fractions.gcd(tmp,A[i])
print(tmp)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
def gcd_list(numbers):
    return reduce(gcd, numbers)

def resolve():
    n = int(input())
    aaa = list(map(int ,input().split()))
    print(gcd_list(aaa))
resolve()

Submission status: Accepted

Solution code:
import sys
readline = sys.stdin.readline
n = int(readline())
a = list(map(int, readline().split()))
a.sort()

zero_count = 0
curr = 0
i = 0

while n - zero_count > 1:
    # print(i,curr,zero_count,a)
    if i != curr and a[i] != 0:
        if a[i] % a[curr] == 0:
            a[i] = 0
        elif a[curr] <= a[i]:
            a[i] = a[i] % a[curr]
            if a[i] < a[curr]:
                curr = i
        if a[i] == 0:
            zero_count += 1
    if i == n - 1:
      i = 0
    else:
      i += 1

print(max(a))

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

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
def calcgcd(a, b):
  if a > b:
    a, b = b, a
  while a > 0:
    a, b = b%a, a
  return b
r = 0
for A in As:
  r = calcgcd(r, A)
print(r)

Submission status: Accepted

Solution code:
from fractions import gcd


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

Submission status: Accepted

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


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


res = nums[0]
for x in nums[1:]:
    res = gcd(res, x)

print(res)

Submission status: Accepted

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

Submission status: Accepted

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

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


if N == 1:
    print(x[0])
else:
    num = gcd(x[0], x[1])
    if N == 2:
        print(num)
    else:
        for i in range(2, N):
            num = gcd(num, x[i])
        print(num)

Submission status: Accepted

Solution code:
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
import math
import bisect
import random
from itertools import permutations, accumulate
import sys



def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LIM(): return list(map(lambda x:int(x) - 1, sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline()
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def LIRM(n): return [LIM() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
mod = 1000000007


n = I()
nums = LI()


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


ret = nums[0]
while len(nums) > 1:
    ret = gcd(ret, nums.pop(-1))



print(ret)

Submission status: Accepted

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

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

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

print(res_1)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

N = int(input())
A = list(map(int,input().split()))
print(reduce(lambda a, b: fractions.gcd(a,b), A))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
import copy

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

while len(alist) > 1:
  min_a = min(alist)
  alist.remove(min_a)
  new_alist = [min_a]
  for a in alist:
    if int(a%min_a) != 0:
      new_alist.append(int(a%min_a))
  alist = copy.deepcopy(new_alist)

print(new_alist[0])

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd
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(x,y):
  if y == 0:
    return x
  else:
    return gcd(y,x%y)

accum_gcd = A[0]
for i in range(n):
    accum_gcd = gcd(accum_gcd,A[i])
print(accum_gcd)

Submission status: Accepted

Solution code:
import fractions

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

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

Submission status: Accepted

Solution code:
def gcd(x,y):
    while y != 0:
        x, y = y, x%y
    return x
n = int(input())
a = [int(i) for i in 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 fractions import gcd
from functools import reduce

def Gcd(*numbers):
  return reduce(gcd, numbers)
N = int(input())
ls = [int(i) for i in input().split()]

print(Gcd(*ls))

Submission status: Accepted

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

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

def gcd(x, y):
	while y:
		x, y = y, x % y
	return x
 
ans = gcd(A[0],A[1])
for i in range(2,n):
  ans = gcd(ans,A[i])
print(ans)

Submission status: Accepted

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

ans = A[0]
for i in range(1,N):
    bns = A[i]
    l = max(ans, bns)
    s = min(ans, bns)
    while l % s != 0:
        l, s = s, l % s
    ans = s

print(ans)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

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

Submission status: Accepted

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

A = sorted(A)

ans = min(A)
while(1):
    prev = ans
    B = list(map(lambda x: x % ans , A[1:]))
    A = [ans] + [i for i in B if i != 0]
    ans = min(A)
    if ans == prev:
        print(ans)
        exit(0)
    A = sorted(A)

Submission status: Accepted

Solution code:
from fractions import gcd

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

memo = []
memo.append(L[0])
for i in range(N):
    memo.append(gcd(memo[-1], L[i]))

print(memo[-1])

Submission status: Accepted

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

import fractions #fractions.gcd() python~3.4

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

Submission status: Accepted

Solution code:
import fractions

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

ans = A[0]
for a in A:
    ans = fractions.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

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

Submission status: Accepted

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

Submission status: Accepted

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


def gcd(a,b):
    if a == b:
        return a
    elif a > b:
        return euclid(a,b)
    elif a < b:
        return euclid(b,a)

    print "error"
    return 0

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

def monsters_battle_royale(n,a):
    _a = sorted(a)
    tmp = _a[0]
    for i in range(n):
        tmp = gcd(tmp,_a[i])

    return tmp
if __name__ == '__main__':
    n = int(raw_input())
    a = map(int,raw_input().split())


    print monsters_battle_royale(n,a)