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 = sorted(list(map(int,input().split())))
ans = A[0]
for i in range(1, N):
    if A[i] % ans != 0:
        if ans > A[i] % ans:
            if ans % (A[i] % ans) != 0:
                ans = ans % (A[i] % ans)
            else:
                ans = A[i] % ans
        
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

a = sorted(a,reverse=True)

if a[0] % a[1] ==0:
    mi = a[0]
else:
    mi=a[0]%a[1]

for i in range(n):
    if a[i] % mi ==0:
        mi = min(mi,a[i])
    else:
        mi = min(mi,a[i]%mi)
print(mi)

Submission status: Wrong Answer

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

flag = 0
for i in range(N):
    atack = A[i]
    for j in range(N):
        if i == j or A[i] == 0:
            continue
        else:
            A[j] %= A[i]
            if A[j] != 0:
                flag = 1
                break
if flag:
    print(1)
else:
    print(sum(A))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = [int(a) for a in input().split()]
A.sort()
m1, m2 = A[0:2]
while True:
    m2 %= m1
    if m1 == 1:
        print(1)
        exit()
    elif m2 in (0, m1):
        print(m1)
        exit()
    m1, m2 = min(m1, m2), max(m1, m2)

print(m1)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = [int(i) for i in input().split()]
a.sort()
attack_min = a[0]
for i in range(1,n):
    a[i] = a[i] % attack_min
    attack_min = min(attack_min,a[i] if a[i] != 0 else attack_min)
attack_min = min(attack_min,(a[0] % attack_min if a[0] % attack_min != 0 else attack_min))
print(attack_min)

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
A.sort()
m1 = A[0]
m2 = A[1]
while True:
  m2 -= m1
  if m2 == 0:
    break
  if m1>m2:
    m1,m2 = m2,m1
print(m1)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N = int(input())
L = sorted(map(int, input().split()))

odd = [l for l in L if l % 2 != 0]
if len(odd) > 0:
    print(1)
    exit()

memo = []
memo.append(L[0])
for i in range(N):
    memo.append(gcd(memo[-1], L[i]))

print(memo[-1])

Submission status: Wrong Answer

Solution code:
from fractions import gcd

N = int(input())
L = sorted(map(int, input().split()))

odd = [l for l in L if l % 2 != 0]
if len(odd) > 0:
    print(1)
    exit()

ans = 10 ** 9
for i in range(1, N):
    ans = min(ans, gcd(L[i-1], L[i]))

print(ans)

Submission status: Wrong Answer

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

A = sorted(A)
ans = min(A)
for i in reversed(range(N - 1)):
    a = A[i + 1] - A[i]
    if a != 0:
        for x in A[:i] + A[i+1:]:
            if x % a < ans and x% a != 0:
                ans = x % a
    else:
        for x in A[:i] + A[i+1:]:
            if x % A[i+1] < ans and x % A[i+1] != 0:
                ans = i % A[i + 1]
print(ans)

Submission status: Wrong Answer

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

# 最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

ans = A[0]

for i in range(N - 1):
    ans = gcd(ans, A[i])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
Min = min(A) #Minの初期値をAの中の最小値にする
cnt = 0
if len(list(set(A))) == 1:
    print(A[0])
    exit()
while 1:
    cnt = 0
    for i in range(N):
        if A[i] != Min and A[i] != 0:
            A[i] = A[i] % Min
    for i in range(N):
        if A[i] == 0:
            cnt += 1
    if cnt == N-1:
        break
    elif len(list(set(A))) == 2:
        break
    for i in range(N):
        if Min > A[i] and A[i] != 0:
            Min = A[i]
    
print(max(A))

Submission status: Wrong Answer

Solution code:
from fractions import gcd

n = int(input())
a_lis = list(map(int,input().split()))
g = 1

for i in range(n):
	g = gcd(g,a_lis[i])
print(g)

Submission status: Wrong Answer

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

count = 0

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

Submission status: Wrong Answer

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

A.sort()
count = 0

for i in range(N-1):
    if A[i] == A[i+1]:
        count += 1
    else:
        break
         
if count == N - 1:
    print(A[0])
else:
    hantei = 1
    while hantei == 1:
        A[1] = A[1] - A[0] 
        if A[1] <= 0:
            print(A[0])
            hantei = 0
        else:
            if A[1] < A[0]:
                A[0],A[1] = A[1],A[0]

Submission status: Wrong Answer

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

