Problem:


Score : 300 points

Problem Statement

There are N monsters, numbered 1, 2, ..., N.

Initially, the health of Monster i is A_i.

Below, a monster with at least 1 health is called alive.

Until there is only one alive monster, the following is repeated:

A random alive monster attacks another random alive monster.

As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking.

Find the minimum possible final health of the last monster alive.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible final health of the last monster alive.

Sample Input 1

4
2 10 8 40

Sample Output 1

2

When only the first monster keeps on attacking, the final health of the last monster will be 2, which is minimum.

Sample Input 2

4
5 13 8 1000000000

Sample Output 2

1

Sample Input 3

3
1000000000 1000000000 1000000000

Sample Output 3

1000000000



Sample input:
4
2 10 8 40


Sample output:
2

Submission status: Accepted

Solution code:
def furui(a,b):
    l=max(a,b)
    s=min(a,b)
    if l%s==0:
        return s
    else:
        return furui(s,l-s*(l//s))

n=int(input())
a=[int(x) for x in input().split()]
ans=a[0]
for i in range(1,n):
    ans=furui(ans,a[i])
print(ans)

Submission status: Accepted

Solution code:
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor

import heapq
import itertools
import operator


def get_int():
    return int(input())


def get_str():
    return input().strip()


def get_int_list():
    return [int(i) for i in input().split()]


def get_char_list():
    return list(input().strip())


def main():
    n = get_int()
    hps = get_int_list()

    x = min(hps)
    while True:
        mod = [v % x for v in hps]
        mod = list(filter(lambda x: x > 0, mod))
        if mod and min(mod) < x:
            x = min(mod)
        else:
            print(x)
            return


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y) #再帰定義
s = gcd(l[0],l[1])
for i in l:
    s = gcd(s,i)
   

print(s)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from queue import Queue

q = Queue()

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

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

for i in li:
    q.put(i)


while True:
    a = q.get()
    if q.empty():
        break
    b = q.get()
    q.put(gcd(a, b))

print(a)

Submission status: Accepted

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

m = int(input())
lis = list(map(int,input().split()))

start = gcd(lis[0],lis[1])

for i in range(2,m):
  start = gcd(start,lis[i])
  if start == 1:
    break
print(start)

Submission status: Accepted

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


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

ans = A[0]

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

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce


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

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 = sorted(a)
def gcd(a,b):
  c = a%b
  if c == 0:
    return b
  else:
    return gcd(b,c)
c = 0
for i in a[1:]:
  c_ = gcd(i,a[0])
  if c_ == 1:
    c = 1
    break
  else:
    if c_ < c or c == 0:
      c = c_
print(c)

Submission status: Accepted

Solution code:

def gdc_euclid(u, v):
    r = 0
    while 0 != v:
        r = u % v
        u = v
        v = r
    return u


# 最大公約数を出す問題かな？
if __name__ == '__main__':
    n = int(input())
    monsters = list(map(int, input().split()))

    before = 0
    for a in monsters:
        if before == 0:
            before = a
        else:
            before = gdc_euclid(a, before)

    print(before)

Submission status: Accepted

Solution code:
N=int(input())
A=sorted(list(map(int,input().split())))
while len(A)!=1:
    B=[A[0]]+[A[i]-(A[i]//A[0])*A[0] for i in range(1,len(A))]
    A=sorted(list(set(filter(lambda x:x>0, B))))
print(A[0])

Submission status: Accepted

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

def main():
    N = int(input())
    A = list(map(int, input().split()))  # 体力

    while True:
        A.sort()

        before_min = A[0]
        after_min = before_min
        for i in range(1, N):
            A[i] = (A[i] % A[0]) if A[i] % A[0] != 0 else A[i]
            after_min = min(after_min, A[i])

        # print(A)
        if before_min == after_min:
            print(before_min)
            exit()

main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from functools import reduce

def gcd(a, b):
    x = max(a, b)
    y = min(a, b)
    z = y
    while x%y != 0:
        z = x%y
        x = y
        y = z
    else:
        return z
            

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


N = int(input())

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

print(gcd_list(A))

Submission status: Accepted

Solution code:
from functools import reduce

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

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

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

print(gcd_list(A))

Submission status: Accepted

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

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

print(gcd_list(monster_list))

Submission status: Accepted

Solution code:
import sys
from collections import deque
import copy
import math
def get_read_func(fileobject):
    if fileobject == None :
        return raw_input
    else:
        return fileobject.readline

def main():
    if len(sys.argv) > 1:
        f = open(sys.argv[1])
    else:
        f = None
    read_func = get_read_func(f);
    input_raw = read_func().strip().split()
    [N] = [int(input_raw[0])]
    input_raw = read_func().strip().split()
    A = []
    for i in range(N):
        A.append(int(input_raw[i]))



    while(1):
        min_A = min(A)
        is_all_dividable = True
        for i in range(N):
            if A[i]%min_A != 0:
                A[i] = A[i] % min_A
                is_all_dividable = False
        if is_all_dividable == True:
            break
    print min_A


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import fractions
 
def gcd_1(a):
    p = fractions.gcd(a[0],a[1])
    if len(a) > 2:
        for i in range(2,len(a)):
            p = gcd_1([p,a[i]])
    else:
        p = fractions.gcd(a[0],a[1])
 
    return p
 
n = int(input())
a = [int(i) for i in input().split()]
 
print(gcd_1(a))

Submission status: Accepted

Solution code:
import fractions

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

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

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())

energy = np.array(list(map(int, input().split())))
energy.sort()

while (len(energy) > 1):
    energy[1:] = energy[1:] % energy[0]
    energy.sort()
    energy = energy[~(energy < 1)]

print(energy[0])

Submission status: Accepted

Solution code:
n = int(raw_input())
a = map(int, raw_input().split())
def gcd(x, y):
    while y:
        x, y = y, x % y
    return x
while len(a)>=2:
    k = gcd(a[0],a[1])
    a[1]=k
    del a[0]
print k

Submission status: Accepted

Solution code:
from fractions import gcd

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

for i,x in enumerate(A):
	if i==0:
		ans=x
	else:
		ans=gcd(ans,x)
print ans

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
n = min(A) 
idx = A.index(n)
while True:
    tmpn = n
    tmpi = idx
    for i in range(N):
        if i == idx:
            continue
        if A[i] % n == 0:
            continue
        if (A[i] % n) < n:
            tmpn = A[i] % n
            tmpi = i
    if tmpn == n:
        break
    A[tmpi] = tmpn
    n = tmpn
    idx = tmpi
print(n)

Submission status: Accepted

Solution code:
from fractions import gcd
N = int(input())
li = set(map(int,input().split()))
li = list(li)

ans = li[0]
for i in range(1,len(li)):
    ans = gcd(ans,li[i])
    if ans == 1: break

print(ans)

Submission status: Accepted

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

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

max_k = gcd(A_arr[0], A_arr[1])
if N > 2:
    for i in range(2, N):
        max_k = gcd(max_k, A_arr[i])
else:
    pass

print(max_k)

Submission status: Accepted

Solution code:
n = int(input())
a = set(map(int, input().split()))
while len(a) >= 2:
    m = min(a)
    a = {ai % m for ai in a} 
    a |= {m} 
    a -= {0}
print(min(a))

Submission status: Accepted

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


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

ans = monsters[0]
        
for m in monsters:
    ans = gcd(ans, m)

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

n = input()
alist = [int(s) for s in input().split()]

print(gcd_list(alist))

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
def zero_min(Alist,L):
    Alist.sort()
    for i in range(L):
        if Alist[i] != 0:
            return Alist[i]
            break
        else:
            pass
        
def euc(Alist,L):
    Alist.sort()
    MIN = zero_min(Alist,L)
    minindex = Alist.index(MIN)
    for i in range(L):
        if A[i] == 0 or i == minindex:
            pass
        else:
            Alist[i] = Alist[i]%MIN
            
    if 1 in Alist:
        return 1
    elif sum(Alist) == MIN:
        return MIN
    else:
        return euc(Alist,L)
print(euc(A,N))

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)
def gcd_reduce(T):
    result=T[0]
    for i in range(1,len(T)):
        result=gcd(result,T[i])
    return result
print(gcd_reduce(A))

Submission status: Accepted

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

Submission status: Accepted

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

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
x = A_list[0]
for i in range(1, N):
    x = gcd(x, A_list[i])
print(x)

Submission status: Accepted

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

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())
life = list(map(int,input().split()))
while len(life) != 1:
    life.sort()
    for i in range(len(life)):
        if life[i] != 0:
            life = life[i:]
            break
    min_life = life[0]
    for j in range(len(life)-1):
        life[j+1] = life[j+1]%min_life
