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: Runtime Error

Solution code:
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict
from heapq import heappop, heappush, heappushpop
import sys
INF = float('inf')
mod = 10**9+7


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

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    n = I()
    lst = LI()
    print(gcd(lst))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
a.append(a[0])
div = a[0]
minVal = a[0]
for i in range(n+1):
    mod = a[i] % div
    if mod > 0:
        minVal = min(mod, div - mod, minVal, mod - (div - mod))
        div = minVal
    else:
        continue
print(minVal)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a_list = list(map(int, input().split()))
import math
def dfs(lis, i):
    if i == 0:
        return lis[0]
    if i >0:
        ans = math.gcd(dfs(lis,i-1),lis[i])
        return ans
print(dfs(a_list,n-1))

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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


def main():
    from heapq import heappush, heappop

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

    for ai in a:
        heappush(elements, ai)

    while len(elements) >= 2:
        a_min = heappop(elements)

        for _ in range(len(elements)):
            aj = heappop(elements)
            aj %= a_min

            if aj != 0:
                heappush(elements, aj)

        if len(elements) == 0:
            print(a_min)
            exit()

    print(min(a_min, elements))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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=list(c.keys)

d=d.sorted
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: Runtime Error

Solution code:
N, Q = map(int, input().split())
S = input()
quiz = [list(map(int, input().split())) for _ in range(Q)]

t = [0] * (N+1)
for i in range(N):
  t[i+1] = t[i] + (1 if S[i:i+2] == "AC" else 0)

for q in quiz:
  l = q[0]
  r = q[1]
  print(t[r-1] - t[l-1])

Submission status: Runtime Error

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

def recurfunc(i, x):
  if i==N-1:
    print(x)
    return
  recurfunc(i+1, gcd(x, A[i+1]))

N = int(input())
A = list(map(int, input().split()))
recurfunc(1, gcd(A[0], A[1]))

Submission status: Runtime Error

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

Submission status: Runtime Error

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%ans!=0:
    ans=min(ans, gcd(mn,m))
print(ans)

Submission status: Runtime Error

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%ans!=0:
    ans=min(ans, gcd(mn,m))
    break

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N=int(intput())
M=list(map(int, input().split()))
ans=min(M)
for m in M:
  if m%ans!=0:
    ans=1
    break
print(ans)

Submission status: Runtime Error

Solution code:
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: Runtime Error

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(a[i],gcd)
print(gcd)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from fractions import gcd
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: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
# def helper(A):
#     v = min(A)
#     ans = set()
#     for a in A:
#         if a%v!=0:
#             ans.add(a%v)
#     ans.add(v)
#     return ans

# while len(A)>1:
#     A = helper(A)
# print(min(A))
def gcd(x,y):
    if y==0: return x
    return gcd(y,x%y)
ans = A[0]
for a in A:
    ans = gcd(ans,i)
print(ans)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import functools
import math
n, *a = map(int, open(0).read().split())
gcd = functools.reduce(math.gcd, a)
print(gcd)

Submission status: Runtime Error

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

import math

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

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

print(monsters[-1])

Submission status: Runtime Error

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

A.sort()
stack = A[1:]
m = A[0]

while stack:
  stack = list(stack)
  l = []
  for x in stack:
    if x % m == 0:
      continue
    l.append(x % m)
  
  m = min(l)
  stack = set(l)

print(m)

Submission status: Runtime Error

Solution code:
from math import gcd as gcd
n=int(input())
a=sorted(map(int,input().split()))
INF=2*10**9
ans=INF
for i in range(len(a)-1):
	tmp=gcd(a[i],a[i+1])
	if tmp!=0 and tmp<ans:
		ans=tmp
print(ans)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import fractions
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()))

p=gcd_list(a)

print(p)

Submission status: Runtime Error

Solution code:
import fraction
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()))

p=gcd_list(a)

print(p)

Submission status: Runtime Error

Solution code:
import flactions

N = int(input())
A = list(input().split())
monster = list(sorted([int(A[i]) for i in range(N)]))
ans = float('inf')
MIN = monster[0]

for i in range(N):
    tmp = monster[i]
    ans = min(ans, int(flactions.gcd(tmp, MIN)))

print(ans)

Submission status: Runtime Error

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

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


set_odd = set()
set_even = set()

