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 heapq

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

A_attention = heapq.nlargest(2, A)

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

Submission status: Wrong Answer

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

res = 100000000
for a in a_list:
    temp = [a for a in a_list]
    temp = list(map(lambda x:x%a, temp))
    temp_ans = a-max(temp)
    res = min(res, temp_ans)

print(res)

Submission status: Wrong Answer

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

a.sort()
ans = float('inf')
for i in range(n):
    for j in range(i + 1, n):
        ans = min(ans, a[i] - a[j] % a[i])

print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
monsters = sorted(map(int, input().split()), reverse=True)
 
while True:
  a, b = monsters[-2:]
  c = a - b
  if c > 0:
    monsters.append(c)
  break
 
remain = monsters[0] % monsters[-1]
if remain == 0:
  remain = monsters[-1]
print(remain)

Submission status: Wrong Answer

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

mi = min(lis)
lis.remove(mi)
d = 0
for i in lis:
    if i % mi == 0:
        d += 1

if d == len(lis):
    print(mi)
    exit()
else:
    print(1)
    exit()

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()
def attack(a):
    if a[0] == 1:
        return 1
    if len(a) == 2:
        if a[1] % a[0] == 0:
            return a[0]
        else:
            return a[1] % a[0]

    i = 1
    while i < len(a):
        a[i] %= a[0]
        if a[i] <= 0:
            a.remove(a[i])
            if len(a) == 2:
                if a[0] > a[1]:
                    a[0], a[1] = a[1], a[0]
                if a[1] % a[0] == 0:
                    return a[0]
                else:
                    return a[1] % a[0]
            continue
        i += 1
    
    if a[0] > a[1]:
        a[0], a[1] = a[1], a[0]
    
    return(attack(a))

print(attack(a))

#%%

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(input())
A_list= sorted(list(map(int, input().split())))[-1::-1]

while(True):
    residual = []
    for idx, A in enumerate(A_list):
        if idx == N-1:
            continue
        else:
            residual.append(A_list[idx] - A_list[idx+1])
    minimum_idx = np.argmin(residual)
    if A_list[minimum_idx] > A_list[minimum_idx+1]:
        bigger = minimum_idx
        smaller = minimum_idx+1
    else:
        bigger = minimum_idx+1
        smaller = minimum_idx
#     print(bigger, smaller, A_list, residual)
        
    if A_list[smaller] == 0:
        break
        
    A_list[bigger] = A_list[bigger] - A_list[smaller]
    
    
print(np.max(A_list))

Submission status: Wrong Answer

Solution code:
n = int(input())

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

a.sort()

b = []
for i in range(n):
    for j in range(i+1,n):
        if a[j] % a[i] != 0:
            b.append(a[j] % a[i])
            
check = sorted(list(set(b + a)))
ans = 10 ** 9
for i in range(len(check)-1):
    ans = min(ans, check[i+1] - check[i])
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()
for i in range(1,len(a)):
    if(a[i]!=0 and 0<a[i]%mi<mi):
        a.append(mi)
        mi=a[i]%mi
if(t==N-1):
    print(mi)
else:
    print(mi)

Submission status: Wrong Answer

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

if len(set(a)) == 1:
    print(a[0])
else:
    if sum(a) % min(a) == 0:
        result = min(a)
    else:
        result = (sum(a) % min(a)) - (max(a)%min(a))
    print(result)

Submission status: Wrong Answer

Solution code:
""" AtCoder"""

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

if sum(A) == A[0] * N:
    print(A[0])
    exit()

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

print(2)

Submission status: Wrong Answer

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

min = 1000000001
num = {}
for i in A:
    if min > i: min = i
    for j in A:
        if i > j:
            num[i%j] = 1
        else:
            num[j%i] = 1

odd = False
even = False
for k in num:
    if k == 0: continue
    if k % 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(int(i) for i in input().split())

A.sort()


if((A[1] - A[0]) == 0):
    min_HP = A[0]
    print(min_HP)
