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:
# ABC118c
from functools import reduce
from fractions import gcd
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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


def gcds(*numbers):
    return reduce(gcd, numbers)


print(gcds(a))
exit(0)


def solve(l):
    m = min(l)
    nl = list()
    for i in l:
        if i % m != 0:
            nl.append(i % m)
    nl.append(m)
    # print(nl)
    if len(nl) == 1:
        return m
    return solve(nl)


print(solve(a))

Submission status: Wrong Answer

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

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

A.sort()

ans = 0
if A[0] == max(A):
    ans = A[0]
else:
    a = A[0]
    b = 0
    for i in range(1, N):
        if a != A[i]:
            b = A[i]
            break

    ans = gcd(a, b)


print(ans)

Submission status: Wrong Answer

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

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

A.sort()

ans = 0
if A[0] == max(A):
    ans = A[0]
else:
    a = A[0]
    b = 0
    for i in range(1, N):
        if a != A[i]:
            b = A[i]
            break
        
    ans = gcd(a, b)


print(ans)

Submission status: Wrong Answer

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

A.sort()

if A[0] == max(A):
    print(A[0])
else:
    a = A[0]
    b = 0
    for i in range(N):
        if a != A[i]:
            b = A[i]
            break

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

    print(gcd(a, b))

Submission status: Wrong Answer

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

A.sort()

print(A[0], A[1])

if A[0] == max(A):
    print(A[0])
else:
    a = A[0]
    b = 0
    for i in range(N):
        if a != A[i]:
            b = A[i]
            break

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

    print(gcd(a, b))

Submission status: Wrong Answer

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

A.sort()

if A[0] == max(A):
    print(A[0])
else:
    a = A[0]
    b = 0
    for i in range(N):
        if a != A[i]:
            b = A[i]
            break

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

    print(gcd(a, b))

Submission status: Wrong Answer

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

A.sort()

dig = 0
a = A[0]
while a >= 10:
    a = a // 10
    dig += 1

ans = 2
for i in range(N):
    b = A[i] // 10 ** dig
    if b % 2 == 1:
        ans = 1
        break

print(ans * 10 ** dig)

Submission status: Wrong Answer

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

A.sort()

dig = 0
while A[0] >= 10:
    A[0] = A[0] // 10
    dig += 1

ans = 2
for i in range(N):
    a = A[i] // (10 ** dig)
    if a % 2 == 1:
        ans = 1
        break

print(ans * 10 ** dig)

Submission status: Wrong Answer

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

A.sort()


dig = 0
while A[0] >= 10:
    A[0] = A[0] // 10
    dig += 1

ans = 2
for i in range(N):
    if A[i] % (2 * 10 ** dig) == 1:
        ans = 1
        break

print(ans * 10 ** dig)

Submission status: Wrong Answer

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

A.sort()

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

Submission status: Wrong Answer

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

while np.any(A[:-1]>0):
    try:
        m=sorted(list(A[A>0]))[0]
        A=list(A[1:]%m)
        A.append(m)
        A=np.array(A)

    except:
        continue
print(m)

Submission status: Wrong Answer

Solution code:
def main():
	# n,k = map(int,input().split())
	n = int(input())
	# s = str(input())
	h = list(map(int,input().split()))
	# l = [list(map(int, input().split())) for _ in range(n)]
	# s = list(s)
	
	od_check = 0
	ev_check = 0
	# for check in range(n):
	# 	if h[check] % min(h) ==0:
	# 		ev_check += 1
	# 	elif h[check] % 2 == 1:
	# 		od_check += 1
	# 		break

	def amari(n):
		return n % 2
	check_ev = list(map(amari,h))
	
	def amari_2(n):
		return n % min(h)
	check_min = list(map(amari_2,h))

	if sum(check_min) == 0:
		print(min(h))
	elif sum(check_ev) == 0:
		print(2)
	elif sum(check_ev) >= 1:
		print(1)