L.sort()
ans=L[0]
for i in range(n-1):
  if L[i+1]%ans!=0:
    ans=L[i+1]%ans
    

print(ans)

Submission status: Wrong Answer

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

d=0
e=0
for i in a:
    if i==a[0]:
        pass
    elif i%2==0:
        d+=1
    elif i%2==1:
        e+=1
    if d>0 and e>0:
        break
    
if d==0 and e==0:
    print(min(a))
elif d!=0 and e==0:
    print(2)
else:
    print(1)

Submission status: Wrong Answer

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

t2 = sorted(t)

if t2[0] == sum(t)/n:
    print(t2[0])
else:
    if t2[0]%2 == 0 and t2[1]%2 ==0:
        print(2)
    elif t2[0]%2 != 0 or t2[1]%2 !=0:
        print(1)

Submission status: Wrong Answer

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

t2 = sorted(t)
if t2[0]%2 == 0 and t2[1]%2 ==0:
    print(2)
elif t2[0]%2 != 0 or t2[1]%2 !=0:
    print(1)

Submission status: Wrong Answer

Solution code:
n = int(input())
monster = sorted(list(map(int,input().split())))
ans = 0
for m in monster:
  if ans==0 and m%2==0:
    ans = m
  if m%2==1:
    ans = 1
    break

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
ans=1
a=list(map(int,input().split()))
if all(a[i]%2==0 for i in range(n)):
    ans=min(a)
print(ans)

Submission status: Wrong Answer

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

x = [a[1],a[0],a[1] % a[0]]
a.sort()
for i in range(1,n):
    while x[2] > 0:
        x[0] = x[1]
        x[1] = x[2]
        x[2] = x[0] % x[1]
    if i != n - 1:
        x[0] = a[i+1]
        x[2] = x[0] % x[1]

print(x[1])

Submission status: Wrong Answer

Solution code:
import sys
input=sys.stdin.readline

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

a.sort()
m = a[0]
for i in a:
    if i%m != 0 and i%m < m:
        m = i%m
print(m)

Submission status: Wrong Answer

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

nhk = sum(a_lis[1::])
z = nhk % a_lis[0]

if z==0:
	print(a_lis[0])
else:
	print(z)

Submission status: Wrong Answer

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

def GCD(a: int, b: int) -> int:
    return a if b == 0 else GCD(b, a % b)

l = [0]
r = [0]
for i in range(n):
    l.append(GCD(l[i], a[i]))
    r.append(GCD(r[i], a[n-1 - i]))
r = r[::-1]

ans = 1
for i in range(n):
    ans = max(ans, GCD(l[i], r[i+1]))

print(ans)

Submission status: Wrong Answer

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

if len(set(a)) == 1:
    print(a[0])
elif any([b % 2 == 1 for b in a]):
    print(1)
else:
    print(2)

Submission status: Wrong Answer

Solution code:
import numpy as np
N = int(input())
A = list(map(int, input().split()))
A = np.array(A)
A_set = np.unique(A)
if len(A_set) == 1:
    print(A_set[0])
else:
    if (A_set % 2 ==0).all():
        print("2")
    else:
        print("1")

Submission status: Wrong Answer

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


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


for i in range(N-1):
    ans = gcd(A[i], A[i+1])
    if ans == 1:
        print(1)
        exit()
    elif ans == 2:
        print(2)
        exit()
print(ans)

Submission status: Wrong Answer

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


if A.count(A[0]) == N:
    print(A[0])
    exit()
else:
    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 = list(map(int, input().split()))


if A.count(A[0]) == N:
    print(A[0])
else:
    for i in range(N):
        if A[i] % 2 == 1:
            print(1)
        else:
            print(2)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
n=int(input())

l=sorted(list(map(int,input().split())))
m=[l[0]]
amari=[]

for i in range(n):
    for j in range(n):
        amari.append(l[i]%l[j])

amari2=set(amari)
amari3=list(amari2)
n2=len(amari3)

for i in range(n2):
    for j in range(n2):
        if abs(amari3[i]-amari3[j])>0:
            m.append(abs(amari3[i]-amari3[j]))

print(min(m))

Submission status: Wrong Answer

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

cond = 1

while cond:
    mod = a.pop(0)
    a = sorted([mod if a[i] % mod == 0 else a[i] % mod for i in range(len(a))])

    if len(a) == 1:
        cond = 0

print(a[0])