else:
    min_HP = A[1] - A[0]
    while((A[1] - A[0]) > 0):
        A.insert(0, A[1] - A[0])
        A.sort()
        if((A[1] - A[0]) == 0):
            break
        min_HP = A[1] - A[0]

    tmp_min = min_HP
    for a in A:
        if ((a % tmp_min) < min_HP and (a % tmp_min) > 0):
            min_HP = tmp_min
    print(min_HP)

Submission status: Wrong Answer

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


main()

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
for i in range(n):
    if a[i] % min(a) != 0:
        break
    break
    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 = list(map(int, input().split()))
a.sort(reverse=True)

m = a[-1]
b= []
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:
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()
for i in range(1,len(a)):
    if(a[i]%mi==0):
        t+=1
    if(a[i]%2==0):
        g+=1
        if(a[i]!=0 and 0<a[i]%mi<mi):
            a.append(mi)
            mi=a[i]%mi
    else:
        k+=1
if(t==N-1):
    print(mi)
elif(k>0):
    print(1)
else:
        print(mi)

Submission status: Wrong Answer

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

A.sort()


if((A[1] - A[0]) == 0):
    min_HP = A[0]
else:
    min_HP = A[1] - A[0]
    while((A[1] - A[0]) > 0):
        A.insert(0, A[1] - A[0])
        A.sort()
        if((A[1] - A[0]) == 0):
            break
        min_HP = A[1] - A[0]

tmp_min = min_HP
for a in A:
    if ((a % tmp_min) < min_HP and (a % tmp_min) > 0):
        min_HP = tmp_min

print(min_HP)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

while True:
    m = min(As)
    idx = As.index(m)
    As = [a if i == idx else a % m for i, a in enumerate(As)]
    As = [a for a in As if a > 0]
    print(idx, m, As)
    if len(As) == 1:
        break
print(As[0])

Submission status: Wrong Answer

Solution code:
def f(a, m):
  if a % m == 0:
    return m
  else:
    return a % m

def solve():
  N = int(input())
  A = list(map(int, input().split()))
  while True:
    m = min(A)
    print(list(map(lambda a: f(a, m), A)))
    A = list(map(lambda a: f(a, m), A))
    if all([a == m for a in A]): return m

print(solve())

Submission status: Wrong Answer

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

A.sort()


if((A[1] - A[0]) == 0):
    min_HP = A[0]
else:
    min_HP = A[1]
    while((A[1] - A[0]) > 0):
        A.insert(0, A[1] - A[0])
        A.sort()
        if((A[1] - A[0]) == 0):
            break
        min_HP = A[1] - A[0]

tmp_min = min_HP
for a in A:
    if ((a % tmp_min) < min_HP and (a % tmp_min) > 0):
        min_HP = tmp_min

print(min_HP)

Submission status: Wrong Answer

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

temp = 1e10
sA = sorted(A)
divs = [sA[0]]+[k if k > 0 else sA[0] for k in np.diff(sA)]
divs = list(set(divs))

for i in range(N):
    temp = min(temp,min([A[i]%a if A[i]%a > 0 else A[i] for a in divs]))

print(temp)

Submission status: Wrong Answer

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

for hp in monster:
  if hp%2==0:
    cnt+=1
print(1 if cnt>0 else 2)

Submission status: Wrong Answer

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

md = None
for a, b in zip(sorted(alist), sorted(alist)[1:]):
  if md is None:
    md = b % a if b % a != 0 else a
    if md - a != 0:
      md = min(md, abs(md - a))
  else:
    _md = b % md if b % md != 0 else md
    if _md - md != 0:
      _md = min(_md, abs(_md - md))
    ab = b % a if b % a != 0 else a
    if ab - a != 0:
      ab = min(ab, abs(ab - a))
    md = min(_md, ab)
print(md)

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]
while 1:
  if a>b:
    a=a-b
  elif a<b:
    b=b-a
  elif a==b:
    print(a)
    break

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int,input().split()));d = 0
while True:
    a.sort()
    if a[-2] == 0:break
    c = d-1;d = 0
    for i in range(len(a)):
        if i <= c or i == 0:
            d += 1;continue
        a[i] = a[i]%a[c]
        if a[i] == 0:d+=1
