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
from collections import defaultdict
import math

def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort(reverse=True)
    g = A[0]

    for i in range(1,N):
        g = math.gcd(g,A[i])

    print(g)





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
import math

def input():
    return sys.stdin.readline().rstrip()


def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()
    g = A[0]

    for i in range(1,N):
        g = math.gcd(g,A[i])

    print(g)





if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from collections import defaultdict
import math

def input():
    return sys.stdin.readline().rstrip()


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

    print(g)





if __name__ == "__main__":
    main()

Submission status: Accepted

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

Submission status: Accepted

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

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
n=int(input())
A=[]*n
A[:]=map(int,input().split())

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

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

Submission status: Accepted

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

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

print(ans)

Submission status: Accepted

Solution code:
import math


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

    ans = math.gcd(As[0], As[1])
    for i in range(2, n):
        ans = math.gcd(ans, As[i])
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
from math import gcd
from functools import reduce
input()
print(reduce(gcd, map(int, input().split())))

Submission status: Accepted

Solution code:
#! python3
# 118_C 体力の最小値を表示
#体力の最小値は体力の最大公約数

import math

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

ans = st_list[0]

for i in range(N):
    ans = math.gcd(ans,st_list[i])
    
print(ans)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math

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

for i in range(1,n):
    if i == 1:
        ans = math.gcd(a[0],a[i])
    else:
        ans = math.gcd(ans,a[i])

print(ans)

Submission status: Accepted

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

MIN= min(A)
while 1:
  newA = []
  MIN0 = MIN
  for i in range(len(A)):
    a = A[i] % MIN
    if a == 0:
      newA.append(a)
    else:
      if a < MIN:
        MIN = a
      newA.append(a)
  if MIN==1:break
  if MIN0 == MIN:break

print(MIN)

Submission status: Accepted

Solution code:

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

f = A[0]
for i in range(1,N):
    a,b=f, A[i]
    f=math.gcd(a,b)

print(f)

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
from functools import reduce
from math import gcd

n, *a = map(int, open(0).read().split())
print(reduce(gcd, a))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

print(gcd(an))

Submission status: Accepted

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
print(np.gcd.reduce(A))

Submission status: Accepted

Solution code:
def main():
    n = int(input())
    inlis = list(map(int, input().split()))
    inlis = set(inlis)
    inlis = list(inlis)
    inlis.sort()

    while len(inlis) > 1:
        tmp = 0
        i = 1
        while tmp < len(inlis):
            #print(i, tmp)
            if inlis[i] % inlis[0] != 0:
                inlis[i] %= inlis[0]
                i += 1
                if i >= len(inlis):
                    break
            else:
                inlis.remove(inlis[i])
            tmp += 1
        inlis = set(inlis)
        inlis = list(inlis)
        inlis.sort()
        #print(inlis, len(inlis))
    print(inlis[0])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, 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()))

m = 0
tmp = min(a)
while m != tmp:
    m = tmp
    for i in range(n):
        if a[i] != m:
            a[i] = a[i] % m
        if a[i] < m and a[i] != 0:
            tmp = a[i]
print(m)

Submission status: Accepted

Solution code:
from math import gcd

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

Submission status: Accepted

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

Submission status: Accepted

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

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:
import sys
N = int(input())
A = list(map(int, input().split()))
a = min(A)
b = a
while True:
    for _a in A:
        _b = _a % a
        if _b > 0 and _b < a:
            b = _b
    if b == a:
        print(a)
        sys.exit()
    a = b

Submission status: Accepted

Solution code:
n = int(input())
A = tuple(map(int, input().split()))
ma = min(A)
while True:
    ra = set([a%ma for a in A if a%ma > 0])
    if len(ra) == 0:
        print(ma)
        break
    minra = min(ra)
    if ma == minra:
        print(ma)
        break
    ma = minra

Submission status: Accepted

Solution code:
import math
n = int(input())
A = tuple(map(int, input().split()))
g = A[0]
for a in A[1:]:
    g = math.gcd(g, a)
print(g)

Submission status: Accepted

Solution code:
from math import gcd

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

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

Submission status: Accepted

Solution code:
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
d = a.min()
while True:
    a1 = a % d
    if all(a1 == 0):
        ans = d
        break
    d = min(a1[a1 != 0])    
print(ans)

Submission status: Accepted

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

m = numpy.inf

while True:
    if numpy.min(L) == m:
        break

    m = numpy.min(L)
    mi = numpy.argmin(L)

    L = L % m
    L[mi] = m
    L = L[L != 0]

print(numpy.sum(L))

