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())
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")
                    break
        if count == 0:
            print("2")

Submission status: Wrong Answer

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

l = sorted(l)


pre = min(l)
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:
                print(m)
                break

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def main():
    row_input = input()
    N = int(row_input)

    A = []
    row_input = input()
    split_input = row_input.split()
    for tmp in split_input:
        A.append(int(tmp))

    #すべて同じ値だった場合
    if len(A) == A.count(A[0]):
        print(A[0])
        return

    result = monstor_hp(A)
    print(result)


def monstor_hp(A):
    zero_num = A.count(0)
    for i in range(zero_num):
        A.remove(0)

    mini = min(A)
    A_tmp = A
    mini_num = A_tmp.count(mini)
    if mini_num == len(A_tmp):
        return mini

    for i in range(mini_num):
        A_tmp.remove(mini)


    A_remnant = []
    for i in range(len(A_tmp)):
        A_remnant.append(A_tmp[i] % mini)

    if A_remnant.count(0) == len(A_remnant):
        return mini

    return monstor_hp(A_remnant)




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)==0 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:
import heapq

def extend_mod(p,q):
    return p%q if p%q < q/2 else abs(p%q -q)
    
N = int(input())
A = list(map(int,input().split()))

candidate = 10000000000

for A_ in A:
    if A_ != max(A):
        attention_list = [extend_mod(Ai,A_) for Ai in A if Ai > A_ and extend_mod(Ai,A_)!= 0]
        if len(attention_list)!=0:
            candidate = min(candidate,min(attention_list))
        
print(candidate if candidate != 10000000000 else min(A) )

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

nokori = n1%n2

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:
10000000000

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):
            result = 2
        else:
            result = 1

Submission status: Wrong Answer

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

a = list(set(a))
a.sort()
while len(a) > 1:
    while (a[0] < a[1]):
        a[1] -= a[0]
    a = list(set(a))
    a.sort()
    if a[0] == 1:
        break
    if len(a) == 2:
        a[0] = a[1]%a[0]
        break
