Problem:


Score : 300 points

Problem Statement

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

Initially, the health of Monster i is A_i.

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

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

A random alive monster attacks another random alive monster.

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

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

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

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

Sample Input 1

4
2 10 8 40

Sample Output 1

2

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

Sample Input 2

4
5 13 8 1000000000

Sample Output 2

1

Sample Input 3

3
1000000000 1000000000 1000000000

Sample Output 3

1000000000



Sample input:
4
2 10 8 40


Sample output:
2

Submission status: Accepted

Solution code:
import numpy as np
from copy import deepcopy

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

## 一番小さい数のmodを取ることを繰り返す
## (一番体力の少ないものが可能な限り攻撃する)
## set使わなくても.indexは最初のインデックスを取得してくれるわ

def ABC118(lst):
  if len(lst) == 1:
    return lst[0]
  new_lst = deepcopy(list(set(lst)))
  min_idx = new_lst.index(min(new_lst))
  min_var = new_lst[min_idx]
  new_lst = [(new_lst[i] % min_var) for i in range(len(new_lst)) if i != min_idx]
  new_lst.append(min_var)
  new_lst = [x for x in new_lst if x != 0]
  return(ABC118(new_lst))
  
ans = ABC118(A)
print(ans)

Submission status: Accepted

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

result = A
while True:
    result = list(set(result))
    result.sort()
    if min(result) == 0:
        result.remove(0)
    tmp_min = min(result)
    #print(result)
    if len(result) == 1:
        break
    result =[r % tmp_min for r in result[1:]]
    #print(result)
    if max(result) == 0:
        result.append(tmp_min)
        break
    result.append(tmp_min)
    #print(result)

print(max(result))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

Submission status: Accepted

Solution code:
from fractions import gcd

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

current = A[0]
for index in range(1, N):
    current = gcd(current, A[index])

print(current)

Submission status: Accepted

Solution code:
from fractions import gcd

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

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()))
while True:
  min_A = min(A)
  A = list(map(lambda x: x % min_A, A))
  A = [x for x in A if x != 0]
  A.append(min_A)
  if len(A)==1:
    break

print(min_A)

Submission status: Accepted

Solution code:
# C - Monsters Battle Royale
# https://atcoder.jp/contests/abc118/tasks/abc118_c

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

while len(A) != 1:

    # minimum number of A
    minA = min(A)

    # next round A
    nA = set()
    nA.add(minA)

    for Ai in A:
        if Ai == minA: continue
        if Ai % minA != 0:
            nA.add(Ai%minA)

    # update for next round
    A = nA

print '{}'.format( list(A)[-1])

Submission status: Accepted

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

while len(A) != 1:
    minA = min(A)

    nextA = set()
    for Ai in A:
        if Ai == minA:
            nextA.add(Ai)
            continue
        if Ai % minA != 0:
            nextA.add(Ai%minA)

    A = nextA