if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def main():
	# n,k = map(int,input().split())
	n = int(input())
	# s = str(input())
	h = list(map(int,input().split()))
	# l = [list(map(int, input().split())) for _ in range(n)]
	# s = list(s)
	od_check = 0
	ev_check = 0
	for check in range(n):
		if h[check] % min(h) ==0:
			ev_check += 1
		elif h[check] % 2 == 1:
			od_check += 1
			break


	if ev_check == n:
		print(min(h))
	elif od_check >= 1:
		print(1)

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
def main():
	# n,k = map(int,input().split())
	n = int(input())
	# s = str(input())
	h = list(map(int,input().split()))
	# l = [list(map(int, input().split())) for _ in range(n)]
	# s = list(s)
	od_check = 0
	ev_check = 0
	for check in range(n):
		if h[check] % min(h) ==0:
			ev_check += 1
		elif h[check] % 2 == 1:
			od_check += 1


	if ev_check == n:
		print(min(h))
	elif od_check >= 1:
		print(1)
	





if __name__ == '__main__':
	main()

Submission status: Wrong Answer

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

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

print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
    if b>a:
        return(gcd(b,a))
    elif b==0:
        return(a)
    else:
        return(gcd(b,b%a))
ans=A[0]
for i in range(n-1):
    ans=gcd(ans,A[i+1])
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
A=list(map(int,input().split()))
def gcd(a,b):
    if b==0:
        return(a)
    else:
        return(gcd(b,b%a))
ans=A[0]
for i in range(n-1):
    ans=gcd(ans,A[i+1])
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = sorted(list(map(int, input().split())))
print("I can't")

Submission status: Wrong Answer

Solution code:
n = int(input())
A = list(map(int,input().split()))
is_odd = False
for a in A:
  if a % 2 != 0:
    is_odd = True
if is_odd:
  print(1)
else:
  print(min(A))

Submission status: Wrong Answer

Solution code:
import math
n = int(input())
hp = [int(x) for x in input().split()]
for i in range(n-1):
  a = hp[i]
  b = hp[i+1]
  if a == b: ans = a
  r = a % b
  while r != 0:
    ans = r
    a = b
    b = r
    r = a % r
  hp[i+1] = ans
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
lista = sorted(list(map(int, input().split())))
length = 2
while length>1:
    #print(length)
    #print(lista)
    for n in range(1, length):
        print(lista[n-1])
        lista[n] = lista[n]%lista[0]
    #print(lista)
    lista = list(set(lista))
    lista.sort()
    if lista[0] == 0:
        lista.remove(0)
    #print(lista)
    length = len(lista)
print(lista[0])

Submission status: Wrong Answer

Solution code:
N = int(input())
lista = list(set(sorted(list(map(int, input().split())))))
length = len(lista)
while length>1:
    print(length)
    print(lista)
    for n in range(1, length):
        print(lista[n-1])
        lista[n] = lista[n]%lista[0]
    print(lista)
    lista.sort()
    print(lista)
    lista = list(set(lista))
    if lista[0] == 0:
        lista.remove(0)
    print(lista)
    length = len(lista)
