Problem:


Score : 300 points

Problem Statement

There are N monsters, numbered 1, 2, ..., N.

Initially, the health of Monster i is A_i.

Below, a monster with at least 1 health is called alive.

Until there is only one alive monster, the following is repeated:

A random alive monster attacks another random alive monster.

As a result, the health of the monster attacked is reduced by the amount equal to the current health of the monster attacking.

Find the minimum possible final health of the last monster alive.

Constraints

All values in input are integers.

2 \leq N \leq 10^5

1 \leq A_i \leq 10^9

Input

Input is given from Standard Input in the following format:

N
A_1 A_2 ... A_N

Output

Print the minimum possible final health of the last monster alive.

Sample Input 1

4
2 10 8 40

Sample Output 1

2

When only the first monster keeps on attacking, the final health of the last monster will be 2, which is minimum.

Sample Input 2

4
5 13 8 1000000000

Sample Output 2

1

Sample Input 3

3
1000000000 1000000000 1000000000

Sample Output 3

1000000000



Sample input:
4
2 10 8 40


Sample output:
2

Submission status: Wrong Answer

Solution code:
N = int(input())
A = 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]

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

Submission status: Wrong Answer

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

hp = list(set(hp))
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()))
A = sorted(A)
A_ = [2*i for i in A]
A_ = [i%A[0] for i in A_]
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())
array = sorted([int(x) for x in input().split()])
if len(set(array)) == 1:
    print(array[0])
    exit()
even = False
odd = False
for i in array:
    if i % 2 == 0:
        even = True
    elif i % 2 != 0:
        odd = True
else:
    if even and odd:
        print(1)
        exit()
while True:
    min_array = array[0]
    tmp_array = list(array)
    array = sorted([max(0, x%min_array) if max(0, x%min_array) != 0 else x for x in array])
    if len(set(array)) == 1 or array == tmp_array:
        break
print(array[0] if array else min_array)

Submission status: Wrong Answer

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

print(ans)

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:
      # print('aa')


  print(monsters[0])

main()

Submission status: Wrong Answer

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

odd = False
even = False
for i in A[0:int(N/2)+1]:
    for j in A[int(N/2):]:
        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): break

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

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[0]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
n=int(input())
enemy=(list(map(int,input().split())))
enemy.sort()
enemy.reverse()
while len(enemy)>1:
    enemy[0]=enemy[0]%enemy[1]
    if enemy[0]==0:
        del enemy[0]
    elif enemy[0]==1:
        break
    else:
        damaged=enemy[0]
        del enemy[0]
        length=len(enemy)
        for i in range(length):
            if damaged>enemy[i]:
                enemy.insert(i,damaged)
                break
print(enemy[0])

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()
    count = 0
    while(count <= 10 ^ 9):
        count = count + 1
        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:
from fractions import gcd

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


answer = 500000000000

e.sort(reverse=True)
for i in range(0,n-2):
    for j in e[i+1:n-1]:
        if gcd(e[i],j) < answer:
            answer = gcd(e[i],j)
            
print(answer)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
if all(A[0]==a for a in A):
    print(A[0])
else:
    B = []
    D = []
    for a in A:
        for i in range(len(A)):
            if A[i]%a != 0:
                B.append(A[i]%a)
                C = list(set(B))
                C.sort()
    for i in range(len(C)-1):
        D.append(abs(C[i]-C[i+1]))
    print(min(min(C),min(D)))

Submission status: Wrong Answer

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

f = 0
p = 0
for i in range(n):
    if a[i] % 2 == 1:
        f = 1
    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 = [int(i) for i in input().split()]

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


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

print(ans)

Submission status: Wrong Answer

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

minimum = np.min(A)

while 1:
    data = np.unique(A%minimum)
    data = data[data>0]
    dev_list = []
    for i in data:
        dev_list.extend(A%i)
    dev_list=np.array(dev_list)
    if(len(dev_list)==0):
        break
    if((minimum<np.min(dev_list))):
        break
    else:
        minimum = np.min(dev_list)
print(minimum)

Submission status: Wrong Answer

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