A = list(A)
print '{}'.format(A[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

now_gcd = A[0]
for a in A[1:]:
  now_gcd = gcd(now_gcd, a)
  if now_gcd == 1:
    break
print(now_gcd)

Submission status: Accepted

Solution code:
import functools

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

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

ans = functools.reduce(gcd, a)
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())
a = list(map(int, input().split()))

print(gcd_list(a))

Submission status: Accepted

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

while len(A) >= 2: #残りの数が1になったら終わり
  if A[0] == 1: break
  #余りが出る場合は、左側の数字と余りを入れ替える
  rem = A[1] % A[0] #余り
  if rem != 0: A[0], A[1] = rem, A[0]
  #余りが0の場合、そいつは下位互換なので要らない？
  else: del A[1]

print(A[0])

Submission status: Accepted

Solution code:
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  if b==0:
    return a
  else:
    return gcd(b,a%b)
 
n=int(input())
arr=list(map(int,input().split()))
tmp=gcd(arr[0],arr[1])
for i in range(1,n):
  tmp=gcd(tmp,arr[i])
print(tmp)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N=int(input())
A = list(map(int, input().split()))
A.sort()
sa = []
for i in range(N-1):
    diff = A[i+1]-A[i]
    if diff > 0:
        sa.append(diff)
sa.sort()

if len(sa)>=2:
    score = sa[1] - sa[0]
    if score <= 0:
        print(sa[0])
    else:
        dai = max(score, sa[0])
        sho = min(score, sa[0])
        while dai-sho > 0:
            dai, sho = sho, dai-sho
            if dai <= sho:
                dai, sho = sho, dai
        print(dai-sho if dai-sho > 0 else sho)
elif len(sa) == 1:
    dai = max(A[0], sa[0])
    sho = min(A[0], sa[0])
    while dai-sho > 0:
        dai, sho = sho, dai-sho
        if dai <= sho:
            dai, sho = sho, dai
    print(dai-sho if dai-sho > 0 else sho)
else:
    print(A[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

input()

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

Submission status: Accepted

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

while len(A) > 1:
    minA = min(A)
    tempA = []
    tempA.append(minA)
    for a in A:
        mod = a % minA
        if mod > 0:
            tempA.append(mod)
    A = tempA

print(A[0])

Submission status: Accepted

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

while len(A) > 1:
    minA = min(A)
    tempA = set()
    tempA.add(minA)
    for a in A:
        mod = a % minA
        if mod != 0:
            tempA.add(mod)
    A = tempA

print(list(A)[0])

Submission status: Accepted

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

while len(A) > 1:
    minA = min(A)
    tempA = []
    tempA.append(minA)
    for a in A:
        mod = a % minA
        if mod != 0:
            tempA.append(mod)
    A = tempA

print(A[0])

Submission status: Accepted

Solution code:
def yuk(a, b):
    ans = int(a / b)
    amari = a % b
    if amari != 0:
        ans = yuk(b, amari)
    else:
        ans = b
    return ans

N = int(input())
alst = list(map(int, input().split()))
ans = alst[0]
for i in range(1, N):
    if ans > alst[i]:
        ans = yuk(ans, alst[i])
    else:
        ans = yuk(alst[i], ans)
print(ans)

Submission status: Accepted

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


def lcm(x, y):
    while y != 0:
        z = x % y
        x = y
        y = z
    return x


prev = None
for a in alist:
    if prev is None:
        prev = a
        continue
    prev =lcm(prev, a)

print(prev)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
N = int(input())

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

tmp = monster_list[0]

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

for i in range(len(monster_list)):
    if i == 0:
        continue
    else:
        tmp = gcd(tmp,monster_list[i])
 

print(tmp)

Submission status: Accepted

Solution code:
N = int(input())

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

tmp = monster_list[0]

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

for i in range(len(monster_list)):
    if i == 0:
        continue
    else:
        if(tmp >= monster_list[i]):
            tmp = gcd(tmp,monster_list[i])
        else:
            tmp = gcd(monster_list[i],tmp)
print(tmp)

Submission status: Accepted

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

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

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


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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

N = int(input())
A = reduce(fractions.gcd, map(int, input().split()))
print(A)

Submission status: Accepted

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

while N > 1:
    a = A[0]
    b = A[1] % a
    if b == 0:
        A.pop(1)
        N -= 1
    else:
        A[1] = a
        A[0] = b

print(A[0])

Submission status: Accepted

Solution code:
def main():
  if 'get_ipython' not in globals():  
    # For Subsession
    N = int(input())
    A = list(map(int, input().split()))
  else:
    # For Test
    # N = 4
    # A = [2,10,8,40]
    # N = 4
    # A = [5,13,8,1000000000]
    N = 3
    A = [1000000000,1000000000,1000000000]

  while len(A)>1:
    minA = min(A)
    tempA = []
    tempA.append(minA)
    for row in A:
      wk = row % minA
      if wk > 0:tempA.append(wk)
    A = tempA
  print(A[0])
  
main()

Submission status: Accepted

Solution code:
N = int(input())
As = list(map(int, input().split()))
smallest = min(As)

while True:
    l = []
    for i in range(len(As)):
        if As[i] > smallest and As[i]%smallest > 0:
            l.append(As[i]%smallest)
        elif As[i]== smallest :
            l.append(As[i])
        
    if l == As:
        smallest = min(As)
        break
    else:
        As = l
        smallest = min(As)

print(smallest)

Submission status: Accepted

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


def euclid(v1, v2):
    if v2 == 0:
        return v1
    elif v1 > v2:
        return euclid(v2, v1 % v2)
    else:
        return euclid(v1, v2 % v1)


out = A[0]
for A_i in A[1:]:
    out = euclid(out, A_i)
print(out)

Submission status: Accepted

Solution code:
n = int(input())

zombies = [int(c) for c in input().split()]


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


m = zombies[0]
for i in range(1, len(zombies)):
    m = gcd(m, zombies[i])

print(m)

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)


def gcd_arr(a):
    ans = a[0]
    for i, a_i in enumerate(a):
        ans = gcd(ans, a_i)
    return ans

print(gcd_arr(A))

Submission status: Accepted

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

ans = 10 ** 10
while min(A) != ans:
    ans = min(A)
    for i, a_i in enumerate(A):
        if a_i > ans:
            A[i] = a_i % ans
            if A[i] == 0:
                del A[i]

print(ans)

Submission status: Accepted

Solution code:
input()

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

while len(A) != 1:
    A.sort()
    for i, a in enumerate(A):
        if i + 1 < len(A) and A[i + 1] >= a > 0:
            A[i + 1] %= a
    A = [a for a in A if a > 0]

print(min(A))

Submission status: Accepted

Solution code:
n = int(input())
hps = list(map(int, input().split()))
m = min(hps)
def gojo(a, b):
  if b == 0:
    return a
  else:
    return gojo(b, a % b)
res = m
for hp in hps:
  res = gojo(hp, res)
print(res)

Submission status: Accepted

Solution code:
n = int(input())
hps = list(map(int, input().split()))
m = min(hps)
def gojo(a, b):
  if b == 0:
    return a
  else:
    return gojo(b, a % b)
res = m
for hp in hps:
  res = gojo(max(res, hp),min(res, hp))
print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
class NC:
  """ 整数計算 """

  @staticmethod
  def gcd(x, y, *z):
    """ 最大公約数 """

    from fractions import gcd as _gcd

    if z:
      from functools import reduce
      return reduce(_gcd, (x, y) + z)
    else:
      return _gcd(x, y)

    @staticmethod
    def lcm(x, y, *z):
      """ 最小公倍数 """

      from fractions import gcd as _gcd

      def _lcm(a, b):
        return a * b // _gcd(a, b)
      if z:
        from functools import reduce
        return reduce(_lcm, (x, y) + z)
      else:
        return _lcm(x, y)
          
def main():
  _ = int(input())
  ts = list(map(int, input().split()))
  nc = NC()
  g = nc.gcd(*ts)
  print(g)
main()

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
min_ans=0
nxt=a
while len(nxt)!=0:
    min_ans=min(nxt)
    nxt=[]
    for v in a:
        if v%min_ans!=0:
            nxt.append(v%min_ans)
print(min_ans)

Submission status: Accepted

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

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 fractions import*
from functools import*
n,*a=map(int,open(0).read().split())
print(reduce(gcd,a))

Submission status: Accepted

Solution code:
# gcdの匂いがする

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


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


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

print(ans)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

print(reduce(fractions.gcd, As))

Submission status: Accepted

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


def mod_2(num,mod):
    a = num%mod 
    if a ==0:
        a = mod
    return a
m = min(A)
def min_mod(minimum,A_list):
    if all([A_list[j]==minimum for j in range(len(A_list))]):
        return minimum
        
    A_list = [mod_2(A_list[i],minimum) for i in range(len(A_list)) ]
    minimum = min(A_list)
    return min_mod(minimum,A_list)
    
print(min_mod(m,A))

Submission status: Accepted

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

while True:
    A.sort()
    B=[A[0]]


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

    if len(B)==1:
        print(B[0])
        break
    else :
        A = B

Submission status: Accepted

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

a.sort()
a = np.array(a)
min_index = a.argmin()

while True:
    damaged = a % a[min_index]
    nonzero_index = damaged.nonzero()
    nonzero = damaged[nonzero_index]
    if nonzero.size == 0:
        break
    target = nonzero.argmin()
    min_index = nonzero_index[0][target]
    a[min_index] = nonzero[target]
print(a[min_index])

Submission status: Accepted

Solution code:
#9:54〜10:29
N=int(input())
A=sorted(map(int,input().split()))
while len(A) != 1:
	B_nonzeros=[A[0]]
	for n in range(len(A)):
		i = A[n]%A[0]
		if i != 0:
			B_nonzeros.append(i)
	B_nonzeros.sort()
	A=B_nonzeros
print(A[0])

Submission status: Accepted

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

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

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

Submission status: Accepted

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

def battle(s):
  tmp = [i for i in s if i > 0]
  if len(tmp) == 1:
    return tmp[0]
  p = min(tmp)
  f = False
  for i in range(N):
    if not f and s[i] == p:
      f = True
    else:
      s[i] = s[i] % p
  return battle(s)

print(battle(S))

Submission status: Accepted

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

while True:
    A = list(set(A))
    A.sort()
    if 0 in A:
        A.remove(0)
    if len(A) == 1:
        print(A[0])
        exit()

    A0 = A[0]
    i = 1
    for a in A[1:]:
        A[i] = a % A0
        i += 1

Submission status: Accepted

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

ans = 2 ** 30

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

tmp = A[0]
for a in A[1:]:
    tmp = GCD(a,tmp)
    
print(tmp)

Submission status: Accepted

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


def gcd(n, m):
    if n < m:
        temp = n
        n = m
        m = temp
    
    def ecd(n, m):
        if n % m == 0:
            return m
        else:
            temp = n % m
            a = ecd(m, temp)
        return a
           
    return ecd(n, m)

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

Submission status: Accepted

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

As = sorted(A)
As = [a%As[0] if a%As[0] != 0 else As[0] for a in As]
As = sorted(As)

def judge(tmp_one, tmp_two):
    flg = 1

    while flg:
        if tmp_two%tmp_one == 0:
            tmp_two = tmp_one
        else:
            tmp_two = tmp_two%tmp_one

        if tmp_one%tmp_two == 0:
            tmp_one = tmp_two
        else:
            tmp_one = tmp_one%tmp_two
        if tmp_one == tmp_two:
            flg = 0

    return tmp_one

tmp_one = As[0]
for i in range(1, N):
    if i == N - 1:
        tmp_two = As[i]
    elif As[i] != As[0]:
        tmp_two = As[i]
        break

ans = judge(tmp_one, tmp_two)
print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import fractions
from functools import reduce
from sys import stdin
N = int(stdin.readline().rstrip())
A = [int(_) for _ in stdin.readline().rstrip().split()]
def gcd_list(numbers):
    return reduce(fractions.gcd, numbers)
print(gcd_list(A))

Submission status: Accepted

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

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

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

print(ans)

Submission status: Accepted

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

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

ans = alist[0]
for a in alist[1:]:
  if a <= ans:
    ans = gcd(ans, a)
  else:
    ans = gcd(a, ans)
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

for i in k:
    ans = gcd(ans, i)

print(ans)

Submission status: Accepted

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
def euclid(a,b):
  x=max(a,b)
  y=min(a,b)
  z=x%y
  if z!=0:
    return euclid(y,z)
  else:
    return y
g=euclid(A[0],A[1])
for i in range(2,len(A)):
  g=euclid(A[i],g)
print(g)

Submission status: Accepted

Solution code:
n=int(input())
l=list(map(int,input().split()))
ans=l[0]
for a in l:
  while a>0:
    ans%=a
    a,ans=ans,a
print(ans)

Submission status: Accepted

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


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


def list_lcm(number_list):
    lcm_number = 1
    for j in number_list:
        lcm_number = lcm(lcm_number, j)

    return lcm_number


def list_gcd(number_list):
    gcd_number = number_list[0]
    for i in number_list:
        gcd_number = gcd(gcd_number, i)

    return gcd_number


if __name__ == '__main__':
    n = input()
    number_list = list(map(int, input().split()))
    print(list_gcd(number_list))

Submission status: Accepted

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

monsters = A[:]
while True:
    a_min = min(monsters)
    monsters = [m % a_min for m in monsters if m % a_min != 0]
    if len(monsters) == 0:
        print(a_min)
        break
    else:
        monsters.append(a_min)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

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

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

print(gcd(A))

Submission status: Accepted

Solution code:
import fractions
import functools


_ = input()
A = list(map(int, input().split()))
print(functools.reduce(fractions.gcd, A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

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

for i in range(1,N):
  GCD = alg_gcd(GCD,A[i])
print(GCD)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import fractions

N =int(input())
lives = [int(i) for i in input().split()]
gcd_value = lives[0]

for i in range(1,len(lives)) :
    gcd_value = fractions.gcd(gcd_value, lives[i])

print(gcd_value)

Submission status: Accepted

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

m = min(A)

while True:
  flag = False
  temp = m
  for i in range(len(A)):
    if A[i] % m > 0 and (A[i] % m) < temp:
      temp = A[i] % m
      flag = True
  if flag == False:
    break
  else:
    m = temp
print(m)

Submission status: Accepted

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

min_idx = None
for i, a in enumerate(A):
    if min_idx is None or A[min_idx] > a:
        min_idx = i

while 1:
    next_min_idx = None

    for i, a in enumerate(A):
        if min_idx == i: continue
        A[i] = a % A[min_idx]

        if A[i] > 0:
            if next_min_idx is None or A[next_min_idx] > A[i]:
                next_min_idx = i

    if next_min_idx is None:
        print(A[min_idx])
        exit()

    min_idx = next_min_idx

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
def euc(x,y):
  x,y=max(x,y),min(x,y)
  if x%y==0:
    return y
  else:
    return euc(y,x%y)
k=a[0]
for i in range(1,n):
  k=euc(a[i],k)
print(k)

Submission status: Accepted

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

def gcd(p,q):
    if q == 0:
    	return p
    return gcd(q, p % q)


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

Submission status: Accepted

Solution code:
def solve(m_list):
    m_val = m_list[0]
    for i in m_list:
        m_val = min(m_val,gcd(m_val,i))
    return m_val

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

def main():
    n = int(input())
    m_list = list(map(int,input().split()))

    ans = solve(m_list)
    print(ans)

main()

Submission status: Accepted

Solution code:
def solve(m_list):
    min_val = m_list[0]
    # time O(N log(A))
    for m in m_list:
        min_val = min(min_val, gcd(min_val, m))
    return min_val


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


def main():
    n = int(input())
    m_list = list(map(int, input().split()))

    ans = solve(m_list)
    print(ans)


main()

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

Submission status: Accepted

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


def euclid_gcd(a: int, b: int):
    if a < b:
        return euclid_gcd(b, a)
    r = a % b
    while r != 0:
        a = b
        b = r
        r = a % b
    return b


def solve(N: int, A: "List[int]"):
    lastGCD = A[0]
    for i in range(1, N):
        lastGCD = euclid_gcd(lastGCD, A[i])
    print(lastGCD)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
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:
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a

N = int(input())
A = [int(i) for i in input().split()]
g = A[0]
for n in range(1,N):
    g = gcd(g,A[n])

print(g)

Submission status: Accepted

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

for i in range(N-1):
    a = [A[i], A[i+1]]
    a.sort(reverse=True)
    while True:
        tmp = a[0] % a[1]
        if tmp == 0:
            A[i+1] = a[1]
            break
        a[0], a[1] = a[1], tmp

print(a[1])

Submission status: Accepted

Solution code:
n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for i in a[1:]:
	if ans > i:
		ans,i=i,ans
	while i%ans!=0:
		i,ans=ans,i%ans
	if ans ==1:
		print(1)
		break
else:
	print(ans)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
a = list(map(int, input().split()))
b = [1] * N
c = min(a)

while max(b) != 0:
    for i in range(N):
        b[i] = a[i] % c
    for i in range(N):
        if b[i] != 0:
            c = min(c, b[i])
print(c)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
m = 10**9
while m >0:
    for i in A:
        if i != 0 and i <= m:
            m = i
    A = [k%m for k in A]
    if max(A) == 0:
        break
    A += [m]
print(m)

Submission status: Accepted

Solution code:
def maxDivisor(divisor, divided):
    '''最大公約数を返す関数'''
    while(True):
        rest = divided % divisor
        if rest == 0:
            return divisor
        else:
            divided = divisor
            divisor = rest


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

inf = 1 * 10**9
ans = inf
for i in range(len(A)):
    if i == len(A) - 1:
        break
    else:
        ans = min(ans, maxDivisor(A[i], A[i+1]))

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.sort(reverse=1)

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

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(i) for i in input().split()]
a.sort()

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

ans = tmp
print(ans)

Submission status: Accepted

Solution code:
import fractions
import functools

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

print(functools.reduce(fractions.gcd, a))

Submission status: Accepted

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

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

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

for i in A[2:]:
    x = gcd(x,i)

print(x)

Submission status: Accepted

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

def gojo(num1, num2):
	if num2 > num1:
		num1, num2 = num2, num1
	if num2 == 0:
		return num1
	else:
		num3 = num1 % num2
		return gojo(num2, num3)
counter = gojo(a[0], a[1])
for i in range(n - 1):
	checker = gojo(a[i], a[i + 1])
	if checker < counter:
		counter = checker

print(counter)

Submission status: Accepted

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

def gcd(x, y):
    if y == 0:
        return x
    else:
        return gcd(y, x % y)
        
x = gcd(A[0], A[1])
for i in range(2, N):
    x = gcd(x, A[i])

print(x)

Submission status: Accepted

Solution code:
import math
N = int(input())
values = [int(i) for i in input().split()]
def gcd(a, b):
	while b:
		a, b = b, a % b
	return a
c = values[0]
for i in range(N):
    c = gcd(c,values[i])
print(c)

Submission status: Accepted

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

def gcd(x,y):
    d = 0
    if max(x,y) == x:
        x,y = y,x
    while True:
        if y%x == 0:
            return x
        else:
            d = y%x
            y,x = x,d

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

Submission status: Accepted

Solution code:
n=int(input())
X=list(map(int,input().split()))
x=X[0]
def gcd(a,b):
    while b:
        a,b=b,a%b
    return a


for i in range(1,n):
    x=gcd(x,X[i])
if x!=1:
    print(x)
else:
    print(1)