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 fractions import gcd


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

ans = next(A)

for a in A:
    ans = gcd(ans, a)

print(ans)

Submission status: Accepted

Solution code:
# 解説読んでやり方理解した
from fractions import gcd
from functools import reduce


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


def main():
    N = int(input())
    monsters = list(map(int, input().split(" ")))
    print(get_gcd(monsters))


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
import fractions
#from scipy.misc import comb

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

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

print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

print(a)

Submission status: Accepted

Solution code:
from fractions import gcd
def list_gcd(list):
    c=list[0]
    for i in list:
        c=gcd(c,i)
    return c
n=int(input())
print(list_gcd(list(map(int,input().split()))))

Submission status: Accepted

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

n = ni()
a = na()

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

res = 0
for i in a:
    res = gcd(i, res)

print(res)

Submission status: Accepted

Solution code:
import fractions

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

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

g = []
for index, a in enumerate(A):
  if index == len(A) - 1:
    break
  g.append(fractions.gcd(a, A[index+1]))
  
  
print(min(g))

Submission status: Accepted

Solution code:
def gcd(a,b):
    if b==0:
        return a
    return gcd(b,a%b)
def lcm(a,b):
    g=gcd(a,b)
    return a/g*b

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

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:
def gcd(A, B):
    while B != 0:
        A, B = B, A%B
    return A

N = int(input())
A = [int(i) for i in input().split()]
A.sort(reverse = True)
ans = A[0]
if N == 1:
    print(ans)
    exit()
for i in range(1,N):
    A[i] = gcd(A[i-1], A[i])

print(A[N-1])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import functools

def gcd(num1, num2):
    r = num1 % num2
    while (r > 0):
        num1 = num2
        num2 = r
        r = num1 % num2
    return num2

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

max_koyaku_num = functools.reduce(gcd, a)

print(max_koyaku_num)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
minhp = -1
while 1:
  minhp = min(a)
  minhpi = a.index(minhp)
  for i in range(len(a)):
    if i == minhpi:
      continue
    a[i] = a[i] % minhp
  a = list(filter(lambda x:x!=0, a))
  if min(a) == minhp:
    break
print(minhp)

Submission status: Accepted

Solution code:
import fractions 

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys
from functools import reduce

def gcd(a, b):
    while b:
        a, b = b, a % b
    return abs(a)
    
n, *a = map(int, sys.stdin.read().split())

def main():
    return reduce(gcd, a)

if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Accepted

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


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

Submission status: Accepted

Solution code:
from functools import reduce


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


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


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


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


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

print(gcd_list(a))

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
#ABC118 C

n = int(input())
a = list(map(int,input().split()))
a.sort()
c = a.count(0)
mi = 10**9
while 1:
    for i in range(c+1,n):
        a[i] = a[i] % a[c]
    a.sort()
    c = a.count(0)
    if a[-2] == 0:
        break
print(a[-1])

Submission status: Accepted

Solution code:
def examA():
    A, B = LI()
    if B%A==0:
        ans = A+B
    else:
        ans = B-A
    print(ans)
    return

def examB():
    N, M = LI()
    Flag = [0]*M
    for i in range(N):
        K = LI()
        for j in range(1,K[0]+1):
            Flag[K[j]-1] +=1
    ans = 0
    for i in Flag:
        if i==N:
            ans +=1
    print(ans)
    return

def gcd(x,y):
    if y==0:
        return x
    while(y!=0):
        x, y = y,x%y
    return x
def examC():
    N = I()
    A = LI()
    cur = A[0]
    for i in range(N-1):
        cur = gcd(cur,A[i+1])
    ans = cur
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examC()

Submission status: Accepted

Solution code:
import fractions

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

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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


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

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

Submission status: Accepted

Solution code:
N=int(input())
A=list(map(int,input().split()))
while len(A)>=2:
    A=sorted(A,reverse=True)
    while 1:
        if not A[-1]:
            A.pop()
        else:
            for i in range(len(A)-1):
                A[i]%=A[-1]
            break