B = []
for i in range(len(A)):
	init = A[i]
	for j in range(len(A)):
		if(i == j or A[i] < A[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 = A[i]
	for j in range(len(A)):
		if(i == j or A[i] < A[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:
n = int(input())
aarr = list(map(int,input().split()))
barr=[]
ans = float('inf')
for i in range(n):
    for j in range(n):
        barr += [aarr[j] % aarr[i]]
    tmp = aarr[i] - max(barr)
    ans = min(ans,tmp)
    barr = []
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input()) 
#n=3
lst = [int(i) for i in input().split()]
#lst = [2, 10, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [1000000000, 1000000000, 1000000000]
hps = np.array(lst)
while(1):
    hps = sorted(hps)
    #print(hps)
    if(hps[0]==0): break
    if(hps[0]==hps[n-1]): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

Submission status: Wrong Answer

Solution code:
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

n = int(input())
a = list(map(int, input().split()))
a.sort()
b = []
for i in reversed(range(0, n - 1)):
    k = a[i + 1] % a[i]
    if k == 0:
        k = a[i]
    b.append(k)
b = deque(b)
ans = 10 ^ 9
for i in b:
    if i == 1:
        ans = 1
        break
    for j in a:
        k = j % i
        if k == 0:
            k = ans
        ans = min(k, i)
print(ans)

Submission status: Wrong Answer

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

if N == 2:
    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])
        
else:
    small_As = [As[0], As[1] , As[2]]
    tmp1 = small_As[1] - small_As[0]
    tmp2 = small_As[2] - small_As[1]
    tmp3 = small_As[2] - small_As[0]
    
    while tmp1 > 0 or tmp2 > 0 or tmp3 > 0:
        tmp1 = small_As[1] - small_As[0]
        tmp2 = small_As[2] - small_As[1]
        tmp3 = small_As[2] - small_As[0]
        small_As.append(tmp1)
        small_As.append(tmp2)
        small_As.append(tmp3)
        small_As.sort()
    
    for i in range(1, len(small_As)):
        if small_As[i] > 0:
            print(small_As[i])
            break

Submission status: Wrong Answer

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

a.sort()

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

min_amari = a[0]

for amari in amaris:
    if amari != 0 and amari < min_amari:
        min_amari = amari

#print(min_amari)
amari = min_amari
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:
n = int(input())
a_list = list(map(int, input().split()))

def second_get(List):
    max_val = max(List)
    List = [x for x in List if x!=max_val]
    return max(List)

def hoge(i, temp_list):
    if sum(temp_list)==0:
        return i
    else:
        temp_list = sorted(temp_list, reverse=False)
        dev = temp_list[-2]
        if dev == 0:
            return temp_list[-1]
        new_temp = list(map(lambda x:x%dev, temp_list))
        return hoge(dev, new_temp)
a_list = sorted(a_list,reverse=False)
print(hoge(a_list[-2], a_list))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
m = A[0]
l = [max(A)]*(N-1)
A = A[1:]
B = [0]*len(A)
while(len(B) > 2):
  B = [0]*len(A)
  cnt = len(B)
  #print('0', A)
  #print(m)
  for i in range(len(A)):
    if cnt > 0:
      B[i] = A[i] % m
      if B[i] == 0:
        cnt -= 1
      if B[i] < m and B[i] > 1:
        m = B[i]
  A = [B[i] for i in range(len(B)) if B[i] != 0]
  A.sort()
if A == []:
  print(m)
else:
  print(min(A))

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)
  rr1 = abs(int(b / a) * a - b)
  rr2 = abs(int(b / res) * res - b)
  if rr1 != 0:
    if rr1 < res:
      res = rr1
  if rr2 != 0:
    if rr2 < res:
      res = rr2
  #print('rr',a,b,rr1,rr2)

print(int(res))

Submission status: Wrong Answer

Solution code:
import numpy as np
n = int(input()) 
#n=3
lst = [int(i) for i in input().split()]
#lst = [2, 10, 8, 40]
#lst = [5, 13, 8, 1000000000]
#lst = [1000000000, 1000000000, 1000000000]
hps = np.array(lst)
while(1):
    hps = sorted(hps)
    print(hps)
    if(hps[0]==0): break
    if(hps[0]==hps[n-1]): break
    hps[1] = hps[1] - hps[0]
print(hps[1])

Submission status: Wrong Answer

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

if N == 2:
    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])
        
else:
    small_As = [As[0], As[1] , As[2]]
    tmp1 = small_As[1] - small_As[0]
    tmp2 = small_As[2] - small_As[1]
    
    while tmp1 > 0 or tmp2 > 0:
        tmp1 = small_As[1] - small_As[0]
        tmp2 = small_As[2] - small_As[1]
        small_As.append(tmp1)
        small_As.append(tmp2)
        small_As.sort()
    
    for i in range(1, len(small_As)):
        if small_As[i] > 0:
            print(small_As[i])
            break