print(a[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
listA=list(map(int, input().split()))
listA.sort()
minDelta=1000000000
index=0
while index < len(listA)-1:
    if listA[index+1]-listA[index] < minDelta:
        minDelta = listA[index+1]-listA[index]
    index+=1
max1=listA[len(listA)-1]
max2=listA[len(listA)-2]
index = len(listA)-2
while index > -1:
    if max1 > listA[index]:
        if max1%listA[index]==0:
            max1 = listA[index]
        else:
            max1 = max1%listA[index]
    index-=1
index2 = len(listA)-3
while index2 > -1:
    if max2 > listA[index2]:
        if max2 % listA[index2] == 0:
            max2 = listA[index2]
        else:
            max2 = max2 % listA[index2]
    index2 -= 1
minmum = min(max1, max2)
if minmum > minDelta and minDelta!=0:
    if minmum%minDelta==0:
        minmum = minDelta
    else:
        minmum = minmum%minDelta
print(minmum)

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
for i in range(len(AList)) :
    if AList[i] % minValue > 0 : 
        minValue = AList[i] % minValue
print(minValue)

Submission status: Wrong Answer

Solution code:
n=int(input())
a_list=list(map(int, input().split()))
a_list.sort()
 
if len(a_list) == 1:
  print(a_list[0])
  exit()

a,b=a_list[:2][0], a_list[:2][1]
 
if a==b:
  print(a)
elif b%a == 0:
  print(a)
else:
  print(1)

Submission status: Wrong Answer

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

ans = min(a)

print(ans)

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

Solution code:
num = int(input())
mons =list( 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]
    aft .append (at)
    print (aft)
    if len (aft) == 0 :
       break
    else:
        at = min(aft)
if len ( aft ) == 1 :
    res = at
else:
    res = 0
print ( res )

Submission status: Wrong Answer

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

N = int(input())

if N < 2 and N > 10 ** 5:
    pass

_monsters = {i: int(x) for i, x in enumerate(input().split(" ")) if int(x) >= 1 and int(x) <= 10 ** 9}

results = []

if len(_monsters) == N:
    for i in range(100):
        monsters = _monsters
        while len(monsters) > 1:
            a, b = random.sample(monsters.keys(), 2)
            new_mons_a = monsters[a] - monsters[b]

            if new_mons_a < 1:
                monsters.pop(a)
            else:
                monsters[a] = new_mons_a

        results.append(monsters[list(monsters.keys())[0]])

print(min(results))

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)==0 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:
from sys import stdin
import random


def c(monster_num, monster_hp_list):
    living_monster_hp = -1
    living_monster_count = monster_num
    while(living_monster_count != 1):
        attacked_monster_id = random.randint(0, monster_num-1)
        attack_monster_id = random.randint(0, monster_num-1)
        while monster_hp_list[attack_monster_id] <= 0 or attack_monster_id == attacked_monster_id:
            attack_monster_id = random.randint(0, monster_num-1)
        monster_hp_list[attacked_monster_id] -= monster_hp_list[attack_monster_id]
        if monster_hp_list[attacked_monster_id] <= 0:
            living_monster_count -= 1
            #print(living_monster_count)
        living_monster_hp = monster_hp_list[attack_monster_id]
        #print(monster_hp_list)
        #print(monster_hp_list)
    return living_monster_hp


def main():
    input_line = stdin.readlines()
    monster_num = int(input_line[0])
    monster_hp_list = [int(x) for x in input_line[1].split()]
    print(c(monster_num, monster_hp_list))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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

    print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
ans = set(a)
t = []

while not len(ans) < 2:
    t = [s%min(a) for s in a if s%min(a) != 0]
    t.append(min(a))
    a = t
    ans = set(t)

d = list(ans)
print(d)

Submission status: Wrong Answer

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

odd = False
even = False
for n in A:
    for i in range(N):
        if n > A[i]:
            b = n
            s = A[i]
        else:
            b = A[i]
            s = n

        if b%s == 0:
            continue
        if b%s%2 == 0:
            even = True
        else:
            odd = True

    if (even and odd): break


if even and odd:
    print(1)
elif even:
    print(2)
else:
    print(min(A))

Submission status: Wrong Answer

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

while(a[-1] != 1):
	m = a[-1]
	b = []

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

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

Submission status: Wrong Answer

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_ = A_1 + A_2 
A_ = sorted(set(A_))
if A_ == [0]*len(A_):
  print(A[0])
else:
  print(A_[1])

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]

    A = sorted(A)
    list.append(min(A))
    if iii > 128:
        break       
#print(list)
print(min(list))

Submission status: Wrong Answer

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

# print(A)
mi = A[0]
tmp = []
for i in range(len(A)-1):
    for j in range(i+1,len(A)):
        # print(A[i],A[j])
        tmp.append(A[j]%A[i])
tmp = [i for i in tmp if i > 0]
if(len(tmp)==0):
    print(mi)
else:
    for i in tmp:
        for j in A:
            if((j%i) < mi and j%i>0):
                mi = j%i
    print(mi)

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:
    print(max(ans)//max(ans))

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int,input().split()))
flag = 0
#mi = min(A)
Q = np.array(A)
an = 1
def toku(Q):
    mi = min(Q)
    R1 = Q % mi
    if any(R1) == 0:
        flag = 1
        an = mi
        return(R1)
    else:
        R = R1[R1!=0]
        return(R)

while flag == 1:
    Q = toku(Q)

print(an)

Submission status: Wrong Answer

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

l = sorted(l)


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

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=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 ai in a:
        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: 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  min([i%min(list) for i in list]) ==0:
  print(min(list))
else:
  print(1)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())

A = [int(i) for i in input().split()]
A = np.array(A)
print(N,A)

min_amari = min(A)
while 0==0:
  amari = A%min_amari
  amari = amari[amari!=0]
  if len(amari)==0:
    print(min_amari)
    break
  else:
    min_amari = min(amari)

