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

#C
n = int(input())
aa = list(map(int,input().split()))

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]
m = min(A)
if m == 1:
    print(m)
else:
    while m > 0:
        m = min(A)
        for i in range(0,len(A)):
            if A[i] != m:
                A[i] = A[i]%m
        z = A.count(0)
        for j in range(z):
            A.remove(0)
        if A == []:
            break
        elif A.count(1) > 1:
            m = 1
            break
        else:
            if [_%min(A) for _ in A].count(0) == len(A):
                break
    print(m)

Submission status: Wrong Answer

Solution code:
a = map(int, input())

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

min_monster = min(monster)

tmp = 0
f = True
for x in monster:
    tmp = x % min_monster
    if tmp != 0:
        f = False

if tmp == 0 and f == True :
    print(min_monster)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
N = int(input())
aA=sorted(set(int(_) for _ in input().split()))
N = len(aA)
def ggg(i,j):
    if i < j :
        i,j = j,i
    i %= j
    if i == 0:
        return j
    else:
        return ggg(j,i)

if len(aA) == 1:
    print(aA[0])
else:
    iMin = aA[0]
    iMax = aA[-1]
    if iMin  == 1:
        print(1)
    else:
        if max(i % iMin for i in aA) == 0:
            print(iMin)
            exit()
        else:
            iM = iMax
            for i in range(N):
                iA = aA[i]
                for j in range(i+1,N):
                    iMt = ggg(iA,aA[j])
                    print(iMt)
                    if 0 < iMt and iMt < iM:
                        iM = iMt
                if iM == 1:
                    print(1)
                    exit()
            print(iM)

Submission status: Wrong Answer

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

ans=a[0]

for i in range(n[0]):
  if ans < a[i]:
    ans=f(a[i],ans)
  else:
    ans=f(ans,a[i])
    
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:
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
        A = sorted(A)
        list.append(min(A))
        iii += 1
        if iii > 100:
            break
    elif N >= 3 and A[N-1] % A[N-3] != 0:
        A[N-1] = A[N-1] % A[N-3]
        A = sorted(A)
        list.append(min(A))
        iii += 1
        
        if iii > 100:
            break
    elif N >= 4 and A[N-1] % A[N-4] != 0:
        A[N-1] = A[N-1] % A[N-4]
        A = sorted(A)
        list.append(min(A))
        iii += 1
        
        if iii > 100:
            break
    else:
        iii += 1
        
        if iii > 100:
            break

#print(list)
print(min(list))

Submission status: Wrong Answer

Solution code:
import numpy as np
from sys import stdin
N=int(stdin.readline().rstrip())
data=[int(x) for x in stdin.readline().rstrip().split()]
if len(set(data))==1 or len(data)==1:
    print(data[0])
else:
    data=np.array(data)
    if len(data[data%2==0])==len(data):
        print("2")
    else:
        print("1")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

f = 0
for i in range(n):
    if a[i] % 2 == 1:
        f = 1
        break

p = 0
for i in range(n):
    if a[i] % min(a) == 0:
        p += 1
    else:
        break

if p == n:
    f = 2

if f == 0:
    print(2)
elif f == 2:
    print(1)
else:
    print(min(a))

Submission status: Wrong Answer

Solution code:
import sys

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

a.sort()
answers = []
for i in range(1, n):
    if a[i] % a[0] == 0: continue

    x, y = a[0], a[i] # x < y
    while x != 0:
        x, y = y % x, x
    print(y)
    sys.exit()

print(a[0])

Submission status: Wrong Answer

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

minHP = Mons[0]

if minHP == 1 or len(Mons) == 1:
    print(minHP)
    exit()
    
minSA = minHP

for a,b in zip(Mons[:],Mons[1:]):
    sa = b % a
    if sa and sa < minSA:
        minSA = sa

ans = minSA
hoge = [val % minSA for val in Mons if val % minSA]

if hoge:
    ans = min(hoge)