Submission status: Wrong Answer

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

min_a=float('inf')
b=[]
for i in range(n):
    for i2 in range(n):
        if i == i2:
            continue
        tmp=a[i]%a[i2]
        if tmp != 0:
            b.append(tmp)
            if min_a > tmp:
                min_a = tmp
        else:
            # 0の時
            if min_a > a[i2]:
                min_a = a[i2]

for i in range(len(b)):
    for i2 in range(n):
        tmp=a[i2]%b[i]
        if tmp != 0:
            if min_a > tmp:
                min_a = tmp
        else:
            # 0の時
            if min_a > b[i]:
                min_a = b[i]
print(min_a)

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

Submission status: Wrong Answer

Solution code:
number=int(input())
hitpoint=list(map(int,input().split()))
xyz=[]
for i in range(len(hitpoint)):
    xyz.append(hitpoint[i]%2)
if hitpoint.count(hitpoint[0])==len(hitpoint):
    print(hitpoint[0])
elif hitpoint.count(1)!=0:
    print(1)
elif xyz.count(0)!=len(xyz):
    print(1)
elif xyz.count(1)==len(xyz):
    print(1)
else:
    print(2)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
'''Snippets for factorization.
Available functions:
- run_prime_factorization: Run prime factorization.
'''


def run_prime_factorization(max_number: int) -> dict:
    '''Run prime factorization.
    Args:
        max_number: Int of number (greater than 1).
    Returns:
        A dictionary's items ((base, exponent) pairs).
    Landau notation: O(log n)
    '''

    from math import sqrt

    ans = dict()
    remain = max_number

    for base in range(2, int(sqrt(max_number)) + 1):
        if remain % base == 0:
            exponent_count = 0

            while remain % base == 0:
                exponent_count += 1
                remain //= base

            ans[base] = exponent_count

    if remain != 1:
        ans[remain] = 1

    return ans


def main():
    n = int(input())
    a = list(map(int, input().split()))
    key_min = float('inf')

    for ai in a:
        key_min = min(list(run_prime_factorization(ai).keys())[0], key_min)

    mod_a = max([ai % key_min for ai in a])

    if mod_a == 0:
        print(min(a))
    else:
        print(mod_a)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def read():
    return int(input())

def reads():
    return list(map(int, input().split()))

n = read()
a = reads()
cnt = 0
m = min(a)
if m*n == sum(a):
    print(m)
    exit()

for i in range(n):
    if not  a[i] % 2 == 0:
        cnt = 1
if cnt == 1:
    print(1)
else:
    print(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] % 2 != 0:
            count += 1
            print("1")
            break
        if monsterlist[i] % minnum != 0:
            count2 += 1
    if count == 0:
        if count2 == 0:
            print(minnum)
        else:
            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:
        for i in range(1,N):
            if monsterlist[i] % 2 == 0:
                count += 1
                print("1")
                break
        if count == 0:
            print("2")

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]
        A = sorted(A)
        list.append(min(A))

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

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

    elif N >= 5 and A[N-1] % A[N-5] != 0:
        A[N-1] = A[N-1] % A[N-5]
        A = sorted(A)
        list.append(min(A))

    elif N >= 6 and A[N-1] % A[N-6] != 0:
        A[N-1] = A[N-1] % A[N-6]
        A = sorted(A)
        list.append(min(A))

    elif N >= 7 and A[N-1] % A[N-7] != 0:
        A[N-1] = A[N-1] % A[N-7]
        A = sorted(A)
        list.append(min(A))

    elif N >= 8 and A[N-1] % A[N-8] != 0:
        A[N-1] = A[N-1] % A[N-8]
        A = sorted(A)
        list.append(min(A))

    elif N >= 9 and A[N-1] % A[N-9] != 0:
        A[N-1] = A[N-1] % A[N-9]
        A = sorted(A)
        list.append(min(A))    

    elif N >= 10 and A[N-1] % A[N-10] != 0:
        A[N-1] = A[N-1] % A[N-10]
        A = sorted(A)
        list.append(min(A))   
    if iii > 100:
        break

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = input().split()
A = [int(i) for i in A]
A.sort()
sub = []
for i in range(len(A)-1):
    sub_next = A[i+1]-A[i]
    sub.append(sub_next)
