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 sys

input = sys.stdin.readline

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

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

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

Submission status: Accepted

Solution code:
import sys

input = sys.stdin.readline

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

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

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

Submission status: Accepted

Solution code:
import functools
import fractions

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

Submission status: Accepted

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

while(len(mons) > 1):
    mons = sorted([mons[0]] + list(map(lambda x:x%mons[0], mons[1:])))
    while mons[0]==0: del mons[0]
print(mons[0])

Submission status: Accepted

Solution code:
from fractions import gcd

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

g = 0

for i in range(n):
    g = gcd(g,x[i])

print(g)

Submission status: Accepted

Solution code:
from fractions import gcd

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

g=0

for i in range(n):
    g=gcd(g,x[i])

print(g)

Submission status: Accepted

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

A.sort()

mins = A[-1]
for i in range(N):
    s = fractions.gcd(A[i], A[0])
    if s > 0 and s < mins:
        mins = s
print(min(mins,A[0]))

Submission status: Accepted

Solution code:
def gcd(x, y):
    if x < y:
        x = x ^ y
        y = x ^ y
        x = x ^ y
    div = x % y
    while div != 0:
        x = y
        y = div
        div = x % y
    return y

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

res = As[0]
for i in range(1, N):
    res = gcd(res, As[i])

print(res)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
from functools import reduce

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

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

print(reduce(gcd, A))

Submission status: Accepted

Solution code:
N = int(input())

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

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

a = A[0]

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

print(a)

Submission status: Accepted

Solution code:
from fractions import gcd

N, *A = map(int, open(0).read().split())

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

Submission status: Accepted

Solution code:
n=int(input())
a=[int(i) for i in input().split()]
while len(a)>1:
    c=[]
    d=min(a)
    for i in range(len(a)):
        if a[i]!=d:
            div=a[i]%d
            if div!=0:
                c.append(div)
    c.append(d)        
    a=c
print(a[0])

Submission status: Accepted

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

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

g = 0
for x in S:
  g = gcd(g, x)

print(g)

Submission status: Accepted

Solution code:
from functools import reduce

N=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
    while b!=0:
        a,b=b,a%b
    return a
print(reduce(gcd,A))

Submission status: Accepted

Solution code:
from functools import reduce

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

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

print(reduce(gcd, a))

Submission status: Accepted

Solution code:
from __future__ import print_function
# import numpy as np
# import numpypy as np
import sys
import math
import string
import fractions
import re
import array
import copy
import functools
import operator

import collections
import itertools
import bisect
import heapq


from heapq import heappush
from heapq import heappop

# from itertools import accumulate
# from collections import deque
import random

def eprint(*args, **kwargs):
    print(*args, file=sys.stderr, **kwargs)


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

    eprint("=======================")
    while True:
        xx = min([x for x in l if x > 0])
        # eprint("min_index: "+str(min_index))
        eprint("xx: "+str(xx))
        flag = 0
        for i in range(len(l)):
            if l[i] == xx and flag == 0:
                flag=1
            else:
                l[i] = l[i]%xx

        # eprint(l)
        if all(x==l[0] for x in l):
            # eprint(l)
            print(l[0])
            return 0
        if 1 in l:
            print(1)
            return 0
        if sum(l)==xx:
            print(xx)
            return 0
        eprint("=======================")

    print(xx)
    return 0


if __name__ == '__main__':
    main()

Submission status: Accepted

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

while len(A) > 1:
    A = sorted(A)
    min_A = A[0]
    next_A = [min_A]
    for i in range(1, len(A)):
        A[i] %= min_A
        if A[i] != 0:
            next_A.append(A[i])
    A = next_A

print(A[0])

Submission status: Accepted

Solution code:
def sub():
    N = int(input())
    As = [int(e) for e in input().split()]
    ans = None
    while True:
        # print(As)
        a_min = min(As)
        As = [a % a_min for a in As]
        As = [a for a in As if a != 0]
        if len(As) == 0:
            ans = a_min
            break
        else:
            As.append(a_min)
    print(ans)

sub()

Submission status: Accepted

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