print(life[0])

Submission status: Accepted

Solution code:
import math
import functools


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

    return gcd(b, a%b)
n = int(input())

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

g = functools.reduce(gcd, a)

print(g)

Submission status: Accepted

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
import numpy as np

sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]


def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    N = I()
    A = LI()
    #  print(N, A)


    # 余りを活用する
    A = list(set(A))
    A.sort(reverse=True)
    if A[-1] == 0:
        del A[-1]
    #  print(A)
    while len(A) > 1:
        #  A[0] = A[0] % A[1]
        A = [a % A[idx+1] if idx < len(A) - 1 else a for idx, a in enumerate(A)]
        A = list(set(A))
        A.sort(reverse=True)
        if A[-1] == 0:
            del A[-1]

        #  if A[0] == 0:
        #      del A[0]

    print(A[0])

main()

Submission status: Accepted

Solution code:
import sys

def main():
	n = map(int, input())
	monsters = list(map(int, input().split()))
	monsters.sort()
	minimum = sys.maxsize
	while len(monsters) > 1:
		new_monsters = [monsters[0]]
		for i, m in enumerate(monsters):
			if i == 0:
				continue
			new_m = m%monsters[0]
			if new_m != 0:
				new_monsters.append(new_m)
		new_monsters.sort()
		if new_monsters[0] < minimum:
			minimum = new_monsters[0]
		monsters = new_monsters
	print(minimum)


