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:
n = int(input())
a = list(map(int, input().split()))
def gcm(a, b) :
  while(b) :
    a, b = b, a%b
  return a

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
while len(A) > 1:
    A.sort()
    devided_num = int(A[0])
    devi_lis = [devided_num]
    As = A
    As.pop(0)
    A =[_%devided_num for _ in As if _%devided_num > 0]
    A += devi_lis
print(A[0])

Submission status: Accepted

Solution code:
from fractions import gcd

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

num = A[0]
for a in A:
    num = gcd(num,a)

print(num)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
while len(A) > 1:
    a_ = A[0]
    for x in range(1,len(A)):
        A[x] %= a_
    A = [ans for ans in A if ans > 0]
    A.sort()
print(A[0])

Submission status: Accepted

Solution code:
###C - Monsters Battle Royale
N = int(input())
A = list(map(int, input().split()))

while(len(set(A)) != 1):
    minA  = min(A)
    for i in range(N):
        if A[i] > minA:
            time = A[i] // minA
            if time == 1:
                A[i] =A[i] -  time * minA
            else:
                A[i] =A[i] -  (time - 1) * minA
                
print(min(A))

Submission status: Accepted

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

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

x = gcd(a[0],a[1])

if n != 2:
    for i in range(2,n):
        x = gcd(x,a[i])
        
print(x)

Submission status: Accepted

Solution code:
""" AtCoder """

from fractions import gcd

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

ans = A[0]

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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def gcd(x, y):
  while y != 0:
      x, y = y, x%y
  return x
  
N = int(input())

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

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

print(ans)

Submission status: Accepted

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

def euclid(a, b):
    c,d = sorted([a, b])
    r = 1
    while (r > 0):
        r = d % c
        c,d = r,c
    return d

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

Submission status: Accepted

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

m = max(A)
while m != min(A):
    m = min(A)
    A = [(a%m)if a!=m else m for a in A if a==m or (a%m)>0]
print(m)

Submission status: Accepted

Solution code:
def gcd(a,b):
  if min(a,b)==a:
    if b%a==0:return a
    else:b%=a
  while 1:
    if a%b==0:break
    a%=b
    if b%a==0:break
    b%=a
  return min(a,b)
n=int(input())
a=list(map(int,input().split()))
for oAo in range(len(a)-1):
  a[0]=gcd(a[0],a[1])
  del a[1]
print(a[0])

Submission status: Accepted

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

while True:
    if len(A) == 1:
        print(A[0])
        break
    A.sort()
    A = [A[0]] + [x % A[0] for x in A[1:]]
    A = [x for x in A if x != 0]

Submission status: Accepted

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

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

while True:
    min_value = min(A)
    flag_update = False
    pop_indices = []
    for i, v in enumerate(A):
        if v != min_value:
            flag_update = True
            A[i] = v % min_value
            if A[i] == 0:
                pop_indices.append(i)
    
    for i in pop_indices[::-1]:
        A.pop(i)
            
    if flag_update == False:
        break

print(min_value)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
a = A[0]

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

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

Submission status: Accepted

Solution code:
from fractions import*;input();a,*b=map(int,input().split())
for i in b:a=gcd(a,i)
print(a)

Submission status: Accepted

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

def gcd(x, y):
  while y != 0:
    x, y = y, x%y
  return x
  
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)
zero_monster_indexes = []

while True:
    for monster_i in range(1, len(a)):
        if a[monster_i] == 0:
            zero_monster_indexes.append(monster_i)
        else:
            a[monster_i] %= a[0]

            if a[monster_i] == 0:
                zero_monster_indexes.append(monster_i)

    for zero_monster_index in reversed(zero_monster_indexes):
        a.pop(zero_monster_index)
    zero_monster_indexes.clear()

    a = sorted(a)
    if len(a) == 1:
        break

print(a[0])

Submission status: Accepted

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

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

def lcm(m, n):
  return (m*n)//gcd(m, n)

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

Submission status: Accepted

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

if N == 1:
	print(abs(x[0]))
else:
	a = x[0]
	for i in range(N - 1):
		b = x[i + 1]
		a, b = sorted([a, b])
		while True:
			if b % a == 0:
				break
			else:
				a, b = b % a, a
	print(abs(a))

Submission status: Accepted

Solution code:
N = int(input())
a = [int(i) for i in input().split()]
while len(a)>1:
    while 0 in a:
        a.remove(0)
    a.sort()
    for i in range(1,len(a)):
        a[i] = a[i] % a[0]