dp = [0] * n
dp[0] = a[0]

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

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

print(dp[n - 1])

Submission status: Accepted

Solution code:
from fractions import gcd

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

print(g)

Submission status: Accepted

Solution code:
from fractions import gcd

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

g = [0] * (N + 1)
for i in range(N):
    g[i+1] = gcd(g[i], A[i])

print(g[-1])

Submission status: Accepted

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

n=int(input())
hoge=list(map(int,input().split()))
hoge.sort()
for i in range(n-1):
  hoge[i+1]=gcd(hoge[i],hoge[i+1])
  
print(hoge[-1])

Submission status: Accepted

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

    return gcd(b % a, a)


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

g = gcd(xs[0], xs[1])
for x in xs[2:]:
    g = gcd(g, x)

print(g)

Submission status: Accepted

Solution code:
n = int(input())
data = [int(s) for s in input().split()]

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


x = gcd(data[0], data[1])
for i in range(2,n-1):
    x = gcd(x,data[i])
print(x)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
while len(A) >= 2:
  mn = min(A)
  A = [a % mn for a in A]
  A = [a for a in A if a != 0]
  A.append(mn)
print(A[0])

Submission status: Accepted

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

Submission status: Accepted

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

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

def solve(N: int, A: "List[int]"):
    res = A[0]
    B = A[1:]
    for a in B:
        res = gcd(res,a)

    print(res)

# Generated by 1.1.4 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:
from functools import reduce

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

def calc(a, b):
    while True:
        if a > b:
            b, a = a, b
        b = b % a
        if b == 0:
            return a

def main():
    ans = reduce(calc, A)    
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

for i in range(n):
    num = gcd(num, a[i])

print(num)

Submission status: Accepted

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

monsters.sort()  # 昇順
minnum = monsters[0]

cnt = len(monsters)
minidx = 0
while cnt > 1:
    for i in range(cnt - 1, 0, -1):
        monsters[i] = monsters[i] % monsters[0]

        if monsters[i] == 0:
            del monsters[i]

        elif monsters[i] == 1:
            print('1')
            quit()

    workmin = min(monsters)
    minidx = monsters.index(min(monsters))
    monsters[minidx] = monsters[0]
    monsters[0] = workmin

    cnt = len(monsters)

print(monsters[0])

Submission status: Accepted

Solution code:
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
from string import ascii_lowercase
from functools import lru_cache
import sys
sys.setrecursionlimit(10000)
INF = float("inf")
YES, Yes, yes, NO, No, no = "YES", "Yes", "yes", "NO", "No", "no"
dy4, dx4 = [0, 1, 0, -1], [1, 0, -1, 0]
dy8, dx8 = [0, -1, 0, 1, 1, -1, -1, 1], [1, 0, -1, 0, 1, 1, -1, -1]


def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W


def ceil(a, b):
    return (a + b - 1) // b


# aとbの最大公約数
def gcd(a, b):
    if b == 0:
        return a
    return gcd(b, a % b)


# aとbの最小公倍数
def lcm(a, b):
    g = gcd(a, b)
    return a // g * b


def main():
    N = int(input())
    A = list(sorted(list(map(int, input().split()))))

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
from itertools import combinations

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

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

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

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:
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 = list(map(int, input().split()))

# 最大公約数が答え

import fractions
import functools

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

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

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

print(mon_life[0])

Submission status: Accepted

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

lst = []
def Gcd(a , b):
    r =  b % a
    if r == 0:
        return a
    else:
        b = a
        return Gcd(r, a)

for i in range(N - 1):
    v = Gcd(A[i], A[i + 1])
    lst.append(v)

print(min(lst))

Submission status: Accepted

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

ans = fractions.gcd(A[0], A[1])

for a in A[2:]:
    ans = fractions.gcd(ans, a)
print(ans)

Submission status: Accepted

Solution code:
import fractions


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

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

Submission status: Accepted

Solution code:
import fractions
n=input()
a=list(map(int,input().split()))
if 1 in a:a=[1]
while len(a)>1:
    a.append(fractions.gcd(a.pop(),a.pop()))
    if a[-1]==1:break
