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:
# coding: utf-8
import sys
# import bisect
import math
# import numpy as np


"""Template"""


class IP:
    """
    入力を取得するクラス
    """
    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        """
        1文字の取得に使います
        :return: int
        """
        return int(self.input())

    def S(self):
        """
        1文字の取得(str
        :return: str
        """
        return self.input()

    def IL(self):
        """
        1行を空白で区切りリストにします(int
        :return: リスト
        """
        return list(map(int, self.input().split()))

    def SL(self):
        """
        1行の文字列を空白区切りでリストにします
        :return: リスト
        """
        return list(map(str, self.input().split()))

    def ILS(self, n):
        """
        1列丸々取得します(int
        :param n: 行数
        :return: リスト
        """
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        """
        1列丸々取得します（str
        :param n: 行数
        :return: リスト
        """
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        """
        Some Int LineS
        横に複数、縦にも複数
        :param n: 行数
        :return: list
        """
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        """
        Some String LineS
        :param n: 行数
        :return: list
        """
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        """
        Half enumeration
        半分全列挙です
        pの要素の和の組み合わせを作ります。
        ソート、重複削除行います
        :param p: list : 元となるリスト
        :return: list : 組み合わせられた和のリスト
        """
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        """
        bit_full_search2
        bit全探索の改良版
        全探索させたら2進数のリストと10進数のリストを返す
        :return: list２つ : １個目 2進数(16桁)  2個目 10進数
        """
        # 参考
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        # https://atcoder.jp/contests/abc105/submissions/4088632
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    """右からj+1番目のiが1かどうか判定"""
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        """
        ソート関係行います。色々な設定あります。
        :param s: 元となるリスト
        :param r: reversするかどうか 0=False 1=True
        :param m: （2次元配列）何番目のインデックスのソートなのか
        :return: None
        """
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        """
        bit探索で使います。0以上のときにTrue出します
        自然数だからn
        :param a: int
        :param b: int
        :return: bool
        """
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        """
        bit探索で使います。1のときにTrue出すよ
        oneで1
        :param a: int
        :param b: int
        :return: bool
        """
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        """
        Round up
        小数点切り上げ割り算
        :param x: int
        :param y: int
        :return: int
        """
        return -(-x//y)

    def ave(self, a):
        """
        平均を求めます
        :param a: list
        :return: int
        """
        return sum(a) / len(a)

    def d(self, p):
        re = 0
        for i in range(len(p) - 1):
            re += ((p[i][0] - p[i + 1][0]) ** 2 + (p[i][1] - p[i + 1][1]) ** 2) ** 0.5
        return re


"""ここからメインコード"""


def main():
    # 1文字に省略
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    """この下から書いてね"""
    n = ip.I()
    a = ip.IL()
    res = 10**9

    for i in r(n):
        res = min(res, math.gcd(a[0], a[i]))

    print(res)

main()

Submission status: Runtime Error

Solution code:
import math

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

min_last_hp = 10 ** 9

for start in range(N):
    for c in range(start+1, N):
        last_hp = math.gcd(a_list[start], a_list[c])
        # if min_last_hp == None:
        #     min_last_hp = last_hp
        if last_hp < min_last_hp:
            min_last_hp = last_hp

print(min_last_hp)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
from functools import reduce

def gcd(a, b):
    x = max(a, b)
    y = min(a, b)
    z = y
    while x%y != 0:
        z = x%y
        x = y
        y = z
    else:
        return z

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 sys
import math
import numpy as np
import itertools


# ひとつ入力
n = int(input())

# リストに入れる
a = [int(i) for i in input().split()] 

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

Submission status: Runtime Error

Solution code:
from math import gcd

N = int(input())
A = [int(x) for x in 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 fraction

def gcd_1(a):
    p = fraction.gcd(a[0],a[1])
    if len(a) > 2:
        for i in range(2,len(a)):
            p = gcd_1([p,a[i]])
    else:
        p = fraction.gcd(a[0],a[1])

    return p

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

print(gcd_1(a))

Submission status: Runtime Error

Solution code:
import fraction

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

A.sort()

res = A[0]
for aa in A:
    res = fraction.gcd(res, aa)

print(res)

Submission status: Runtime Error

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

d = 0


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


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


print(gcd_list(b))

Submission status: Runtime Error

Solution code:
import math
import functools

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

def gcd(numbers):
    return functools.reduce(math.gcd, numbers)
  
print(gcd(a))

Submission status: Runtime Error

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

for i in range(N):
    if i == 0:
        tmp = A[i]
    if i == N:
        break
    else:
        tmp = math.gcd(tmp, A[i])

print(tmp)

Submission status: Runtime Error

Solution code:
import math
n = int(input())
x = [int(i) for i in input().split()]
s = math.gcd(x[0],x[1])
for i in x:
    s = math.gcd(s,i)

print(s)

Submission status: Runtime Error

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

A.sort()

res = A[0]
for aa in A:
    res = math.gcd(res, aa)

print(res)

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int,input().split()))
a = sorted(a)
def gcd(a,b):
  c = a%b
  if c == 1:
    return b
  else:
    return gcd(b,c)