Submission status: Accepted

Solution code:
from math 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 math
n=int(input())
a=list(map(int,input().split()))
a.sort()
b=a[n-1]
for i in range(n-1):
    b=math.gcd(a[i],b)
print(b)

Submission status: Accepted

Solution code:
from functools import reduce
import math


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


def main():
    N = int(input())
    A = list(map(int, input().split()))
    ans = gcd_list(A)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

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

mn = min(A)
while True:
    ok = False
    for a in A:
        x = a % mn
        if x != 0 and x < mn:
            mn = x
            ok = True
    if not ok:
        break
print(mn)

Submission status: Accepted

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

a=sorted(a)

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]
  
c=make_divisors(a[0])


d=sorted(c)
f=[]
for y in range(len(d)):
  e=d[y]
  ch=0
  for x in range(1,n):
    if not a[x]%e==0:
      continue
    ch+=1
  if ch==n-1:
    f.append(e)
    
print(max(f))

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

print(reduce(math.gcd, a))

Submission status: Accepted

Solution code:
import sys
import math
input = lambda: sys.stdin.readline().rstrip()

def main():
    n = int(input())
    a = list(map(int, input().split()))
    for i in range(1, n):
        if i == 1:
            ans = math.gcd(a[i-1], a[i])
        else:
            ans = math.gcd(ans, a[i])
    print(ans)
        
if __name__ == '__main__':
    main()

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:
import math
from functools import reduce
 
def gcd(numbers):
    return reduce(math.gcd, numbers)
 
n=int(input())
A=tuple(map(int,input().split()))
print(gcd(A))

Submission status: Accepted

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

N = int(input())
A = list(map(int, input().split()))
a = A[0]
for i in range(N-1):
  a = gcd(a, A[i+1])
print(a)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

print(gcd(*a))

Submission status: Accepted

Solution code:
import math
n = int(input())
l = list(map(int, input().split()))
def multiGCD(l):
    ans = 0
    for i in l:
        ans = math.gcd(ans, i)
    return ans
print(multiGCD(l))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import math
from functools import reduce


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


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

print(gcd_list(A))

Submission status: Accepted

Solution code:
import sys
from fractions import gcd
# from heapq import heapify, heappop, heappush
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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)

# heapify(a)
# while len(a) != 1:
#     f = heappop(a)
#     s = heappop(a)
#     s %= f
#     if s != 0:
#         heappush(a, s)
#     heappush(a, f)
# print(heappop(a))

Submission status: Accepted

Solution code:
import sys
from heapq import heapify, heappop, heappush
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

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

heapify(a)

while len(a) != 1:
    f = heappop(a)
    s = heappop(a)
    s %= f
    if s != 0:
        heappush(a, s)
    heappush(a, f)

print(heappop(a))

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from collections import deque, defaultdict
from math import sqrt, factorial, gcd
# def input(): return sys.stdin.readline()[:-1] # warning not \n
# def input(): return sys.stdin.buffer.readline().strip() # warning bytes
# def input(): return sys.stdin.buffer.readline().decode('utf-8')


def solve():
    n = int(input())
    a = [int(x) for x in input().split()]
    mn = min(a)
    while True:
        b = set()
        for e in a:
            if e % mn:
                b.add(e%mn)
            else:
                b.add(mn)
        a = list(b)
        mn = min(a)
        if len(a) == 1:
            print(mn)
            return
    

t = 1
# t = int(input())
for case in range(1,t+1):
    ans = solve()


"""

2 3 4 4
3 4 4
2 3 4
2 3 4
2 4 4


"""

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

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

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc118


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

    def gcd(n, m):
        """
        2020/05/22
        """
        while True:
            if m == 0:
                return n
            n, m = m, n % m

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

    return A[i+1]


print(main())

Submission status: Accepted

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

import math
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    return divisors

ans_list = sorted(make_divisors(arr[0]),reverse=True)

for i in ans_list:
    flg =True
    for j in arr:
        if j%i != 0:
            flg =False
            break
    if flg:
        print(i)
        exit()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
N = I()
A_l = LI()
ans = A_l[0]
for i in range(1, N):
    ans = math.gcd(ans, A_l[i])
print(ans)

Submission status: Accepted

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

main()

Submission status: Accepted

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

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

  print(ans)
  return

if __name__ == "__main__":
  resolve()

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

Submission status: Accepted

Solution code:

import math

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

x = A[0]
for a in A:
    x = math.gcd(x, a)

print(x)

Submission status: Accepted

Solution code:
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = inp()
a = inpl()
now = a[0]
for i in range(1,n):
    now = math.gcd(now, a[i])