Submission status: Wrong Answer

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
if A[0] == A[-1]:
	j = 2
if j == 0:
	print(2)
elif j == 1:
	print(1)
else:
	print(A[0])

Submission status: Wrong Answer

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

max_val = max(monsters)
min_val = min(monsters)

# EX3
if max_val == min_val:
    print(max_val)
    exit()

if 1 in monsters:
    print(1)
    exit()

result = (max_val+min_val) % N
if result > min_val:
    print(min_val)
else:
    print(result)

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 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
            if x == 0:
                break
        if x == 0:
            break

    print(count)

Submission status: Wrong Answer

Solution code:

def main():
  N = int(input())
  monsters = list(map(int, input().split()))

  monsters = sorted(monsters)
  # print(monsters)
  prev = None
  while True:
    # print('==============================')
    monsters = sorted(monsters)
    prev = monsters
    # print(monsters)
    
    for i in range(1, len(monsters)):
      monsters[i] = monsters[i] % monsters[0]

    # print(monsters)
    if 0 in monsters:
      monsters = list(set(monsters))
      monsters.remove(0)
      monsters = sorted(monsters)

    # print(monsters)
    if len(monsters) == 2:
      if monsters[1] < monsters[0]:
        monsters[0] -= monsters[1]
        continue
      # print('a')
      last = monsters[1] - monsters[0]
      monsters[0] = last
      monsters.remove(monsters[1])
      # print(monsters)

    if len(monsters) == 1:
      break

    if prev == monsters:
      monsters[0] -= monsters[1]



  print(monsters[0])

main()

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

    while True:
        sz = len(S)
        if sz < 2 or len(set(S))==1: break
        print("=>S:%s"%S)
        mini = min(S)
        maxi = max(S)
        if maxi % mini == 0:
            S.remove(maxi)
        else:
            tmp = maxi % mini
            print("tmp:%s" % (tmp))
            S.remove(maxi)
            S.append(tmp)
    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))

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,0,-1):
        #if lst[i] % lst[j] != 0:
        #    tmp = min(lst[i] % lst[j], tmp)
        try:
            if tmp % lst[i] !=0:
                tmp = min(tmp % lst[i] , tmp)
            if lst[i] % tmp!= 0:
                #print(tmp,lst[i],tmp%lst[i],"e")
                tmp = min(lst[i]%tmp , tmp)
            #print(tmp,lst[i] ,lst[j])

        except:
            pass
print(tmp)

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

print(min(hp))

Submission status: Wrong Answer

Solution code:
num = int(input())
mons =list( 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]
    if len (aft) != 0 :
        at = min(aft)
    else:
        break
if len ( aft ) == 1 :
    res = at
else:
    res = 0
print ( res )

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:
    print(1)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().strip().split()))
min1=min(a)
min2=min1

for i in a:
    amari=i%min1
    if amari!=0:
        if amari<min1:
            min1=amari
lop=True
while lop:
    if min1==min2:
        ans=min1
        lop=False
    elif min1==0 or min2==0:
        ans=1
        lop=False
    elif min1<min2:
        min2=min2%min1
    elif min1>min2:
        min1=min1%min2
print(ans)

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,0,-1):
        #if lst[i] % lst[j] != 0:
        #    tmp = min(lst[i] % lst[j], tmp)
        try:
            if tmp % lst[i] !=0:
                tmp = min(tmp % lst[i] , tmp)
            if lst[i] % tmp!= 0:
                #print(tmp,lst[i],tmp%lst[i],"e")
                tmp = min(lst[i]%tmp , tmp)
            #print(tmp,lst[i] ,lst[j])

        except:
            pass
print(tmp)

Submission status: Wrong Answer

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

a.sort()
res = a[0]
amari = []

for i in reversed(range(n)):
    for j in reversed(range(i)):
        if a[i]%a[j]!=0:
            amari.append(a[i]%a[j])
            amari.append(a[i]%a[j]+a[j])