Submission status: Wrong Answer

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

mod = a[0]

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

ans = a[n-1] % mod
print(ans) if ans != 0 else print(mod)

Submission status: Wrong Answer

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

A.sort()
ans = A[0]
for i in range(1,N):
    if A[i] % A[0] != 0:
        ans = 1

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())

l=sorted(list(map(int,input().split())))
amari=[]
for i in range(n):
    for j in range(n):
        amari.append(l[i]%l[j])

am=sorted(amari)  
if am[-1]==0:
    print(l[0])
else:
    print(am[-1]-am[-2])

Submission status: Wrong Answer

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

min_A = min(A)

for i in range(N):
#最小値で割り切れない数がある場合 -> 1
    if A[i] % min_A != 0:
        print(1)
        exit()
#全部値が同じ場合 -> min_A
#全部最小値で割り切れる場合 -> min_A
print(min_A)

Submission status: Wrong Answer

Solution code:
import sys

Submission status: Wrong Answer

Solution code:
import heapq

a = int(input())
b = list(map(int, input().split()))
heapq.heapify(b)
while True:
    c = heapq.heappop(b)
    d = heapq.heappop(b)
    if c == 0:
        print(d)
        exit()
    elif d == 0:
        print(c)
        exit()
    else:
        heapq.heappush(b, d-c)
        heapq.heappush(b, c)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

dp = [0] * N
dp[0] = AAA[0]

for i, A in enumerate(AAA):
    if i + 1 == N:
        break
    dp[i + 1] = gcd(dp[i], A)

print(dp[N-1])

Submission status: Wrong Answer

Solution code:
import sys
import math
from collections import deque

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def gcd_multi(nums):
    if len(nums) == 0:
        return 0
    if len(nums) <= 2:
        return min(nums)

    ret = math.gcd(nums.pop(), nums.pop())
    while len(nums) > 0:
        ret = math.gcd(ret, nums.pop())
    return ret


def solve(inputs):
    monsters = string_to_int(inputs[0])
    return gcd_multi(monsters)


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(1))
    print(ret)

Submission status: Wrong Answer

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

ans = A[0]
for i in range(1, N):
    tmp = A[i] % ans
    if tmp > 0:
        ans = tmp

print(ans)

Submission status: Wrong Answer

Solution code:
def gen():
    from random import randint
    N = 10 ** 5
    with open("9", "w") as o:
        print(N, file=o)
        print(" ".join(str(randint(1, 10**9)) for i in range(N)), file=o)
    
def solve(N, A):
    A = sorted(A)
    M = [0] * N
    M[0] = A[0]
    a = A[0]
    for i in range(1, N):
        b = A[i] % a
        if b == 0:
            M[i] = a
        else:
            M[i] = b
            a = b
    return min(M)

N = int(input())                        # 2 <= N <= 10^5
A = [int(x) for x in input().split()]   # 1 <= A <= 10^9

print(solve(N, A))

Submission status: Wrong Answer

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

a, b = a[0], a[1]
while a > 0 and b > 0:
    if a >= b:
        a -= b
    else:
        b -= a
print(max(a, b))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 10**9
A_sum = sum(A)
for i in range(N):
    if (A_sum-A[i])%A[i] > 0:
        ans = min(ans, (A_sum-A[i])%A[i])
    else:
        ans = min(ans, A[i])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 10**9
for i in range(N):
    if (sum(A)-A[i])%A[i] > 0:
        ans = min(ans, (sum(A)-A[i])%A[i])
    else:
        ans = min(ans, A[i])
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
mod = a[0]
for i in a:
    ans = i % mod
    if ans != 0 and mod > ans:
        mod = ans
print(mod)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
minimum = min(A)
if all(i % minimum == 0 for i in A):
  print(minimum)
else:
  print(1)

Submission status: Wrong Answer

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


A.sort()

mini=A[0]
flag=0

for i in range(N-1):
    if A[i+1]%mini!=0:
        mini=min(mini,A[i+1]%mini)
        flag=1

if flag==0:
    print(A[0])
else:
    print(mini)

Submission status: Wrong Answer

Solution code:
n1 = int(input())

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

n3 = min(na2)

while True:
    c1 = 0
    for i1 in range(n1):
        if na2[i1] != n3:
            na2[i1] -= n3
        if na2[i1] <= n3:
            c1 += 1
    if c1 == n1:
        break
    n3 = min(na2)

print(n3)

