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: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
b=[]
e=False
while e==False:
    b=[]
    a_m=[]
    for i in a:
        if i!=0:
            a_m.append(i)
    print(a_m)#a=m a of positive
    temp=min(a_m)
    #5
    for i in a:
        g=i%temp
        if i==temp:
            b.append(i)#myself
        elif g!=0:
            b.append(i%temp)
        
    #b is only positive
    print("temp:",temp)
    print("b",b)
    if not b:#if empty 
        ans=temp
        e=True
         
    else:
        if temp==min(b):
            ans=temp
            e=True
        else:
            a=b
            print(a)
                
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
monsters = list(map(int, input().split()))
def gcd(a, b):
    if b == 0:  
        return a
    else:
        return gcd(b, a%b)
gcd(4,2)

def gcd_more(a):
    ans = a[0]
    for i in range(1,len(a)):
        ans = gcd(ans, a[i])
    return ans
gcd_more(monsters)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
"""
import math
N = int(input())
A = list(map(int, input().split()))
g = math.gcd(A[0], A[1])
for a in A:
    if g == 1:
        break
    g = math.gcd(g, a)
print(g)
"""
def gcd(a, b):
    if b == 0:
        return a
    else:
        return gcd(b, a % b)
N = int(input())
A = list(map(int, input().split()))
g = gcd(A[0], A[1])
for a in A:
    if g == 1:
        break
    g == gcd(g, a)
print(g)

Submission status: Wrong Answer

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

monster.sort()
while monster[0] > 0:
    tmp = monster[1] - monster[0]
    if monster[0] > tmp:
        monster[1] = monster[0]
        monster[0] = tmp
    else:
        monster[1] = tmp
    monster.sort()

print(monster[1])

Submission status: Wrong Answer

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

a, b = monster[0:2]
while a > 0:
    tmp = b - a
    if a > tmp:
        b = a
        a = tmp
    else:
        b = tmp

print(b)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))
while True:
	print(A)
	min_a = A.min()
	new_A = np.where(A%min_a==0,min_a,A%min_a)
	A = new_A
	if (np.all(A == A[0])):
		break
print(A.min())

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())

a_set = set(map(int, input().split()))

if len(a_set) == 1:
    print(list(a_set)[0])