print(now)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
from math import gcd
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

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

Submission status: Accepted

Solution code:
from math import gcd
N = int(input())
A = list(map(int,input().split()))
g = 0
for a in A:
    g = gcd(a,g)
print(g)

Submission status: Accepted

Solution code:
import sys
from math import gcd
input = sys.stdin.readline
N = int(input())
res = 0
a = list(map(int, input().split()))
for x in a: res = gcd(res, x)
print(res)

Submission status: Accepted

Solution code:
#C
n = int(input())
a = list(map(int, input().split()))
#最大公約数
def gcd(a, b):
    while b != 0:
        if a < b:
            b, a = a, b
        a, b = b, a % b
    return a
#最大公倍数
def lcm(a, b):
    return a * b // gcd(a, b)
ans = a[0]
for i in range(1, n):
    ans = gcd(ans, a[i])
print(ans)

Submission status: Accepted

Solution code:
# なんかまともに考えるとわからん
# テキトーに問題文読まずサンプルだけ眺めるとgcdになる

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


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


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

Submission status: Accepted

Solution code:
import numpy as np
def main():
    n = int(input())
    a = [int(i) for i in input().split()]
    print(np.gcd.reduce(a))
main()

Submission status: Accepted

Solution code:
import functools
import math
N = int(input())
A = list(map(int, input().split()))
print(functools.reduce(lambda x,y:math.gcd(x,y),A))

Submission status: Accepted

Solution code:
import math;input();a=list(map(int,input().split()));d=a[0]
for i in a:d=math.gcd(i,d)
print(d)

Submission status: Accepted

Solution code:
from collections import defaultdict
from collections import deque
from collections import Counter
import itertools
import math

def readInt():
  return int(input())
def readInts():
  return list(map(int, input().split()))
def readChar():
  return input()
def readChars():
  return input().split()

n = readInt()
a = list(set(readInts()))

if len(a)==1:
  print(a[0])
  exit()

odd = []
even = []


from math import gcd


d = a[0]
for i in a:
  d = gcd(i,d)
print(d)

Submission status: Accepted

Solution code:
from functools import reduce
from math import gcd
n = int(input())
A = list(map(int, input().split()))
print(reduce(gcd, A))

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

from math import gcd

N = INT()
A = LI()
A.sort()
ans = A[0]

all_can_div = True

for i in range(1, N):
    A[i] = gcd(A[i], ans)
    
    if A[i] != ans and all_can_div:
        all_can_div = False

print(ans if all_can_div else min(A))

Submission status: Accepted

Solution code:
def INT():
    return int(input())

def MI():
    return map(int, input().split())

def LI():
    return list(map(int, input().split()))

from collections import deque
N = INT()
A = LI()
A.sort()

while True:
    mod = A[0]
    flg = True
    ans = A[0]
    tmp = deque([A[0]])
    
    if ans == 1:
        print(ans)
        break
    
    for i in range(1, len(A)):
        A[i] %= mod

        if A[i] != 0 and flg:
            flg = False
        
        if A[i] == 0:
            continue
        tmp.append(A[i])
        
    if flg:
        print(ans)
        break
    
    A = sorted(tmp)

Submission status: Accepted

Solution code:
import math
N = int(input())
A = sorted([int(X) for X in input().split()])
GCDA = A[0]
for T in range(1,N):
    GCDA = math.gcd(GCDA,A[T])
    if GCDA==1: break
print(GCDA)

Submission status: Accepted

Solution code:
import math

N=int(input())
S=list(map(int,input().split()))
F=S[0]
for i in range(N-1):
    F=math.gcd(F,S[i+1])

print(F)

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
  
N = int(input())
L = list(map(int,input().split()))

print(gcd_list(L))

Submission status: Accepted

Solution code:
from math import gcd
from functools import reduce

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

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

g = gcd_list(A)
print(g)

Submission status: Accepted

Solution code:
import math
from functools import reduce
N = int(input())
A = list(map(int,input().split()))
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
print(gcd_list(A))

Submission status: Accepted

Solution code:
import math
from functools import reduce

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

def main():
    N = int(input())
    A = [int(x) for x in input().split()]
    ans = gcd(sorted(A,reverse=True))
    print(ans)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
input=sys.stdin.buffer.readline
from math import*

n=int(input())
arr=list(map(int,input().split()))
ans=1
if n>2:
	ans=gcd(arr[0],arr[1])
	for i in range(2,n):
		ans=gcd(ans,arr[i])
else:
	ans=gcd(arr[0],arr[1])
print(ans)

