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)
#print(A)
for i in range(N-1):
    R = A[N-1] % A[i]
    if R != 0:
        list.append(R)
#print(list)

for i in range(N-1):
    R = max(list) % A[i]
    if R != 0:
        list.append(R)
#print(list)
print(min(list))

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

Submission status: Wrong Answer

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

mi = min(A)

def mak(num):
    if num < 1:
        return []
    elif num == 1:
        return [1]
    else:
        divisor_list = []
        divisor_list.append(1)
        for i in range(2, num // 2 + 1):
            if num % i == 0:
                divisor_list.append(i)
        divisor_list.append(num)

        return divisor_list
    
P = mak(mi)[1:]
lenp = len(P)

Q = np.array(A)

an = 1
for i in range(lenp):
    if any(Q % P[i]) == 0:
        an = P[i]
    else:
        break

print(an)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n=int(input())
a = list(map(int, input().split()))
a.sort()
r=a.pop(0)
while len(a)>0:
  x = a.pop(0)
  if x%r!=0:
    r=x%r

print(r)

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

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
a_min = a[0]
for element in a:
    if not element % a_min == 0 and element % a_min <= a_min:
        a_min = element % a_min
    elif element <= a_min:
        a_min = element
print(a_min)

Submission status: Wrong Answer

Solution code:
N = int(input())
p = [int(x) for x in input().split(' ')]
p.sort()
res = 1
for i in range(N-1):
  a,b = p[i],p[i+1]
  if abs(int(b / a) * a - b) == 0:
    res = a
    break
print(res)

Submission status: Wrong Answer

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

arr.sort()
small, big = arr[:2]
if small == big:
    print(big)
else:
    tmp = 0
    while small >= 1 and big >= 1:
        big -= small
        if small > big:
            small, big = big, small
    if small == 0:
        print(big)
    else:
        print(small)

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-1):
    if a[i] != a[i+1]:
        break
    f = 2

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = map(int, input())
A = list(map(int, input().split()))

while len(A) >= 2:
    largest_elem = A.index(max(A))
    x = A.pop(largest_elem)
    largest_elem = A.index(max(A))
    y = A.pop(largest_elem)
    print(x, y)
    if x == 1 and y == 1:
        A.append(y)
    elif x % y == 0:
        A.append(y)
    else:
        A.append(x % y)
        A.append(y)

print(A[0])

Submission status: Wrong Answer

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

num = 0

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

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

Submission status: Wrong Answer

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


main()

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)

    flag = 0

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

Submission status: Wrong Answer

Solution code:
def isSame(a):
    ans = True
    for i in a[1:]:
        if not a[0] == i:
            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 isSame(A):
    print(A[0])
elif isOdd(A):
    print(1)