print(a[-1])

Submission status: Accepted

Solution code:
import fractions
n=input()
a=list(map(int,input().split()))
while len(a)>1:
    a.append(fractions.gcd(a.pop(),a.pop()))
    if a[-1]==1:break
print(a[-1])

Submission status: Accepted

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

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

gcd_num = 0
for i in range(len(A_list)):
    gcd_num = gcd(gcd_num, A_list[i])
print(gcd_num)

Submission status: Accepted

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

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

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

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
#C-118
n = int(input())
a = [int(i) for i in input().split()]
min_HP = min(a) 
while True:
  for ni in range(n):
    if a[ni]%min_HP!=0:
      a[ni] = a[ni]%min_HP
  if min_HP > min(a):
    min_HP = min(a)
  else:
    break
print(min_HP)

Submission status: Accepted

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

N = int(input())
L = [int(v) for v in input().split()]

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

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

Submission status: Accepted

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

from fractions import gcd

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

Submission status: Accepted

Solution code:
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:
n = int(input())
a = list(map(int,input().split()))
while True:
  att = min(a)
  attin = a.index(att)
  a = [i % att for i in a]
  a = [i for i in a if i != 0]
  a.append(att)
  if len(a) == 1:
    break
print(a[0])

Submission status: Accepted

Solution code:
import fractions

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

for i in ms[1:]:
  ans = fractions.gcd(ans, i)
  
print(ans)

Submission status: Accepted

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

def battle(lis):
  while True:
    if len(lis) == 1: break
    lis = [i for i in lis if i != 0]
    lis.sort()
    for i in range(len(lis)-1):
      lis[i+1] %= lis[0]
  return lis[0]

print(battle(A))

Submission status: Accepted

Solution code:
from fractions import gcd

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

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

Submission status: Accepted

Solution code:
from collections import defaultdict
import sys,heapq,bisect,math,itertools,string,queue,datetime
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7
def inpl(): return list(map(int, input().split()))
def inpl_str(): return list(input().split())

#最大公約数
def gcd(a,b):
	while b:
		a,b = b, a%b
	return a

#最小公倍数
def lcm(a,b):
	return a*b // gcd(a,b)

N = int(input())
aa = inpl()
ans = aa[0]
for a in aa:
    ans = gcd(a,ans)
print(ans)

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(1,len(A)):
    gcd = fractions.gcd(gcd,A[i])

print(gcd)

Submission status: Accepted

Solution code:
def gcd(a, b):
    if a < b:
        a, b = b, a
    if b == 0:
        return a
    c = a % b
    return gcd(b, c)
  
N = int(input())
li = [ int(it) for it in input().split() ]

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

Submission status: Accepted

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

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


def calc(monsters):
    if len(monsters) == 1:
        return monsters[0]

    min_monster = min(monsters)
    min_index = monsters.index(min_monster)
    new_monsters = []
    for i in range(len(monsters)):
        if i == min_index:
            new_monsters.append(monsters[i])

        remndr = monsters[i] % min_monster
        if remndr != 0:
            new_monsters.append(remndr)

    return calc(new_monsters)


ans = calc(A)
print(ans)

Submission status: Accepted

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

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


def calc(monsters):
    if len(monsters) == 1:
        return monsters[0]

    min_monster = min(monsters)
    min_index = monsters.index(min_monster)
    new_monsters = []
    for i in range(len(monsters)):
        if i == min_index:
            new_monsters.append(monsters[i])

        remndr = monsters[i] % min_monster
        if remndr != 0:
            new_monsters.append(remndr)

    return calc(new_monsters)


ans = calc(A)
print(ans)

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

Submission status: Accepted

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


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


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


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


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

print(ever_gcd)

Submission status: Accepted

Solution code:
N = int(input())
A = [int(c) for c in input().split()]
A.sort()
while True:
    pivot = A.pop(0)
    A = [a % pivot for a in A if a % pivot != 0]
    if len(A) == 0:
        print(pivot)
        break
    A.append(pivot)
    A.sort()

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
b = A[0]
def gcm(x,y):
    if x < y:
        x, y = y, x
    if y == 0:
        return x
    return gcm(y,x%y)