print(A[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
"""
import math
n=int(input())
a=list(map(int,input().split()))
m1=min(a)

def a_gcd(t,y):
    return math.gcd(t,y)

if m1==1:
    print(m1)
    exit()
for i in range(n):
    m1=a_gcd(m1,a[i])
    if m1==1:
        break

print(m1)
"""
import fractions
n=int(input())
a=list(map(int,input().split()))
m1=min(a)

def a_gcd(t,y):
    return  fractions.gcd(t,y)

if m1==1:
    print(m1)
    exit()
for i in range(n):
    m1=a_gcd(m1,a[i])
    if m1==1:
        break

print(m1)

Submission status: Accepted

Solution code:
import sys
import math
import itertools
stdin = sys.stdin
mod = 10**9 + 7

ns = lambda: stdin.readline().rstrip()
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
sa = lambda h: [list(map(int, stdin.readline().split())) for i in range(h)]
#a,bの最大公約数
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


n = ni()
a = na()

ans = a[0]

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

Submission status: Accepted

Solution code:
# ABC118c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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


def solve(l):
    m = min(l)
    nl = list()
    for i in l:
        if i % m != 0:
            nl.append(i % m)
    nl.append(m)
    # print(nl)
    if len(nl) == 1:
        return m
    return solve(nl)


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

A.sort()

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

print(ans)

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
def input():
    return sys.stdin.readline().rstrip()

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

if __name__ == '__main__':
    main()

Submission status: Accepted

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


def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    ans = A[0]
    for a in A:
        ans = fractions.gcd(ans, a)
    print(ans)

    
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

import functools
import fractions
gcd=functools.reduce(fractions.gcd,A)
print(gcd)

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()))
A=[int(i) for i in input().split()]

m=0
for a in A:
    m=gcd(a,m)
print(m)

Submission status: Accepted

Solution code:
import numpy as np
N=int(input())
# A=list(map(int,input().split()))
A=[int(i) for i in input().split()]
A=np.array(sorted(A))

while np.any(A[:-1]>0):
    try:
        m=sorted(list(A[A>0]))[0]
        A=list(A[1:]%m)
        A.append(m)
        A=np.array(A)

    except:
        continue
print(m)

Submission status: Accepted

Solution code:
import fractions, functools
input()
print(functools.reduce(fractions.gcd, (int(i) for i in input().split())))

Submission status: Accepted

Solution code:
import functools

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


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


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

Submission status: Accepted

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

Submission status: Accepted

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

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

g = a[0]
for n in a:
    g = gcd(g, n)

print(g)

Submission status: Accepted

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

while True:
    min_num = min(a)
    min_ind = a.index(min_num) 
    a = [n % min_num for n in (a[:min_ind] + a[min_ind+1:]) if n % min_num != 0]
    if a == []:
        print(min_num)
        exit()
    a.append(min_num)

Submission status: Accepted

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

min_ind = a.index(min(a))

while True:
    min_num = min(a)
    min_ind = a.index(min_num) 
    a = [n % min_num for n in (a[:min_ind] + a[min_ind+1:]) if n % min_num != 0]
    if a == []:
        print(min_num)
        exit()
    a.append(min_num)

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

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


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

ans = monsters[0]
for i in range(1, monster_count):
    ans = get_kouyaku(ans, monsters[i])

print(ans)

Submission status: Accepted

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

while True:
    m=min(A)
    A=[i%m for i in A]
    A.append(m)
    A=[i for i in A if i!= 0]
    if len(A)==1:
        break

print(max(A))

Submission status: Accepted

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

while True:
    MOD = min(A)
    for i in range(N):
        A[i] = A[i]%MOD if A[i]%MOD != 0 else A[i]
    if MOD == min(A):
        break
print(MOD)

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(map(int, input().split()))
print(gcd_list(monster))

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:
N = int(input())
A = [inp for inp in map(int, input().split())]

a = A[0]
for i in range(1, N):
  b = A[i]
  while b != 0:
    a, b = b, a%b
    
print(a)

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

print(ans)

Submission status: Accepted

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

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

print(x)

Submission status: Accepted

Solution code:
def main():
	# n,k = map(int,input().split())
	n = int(input())
	# s = str(input())
	h = list(map(int,input().split()))
	# l = [list(map(int, input().split())) for _ in range(n)]
	# s = list(s)
	
	from fractions import gcd

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


if __name__ == '__main__':
	main()

Submission status: Accepted

Solution code:
import bisect
import cmath
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(10 ** 9)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7
# MOD = 998244353

