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:
from sys import stdin

def fun():
    n = (int(i) for i in input().split())

    l = [int(x) for x in stdin.readline().rstrip().split()]

    l = list(set(l))
    l.sort()

    while 1 < len(l):
        k = len(l)
        for i in range(1, k):
            if l[k-i]%l[0] == 0:
                l.pop(k-i)
            elif l[k-i] - l[k-i-1] == 1:
                print(1)
                return
            else:
                l[k-i] = l[k-i]%l[0]
        #l = [e for e in l if e != 0]
        l = list(set(l))
        l.sort()

        if l[0]==1:
            print(1)
            return

    print(l[0])
    return

if __name__ == '__main__':
    fun()

Submission status: Accepted

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

import sys

def gcd(a, b):

    c = min(a, b)
    d = max(a, b)
    r = 0    
    while True:
        r = d % c
        if r == 0:
            break
        d = c
        c = r

    return c

def parse_input(lines_as_string = None):

    lines = []
    if lines_as_string is None:
        for line in sys.stdin:
            lines.append(line)
    else:
        lines = [e for e in lines_as_string.split("\n")][1:-1]

    # 出力
    nm = lines[0].split(" ")
    n = int(nm[0])

    rows = []
    for i in range(1, 2):
        rows.append([int(e) for e in lines[i].split(" ")])

    return (n, rows[0])

def solve(n, monsters):

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


    return g

def main():

    print("%d" % solve(*parse_input()))

if __name__ == '__main__':

    main()

Submission status: Accepted

Solution code:
def euclid(a,b):
    max_v=max(a,b)
    min_v=min(a,b)
    while 1:
        if max_v%min_v==0:
            return min_v
        tmp=max_v%min_v
        max_v=min_v
        min_v=tmp

        
    
if __name__=='__main__':
    n=int(input())
    hp=[int(i) for i in input().split()]
    cd=hp[0]
    for i in range(1,n):
        cd=euclid(cd,hp[i])
    print(cd)

Submission status: Accepted

Solution code:
def inpul(): return list(map(int, input().split()))

import fractions
from functools import reduce

#最大公約数
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

N = inpul()
a = inpul()

ans = gcd_list(a)
print(ans)

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int,input().split()))
# print(N,A,sep="\n")
data = set(A)

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

def culc(data):
  A_min=min(data)
  if set(map(lambda x: x%A_min,data))=={0}:
    return A_min
  A.sort()
  ans = A_min
  for i in A[1:]:
    ans=gdc(ans,i)
    if set(map(lambda x: x%ans,data))=={0}:
      return ans
  return ans

print(culc(data))

Submission status: Accepted

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

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

Submission status: Accepted

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

    n = len(x)
    if n == 1:
        return x[0]
    else:
        element = gcd(x[0], x[1])
        if n == 2:
            return element
        else:
            for i in range(2,n):
                element = gcd(element,x[i])
            return element

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

Submission status: Accepted

Solution code:
N = int(input())
A_arr = [int(x) for x in input().split()]

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

m = A_arr[0]
for A in A_arr[1:]:
    m = gcd(m, A)

print(m)

Submission status: Accepted

Solution code:
import sys
import pprint

pp = pprint.PrettyPrinter(indent=4)

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

def main():
    """ Code implementation """
    n = int(input())
    healths = list(map(int, input().split()))
    m = healths[0]
    for i in range(1, len(healths)):
        if (m < healths[i]):
            g = gcd(m, healths[i])
        else:
            g = gcd(healths[i], m)
        if m > g:
            m = g

    print(m)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
# !/usr/bin/env python
# vim: set fileencoding=utf-8 :

"""
#
# Author:   Noname
# URL:      https://github.com/pettan0818
# License:  MIT License
# Created: 土  2/23 16:47:57 2019

# Usage
#
"""
from fractions import gcd
from functools import reduce

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

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


if __name__ == '__main__':
	print(solve(i()))

Submission status: Accepted

Solution code:
from functools import reduce

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

def gcd(*numbers):
    return reduce(mgcd, numbers)

input()

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

print(gcd(*li))

Submission status: Accepted

Solution code:
from functools import reduce

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

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

def gcd(*num):
    return reduce(gcd_base, num)

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

print(gcd_list(A))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
import numpy as np

v = []
for line in sys.stdin:
  v.append([int(l) for l in line.split()])

m = np.array(v[1])

while len(m) != 1:
  min_m = np.min(m)
  arg_min_m = np.argmin(m)
  for idx, i in enumerate(m):
    if idx != arg_min_m:
      m[idx] %= min_m
  m = m[m!=0]
print(m[0])

Submission status: Accepted

Solution code:
def kumitate(a,b):
    a,b =max(a,b),min(a,b)
    while b != 0:
        a,b = b,a%b
    return a