amari = list(set(amari))
# print(amari)

for i in reversed(amari):
    for j in a:
        # print(i,j,res)
        if j>i:
            break
        if res>i%j and i%j!=0:
            res = i%j
else:
    print(res)

Submission status: Wrong Answer

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

minn = A[0]
for i in range(1, N):
    if minn == 1:
        break
    for j in range(0, i):
        if A[i] % A[j] == 0:
            continue
        minn = min(minn, A[i] % A[j])
        A[i] = min(minn, A[i] % A[j])

print(minn)

Submission status: Wrong Answer

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

if len(hp) == 1:
    print(hp[0])
elif min(hp) == 1:
    print(1)
elif any((x % 2 == 1 for x in hp)):
    print(1)
else:
    print(min(hp))

Submission status: Wrong Answer

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

tempAns = max(a)

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

    a[i] = newx
    x = newx
    
    for k in range(n):
        if k == i:
            continue
        newxk = a[k] % x
        if newxk < a[k] and newxk < 0:
            a[k] = newxk
            
    for m in range(n):
        tempabs = abs(x-a[m])
        if tempabs < tempAns and tempabs > 0:
            tempAns = tempabs
        
print(min(tempAns,min(a)))

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) == 0:
    print(min(arr))
else:
    print(1)

Submission status: Wrong Answer

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
def map_all(es):
    return all([e == es[0] for e in es[1:]]) if es else False
if map_all(A):
    print(A[0])
elif all(a%min(A)==0 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:
import numpy as np

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

A.sort()
s=A[0]
for i in range(min([s, n])):
    c = A[0]
    A = A % c
    A[0] = c
    A.sort()
    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: Wrong Answer

Solution code:
N = int(input())
A = [int(x) for x in input().split()]
min_A = min(A)
B = [x % 2 for x in A]
if min(B) != max(B):
  print(1)
else:
  print(min_A)

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]
maxb=max(bb)
if bb.count(0)==len(bb):
    print(mina)
elif mina % maxb ==0:
    print(maxb)
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 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: 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
print(minValue)

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

nokori = n1%n2

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

Submission status: Wrong Answer

Solution code:
import numpy as np
import math
import copy
from functools import reduce

n = int(input())
hps = list(map(int, input().split(' ')))

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

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)

def lcm_list(numbers):
    return reduce(lcm_base, numbers, 1)


for i in range(n):
    h = copy.deepcopy(hps)
    h.pop(i)
    lcm = lcm_list(h)
    while hps[i] >= lcm * 2:
        hps[i] -= lcm

result = int(np.power(10, 9) + 1)

def attack(mynumber, myhp):
    global result
    li = list(np.arange(n))
    li.pop(mynumber)
    for i in li:
        if myhp <= hps[i]:
            if myhp < result:
                result = myhp
            break
            if result == 1:
                return
        else:
            myhp -= hps[i]
            attack(mynumber, myhp)

for i in range(n):
    attack(i, hps[i])
print(str(result))

Submission status: Wrong Answer

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

Solution code:
N=int(input())
A=[int(i) for i in input().split()]
def map_all(es):
    return all([e == es[0] for e in es[1:]]) if es else False
if map_all(A):
    print(A[0])
elif all(a%min(A)==0 for a in A):
    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())
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[x] / a[i] + 1)):
                        if (a[i] * t) % a[x] != 0:
                            hp.append((a[i] * t) % a[x])

print(min(hp))

Submission status: Wrong Answer

Solution code:
n=[int(i) for i in input()]
a = [int(i) for i in input().split()]
a.sort()
#print(n,a)
def f(y,x):
    if x==0:
        return y
    else:
        return f(x,y%x)

ans=a[-1]

for i in range(1,n[0]):
  if ans < a[i]:
    ans=f(a[i],ans)
  else:
    ans=f(ans,a[i])
    
print(ans)