c = 0
for i in a[1:]:
  c_ = gcd(i,a[0])
  if c_ == 1:
    c = 1
    break
  else:
    if c_ < c:
      c = c_
print(c)

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce


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

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

print(gcd(a))

Submission status: Runtime Error

Solution code:
def main():
	N = int(input())
	A = list(map(int, input().split()))
	while(len(A) != 1):
		A = QUICKSORT(A)
		mini = A[0]
		for i in range(1, len(A)):
			if i >= len(A):
				continue
			if A[i] % mini == 0:
				A.pop(i)
			else:
				A[i] = A[i] % mini
		A = QUICKSORT(A)
		piv = A[0]
		for i in range(1, len(A)):
			if i >= len(A):
				continue
			if A[i] == piv:
				A.pop(i)
	print(A[0])

def QUICKSORT(A):
	if len(A) < 1:
		return A
	pivot = A[0]
	left = []
	right = []
	for x in range(1, len(A)):
		if A[x] <= pivot:
			left.append(A[x])
		else:
			right.append(A[x])
	left = QUICKSORT(left)
	right = QUICKSORT(right)
	foo = [pivot]
	return left + foo + right

if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
import math

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

min_last_hp = None

for start in range(N):
    for c in range(start+1, N):
        last_hp = math.gcd(a_list[start], a_list[c])
        if min_last_hp == None:
            min_last_hp = last_hp
        if last_hp < min_last_hp:
            min_last_hp = last_hp

print(min_last_hp)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

n = input()
alist = [int(s) for s in input().split()]

print(gcd_list(alist))

Submission status: Runtime Error

Solution code:
import math
import functools
n = int(input())

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

g = functools.reduce(math.gcd, a)

print(g)

Submission status: Runtime Error

Solution code:
import math

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

max_k = math.gcd(A_arr[0], A_arr[1])
if N > 2:
    for i in range(2, N):
        max_k = math.gcd(max_k, A_arr[i])
else:
    pass

print(max_k)

Submission status: Runtime Error

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

print(s)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
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:
n=int(input())
#for i in range(n):
if n>2:
    A=list(set(list(map(int, input().split(" ")))))
else:
    A=list(map(int, input().split(" ")))

A.sort()
t1=A[0]
t2=A[1]

while t1!=t2:
    #print(t1)
    if t1>t2:
        t1=t1-t2
    else:
        t2=t2-t1

print(t1)

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()))
A.sort()

flag = 0
i = 1
while flag == 0:
    if A[i] % A[0] != 0:
        A[i] = A[i] % A[0]
        A.sort()
        i = 1
    else:
        i += 1
    if i == N-1:
        flag = 1
        print(A[0])

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

li.sort()
while len(li) > 1:
    a = li.pop()
    b = li.pop()
    if a % b == 1:
        li[0] = 1
        break
    if a % b != 0:
        li.append(a % b)
    li.append(b)
    li.sort()
print(li[0])

Submission status: Runtime Error

Solution code:
import bisect
n = int(input())
a = list(int(i) for i in input().split())
a.sort()
flag = 1
sa = [1]*(n-1)
for i in range(n-1):
  sa[i] = a[i+1]-a[i]
  if sa[i] != 0: flag = 0
if flag == 1: 
  print(min(a))
  exit()