print(ans)

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 -= min1
    else:
      min1 -= min2
  print(max(min1, min2))

Submission status: Wrong Answer

Solution code:
# import math
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a


input()
a_list = [int(s) for s in input().split()]
f = min(a_list)
a_list.remove(f)
s = min(a_list)
print(gcd(f,s))

Submission status: Wrong Answer

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

  monsters = sorted(monsters)
  # print(monsters)

  while True:
    # print('==============================')
    # 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
  print(monsters[0])

main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(_) for _ in input().split()]
m = min(A)
if m == 1:
    print(m)
else:
    while m > 0:
        m = min(A)
        for i in range(0,len(A)):
            if A[i] != m:
                A[i] = A[i]%m
        z = A.count(0)
        for j in range(z):
            A.remove(0)
        if A == []:
            break
        elif A.count(1) > 1:
            m = 1
            break
        else:
            if [_%min(A) for _ in A].count(0) == len(A):
                break
print(m)

Submission status: Wrong Answer

Solution code:
import sys

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

a.sort()
for i in range(1, n):
    if a[i] % a[0] == 0: continue

    x, y = a[0], a[i] # x < y
    while x != 0:
        x, y = y % x, x
    print(x)
    sys.exit()

print(a[0])

Submission status: Wrong Answer

Solution code:
import copy

N = int(input())
A = list(map(int, input().split()))
a_input = A
temp = []

if sum([A[i] - A[i-1] for i in range(1, len(A))]) == 0:
	print(A[0])
	exit()

while True:
	temp.extend(A)
	if len(A) == 1:
		break
	A.sort()
	diff_A = [A[i] - A[i-1] for i in range(1, len(A))]
	#print(diff_A)
	A = diff_A
ans = []
for i in range(len(a_input)):
	a = a_input[i] // min(A)
	ans.append(a)
ans.sort()
#print(ans)
print(ans[N-1])

Submission status: Wrong Answer

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

m = min(A)

def MBR(l):
    #print(l)
    global m
    l1 = [i for i in l if i > 0]
    if l1:
        m1 = min(l1)
        if m > m1:
            m = m1
    [MBR([m % i for m in l if m > 0]) for i in l if i > 0]

MBR(A)
print(m)

Submission status: Wrong Answer

Solution code:
from collections import Counter
n=int(input())
lst=list(map(int,input().split()))
c_lst=list(Counter(lst).keys())
abs_lst=[]
c_lst=sorted(c_lst)
for i in range(len(c_lst)-1):
    abs_lst.append(c_lst[i+1]-c_lst[i])
answer=n
if len(abs_lst)==0:
    print(0)
    exit()

for i in lst:
    if i%abs_lst[0] < answer:
        answer=i%abs_lst[0]
print(answer)

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 (a%b)==0 and b>1:
  print(b)
elif (b%a)==0 and a>1:
  print(a)
else:
  print(1)

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 = [int(n) for n in input().split(" ")]
    min1 = min(monsters)
    monsters.remove(min1)
    min2 = min(monsters)
    print(calc_min(min1, min2))

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

B = []
for i in range(len(A)):
	init = 1000000000
	for j in range(len(A)):
		if i == j:
			continue
		test = A[i]%A[j]
		if(test !=0 and test < init):
			init = test
	B.append(init)

A.extend(B)
C = []
for i in range(len(A)):
	init = 1000000000
	for j in range(len(A)):
		if i == j:
			continue
		test = A[i]%A[j]
		if(test !=0 and test < init):
			init = test
	C.append(init)

print(min(C))

Submission status: Wrong Answer

Solution code:
import numpy as np
from sys import stdin
N=int(stdin.readline().rstrip())
data=[int(x) for x in stdin.readline().rstrip().split()]
if len(set(data))==1 or len(data)==1:
    print(data[0])
