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:
n = int(input())
tmp = input()
an = []
for t in tmp.split():
    an.append(int(t))

while True:
    # 最小値を抽出する
    # 最小値以外の要素に対し、int(tmp/min)*minを引く
    min_tmp = 0
    for i in range(len(an)):
        if(an[i] < an[min_tmp] and an[i] > 0):
            min_tmp = i

    # i_min = an.index(min(an))
    i_min = min_tmp
    for i in range(len(an)):
        if i == i_min:
            continue
        an[i] = an[i] - int(an[i]/an[i_min]) * an[i_min]

    flag = True
    for i in range(len(an)):
        if(an[i] > 0 and not i == i_min):
            flag = False
    if flag:
        break

print(an[i_min])

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))   
if len(b)==1:
    print(b[0])
    exit()
else:
    c=sorted(b)
    x=1
    while x>0:
        v=c[0]
        for i in range(len(c)):
            if i!=0:
                c[i]=c[i]%v
        c.remove(0)
        c=sorted(list(set(c)))
        if len(c)==1:
            print(c[0])
            exit()
        if c[0]==1:
            x=0
print(1)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))   
if len(b)==1:
    print(b[0])
    exit()
else:
    c=sorted(b)
    x=1
    while x>0:
        v=c[0]
        for i in range(len(c)):
            if i!=0:
                c[i]=c[i]%v
        c.removed(0)
        c=sorted(list(set(c)))
        if len(c)==1:
            print(c[0])
            exit()
        if c[0]==1:
            x=0
print(1)

Submission status: Runtime Error

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

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

while len(x) > 1:
    i = 0
    next = []
    while i < len(x) - 1:
        next.append(gcd(x[i], x[i+1]))
        i += 2

    x = [] + next

print(x[0])

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())
tmp = input()
an = []
for t in tmp.split():
    an.append(int(t))

while True:
    # 最小値を抽出する
    # 最小値以外の要素に対し、int(tmp/min)*minを引く
    try:
        min_tmp = 0
        for i in range(len(an)):
            if(an[i] < an[min_tmp] and an[i] > 0):
                min_tmp = i

        # i_min = an.index(min(an))
        i_min = min_tmp
        for i in range(len(an)):
            if i == i_min:
                continue
            an[i] = an[i] - int(an[i]/an[i_min]) * an[i_min]

        flag = True
        for i in range(len(an)):
            if(an[i] > 0 and not i == i_min):
                flag = False
        if flag:
            break
    except:
        import pdb; pdb.set_trace()

print(an[i_min])

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

def gcd_list(numbers):
    return reduce(math.gcd, numbers)
n = int(input())
listA=list(map(int, input().split()))
print(gcd_list(listA))

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
def read():
    return int(input())

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

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

n = read()
a = reads()
print(gcd(a))

Submission status: Runtime Error

Solution code:
import math
import functools
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())
2.b = list(map(int,input().split()))
3.b.sort()
4.     
5.d = b[0] + 0
6. 
7.while len(b) > 1 :
8.    for i in range(1,len(b)) :
9.        b[i] = b[i] % b[0]
10.    if b.count(0) == len(b)-1 :
11.        d = b[0]
12.        break
13.    else :
14.        b.sort()
15.        for j in range(b.count(0)) :
16.            b.remove(0)
17.print(d)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
import math
from functools import reduce

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

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

def main():    
    N = int(input())
    lst= list(map(int,input().split()))
    print(gcd_list(lst))
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
n = int(input())
l = list(map(int,input().split()))
ans = min(l)
if ans == 1:
    print(ans)
else:
    l_set = set(l)
    for i in range(n):
        for j in range(i,n):
            if l[i] % l[j] != 0 :
                l_set.add(l[i] % l[j] )
    l_set = sorted(list(l_set))
    print(min([l_set[i+1] - l_set[i] for i in range(len(l_set)-1)]))

Submission status: Runtime Error

Solution code:

while True:
    for n in range(int(N)):
        if n!=index and list_monster[n]>=1:
            list_monster[n] = list_monster[n] - list_monster[index]
            
        elif list_monster[n]<1:
            num = num+1
    min_monster = int(min(list_monster))
    index = list_monster.index(min(list_monster))
    if num==count:
        break
   # print(sec_list)

#print(sec_list)

for i in range(int(N)):
    if list_monster[n]>=1:
        sec_list.append(list_monster[n])
        