N =int(input())
l =[int(i)for i in input().split()]
l =sorted(l)
mini =l[0]
for i in l:
    mini = kumitate(mini,i)
print(mini)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def main():
    N = int(input())
    health = set(map(int, input().split()))
    min_num = min(health)
    for i in health:
        while i % min_num != 0:
            temporary_min_num = min_num
            min_num = i % min_num
            i =  temporary_min_num
    print(min_num)

main()

Submission status: Accepted

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

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

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

Submission status: Accepted

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


while True:
    while 0 in monster_life_lst:
        monster_life_lst.remove(0)
    monster_life_lst.sort()
    for i in range(1, len(monster_life_lst)):
        monster_life_lst[i] = monster_life_lst[i] % monster_life_lst[0]
    if len(monster_life_lst) == 1:
        out_flag = monster_life_lst[0]
        break

def out(out_flag):
    print(out_flag)

out(out_flag)

Submission status: Accepted

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

# A内の整数値を用いて作られる最小の整数を求めよ、という問題


def gcd(a, b):
    """
    自然数a, b の最大公約数を求める
    """
    if b == 0:
        return a
    else:
        return gcd(b, a % b)


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


print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

print(ans)

Submission status: Accepted

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

#print(reduce(math.gcd, a))

b=a[0]
c=a[1]
result=1
for i in range(1,n):
    while 1:
        if b%c == 0:
            result = c
            break
        else:
            r = b%c
            b = c
            c = r
    b=result
    c=a[i]
 
print(result)

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
while len(a)>1:
    m=min(a)
    def f(n):
        return n%m
    a=map(f,a)
    a=set(a)
    a.add(m)
    a.remove(0)
    a=list(a)
print(a[0])

Submission status: Accepted

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


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


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

print(ans)

Submission status: Accepted

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

def GCD(a, b):
    a, b = max(a, b), min(a, b)
    while a % b != 0:
        a, b = b, a%b
    return b

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())
L = [int(s) for s in input().split(' ')]

while len(L) > 1:
  L.sort()
  L_new = [L[0]]
  for l in L[1:]:
    v = l % L_new[0]
    if v != 0:
      L_new.append(v)
  L = L_new
print(L[0])

Submission status: Accepted

Solution code:
n = int(input())

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

hitPoint.sort()

while not len(hitPoint) <= 1:
	a = hitPoint.pop(0)
	hitPoint = [ elem % a for elem in hitPoint if not elem % a == 0]
	hitPoint.append(a)
	hitPoint.sort()