if __name__ == '__main__':
	main()

Submission status: Accepted

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

N = int(input())
A = [int(i) for i in input().split()]
K = gcd(A[0], A[1])

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

print(K)

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-

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

def arrgcd(a):
    alen = len(a)
    if alen == 3:
        return gcd(a[0], gcd(a[1], a[2]))
    elif alen == 2:
        return gcd(a[0], a[1])
    elif alen == 1:
        return a[0] # 最初から1つ
    elif alen == 0:
        return 0
    else:
        return gcd(arrgcd(a[:alen//2]), arrgcd(a[alen//2:]))

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    print(arrgcd(al))

if __name__=="__main__":
    solve()

Submission status: Accepted

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

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

print(A[0])

Submission status: Accepted

Solution code:
def gcd(LIST):
    ans=LIST[0]
    for member in LIST[1:]:
        x=max(ans,member)
        y=min(ans,member)
        if x%y==0:
            ans=y
        else:
            while x%y!=0:
                z=x%y
                x=y
                y=z
            ans=z
    return ans
N=int(input())
A=list(map(int,input().split()))
print(gcd(A))

Submission status: Accepted

Solution code:
import numpy as np
def gcd(a, b):
    if a % b:
        return gcd(b, (a % b))
    else:
        return b
N = int(input())
A = list(map(int,input().split()))
A_gcd = A[0]
for a in A:
    A_gcd = gcd(a,A_gcd)
print(A_gcd)

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

Submission status: Accepted

Solution code:
N = int(input())
monslist = list(map(int, input().split()))
monslist.reverse()
while max(monslist)!=0:
    mn = monslist[-1]
    for i in range(len(monslist)-1):
        monslist[i] = monslist[i]%mn
    monslist.reverse()
    for i in range(len(monslist)):
        if(monslist[-1]==0):monslist.pop()
    if(len(monslist) == 1): break
print(monslist[0])

Submission status: Accepted

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

while True:
    mA=min(A)
    pre_A=[a-((a-1)/mA)*mA for a in A]
    if pre_A==A:
        break
    A=pre_A[:]

print min(A)

Submission status: Accepted

Solution code:
import numpy as np
from functools import reduce

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


N = input()
A = list(map(int, input().split()))
print(reduce(gcd, A, A[0]))

Submission status: Accepted

Solution code:
from functools import reduce


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

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


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

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)

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

Submission status: Accepted

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

sys.setrecursionlimit(100000000)


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


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

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#N, M = map(int, input().split())
#
#ans = [0 for i in range(M)]
#
#for i in range(N):
#    tmp = list(map(int, input().split()))
#    for j in range(tmp[0]):
#        ans[tmp[j]]+=1
#        
#now = 0
#        
#for i in range(M):
#    if ans[i]==N:
#        now+=1
#        
#print(now)

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

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


ans = 0
now = a[0]

for i in range(N-1):
    tmp = gcd(now, a[i+1])
    now = tmp

    
print(now)

Submission status: Accepted

Solution code:
n=int(input())
a=[]
s=input().split()
for i in range(n):
  a.append(int(s[i]))
Min=1000000000
min=1000000000
while(True):
  a=sorted(a)
  d=0
  for i in range(n):
    if a[i]==0:
      continue
    elif d==0:
      d=a[i]
      if d<min:
        min=d
      continue
    a[i]=a[i]%d
    if a[i]!=0 and a[i]<min:
      min=a[i]
  if min<Min:
    Min=min
  else:
    break
print(Min)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
#coding:utf-8
N  = int(input())
A = list(map(int,input().split()))
def c(A,B):
    for a,b in zip(A,B):
        if a != b:
            return False
    return True
while True:
    A.sort()
    prev = A[:]
    
    s = A[0]
    for i in range(N):
        if A[i] % s == 0:
            A[i] = s
        else:
            A[i] = A[i] % s
    A.sort()
    #print("A  :",A)
    #print("pre:",prev)
    if  c(prev,A) : break
#print("A  :",A)
#print("pre:",prev)
print(A[0])

Submission status: Accepted

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

while len(B)>1:
  C=[i for i in range(len(B))]
  C.remove(B.index(min(B)))
  d=min(B)

  for i in C:
    B[i]=B[i]%d
  while 0 in B:
    B.remove(0)
print(B[0])

Submission status: Accepted

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


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

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

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

print(gcd_list(As))

Submission status: Accepted

Solution code:
def aaa(n, lst):
    lst = [x % n for x in lst if x % n != 0]
    lst.append(n)
    return sorted(lst)

N = int(input())
lst = sorted(map(int, input().split()))
while len(lst) > 1:
    lst = aaa(lst[0], lst[1:])

print(lst[0])

Submission status: Accepted

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

while len(a)!=1:
  t=min(a)
  a=set(i for i in map(lambda x:x%t if x!=t else t,a) if i)

print(a.pop())

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    *A, = map(int, input().split())

    ans = f(N, A)
    print(ans)


try:
    # 最大公約数: greatest common divisor
    # py3.5+
    from math import gcd
except ImportError:
    from fractions import gcd


def f(N, A):
    """
    はじめ、モンスター iの体力は Ai
    以降、体力が1以上のモンスターを生きているモンスターと呼びます。
    生きているモンスターが 1体になるまで以下を繰り返します。

    ランダムに 1体の生きているモンスターがランダムに別の生きているモンスターに攻撃します。
    その結果、攻撃されたモンスターの体力を攻撃したモンスターの体力と同じ値だけ減らします。

    最後に生き残ったモンスターの最終的な体力の最小値を求めてください。

    成約
        入力は全て整数である。
        2 ≤ N  ≤ 10^5
        1 ≤ Ai ≤ 10^9

    どれだけ体力を減らせるか
    1のモンスターがいたら1
    一番少ない体力のモンスターが最低限の体力
    その体力で他のモンスターを攻撃し続けると Amax % Amin が最小になる
        ただし0になったらだめ
    多いモンスターは他に攻撃してもらう

    なんとなく最小公倍数・最大公約数が浮かんだ
    他のモンスターの体力で割り切れてしまうなら
        約数なら、他のモンスターが最小
        6と3
        6と4なら2残る
        9と2なら1残る
    """
    ans = A[0]
    for a in A[1:]:
        ans = gcd(ans, a)

    return ans


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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=input()
A=set(map(int,input().split()))
R=max(A)
while 1:
    r=min(A)
    if r==R:break
    A=set(i%r for i in A)-{0}|{r}
    R=r
print(R)

Submission status: Accepted

Solution code:
from sys import stdin
from functools import reduce

n = stdin.readline().rstrip()
A = list(map(int, stdin.readline().rstrip().split()))

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

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

N = int(input())
a = [int(v) for v in input().split()]
print(gcd_list(a))

Submission status: Accepted

Solution code:
num_of_monsters = int(input())
monsters = list(map(lambda x: int(x), input().split(' ')))
monsters = sorted(monsters)

while len(monsters) > 1:
  minimum = monsters[0]
  for i in range(1, len(monsters)):
    max_division_times = int(monsters[i] / minimum)
    monsters[i] -= (minimum * max_division_times)
  
  monsters = sorted(filter(lambda a: a != 0, monsters))
print (monsters[0])

Submission status: Accepted

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

while len(a) > 1:
    m = min(a)
    a = [x % m for x in a if x % m != 0]
    a.append(m)

print(a[0])

Submission status: Accepted

Solution code:
def gcd(a, b):
  while b != 0:
    a, b = b, a % b
  return a
n=int(input())
l=list(map(int,input().split()))
ans=l[0]
l.remove(ans)
for i in l:
  ans=gcd(ans,i)
print(ans)

Submission status: Accepted

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


while len(A)>1:
    m = min(A)
    A.remove(m)
    A = set(A)
    A = {i%m for i in A}
    if 0 in A:
        A.remove(0)
    A = list(A)
    A.append(m)

print(A[0])

Submission status: Accepted

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

while len(a) > 1:
  minimum_value = min(a)
  for i in range(len(a)):
    r = a[i] % minimum_value
    a[i] = r if r > 0 else minimum_value

  a = list(set(a))

print(a[0])

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
while True:
    minimum = A[0]
    A = sorted([a % minimum for a in A[1:] if a % minimum != 0]) + [minimum]
    if len(A) == 1:
        break
print(A[0])

Submission status: Accepted

Solution code:
import copy
N = int(input())
A = [int(i) for i in input().split()]
A=list(set(A))
A.sort()

while True:
    B=copy.deepcopy(A)
    for i in range(1, len(A)):
        A[i] = A[i] % A[0] if not A[i] % A[0] ==0 else A[i]

    if B==A or len(A)==1:
        print(min(A))
        exit(0)
    A = list(set(A))
    A.sort()

Submission status: Accepted

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

while True:
    amin = 10**10
    for i in a:
        if i != 0 and amin > i:
            amin = i
    c = 0
    flag = False
    for i in range(len(a)):
        if amin == a[i] and flag == False:
            flag = True
            continue
        if a[i] <= amin and a[i] != 0:
            c += 1
            a[i] = 0
        if a[i] != 0:
            a[i] %= amin
            c += 1
    if c == 0:
        break
print(amin)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
from functools import reduce

def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
def gcd_list(numbers):
    return reduce(gcd, numbers)

N = int(input())

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

print(gcd_list(As))

Submission status: Accepted

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

while True:
    a.sort()
    for i in range(1,len(a)):
        a[i] = a[i] % a[0]
    
    if sum(a[1:]) == 0:
        print(a[0])
        exit()

    b = []
    for i in range(len(a)):
        if a[i] != 0:
            b.append(a[i])
    a = b

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 = input().split()

for i in range(len(a)):
    a[i] = int(a[i])

while(sum(a)!=max(a)):
    a = [i for i in a if i != 0]
    a = sorted(a)
    for i in range(len(a)-1):
        a[i+1] = a[i+1]%a[0]

print(a[0])

Submission status: Accepted

Solution code:
def main():
    n = int(input().rstrip("\n"))
    current , *numbers = [int(x) for x in input().rstrip("\n").split(" ")]
    while current >= 2 and numbers:
        next_value = numbers.pop(0)
        a, b = min(current, next_value), max(current, next_value)
        while b % a > 0:
            a, b = (b % a), a
        current = a
    print(current)
    

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from functools import reduce

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

n = int(input())
numbers = [int(x) for x in input().split()]
print(reduce(gcd, numbers))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
flag = True
while(flag):
    flag = False
    A.sort()
    first = A[0]
    for index,i in enumerate(A):
        A[index] = i%first if i%first!=0 else first
    for i in A:
        if(first != i):
            flag = True
print(A[0])

Submission status: Accepted

Solution code:
list(map(int, input().split()))
h = list(map(int, input().split()))
mh = min(h)
bmh = 0
while mh != bmh:
  bmh = mh
  h = list(map(lambda x: x % mh if x % mh != 0 else mh, h))
  mh = min(h)
print(mh)

Submission status: Accepted

Solution code:
import fractions

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

a_min = min(a)
ans = 1e10
for i in a:
    tmp = fractions.gcd(a_min, i)
    if(tmp < ans): ans = tmp

print(ans)

Submission status: Accepted

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


n=int(input())
a=list(map(int, input().split()))
prv=a[0]
for ai in a[1:]:
  prv=gcd(ai,prv)
print(prv)

Submission status: Accepted

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

from functools import reduce
from fractions import gcd

def solve():
    input()
    res = reduce(gcd, map(int, input().split()))

    return str(res)
if __name__ == '__main__':
    print(solve())

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    aa = list(map(int, input().split()))
    while len(aa) > 1:
        a_min = min(aa)
        a_min_i = aa.index(a_min)
        del aa[a_min_i]
        aa = [a % a_min for a in aa if a % a_min != 0]
        aa.append(a_min)
    print(aa[0])


if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())

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

while(len(life)>1):
    attack = life[0]
    for i in range(1,len(life)):
        life[i] %= attack
    life = [item for item in life if item >0]
    life.sort()
print(life[0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python
# coding: utf-8


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

def main():
    n = int(input())
    la = list(map(int, input().split()))
    la.sort()
    m = la[0]
    ans = pow(10, 9) + 1
    for a in la[1:]:
        g = gcd(a, m)
        if g < ans:
            ans = g
        if ans == 1:
            break
    print(ans)



if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
import functools
# import math
import fractions
N = int(input())
A = list(map(int, input().split()))
# ans = functools.reduce(math.gcd, A)
ans = functools.reduce(fractions.gcd, A)
print(ans)