print(lista[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
N=int(input())
A=list(map(int,input().split()))
A.sort()
b=A[0]
for a in A:
    if a%b!=0:
        b=a%b
print(b)

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
A = [int(i) for i in input().split()]
gcd = A[0]
for i in range(N-2):
  gcd = fractions.gcd(gcd, A[i+1])
  
print(gcd)

Submission status: Wrong Answer

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

if len(A) == 1:
  print(A.pop())
  exit()

is_all_even = True

for x in A:
  if x % 2 == 1:
    is_all_even = False
    break
    
if is_all_even:
  print(min(A))
else:
  print(1)

Submission status: Wrong Answer

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

if len(A) == 1:
  print(A.pop())
  exit()

min1 = min(A)
A.remove(min1)
min2 = min(A)

while True:
  tmp = min1
  min1 = min2 % min1
  min2 = tmp
  if min1 == 0:
    min1 = tmp
    break
  if min1 == 1:
    break
    
print(min1)

Submission status: Wrong Answer

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

while True:
  tmp = min1
  min1 = min2 % min1
  min2 = tmp
  if min1 == 0:
    min1 = tmp
    break
  if min1 == 1:
    break
    
print(min1)

Submission status: Wrong Answer

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

A.sort()

min_score = A[0]
for idx, a in enumerate(A):
    if A[idx] % min_score == 0:
        continue
    else:
        min_score = min(min_score, A[idx] % min_score)
print(min_score)

Submission status: Wrong Answer

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

def gcd(a,b):
    if a == 0:
        return b
    if b == 0:
        return a
    r = 1
    while r > 0:
        r = a % b
        a = b
        b = r
    return a

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

print(l[-1])

Submission status: Wrong Answer

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

ans = a[0]
for i in range(n):
    for j in range(i):
        tmp = a[j] % ans
        if tmp:
            ans = min(ans, tmp)
        
print(ans)

Submission status: Wrong Answer

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

ans = a[0]
for v in a:
    tmp = v % ans
    if tmp:
        ans = min(ans, tmp)
        
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

A.sort()

for i in range(1, N):
    if  A[i] % A[0] != 0:
        break
    if i == N - 1:
        print(A[0])
        sys.exit()
       
for i in range(N):
    if A[i] % 2 != 0:
        print(1)
        sys.exit()
print(2)

Submission status: Wrong Answer

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

A.sort()

for i in range(1, N):
    if  A[i] % A[0] != 0:
        break
    if i == N - 1:
        print(A[0])
        sys.exit()
       
for i in range(1, N):
    if A[i] % 2 != 0:
        print(1)
        sys.exit()
print(2)

Submission status: Wrong Answer

Solution code:
n = int(input())
m = [int(x) for x in input().split()]
m = sorted(m)
min_diff = float('inf')
ii,jj = None,None
ans = m[0]
while m:
    new = []
    for i in range(len(m)- 1):
        mm = m[i+1] % m[i]
        if mm > 1 and mm < min_diff:
            min_diff = mm
            ii,jj = m[i], m[i+1]
            new.append(m[i])
    m = new
if ii is not None:
  mmin, mmax = ii,jj
  while mmin > 0:
      f = mmax // mmin
      mmax -= mmin*f
      mmax, mmin = mmin, mmax
  ans = min(ans, mmax)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
m = [int(x) for x in input().split()]
m = sorted(m)
min_diff = float('inf')
ii,jj = None,None
for i in range(n-1):
    mm = m[i+1] % m[i]
    if mm > 1 and mm < min_diff:
        min_diff = mm
        ii,jj = i, i+1
ans = m[0]
if ii is not None:
  mmin, mmax = m[ii],m[jj]
  while mmin > 0:
      f = mmax // mmin
      mmax -= mmin*f
      mmax, mmin = mmin, mmax
  ans = min(ans, mmax)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
m = [int(x) for x in input().split()]
m = sorted(m)
min_diff = float('inf')
ii,jj = None,None
ans = m[0]
while m:
    new = []
    for i in range(len(m)- 1):
        mm = m[i+1] - m[i]
        if mm > 1 and mm < min_diff:
            min_diff = mm
            ii,jj = m[i], m[i+1]
            new.append(m[i])
    m = new
if ii is not None:
  mmin, mmax = ii,jj
  while mmin > 0:
      f = mmax // mmin
      mmax -= mmin*f
      mmax, mmin = mmin, mmax
  ans = min(ans, mmax)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
m = [int(x) for x in input().split()]
m = sorted(m)
min_diff = float('inf')
ii,jj = None,None
for i in range(n-1):
    mm = m[i+1] - m[i]
    if mm > 1 and mm < min_diff:
        min_diff = mm
        ii,jj = i, i+1
ans = m[0]
if ii is not None:
  mmin, mmax = m[ii],m[jj]
  while mmin > 0:
      f = mmax // mmin
      mmax -= mmin*f
      mmax, mmin = mmin, mmax
  ans = min(ans, mmax)
print(ans)

Submission status: Wrong Answer

Solution code:
n = int(input())
m = [int(x) for x in input().split()]
m = sorted(m)
min_diff = float('inf')
ii,jj = None,None
for i in range(n-1):
    mm = m[i+1] - m[i]
    if mm > 1 and mm < min_diff:
        min_diff = mm
        ii,jj = i, i+1
if ii is None:
  ans = min(m)
else:
  mmin = min(m[ii],m[jj])
  mmax = max(m[ii],m[jj])
  while mmin > 0 and mmax > 0:
      f = mmax // mmin
      if f == 0:
        mmax -= mmin
      else:
        mmax -= mmin*f
      mmax, mmin = mmin, mmax
  some_ans = mmax
  ans = min(min(m), some_ans)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
A = sorted(list(map(int, input().split())))

d = deque(A)
while len(d) > 1:
    l = d.popleft()
    r = d.popleft()
    a = r % l
    if a == 0:
        d.appendleft(l)
    elif a == 1:
        print(1)
        exit()
    else:
        d.appendleft(r)
        d.appendleft(a)
print(d[0])

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
A = sorted(list(map(int, input().split())))

d = deque(A)
ans = d.popleft()
while d:
    b = d.popleft()
    a = b % ans
    if a == 0:
        continue
    elif a == 1:
        ans = 1
        break
    else:
        if ans > a:
            ans = a
        else:
            d.appendleft(a)
print(ans)

Submission status: Wrong Answer

Solution code:
from collections import deque
N = int(input())
A = sorted(list(map(int, input().split())))

d = deque(A)
ans = d.popleft()
while d:
    b = d.popleft()
    a = b % ans
    if a == 0:
        continue
    elif a == 1:
        ans = 1
        break
    else:
        ans = min(ans, a)
print(ans)

Submission status: Wrong Answer

Solution code:
import fractions

# N個の最大公約数
# ユークリッド互除法


def good(A, N):
    A = sorted(A)
    ans = A[0]
    for i in range(1, N):
        ans = fractions.gcd(A[1], ans)
    print(ans)


def my(A, N):
    A = sorted(A)

    while True:
        v = A[0]
        tmp = [v]
        for i in range(len(A)):
            if A[i] % v == 1:
                print(1)
                return
            if A[i] % v == 0:
                pass
            else:
                tmp.append(A[i] % v)

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

        A = sorted(tmp)
        # print(A)


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

    good(A, N)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import fractions

# N個の最大公約数
# ユークリッド互除法


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


def my(A, N):
    A = sorted(A)

    while True:
        v = A[0]
        tmp = [v]
        for i in range(len(A)):
            if A[i] % v == 1:
                print(1)
                return
            if A[i] % v == 0:
                pass
            else:
                tmp.append(A[i] % v)

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

        A = sorted(tmp)
        # print(A)


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

    good(A, N)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

# ki gu 3 8  ⇒1
# gu gu 4 14 ⇒2
# ki ki 5 17 ⇒1
cnt =0
judge =0

list_aaa=sorted(list_aaa)
min_aaa =min(list_aaa)

# すべての数が等しい場合
if len(set(list_aaa)) == 1:
    print(list_aaa[1])
    exit()

# 偶奇判定
for i in range(N):
    if list_aaa[i]%2 ==0:
        cnt +=0
    else :
        cnt +=1
if cnt >=2:
    print(1)
    exit()
else:
    for i in range(N):
        if i==0:
            continue
        if list_aaa[i]%min_aaa==0 :
            judge+=1

    # 最小値が公約数の場合
    if judge>=1:
        print(min_aaa)
        exit()
    else:
        print(2)
        exit()

Submission status: Wrong Answer

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

# ki gu 3 8  ⇒1
# gu gu 4 14 ⇒2
# ki ki 5 17 ⇒1
cnt =0

if len(set(list_aaa)) == 1:
    print(list_aaa[1])
    exit()

for i in range(N):
    if list_aaa[i]%2 ==0:
        cnt +=0
    else :
        cnt +=1
if cnt >=2:
    print(1)
else:
    print(2)

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
A = sorted(list(map(int,input().split())),reverse=1)
tmp = 0
for i in range(N-1):
    tmp = fractions.gcd(A[i],A[i+1])
print(tmp)

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int,input().split()))
if A == ([A[0]]*N):
    print(A[0])