else:
    data=np.array(data)
    if len(data[data%2==0])==len(data):
        print(2)
    else:
        print(1)

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)

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

        h = sorted(h)

    print(h)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
l = list(map(int,input().split()))
odd = 0
even = 0
for ll in l:
	if ll % 2 == 0:
		even = 1
	else:
		odd = 1
	if even == 1 and odd == 1:
		break
if l.count(l[0])==len(l):
	print(l[0])
else:
	if even==1 and odd==0:
		print(2)
	else:
		print(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:
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
        A = sorted(A)
        list.append(min(A))
        iii += 1
        if iii > 100:
            break
    else:
        if N >= 3 and A[N-1] % A[N-3] != 0:
            A[N-1] = A[N-1] % A[N-2]
            A = sorted(A)
            list.append(min(A))
        iii += 1
        
        if iii > 100:
            break
#print(list)
print(min(list))

Submission status: Wrong Answer

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

A.sort()

num = 0

if N == A.count(A[0]):
    num = 1
else:
    cnt = 0
    for i in range(len(A)):
        if A[i] % 2 == 0:
            cnt += 1
    if N == cnt:
        num = 2
    else:
        l = A
        x = []

        while True:
            x = []
            x.append(l[0])
            for i in range(1, len(l)):
                if 0 < l[i] % l[0]:
                    x.append(l[i] % l[0])

            if len(x) == 1:
                break

            x.sort()

            l = x

print(A[0] if num == 1 else 2 if num == 2 else x[0])

Submission status: Wrong Answer

Solution code:
import numpy as np

N = input()
A_list= list(map(int, input().split()))
min_ = np.min(A_list)


while(True):
    minima = 100000
    flag = False
    for life in A_list:
        amari = life % min_
        if amari == 0:
            continue
        elif amari < minima:
            minima = amari
            flag = True
    if flag:
        min_ = minima
        additional = []
        for idx,life in enumerate(A_list):
            if life == min_:
                pass
            else:
                save = [life]
                while(True):
                    if save[-1]-min_ > 0:
                        save.append(save[-1]-min_)
                    else:
                        break
        A_list.extend(save[1:])
    if not flag or np.min(A_list)==1:
        if np.min(A_list)==1:
            min_ = 1
        break
print(min_)

Submission status: Wrong Answer

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

    while True:
        m = min(a)
        new = [0 for i in range(n)]
        new[0] = m

        for i in range(len(a)):
            ind=1
            if a.index(m) != i:
                num = a[i]%m
                if num != 0:
                    new[ind] = a[i]%m
                    ind+=1

        a = new[:ind]

        if len(a) == 1:
            print(min(a))
            exit()



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
while True:
    x = A.index(min(A))
    a = A.pop(x)
    for i in range(len(A) - 1):
        A[i] %= a
    if len(A) == 1:
        print(a)
        break
    A = list(set(A))
    if 0 in A:
        A.remove(0)
    A.append(a)

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:
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
        A = sorted(A)
        list.append(min(A))
        
        
        
        iii += 1
        
        if iii > 1000:
            break
    else:
        if N >= 3 and A[N-1] % A[N-3] != 0:
            A[N-1] = A[N-1] % A[N-2]
            A = sorted(A)
            list.append(min(A))
        iii += 1
        
        if iii > 1000:
            break
#print(list)
print(min(list))

Submission status: Wrong Answer

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

min = 1000000001
num = {}
odd = False
even = False

for i in A:
    if min > i: min = i
    for j in A:
        if i > j:
            b = i
            s = j
        else:
            b = j
            s = i

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

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

Submission status: Wrong Answer

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

a.sort()
amari = a[0]

for i in range(n):
    t = a[i]
    t_amari = t%amari
    if t_amari != 0 and t_amari < amari:
        amari = t_amari

print(amari)

Submission status: Wrong Answer

Solution code:
""" AtCoder"""

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

A_min = min(A)
count = 0
for i in range(N):
    if A[i] % A_min == 0:
        count += 1
    else:
        break

if count == N:
    print(A_min)
    exit()

for i in range(N):
    if A[i] % 2 == 1:
        print(1)
        exit()

print(2)

Submission status: Wrong Answer

Solution code:
import sys

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

a.sort()
for i in range(1, n):
    if a[i] % a[0] != 0:
         print(1)
         sys.exit()

print(a[0])

Submission status: Wrong Answer

Solution code:
import heapq

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

A_attention = heapq.nlargest(2, set(A))
A_attention.append(0)

print(A_attention[1] - A_attention[0] % A_attention[1] if A_attention[1] != 0 and A_attention[0] % A_attention[1] != 0 else min(A) )

Submission status: Wrong Answer

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

for i in range(n):
    t = max(arr) % min(arr)
    if t == 0:
        arr.pop(arr.index(max(arr)))
    else:
        arr[arr.index(max(arr))] = t
    if len(arr) == 1:
        break
print(min(arr))

Submission status: Wrong Answer

Solution code:
n = int(input())
A = [int(i) for i in input().split()]
while True:
    x = A.index(min(A))
    a = A.pop(x)
    for i in range(len(A) - 1):
        A[i] %= a
    if sum(A) == 0 or len(A) == 1:
        print(a)
        break
    A = list(set(A))
    if 0 in A:
        A.remove(0)
    A.append(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()))