for a in A:
    b = gcm(b,a)
print(b)

Submission status: Accepted

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

Submission status: Accepted

Solution code:

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

def gcd(n_list):
    ans = n_list[0]
    for n in n_list:
       ans = euclid_gcd(ans, n)
    return ans



if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))

    answer = gcd(A)

    print(answer)

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(2,n):
  ans=fractions.gcd(ans,a[i])
print(ans)

Submission status: Accepted

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


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


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

print(A[N-1])

Submission status: Accepted

Solution code:
def gcd(m,n):
    x = max(m,n)
    y = min(m,n)
    tmp = x%y
    while not tmp == 0:
        x = y
        y = tmp
        tmp = x%y
    return y
N = int(input())
A = list(map(int,input().split()))
hp = A[0]
for i in A:
    hp = gcd(hp,i)
print(hp)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
ans = []
def chr(a,b):
  #  print(a,b)
    if a >= b:
        a = a%b
    else:
        b = b%a
    if a == 0 or b == 0:
        return(max(a,b))
    else:
        return(chr(a,b))

ans.append(chr(a[0],a[1]))
#print(ans)

for i in range(1,n):
    ans.append(chr(ans[-1],a[i]))
print(ans[-1])

Submission status: Accepted

Solution code:
def gcd(x,y):
    if y>x:
        a=y
        y=x
        x=a
    a=1
    while a*y:
        a=x%y
        x=y
        y=a
    return x
a=int(input())
b=[int(i) for i in input().split()]
c=b[0]
for i in range(a-1):
    c=gcd(c,b[i+1])
print(c)

Submission status: Accepted

Solution code:
n = int(input())
a = sorted(map(int, input().split()))
while not len(a) == 1:
    b = []
    for hp in a:
        hp %= a[0]
        if hp > 0:
            b.append(hp)
    b.append(a[0])
    a = sorted(b)
print(*a)

Submission status: Accepted

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

Submission status: Accepted

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

from fractions import gcd

M = a[0]
         
for x in a[1:]:
    M = gcd(M, x)

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)

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

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

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce

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

print(reduce(gcd, a))

Submission status: Accepted

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

def gcd(x,y):
    if x<y:
        x,y=y,x
    #x>y
    if y==0:
        return x
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)
      
x = l[0]
for i in range(1,n):
  x = gcd(x,l[i])
  
print(x)

Submission status: Accepted

Solution code:
from fractions import gcd

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

mini = min(A)
ans = min(A)
for a in A:
    amari = a % mini
    if amari != 0:
        if amari < ans:
            ans = amari            
if mini - ans == 0:
    print(ans)
else:
    print(gcd(mini, ans))

Submission status: Accepted

Solution code:
from fractions import gcd

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

a = sorted(A)
B = [a[0]]
C = []
for i in range(1,N):
    x = a[i]%a[0]
    if x != 0:
        B.append(x)
b =sorted(B)
for i in range(len(b)-1):
    y = gcd(b[i],b[-1])
    C.append(y)
    
if len(b) == 1:
    print(b[0])
else:
    print(min(C))

Submission status: Accepted

Solution code:
from fractions import gcd
from functools import reduce
N = int(input())
A = [int(a) for a in input().split(" ")]
print(reduce(lambda acc, c: gcd(acc, c), A, A[0]))

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)

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

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

print(g)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int, input().split()))
INF = 10**9
mod = a[::]
previous_min = min(a)

while True:
    if sum(mod) == 0:
        ans = previous_min
        break
    current_min = min(filter(lambda x: x > 0, mod))
    mod = [a[i] % current_min for i in range(len(a))]
    previous_min = current_min

print(ans)

Submission status: Accepted

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


def gcd(x,y):
  if x < y:
    tmp = x
    x = y
    y = tmp
    
  while y:
    x, y = y, x % y
  return x  
    
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())
a=[int(i) for i in input().split()]
b=a[0]
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x

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

Submission status: Accepted

Solution code:
import fractions
n = int(input())
a = list(map(int,input().split()))
d = min(a)
for t in a:
  d = fractions.gcd(d, t)