print(min(sec_list))

Submission status: Runtime Error

Solution code:
import math

num = int(input())
val = input().split(" ")
val.sort(reverse=True)
s = set(val)
if len(s) == 1:
  print(s[0])
else:
  a = math.round(int(val[1]) - int(val[0]))
  b = math.round(int(max(val)) / a)
  c = int(max(val)) - a * b
  print(c)

Submission status: Runtime Error

Solution code:
import numpy as n;print([input(),n.gcd.reduce(list(map(int,input().split())))][1])

Submission status: Runtime Error

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *
 
n = int(input())
a = list(map(int, input().split()))
a = deque(sorted(a))
ans = 0
for i in a:
    ans = math.gcd(ans, i)
print(ans)

Submission status: Runtime Error

Solution code:
n = int(input())
a = sorted(map(int,input().split()))
b = [a[i] - a[i-1] for i in range(1,n) if a[i] - a[i-1] != 0]

amin = min(a)
c = [i % amin for i in amin if i % amin != 0]
if c:
    c = min(c)
    amin = min(amin,c)


if b:
    b = min(b)
    d = [i % b for i in a if i % b != 0]
    if d:
        d = min(d)
        b = min(b,d)
    amin = min(amin,b)



print(amin)

Submission status: Runtime Error

Solution code:
import numpy as np

n = int(input())
A = np.array([int(i) for i in input().split()])

A=np.sort(A)
s=A[0]
for i in range(max([n, s])):
    c = A[0]
    A = A % c
    A[0] = c
    z=A.count(0)
    A=np.sort(A)[z:]
    for j in range(len(A)):
        if A[0] != 0:
            break
        A = np.delete(A, 0)
    if len(A) == 1:
        break
print (A[0])

Submission status: Runtime Error

Solution code:
from fractions import gcd 

n = int(input())
a_set = set(map(int, input().split()))
max_a = max(a_set)
min_sub = max_a


if len(a_set) == 1:
    print(a_list[0])
    exit()
elif 1 in a_set:
    print(1)
    exit()
else:
    for val in a_set:
        min_sub = min(gcd(max_a, val), min_sub)
        if min_sub == 1:
            print(1)
            exit()
print(min_sub)

Submission status: Runtime Error

Solution code:
N = int(input())
As = list(map(int, input().split()))
As.sort()
 
if N == 2:
    small_As = [As[0], As[1] ]
    tmp = small_As[1] - small_As[0]
else:
    small_As =[As[0]]
    setAs = set(As)
    small_As.append(setAs[1])
 
while tmp > 0:
    tmp = small_As[1] - small_As[0]
    small_As.append(tmp)
    small_As.sort()
 
    
print(small_As[1])
N = int(input())
As = list(map(int, input().split()))
As.sort()

small_As = [As[0], As[1] ]
tmp = small_As[1] - small_As[0]

while tmp > 0:
    tmp = small_As[1] - small_As[0]
    small_As.append(tmp)
    small_As.sort()

    
print(small_As[1])

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input())
hp = [int(x) for x in input().split()]
hp.sort()
hp = np.array(hp)

ans = np.amin(hp)

for i in range(n - 1):
  a = hp[i + 1:] % hp[i]
  a = a[a > 0]
  a = np.amin(a)
  if a > 0 and ans > a:
    ans = a

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
set(a)
v=a[-1]
a[-1]=a[-1]%a[-2]
a.sort()
l=a[-1]
i=1
while i<=n:
    while v!=l:
        v=a[-1]
        a[-1]=a[-1]%a[-(i+1)]
        a.sort()
        l=a[-1]
    if a[-1]==0 or a[-1]==1:
        break
    i+=1
if a[-1]==0:
    print(v)
else:
    print(a[0])

Submission status: Runtime Error

Solution code:
import numpy as np

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

def numpy_gcd(a, b):
    a, b = np.broadcast_arrays(a, b)
    a = a.copy()
    b = b.copy()
    pos = np.nonzero(b)[0]
    while len(pos) > 0:
        b2 = b[pos]
        a[pos], b[pos] = b2, a[pos] % b2
        pos = pos[b[pos] != 0]
    return a

while len(x) > 1:
    i = 0
    next = []
    while i < len(x) - 1:
        next.append(numpy_gcd(x[i],x[i+1]))
        i += 2

    x = [] + next