else:
 for i in range(n):
  if a[i]%(min(sa))!= 0:
   a[i] = a[i]%(min(sa))
 
print(min(a))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import sympy
def gcd(LIST):
    ans=LIST[0]
    for member in LIST[1:]:
        ans=sympy.gcd(ans,member)
    return ans
N=int(input())
A=list(map(int,input().split()))
print(gcd(A))

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce

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

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

print(gcd(*a))

Submission status: Runtime Error

Solution code:
n=int(input())
#for i in range(n):
A=list(set(list(map(int, input().split(" ")))))

A.sort()
t1=A[0]
t2=A[1]

while t1!=t2:
    #print(t1)
    if t1>t2:
        t1=t1-t2
    else:
        t2=t2-t1

print(t1)

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 numpy as np

N = input()
A = np.fromiter(map(int, input().split()), dtype=np.int64)
print(np.gcd.reduce(A))

Submission status: Runtime Error

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

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

max_gcd = L[0]

for i in range(1, N):
    max_gcd = gcd(max_gcd, L[i])

print(max_gcd)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
#N, M = map(int, input().split())
#
#ans = [0 for i in range(M)]
#
#for i in range(N):
#    tmp = list(map(int, input().split()))
#    for j in range(tmp[0]):
#        ans[tmp[j]]+=1
#        
#now = 0
#        
#for i in range(M):
#    if ans[i]==N:
#        now+=1
#        
#print(now)
import math

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

        
ans = 0
now = a[0]

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

    
print(now)

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:
# -*- coding: utf-8 -*-
import math
from functools import reduce

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

N = int(input())

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

print(gcd_list(As))

Submission status: Runtime Error

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

import math
from functools import reduce

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

print(gcd_list(A))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import fraction

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

a_min = min(a)
ans = 1e10
for i in a:
    tmp = fraction.gcd(a_min, i)
    if(tmp < ans): ans = tmp

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:
n=int(input())
l=list(map(int,input().split()))
ans=0
def gcd(a,b):
    if b==0:return a
    return gcd(b,a%b)
if n==1:
    ans=x[0]
else:
    element = gcd(x[0], x[1])
    if n==2:
      ans=element
    else:
        for i in range(2,n):
            element=gcd(element,x[i])
        ans=element
print(ans)

Submission status: Runtime Error

Solution code:
from heapq import heappush
N = int(input())
li = list(map(int,input().split()))

li.sort()
while len(li) > 1:
    a = li.pop()
    b = li.pop()
    if a % b != 0: heappush(li,a % b)
print(li[0])

Submission status: Runtime Error

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

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 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:
import math
from functools import reduce
N = int(input())
A = list(map(int, input().split()))
num = reduce(math.gcd, A)
print(num)

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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

print(gcd)

Submission status: Runtime Error

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

print(sympy.gcd(a))

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n = int(input())
a = list(map(int, input().split()))
while(len(a) != 1):
    a.sort()
    for i in range(1, len(a) - 1):
        a[i] = a[i] % a[0]
        if a[i] <= 0:
            del a[i]
    if len(a) == 2:
        a[1] = a[1] % a[0]
        a.sort()
        if a[0] == 0:
            del a[0]
            break
        a[1] = a[1] % a[0]
        a.sort()
        del a[1]
    if len(a) == 1:
        break
    
print(a[0])

Submission status: Runtime Error

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

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

print(gcd(*a))

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())
a = list(map(int,input().split()))
mina = max(a)
for i in range(n-1):
    mina = min(mina,math.gcd(a[i],a[i+1]))
print(mina)

Submission status: Runtime Error

Solution code:
import math

def main():
    N=int(input())
    ary = list(map(int,input().split()))
    ans = ary[0]
    for elem in ary:
        ans = math.gcd(ans,elem)
    print(ans)
    
if __name__=='__main__':
    main()

Submission status: Runtime Error

Solution code:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())|	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]

import collections
import math
from functools import reduce

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

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

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

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

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

print(gcd_list(numbers))

Submission status: Runtime Error

Solution code:
import math

N = int(input())

A = list(map(int, input().split()))
a = A[0]
for i in range(1, len(A)):
    a = math.gcd(a, A[i])

print(a)

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

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