print(hitPoint[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
n = int(input())
al = list(map(int, input().split()))

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

res = al[0]
for i in range(1,n):
    res = gcd(res,al[i])

print(res)

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

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

Submission status: Accepted

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

def f(l):
    m=min(l)
    li=[m]
    if m==sum(l):
        return m
    else:
        for i in range(len(l)):
            if l[i]%m!=0:
                li.append(l[i]%m)
        return f(li)

print(f(a))

Submission status: Accepted

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

def m(a):
    a.sort()
    l = len(a)
    b = []
    for i in range(l // 2):
        b.append(gcd(a[i], a[l - i - 1]))
    if l % 2 == 1:
        b.append(a[l // 2])
    return list(set(b))

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

while len(a) > 1:
    a = m(a)

print(a[0])

Submission status: Accepted

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


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

ans = mons[-1]
for i in mons:
    ans = gcd(ans, i)

print(ans)

Submission status: Accepted

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

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

ans = line[0]

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

print(ans)

Submission status: Accepted

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

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

res = l[0]
for i in range(1,n):
    res = gcg(res,l[i])
else:
    print(res)

Submission status: Accepted

Solution code:
gcd = lambda a, b: a if b == 0 else gcd(b, a % b)
N = int(input())
A = list(map(int, input().split()))
if A[0] < A[1]:
    tmp = A[0]
    A[0] = A[1]
    A[1] = tmp
c = gcd(A[0], A[1])
for i in range(2, N):
    if c < A[i]:
        tmp = c
        c = A[i]
        A[i] = tmp
    c = gcd(c, A[i])
print(c)

Submission status: Accepted

Solution code:
def gcd(a, b):
    q = a % b
    if q == 0:
        return b
    else:
        return gcd(b,q)
    
n = int(input())
li = list(map(int, input().split()))
ans = li[0]

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

print(ans)

Submission status: Accepted

Solution code:
import numpy as np

_ = input()
L = np.array(list(map(int, input().split())))

while True:
    th, index = np.amin(L), np.argmin(L)
    L = np.mod(L, th)
    L[index] = th
    L = L[L > 0]
    if len(L) == 1:
        print(L[0])
        break

Submission status: Accepted

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

Submission status: Accepted

Solution code:
gN = int(input())
gA = list(map(int,input().split()))

def attack():
    while True:
        minA = min(gA,key=lambda x: float('inf') if x==0 else x)
        maxA = max(gA)
        if minA == maxA:
            return minA

        for a in range(gN):
            if gA[a] == minA: continue
            gA[a] %= minA

if __name__ == "__main__":
    print(attack())

Submission status: Accepted

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

a=A[0]
b=A[1]
gcd=1
for i in range(1,N):
  while 1:
    if a%b == 0:
      gcd=b
      break
    else:
      r = a%b
      a = b
      b = r
  a=gcd
  b=A[i]

print(gcd)

Submission status: Accepted

Solution code:
import fractions as fr
import functools as ft


N = map(int, input().split())
A = list(map(int, input().split())) # "1 2 3"と入力

cal1 = lambda x, y : fr.gcd(x, y)

print(ft.reduce(cal1, A))

Submission status: Accepted

Solution code:
import numpy as np

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

while A.size > 1:
    A[1:] = A[1:] % A[0]
    A = np.setdiff1d(A, [0])

print(A[0])

Submission status: Accepted

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

"""
参考：https://img.atcoder.jp/abc118/editorial.pdf
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

print(gcd_list(A))

Submission status: Accepted

Solution code:
n = int(input())
alist = list(map(int,input().split()))
i_roop = 1
while i_roop > 0 :
  alist.sort()
  n = len(alist)  
  k = min(alist)
  if k == sum(alist) :
    break
  else:
    for j in range(1,n):
      alist[j] = alist[j] % k
  
  alist = [i for i in alist if not i  == 0]  
print(alist[0])

Submission status: Accepted

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

while True:
  mini = min(A)
  newA = []
  op = False
  for i in A:
    if i == mini:
      newA.append(i)
    elif i % mini == 0:
      newA.append(mini)
    else:
      newA.append(i % mini)
  A = newA
  if len(set(A)) == 1:
    break

print(A[0])

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)

def gcd(i,j):
  if i>j:
    i,j=j,i
  if j%i==0:
    return i
  return gcd(j-i,i)

n=int(input())
l=[int(i) for i in input().split()]
l.sort()
g=gcd(l[0],l[1])
for i in range(2,len(l)):
  g=gcd(g,l[i])
print(g)

Submission status: Accepted

Solution code:
n = int(input())
A = [int(a) for a in input().split()]
A.sort()
while(len(A)!=1):  
    n = A[0]
    A = map(lambda _: _% n, A[1:])
    A = [n] + [a for a in A if a != 0]
    A.sort()
    
print(A[0])

Submission status: Accepted

Solution code:
#-*-coding:utf8;-*-
#qpy:3
#qpy:console
n = int(input())
hp = list(map(int, input().split()))
while len(hp) != 1:
    minhp = min(hp)
    hp = [i % minhp if not i == minhp else i for i in hp]
    hp = [i for i in hp if not i == 0]
    if min(hp) == 1:
        minhp = min(hp)
        break
    elif hp == [minhp for i in hp]:
        break
print(minhp)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
s = min(A)
d = [x % s for x in A]
while max(d) > 0 and s > 1:
  d = [e for e in d if e > 0] + [s]
  s = min(d)
  d = [x % s for x in d]
print(s)

Submission status: Accepted

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


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


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

for i in range(2, len(a)):
    ans = gcd(ans, a[i])

print(ans)

Submission status: Accepted

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

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians, log10
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul, xor
from copy import copy, deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
A = LIST()

A.sort()
mn = A[0]
i = 1
while i < N and mn > 1:
    div = A[i] % mn
    if div != 0 and mn > div:
        mn = div
        i = 0
    else:
        i += 1
print(mn)

Submission status: Accepted

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


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


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
N = int(input())
A = list(int(x) for x in input().split())

while 1 < len(A):
	low = min(A)
	A.remove(low)

	A = map(lambda x: x%low, A)
	A = list(filter(lambda x: x>0, A))

	A.append(low)

print(A[0])

Submission status: Accepted

Solution code:
from fractions import *
from functools import *

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

print(reduce(gcd, an))

Submission status: Accepted

Solution code:
#A
"""
a,b = map(int, input().split())
if b % a == 0:
    print(b + a)
else:
    print(b-a)
"""

#B
"""
n, m = map(int, input().split())
ans = input().split()
del ans[0]
for i in range(n-1):
    a = input().split()
    del a[0]
    for k in ans:
        if k in a:
            continue
        else:
            ans.remove(k)
    if len(ans) == 0:
        break
print(len(ans))
"""
#C
import fractions
from functools import reduce

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

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

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

Submission status: Accepted

Solution code:
a = int(input())
list = input().split()
for j in range(a):
	list[j] = int(list[j])
gcd = list[0]
for i in range(a):
	m = list[i] 
	n = gcd
	while n != 0:
		m,n = n,m%n
	if(m<gcd):
		gcd = m
print(gcd)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

for i,item in enumerate(a):
    if i != 0:
        ans = gcd(ans,item)

print(ans,end='')

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

def main():
    n = int(input())
    nums = list(map(int, input().split()))
    print(reduce(gcd, nums))
    
if __name__ == '__main__':
    main()

Submission status: Accepted

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

def gcd(A, B):
    P = max(A, B)
    Q = min(A, B)
    while P%Q!=0:
        R = P%Q
        P = Q
        Q = R
    return Q

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

Submission status: Accepted

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

from functools import reduce
import fractions 


A.sort(reverse = True)

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

print(gcd_list(A))

Submission status: Accepted

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

from fractions import gcd
from functools import reduce


def solve(string):
    n, *a = map(int, string.split())
    return str(reduce(gcd, a))


if __name__ == '__main__':
    print(solve("\n".join([input(), input()])))

Submission status: Accepted

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

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

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

Submission status: Accepted

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

b = min(A)
for a in A:
    while True:
        if a%b == 0:
            break
        tb = b
        b = a%b
        a = tb

print(b)

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
# print(A)
i = 0
while i < len(A) - 1:
    a, b = A[i], A[i + 1]
    A[i] = b % a
    A[i + 1] = a
    if A[i] == 0:
        i += 1
print(A[i])

Submission status: Accepted

Solution code:
N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse = True)

def calc(a, b):
    largeNum = max(a, b)
    smallNum = min(a, b)
    while(largeNum != 0 and smallNum != 0):
        largeNum %= smallNum
        x = largeNum
        largeNum = smallNum
        smallNum = x
    return max(smallNum, largeNum)

ans = 1
for i in range(0, N - 1):
    a = calc(A[i], A[i+1])
    A[i], A[i+1] = a, a
    if a == 1:
        break
else:
    ans = min(A)

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

ans = li[0]

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

print(ans)

Submission status: Accepted

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

def main():
  N = int(input())
  a = list(map(int, input().split()))
  r = a[0]
  
  for i in range(1, len(a)):
    r = gcd(r, a[i])
    if r == 1:
      break

  print(r)
    

if __name__ == '__main__':
  main()

Submission status: Accepted

Solution code:
#coding:utf-8

n=input()
A=map(int, raw_input().split(" "))
A.sort()
last=-1
ans=A[0]

while True:
    if last==ans:
        break
    last=ans
    for a in A:
        m=a%ans
        if m!=0:
            ans=min(m,ans)

print(ans)

Submission status: Accepted

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

N = int(raw_input())

arr = map(int, raw_input().strip().split(' '))

result = arr[0]
for i in xrange(1, len(arr)) : 
    result = gcd(result, arr[i])


print result

Submission status: Accepted

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

    b = min(A)
    for a in A:
        while True:
            if a%b == 0:
                break
            a,b = b, a%b
    print(b)

main()

Submission status: Accepted

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

b = min(A)
for a in A:
    while True:
        if a%b == 0:
            break
        #a,b = b, a%b
        tb = b
        b = a % b
        a = tb
print(b)

Submission status: Accepted

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

b = min(A)
for a in A:
    while True:
        if a%b == 0:
            break
        a,b = b, a%b
print(b)

Submission status: Accepted

Solution code:
N = int(input())
#A = [int(i) for i in input().split()]
A = list(map(int,input().split()))

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

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

Submission status: Accepted

Solution code:
N = int(input())
#A = [int(i) for i in input().split()]
A = list(map(int,input().split()))

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

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

Submission status: Accepted

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

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

def process(number_list):
    left, point = number_list[0], number_list[-2]
    if left == 1:
        print(1)
        return 0
    right = number_list[-1] % left
    number_list.pop(-1)
    if right == 0:
        if len(number_list) == 1:
            print(number_list[0])
            return 0
    else:
        number_list.insert(0, right)
    return number_list

def main():
    num = int(input())
    number_list = list(map(int, input().split()))
    number_list.sort()
    while 1:
        number_list = process(number_list)
        if number_list == 0:
            break


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from fractions import gcd

n = int(input())
hp_list = list(map(int,input().split()))
test = hp_list[0]

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

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N, = list(map(int, input().split()))
A = list(map(int, input().split()))
b = set(A)
while len(b)>1:
  m = min(b)
  c = set((m,))
  for bi in b:
    if bi%m>0:
      c.add(bi%m)
  b = c
print(list(b)[0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
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 = [int(i) for i in input().split()]

print(reduce(gcd, A))

Submission status: Accepted

Solution code:
import numpy as np

def input_numbers():
    temp = list(map(int, input().split()))
    return temp

def GCD(a, b):
    if(a < b):
        temp = a
        a = b
        b = temp
    a = a % b
    if(a == 0):
        return b
    else:
        return GCD(a, b)

n = int(input())
a = input_numbers()

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

print(g)