else:
    eo = []
    for i in A:
        eo.append(i%2)
    if 0 in eo and 1 in eo:
        print(1)
    else:
        print(min(A))

Submission status: Wrong Answer

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

num = A[0]
if all (a == num for a in A):
    print(num)
elif all (a %2 == 0 for a in A ):
    print(2)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
def gcd(n,m):
  a=min(n,m)
  b=max(n,m)
  while a!=0:
    b,a=a,b%a
  return a
n=int(input())
l=list(map(int,input().split()))
ans=l[0]
for i in range(1,n):
  ans=gcd(ans,l[i])
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

print(A[0])

Submission status: Wrong Answer

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

print(A[0])

Submission status: Wrong Answer

Solution code:
n = int(input())
a = sorted([int(i) for i in input().split()])
ans = min(a)
for i in range(len(a)-1):
    ans = min(ans,a[i+1]-a[i]) if a[i+1]-a[i] != 0 else ans
for i in range(len(a)):
    ans = min(ans,a[i]%ans) if a[i]%ans != 0 else ans
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

while len(li) > 1:
    for i in range(1,len(li)):
        if ans >= li[i]:
            s = ans%li[i]
            li[i-1] = s
        else:
            s = li[i]%ans
            li[i] = s
        if s == 0:
            continue
        ans = min(ans,s)
    else:
        li = [j for j in li if j > 0]
        