print(d)

Submission status: Accepted

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

Submission status: Accepted

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

#ユーグリッドの互除法で、a,bを与えて、aをbで割ってあまりを計算する
#あまりがないときは、最後に割った数を返す（最大公約数）
#あまりがあるときは、bにあまりを入れて、再び計算する
def gcd(a,b):
	if b == 0:
		return a
	return gcd(b,a%b)


x = A[0]
for i in A[1:]:
	x = gcd(x,i)
print(x)

Submission status: Accepted

Solution code:
import functools
from fractions import gcd

n = int(input())
l = list(map(int, input().split()))
ans = functools.reduce(gcd, l)
print(ans)

Submission status: Accepted

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

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

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

Submission status: Accepted

Solution code:
N = int(input())
A = list(map(int, input().split()))
x=0
key = min(A)
while x==0:
    for i in range(N):
        if int(A[i]%key)==0:
            A[i]=key
        else:
            A[i]=A[i]%key
            
    if min(A)==key:
        print(key)
        break
    else:
        key = min(A)

Submission status: Accepted

Solution code:
import fractions
from functools import reduce

_ = int(input())
ans = reduce(fractions.gcd, [int(i) for i in input().split()])
print(ans)

Submission status: Accepted

Solution code:
# 2019/05/04
# AtCoder Beginner Contest 118 - C

import fractions

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

# Search GCD
wkgcd = a[0]
for i in range(1, n):
    wkgcd = fractions.gcd(wkgcd, a[i])

# Output
print(wkgcd)

Submission status: Accepted

Solution code:
N = int(input())
A = sorted(list(map(int,input().split())))
m = min(A)
def gcd(a, b):
    r = a%b
    while r != 0:
        a = b
        b = r
        r = a%b
    return b
g = A[0]
for i in range(N):
    g = gcd(g, A[i])
print(min(g,m))

Submission status: Accepted

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

Submission status: Accepted

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

min_g = fractions.gcd(A[0], A[1])
for i in A[2:]:
  min_g = fractions.gcd(min_g, i)
  
print(min_g)

Submission status: Accepted

Solution code:
n = int(input())
a = list(map(int,input().split()))
def gcd(x,y):
    if x<y:
        x,y = y,x
    if y==0:
        return x
    if x%y==0:
        return y
    else:
        return gcd(y,x%y)
ans = a[0]
for i in a:
    ans = gcd(ans,i)
print(ans)

Submission status: Accepted

Solution code:
from fractions import gcd

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

g = 0
for i in a:
    g = gcd(g,i)
print(g)

Submission status: Accepted

Solution code:
N = int(input())

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

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

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

print (ans)

Submission status: Accepted

Solution code:
import math
N = int( input())
temp = list(map(int,input().split(" ")))
temp.sort()
def GCD( a,  b ):
    if b == 0:
        # print("--" * 10)
        return a
    else:
        # print(b)
        return GCD(b, a % b)
ans = [GCD(temp[0],temp[1])]
for i,num in enumerate(temp[2:]):
    ans.append(GCD(ans[i],num))

print(ans[-1])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(N: int, A: "List[int]"):
    while len(A) != 1:
        A.sort(reverse=True)
        while A[-1] == 0:
            A.pop()
        for i in range(len(A) - 1):
            A[i] %= A[-1]
    return A[0]


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]"
    result = solve(N, A)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
# 入力
input_int = lambda:int(input())
input_ints = lambda:map(int,input().split())
input_str = lambda:input()
input_strs = lambda:input().split()
input_lines = lambda n,f:[f() for _ in range(n)]

import functools,fractions
import numpy as np
gcd = lambda a:functools.reduce(fractions.gcd,a) # 最大公約数（リスト）
lcm_base = lambda a,b:(a*b)//fractions.gcd(a,b) # 最小公倍数(2値)
lcm = lambda a:functools.reduce(lcm_base,a,1) # 最小公倍数(リスト)

def solution():
    N = input_int()
    As = input_ints()
    ans = gcd(As)
    print(ans)

if __name__ == '__main__':
    solution()