s = sum(a)
c = []
for i in range(len(a)):
  c.append(s%a[i])
if min(c) == 0:
  print(min(a))
else:
  print(min(c))

Submission status: Wrong Answer

Solution code:
N = int(input())
monster = list(map(int, input().split()))
monster.sort()
if len(monster) == 1 or 1 in monster:
  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:
A = [int(i) for i in input().split()]

min = 1000000001
num = {}
odd = False
even = False

for i in A:
    if min > i: min = i
    for j in A:
        if i > j:
            b = i
            s = j
        else:
            b = j
            s = i

        if i%j == 0:
            continue
        if i%j%2 == 0:
            even = True
        else:
            odd = True

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

Submission status: Wrong Answer

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

if A[0] == A[-1]:
    print(A[0])
    exit()

if all([a % 2 == 0 for a in A]):
    print(2)
    exit()

print(2)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
for i in a:
    a.extend([j % i for j in a if j % i > 0 and j > i])
    a = list(set(a))
print(min(a))

Submission status: Wrong Answer

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

# 1番大きいものを2番目に大きいものでわる
for i in range(N):
    tmp = A[0] % A[1] != 0
    if tmp != 0:
        A[0] = A[0] % A[1]
    A = sorted(A, reverse = True)

print(min(A))

Submission status: Wrong Answer

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

A = list(set(B))

A.sort()

if A[0] == 1:
    print(A[0])
    exit()

if len(A) == 1:
    print(A[0])

else:
    a = A[0]
    b = A[1]
    tmp = 0

    while True:
        if b % a != 0:
            tmp = b % a
            b = a
            a = tmp
        else:
            break


    print(a)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(m) for m in input().split()]
a.sort()
new = [a[0]]
for i in range(1, n):
    new.append(a[i] % a[0])

for i in range(1, n):
    if new[i] != 0:
        print(1)
        exit()