Submission status: Accepted

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

A.sort()
A = deque(A)
while len(A) > 1:
  s = []
  for i in range(len(A)-1):
    div = A[-1] % A[0]
    A.pop()
    if div != 0:
      s.append(div)
  s.append(A[0])
  s.sort()
  A = deque(s)
print(*A)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

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

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

Submission status: Accepted

Solution code:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

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

import heapq

ans = 0
heapq.heapify(a)
while a:
    t = heapq.heappop(a)
    if ans == 0:
        ans = t
        continue
    else:
        big = max(ans, t)
        small = min(ans, t)
        if big % small != 0:
            ans = big % small
            heapq.heappush(a, small)

print(ans)

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import math

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

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

Submission status: Accepted

Solution code:
import numpy as np

N= int(input())

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

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

r = 0
for i in A:
  r = gcd(i,r)
print(r)

Submission status: Accepted

Solution code:
import sys

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def main():
    n = I()
    A = LI()
    while True:
        ans = min(A)
        A = [x%ans for x in A if x%ans != 0]
        if not A:
            print(ans)
            break
        A.append(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

rem=-1
while True:
    a=sorted(a)
    if a[0]==rem:
        print(a[0])
        break
    rem=a[0]
    for i in range(1,n):
        a[i]%=rem
        if a[i]==0:
            a[i]+=rem

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)
def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()


def C(line):
    return [sys.stdin.readline() for _ in range(line)]
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

N = z()
A = zz()
# A = sorted(A)
tmp =gcd(A[0], A[1])
for a in A[1:]:
    tmp = gcd(tmp, a)
ans = tmp
# for i in range(N):
#     for j in range(0, i):        
#         tmp = A[i] % A[j]
#         tmp = min(tmp, A[j]-tmp)
#         if (tmp != 0):
#             ans = min(ans, tmp)
print(ans)

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
from math import gcd
def main():
    n, *a = map(int, read().split())
    r = gcd(a[0], a[1])
    if n == 2:
        print(r)
        sys.exit()
    for i1 in range(2, n):
        r = gcd(r, a[i1])
    print(r)

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import bisect,copy,heapq,string
from collections import *
from math import *
from itertools import *
import sys
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
a = LIST()

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

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

Submission status: Accepted

Solution code:
# 最大公約数(mathは3.5以降) 
import math
from functools import reduce
def gcd(*numbers):
    return reduce(math.gcd, numbers)

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

# 初期入力
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))

ans =gcd_list(A)
print(ans)

Submission status: Accepted

Solution code:
n = int(raw_input())
ais = map(int, raw_input().split())
def gcd(a,b):
	return gcd(b, a % b ) if b else a
print reduce(gcd, ais)

Submission status: Accepted

Solution code:
import math
n=int(input())
a=list(map(int,input().split()))
num=a[0]
def g(num1,num2):
    return math.gcd(num1,num2)
for i in range(n-1):
    num=g(num,a[i+1])
print(num)

Submission status: Accepted

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


    
ans = a[0]

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

Submission status: Accepted

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

def gcd(a, b):
    if b != 0:
        return gcd(b, a%b)
    else:
        return a
ans = 10**10
for i in range(N-1):
    ans = min(ans, gcd(a[i], a[i+1]))
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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


    
ans = a[0]

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

Submission status: Accepted

Solution code:
N=int(input())
M=list(map(int, input().split()))
ans=min(M)
mn=min(M)
from math import gcd
for m in M:
  if m%mn!=0:
    ans=min(ans, gcd(mn,m))
print(ans)

Submission status: Accepted

Solution code:
#ABC 118 C - Monsters Battle Royale 21:58

def func(A):
    #(1)Aの最小値mを見つける
    #(2)Aの要素をmで割った余りで配列A'を作る（０は無視）
    #A'の要素が０個の場合、mが答え
    A = sorted(A)
    m = min(A)
    B = [A[0]]
    
    for i in range(1,len(A)):
        if A[i]%m != 0:
            B.append(A[i]%m)
    
    if len(B) == 1:
        print(m)
        return len(B)
    else:
        func(B)
    
n = int(input())
A = list(map(int, input().split()))
func(A)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
n = int(input())
min_ = 0
list_ = set(list(map(int, input().split())))

while True:
  tmp = min(list_)
  list_ = set([i%tmp for i in list_])
  if 0 in list_:
    list_.remove(0)
  list_.add(tmp)
  if tmp==min(list_):
    break
print(tmp)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
def gcd(*numbers): reduce(math.gcd, numbers)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
count = 0

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

print(ans)

Submission status: Accepted

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