N = int(sys.stdin.buffer.readline())
A = list(map(int, sys.stdin.buffer.readline().split()))

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

Submission status: Accepted

Solution code:

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


from fractions import gcd
from functools import reduce

print(reduce(gcd, A))

Submission status: Accepted

Solution code:
from fractions import gcd
n = int(input())
A = list(map(int, input().split()))
ans = A.pop()
for a in A:
	ans = gcd(ans, a)
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

print(reduce(gcd,A))

Submission status: Accepted

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

for i in range(1,n):
    while a[i]%a[0] != 0:
        a[0],a[i] = a[i]%a[0],a[0]
else:
    ans = a[0]

print(ans)

Submission status: Accepted

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

a.sort()
for i in range(1,n):
    while a[i]%a[0] != 0:
        a[0],a[i] = a[i]%a[0],a[0]
else:
    ans = a[0]

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd


def solve():
    N, *A = map(int, open(0).read().split())
    
    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:
import fractions

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

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

Submission status: Accepted

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

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

A = sorted(A)[::-1]

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

print(ans)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
# 複数の整数の最大公約数を求める
import fractions
from functools import reduce
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)

def solve(N: int, A: "List[int]"):
    print(gcd_list(A))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, A)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:

from functools import reduce
from fractions import gcd

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

print(reduce(gcd, A))

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
amin=min(a)
while len(a)>1:
    s=min(a)
    a = list(map(lambda x:x%s, a))
    a = [i for i in a if i > 0]+[s]
print(a[0])

Submission status: Accepted

Solution code:
from fractions import gcd as a
n=int(input())
f=1
for i in map(int,input().split()):
  if f:
    g=i
    f=0
  else:
    g=a(g,i)
print(g)

Submission status: Accepted

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

Submission status: Accepted

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

while True:
  num = sorted(num)
  for j in range(N):
    min = num[j]
    if min != 0:
      break
  for i in range(j+1,N):
    num[i] -= (num[i]//min)*min

  if num[N-1] == sum(num):
    break

print(sum(num))

Submission status: Accepted

Solution code:
n, *a = map(int, open(0).read().split())

def gcd(p, q):
    if p % q == 0:
        return q
    else:
        return gcd(q, p % q)
cd = a[0]
for i in range(n - 1):
    cd = gcd(cd, a[i + 1])
print(cd)

Submission status: Accepted

Solution code:
def main():
    N, *A = map(int, open(0).read().split())
    b = None
    for a in A:
        if b is None:
            b = a
            continue
        while b:
            a, b = b, a % b
        b = a
    print(a)
    return


main()

Submission status: Accepted

Solution code:
from functools import reduce


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


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


def main():
    N, *A = map(int, open(0).read().split())
    print(gcd_n(A))
    return


main()

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 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 count_zero(arr):
    cnt = 0
    for a in arr:
        if a == 0:
            cnt += 1

    return cnt
def main():
    N = I()
    a = LI()
    min_element = inf
    min_ix = -1
    while True:
        prev_min = min_element
        for i in range(N):
            if 0 < a[i] < min_element:
                min_element = a[i]
                min_ix = i
        if count_zero(a) == N-1:
            break
        for i in range(N):
            if i == min_ix:
                continue
            a[i] %= min_element
    print(prev_min)
main()

Submission status: Accepted

Solution code:
n = int(input())
A = list(map(int,input().split()))
def gcd(x,y):
    a = max(x,y)
    b = min(x,y)
    while b!=0:
        a,b=b,a%b
    return a
ans = A[0]
for i in range(n-1):
    ans = gcd(ans,A[i+1])
print(ans)

Submission status: Accepted

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

import fractions as math
N = int(input())
monsters = list(map(int, input().split()))
for i in range(N):
    if i != 0:
        monsters[i] = math.gcd(monsters[i - 1], monsters[i])
print(monsters[N - 1])

Submission status: Accepted

Solution code:
def gcd(x, y):
    a = x
    b = y
    while True:
        r = a % b
        if r == 0:
            break
        a = b
        b = r
    return b


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

B = sorted(A)
b = B[0]

for i in range(1, N):
    b = gcd(b, B[i])

print(b)

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

Submission status: Accepted

Solution code:
import fractions

def main():
    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)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