else:
    b_set = set(map(lambda x: x % 2, a_set))
    print(1 if 1 in b_set else 2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def gcd(a,b):
    lt,gt = sorted([a,b])
    if lt == 0:
        return gt
    else:
        return gcd(gt % lt,lt)

def q3():
    N = int(input())
    A = list(map(int,input().split()))
    assert(N == len(A))
    ret = A[0]
    for n in range(1,N):
        ret = gcd(ret,A[n])
    print(ret)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
A.sort()
A.reverse()
minHP = 10**9

for i in range(N):
    HP = A[i]
    B = A[i+1:]
    for j in range(len(B)):
        zHP = HP
        if j!= 0:
            if B[j-1]+zHP>B[j]:            
                zHP = B[j-1]+zHP
                
        if HP%B[j] != 0:
            zHP = zHP%B[j]
        else:
            zHP = B[j]

        if HP>zHP:
            HP = zHP
    if minHP > HP:
        minHP = HP
print(minHP)

Submission status: Wrong Answer

Solution code:
n=int(input())
a = [int(x) for x in input().split()]
sort_a = sorted(a)
mini=sort_a[0]
def gcd(a,b):
            if(a%b!=0):
                return a%b
            else:
                return b
for fa in sort_a:
    mini = gcd(fa,mini)
    if(mini ==1):
        break
print(mini)

Submission status: Wrong Answer

Solution code:
from sys import stdin

def fun():
    n = (int(i) for i in input().split())

    l = [int(x) for x in stdin.readline().rstrip().split()]

    l = list(set(l))
    l.sort()

    while 1 < len(l):
        print(l)
        k = len(l)
        for i in range(1, k):
            if l[k-i]%l[0] == 0:
                l.pop(k-i)
            elif l[k-i] - l[k-i-1] == 1:
                print(1)
                return
            else:
                l[k-i] = l[k-i]%l[0]
        #l = [e for e in l if e != 0]
        l = list(set(l))

        if l[0]==1:
            print(1)
            return

    print(l[0])
    return

if __name__ == '__main__':
    fun()

Submission status: Wrong Answer

Solution code:
def sort(hp):
    for i in range(len(hp)-1):
        for j in range(i+1,len(hp)):
            if hp[i]>hp[j]:
                tmp=hp[i]
                hp[i]=hp[j]
                hp[j]=tmp
if __name__=='__main__':
    n=input() 
    hp=[int(i) for i in input().split()]
    sort(hp)
    hp_min=hp[0]       
    for i in range(1,len(hp)):
        if hp[i]%hp_min!=0 and hp[i]%hp_min<hp_min:
            hp_min=hp[i]%hp_min

    print(hp_min)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
# print(N,A,sep="\n")
data = set(A)

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

def culc(data):
  A_min=min(data)
  if len(set(map(lambda x: x%A_min,data|{0})))==1:
    return A_min
  A.sort()
  ans = A_min
  for i in A[1:]:
    ans=gdc(ans,i)
    if len(set(map(lambda x: x%ans,data|{0})))==1:
      return ans
  return ans

print(culc(data))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
# print(N,A,sep="\n")
data = set(A)

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

def culc(data):
  A_min=min(data)
  if len(set(map(lambda x: x%A_min,data)))==1:
    return A_min
  A.sort()
  ans = A_min
  for i in A[1:]:
    ans=gdc(ans,i)
    if len(set(map(lambda x: x%ans,data)))==1:
      return ans
  return ans

print(culc(data))

Submission status: Wrong Answer

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

while d[1] > d[0]:
    d[1] = d[1] - d[0]
    if d[1] == d[0]:
        print(d[0])
        exit()
    elif d[1] < d[0]:
        a = d[1]
        b = d[0]
        d[0] = a
        d[1] = b
    else:
        continue
print(d[1])

Submission status: Wrong Answer

Solution code:
a=int(input())
lm=list(map(int, input().split()))
mini = min(lm)
ans=[ i % mini for i in lm]
print(mini if ans.count(0) == a else 1)

Submission status: Wrong Answer

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

def gcd(x,y):
    if y ==0:
        return x
    else:
        return gcd(y,x%y)
mon.sort()
mini = mon[0]
for i in range(1,N):
    ans = gcd(mini,mon[i])
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import copy

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

a = list(set(a))
a.sort()
arr = np.array(a)

for c1 in arr:
    o = copy.deepcopy(arr)
    arr %= c1
    for i, each in enumerate(arr):
        if each == 0:
            arr[i] = o[i]

print(min(arr))

Submission status: Wrong Answer

Solution code:
N =int(input())
l =[int(i)for i in input().split()]
l =sorted(l)
mini =l[0]
for i,st in enumerate(l):
    st = st % mini
    if 0 < st < mini:
        if mini%st==0:
            mini =st
        else:
            mini = min(st,mini%st)
print(mini)

Submission status: Wrong Answer

Solution code:
N =int(input())
l =[int(i)for i in input().split()]
l =sorted(l)
min = l[0]
for i,num in enumerate(l[1:]):
    num = num%min
    if num < min and num != 0:
        min = num
print(min)

Submission status: Wrong Answer

Solution code:
monsters = int(input())
monsterabc= [int(x) for x in input().split()]
min(monsterabc)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=sorted(list(map(int,input().split())))
diff=[A[i]-A[i-1] for i in range(1,len(A))]
mind=min(diff)
mina=min(A)
dekai=10**9
flag=True
try:
    ans=A
    for i in range(len(A)):
      ans[i]=min(A[i]%mind if A[i]%mind>0 else dekai,mind,A[i]%mina if A[i]%mina>0 else dekai)
    minans=min(ans)
    while flag==True:
      ans=list(map(lambda x:x%minans if x%minans>0 else dekai,ans))
      if min(ans)<minans:
        minans=min(ans)
      else:
        flag=False
    print(minans)
except ZeroDivisionError:
  print(A[0])

Submission status: Wrong Answer

Solution code:
n=int(input())
A=sorted(list(map(int,input().split())))
diff=[A[i]-A[i-1] for i in range(1,len(A))]
mind=min(diff)
mina=min(A)
dekai=10**9
try:
    ans=A
    for i in range(len(A)):
      ans[i]=min(A[i]%mind if A[i]%mind>0 else dekai,mind,A[i]%mina if A[i]%mina>0 else dekai)
    print(min(ans))
except ZeroDivisionError:
  print(A[0])

Submission status: Wrong Answer

Solution code:
from queue import PriorityQueue
N = int(input())
A = map(int, input().split())
q = PriorityQueue()
for a in A:
    q.put(-a)
x = -q.get()
while not q.empty():
    y = -q.get()
    if y == 0:
        break
    q.put(x % y)
    x = y
print(x)

Submission status: Wrong Answer

Solution code:
from queue import PriorityQueue
N = int(input())
A = map(int, input().split())
q = PriorityQueue()
for a in A:
    q.put(a)
x = q.get()
while not q.empty():
    y = q.get()
    if y == 0:
        break
    q.put(x % y)
    x = y
print(x)

Submission status: Wrong Answer

Solution code:
n = int(input())

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

hitPoint.sort()

a,b = hitPoint[0], hitPoint[1]

while not a==0:
	# print(a, b)
	tmp = b - a
	if tmp <= a:
		a, b = tmp, a
	else:
		a, b = a, tmp

print(b)

Submission status: Wrong Answer

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

def gcd(a, b) :
    if b == 0 :
        return a
    else :
        return gcd(min(a, b), max(a, b) % min(a, b))
      
cur = A[0]
for i in range(1, len(A) - 1) :
    cur = gcd(cur, A[i])
    
print(cur)

Submission status: Wrong Answer

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

def q3():
    N = int(input())
    A = list(map(int,input().split()))
    assert(N == len(A))
    ret = A[0]
    for n in range(1,N - 1):
        ret = gcd(ret,A[n])
    print(ret)
    
q3()

Submission status: Wrong Answer

Solution code:
def gcd(a, b):
    while a != b:
        if a < b:
            b = b - a
        else:
            a = a - b
    return a

n = int(input())
a = [int(x) for x in input().split(" ")]
a.sort()
g = a[n - 1]

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


print(g)

Submission status: Wrong Answer

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

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

ans = line[0]

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

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
for main_loop in range (0,N):    
    A.sort()
    de = A.count(0)
    del A[:de]
    li = len(A)
    if li <= 1:
        break
    if A[0] == 1:
        break
    for x in range(1,li):
        A[x] = A[x]%A[0]
print(A[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
for main_loop in range (0,N):    
    A.sort()
    de = A.count(0)
    del A[:de]
    li = len(A)
    if li <= 0:
        break
    if A[0] == 1:
        break
    for x in range(1,li):
        A[x] = A[x]%A[0]
A.sort()
print(A[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
for main_loop in range (0,N):    
    A.sort()
    de = A.count(0)
    del A[:de]
    li = len(A)
    if li <= 0:
        break
    if A[0] == 1:
        break
    for x in range(1,li):
        A[x] = A[x]%A[0]
print(A[0])

Submission status: Wrong Answer

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

min = min(A)
count = 0
for i in range(n):
    if(A[i]%min != 0):
       count = 1

if(count == 1):
    print("1")
else:
    print(min)

Submission status: Wrong Answer

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

for i in range(n):
    A.append(A[i]%2)

a = 1

for i in range(n,n+n):
    if(A[i] == 1):
        print("1")
        exit()

print(min(A[:n]))

Submission status: Wrong Answer

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

a=A[0]
b=A[1]
gcd=1
for i in range(2,N):
  while 1:
    if a%b == 0:
      gcd=b
      break
    else:
      r = a%b
      a = b
      b = r
  a=gcd
  b=A[i]

print(gcd)

Submission status: Wrong Answer

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

A.sort()
j = 0

while j == 0:
    a = A[1] - A[0]
    A.append(a)
    A.sort()
    if A[0] == A[1] :
        j = 1

print(A[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
s = min(A)
d = [x % s for x in A]
while max(d) > 0:
  d = [e for e in d if e > 0]
  s = min(d)
  d = [x % s for x in d]
print(s)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
s = min(A)
d = [x % s for x in A]
while max(d) > 0:
  s = min([e for e in d if e > 0])
  d = [x % s for x in d]
print(s)

Submission status: Wrong Answer

Solution code:
n = int(input())
alist = list(map(int,input().split()))
alist.sort()
#print(alist)
while len(alist)>= 1 :
  if len(alist) == 1 :
    print(min(alist))
    break
  else:
    a = min(alist)
    blist = [a]
    for k in range(1,len(alist)) :
      j = alist[k] - a
      if j != 0 :
        blist.append(j)
    alist = []
    alist = blist

Submission status: Wrong Answer

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


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


ans = 0

for i in range(len(a)):
    for j in range(i+1, len(a)):
        x = gcd(a[i], a[j])
        if x == 1:
            print(1)
            break

        elif ans == 0:
            ans = x
        elif x < ans:
            ans = x
    if x == 1:
        break

Submission status: Wrong Answer

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

if len(set(a)) == 1:
    print(a[0])
else:
    def gcd(a, b):
        if b % a == 0:
            return a
        else:
            return(gcd(b % a, a))

    a.sort()
    ans = 0

    for i in range(len(a)):
        for j in range(i+1, len(a)):
            x = gcd(a[i], a[j])
            if x == 1:
                print(1)
                break

            elif ans == 0:
                ans = x
            elif x < ans:
                ans = x
        if x == 1:
            break

Submission status: Wrong Answer

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

init = min(A)

if sum(A) % min(A) == 0 :
    print(min(A))
else :
    print(sum(A) % min(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
# print(A)
while len(A) > 1:
    a, b = A[0], A[1]
    c = b % a
    if c == 0:
        A = [a] + A[2:]
    else:
        d = a % c
        if d == 0:
            A = [c] + A[2:]
        else:
            A = [d] + A[2:]
print(A[0])

Submission status: Wrong Answer

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

while len(A)>1:
    A.sort(reverse=True)
    A[0]-=min(A)*(ceil((A[0]-A[1])/min(A))+1)
    if A[0]<1:
        del A[0]
print(A[0])

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
  if x < y:
    a = y
    y = x
    x = a
  
  while y > 0:
    r = x % y
    x = y
    y = r
  
  return x

def main():
  N = int(input())
  a = list(map(int, input().split()))
  
  for i in range(1, len(a)):
    r = gcd(a[0], a[i])
  
  print(r)
    

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
def gcd(x, y):
  if x < y:
    a = y
    y = x
    x = a
  
  while y > 0:
    r = x % y
    x = y
    y = r
  
  return x

def main():
  N = int(input())
  a = list(map(int, input().split()))
  
  for i in range(1, len(a)):
    r = gcd(a[0], a[i])
    if r == 1:
      break
  
  print(r)
    

if __name__ == '__main__':
  main()

Submission status: Wrong Answer

Solution code:
a = int(input())
ar = list(map(int,input().split(" ")))
ar.sort()
br = ar[1:a]
b = ar[0]
while True:
    count = 0
    for r in br:
        if r % b == 0:
            count += 1
        else:
            break
    if count == len(br):
        print(b)
        exit()
    b -= 1

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
for main_loop in range (0,N):    
    A.sort()
    de = A.count(0)
    del A[:de]
    li = len(A)
    if A[0] == 1:
        break
    for x in range(1,li):
        A[x] = A[x]%A[0]
print(A[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
for main_loop in range (0,N):    
    A.sort()
    de = A.count(0)
    del A[:de]
    li = len(A)
    if A[0] == 1:
        break
    print(A)
    for x in range(1,li):
        A[x] = A[x]%A[0]
        print(A[x])
print(A[0])

Submission status: Wrong Answer

Solution code:
#coding:utf-8

n=input()
A=map(int, raw_input().split(" "))
A.sort()
ans=A[0]
for a in A[1:]:
    m=a%ans
    if m!=0:
        ans=min(m,ans)
print(ans)

Submission status: Wrong Answer

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

def yakusuu(p):
	A.reverse()
	for i in range(1,p):
		if A[0] % A[i] == 0:
			A.pop(0)
			return
	else:
		return
def syou(k):
	A.sort()
	if (A[0] == 0)&(k > 0):
		A.pop(0)
		A[k-1] = A[k-1] % A[0]
	else:
		A[k] = A[k] % A[0]
	return A
for i in range(N):
	if len(A) >= 1:
		yakusuu(len(A))
while	len(A) > 1:
	syou(len(A)-1)
print(A[0])

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

n=int(input())
hp=list(map(int,input().split()))
print(hp)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
As.sort()
while True: 
    end = False
    As.sort()
    for i in range (1,N):
        As[i] -= As[0] 
        if As[i] < 1:
            end = True
            break
    if end == True or As[0] == 1:
        print(As[0])
        break

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
while True:
  minnum = As.index(min(As))
  for i in range(len(As)):
    if not i == minnum:
      As[i] -= As[minnum] 
      if As[i] <= 0:
        As[i] = 0
  while True:
    if 0 in As:
      As.remove(0)
    else:
      break
  if len(As) <= 1 or As[minnum] == 1:
    print(As[0])
    break

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
while True:
  minnum = As.index(min(As))
  for i in range(len(As)):
    if not i == minnum:
      As[i] -= As[minnum] 
      if As[i] < 0:
        As[i] = 0
  while True:
    if 0 in As:
      As.remove(0)
    else:
      break
  if len(As) <= 1 or As[minnum] == 1:
    print(As[minnum])
  break

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
while True:
  minnum = As.index(min(As))
  if len(As) <= 1 or As[minnum] == 1:
    print(As[minnum])
  break
  for i in range(len(As)):
    if not i == minnum:
      As[i] -= As[minnum] 
      if As[i] < 0:
        As[i] = 0
  while True:
    if 0 in As:
      As.remove(0)
    else:
      break

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
while True:
  minnum = As.index(min(As))
  for i in range(len(As)):
    if not i == minnum:
      As[i] -= As[0] 
      if As[i] < 0:
        As[i] = 0
  while True:
    if 0 in As:
      As.remove(0)
    else:
      break
  if len(As) <= 1 or As[0] == 1:
    print(As[0])
    break

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
while True:
  minnum = As.index(min(As))
  for i in range(len(As)):
    if not i == minnum:
      As[i] -= As[0] 
      if As[i] < 0:
        As[i] = 0
        break
  while True:
    if 0 in As:
      As.remove(0)
    else:
      break
  if len(As) <= 1 or As[0] == 1:
    print(As[0])
    break

Submission status: Wrong Answer

Solution code:
import numpy as np

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

b = list(map(lambda x: x%2 , a))

def f(a,b):
    if any(a%a.min()):
        if any(b):
            print(1)
            return
        else:
            print(2)  
            return
    
    # 全要素がaの最小値の倍数
    else:
        print(a.min())
        return
    
f(a,b)

Submission status: Wrong Answer

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

b = list(map(lambda x: x%2 , a))

def f(a,b):
    # すべて同じ
    if a == [a[0] for i in range(len(a))]:
        print(a[0])
        return
    
    # 奇数があれば
    elif any(b):
        print(1)
        return
    
    else:
        print(2)

f(a,b)

Submission status: Wrong Answer

Solution code:
N = int(input())
As = list(map(int,input().split()))
As.sort()
print(As)
while True: 
    end = False
    As.sort()
    for i in range (1,N):
        As[i] -= As[0] 
        if As[i] < 1:
            end = True
            break
    if end == True or As[0] == 1:
        print(As[0])
        break

Submission status: Wrong Answer

Solution code:
n=int(input())
l = [int(x) for x in input().split()]

a = max(l)
b = False
while 1:
    c = a
    if a in l:
        l.remove(a)
    n -= 1

    for i in range(n):
        if a%l[i]>0:
            a = l[i]-a%l[i]
            b = True
            break
    if c==a:
        a = a if b else min(l)
        break
print(a)

Submission status: Wrong Answer

Solution code:
N = int(input())
Mo = [int(x) for x in input().split()]
Mo.sort()
Mo.reverse()
last = Mo.pop(0)
for i in range(len(Mo) - 1):
    if last%Mo[i] != 0:
        if last > last - (int(last/Mo[i])*Mo[i]):
            last = last - (int(last/Mo[i])*Mo[i])
    else:
        if last > last - (int(last/Mo[i])*Mo[i]):
            last = last - (int(last/Mo[i] - 1)*Mo[i])
Mo.reverse()
if sum(Mo)%Mo[0] < last and sum(Mo)%Mo[0] != 0:
    print(sum(Mo)%Mo[0])
else:
    print(last)

Submission status: Wrong Answer

Solution code:
N = int(input())
Mo = [int(x) for x in input().split()]
Mo.sort()
Mo.reverse()
last = Mo.pop(0)
print(last)
print(Mo)
for i in range(len(Mo) - 1):
    if last%Mo[i] != 0:
        if last > last - (int(last/Mo[i])*Mo[i]):
            last = last - (int(last/Mo[i])*Mo[i])
    else:
        if last > last - (int(last/Mo[i])*Mo[i]):
            last = last - (int(last/Mo[i] - 1)*Mo[i])
Mo.reverse()
if sum(Mo)%Mo[0] < last and sum(Mo)%Mo[0] != 0:
    print(sum(Mo)%Mo[0])
else:
    print(last)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort(reverse=True)
ans=A[0]
for i in range(1,N):
    l=[ans,A[i]]
    if ans%A[i]!=0:
        l.append(ans%A[i])
    if A[i]%ans!=0:
        l.append(A[i]%ans)
    ans=min(l)
print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
ans=A[0]
for i in range(1,N):
    if A[i]%ans!=0:
        ans=A[i]%ans
print(ans)

Submission status: Wrong Answer

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

A.sort()

def rest( a, b ):
    if b % a > 0: return b % a
    else: return a

while len(A) > 1:
    A.insert( 0, rest( A[0], A[1] ) )
    del A[1:3]

print(A[0])

Submission status: Wrong Answer

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

odd = 0
even =0
M_unique = list(set(M))

for i in range(len(M_unique)):
    if M_unique[i]%2==0:
        even+=1
    else:
        odd+=1

if len(list(set(M)))==1:
    print(M[0])
elif odd>=2 or odd>=1 and even>=1:
    print(1)
else:
    print(min(M))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
import sys

# import bisect
# import math
# import itertools

# 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 gcd(self, x, y):
        if y == 0:
            return x
        else:
            return self.gcd(y, x % y)


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


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

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

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

    print(res)


main()