min_sub = min(sub)

if(min_sub ==0):
    print(min(A))
else:
    mod = []
    for i in range(len(A)):
        mod_next = A[i]%min_sub
        mod.append(mod_next)
    min_mod = min(mod)
    if(min_mod ==0):
        print(min_sub)
    else:
        print(min_mod)

Submission status: Wrong Answer

Solution code:
n = int(input())
li = list(map(int,input().split()))
while len(li) > 1:
    i = n - 1
    while i > 0:
        if li[i] <= 0:
            del li[i]
        i = i - 1
    n = len(li)
    for j in range(n):
        li[j] = li[j] - min(li)
    minn = li.index(min(li))
    li[minn] = li[minn] + min(li)
print(li[0])

Submission status: Wrong Answer

Solution code:
import numpy as np

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

for i in range(n):
    s = np.sum(hps) - hps[i]
    if hps[i]//s >= 2:
        hps[i] -= s * (hps[i]//s - 2)

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:
#-*- 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 len(S) >= 2:
        mini = min(S)
        maxi = max(S)
        if maxi % mini == 0:
            S.remove(maxi)
        else:
            tmp = maxi % mini
            ans = mini - tmp
            S.remove(maxi)
            S.remove(mini)
            S.append(ans)

    return mini



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:
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:
N = int(input())
monster = input().split()
monster = [int(life) for life in monster]
monster.sort()
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:
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])

new.sort()
p = 0
for i in range(1, n):
    if new[i] != 0:
        p = new[i]
        break
    if i == n - 1:
        if new[i] == 0:
            print(1)
            exit()

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

Submission status: Wrong Answer

Solution code:
number=int(input())
hitpoint=list(map(int,input().split()))
xyz=[]
for i in range(len(hitpoint)):
    xyz.append(hitpoint[i]%2)
if hitpoint.count(hitpoint[0])==len(hitpoint):
    print(hitpoint[0])
elif hitpoint.count(1)!=0:
    print(1)
elif xyz.count(0)!=len(xyz):
    print(1)
else:
    print(2)

Submission status: Wrong Answer

Solution code:
n = int(input())
monster = sorted(list(map(int,input().split())))
cnt=0
for hp in monster:
  if hp%monster[0]!=0:
    if hp%2==1:
      print(1)
      exit()
    else:
      cnt+=1
print(min(monster) if cnt==0 else 2)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(sorted(map(int,input().split()),reverse=True))
L=[]
for s in a:
  L.extend([i%s for i in a if i%s!=0])
if L==[]:
  print(a[0])
else:
  print(max(L)%min(L) if max(L)%min(L)!=0 else min(L))

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(1,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:
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:
                print(1)
                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())
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
    elif N >= 5 and A[N-1] % A[N-5] != 0:
        A[N-1] = A[N-1] % A[N-5]
        A = sorted(A)
        list.append(min(A))
        iii += 1
        
        if iii > 100:
            break
    elif N >= 6 and A[N-1] % A[N-6] != 0:
        A[N-1] = A[N-1] % A[N-6]
        A = sorted(A)
        list.append(min(A))
        iii += 1
        
        if iii > 100:
            break
    elif N >= 7 and A[N-1] % A[N-7] != 0:
        A[N-1] = A[N-1] % A[N-7]
        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:
# -*- coding: utf-8 -*-
'''Snippets for factorization.
Available functions:
- run_prime_factorization: Run prime factorization.
'''


def run_prime_factorization(max_number: int) -> dict:
    '''Run prime factorization.
    Args:
        max_number: Int of number (greater than 1).
    Returns:
        A dictionary's items ((base, exponent) pairs).
    Landau notation: O(log n)
    '''

    from math import sqrt

    ans = dict()
    remain = max_number

    for base in range(2, int(sqrt(max_number)) + 1):
        if remain % base == 0:
            exponent_count = 0

            while remain % base == 0:
                exponent_count += 1
                remain //= base

            ans[base] = exponent_count

    if remain != 1:
        ans[remain] = 1

    return ans


def main():
    n = int(input())
    a = list(map(int, input().split()))
    key_min = float('inf')

    for ai in a:
        key_min = min(min(run_prime_factorization(ai).keys()), key_min)

    mod_a = max([ai % key_min for ai in a])

    if mod_a == 0:
        print(min(a))
    else:
        print(mod_a)


if __name__ == '__main__':
    main()