for i in a:
    if i % 2 == 1:
        set_odd.add(i)
    else:
        set_even.add(i)

if len(set_odd) >= 2:
    print(1)
    exit()
elif len(set_odd) == 1:
    if len(set_even) >= 1:
        print(1)
        exit()
    else:
        print(min(set_odd))

# only even number
min_a = min(set_even)
set_even = list(set_even)

ans = []

for i in range(len(set_even)):
    ans_tmp = set_even[i] % min_a
    if ans_tmp != 0:
        ans.append(ans_tmp)
    if min_a-ans_tmp != 0:
        ans.append(min_a-ans_tmp)

if ans == []:
    print(min(set_even))
else:
    print(min(ans))

Submission status: Runtime Error

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

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


set_odd = set()
set_even = set()

for i in a:
    if i % 2 == 1:
        set_odd.add(i)
    else:
        set_even.add(i)

if len(set_odd) >= 2:
    print(1)
    exit()
elif len(set_odd) == 1:
    if len(set_even) >= 1:
        print(1)
        exit()
    else:
        print(min(set_odd))

# only even number
min_a = min(set_even)
set_even = list(set_even)

ans = []

for i in range(len(set_even)):
    ans_tmp = a[i] % min_a
    if ans_tmp != 0:
        ans.append(ans_tmp)
    if min_a-ans_tmp != 0:
        ans.append(min_a-ans_tmp)

if ans == []:
    print(min(set_even))
else:
    print(min(ans))

Submission status: Runtime Error

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

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


set_odd = set()
set_even = set()

for i in a:
    if i % 2 == 1:
        set_odd.add(i)
    else:
        set_even.add(i)

if len(set_odd) >= 2:
    print(1)
    exit()
elif len(set_odd) == 1:
    if len(set_even) >= 1:
        print(1)
        exit()
    else:
        print(min(set_odd))

# only even number
min_a = min(set_even)
set_even = list(set_even)

ans = []

for i in range(len(a)):
    ans_tmp = a[i] % min_a
    if ans_tmp != 0:
        ans.append(ans_tmp)
    if min_a-ans_tmp != 0:
        ans.append(min_a-ans_tmp)

if ans == []:
    print(min(set_even))
else:
    print(min(ans))

Submission status: Runtime Error

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

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


set_odd = set()
set_even = set()

for i in a:
    if i % 2 == 1:
        set_odd.add(i)
    else:
        set_even.add(i)

if len(set_odd) >= 2:
    print(1)
    exit()
elif len(set_odd) == 1:
    if len(set_even) >= 1:
        print(1)
        exit()
    else:
        print(min(set_odd))

# only even number
min_a = min(set_even)
set_even = list(set_even)

ans = []

for i in range(len(a)):
    ans_tmp = a[i] % min_a
    if ans_tmp != 0:
        ans.append(ans_tmp)
    if min_a-ans_tmp != 0:
        ans.append(min_a-ans_tmp)

print(min(ans))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
def gdc(p, q):
    if q <= 0:
        return p
    p -= q
    return gdc(max(p,q), min(p,q))

def main():
    N = int(input())
    A = list(map(int, input().split()))
    A_sorted = sorted(A)
    print(gdc(A[1], A[0]))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

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

g= A[0]
'''import fractions
for i in range(1,n):
    g = fractions.gcd(g, A[i])'''
import math
for i in range(1,n):
    g = math.gcd(g,A[i])
print(g)

Submission status: Runtime Error

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: Runtime Error

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: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce
n=int(input())
A=list(map(int,input().split()))
def gcd(*numbers):
    return reduce(fraction.gcd,numbers)
print(gcd(*A))

Submission status: Runtime Error

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

Submission status: Runtime Error

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(*a))

Submission status: Runtime Error

Solution code:
def f(a,*b):
    if len(b)>1:
        return f(a,f(*b))
    b=b[0]
    if b:
        return f(b,a%b)
    return a
n=int(input())
a=list(map(int,input().split()))
print(f(*a))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
N=int(input())
a=input().split()
A=[int(b) for b in a]
A=sorted(A,reverse=True)
numbers=[]
numbers.append(math.gcd(A[0],A[1]))
for a in range(1,N):
    answer=math.gcd(numbers[-1],A[a])
    numbers.append(answer)
print(numbers[-1])

Submission status: Runtime Error