else:
    print(2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(aa)
def mod(xx):
    bb=[]
    for i in range(len(xx)):
        b = xx[i] if (0<xx[i] and xx[i] <= min(xx)) else xx[i] % min(xx)
        if b>0:
            bb.append(b)
    return bb

while True:
    bb = mod(aa)
    # print(bb)
    if min(aa)==min(bb):
        break
    aa=bb
print(min(bb))

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(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_
#         print(A_list)
    if not flag:
        break
print(min_)

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

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:
def gcd(a, b):
    while b:
        a, b = b, a % b
    return a

import sys
input = sys.stdin.readline
N = int(input())
hp = sorted(list(map(int, input().split())))
hp = hp[:2]
if hp[0] == hp[1]:
    print(hp[0])
    sys.exit()
n = gcd(hp[1], hp[0])
if n == 0:
    print(2)
if n == 1:
    print(1)
else:
    print(n)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a = list(set(a))
while (1000000):
    a.sort()
    if len(a) == 1:
        print(a[0])
        exit()
    if 1 in a:
        print(1)
        exit()
    if a[-1]%a[-2] != 0:
        a[-1] = a[-1]%a[-2]
    else:
        a[-1] = a[-1]//a[-2]
    a = list(set(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

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

Submission status: Wrong Answer

Solution code:
from fractions import gcd
from functools import reduce

def gcd_list(numbers):
    return reduce(gcd,numbers)

N = int(input())
A = list(map(int,input().split()))
if gcd_list(A) == 1:
    print(1)
else:
    print(min(A))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc118/tasks/abc118_c

def main():
    N = int(input())
    A = list(map(int, input().split()))  # 体力

    while True:
        A.sort()
        # print(A)
        if A[0] == 1:
            print(1)
            exit()
        min_diff = 10**5
        diff_index = -1
        for i in range(1, N):
            diff = A[i] - A[i - 1]
            # print("{} - {} == {}".format(A[i], A[i - 1], diff))
            if diff < min_diff and diff != 0:
                min_diff = diff
                diff_index = i
                # print("{}, index = {}".format(min_diff, diff_index))
                # exit()

        if diff_index == -1:  # これ以上小さくならないなら答え
            print(A[0])
            exit()
        else:
            A[diff_index] = min_diff


main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
N = map(int, input())
A = list(map(int, input().split()))

while len(A) >= 2:
    largest_elem = A.index(max(A))
    x = A.pop(largest_elem)
    largest_elem = A.index(max(A))
    y = A.pop(largest_elem)
    if x % y == 0:
        A.append(y)
    elif x == 1 and y == 1:
        A.append(1)
    else:
        A.append(x % y)

print(A[0])

Submission status: Wrong Answer

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

l.sort()
flag = 0
a = l[0]

for i in l:
    if i != a:
        b = i
        flag = 1
        break

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

c = b
d = a

while flag == 1:
    if b > a:
        c -= a
    else:
        d -= b

    if c*d <= 0 or c==d:
        print(min(a,b))
        flag = 0

    b = c
    a = d

Submission status: Wrong Answer

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

a.sort()

diff = 10 ** 20
for i in range(n):
    if a[i + 1] != a[i]:
        diff = min(diff, a[i + 1] - a[i])

ans = 10 ** 20
for i in a:
    if i % diff == 0:
        ans = min(ans, diff)
    else:
        ans = min(ans, i % diff)

print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

min = a[0]
for elem in a:
    res = elem % min
    if res == 0:
        pass
    else:
        if res < min:
            min = res
print(min)

Submission status: Wrong Answer

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

import sys
input = sys.stdin.readline
N = int(input())
hp = sorted(list(map(int, input().split())))
hp = hp[:2]
if hp[0] == hp[1]:
    print(hp[0])
    sys.exit()
n = gcd(hp[0], hp[1])
if n == 0:
    print(2)
if n == 1:
    print(1)
else:
    print(n)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=[]
s=input().split()
for i in range(n):
  a.append(int(s[i]))
Min=100000000
min=100000000
while(True):
  a=sorted(a)
  d=0
  for i in range(n):
    if a[i]==0:
      continue
    elif d==0:
      d=a[i]
      if d<min:
        min=d
      continue
    a[i]=a[i]%d
    if a[i]!=0 and a[i]<min:
      min=a[i]
  if min<Min:
    Min=min
  else:
    break
print(Min)

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import bisect

def solve():
    n = int(input())
    al = [int(i) for i in input().split()]
    al.sort()
    s = sum(al)
    while len(al) > 1:
        p = al[-1] % (s - al[-1])
        q = al[-1]
        al = al[:-1]
        if p == 0:
            s -= q
            continue
        if p == q:
            q -= al[-1]
            if q <= 0:
                s -= q
                continue
            p = q
        s -= p
        bisect.insort(al, p)
    print(al[0])

if __name__=="__main__":
    solve()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(list(set(A)))
if min(A) == 1:
    print(1)
else:
  if len(A) >= 2:
    m1, m2 = A[:2]
    while m1 >= 1 and m2 >= 1:
        if m1 > m2:
            m1 = m1 % m2
        else:
            m2 = m2 % m1
    if m1 <= 0:
        print(m2)
    elif m2 <= 0:
        print(m1)
  else:
    print(A[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
mons = list(map(int, input().split()))
atk = min(mons)
blk = sum(mons) - atk
if blk % atk :
    print(blk % atk)
else :
    print(atk)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted(list(map(int, input().split())))
a_min = a[-1]
for element in a:
    if not element % a_min == 0 and element % a_min <= a_min:
        a_min = element % a_min
    elif element <= a_min:
        a_min = element
print(a_min)

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()))
b = deque(sorted(a))
ans = b[0]
b.popleft()

for i in b:
    j = i % ans
    if j == 0:
        j = ans
    ans = min(j, i)
print(ans)

Submission status: Wrong Answer

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

ans = monsters[0]
for i in monsters:
    if i%2 == 1:
        ans = 1
    
print(ans)

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]
tmp_two = As[1]

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
if len(list(set(A))) == 1:
    print(A[0])
    exit()
for a in A:
    if a % 2 == 1:
        print(1)
        exit()
print(2)

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc118/tasks/abc118_c

def main():
    N = int(input())
    A = list(map(int, input().split()))  # 体力

    while True:
        A.sort()
        # print(A)
        min_diff = A[0]
        diff_index = -1
        for i in range(1, N):
            diff = A[i] - A[i - 1]
            # print("{} - {} == {}".format(A[i], A[i - 1], diff))
            if diff < min_diff and diff != 0:
                min_diff = diff
                diff_index = i
                # print("{}, index = {}".format(min_diff, diff_index))
                # exit()

        if diff_index == -1:  # これ以上小さくならないなら答え
            print(A[0])
            exit()
        else:
            A[diff_index] = min_diff


main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc118/tasks/abc118_c

def main():
    N = int(input())
    A = list(map(int, input().split()))  # 体力

    while True:
        A.sort()
        print(A)
        min_diff = A[0]
        diff_index = -1
        for i in range(1, N):
            diff = A[i] - A[i - 1]
            # print("{} - {} == {}".format(A[i], A[i - 1], diff))
            if diff < min_diff and diff != 0:
                min_diff = diff
                diff_index = i
                # print("{}, index = {}".format(min_diff, diff_index))
                # exit()

        if diff_index == -1:  # これ以上小さくならないなら答え
            print(A[0])
            exit()
        else:
            A[diff_index] = min_diff


main()

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(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())
A = list(map(int, input().split()))
A = sorted(A)
for _ in range(N):
    minimum = A[0]
    A = sorted([a % minimum for a in A[1:] if a > minimum and a % minimum != 0])+[minimum]
    if len(A) == 1:
        break
print(A[0])

Submission status: Wrong Answer

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

l.sort()
flag = 0
a = l[0]
b = l[1]
c = b
d = a
if c == d:
    print(c)
    exit()
while flag == 0:
    if b > a:
        c -= a
    else:
        d -= b

    if c*d <= 0 or c==d:
        print(min(a,b))
        flag = 1

    b = c
    a = d

Submission status: Wrong Answer

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

#最小値で余りを求めていく
prev = 0
min_a = min(A)
for i in range(N):
  B = []
  for k in range(N):
    a = A[k] % min_a
    if (a != 0):
      B.append(a)
    else:
      B.append(min_a)
  
  min_a = min(B)
  if (prev == min_a):
    break
  prev = min_a

print(min_a)

Submission status: Wrong Answer

Solution code:
from functools import reduce

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

numbers = [int(x) for x in input().split()]
print(reduce(gcd, numbers))

Submission status: Wrong Answer

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

l.sort()
flag = 0
a = l[0]
b = l[1]
c = b
d = a
if c == d:
    print(c)
    exit()
while flag == 0:
    if b > a:
        c -= a
    else:
        d -= b

    if c*d <= 0 or c==d:
        print(min(c,d))
        flag = 1

    b = c
    a = d

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):
    if a[i]%a[0]!=0:
        if a[0]%(a[i]%a[0])==0:
            a[0] = a[i]%a[0]
        else:
            OK = False
print(a[0] if OK else 1)

Submission status: Wrong Answer

Solution code:
n=int(input())
#for i in range(n):
A=list(map(int, input().split(" ")))

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 = [int(x) for x in input().split()]

A.sort()

m = A[0]
del A[0]

while True:
    flag = True
    for a in A:
        tmp = a % m
        if tmp != 0 and tmp < m:
            m = tmp
            flag = False
            break

    if flag:
        break

print(m)

Submission status: Wrong Answer

Solution code:
n = int(input())
listA=list(map(int, input().split()))
listA.sort()
listAMin=listA[0]
index=0
deltaMin=1000000000
while index < len(listA)-1:
    delta = listA[index+1]-listA[index]
    if delta < deltaMin:
        deltaMin=delta
    index+=1
minMonster=100000000

index2=0
while index2 < len(listA):
    if listA[index2] % listAMin != 0 and listA[index2] % listAMin < minMonster:
        minMonster = listA[index2] % listAMin
    elif listAMin < minMonster:
        minMonster = listAMin
    if deltaMin!=0:
        if listA[index2] % deltaMin != 0 and listA[index2] % deltaMin < minMonster:
            minMonster = listA[index2] % deltaMin
        elif deltaMin < minMonster:
            minMonster = deltaMin
    if minMonster == 1:
        break
    index2+=1
print(minMonster)

Submission status: Wrong Answer

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

result = 10**9
A.sort()
for i in range(N):
    num = A[i]
    for j in A[i+1:]:
        if j % num == 0:
            result = min(result, num)
        else:
            result = min(result, j%num)

print(result)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
n=int(input())
a = list(map(int, input().split()))
a.sort()
r=a.pop(0)
while len(a)>1:
  x = a.pop(0)
  if x%r!=0:
    r=x%r
print(r)

Submission status: Wrong Answer

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

t=min(a)
*b,=map(lambda x:x%t,a)

if any(b):
  print(1)
else:
  print(t)

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
  else:
    _md = b % md if b % md != 0 else md
    ab = b % a if b % a != 0 else a
    md = min(_md, ab)
print(md)

Submission status: Wrong Answer

Solution code:
N = int(input())
L = list(map(int,input().split()))
L.sort()
flag = True
for i in range(N):
  if L[i] % L[0] != 0:
    flag = False
    break
if flag:
  print(L[0])
else:
  print(1)

Submission status: Wrong Answer

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

#最小値で余りを求めていく
prev = 0
for i in range(N):
  min_a = min(A)
  if (prev == min_a):
    break
  prev = min_a

  for k in range(N):
    a = A[k] % min_a
    if (a != 0):
      A[k] = a

print(min_a)

Submission status: Wrong Answer

Solution code:
def main():
    N = int(input())
    A = sorted(list(set(map(int, input().split()))))
    if len(A) == 1:
        print(A[0])
    elif A[0] % 2 == 1 or A[1] % 2 == 1:
        print(1)
    else:
        print(2)


main()

Submission status: Wrong Answer

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

if len(A) >= 2:
    m1, m2 = A[:2]
    while m1 >= 1 and m2 >= 1:
        if m1 > m2:
            m1 = m1 % m2
        else:
            m2 = m2 % m1
    if m1 <= 0:
        print(m2)
    elif m2 <= 0:
        print(m1)

else:
    print(A[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
A = sorted(A)
for _ in range(N):
    minimum = A[0]
    A = sorted([a % minimum for a in A[1:] if a % minimum != 0]+[minimum])
    if len(A) == 1:
        break
print(A[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
array = [int(x) for x in input().split()]
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)
    else:
        print(min(array))

Submission status: Wrong Answer

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

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

print(1)

Submission status: Wrong Answer

Solution code:
import numpy as np

N = int(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
    if not flag:
        break
print(min_)

Submission status: Wrong Answer

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

print(min(A))

Submission status: Wrong Answer

Solution code:
import bisect
n = int(input())
a = list(int(i) for i in input().split())
a.sort()
ans = 10**15
for i in range(n):
  tmp = bisect.bisect_left(a,a[i])
  for j in range(tmp):
   if a[i]%a[j]!= 0:
    a[i] = a[i]%a[j]
print(min(a))

Submission status: Wrong Answer

Solution code:
N=input()
A=set(map(int,input().split()))
R=max(A)
while 1:
    r=min(A)
    if r==R:break
    A=set(i if i<=r else i%r for i in A)
    A=set(i for i in A if i!=0)
    R=r
    print(A)
print(R)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
N = int(input())
hp = sorted(list(map(int, input().split())))
hp = hp[:2]
if hp[0] == hp[1]:
    print(hp[0])
    sys.exit()
if (sum(hp)) % 2 == 0:
    print(2)
else:
    print(1)

Submission status: Wrong Answer

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

for i in range(10):
    mA=min(A)
    pre_A=[a-((a-1)/mA)*mA for a in A]
    if pre_A==A:
        break
    A=pre_A[:]

print min(A)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
is_odd = sum([Ai % 2 for Ai in A])
if is_odd >= 1:
    print(1)
else:
    minA = min(A)
    maxA = max(A)
    if minA == max(A):
        print(minA)
    else:
        print(2)

Submission status: Wrong Answer

Solution code:
from fractions import gcd


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

now = A[0]
for i in range(1, N):
    if gcd(now, A[i]) != 1:
        now = min(now, A[i])
    else:
        now = 1
print(now)

Submission status: Wrong Answer

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

def kouyaku(a, b):
    if a % b == 0:
        return b
    else:
        return kouyaku(b, a % b)
a.sort()
tmpa = a[0]
for i in range(1, n):
    tampa = kouyaku(tmpa, a[i])
print(tmpa)

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):
    if a[i]%a[0]!=0:
        OK = False
print(a[0] if OK else 1)

Submission status: Wrong Answer

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

preva = None
md = None
for a in sorted(alist):
  if preva is None:
    preva = a
  else:
    if md is None:
      md = a % preva if a % preva != 0 else preva
    elif a % md != 0:
      md = min(md, a % md)
print(md)

Submission status: Wrong Answer

Solution code:
n = input()
l = map(int, raw_input().split())
l.sort()
f = 0
for i in xrange(1,n):
	if l[i]%l[0] != 0:
		f = 1
		break
if f == 1:
	print 1
else:
	print l[0]

Submission status: Wrong Answer

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

L = sorted(L)


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

Submission status: Wrong Answer

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

tmp=A[0]
for a in A[1:]:
  tmp=tmp%a
  
print(min(A)-tmp)

Submission status: Wrong Answer

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

now = A[0]
for i in range(1, N):
    if max(now, A[i]) % min(now, A[i]) == 0:
        now = min(now, A[i])
    else:
        now = 1
print(now)

Submission status: Time Limit Exceeded

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

A.sort(reverse=True)
while len(A) > 1:
    tmp = A[0] % A[1]
    A = A[1:]
    if tmp == 0:
        continue
    i = 0
    while i < len(A) and A[i] > tmp:
        i += 1
    if i == len(A):
        A.append(tmp)
    else:
        A.insert(i, tmp)

print(A[0])

Submission status: Time Limit Exceeded

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

a = sorted(a, reverse=True)

changed = True
while changed:
    changed = False
    for i in range(1, n):
        t = a[i-1]%a[i]

        if t != 0:
            a[i-1] = t
            changed = True
            break

    if changed:
        a = sorted(a, reverse=True)

print(a[-1])

Submission status: Time Limit Exceeded

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    N = ii()
    A = list(mi())

    A.sort()
    if A[0] == 1:
        print(1)
        exit()
    
    ini = A[0]
    while len(A) > 1:
        x = A[0]
        B = set([x])
        for a in A:
            b = a%x
            if b > 0:
                B.add(b)

        A = list(B)
        #print(A)

    if len(A) > 0:
        print(A[0])
    else:
        print(ini)
            

            
        



if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

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

    while len(inlis) > 1:
        tmp = 0
        i = 1
        while tmp < len(inlis):
            #print(i, tmp)
            if inlis[i] % inlis[0] != 0:
                inlis[i] %= inlis[0]
                i += 1
                if i >= len(inlis):
                    break
            else:
                inlis.remove(inlis[i])
            tmp += 1
        inlis.sort()
        #print(inlis, len(inlis))
    print(inlis[0])


if __name__ == "__main__":
    main()

Submission status: Time Limit Exceeded

Solution code:
import numpy as np
n = int(input())
a = np.array([int(i) for i in input().split()])
a = np.sort(a)
d = a[0]
while True:
    a1 = a % d
    if all(a1 == 0):
        ans = d
        break
    a1[0] = d
    d = min(a1[a1 != 0])    
print(ans)