print(a[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split(" ")))
A = [a for a in A if a >= 1]

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

temp = A[0]
for i in range(N-1):
    temp = gcd(A[i], A[i+1])
    if temp == 1:
        break
print(temp)

Submission status: Wrong Answer

Solution code:
print("2")

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
ans = A[0]

for i in A[1:]:
    print(ans)
    x = i%ans
    if not x == 0:
        ans = min(ans, i%ans)

print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

n = int(input().strip())
az = list(map(int, input().strip().split()))

az.sort()

a, b = az[:2]

while True:
    m = b % a
    if m == 0:
        print(a)
        break
    else:
        b = m
        if b < a:
            a, b = b, a

Submission status: Wrong Answer

Solution code:
print("1")

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
a_min = a[0]
b = []
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)
while True:
    if not a == b:
        a = b
        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)
    else:
        break
print(a_min)

Submission status: Wrong Answer

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

tmp=A[0]
for a in A[1:]:
  if a%tmp!=0:
    tmp=a%tmp
    
for a in A:
  if a%tmp!=0:
    tmp=a%tmp
    
print(tmp)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = np.array([int(i) for i in input().split()])

dev_list=[]

for i in range(N):
    dev_list.extend(A%A[i])
dev_list = np.unique(np.array(dev_list))

if(np.sum(dev_list)==0):
    print(np.min(A))
else:
    devdev_list = []
    for i in dev_list:
        devdev_list.extend(A%i)
    devdev_list = np.array(devdev_list)

    print(int(np.min(devdev_list[devdev_list>0])))

Submission status: Wrong Answer

Solution code:
print("3")

Submission status: Wrong Answer

Solution code:
N = int(input())

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


ans_L = []
for i in L:
    flag = 0
    for j in L:
        if j % i == 0:
            pass
        else:
            flag = 1
    if flag == 0:
        ans_L.append(i)


if len(ans_L) == 0:
    print(1)
else:
    print(min(ans_L))

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:
  print(data[0])
else:
  for i in range(N-1):
      data=np.sort(data)
      minv=data[0]
      data[1:]=data[1:]-minv
  print(np.sort(data)[0])

Submission status: Wrong Answer

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

A = list(set(B))

A.sort()