Submission status: Wrong Answer

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

i=0
s=[]
while i!=n:
    s.append(a[i]%2)
    i+=1
if a.count(a[0])==len(a):
    print(a[0])
elif (1 in s)==True:
    print(1)
else:
    print(2)

Submission status: Wrong Answer

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

#print(len(a))
while len(a)!=1 and 1 ==False:
    i=1
    a.sort()
    while i!=n:
        #print(a[i]%a[0])
        #print (a[i]%a[0] in a)
        if (a[i]%a[0] in a) ==False and a[i]%a[0]!=0:
            a[i]=a[i]%a[0]
            i+=1
            #print (a)
        else:
            del a[i]
            n-=1
            #print(a,"del")

print(a[0])

Submission status: Wrong Answer

Solution code:
import functools
N = int(input())
n_lis = sorted(list(map(int, input().split())), reverse=True)

while len(set(n_lis)) > 2: 
    n_lis = sorted(n_lis, reverse=True)
    for i in range(len(n_lis)):
        n_lis[i] = functools.reduce(lambda a, b: a % b, n_lis[i:])

    n_lis = [i for i in n_lis if i > 0]
print(min(n_lis))

Submission status: Wrong Answer

Solution code:
import functools
N = int(input())
n_lis = sorted(list(map(int, input().split())), reverse=True)


for i in range(len(n_lis)):
    n_lis[i] = functools.reduce(lambda a, b: a % b, n_lis[i:])

n_lis = [i for i in n_lis if i > 0]
for i in range(len(n_lis)):
    n_lis[i] = functools.reduce(lambda a, b: a % b, n_lis[i:])
print(min(n_lis))

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
for i in range(N):
    if A[i] % A[0] > 0:
        flag = 1
        break
else:
    print(A[0])
    flag = 0
if flag:
    for i in range(N):
        if A[i] % 2 == 1:
            odd = 1
            break
    else:
        odd = 0
    if odd:
        print('1')
    else:
        print('2')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
for i in range(N):
    if A[i] % A[0] > 0:
        flag = 1
        break
else:
    print(A[0])
    flag = 0
if flag:
    print(A[0])
    for i in range(N):
        if A[i] % 2 == 1:
            odd = 1
            break
    else:
        odd = 0
    if odd:
        print('1')
    else:
        print('2')

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A.sort()
for i in range(N):
    if A[i] % A[0] > 0:
        print(A[0])
        break
else:
    for i in range(N):
        if A[i] % 2 == 1:
            odd = 1
            break
    else:
        odd = 0
    if odd:
        print('1')
    else:
        print('2')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
ans = 10 ** 12

for i in range(N):
    for j in range(N):
        if i == j:
            continue
        hp = A[j] % A[i]
        if hp == 0:
            continue
        A[j] = hp
ans = min(A)
print(ans)

Submission status: Wrong Answer

Solution code:
def progress():
    for i in range(N):
        hp = A[i]
        for j in range(N):
            if i == j:
                continue
            if A[i] > A[j]:
                A[i] -= A[j]
                progress()
            if min(A) == 1:
                break
        if min(A) == 1:
            break
    return min(A)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = list(map(int, input().split()))
boolean = False
updated_lst = []
minimum = min(lst)
min_num = 0
for i in lst:
  num = i % minimum
  if (i != minimum):
    updated_lst.append(num)
  else:
    updated_lst.append(minimum)
    min_num += 1
  if (num % 2 == 1):
    boolean = True

if (min_num == len(lst)):
  print(minimum)
else:
  if (boolean):
    print(1)
  else:
    print(min(updated_lst))

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = list(map(int, input().split()))
boolean = False
updated_lst = []
minimum = min(lst)
min_num = 0
for i in lst:
  num = i % minimum
  if (i != minimum):
    updated_lst.append(num)
  else:
    updated_lst.append(minimum)
    min_num += 1
  if (num % 2 == 1):
    boolean = True

if (min_num == len(lst)):
  print(minimum)
else:
  if (boolean):
    print(1)
  else:
    print(2)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = list(map(int, input().split()))
boolean = False
updated_lst = []
minimum = min(lst)
min_num = 0
for i in lst:
  num = i % minimum
  if (i != minimum):
    updated_lst.append(num)
  else:
    updated_lst.append(minimum)
    min_num += 1
  if (num % 2 == 1):
    boolean = True

sum = sum(updated_lst)