print(a[0])

Submission status: Accepted

Solution code:
def equ(a, b):
    while b > 0:
        a, b = b, a % b
    return a


N = int(input())

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

Submission status: Accepted

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

def gcm_list(a):
    ans = a[0]
    l = len(a)
    for i in range(1, l):
        ans = gcm(ans, a[i])
    return ans

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

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)

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

Submission status: Accepted

Solution code:
def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x % y == 0:
      return y
    else:
      while x % y != 0:
        z = x % y
        x = y
        y = z
      return y


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

Submission status: Accepted

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

mi = min(A)
while 1:
    for i in range(N):
        if A[i] != mi:
            A[i] %= mi
            if A[i] <= 0:
                A[i] = mi
    if min(A) == mi:
        break
    else:
        mi = min(A)

print(mi)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N  = int(input())

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

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


while i < N-1:
  com =  euq(data[i],data[i + 1])
  data[i+1] = com
  i += 1
  
  

print(com)

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

Submission status: Accepted

Solution code:
from functools import reduce
def gcd(a:int,b:int)->int:
  if a<b:a,b=b,a
  return a if b==0 else  gcd(b,a%b)
N=int(input())
print(reduce(gcd,list(map(int,input().split(" ")))))

Submission status: Accepted

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

def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
  
gcd = functools.reduce(gcd, m)
print(gcd)

Submission status: Accepted

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

while len(a) > 1:
    idx = 0
    m = a[0]
    for i in range(len(a)):
        aa = a[i]
        if aa > 0 and aa < m:
            idx = i
            m = a[idx]
    for i in range(len(a)):
        if i != idx:
            a[i] = a[i] % m
    a = [aa for aa in a if aa > 0]
print(a[0])

Submission status: Accepted

Solution code:
def gcd(a, b):
    """ 最大公約数。aはbより大きいこと """
    if b == 0:
        return a
    else:
        return gcd(b, a%b)


def solve():
    N = int(input())
    A = [int(x) for x in input().split(" ")]

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

    print(ans)


if __name__ == "__main__":
    solve()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
while len(A) > 1:
    A.sort()
    min_A = A[0]
    A = [min_A] + [Ai % min_A for Ai in A if Ai % min_A != 0]

print(A[0])

Submission status: Accepted

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

# print(N,a,n)

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

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

Submission status: Accepted

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

def gcd(l):
    ans=l[0]
    for i in l:
        ans=gcd_(ans,i)
    return ans  
  