print(x[0])

Submission status: Runtime Error

Solution code:
import math
from functools import reduce
n=int(input())
number=input()
number=[int(x.strip()) for x in number.split()]
def gcd_list(numbers):
    return reduce(math.gcd, numbers)
print(gcd_list(number))

Submission status: Runtime Error

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

tempAns = max(a)
newList = []
for i in range(n):
    x = a[i]
    newx = x
    for j in range(n):
        if j == i:
            continue
        tempNewx = x%a[j]
        if tempNewx < newx and tempNewx > 0:
            newx = tempNewx
    newList[i] = newx

ansList = []
for i in range(n):
	for k in range(n):
        tempansk= a[i] % newList[k]
        if tempansk < 0 and a[i] < tempansList:
        	a[i] = tempansk
           
        
print(min(a)

Submission status: Runtime Error

Solution code:
n = int(input())
hp = [0] * (n+1)
hp = list(map(int, input().split()))

hp = list(set(hp))
if len(hp) == 1:
    print(hp[0])
elif min(hp) == 1:
    print(1)
elif any((x % 2 == 1 for x in hp)):
    print(1)
elif min(hp) == 2:
    print(2)
elif min(hp) > 2:
    diff = [0] * (n+1)
    for i in range(len(hp))+1:
        diff[i] = abs(hp[i] - hp[i+1])
    print(min(diff))

Submission status: Runtime Error

Solution code:
result = [0 for i in range(0,len(al)**2)]
for i in range(len(al)):
    for j in range(len(al)):
        result = abs(i-j)
print(min(result))

Submission status: Runtime Error

Solution code:
import collections
import itertools
import random

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

for j in a:
  if len(a) > 1:
	for i in range(len(a)):
  		random.shuffle(a)
  		a[i] = a[i+1]
  		if a[i]==0:
    		del a[i]
  		else:
    		break
	else:
      print(a)

Submission status: Runtime Error

Solution code:
n=int(input())
a_list=list(map(int, input().split()))
a_list.sort()
 
a,b=a_list[:2][0], a_list[:2][1]
while 1:
  if a>b:
    a=a-b
  elif a<b:
    b=b-a
  elif a==b:
    print(a)
    break
n=int(input())
a_list=list(map(int, input().split()))
a_list.sort()

a,b=a_list[:2][0], a_list[:2][1]
while 1:
  if a>b:
    a=a-b
  elif a<b:
    b=b-a
  elif a==b:
    print(a)
    break

Submission status: Runtime Error

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

def gcd(mn, xn):
  if xn == 0:
    return mn
  else:
    return gcd(xn, mn%xn)

ans = 0  
for i in range(N):
  if i < N-1:
    ans = gcd(num_li[i], num_li[i+1])
    if ans == 1:
      print(1)
      exit()
    else:
      ans += gcd(num_li[i], num_li[i+1] 
  
print(ans/N)

Submission status: Runtime Error

Solution code:
import numpy as np
n = input()
hp = [int(x) for x in input().split()]
hp.sort()
hp = np.array(hp)

ans = np.amin(hp)

for i in range(n - 1):
  a = hp[i + 1:] % hp[i]
  a = a[a > 0]
  a = np.amin(a)
  if a > 0 and ans > a:
    ans = a

print(ans)

Submission status: Runtime Error

Solution code:

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

A.sort()
check = []
while True:
    min_num = A[0]
    for i in A:
        # 余りのリスト
        if
        check.append(i%A[0])
    check[0] = min_num
    if A[1] - A[0]>0:
        A[1] = A[1] - A[0]
    else:
        break
    A = check
    A.sort()

print(A[0])

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
j = 0
A.sort()
for n in A:
	if n%2 == 1:
		j = 1
a = 0
for n in range(1, len(A)-1):
	if A[n] % A[0] == 1
		a = 1
if a == 0:
	j = 3
if A[0] == A[-1]:
	j = 2
if j == 0:
	print(2)
elif j == 1:
	print(1)
elif j == 3:
	print(A[0])
else:
	print(A[0])

Submission status: Runtime Error

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

while len(A)!=1:
#for i in range(2):
    A.sort()
    if A.count(0):A.remove(0)
    for i in range(len(A)-1):            
        A[i+1]=A[i+1]%A[0]

print(max(A))

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:
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

while(a[-1] != 1):
	for i in range(len[a]):
		if a[-i] == 0:
			continue
		else:
			m = a[-i]
			break
	b = []

	for i in range(len(a) - 1):
		b.append(a[i] % m)

	if  max(b) == 0:
		print(m)
		exit()
	else:
		b.append(m)
		a = sorted(b, reverse=True)
		print(b)
print('1')

Submission status: Runtime Error

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

min_a=float('inf')
b=set()
for i in range(n):
    for i2 in range(n):
        if i == i2:
            continue
        tmp=a[i]%a[i2]
        if tmp != 0:
            b.add(tmp)
            if min_a > tmp:
                min_a = tmp
        else:
            if min_a > a[i2]:
                min_a = a[i2]

for bi in b:
    for a in ai:
        tmp=ai%bi
        if tmp != 0:
            if min_a > tmp:
                min_a = tmp
        else:
            if min_a > bi:
                min_a = bi
print(min_a)

Submission status: Runtime Error

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

while(a[-1] != 1):
	for i in range(a):
		if a[-i] == 0:
			continue
		else:
			m = a[-i]
			break
	b = []

	for i in range(len(a) - 1):
		b.append(a[i] % m)

	if  max(b) == 0:
		print(m)
		exit()
	else:
		b.append(m)
		a = sorted(b, reverse=True)
		print(b)
print('1')

Submission status: Runtime Error

Solution code:
def f(a):
    if len(a) == 2:
        if a[1] % a[0] == 0: return a[0]
        elif a[0] % 2 == 1 or a[1] % 2 == 1: return 1
        else: return 2
    else:
        return f([f(a[:len(a)//2]), f(a[len(a)//2:])])

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

Submission status: Runtime Error

Solution code:
N = int(input())
monster = list(map(int, input().split()))
if 1 in monster:
  print(1)
else:
  monster.sort()
  min1, min2 = monster[0], monster[1]
  while min1 >= 0 and min2 > 0:
    if min1 <= min2:
      min2 = min2 % min1
    else:
      min1 = min1 % min2
  print(max(min1, min2))

Submission status: Runtime Error

Solution code:
def decice_winner(a, b):
    if a > b and b != 0:
        return b
    else:
        return a
def calc_min(a, b):
    while True:
        if a <= 1 or b <=1:
            return decice_winner(a, b)
        elif a > b and a / b > 0 :
            a = a % b
        elif b > a and b / a > 0:
            b = b % a
        else:
            return decice_winner(a, b)

def main():
    _ = input()
    monsters = list(set([int(n) for n in input().split(" ")]))
    min1 = min(monsters)
    monsters.remove(min1)
    monsters = list(set([n % min1 for n in monsters]))
    monsters.remove(0)
    if len(monsters) == 0:
        print(min1)
    else:
        min2 = min(monsters)
        print(calc_min(min1, min2))

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def f(a):
    if len(a) == 2:
        if a[1] % a[0] == 0: return a[0]
        elif a[0] % 2 == 1 or a[1] % 2 == 1: return 1
        else: return 2
    else:
        return f([f(a[:len(a)//2]), f(a[len(a)//2:])])

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

print(f(a))

Submission status: Runtime Error

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
i=0
while(a[1] != 0):
    a[i+1]=a[i+1]-(a[i+1]//a[i])*a[i]
    a=sorted(a)
    if(a[0] == 0):
        i += 1
        while(a[1] != 0):
            a[i+1]=a[i+1]-(a[i+1]//a[i])*a[i]
            a=sorted(a)
print(a[i+1])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 22:22:17 2019

@author: iwata
"""
import numpy as np
N = input()
c = np.array(map(int, input().split()))
b=0
for i in range(N):
    a = c%c[N]
    if b==0:
        b = min(a)
    if b > min(a):
        b = min(a)
print(b)

Submission status: Runtime Error

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

if A[0] == A[N-1]:
    print(A[0])
elif all([a % A[0] == 0 for a in A]):
    print(A[0])
elif all([a % 2 == 0 for a in A]):
    print(2)
    exit()
a = sorted(list(set(A)))
a1 = a[0] 
a2 = a[1]
a = max(a1,a2)
b = min(a1,a2)
while a != b:
    t = a - b
    a = max(t, b)
    b = min(t, b)
if a != 0:
    print(a)
else:
    print(1)

Submission status: Runtime Error

Solution code:
import numpy as np
n = input()
hp = [int(x) for x in input().split()]
hp.sort()
hp = np.array(hp)

ans = np.amin(hp)

for i in range(n - 1):
  a = np.amin(hp[i+1:] % hp[i])
  if a > 0 and ans > a:
    ans = a

print(ans)

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:
n=int(input())
a=list(sorted(map(int,input().split()),reverse=True))
L=[]
for s in range(len(a)-1):
  x=a[s]
  b=a[s+1:]
  L.extend([x%s for s in b if x%s!=0])
if L!=[]:
  print(min([r%d for r in a for d in L if r%d!=0]))
else:
  print(0)

Submission status: Runtime Error

Solution code:
enems = int(input())

hps = input().split(" ")
hps.sorted()

cnt = 0
for i in range(1,enems):
    cnt += hps[i] % hps[0]
    
if (cnt = 0):

else: 
    cnt = 0
    for i in range(1,enems):
        for j in range(0,i):
            cx = hps[j] % hps[i]
            if (cnt == 0 OR cx < cnt):
                cnt = cx
print(cnt)

Submission status: Runtime Error

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

e.sort()
amari = e[0]
while e[n-2]:
    for i,v in enumerate(e):
        if v != 0:
            e[i] = v % e[0]
            e.sort()
    
print(e[n-2])

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
A_ = []
tmp = A[1]-A[0]
A_1 = [i for i in A]
A_1 = [i%A[0] for i in A_1]
A_2 = [2*i for i in A]
A_2 = [i%A[0] for i in A_2]
A_3 = [i for i in A]
A_3 = [i%tmp for i in A_3]
A_ = A_1 + A_2 + A_3 
A_ = sorted(set(A_))
if A_ == [0]*len(A_):
  print(A[0])
else:
  print(A_[1])

Submission status: Runtime Error

Solution code:
n = int(input())
from functools import reduce
from fractions import gcd
import numpy as np
arr = np.array(list(set(map(int, input().split()))))

from collections import deque
q = deque([arr])
ans = arr.min()
mi = reduce(gcd, arr)
while len(q) > 0:
    ar = q.popleft()
    ans = min(ar.min(), ans)
    if ans <= mi:
        break
    if ans <= reduce(gcd, ar):
        continue
    for mon in ar:
        tmp = (ar - 1) % mon + 1
        if np.any(ar != tmp):
            q.append(np.unique(tmp).sort())

print(ans)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=list(set(a))   
if len(b)==1:
    print(b[0])
    exit()
else: 
    x=1
    while x>0:
        c=sorted(b)
        c[1]=c[1]-c[0]
        c=sorted(list(set(c)))
        if c[0]==1:
            x=0
        if len(c)==1:
            print(2):
            exit()
print(1)

Submission status: Runtime Error

Solution code:
enems = int(input())

hps = input().split(" ")
hps.sorted()

cnt = 0
for i in range(1,enems):
    cnt += hps[i] % hps[0]
    
if (cnt = 0):

else: 
    cnt = 0
    for i in range(1,enems):
        for j in range(0,i):
           cx = hps[j] % hps[i]
           if (cnt == 0 OR cx < cnt):
            cnt = cx
print(cnt)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 20:59:16 2019

@author: doppe
"""
import math
from functools import reduce

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


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

print(gcd_list(A))

Submission status: Runtime Error

Solution code:
N = int(input())
monster = list(map(int, input().split()))
if 1 in monster:
  print(1)
else:
  monster.sort()
  min1, min2 = monster[0], monster[1]
  while min1 >= 0 and min2 > 0:
    if min1 < min2:
      min2 = min2 % min1
    else:
      min1 = min1 % min2
  print(max(min1, min2))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int,input().split()))
A = sorted(A)
A_ = []
A_1 = [i for i in A]
A_1 = [i%A[0] for i in A_1]
A_2 = [2*i for i in A]
A_2 = [i%A[0] for i in A_2]
A_3 = [i for i in A]
A_3 = [i%(A[1]-A[0]) for i in A_3]
A_ = A_1 + A_2 + A_3 
A_ = sorted(set(A_))
if A_ == [0]*len(A_):
  print(A[0])
else:
  print(A_[1])

Submission status: Runtime Error

Solution code:
print [input(),reduce(raw_input().split(),gcd)][1]

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input)
hp = [int(x) for x in input().split()]
hp = np.array(hp)

ans = np.amin(hp)

for i in range(n):
  a = np.amin(hp % hp[i])
  if a > 0 and ans > a:
    ans = a

print(ans)

Submission status: Runtime Error

Solution code:
number=int(input())
hitpoint=list(map(int,input().split()))
xyz=[]
png=[]
m=min(hitpoint)
for i in range(len(hitpoint)):
    xyz.append(hitpoint[i]%2)
if hitpoint.count(hitpoint[0])==len(hitpoint):
    print(hitpoint[0])
elif hitpoint[len(hitpoint)]%m==0:
    for i in range(len(hitpoint)):
        png.append(hitpoint[i]%m)
    if png.count(0)==len(png):
        print(min(hitpoint))
    else:
        if hitpoint.count(1)!=0:
            print(1)
        elif xyz.count(0)!=len(xyz):
            print(1)
        elif xyz.count(1)==len(xyz):
            print(1)
        else:
            print(2)
elif hitpoint.count(1)!=0:
    print(1)
elif xyz.count(0)!=len(xyz):
    print(1)
elif xyz.count(1)==len(xyz):
    print(1)
else:
    print(2)

Submission status: Runtime Error

Solution code:
N = int(input())
monster = list(map(int, input().split()))
if 1 in monster:
  print(1)
else:
  monster.sort()
  min1, min2 = monster[0], monster[1]
  while min1 >= 0 and min2 > 0:
    if min1 < min2:
      min2 = min2 % min1
    else:
      min1 = min1 % min2
  print(min1 + min2)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce



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


N = input()
A = input().split()
for i in range(len(A)):
    A[i] = int(A[i])
answer = gcd_list(A)
print("{}".format(answer))

Submission status: Runtime Error

Solution code:
N = int(input())
A = list(map(int, input().split()))
if all(A[0]==a for a in A):
    print(A[0])
else:
    B = []
    D = []
    for a in A:
        for i in range(len(A)):
            if A[i]%a != 0:
                B = append(A[i]%a)
                C = list(set(B))
    for i in range(len(C)-1):
        D.append(abs(C[i]-C[i+1]))
    print(min(min(C),min(D)))

Submission status: Runtime Error

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

import math
import itertools

m = min(A)

for v in itertools.combinations(A,2):
    m1 = math.gcd(*v)
    if m > m1:
        m = m1
print(m)

Submission status: Runtime Error

Solution code:
N = int(input())
As = input().split()
import math
from functools import reduce
A = []

for Xs in As:
    A.append(int(Xs))


print(reduce(math.gcd, A))

Submission status: Runtime Error

Solution code:
number=int(input())
hitpoint=list(map(int,input().split()))
xyz=[]
png=[]
m=min(hitpoint)
for i in range(len(hitpoint)):
    xyz.append(hitpoint[i]%2)
if hitpoint.count(hitpoint[0])==len(hitpoint):
    print(hitpoint[0])
elif hitpoint[len(hitpoint)]%m==0:
    for i in range(len(hitpoint)):
        png.append(hitpoint[i]%m)
    if png.count(0)==len(png):
        print(min(hitpoint))
elif hitpoint.count(1)!=0:
    print(1)
elif xyz.count(0)!=len(xyz):
    print(1)
elif xyz.count(1)==len(xyz):
    print(1)
else:
    print(2)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce

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



reduce(math.gcd, al)

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
v=a[-1]
a[-1]=a[-1]%a[-2]
a.sort()
l=a[-1]
while v!=l:
    a.sort()
    v=a[-1]
    a[-1]=a[-1]%a[-2]
    a.sort()
    l=a[-1]
if a[-1]==0:
    print(v)
else:
    print(a[-1])

Submission status: Runtime Error

Solution code:
n = int(input())
a = set([int(i) for i in input().split()])
if len(a) == 1:
    print(a[0])
else:
    list_a = set([max([mons%i for i in a]) for mons in a])
    list_b = set([min([m%i for i in list_a if i != m and i!=0]) for m in list_a])
    print(min([i for i in list_b if i != 0]))

Submission status: Runtime Error

Solution code:
import numpy as np
n = int(input()) 
#n=3
lst = [int(i) for i in input().split()]
#lst = [2, 10, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [1000000000, 1000000000, 1000000000]
hps = set(lst)
while(1):
    hps = sorted(hps)
    #print(hps)
    if(hps[0]==0): break
    if(hps[0]==hps[len(hps)-1]): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

Submission status: Runtime Error

Solution code:
num = int(input())
mons = map ( int , input ().split())
aft = mons
at = min(aft)
while len(aft) >1:
    aft = [i % at for i in aft]
    aft = [n for n in aft if n > 0]
    at = min(aft)
if len ( aft ) == 1 :
    res = at
else:
    res = 0
print ( res )

Submission status: Runtime Error

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

if len(set(a)) == 1:
    print(a[0])
else:
    a.sort()
    for i in range(1, 10 ^ 9+1):
        count = i
        for i in range(1, len(a)):
            x = a[i] + count
            for j in range(i):
                x = x % a[i-1-j]
        if x == 0:
            break

    print(count)

Submission status: Runtime Error

Solution code:
N = int(input())
list_A = list(map(int,input().split()))
for _ in range(100):
    min_A = min(list_A)
    list_A.remove(min_A)
    l = np.array([list_A]) % min_A
    lr = list(l.ravel())
    lr.append(min_A)
    list_A = [x for x in lr if x != 0]
    if len(list_A) <= 1:
        break
print(list_A[0])

Submission status: Runtime Error

Solution code:
import fraction
from functools import reduce


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


N = input()
A = input().split()
for i in range(len(A)):
    A[i] = int(A[i]) 
print("{}".format(gcd_list(A)))

Submission status: Runtime Error

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

lcm = sympy.gcd(A)
print(lcm)

Submission status: Runtime Error

Solution code:
n = int(input()) 
#n=3
lst = [int(i) for i in input().split()]
#lst = [2, 10, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [1000000000, 1000000000, 1000000000]
hps = set(lst)
while(1):
    hps = sorted(hps)
    #print(hps)
    if(hps[0]==0): break
    if(hps[0]==hps[n-1]): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

Submission status: Runtime Error

Solution code:
n = int(input()) 
#n=3
lst = [int(i) for i in input().split()]
#lst = [2, 10, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [1000000000, 1000000000, 1000000000]
hps = set(lst)
while(1):
    hps = sorted(hps)
    print(hps)
    if(hps[0]==0): break
    if(hps[0]==hps[n-1]): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

Submission status: Runtime Error

Solution code:
n = int(input())
li = list(map(int,input().split()))
while len(li) > 1:
    i = n - 1
    while i > 0:
        if li[i] <= 0:
            del li[i]
        i = i - 1
    n = len(li)
    a = min(li)
    minn = li.index(min(li))
    def jj(n):
      return n - a
    li = map(jj,li)
    li[minn] = li[minn] + min(li)
print(li[0])

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 = [int(_) for _ in input().split()]

print(gcd_list(A))

Submission status: Runtime Error

Solution code:
import math
n=int(input())
k=list(map(int,input().split()))
c=k[0]

for i in range(len(k)):
    c=math.gcd(c,k[i])
    
print(c)

Submission status: Runtime Error

Solution code:
n=int(input())
a=list(map(int,input().split()))
if a.count(a[0])==n:
    print(a[0])
else:
    a.sort()
    v=a[-1]
    a[-1]=a[-1]%a[-2]
    a.sort()
    l=a[-1]
    while v!=l:
        a.sort()
        v = a[-1]
        a[-1] = a[-1] % a[-2]
        a.sort()
        l = a[-1]
    if min(a)==0:
        print(v)
    else:
        print(min(a))

Submission status: Runtime Error

Solution code:
N=int(input())
a_list=[]
a_list = list(map(int, input().split())) # "1 2 3"と入力
min_num=min(a_list)
nokori_list=[i%min_num for i in a_list if i%min_num!=0]

if len(nokori_list)==0:
    print(min_num)
else:
    can_min=min(nokori_list)
    futuer_min=min_num%can_min
    while futuer_min>0:
        big=max(can_min,futuer_min)
        small=min(can_min,futuer_min)
        futuer_min=big%small
        if futuer_min==0:
            answer=small
            break
        answer=small
    print(answer)

Submission status: Runtime Error

Solution code:
import math
from functools import reduce


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


N = input()
A = input().split()
for i in range(len(A)):
    A[i] = int(A[i]) 
print("{}".format(gcd_list(A)))