if (sum == minimum*min_num):
  print(minimum)
else:
  if (boolean):
    print(1)
  else:
    print(2)

Submission status: Wrong Answer

Solution code:
N = int(input())
lst = list(map(int, input().split()))
boolean = False
updated_lst = []
minimum = min(lst)
min_num = 0
for i in lst:
  num = i % minimum
  if (i != minimum):
    updated_lst.append(num)
  else:
    updated_lst.append(minimum)
    min_num += 1
  if (num % 2 == 1):
    boolean = True

sum = sum(updated_lst)

if (sum == minimum*min_num):
  print(minimum)
else:
  if (boolean):
    print(1)
  else:
    print(min(updated_lst))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l.sort()

  a=l[0]

  for x in l[1:]:
    if x%a!=0:
      return 1

  return a

print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l=list(set(l))

  if len(l)==1:
    return l[0]

  f=False
  for x in l:
    if x%2!=0:
      f=True

  if f:
    return 1
  return 2

print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l=list(set(l))

  if len(l)==1:
    return l[0]

  f=False
  for x in l:
    if x%2==0:
      f=True

  if f:
    return 1
  return 2

print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  l=list(set(l))

  if len(l)==1:
    return l[0]

  f1=f2=False
  for x in l:
    if x%2==0:
      f1=True
    else:
      f2=True

  if f1 and f2:
    return 1
  else:
    if min(l)==1:
      return 1
    return 2

print(main())

Submission status: Wrong Answer

Solution code:
N = input()
A = {int(x) for x in input().split()}

while len(A) == 1:
    mn = min(A)
    A = {x % mn for x in A if x % mn != 0}
    A.add(mn)
print(A.pop())

Submission status: Wrong Answer

Solution code:
# ABC118C - Monsters Battle Royale
n = int(input())
arr = list(map(int, input().rstrip().split()))
m = min(arr)
r = sum(arr) % m 
if r == 0:
    print(m)
else:
    print(min(m, r))

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  sl=list(set(l))
  if len(sl)==1:
    return sl[0]

  f1=False
  for x in l:
    if x%2!=0:
      f1=True

  if f1:
    return 1
  else:
    return 2

print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  n=I()
  l=LI()

  sl=list(set(l))
  if len(sl)==1:
    return sl[0]

  for x in l:
    if x%2==0:
      return 2
    else:
      return 1

print(main())

Submission status: Wrong Answer

Solution code:
a = int(input())
b= list(map(int,input().split()))
c  = []
d = 1000000000
for i in range(a):
    for j in range(a):
        if b[i] > b[j] and b[i]%b[j] != 0:
            if d > b[i]%b[j]:
                d = b[i]%b[j]
            if b[i] > d and b[i]%d != 0:
                if d > b[i]%d:
                    d = b[i]%d
print(d)

Submission status: Wrong Answer

Solution code:
def f(a, b):
    if a < b:
        d = a
        a = b
        b = d
    if a % b == 0:
        return b
    else:
        return f(b, a % b)

def main():
    n = int(input())
    A = list(map(int, input().split()))
    ans = 1e9
    for i in range(1, n):
        ans = min(ans, f(A[i], A[i - 1]))
    print(ans)