Solution code:
import math
N=int(input())
a=input().split()
A=[int(b) for b in a]
A=sorted(A,reverse=True)
numbers=[]
for n in range(N-1):
    answer=math.gcd(A[n],A[n+1])
    numbers.append(answer)
numbers.append(A[-1])
print(min(numbers))

Submission status: Runtime Error

Solution code:
import math
N=int(input())
a=input().split()
A=[int(b) for b in a]
A=sorted(A,reverse=True)
numbers=[]
for n in range(N-1):
    answer=math.gcd(A[n],A[n+1])
    numbers.append(answer)
print(min(numbers))

Submission status: Runtime Error

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

Submission status: Runtime Error

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: Runtime Error

Solution code:
import math
n = int(input())
a_list = sorted(list(map(int,input().split())))

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

print(a)

Submission status: Runtime Error

Solution code:
n=int(input()) 
lis=list(map(int,input().split()))
m=min(lis)
new=lis
while True:
  for i in range(n):
    new[i]%=m
  if all(nn==0 for nn in new):
    print(m)
    exit()
  ll=[m]
  for nn in new:
    if nn!=0:
      ll.append(nn)
  new=ll
  m=min(new)

Submission status: Runtime Error

Solution code:
import math

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

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

print(a)

Submission status: Runtime Error

Solution code:
from math import gcd
n = int(input())
a_input = list(map(lambda x:-int(x),input().split()))

x = a_input.pop(0)
for i in range(len(a_input)):
    x = gcd(x,a_input[i])
print(x)

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
A = getList()

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

Submission status: Runtime Error

Solution code:
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

from collections import defaultdict, deque, Counter
from sys import exit
import heapq
import math
import copy
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7

N = getN()
A = getList()

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import numpy as np
import sys
readline = sys.stdin.readline
read = sys.stdin.read

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

N = II()
A = LII()
A = np.array(A)

if sum(A % 2) == 0:
    print(min(A))
else:
    a = min(A)
    AA = np.array(A)

    while True:
        AA = AA % a
        if len(AA[AA > 0]) > 0:
            a = min(AA[AA > 0])
        else:
            break
    A %= a
    print(min(A[A>0]))

Submission status: Runtime Error

Solution code:
import math,functools
input()
A = [int(hoge) for hoge in input().split()]
print(functools.reduce(math.gcd,A))

Submission status: Runtime Error

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


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


print(gcd(An))

Submission status: Runtime Error

Solution code:
import sys
import math


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


MOD = 10 ** 9 + 7
sys.setrecursionlimit(20000000)


def main():
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    a = A[0]
    B = set()
    for i in range(1, N):
        g = math.gcd(A[i], a)
        if g == 1:
            B.add(1)
        elif g == a:
            continue
        else:
            B.add(g)
    if len(B) == 0:
        print(a)
    else:
        print(min(B))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
from math import gcd

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''

import math
n=int(input())
a=list(map(int,input().split()))
for i in range(n-1):
    a[i+1]=math.gcd(a[i],a[i+1])
print(min(a))

Submission status: Runtime Error

Solution code:
import fractions
def myAnswer(N:int,A:list) -> int:
   A.sort()
   target = A.pop(0)
   for a in A:
      if(fractions.gcd(A[0],A[1])==1):
         return 1
   return target

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

Submission status: Runtime Error

Solution code:
import math
def myAnswer(N:int,A:list) -> int:
   A.sort()
   return math.gcd(A[0],A[1])

def modelAnswer():
   return
def main():
   N = int(input())
   A = list(map(int,input().split()))
   print(myAnswer(N,A[:]))
if __name__ == '__main__':
   main()

Submission status: Runtime Error

Solution code:
def ngcd(lista):
    from math import gcd
    res = lista[0]
    for i in range(1,len(lista)):
        if res != 1:
            res = gcd(lista[i],res)
    return res

def main():
    n = int(input())
    a = list(map(int,input().split()))
    print(ngcd(a))

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
from fractions import math
n = int(input())
a = list(map(int, input().split()))
min_mod = min(a)
flag = True
b = math.gcd(a[0], a[1])
for i in range(2, n):
    b = math.gcd(a[i], b)
print(b)

Submission status: Runtime Error

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: Runtime Error