N = int(input())
li = list(map(int,input().split()))
HPmin = 0
sum = 0
while sum != N-1 :
    li.sort()
    for i in range(sum + 1,N) :
        li[i] %= li[sum]
    HPmin = li[0]
    sum = 0
    for i in range(N) :
        if li[i] == 0 :
            sum+=1
li.sort()
print(li[N-1])

Submission status: Accepted

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

while len(A)>1:
    A0=[A[0]]
    A=[i%A0[0] for i in A[1:] if i%A0[0]!=0]
    A=A0+A
    A.sort()

print(A[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
n = int(input())
hp = [int(x) for x in input().split()]
for i in range(n-1):
  a = hp[i]
  b = hp[i+1]
  r = a % b
  if r == 0:
    ans = b
    continue
  while r != 0:
    ans = r
    a = b
    b = r
    r = a % b
  hp[i+1] = ans
print(ans)
a = b * i + r

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
N=int(input())
ls=[int(s) for s in input().split()]
a=0
for e in ls:
  a=fractions.gcd(a,e)
print(a)

Submission status: Accepted

Solution code:
from functools import reduce
from fractions import gcd

N = map(int, input().split())
A = 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()))
print(reduce(gcd,A))

Submission status: Accepted

Solution code:
import fractions
def gcdcheck(a, b):
    return fractions.gcd(a, b)

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

ans = monster_list[0]
for i in range(1, n):
    ans = gcdcheck(ans, monster_list[i])

print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())
lista = sorted(list(map(int, input().split())))
length = 2
while length>1:
    #print(length)
    #print(lista)
    for n in range(1, length):
        lista[n] = lista[n]%lista[0]
    #print(lista)
    lista = list(set(lista))
    lista.sort()
    if lista[0] == 0:
        lista.remove(0)
    #print(lista)
    length = len(lista)
print(lista[0])

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

print(gcd_list(a))

Submission status: Accepted

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


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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
import numpy as np
N = int(input())
A = [int(x) for x in input().rstrip().split()]
A = np.array(A, np.int64)
while len(A) > 1:
    A = A[np.nonzero(A)]
    A = np.sort(A)
    minA = A[0]
    A %= minA
    A[0] = minA
A = A[np.nonzero(A)]
print(A[0])

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A, np.int64)
while len(A) > 1:
    A = A[np.nonzero(A)]
    A = np.sort(A)
    minA = A[0]
    A %= minA
    A[0] = minA
A = A[np.nonzero(A)]
print(A[0])

Submission status: Accepted

Solution code:
import fractions

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
gcd = a[0]
def Euclid(n1,n2):
    if n1 % n2 == 0:
        return n2
    return Euclid(n2,n1%n2)
for i in range(1,n):
    gcd = Euclid(gcd,a[i])
print(gcd)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
gcd = a[-1]
def Euclid(n1,n2):
    if n1 % n2 == 0:
        return n2
    return Euclid(n2,n1%n2)
for i in range(n-1):
    gcd = Euclid(gcd,a[(-1)*(i+2)])
print(gcd)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
a.sort()
gcd = a[-1]
def Euclid(n1,n2):
    if n1 % n2 == 0:
        return n2
    return Euclid(n2,n1%n2)
for i in range(n-1):
    gcd = Euclid(gcd,a[(-1)*(i+2)])
print(gcd)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

print(reduce(fractions.gcd, A))

Submission status: Accepted

Solution code:
import heapq

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

def battle(a,b):
    # x = attack, y = defense
    x, y = min(a,b),max(a,b)
    x -= y * (x // y)
    return x,y

while len(A) != 1:
    a = heapq.heappop(A)
    b = heapq.heappop(A)
    
    while a != 0 and b != 0: a,b = battle(a,b)
    heapq.heappush(A, a) if a != 0 else heapq.heappush(A, b)

print(-A[0])

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

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

#最大公約数
import fractions
temp = a[0]
for i in a[1::]:
    temp = fractions.gcd(temp,i)
    if temp==1:
        break
print(temp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

N = INT()
A = MAP()

while True:
	min_a = min(A)
	cnt = 0
	for i in range(N):
		if A[i] % min_a != 0:
			cnt += 1
			A[i] %= min_a
		elif A[i] % min_a == 1:
			break
	if cnt==0: break
print(min_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(a)
print(reduce(gcd, a))