print(ans)

Submission status: Wrong Answer

Solution code:
N = int(input())
 
A = list(map(int,input().split()))
 
A = sorted(A)[0:2]
 
INF = 10 ** 9

for i in range(0,INF):
	A[1] = A[1] % A[0]
	if A[1] < A[0]:
		A[1],A[0] = A[0],A[1]
	if A[0] <= 0:
		break
		
if A[0] == 1:
	print(1)
else:print(A[1])

Submission status: Wrong Answer

Solution code:
N = int(input())
 
A = list(map(int,input().split()))
 
A = sorted(A)[0:2]
 
INF = 10 ** 9
 
for i in range(0,INF):
	A[1] = A[1] % A[0]
	if A[1] < A[0]:
		A[1],A[0] = A[0],A[1]
	if A[0] <= 0:
		break
		
print(A[1])

Submission status: Wrong Answer

Solution code:
import fractions

N = int(input())

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

A = sorted(A)[0:2]

print(fractions.gcd(A[0],A[1]))

Submission status: Wrong Answer

Solution code:
N = int(input())

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

A = sorted(A)[0:2]

INF = 10 ** 9

for i in range(0,INF):
	A[1] = A[1] - A[0]
	if A[1] < A[0]:
		A[1],A[0] = A[0],A[1]
	if A[0] <= 0:
		break
	
print(A[1])

Submission status: Wrong Answer

Solution code:
from sys import stdin, exit
from math import factorial
input = stdin.readline
lmi = lambda: list(map(int, input().split()))
mi = lambda: map(int, input().split())
si = lambda: input().strip('\n')
ssi = lambda: input().strip('\n').split()

n = int(input())
arr = lmi()
a = min(arr)
for i in range(n):
    arr[i] %= a
print(min(arr))

Submission status: Wrong Answer

Solution code:
# ABC118C - Monsters Battle Royale
from fractions import gcd


def main():
    N, *A = map(int, open(0).read().split())
    lcm = lambda x, y: x // gcd(x, y) * y
    ans = A[0]
    for a in A[1:]:
        ans = lcm(ans, a)
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
N = int(input())
A = list(map(int, input().split()))
m = min(A)
import sys
for i in A:
    if i % m != 0:
        print(1)
        sys.exit()
print(m)

Submission status: Wrong Answer

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

