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:
import itertools
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N = I()
A = IL()

if len(set(A)) != 1:
    absA = [min(A),]
    A.sort()
    for i in range(N-1):
        absA.append(abs(A[i+1]-A[i]))

    npA = np.array(absA,dtype=int)

    minA = np.min(npA)
    npA = npA % minA

    if np.sum(npA == 0) == N:
        print(min(A))
    else:
        print(1)
else:
    print(A[0])

Submission status: Wrong Answer

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]))
    if 0 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: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input()) 
#n=4
lst = [int(i) for i in input().split()]
#lst = [2, 2, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [0, 1, 0]
hps = np.array(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]
for i in range(len(hps)):
    if(hps[i]==0): continue
    print(hps[i])

Submission status: Wrong Answer

Solution code:
n = int(input())
array = [int(k) for k in input().split()]
array.reverse()
result = 0
m = 0
for i, num in enumerate(array):
    if i == 0:
        m = num
    else:
        if m % num != 0:
            result += num - m % num
print(result)

Submission status: Wrong Answer

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

if A[0] == A[N-1]:
    print(A[0])
    exit()
elif all([a % A[0] == 0 for a in A]):
    print(A[0])
    exit()
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: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sat Feb 16 20:59:16 2019
 
@author: doppe
"""
N = int(input())
 
A = [int(i) for i in input().split()]
 
minValue = min(A)
 
ans = 1
ansList = [1]
i = 2
while i * i < minValue:
    j = 1
    for k in A:
        if (k % i != 0):
            break
        if (j == len(A)):
            ans = i
            ansList.append(i)
        j += 1
    i += 1
flg = 0
 
for i in range(0, len(ansList)):
    value = minValue / ansList[i]
 
    j = 1
    for k in A:
        if (k % value != 0):
            break
        if (j == len(A)):
            ans = value
            flg = 1
        j += 1
    if (flg == 1):
        break
            
print(int(ans))

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
if len(list(set(A)))==1:
    print(A[0])
elif all(a/min(A)>2 for a in A)&min(A)!=2:
    print(min(A))
elif all(a%2 == 0 for a in A):
    print("2")
else:
    print("1")

Submission status: Wrong Answer

Solution code:
n = int(input())
listA=list(map(int, input().split()))
listA.sort()
min1=listA[0]
min2=listA[1]
flag=1
while flag:
    flag=0
    if min2 > min1 and min2-min1 > 0:
        min2-=min1
        flag=1
    if min1 > min2 and min1-min2 > 0:
        min1-=min2
        flag=1
print(min(min1, min2))

Submission status: Wrong Answer

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

a.sort(reverse=True)
min_j = a[0]
for i in range(len(a)):
    for j in range(len(a)):
        if i == j:
            continue
        tmp_j = a[i] % a[j]
        if 0 == tmp_j:
            continue
        if min_j > tmp_j:
            min_j = tmp_j
for a_i in a:
    tmp_j = a_i % min_j
    if 0 == tmp_j:
            continue
    if min_j > tmp_j:
            min_j = tmp_j 
print(min_j)

Submission status: Wrong Answer

Solution code:
N = int(input())
An = [int(n) for n in input().split()]
M = sorted(set(An))
mini=M[0]
            
while len(M) > 1:
    M = [mini] + [x-mini for x in M[1:] if x % mini != 0]
    M = list(map(lambda x:x-mini,M))
    M[0] = mini
    M.sort()
    if 1 in M:
        mini=1
        break
    mini = min(mini,M[0])
print(mini)

Submission status: Wrong Answer

Solution code:
N = int(input())
monsterlist = list(map(int,input().split()))
monsterlist.sort()
minnum = monsterlist[0]
count = 0
count2 = 0
if minnum % 2 == 0:
    count = 0
    for i in range(1,N):
        if monsterlist[i] % minnum != 0:
            count += 1
            comparenum = monsterlist[i]
            break
    if count == 0:
        print(minnum)
    else:
        count = 0
        for i in range(1,N):
            if monsterlist[i] % 2 != 0:
                count += 1
                print("1")
                break
        if count == 0:
            print("2")

else:
    count = 0
    for i in range(1,N):
        if monsterlist[i] % minnum != 0:
            count += 1
            comparenum = monsterlist[i]
            break
    if count == 0:
        print(minnum)
    else:
        count = 0
        for i in range(1,N):
            if monsterlist[i] % 2 == 0:
                if monsterlist[i] % minnum != 0:
                    count += 1
                    print("1")
        if count == 0:
            print("2")

Submission status: Wrong Answer

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

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

min_num = min(e)
is_ok = True
for i in e:
    if i%min_num != 0:
        is_ok = False
        break

if is_ok:
    print(min_num)
    exit()

e.sort(reverse=True)

n1 = e[0]
n2 = sum(e[1:])

if n1 >= n2:
    nokori = n1%n2
else:
    nokori = n2 % n1

if nokori == 0:
    print(min(e))
else:
    if nokori >= e[1]:
        print(nokori-e[1])
    else:
        print(e[1] - nokori)

Submission status: Wrong Answer

Solution code:
from sys import stdin

n = stdin.readline().rstrip().split()[0]
n = int(n)

hp_list = stdin.readline().rstrip().split()
hp_list = [int(hp) for hp in hp_list]

# 最大試行回数は、
def all_gusu(hp_list):
    for i in hp_list:
        if i % 2 == 0:
            continue
        else:
            return False
    else:
        return True

def calc(hp_list):
    if 2 in hp_list:
        if all_gusu(hp_list):
            return 2
        else:
            return 1
    if len(list(set(hp_list))) == 1:
        return hp_list[0]

    min_hp, max_hp = min(hp_list), max(hp_list)
    next_max_hp = max([hp for hp in hp_list if hp != max_hp])
    # print(next_max_hp)

    # 1 - next_max_hpまでが有りうる
    # for kouho in range(next_max_hp):
    # return a
    return 1


if 1 in hp_list:
    print(1)
else:
    a = calc(hp_list)
    print(a)

Submission status: Wrong Answer

Solution code:
N=int(input())
As=[int(x) for x in input().split()]
As.sort()
As.reverse()
print(As)
LL=[]

def ret_factor(num):
    while num % 2 == 0:
        num /= 2
        yield 2

    i = 3
    while num != 1:
        if num % i == 0:
            num /= i
            yield i
        else:
            i += 2


def intersect_list(lst1, lst2):
    arr = []
    lst = lst1.copy()
    for element in lst2:
        try:
            lst.remove(element)
        except ValueError:
            pass
        else:
            arr.append(element)
    return arr

cr=As[0] 
for A in As:
    LL.append(list(ret_factor(A)))
print(LL)

rL=[]
for L in LL:
    for L2 in LL:
        r=1
        for k in intersect_list(L,L2):
           r*=k
        rL.append(r)

print(min(rL))

Submission status: Wrong Answer

Solution code:
n=int(input())
a = sorted(list(map(int, input().split())))
ans=0
tmp=a[0]
b=[i % a[0] for i in a]
if max(b)==0:
    print(tmp)
else:
    while  0 in b:
        b.remove(0)
    if len(b)>2:
        print(1)
    else:
        print(min(b))

Submission status: Wrong Answer

Solution code:
N = int(input())
monsters = set(map(int, input().split()))

# x0y1, x1y2, ...
def zip_set(x, y):
  xs, ys = iter(x), iter(y)
  next(ys)
  yield from zip(xs, ys)

def next_(monsters):
  for m, n in zip_set(monsters, monsters):
    if m == n:
        continue
    a, b = (m, n) if m > n else (n, m)
    val = a % b
    yield b if val == 0 else val

old = monsters
while True:
  if len(monsters) == 1:
    break
  monsters = set(next_(monsters))
  if monsters == old:
    break
  old = monsters


print(min(monsters))

Submission status: Wrong Answer

Solution code:
import sys


def main():
    N = int(input())
    monster = list(input().split(' '))
    monster = [int(x) for x in monster]

    h = sorted(monster)

    ans = 0
    while True:
        for i in range(1, len(h)):
            if h[0] == 1:
                print(1)
                sys.exit(0)
            if h[i] - h[0] == 0:
                ans = h[i]
                h[i] = h[i] - h[0]
            else:
                h[i] = h[i] - h[0]

        h = sorted(h)
        if h[0] == 0 and 1 in h:
            print(1)
            sys.exit(0)
        elif h[0] == 0:
            print(ans)
            sys.exit(0)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
if all([e == A[0] for e in A[1:]]):
    print(A[0])
elif all(a/min(A)>2 for a in A)&min(A)!=2:
    print(min(A))
elif all(a%2 == 0 for a in A):
    print("2")
else:
    print("1")

Submission status: Wrong Answer

Solution code:
N = int(input())
monster = input().split()
monster = [int(life) for life in monster]
countEven = 0
for i in monster:
    if i % 2 == 0:
        countEven += 1


if monster.count(monster[0]) == N:
    print(monster[0])
elif countEven == N:
    print(2)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input()) 
#n=4
lst = [int(i) for i in input().split()]
#lst = [2, 2, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [0, 1, 0]
hps = np.array(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: Wrong Answer

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

hp = list(map(int, input().split()))
result = 0
checkyakusuru = []
checkodd = []
checkeven = []

if (hp.count(hp[0]) == m[0]):
    result = hp[0]

minhp = min(hp)

for p in hp:
    if (p % minhp == 0):
        checkyakusuru.append(1)
    
    if (checkyakusuru.count(1) == m[0]):
        result = p
        break
    else:
        if (p % 2 == 0):
            checkeven.append(1)
        if (checkeven.count(1) == m[0]):
            result = 2
            break
        else:
            result = 1

Submission status: Wrong Answer

Solution code:
# 各モンスターの組み合わせで余りの最小値を求める
A = input()
L = list(map(int, input().split()))
L.reverse()
# print(L)
ans = 1000000
for i in range(len(L)):
    for j in range(len(L)):
        # print('ans:', ans)
        # print('L[', i, '] % L[', j, ']')
        # print(L[i], '%', L[j])
        # print(L[i] % L[j])
        B = L[i] % L[j]
        if B != 0 and B < ans:
            ans = B
            C = L[j] % ans
            if C != 0 and C < ans:
                ans = C
print(ans)

Submission status: Wrong Answer

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

mi = min(arr)
def ha(d):
    return d%mi
ans = list(map(ha,arr))

if max(ans) == min(ans):
    print(min(arr))
else:
    mi =max(arr)
    ansa = list(map(ha,ans))
    if min(ansa) != 0:
        print(min(ansa))
    else:
        print(max(ans)//max(ans))

Submission status: Wrong Answer

Solution code:
import itertools as it
n = int(input())
a = list(map(int,input().split()))
if min(a) == max(a):
    print(a[0])
else:
    cs = set(a)
    ccb = it.combinations(cs, 2)
    print(list(ccb))
    for (x,y) in it.combinations(cs, 2):
        if x > y:
            cs.add(x%y)
        else:
            cs.add(y%x)
    print(cs)
    min = max(a)
    for (x,y) in it.combinations(cs, 2):
        if x == 0 or y == 0:
            pass
        else:
            if x > y:
                if min > (x%y) and (x%y)!=0:
                    min = (x%y)
            else:
                if min > (y%x)and (y%x)!=0:
                    min = y%x
    print(min)

Submission status: Wrong Answer

Solution code:
N = int(input())
a = list(map(int, input().split()))
hp = list()
for i in range(N):
    for j in range(N):
        if i == j:
            pass
        elif a[j] % a[i] != 0:
            hp.append(a[j] % a[i])
        else:
            hp.append(a[i])
            for x in range(N):
                if x != i and x != j:
                    for t in range(2, int(a[x] / a[i]) + 10):
                        if (a[i] * t) % a[x] != 0:
                            hp.append((a[i] * t) % a[x])
                        if (a[i] * t) % a[x] == 1:
                            break
        if 1 in hp:
            break
    if 1 in hp:
        break

print(min(hp))

Submission status: Wrong Answer

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

a.sort()
min_val = a[0]

amaris = [a[i+1]%a[i] for i in range(n-1) if a[i+1]%a[i]!=0]
#print(amaris)

for i in range(n):
    t = a[i]
    for t_a in amaris:
        val = t%t_a
        if val != 0 and val < min_val:
            min_val = val

print(min_val)

Submission status: Wrong Answer

Solution code:
n=int(input())
a = sorted(list(map(int, input().split())))
ans=0
tmp=a[0]
b=[i % a[0] for i in a]
if max(b)==0:
    print(tmp)
else:
    while  0 in b:
        b.remove(0)
    print(min(b))

Submission status: Wrong Answer

Solution code:
number=int(input())
hitpoint=list(map(int,input().split()))
xyz=[]
png=[]
for i in range(len(hitpoint)):
    xyz.append(hitpoint[i]%2)
if hitpoint.count(hitpoint[0])==len(hitpoint):
    print(hitpoint[0])
elif max(hitpoint)%min(hitpoint)==0:
    for i in range(len(hitpoint)):
        png.append(hitpoint[i]%min(hitpoint))
    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: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
N = int(input())
lst= list(map(int,input().split()))
lst.sort(reverse=True)
tmp=lst[0]
#print(tmp)
for i in range(len(lst)):
    for j in range(len(lst)-1,i,-1):
        #if lst[i] % lst[j] != 0:
        #    tmp = min(lst[i] % lst[j], tmp)
        try:
            if lst[i] % lst[j] != 0:
                tmp = min(tmp,lst[i] % lst[j])
            if lst[j] % lst[i] != 0:
                tmp = min(tmp,lst[j] % lst[i])
            if tmp % lst[i] !=0:
                tmp = min(tmp % lst[i] , tmp)
            if lst[i] % tmp!= 0:
                tmp = min(lst[i]%tmp , tmp)
            
        except:
            pass
print(tmp)

Submission status: Wrong Answer

Solution code:
a = int(input())
list = input().split(" ")
list = [int(i) for i in list]

if list.count(min(list)) == len(list):
  print(min(list))
elif  max([i%min(list) for i in list if i!=min(list)]) ==0:
  print(min(list))
else:
  print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())
AList = input().split(" ")
AList = [int(i) for i in AList]
AList.sort()
minValue = AList[0]

for i in range(len(AList)) :
    if AList[i] % minValue > 0 : 
        minValue = AList[i] % minValue
if minValue == 0 :
    minValue = 1
print(minValue)

Submission status: Wrong Answer

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


#%%
# n, a = 4, [2, 10, 8, 40]


#%%


#%%

#%%
a.sort()
while len(a) >= 2:
    for i in range(len(a) -1, 0, -1):
        a[i] = a[i] % a[0]
        if a[i] == 0:
            a.remove(a[i])
        elif a[i] == 1:
            a = [0]
            break
        elif a[i] < a[0]:
            a[0], a[i] = a[i], a[0]
            break


#%%
print(a[0])

#%%

Submission status: Wrong Answer

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 = np.array(lst)
while(1):
    hps = np.array(sorted(hps))
    #print(hps)
    #print(hps!=0)
    #print(sum(hps!=0))
    if(sum(hps==0)!=1):
        hps[1] = hps[len(hps)-1]
        break
    if(hps[0]==0): break
    if(hps[0]==hps[len(hps)-1]): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

Submission status: Wrong Answer

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

l = sorted(l)


pre = min(l)
ans = pre
if all([i % pre == 0 for i in l]):
    print(pre)
else:

    m = l[1] % l[0]
    for i in range(2, len(l)):
        if i ==2:
            m = l[1] % l[0]
        if m != 0:
            a = l[i] % m
            if a < m and a >= 1:
                m = a
            else:
                ans = m
print(ans)

Submission status: Wrong Answer

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 = 10 ** 9
for i in range(n - 1):
    k = a[i + 1] % a[i]
    if k == 0:
        k = a[i]
    ans = min(k, ans)
for i in a:
    j = i % ans
    if j == 0:
        j = ans
    ans = min(j, i)
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
# A = sorted(list(map(int, input().split())), reverse = True) 
A = sorted(list(map(int, input().split())))

res = min(A)

nA = []

for i in range(N):
    nA.append(A[i])
    tmp = [e % nA[0] for e in nA if e % nA[0] != 0]
    if len(tmp) != 0:
        cand = min(tmp)
    
        if cand not in nA:
            nA.append(cand)
    
        if 1 in nA:
            break
    nA = sorted(nA)

print(min(nA))

Submission status: Wrong Answer

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

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


ans = 10 ** 9
for ai in a:
    ans = gcd(ans, ai)

print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
import random
N = input()
monstor = []
flg = []
for i in range(int(N)):
    monstor.append(i)
    flg.append(1)

HP = (input().split())
HP =list(map(int, HP))
#print(monstor)
#print(HP)
while(1):
    if len(HP) == 1:
        break
    l = random.sample(monstor, 2)
#    print("l")
#    print(l)
    HP[int(l[0])] = HP[int(l[0])] - HP[l[1]]
    #print("HP = ")
    #print(HP[int(l[0])])
    if HP[int(l[0])] <= 0:
        HP.pop(l[0])
        monstor.pop(len(monstor)-1)
    #    print("monstor")
    #    print(monstor)
    #    print("HP")
    #    print(HP)


print(HP[0])

Submission status: Wrong Answer

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

    
if list1 != []:
        res= min(list1)
     
list2=[list1[0]]
n=len(list1)
for i in range(n-1):
    b=list1[i+1]%list1[i]
    list2.append(b)

list2.sort()

list3=[]
for i in list2:
    if i !=0:
        list3.append(i)
       
    
if list3 != []:
    res=min(list3)        


list3.sort()

list4=[list3[0]]
n=len(list3)
for i in range(n-1):
    b=list3[i+1]%list3[i]
    list4.append(b)
    
list4.sort()

list5=[]
for i in list4:
    if i !=0:
        list5.append(i)
       
    
if list5 != []:
    res=min(list3)        


print(res)

Submission status: Wrong Answer

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

mina=min(aa)
bb = [x%mina for x in aa if x%mina>0]
if len(bb)==0:
    print(mina)
else:
    minb=min(bb)
    # print(bb)
    if mina % minb ==0:
        print(minb)
    else:
        print(1)

Submission status: Wrong Answer

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

if len(set(a)) == 1:
    print(a[0])
else:
    a.sort()
    for k in range(1, (10 ^ 9)+1):
        count = k
        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
            if x == 0:
                break
        if x == 0:
            break

    print(count)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
list = [min(A)]
A = sorted(A)
iii = 0
while True:
    iii += 1
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
    elif N >= 3 and A[N-1] % A[N-3] != 0:
        A[N-1] = A[N-1] % A[N-3]
    elif N >= 4 and A[N-1] % A[N-4] != 0:
        A[N-1] = A[N-1] % A[N-4]
    elif N >= 5 and A[N-1] % A[N-5] != 0:
        A[N-1] = A[N-1] % A[N-5]
    elif N >= 6 and A[N-1] % A[N-6] != 0:
        A[N-1] = A[N-1] % A[N-6]
    elif N >= 7 and A[N-1] % A[N-7] != 0:
        A[N-1] = A[N-1] % A[N-7]
    elif N >= 8 and A[N-1] % A[N-8] != 0:
        A[N-1] = A[N-1] % A[N-8]
    elif N >= 9 and A[N-1] % A[N-9] != 0:
        A[N-1] = A[N-1] % A[N-9]
    elif N >= 10 and A[N-1] % A[N-10] != 0:
        A[N-1] = A[N-1] % A[N-10]
    elif N >= 11 and A[N-1] % A[N-11] != 0:
        A[N-1] = A[N-1] % A[N-11]
    elif N >= 12 and A[N-1] % A[N-12] != 0:
        A[N-1] = A[N-1] % A[N-12]
    elif N >= 13 and A[N-1] % A[N-13] != 0:
        A[N-1] = A[N-1] % A[N-13]
    elif N >= 14 and A[N-1] % A[N-14] != 0:
        A[N-1] = A[N-1] % A[N-14]
    elif N >= 15 and A[N-1] % A[N-15] != 0:
        A[N-1] = A[N-1] % A[N-15]
    elif N >= 16 and A[N-1] % A[N-16] != 0:
        A[N-1] = A[N-1] % A[N-16]
    elif N >= 17 and A[N-1] % A[N-17] != 0:
        A[N-1] = A[N-1] % A[N-17]
    elif N >= 18 and A[N-1] % A[N-18] != 0:
        A[N-1] = A[N-1] % A[N-18]
    elif N >= 19 and A[N-1] % A[N-19] != 0:
        A[N-1] = A[N-1] % A[N-19]
    elif N >= 20 and A[N-1] % A[N-20] != 0:
        A[N-1] = A[N-1] % A[N-20]
    elif N >= 21 and A[N-1] % A[N-21] != 0:
        A[N-1] = A[N-1] % A[N-21]
    elif N >= 22 and A[N-1] % A[N-22] != 0:
        A[N-1] = A[N-1] % A[N-22]
    elif N >= 23 and A[N-1] % A[N-23] != 0:
        A[N-1] = A[N-1] % A[N-23]
    elif N >= 24 and A[N-1] % A[N-24] != 0:
        A[N-1] = A[N-1] % A[N-24]
    elif N >= 25 and A[N-1] % A[N-25] != 0:
        A[N-1] = A[N-1] % A[N-25]
    elif N >= 26 and A[N-1] % A[N-26] != 0:
        A[N-1] = A[N-1] % A[N-26]
    elif N >= 27 and A[N-1] % A[N-27] != 0:
        A[N-1] = A[N-1] % A[N-27]
    elif N >= 28 and A[N-1] % A[N-28] != 0:
        A[N-1] = A[N-1] % A[N-28]
    elif N >= 29 and A[N-1] % A[N-29] != 0:
        A[N-1] = A[N-1] % A[N-25]
    elif N >= 30 and A[N-1] % A[N-30] != 0:
        A[N-1] = A[N-1] % A[N-30]
    elif N >= 31 and A[N-1] % A[N-31] != 0:
        A[N-1] = A[N-1] % A[N-31]
    elif N >= 32 and A[N-1] % A[N-32] != 0:
        A[N-1] = A[N-1] % A[N-32]
    elif N >= 33 and A[N-1] % A[N-33] != 0:
        A[N-1] = A[N-1] % A[N-33]
    elif N >= 34 and A[N-1] % A[N-34] != 0:
        A[N-1] = A[N-1] % A[N-34]
    elif N >= 35 and A[N-1] % A[N-35] != 0:
        A[N-1] = A[N-1] % A[N-35]
    elif N >= 36 and A[N-1] % A[N-36] != 0:
        A[N-1] = A[N-1] % A[N-36]
    A = sorted(A)
    list.append(min(A))
    if iii > 128:
        break       
#print(list)
print(min(list))

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = list(map(int, input().split()))
    ma = min(A)
    for a in A:
        while True:
            if a % ma != 0:
                ma = min(ma, a % ma)
            else:
                break
    print(ma)


main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
N = int(input())
L = list(map(int,input().split()))
L.sort()
p = 0
q = 0
ans = 0
for i in range(1,N):
  L[i] = L[i]%L[0]
L.sort()
for i in range(N):
  if L[i] != 0:
    p = i
    q = L[i]
    break
if q == 1:
  print(1)
else:
  ans = q
  for j in range(p+1,N):
    for k in range(2,int(math.sqrt(N))+2):
      if L[j]%k == q%k == 0:
        ans = k
  print(ans)

Submission status: Wrong Answer

Solution code:
import fractions
from functools import reduce

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

reduce(fractions.gcd, al)

Submission status: Wrong Answer

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

Solution code:
N = int(input())
A = input().split(" ")
A = [int(i) for i in A]
list = [min(A)]
A = sorted(A)
iii = 0
while True:
    iii += 1
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
    elif N >= 3 and A[N-1] % A[N-3] != 0:
        A[N-1] = A[N-1] % A[N-3]
    elif N >= 4 and A[N-1] % A[N-4] != 0:
        A[N-1] = A[N-1] % A[N-4]
    elif N >= 5 and A[N-1] % A[N-5] != 0:
        A[N-1] = A[N-1] % A[N-5]
    elif N >= 6 and A[N-1] % A[N-6] != 0:
        A[N-1] = A[N-1] % A[N-6]
    elif N >= 7 and A[N-1] % A[N-7] != 0:
        A[N-1] = A[N-1] % A[N-7]
    elif N >= 8 and A[N-1] % A[N-8] != 0:
        A[N-1] = A[N-1] % A[N-8]
    elif N >= 9 and A[N-1] % A[N-9] != 0:
        A[N-1] = A[N-1] % A[N-9]
    elif N >= 10 and A[N-1] % A[N-10] != 0:
        A[N-1] = A[N-1] % A[N-10]
    elif N >= 11 and A[N-1] % A[N-11] != 0:
        A[N-1] = A[N-1] % A[N-11]
    elif N >= 12 and A[N-1] % A[N-12] != 0:
        A[N-1] = A[N-1] % A[N-12]
    elif N >= 13 and A[N-1] % A[N-13] != 0:
        A[N-1] = A[N-1] % A[N-13]
    elif N >= 14 and A[N-1] % A[N-14] != 0:
        A[N-1] = A[N-1] % A[N-14]
    elif N >= 15 and A[N-1] % A[N-15] != 0:
        A[N-1] = A[N-1] % A[N-15]
    elif N >= 16 and A[N-1] % A[N-16] != 0:
        A[N-1] = A[N-1] % A[N-16]
    elif N >= 17 and A[N-1] % A[N-17] != 0:
        A[N-1] = A[N-1] % A[N-17]
    elif N >= 18 and A[N-1] % A[N-18] != 0:
        A[N-1] = A[N-1] % A[N-18]
    elif N >= 19 and A[N-1] % A[N-19] != 0:
        A[N-1] = A[N-1] % A[N-19]
    elif N >= 20 and A[N-1] % A[N-20] != 0:
        A[N-1] = A[N-1] % A[N-20]
    elif N >= 21 and A[N-1] % A[N-21] != 0:
        A[N-1] = A[N-1] % A[N-21]
    elif N >= 22 and A[N-1] % A[N-22] != 0:
        A[N-1] = A[N-1] % A[N-22]
    elif N >= 23 and A[N-1] % A[N-23] != 0:
        A[N-1] = A[N-1] % A[N-23]
    elif N >= 24 and A[N-1] % A[N-24] != 0:
        A[N-1] = A[N-1] % A[N-24]
    elif N >= 25 and A[N-1] % A[N-25] != 0:
        A[N-1] = A[N-1] % A[N-25]
    elif N >= 26 and A[N-1] % A[N-26] != 0:
        A[N-1] = A[N-1] % A[N-26]
    elif N >= 27 and A[N-1] % A[N-27] != 0:
        A[N-1] = A[N-1] % A[N-27]
    elif N >= 28 and A[N-1] % A[N-28] != 0:
        A[N-1] = A[N-1] % A[N-28]
    elif N >= 29 and A[N-1] % A[N-29] != 0:
        A[N-1] = A[N-1] % A[N-25]
    elif N >= 30 and A[N-1] % A[N-30] != 0:
        A[N-1] = A[N-1] % A[N-30]
    elif N >= 31 and A[N-1] % A[N-31] != 0:
        A[N-1] = A[N-1] % A[N-31]
    elif N >= 32 and A[N-1] % A[N-32] != 0:
        A[N-1] = A[N-1] % A[N-32]
    A = sorted(A)
    list.append(min(A))
    if iii > 128:
        break       
#print(list)
print(min(list))

Submission status: Wrong Answer

Solution code:
#-*- coding: utf-8 -*-
"""
https://yahoo-procon2019-qual.contest.atcoder.jp/tasks/yahoo_procon2019_qual_a
"""

from collections import defaultdict
import sys
def rec2(S):
    if len([s for s in S if s > 0]) == 1:
        return max(S)
    else:
        mini = sys.maxsize
        for i in range(len(S)):
            for j in range(len(S)):
                if i == j: continue
                S2 = []
                for s in S:
                    S2.append(S[j] - S[i])
                mini = min(mini, rec2(S2))
        return mini



def sol2(n, S):
    return rec2(S)


def sol(n, S):

    S.sort()
    mini = min(S)
    maxi = max(S)
    while True:
        sz = len(S)
        if sz < 2 or len(set(S))==1: break
        print("=>S:%s"%S)
        if maxi % mini == 0:
            S.remove(maxi)
            maxi = S[-1]
        else:
            tmp = maxi % mini
            print("tmp:%s" % (tmp))
            S.remove(maxi)
            S.append(tmp)
            S.sort()
            maxi = S[-1]
    print("S:%s"%S)
    return 0 if len(S)==0 else min(S)



test = False
#test = True
if test:
    n = 4
    S = [2, 10, 8, 40]
    #S =list( map(int, "1 6 3".split()))
    print(sol(n, S))

    n = 4
    S = [5, 13, 8, 1000000000]
    #S =list( map(int, "1 6 3".split()))
    print(sol(n, S))

    n = 3
    S = [1000000000, 1000000000, 1000000000]
    print(sol(n, S))

    n = 3
    S = [1, 1, 1]
    print(sol(n, S))

else:
    n = int(input().strip())
    #n, k = map(int, input().split())
    #print("%s %s %s %s" % (type(n), type(k), n, k))
    S =list( map(int, input().split()))
    print(sol(n, S))