main()

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
     a.sort()
     m0=a[0]
     m1=a[1]
     m1-=m0*(m1//m0)
     if m1==0:
          a[1]=float('inf')
     else:
          a[1]=m1
print(min(a))

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline

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

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if y == 0:
        return 1
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            x, y = y, x%y
        else:
            return x%y

A.sort()

ans = A[0]
for i in range(1, N):
    ans = gcd(ans, A[i])
print(ans)

Submission status: Wrong Answer

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

while len(mons) > 2:
    mons = mons[0:1] + list(map(lambda x:x%mons[0], mons[1:]))
    mons.sort()
    while mons[0]==0: del mons[0]
print(mons[1]-mons[0] if len(mons)==2 else mons[0])

Submission status: Wrong Answer

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

def oddcheck(x):
    return x%2

if len(set(A))==1:
    print(A[0])
else:
    f=A[0]%2
    a=1
    c=0
    while c==0:
        if oddcheck(A[a])!=f:    
            c+=1
        else:
            a+=1
            if a==N:
                break
    if c==0 and f==0:
        print(2)
    elif c==0 and f==1:
        print(1)
    else:
        print(2)

Submission status: Wrong Answer

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

def oddcheck(x):
    return x%2

if len(set(A))==1:
    print(A[0])
else:
    f=A[0]%2
    a=1
    c=0
    while c==0:
        if oddcheck(A[a])!=f:    
            c+=1
        else:
            a+=1
            if a==N:
                break
    if c==0 and f==0:
        print(2)
    elif c==0 and f==1:
        print(1)
    else:
        print(3)

Submission status: Wrong Answer

Solution code:
print(2)

Submission status: Wrong Answer

Solution code:
print(1)

Submission status: Wrong Answer

Solution code:
from functools import reduce

def gcd(a, b):
    if a < b:
        a, b = b, a
    while b != 0:
        a, b = b, b % a
    return a

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

print(reduce(gcd, a))

Submission status: Wrong Answer

Solution code:
def smaller(x, y):
	if x < y: return x
	return y

N = int(raw_input())
A = map(int, raw_input().split())
A.sort()
min1 = A[0]
for i in range(1, N):
	if A[i]%min1 != 0 and A[i]%min1 < min1: min1 = A[i]%min1
min2 = A[-1]
for i in range(1, N):
	if min2%A[-i-1] == 0: min2 = A[i]
	else: min2 = min2%A[i] 
print smaller(min1, min2)

Submission status: Wrong Answer

Solution code:
N = int(raw_input())
A = map(int, raw_input().split())
A.sort()
min = A[0]
for i in range(1, N):
	if A[i]%min != 0 and A[i]%min < min: min = A[i]%min
print min

Submission status: Wrong Answer

Solution code:
def sub():
    N = int(input())
    As = [int(e) for e in input().split()]
    ans = None
    while True:
        print(As)
        a_min = min(As)
        As = [a % a_min for a in As]
        As = [a for a in As if a != 0]
        if len(As) == 0:
            ans = a_min
            break
        else:
            As.append(a_min)
    print(ans)

sub()

Submission status: Wrong Answer

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

comp = [10**9] * n
max_hp = a[n-1]

for i in range(1, n):
    if a[i] % a[i-1] == 0:
        comp[i-1] = a[i-1]
    else:
        comp[i-1] = a[i] % a[i-1]

min_attack = min(comp)
ans = min(min_attack, max_hp%min_attack if max_hp%min_attack!=0 else max_hp)

print(ans)

Submission status: Wrong Answer

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

# A: 全ての値が同じ場合、それが答え？
# B: 一番小さな値で他の全ての値が割り切れる時、一番小さな値が答えになる？
# C: そうでない場合、1が答え？

# A
flag = 0
for i in range(1, N):
    if A[0] != A[i]:
        flag = 1
        break

# B or C
if flag:
    flag = 0
    a = min(A)
    for i in range(N):
        if A[i] % a:
            flag = 1
            break

    if flag:
        print(1)

    else:
        print(a)

else:
    print(A[0])

Submission status: Wrong Answer

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

monsters.sort(reverse=True)
print(monsters)
ans = min(monsters)

while ans > 0:
    maxnum = max(monsters)
    minnum = min(monsters)
    maxidx = monsters.index(maxnum)

    if maxnum % minnum == 0:
        del monsters[maxidx]
        if len(monsters) == 1:
            print(monsters[0])
            quit()
    else:
        ans = maxnum % minnum
        monsters[maxidx] = ans

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline

N = int(input())
L = [int(v) for v in input().split()]

f = True
while f:
    f = False
    
    m = min([v for v in L if v != 0])
    for i in range(N):
        t = L[i]
        if t == 0 or m == 0:
            continue
        L[i] = t % m
        if t % m != 0:
            m = min(m, t % m)
            f = True

print(m)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted([int(a) for a in input().split(" ")])
curr = [A[0]]
for a in A[1:]:
    for b in curr:
        tmp = a%b
        if tmp>0:
            curr.append(tmp)
print(curr[-1])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted([int(a) for a in input().split(" ")])
curr = A[0]
for a in A[1:]:
    tmp = a%curr
    if tmp>0 and tmp<curr:
        curr = tmp
print(curr)

Submission status: Wrong Answer

Solution code:
# coding: utf-8

def gcd_list(l):
    for i in range(len(l)-1):
        x = max(l[i],l[i+1])
        y = min(l[i],l[i+1])
        if x%y==0:
            return y
        else:
            while x%y!=0:
                z = x%y
                x = y
                y = z
            else:
                return z

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

x = gcd_list(a)

print(x)