ans = min(a)
while True:
    prev = ans
    for i in range(1, n):
        tmp = a[i] % ans
        if 0 != tmp and tmp < ans:
            ans = tmp
    if ans == prev or ans == 1:
        break
print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
import functools
import operator

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

result = functools.reduce(operator.mul, A)
i=1

for i in range(1,int(min(A)**0.5//1)+1):
    if min(A)%i==0:
        if result%(i**N)==0:
            ans=max(ans,i)
        if result%((min(A)//i)**N)==0:
            ans=max(ans,min(A)//i)

print(ans)

Submission status: Wrong Answer

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

a_min=min(A)
ans=0

l=list(range(1,int(a_min**0.5)//1+1))
temp=[]

for a in A:
    for item in l:
        if a%item==0:
            temp.append(item)
        if a%(a_min//item)==0:
            temp.append(a_min//item)
    l.clear()
    l+=temp
    temp.clear()
    if max(l)==1:
        break

print(max(l))

Submission status: Wrong Answer

Solution code:
N = int(input())
A_list = list(map(int, input().split()))
A_list.sort()
ans = A_list[0]
for i in range(1, N):
    if ans < A_list[i]:
        if A_list[i] % ans != 0:
            ans = A_list[i] % ans
        else:
            pass
    elif ans > A_list[i]:
        if ans % A_list[i] != 0:
            ans = ans % A_list[i]
        else:
            pass
    else:
        pass
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
ans=10**10
m=a[-1]
for i in range(len(a)-1):
    d=a[i+1]-a[i]
    if d!=0:
        t=m%d
        if t!=0:
            ans=min(ans,t)
    s=a[i+1]%a[i]    
    if s!=0:
        ans=min(ans,s)
print(min(ans,m))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
ans=10**10
m=a[-1]
for i in range(len(a)-1):
    d=a[i+1]-a[i]
    if d!=0:
        t=m%d
        s=a[i+1]%a[i]
        if t!=0:
            ans=min(ans,t)
        if s!=0:
            ans=min(ans,s)
print(min(ans,m))

Submission status: Wrong Answer

Solution code:
n=int(input())
a=sorted(list(map(int,input().split())))
ans=10**7
m=a[-1]
for i in range(len(a)-1):
    d=a[i+1]-a[i]
    if d!=0:
        t=m%d
        s=a[i+1]%a[i]
        if t!=0:
            ans=min(ans,t)
        if s!=0:
            ans=min(ans,s)
print(min(ans,m))

Submission status: Wrong Answer

Solution code:
import sys 
stdin = sys.stdin
ns = lambda : stdin.readline().rstrip()
ni = lambda : int(ns())
na = lambda : map(int, stdin.readline().split())

n = ni()
a = list(na())

def gcd(n, m):
  while m:
    n, m = m, n%m
  return n

ans = 1
for e in a:
  ans = gcd(ans, e)
print(ans)

Submission status: Wrong Answer

Solution code:
n=int(input())
a=list(map(int,input().split()))
a.sort()
#print(a)
if len(set(a))==1:
    print(a[0])
else:
    for i in a:
        if i%2==1:
            print(1)
            break
    else:
        print(2)

Submission status: Wrong Answer

Solution code:
import sys
def gcd(a,b):
    if a < b:
        a,b = b,a
    if b == 0:
        return a
    r = a%b
    return gcd(b,r)

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

mini = min(A)
for a in A:
    if gcd(mini,a) == 1:
        print(1)
        sys.exit()
print(mini)

Submission status: Wrong Answer

Solution code:
import sys

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

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

mini = min(A)
for a in A:
    if gcd(mini,a) == 1:
        print(1)
        sys.exit()
print(mini)

Submission status: Wrong Answer

Solution code:
import sys
def gcd(a,b):
    if a == b:
        return 0
    if b == 0:
        return a
    if a < b:
        a,b = b,a
    r = a%b
    return gcd(b,r)

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

mini = min(A)
for a in A:
    if gcd(mini,a) == 1:
        print(1)
        sys.exit()
print(mini)

Submission status: Wrong Answer

Solution code:
from fractions import gcd

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

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

Submission status: Wrong Answer

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

for i in range(n):
  for j in range(n):
    if i==j:
      continue
    a[j] = a[j]%a[i] if a[j]%a[i] > 0 else a[j]
  if min(a)==1:
    break
print(min(a))

Submission status: Wrong Answer

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

for i in range(n):
  for j in range(n):
    if i==j:
      continue
    a[j] = a[j]%a[i] if a[j]%a[i] > 0 else a[j]
print(min(a))

Submission status: Wrong Answer

Solution code:
# ABC118 C - Monsters Battle Royale
n = int(input())
a = list(map(int,input().split()))
a.sort()
inf = 10**10
ans = inf

c1 = 0
c2 = False
for i in range(n):
    if a[i]%2 == 0:
        c1 += 1

for i in range(n-1):
    if a[i+1]==a[i]:
        c2 = True
    else:
        c2 = False
        break

if c2 == True:
    a.sort()
    print(a[0])
    exit()

if c1 == n:
    print(2)
else:
    print(1)

Submission status: Wrong Answer

Solution code:
# ABC118 C - Monsters Battle Royale
n = int(input())
a = list(map(int,input().split()))
a.sort()
ans = 10**10
while a[1]-a[0] > 0:
    a[1] -= a[0]
    a.sort()
    t = a[0]
    ans = min(ans,t)
print(ans)

Submission status: Wrong Answer

Solution code:
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
b = [a[0],a[1]]
for i in range(1,n):
  ans = gcd(b[0],b[1])
  b[1] = b[0]
  b[0] = ans
print(ans)

Submission status: Wrong Answer

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

while True:
	f=False
	t=[]
	for i in range(len(A)-1):
		x=A[i]%A[i-1]
		if x not in A and x!=0:
			f=True
			t.append(x)
	A = sorted(A+t)
	if not(f):break

print(A[0])

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    N = int(input())
    A = list(map(int, input().split()))
    A.sort()
    mod = A[0]
    flag = True
    while flag:
        for i in range(0, N):
            if A[i]%mod == 0:
                continue
            else:
                mod = A[i]%mod
                A[i] = mod
                break
        if i == N-1:
            flag = False
    print(mod)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [a[0]]
for i in range(1, n):
    if a[0] != a[i]:
        b.append(a[i])
        break
if len(b) != 2:
    print(a[0])
    exit()

while True:
    i = b[0]
    j = b[1] % b[0]

    if (j == 0) or (i == j):
        print(i)
        break
    else:
        b[0] = min(i, j)
        b[1] = max(i, j)

Submission status: Wrong Answer

Solution code:
n = int(input())
a = list(map(int, input().split()))
a.sort()
b = [a[0], a[1]]
while True:
    i = b[0]
    j = b[1] % b[0]

    if (j == 0) or (i == j):
        print(i)
        break
    else:
        b[0] = min(i, j)
        b[1] = max(i, j)

Submission status: Wrong Answer

Solution code:
import fractions
N = int(input())
A = [int(x) for x in input().split()]
a = 1
for i in range(N):
  a =fractions.gcd(a,A[i])
print(a)

Submission status: Wrong Answer

Solution code:
import fractions

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

res = A[0]
for i in range(1, N - 1):
    res = fractions.gcd(res, A[i])

print(res)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import heapq

N = int(input())
a = list(map(int, input().split()))
heapq.heapify(a)
tmp = 0
tmp2 = 0

for i in range(N):
    tmp = heapq.heappop(a)
    if tmp == 1:
        print(tmp)
        exit()
    a = list(map(lambda x: x % tmp, a))
    if sum(a) == 0:
        print(tmp)
        exit()
    else:
        a = [j for j in a if j != 0]
        heapq.heappush(a, tmp)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
from functools import reduce
from fractions import gcd
def gcd_list(numbers):
    return reduce(gcd, numbers)

def resolve():
    n = int(input())
    aaa = list(map(int ,input().split()))
    print(gcd_list(aaa))