Solution code:
from collections import defaultdict
N,M,*A = map(int, open(0).read().split())
ls = [0]*10
ls[1] = 2
ls[2] = 5
ls[3] = 5
ls[4] = 4
ls[5] = 5
ls[6] = 6
ls[7] = 3
ls[8] = 7
ls[9] = 6
dic = defaultdict(int)
for a in A:
  k = ls[a]
  dic[k] = max(dic[k],a)
dp = [-1]*(N+1)
for k in dic.keys():
  if k>N:
    continue
  dp[k] = dic[k]
for i in range(N+1):
  for k in dic.keys():
    if i-k>0 and dp[i-k]!=-1:
      s = str(dp[i-k])
      m = int(s+str(dic[k]))
      dp[i] = max(dp[i], m)
print(dp[N])

Submission status: Runtime Error

Solution code:
import math

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

Submission status: Runtime Error

Solution code:
import math

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

Submission status: Runtime Error

Solution code:
import sys
import os
import math
import bisect
import collections
import itertools

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: x * y / math.gcd(x, y)

MOD = 10 ** 9 + 7
MAX = float('inf')


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

    N = ii()
    A = il()
    sm = sum(A)
    print(min([math.gcd(sm, a) for a in A]))


if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math

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

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

print(ans)

Submission status: Runtime Error

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

#２整数の最大公約数を求める

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



#N 整数の最大公約数を求める
#A = [A[0],...,A[N]] とする

def gcd(A):
    ans = A[0]
    for i in range(1,N) #range(1,N)= 1,2,...,N-1
        ans = gcd(ans, A[i])
    return ans
print(gcd(A))

Submission status: Runtime Error

Solution code:
import math

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)

Submission status: Runtime Error

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(*A))

Submission status: Runtime Error

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

def judge(A):
    
    count = 0
    for i in range(N):
        if A[i] >= 1:
            count += 1
    if count == 1:
        return 1
    else: return 0
    

while judge(A) == 0:
    A.sort()

    for i in range(N):
        if i >=1:
            A[i] = A[i]%A[0]

for i in range(N):
    if A[i] >= 1:
        print(A[i])

Submission status: Runtime Error

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

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

print(G)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
a = [int(i) for i in input().split()]
a = sorted(a)
flag = False
for i in range(1,n):
    if math.gcd(a[i],a[0])==1:
        flag = True
mn = 10**9
if not flag:
    for i in range(1,n):
        mn = min(mn,math.gcd(a[0],a[i]))
print(1 if flag else mn)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,=pin()
    A=tupin()
    
    from math import gcd

    temp=A[0]
    for i in range(1,N):
          temp=gcd(temp,A[i])
    print(temp)
    
#%%submit!
resolve()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
#%%code
def resolve():
    N,=pin()
    A=tupin()
    
    from math import gcd

    temp=A[0]
    for i in range(N-1):
          temp=gcd(temp,A[i])
    print(temp)
#%%submit!
resolve()

Submission status: Runtime Error

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

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

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce

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

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

N = int(input())

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


print(gcd_list(a))

Submission status: Runtime Error

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))

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: Runtime Error

Solution code:
import functools
import fructions

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

gcd = functools.reduce(fructions.gcd, a)
print(gcd)

Submission status: Runtime Error

Solution code:
import math

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

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

res = A[N - 1]
print(res)

Submission status: Runtime Error

Solution code:
import math

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

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

print(A[N - 1])

Submission status: Runtime Error

Solution code:
import math

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

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

print(A[N - 1])

Submission status: Runtime Error

Solution code:
import functools
import math

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

Submission status: Runtime Error

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

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

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

print(gcd_list(A))

Submission status: Runtime Error

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

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

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

print(gcd_list(A))
# 3

Submission status: Runtime Error

Solution code:

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

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

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

print(gcd_list(A))
# 3

Submission status: Runtime Error

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

mod = A[-1] % A[-2]

print(A[0] - mod)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
from math import gcd
n = int(input())
arr = [int(x) for x in input().split()]


ans = arr[0]

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

print(ans)

Submission status: Runtime Error

Solution code:
from math import gcd
from functools import reduce

def gcdli(xl):
    #xlはlist
    return reduce(gcd , xl)

def monsters_battle_royale(n, al):

    ans = gcdli(al)

    return ans

def main():
    n = int(input())
    al = list(map(int, input().split()))
    print(monsters_battle_royale(n, al))

if __name__ == '__main__':
    main()