print(a[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import random
n = int(input())
enemies = list(map(int,input().split()))
while True:
  en_at = random.randrange(len(enemies))
  while True:
    en_h = random.randrange(len(enemies))
    if en_at != en_h: break
  enemies[en_h]-=enemies[en_at]
  if enemies[en_h]<=0: enemies.pop(en_h)
  if len(enemies)==1:
    break
print(enemies[0])

Submission status: Wrong Answer

Solution code:
N = int(input())

A = list(map(int,input().split()))
i = 0
while True:
    A.sort()
    for a in range(len(A)-1):
        if A[a+1] - A[a] >= 1000000:
            A[a+1] = A[a+1] - A[a] * 10000
        A[a+1] = A[a+1] - A[a]

    A = [i for i in A if  i > 0]
    if len(A) == 1:
        break

print(A[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int,input().split()))
ans = min(lst)
if sum(lst)%ans == 2:
    ans = 2
elif sum(lst)%ans != 0:
    ans = 1

print(ans)

Submission status: Wrong Answer

Solution code:
N=int(input())
a=list(map(int,input().split()))
import collections

a=sorted(a)
mi=a[0]
g=0
k=0
t=0
gset=set()
loopnum=len(a)-1
i=1
while i<=loopnum:
    if(0<a[i]%mi<mi):
        a.append(mi)
        mi=a[i]%mi
        print(mi)
        loopnum+=1
    i+=1
        
if(t==N-1):
    print(mi)
else:
    print(mi)

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:
    if A[N-1] % A[N-2] != 0:
        A[N-1] = A[N-1] % A[N-2]
        A = sorted(A)
        list.append(min(A))
        iii += 1
        
        if iii > 100:
            break
    else:
        break
#print(list)
print(min(list))

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 (a%b)==0:
  print(b)
elif (b%a)==0:
  print(a)
else:
  print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
array = [int(x) for x in input().split()]
if len(set(array)) == 1:
    print(array[0])
    exit()
even = False
odd = False
two = False
one = False
for i in array:
    if i % 2 == 0:
        even = True
    elif i % 2 != 0:
        odd = True
    if i == 1:
        one = True
    if i == 2:
        two = True
else:
    if even and odd:
        print(1)
    elif even:
        min_array = min(array)
        tmp = [x - min_array for x in array if x - min_array > 0]
        print(min(tmp + [min_array]) if not two else 2)
    elif odd:
        min_array = min(array)
        tmp = [x % min_array for x in array if x % min_array != 0]
        for i in tmp:
            if i % 2 == 0:
                even = True
            elif i % 2 != 0:
                odd = True
        print(1 if even else min(tmp+[min_array]) if not one else 1)

Submission status: Wrong Answer

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

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

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

    
print(small_As[1])

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array(list(map(int, input().split())))

#A_cnt = N
while True:
    #print(np.where(A>0))
    A_not_zero = A[np.where(A != 0)[0]]
    #print(A_not_zero)
    min_a = min(A_not_zero) # 0より大きい最小値
    A = np.array(list(map(lambda x: (x if x == min_a or x == 0 else x % min_a), A)))
    #print("A", A)
    #print("len", len(set(A)))
    a = sorted(set(A))
    if len(a) == 2:
        result = a[1]
        break
    elif len(a) == 1:
        result = a[0]
        break
print(result)

Submission status: Wrong Answer

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

m = a[-1]
b = []
if n == 1:
	print(a[0])
	exit()

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

if max(b) == 0:
	print(a[-1])
	exit()
else:
	print('1')

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()
    for na in a:
        cs.add(na)
    ccb = it.combinations(a, 2)
    for (x,y) in it.combinations(a, 2):
        if x > y:
            cs.add(x%y)
        else:
            cs.add(y%x)
    for (x,y) in it.combinations(cs, 2):
        if x == 0 or y == 0:
            pass
        else:
            if x > y:
                cs.add(x%y)
            else:
                cs.add(y%x)
    l = sorted(list(cs))
    if l[0] == 0:
        print(l[1])
    else:print(l[0])

Submission status: Wrong Answer

Solution code:

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

  monsters = sorted(monsters)
  # print(monsters)

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

    # print(monsters)
    if 0 in monsters:
      # monsters = is_include_0(monsters)

      monsters = list(set(monsters))
      monsters.remove(0)
      monsters = sorted(monsters)

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

    if len(monsters) == 1:
      break
  print(monsters[0])

main()

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
A = list(map(int, input().split()))
import math
A.sort()
ans = 10000000000000000000000000000000000000000000

for i in A:
    ans = fractions.gcd(ans, i)

print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
lst = list(map(int,input().split()))
ans = min(lst)
if sum(lst)%ans != 0:
    ans = 1
print(ans)

Submission status: Wrong Answer

Solution code:
#ABC118C-MonstersBattleRoyale.py

from sys import stdin

input = stdin.readline

N = int(input())

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

A = set(A)
A = list(A)

while True:
    A.sort()
    for i in range(1,len(A)):
        A[i] = A[i] - A[0]
    if A[0] == 0 or len(A)==1:
        break

i = 0
while True:
    if A[i] != 0:
        print(A[i])
        break
    i += 1

Submission status: Wrong Answer

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

  monsters = sorted(monsters)
  # print(monsters)

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

    # print(monsters)
    if 0 in monsters:
      # monsters = is_include_0(monsters)

      monsters = list(set(monsters))
      monsters.remove(0)
      monsters = sorted(monsters)

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

    if len(monsters) == 1:
      break
  print(monsters[0])

main()

Submission status: Wrong Answer

Solution code:
n = int(input())
monster = list(map(int,input().split()))
if min(monster)==max(monster):
  print(min(monster))
  exit()

for hp in monster:
  if hp%2==1:
    print(1)
    exit()
print(2)

Submission status: Wrong Answer

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

f = 0
for i in range(n):
    if a[i] % 2 == 1:
        f = 1
    break

p = 0
for i in range(n):
    if a[i] % min(a) == 0:
        p += 1
if p == n:
    f = 2

if f == 0:
    print(2)
elif f == 1:
    print(1)
else:
    print(min(a))

Submission status: Wrong Answer

Solution code:
n=int(input())
a_s=list(map(int,input().split()))
while True:
    if len(a_s)==2:
        break
    a_s=set(a_s)
    a_s=list(a_s)
    if len(a_s)==1:
        print(a_s[0])
        exit()
    min = sorted(a_s)[1]
    index=a_s.index(min)
    for i in range(len(a_s)):
        if i!=index:
            a_s[i]=a_s[i]%min
print(sum(a_s))

Submission status: Wrong Answer

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

m = min(A)

def MBR(l):
    global m
    m1 = min([i for i in l if i > 0]+[m])
    if m > m1:
        m = m1
    return [MBR([m % i for m in l]) for i in l if i > 0]

MBR(A)
print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
p = [int(x) for x in input().split(' ')]


p.sort()
#print(p)
res = 10e+10
zcnt = 0
for i in range(N-1):
  a,b = p[i],p[i+1]
  #print(a,b)
  rr = abs(int(b / a) * a - b)
  #print('rr',rr)
  if rr > 0:
    if rr < res:
      res = rr
  else:
    zcnt+=1
  #print(rr)
#print('zcnt',zcnt)
if zcnt == 0:
  res = 1
elif zcnt == N-1:
  res = b
print(int(res))

Submission status: Wrong Answer

Solution code:
#ABC118C-MonstersBattleRoyale.py

from sys import stdin

input = stdin.readline

N = int(input())

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

while True:
    if A[0] == A[1]:
        break
    A.sort()
    for i in range(1,len(A)):
        A[i] = A[i] - A[0]
    if A[0] == 0:
        break

i = 0
while True:
    if A[i] != 0:
        print(A[i])
        break
    i += 1

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
a_min = a[0]
b = [a_min]
for element in a:
    if not element % a_min == 0 and element % a_min < a_min:
        a_min = element % a_min
        b.append(a_min)
    elif element < a_min:
        a_min = element
        b.append(a_min)
old_b = []
while True:
    if b != old_b:
        old_b = b
        b.clear()
        old_b.sort()
        for element in old_b:
            if not element % a_min == 0 and element % a_min < a_min:
                a_min = element % a_min
                b.append(a_min)
            elif element < a_min:
                a_min = element
                b.append(a_min)
    else:
        break
print(a_min)