if len(set(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())
monstar = list(map(int, input().split()))
monstar.sort()
min1, min2 = monstar[0], monstar[1]
while min1 >= 1 and min2 >= 1:
  if min1 < min2:
    min2 -= min1
  else:
    min1 -= min2
print(max(min1, min2))

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

print((max_val+min_val) % N)

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:
    A.sort()
    if A[0] == A[1]:
        break
    for i in range(1,N):
        A[i] = A[i] - A[0]

for i in A:
    if i != 0:
        print(A[0])
        break

Submission status: Wrong Answer

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

def gcd(x, y):
    while y != 0:
        x, y = y, x % y
    return x

temp = A[0]
for i in range(N-1):
    temp = gcd(A[i], A[i+1])
    if temp == 1:
        break
print(temp)

Submission status: Wrong Answer

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

A.sort()


if((A[1] - A[0]) == 0):
    min_HP = A[0]
else:
    min_HP = 0
    while((A[1] - A[0]) > 0):
        A.insert(0, A[1] - A[0])
        A.sort()
        if((A[1] - A[0]) == 0):
            break
        min_HP = A[1] - A[0]

print(min_HP)

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:
    A.sort()
    if A[0] == A[1]:
        break
    for i in range(1,N):
        A[i] = A[i] - A[0]

for i in A:
    if i != 0:
        print(A[0])

Submission status: Wrong Answer

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

def judge(tmp_one, tmp_two):
    flg = 1
 
    while flg:
        if tmp_two%tmp_one == 0:
            tmp_two = tmp_one
        else:
            tmp_two = tmp_two%tmp_one
 
        if tmp_one%tmp_two == 0:
            tmp_one = tmp_two
        else:
            tmp_one = tmp_one%tmp_two
        if tmp_one == tmp_two:
            flg = 0
    return tmp_one

tmp_one = As[0]
for i in range(1, N):
    if i == N - 1:
        tmp_two = As[i]
    elif As[i] != As[0]:
        tmp_two = As[i]
        break

tmp = judge(tmp_one, tmp_two)
print(tmp)

Submission status: Wrong Answer

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

A.sort()

m = A[0]
del A[0]

while True:
    flag = True
    new = list()
    for a in A:
        tmp = a % m
        if tmp != 0 and tmp < m:
            new.append(tmp)
            flag = False

    if flag:
        break
    else:
        m = min(new)

print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
k = sorted([int(i) for i in input().split()])
print(min([k[i]-k[i]%k[n-1] for i in range(n-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()]

sameFlg = 1
fastValue = A[0]

if (A[0] % 2 == 0):
    kisuFlg = -1
else:
    kisuFlg = 1
    
for i in range (0, len(A)):
    if (fastValue != A[i]):
        sameFlg = -1
    if (kisuFlg == -1 and A[i] % 2 != 0):
        kisuFlg = 99
    elif (kisuFlg == 1 and A[i] % 2 == 0):
        kisuFlg = 99
    if (sameFlg == -1 and kisuFlg == 99):
        break

if (sameFlg == 1):
    print(A[0])
elif (kisuFlg == 99):
    print("1")
else:
    print("2")

Submission status: Wrong Answer

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

A.sort()

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

else:
    a = A[0]
    if A[0] != A[1]:
        b = A[1]
    else:
        b = A[2]
    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:
def go(x, y):
    return x % y == 0


N = int(input())
A = sorted(map(int, input().split()))
if N > 2:
    v1, v2, v3 = A[0], A[1], A[2]
    if go(v1, 2) and go(v2, 2) and go(v3, 2):
        print(v1)
    else:
        print(1)
else:
    v1, v2 = A[0], A[1]
    if go(v1, v2):
        print(v1)
    else:
        print(1)

Submission status: Wrong Answer

Solution code:
def func():
    pass


def main():
    n = int(input())
    a = [int(i) for i in input().split()]

    for ai in a:
        for j, bi in enumerate(a):
            x = bi % ai
            if x != 0 and bi != x and x < a[j]:
                a[j] = x

    print(min(a))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
n = int(input())
listA=list(map(int, input().split()))
listA.sort()
listAMin=listA[0]
index=0
deltaMin=100000000000
while index < len(listA)-1:
    delta = listA[index+1]-listA[index]
    if delta < deltaMin:
        deltaMin=delta
    index+=1
if listA[0]==1:
    print(1)
else:
    if deltaMin!=0:
        devided = min(deltaMin, listAMin)
    else:
        devided = listAMin
    minMonster=100000000000
    index2=0
    while index2 < len(listA):
        if listA[index]%devided !=0:
            if listA[index] % devided < minMonster:
                minMonster = listA[index] % devided
        else:
            if devided < minMonster:
                minMonster = devided
        if minMonster == 1:
            break
        index2+=1
    if minMonster == 1:
        print(minMonster)
    else:
        if minMonster > devided and minMonster%devided!=0:
            minMonster=minMonster%devided
        elif minMonster > devided:
            minMonster=devided
        print(minMonster)

Submission status: Wrong Answer

Solution code:
N = int(input())
aA=[int(_) for _ in input().split()]
iMin = min(aA)
iMax = max(aA)
if iMin  == 1:
    print(1)
else:
    iDm = [i % iMin for i in aA]
    if max(iDm) == 0:
        print(iMin)
        exit()
    else:
        print(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]
print(min)

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:
    A.sort()
    if A[0] == A[1]:
        break
    for i in range(1,N):
        A[i] = A[i] - A[0]

print(A[0])

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n = int(input())
le = []
ans = 0
l = map(int, input().split())
le = sorted(l)

for i in range(n):
    if le[i]%le[0]==0:
        ans = le[0]
    else:
        ans = 1
        break
        
print(ans)

Submission status: Wrong Answer

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

A.sort()

a = A[0]
b = A[1]

b -= int(b/a) * a

if b == 0:
    print(a)
    exit()

res = 0
while b > 0 and a > 0:
    na = max(a,b)
    nb = min(a,b)
    a = na - nb
    b = nb
    res = b
    #print(a,b)

print(res)

Submission status: Wrong Answer

Solution code:
n = int(input())
ai = list(map(int, input().split(' ')))
while len(ai) > 1:
    print(ai)
    ai = list(sorted(ai))
    ai_head = ai[0]
    ai = list(filter(lambda x: x != 0, map(lambda x: x%ai_head, list(ai[1:]))))
    ai.append(ai_head)
print(ai[0])

Submission status: Wrong Answer

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

odds_num = sum(list(map(lambda x: x % 2, a_list)))
even_num = len(a_list) - odds_num

if sum(a_list) // len(a_list) == a_list[0]:
    print(a_list[0])
elif odds_num >= 2:
    print(1)
elif even_num >= 2:
    print(2)
else:
    print(1)

Submission status: Wrong Answer

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

if len(set(a)) == 1:
    print(a[0])
else:
    if sum(a) % min(a) == 0:
        result = min(a)
    else:
        result = sum(a) % min(a)
    print(result)

Submission status: Wrong Answer

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

mi = min(a)
ma = max(a)
if mi == ma:
    print(mi)
else:
    su = sum(a) % mi
    if su == 0:
        print(mi)
    else:
        print(su)

Submission status: Wrong Answer

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

m = min(A)
flag = 0
for i in range(N):
    if A[i] % m == 0:
        flag += 1
    else:
        pass
if flag == N:
    print(m)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
#coding:utf-8

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

while len(a)>1:
  for i in range(1,len(a)):
    a[i] %= a[0]
  a.sort()
  while True:
    if a[0] == 0:
      a.remove(0)
    else:
      break;

Submission status: Wrong Answer

Solution code:
def isDivisor(a):
    ans = True
    min_ = min(a)
    for i in a:
        if not int(i % min_) == 0:
            ans = False
    return ans

def isOdd(a):
    ans = False
    for i in a:
        if not int(i % 2) == 0:
            ans = True

    return ans

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

if isDivisor(A):
    print(min(A))
elif isOdd(A):
    print(1)
else:
    print(2)

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
mg=10**10
for i in range(1,len(a)):
    if(a[i]%mi==0):
        t+=1
    if(a[i]%2==0):
        g+=1
        mg=min(mg,a[i]%mi)
    else:
        k+=1
if(t==N-1):
    print(mi)
elif(k>0):
    print(1)
else:
    print(mg)

Submission status: Wrong Answer

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

odds_num = sum(list(map(lambda x: x % 2, a_list)))
even_num = len(a_list) - odds_num

if sum(a_list) // len(a_list) == a_list[0]:
    print(a_list[0])
elif odds_num >= 2:
    print(1)
elif odds_num >= 2:
    print(2)
else:
    print(1)

Submission status: Wrong Answer

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

minutes_mod = min(l)
minutes_mod_list = list()

for i in l:
    if i < minutes_mod:
        new_l = [j % i for j in l]
    else:
        new_l = [j % minutes_mod for j in l]
    new_l_set = list(set(new_l))
    if 0 in new_l_set:
        new_l_set.remove(0)
    if len(new_l_set) != 0:
        minutes_mod_list.append(min(new_l_set))
        minutes_mod = min(new_l_set)

print(minutes_mod)

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

absA = []
A.sort()
for i in range(N-1):
    absA.append(abs(A[i+1]-A[i]))

tmp = min(absA)
if tmp != 0:
    ar = np.array(A,dtype=int)
    ans = ar % tmp
    n = np.min(ans)

    if n == 0:
        print(min(A))
    else:
        print(n)
else:
    print(min(A))

Submission status: Wrong Answer

Solution code:
def isDivisor(a):
    ans = True
    min_ = min(a)
    for i in a:
        if not int(i % min_) == 0:
            ans = False
    return ans

def isOdd(a):
    ans = False
    for i in a:
        if not int(i % 2) == 0:
            ans = True

    return ans

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

if isDivisor(A):
    print(A[0])
elif isOdd(A):
    print(1)
else:
    print(2)

Submission status: Wrong Answer

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

if len(monsters) == 1:
    ans = monsters[0]
else:
    ans = 2

for i in monsters:
    if i%2 == 1:
        ans = 1
        break
#print(monsters)
print(ans)

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
for i in range(n):
    if a[i] % min(a) != 0:
        break
    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_list = list(map(int, input().split()))

odds_num = sum(list(map(lambda x: x % 2, a_list)))
even_num = len(a_list) - odds_num

if sum(a_list) // len(a_list) == a_list[0]:
    print(a_list[0])
elif odds_num >= 2:
    print(1)
else:
    print(2)

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
        for idx,life in enumerate(A_list):
            if life == min_:
                pass
            else:
                A_list[idx] = life - min_
    if not flag:
        break
print(min_)

Submission status: Wrong Answer

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

smallest = min(list_HP)
list_HP.remove(smallest)
second = min(list_HP)

while (0<smallest) & (0<second):
	if smallest < second:
		second = second - smallest
	else:
		smallest = smallest - second

if (0<smallest):
	print(smallest)
else:
	print(second)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
N = int(input())
A = list(map(int,input().split()))
for i in range(N-1):
    res = gcd(A[i+1],A[i])
    if res == 1:
        print(1)
        exit()
print(min(A))

Submission status: Wrong Answer

Solution code:
n=int(input())
#for i in range(n):
tmp=list(map(int, input().split(" ")))
if len(set(tmp))==1:
    A=tmp
else:
    A=list(set(tmp))
#if n>2:
#    A=list(set(list(map(int, input().split(" ")))))
#else:

A.sort()
t1=A[0]
t2=A[1]

while t1!=t2:
    #print(t1)
    if t1>t2:
        t1=t1-t2
    else:
        t2=t2-t1

print(t1)

Submission status: Wrong Answer

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

a.sort()
res = a[0]
amari = [0]*10**5

for i in range(n):
    for j in range(n):
        if i==j:
            continue
        if a[i]%a[j]!=0:
            amari[i] = a[i]%a[j]

for i in range(n):
    for j in range(n):
        if i==j:
            continue
        if (amari[i]+amari[j])%a[j] < res and (amari[i]+amari[j])%a[j]!=0 :
            res = (amari[i]+amari[j])%a[j] 
        if (amari[i]+amari[j])%a[i] < res and (amari[i]+amari[j])%a[i]!=0:
            res = (amari[i]+amari[j])%a[i]
else:
    print(res)

Submission status: Wrong Answer

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

a.sort()

while a[0]>0 and a[1]>0:
    a[1] -= a[0]
    a.sort()

print(a[1])

Submission status: Wrong Answer

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

A.sort()

if len(set(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 = list(map(int,input().split()))
a.sort()
OK = True
for i in range(1,n):
     a[i] = a[i]%a[0] if a[i]%a[0]!=0 else a[0]
a.sort()
for i in range(1,n):
    if a[i]%a[0]!=0:
        OK = False
print(a[0] if OK else 1)

Submission status: Wrong Answer

Solution code:
import sys
from operator import itemgetter
import collections


def r(n, al):
    al.sort()

    bm = sys.maxsize
    for i in range(n):
        m = al[i] % bm
        if m != 0 and bm > m:
            bm = m
    return bm


def main():
    input = sys.stdin.readline
    n = int(input())
    al = list(map(int, input().split()))

    print(r(n, al))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

n = int(input().strip())
az = list(map(int, input().strip().split()))

az.sort()

a, b = az[:2]

if b % a == 0:
    print(a)
else:
    print(1)

Submission status: Wrong Answer

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

tmp=A[0]
for a in A[1:]:
  if a%tmp!=0:
    tmp=a%tmp
    
print(tmp)