N=int(input())
A=list(map(int,input().split()))
print(gcd(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce

def gcd(x , y):
    while y != 0:
        x , y = y , x % y
    return x
    
N = int(input())
An = [ x for x  in  map(int, input().split()) ]
print(reduce(gcd, An))

Submission status: Accepted

Solution code:
N = int(input())
L = list(map(int,input().split()))
while True:
  if len(L) == 1:
    print(L[0])
    quit()
  L = sorted(L)
  m = L[0]
  for i in range(1,len(L)):
    L[i] %= m
  L = list(filter(lambda x:x!=0,L))

Submission status: Accepted

Solution code:
def __gcd(a: int, b: int) -> int:
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    return __gcd(b, a % b)


def monsters_battle_royale(N: int, A: list) -> int:
    a = A[0]
    for b in A[1:]:
        a = __gcd(a, b)

    return a


if __name__ == "__main__":
    N = int(input())
    A = [int(s) for s in input().split()]
    ans = monsters_battle_royale(N, A)
    print(ans)

Submission status: Accepted

Solution code:
def take_mod(L):
	for i in range(1,len(L)):
		if L[i]%L[0] == 0:
			L[i] = L[0]
		else:
			L[i] = L[i]%L[0]
	L.sort()
	return L

N = int(input())
L = list(map(int, input().split()))
L.sort()

while True:
	L = take_mod(L)
	if len(set(L)) == 1:
		print(L[0])
		exit()

Submission status: Accepted

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

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

ret = xs[0]
for x in xs[1:]:
  ret = gcd(ret, x)
print(ret)

Submission status: Accepted

Solution code:
import itertools
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
n = map(int, input().split())
a = list(map(int, input().split()))
result = a[0]
for x in a[1:]:
    result = gcd(result, x)
print(result)

Submission status: Accepted

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


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

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

Submission status: Accepted

Solution code:
from queue import PriorityQueue
N = int(input())
A = map(int, input().split())
q = PriorityQueue()
for a in A:
    q.put(-a)
x = -q.get()
while not q.empty():
    y = -q.get()
    if y == 0:
        break
    q.put(-(x % y))
    x = y
print(x)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce


def gcd(*numbers):
    return reduce(fractions.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()

A_tmp=A[0]
for i in A[1:]:
  if i%A_tmp != 0:
    A_tmp = i%A_tmp
    
while(1):
  tmp = [x%A_tmp for x in A if x%A_tmp != 0]
  if sum(tmp) != 0:
    A_tmp = min(tmp)
  else:
    break
print(A_tmp)

Submission status: Accepted

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

A.sort()

R = A[0]

while True:
    C = A.copy()
    B = [A[0]] + [a for a in [A[i+1] % A[i] for i in range(len(A)-1)] if a > 0]
    B = list(set(B))
    B.sort()
    R = min(R, B[0])
    if C == B:
        break
    elif R == 1:
        break
    else:
        A = B

print(R)

Submission status: Accepted

Solution code:
from functools import reduce

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

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

print(reduce(gcd, a))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[]
e=False
while e==False:
    b=[]
    a_m=[]
    for i in a:
        if i!=0:
            a_m.append(i)
    #print(a_m)#a=m a of positive
    temp=min(a_m)
    #5
    for i in a:
        g=i%temp
        if i==temp:
            b.append(i)#myself
        elif g!=0:
            b.append(i%temp)
        
    #b is only positive
    #print("temp:",temp)
    #print("b",b)
    if not b:#if empty 
        ans=temp
        e=True
         
    else:
        if temp==min(b):
            ans=temp
            e=True
        else:
            a=b
     #       print(a)
                
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


'''考え方
最大公約数が正解となる
'''

# 最大公約数を求める関数
def f_gcd(a, b):
  while b > 0:
    a, b = b, a%b
  return a

# 1回目は普通に求める。これ以降はループさせる
m,n = A[0],A[1]
gcd = f_gcd(m,n)

# 2回目以降
if len(A) >= 3:
  for i in A[2:]:
    gcd = f_gcd(gcd,i)
else:
  pass


print(gcd)

Submission status: Accepted

Solution code:
n = int(input())
monsters = list(map(int, input().split()))
def gcd(a, b):
    if b == 0:  
        return a
    else:
        return gcd(b, a%b)
gcd(4,2)

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

Submission status: Accepted

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

n = int(input())
A = list(map(int, input().split()))
ans = A[0]

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

for i in range(n-1):
    ans = calc(ans, A[i+1])

print(ans)

Submission status: Accepted

Solution code:
N = int(raw_input())
health = map(int, raw_input().strip().split())

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

if len(health) == 1:
	print(health[0])
else:
	g = gcd(health[0], health[1])
	for i in range(2, len(health)):
		g = gcd(g, health[i])
print(g)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(raw_input())
health = map(int, raw_input().strip().split())

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

if len(health) == 1:
	print health[0]
else:
	g = gcd(health[0], health[1])
	for i in range(2, len(health)):
		g = gcd(g, health[i])
print g

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
l = len(A)
flag = 0
while flag == 0:
    flag = 1
    A.sort()
    for i in range(1, l):
        A[i] = A[i] % A[0]
        if A[i] == 0:
            A[i] = A[0]
    for i in A:
        if i != A[0]:
            flag = 0

print(A[0])

Submission status: Accepted

Solution code:
import numpy as np


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


monsterNum = int(input())
monsterHPArray = np.array(list(map(int, input().split())))
a = monsterHPArray[0]
for i in range(1, monsterNum):
    b = monsterHPArray[i]
    # print(a)
    # print(b)
    a = gcd(a, b)

print(a)

Submission status: Accepted

Solution code:
"""
import math
N = int(input())
A = list(map(int, input().split()))
g = math.gcd(A[0], A[1])
for a in A:
    if g == 1:
        break
    g = math.gcd(g, a)
print(g)
"""
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 = gcd(A[0], A[1])
for a in A:
    if g == 1:
        break
    g = gcd(g, a)
print(g)

Submission status: Accepted

Solution code:
def get_gcd(a, b):
  m = max(a, b)
  n = min(a, b)
  while(True):
    if n == 0:
      return m
    r = m % n
    m = n
    n = r

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

a = A_list.pop()

while(len(A_list) > 0):
  b = A_list.pop()
  a = get_gcd(a, b)
  
print(a)

Submission status: Accepted

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

def gcm(x, y):
    x, y = max(x, y), min(x, y)
    while x%y > 0:
        x, y = y, x%y
    return y

a_gcd = a[0]
for i in range(n):
    a_gcd = gcm(a_gcd, a[i])
print(a_gcd)

Submission status: Accepted

Solution code:
from fractions import gcd

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

d = monster[0]
for m in monster[1:]:
    d = gcd(d, m)

print(d)

Submission status: Accepted

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

n=int(input())
arr=list(map(int,input().split()))
while len(arr)>1:
    a=arr.pop()
    b=arr[-1]
    arr[-1]=gcd(a,b)
print(arr[0])

Submission status: Accepted

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

init = a[0]
for i in a[1:]:
    if init >= i:
        x = init
        y = i
    else:
        x = i
        y = init
    z = x % y
    while z:
        x = y
        y = z
        z = x % y
    init = y

print(y)

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
while True:
	min_a = A.min()
	new_A = np.where(A%min_a==0,min_a,A%min_a)
	A = new_A
	if (np.all(A == A[0])):
		break
print(A.min())

Submission status: Accepted

Solution code:
import fractions as frac
from functools import reduce
n=int(input())
a=[int(i) for i in input().split()]
def gcd_list(numbers):
    return reduce(frac.gcd, numbers)
print(gcd_list(a))

Submission status: Accepted

Solution code:
import numpy as np

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


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

min_HP = np.inf
a0 = As[0]
for a in As[1:]:
    b = gcd(a0,a)
    if b <= a0:
        a0 = b
print(a0)

Submission status: Accepted

Solution code:
import sys
import fractions
from functools import reduce
N = int(sys.stdin.readline())
A = list(set(map(int, sys.stdin.readline().split())))
print(reduce(fractions.gcd, A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

print(reduce(gcd, a))

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

n = int(input())

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

g = reduce(gcd, a)

print(g)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

Submission status: Accepted

Solution code:
from functools import reduce
def gcd (a: int,b: int) -> int:
    if a < b: a,b = b,a
    return a if b == 0 else gcd(b,a%b)
N = int(input())
print(reduce(gcd,list(map(int,input().split(" ")))))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
from functools import reduce
def gcd_list(n):
    return reduce(gcd, n)

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
n = int(input())
A = list(map(int,input().split()))
while True:
    if A.count(0) == n - 1:
        print(max(A))
        exit()
    else:
        B = [ _  for _ in A if _ != 0  ]
        attack = min(B)
        sn = A.index(attack)
        
        for i in range(n):
            if A[i] == 0:
                pass
            else:
                if i != sn:
                    A[i] = A[i] % attack
                else:
                    pass

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
while True:
    if A.count(0) == n - 1:
        print(max(A))
        exit()
    else:
        B = [ _  for _ in A if _ != 0  ]
        attack = min(B)
        sn = A.index(attack)
        
        for i in range(n):
            if A[i] == 0:
                pass
            else:
                if i != sn:
                    A[i] = A[i] % attack
                else:
                    pass

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
x=a[0]
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a
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()))
A.sort()

while(len(A) > 1):
    v = A[0]
    for i in range(1, len(A)):
        A[i] = A[i] % v
    for _ in range(A.count(0)):
        A.remove(0)
    A.sort()
print(A[0])

Submission status: Accepted

Solution code:
n=int(input())
l=[int(i) for i in input().split()]
x=ans=min(l)
while 1:
    t=[-1,-1]
    for i,j in enumerate(l):
        if j%x and ans>j%x:
            ans=j%x
            t[0]=i
            t[1]=ans
    l[t[0]]=ans
    x=ans
    if t[0]==-1: break


print(x)

Submission status: Accepted

Solution code:
n = int(input())

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

if len(set(a_list)) == 1:
    print(a_list[0])
else:
    def euclidean_algorithm(a, b):
        a, b = min(a, b), max(a, b)
        while a > 0:
            a, b = b % a, a
        return b

    ans = a_list[0]
    for i in range(len(a_list) - 1):
        ans = euclidean_algorithm(ans, a_list[i + 1])
    print(ans)

Submission status: Accepted

Solution code:
import sys
import collections

b=[]
n = map(int, raw_input().split())
a = map(int, raw_input().split())

while True:
    a.sort()
    b=[]
    if a[0]==1:
        print(1)
        break
    elif a[0]==a[-1]:
        print(a[0])
        break
    else:
        for n in a:
            n=n%a[0]
            if n!=0:
                b.append(n)
        a=[a[0]]
        a.extend(b)

Submission status: Accepted

Solution code:
import numpy as np

n = int(input())
a = list(map(int,input().split(" ")))
while True:
    a = list(set(a))
    if 0 in a:
        a.remove(0)
    a.sort()
    #print(a)
    mini = a[0]
    #print(mini)
    for i in range(1,len(a)):
        a[i] %= mini
    if len(a) == 1:
        #print("ngo")
        print(mini)
        exit()

Submission status: Accepted

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

def solve(a):
    n = len(a)
    if n == 1:
        return a[0]
    b = []
    for i in range(0, n, 2):
        if i+1 < n:
            z = gcd(a[i], a[i+1])
        else:
            z = a[i]
        b.append(z)
    return solve(b)

assert solve([2,10,8,40]) == 2
assert solve([5,13,8,1000000000]) == 1
assert solve([1000000000,1000000000,1000000000]) == 1000000000
n = input()
a = list(map(int, input().split()))
print(solve(a))

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

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

Submission status: Accepted

Solution code:
N=int(input())
a=list(map(int,input().split()))
def u(x,y):
    if x%y==0:
        return y
    else:
        return u(y,x%y)
b=list(range(N))
b[0]=a[0]
for i in range(1,N):
    b[i]=u(b[i-1],a[i])
print(int(b[N-1]))

Submission status: Accepted

Solution code:
def gcd(a,b):
    lt,gt = sorted([a,b])
    if lt == 0:
        return gt
    else:
        return gcd(gt % lt,lt)

def q3():
    N = int(input())
    A = list(map(int,input().split()))
    assert(N == len(A))
    ret = A[0]
    for n in range(1,N):
        ret = gcd(ret,A[n])
    print(ret)
    
q3()

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
while True:
  m = min(a)
  a = list(filter(lambda x: x!=0, [m] + [x%m for x in a]))
  if len(a)==1:
    break
print(a[0])

Submission status: Accepted

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

for i in range(1, N):
  a = A[i - 1]
  b = A[i]
  while a != b:
    if a < b:
      b -= (b // a) * a
      if b == 0:
        b = a
    else:
      a -= (a // b) * b
      if a == 0:
        a = b
  A[i - 1] = a
  A[i] = b
  
print(A[-1])

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)

x = A[0]

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

print(x)

Submission status: Accepted

Solution code:
N = int(input())
import math
#ユークリッド互除法の関数の定義
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)
x = list(map(int,input().split()))

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

# print(gcd_list(numbers))

Submission status: Accepted

Solution code:
def gcd(a,b):
    if(a%b==0):
        return b
    else:
        return gcd(b,a%b)
N = int(input())
s = [int(x) for x in input().split()]
tmp = s[0]
for i in s[1:]:
    tmp = gcd(tmp,i)
print(tmp)

Submission status: Accepted

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


def solve(a):
    min_a = min([elem for elem in a if elem != 0])
    new_a = [elem % min_a for elem in a]
    if len([elem for elem in new_a if elem == 0]) == len(a):
        return min_a
    new_a[new_a.index(0)] = min_a
    return solve(new_a)


print(solve(A))

Submission status: Accepted

Solution code:
N=int(input())
tmplist=list(map(int,input().split(" ")))
tmplist.sort()
tmplist.reverse()
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
res=tmplist[0]
for a in range(1,N):
    res=gcd(tmplist[a],res)
print(res)

Submission status: Accepted

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

j=0
while True:
	if len(A)==1:
		break

	i=0
	while True:
		if i==len(A):
			break
		if A[i]<1:
			A.pop(i)
			i-=1
		i+=1

	A.sort()

	for i in range(1,len(A)):
		A[i]=A[i]%A[0]

	j+=1
print(A[0])

Submission status: Accepted

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

n = int(input())
s = [int(x) for x in input().split()]
tmp= s[0]
for i in s[1:]:
  tmp = gcd(tmp,i)
 
print(tmp)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

def gcd(x,y):
    X = max(x,y)
    Y = min(x,y)
    if Y == 0:
        return X
    else:
        return gcd(Y,X%Y)

GCD = 10**9
for i in range(N-1):
    GCD = min(GCD,gcd(A[i],A[i+1]))

print(GCD)

Submission status: Accepted

Solution code:
n = int(input())
a = input().split()
for i in range(n):
    a[i] = int(a[i])
def gcm(a,b):
    if a >= b:
        if a % b == 0:
            return b 
        else:
            return gcm(b,a%b)
    else: return gcm(b,a)
for i in range(1,len(a)):
    a[0] = gcm(a[0],a[i])
print(a[0])