TnT/Multi_CodeNet4Repair huggingface dataset:
Problem: 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.

Submission attempts (in order):
from sys import stdin

def fun():
    n = (int(i) for i in input().split())

    l = [int(x) for x in stdin.readline().rstrip().split()]

    l = list(set(l))

    while 1 < len(l):
        for i in range(1, len(l)):
            if l[i]%l[0] == 0:
                l[i] = l[0]
            elif l[i] - l[i-1] == 1:
                print(1)
                return
            else:
                l[i] = l[i]%l[0]
        
        l = list(set(l))
        #l.sort()

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

    print(l[0])
    return

if __name__ == '__main__':
    fun()


from sys import stdin

def fun():
    n = (int(i) for i in input().split())

    l = [int(x) for x in stdin.readline().rstrip().split()]

    l.sort()

    while 1 < len(l):
        for i in range(1, len(l)):
            if l[i]%l[0] == 0:
                l[i] = l[0]
            elif l[i] - l[i-1] == 1:
                print(1)
                return
            else:
                l[i] = l[i]%l[0]
        l = [e for e in l if e != 0]
        l.sort()

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

    print(l[0])
    return

if __name__ == '__main__':
    fun()


from sys import stdin

def fun():
    n = (int(i) for i in input().split())

    l = [int(x) for x in stdin.readline().rstrip().split()]

    l = list(set(l))
    l.sort()

    while 1 < len(l):
        print(l)
        k = len(l)
        for i in range(1, k):
            if l[k-i]%l[0] == 0:
                l.pop(k-i)
            elif l[k-i] - l[k-i-1] == 1:
                print(1)
                return
            else:
                l[k-i] = l[k-i]%l[0]
        
        l = list(set(l))

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

    print(l[0])
    return

if __name__ == '__main__':
    fun()


from sys import stdin

def fun():
    n = (int(i) for i in input().split())

    l = [int(x) for x in stdin.readline().rstrip().split()]

    l = list(set(l))
    l.sort()

    while 1 < len(l):
        k = len(l)
        for i in range(1, k):
            if l[k-i]%l[0] == 0:
                l.pop(k-i)
            elif l[k-i] - l[k-i-1] == 1:
                print(1)
                return
            else:
                l[k-i] = l[k-i]%l[0]
        
        l = list(set(l))
        l.sort()

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

    print(l[0])
    return

if __name__ == '__main__':
    fun()


Verdicts: Time Limit Exceeded

Time Limit Exceeded

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):

N=int(input())
A=sorted(map(int,input().split()))
while len(A) != 1:
	B_nonzeros=[A[0]]
	for n in range(len(A)):
		i = A[n]%A[0]
		if i != 0:
			B_nonzeros.append(i)
	B_nonzeros.sort()
	A=B_nonzeros
	print(A)
print(A[0])


N=int(input())
A=sorted(map(int,input().split()))
while len(A) != 1:
	B_nonzeros=[A[0]]
	for n in range(len(A)):
		i = A[n]%A[0]
		if i != 0:
			B_nonzeros.append(i)
	B_nonzeros.sort()
	A=B_nonzeros
print(A[0])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
b=[]
e=False
while e==False:
    b=[]
    a_m=[]
    for i in a:
        if i!=0:
            a_m.append(i)
    print(a_m)#a=m a of positive
    temp=min(a_m)
    #5
    for i in a:
        g=i%temp
        if i==temp:
            b.append(i)#myself
        elif g!=0:
            b.append(i%temp)
        
    #b is only positive
    print("temp:",temp)
    print("b",b)
    if not b:#if empty 
        ans=temp
        e=True
         
    else:
        if temp==min(b):
            ans=temp
            e=True
        else:
            a=b
            print(a)
                
print(ans)






n=int(input())
a=list(map(int,input().split()))
b=[]
e=False
while e==False:
    b=[]
    a_m=[]
    for i in a:
        if i!=0:
            a_m.append(i)
    #print(a_m)#a=m a of positive
    temp=min(a_m)
    #5
    for i in a:
        g=i%temp
        if i==temp:
            b.append(i)#myself
        elif g!=0:
            b.append(i%temp)
        
    #b is only positive
    #print("temp:",temp)
    #print("b",b)
    if not b:#if empty 
        ans=temp
        e=True
         
    else:
        if temp==min(b):
            ans=temp
            e=True
        else:
            a=b
     #       print(a)
                
print(ans)






Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n=input()
a=list(map(int,input().split()))
for i in range(0,len(a)):
    a[i]=a[i]%min(a)
    a.append(min(a))
    for j in range(len(a)):
        if a[j]==0:
            a.remove(a[j])
print(a[0])

n=input()
a=list(map(int,input().split()))
k=[0,99999999]
for i in range(0,n):
    a[i]=a[i]%min(a)
    a.append(min(a))
    for j in range(n+1):
        if a[j]==0:
            a.remove(a[j])
            n-=1
print(a[0])

n=int(input())
a=list(map(int,input().split()))
while len(a)>1:
    m=min(a)
    def f(n):
        return n%m
    a=map(f,a)
    a=set(a)
    a.add(m)
    a.remove(0)
    a=list(a)
print(a[0])


Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = input().split()
for i in range(n):
    a[i] = int(a[i])
a = sorted(a)
while len(a) > 1:
    for i in range(1:len(a)):
        if a[len(a)-1-i] % a[0] == 0:
            a.pop()
        else: a[len(a)-1-i] %= a[0]
    a = sorted(a)
print(a[0])

n = int(input())
a = input().split()
for i in range(n):
    a[i] = int(a[i])
def gcm(a,b):
    if a >= b:
        if a % b == 0:
            return b 
        else:
            return gcm(b,a%b)
    else: return gcm(b,a)
for i in range(1,len(a)):
    a[0] = gcm(a[0],a[i])
print(a[0]) 

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import fraction
from functools import reduce


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


N = input()
A = input().split()
for i in range(len(A)):
    A[i] = int(A[i]) 
print("{}".format(gcd_list(A)))

from functools import reduce

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

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


N = input()
A = input().split()
for i in range(len(A)):
    A[i] = int(A[i])
answer = gcd_list(A)
print("{}".format(answer))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
a=list(map(int,input().split()))
a.sort()

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

print(a[0])

n=int(input())
a=list(map(int,input().split()))
def gcd(x,y):
  if x%y==0:
    return y
  else:
    return(y,x%y)
  
x=a[0]
  
for i in range(1,n):
  x=gcd(x,a[i])
  
print(x)  
  

n=int(input())
a=list(map(int,input().split()))
def gcd(x,y):
  if x%y==0:
    return y
  else:
    return gcd(y,x%y)
  
b=a[0]
  
for i in range(1,n):
  b=gcd(b,a[i])
  
print(b)  
  

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))


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


ans = 0

for i in range(len(a)):
    for j in range(i+1, len(a)):
        x = gcd(a[i], a[j])
        if x == 1:
            print(1)
            break

        elif ans == 0:
            ans = x
        elif x < ans:
            ans = x
    if x == 1:
        break


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

if len(set(a)) == 1:
    print(a[0])
else:
    a.sort()
    for i in range(1, 10 ^ 9+1):
        count = i
        for i in range(1, len(a)):
            x = a[i] + count
            for j in range(i):
                x = x % a[i-1-j]
        if x == 0:
            break

    print(count)


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

if len(set(a)) == 1:
    print(a[0])
else:
    def gcd(a, b):
        if b % a == 0:
            return a
        else:
            return(gcd(b % a, a))

    a.sort()
    ans = 0

    for i in range(len(a)):
        for j in range(i+1, len(a)):
            x = gcd(a[i], a[j])
            if x == 1:
                print(1)
                break

            elif ans == 0:
                ans = x
            elif x < ans:
                ans = x
        if x == 1:
            break


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


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


ans = gcd(a[0], a[1])

for i in range(2, len(a)):
    ans = gcd(ans, a[i])

print(ans)


Verdicts: Wrong Answer

Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N = int(input())
A = [int(n) for n in input().split()]

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

temp_gcm = gcm(A[0],A[1])
 for i in range(2,N):
     temp_gcm = gcm(A[i],temp_gcm)
print(temp_gcm)


N = int(input())
A = [int(n) for n in input().split()]

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

temp_gcm = gcm(A[0],A[1])
for i in range(2,N):
  temp_gcm = gcm(A[i],temp_gcm)
print(temp_gcm)


N = int(input())
A = [int(n) for n in input().split()]

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

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

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# -*- coding: utf-8 -*-
from functools import reduce

def gcd(a, b):
    x = max(a, b)
    y = min(a, b)
    z = y
    while x%y != 0:
        z = x%y
        x = y
        y = z
    else:
        return z

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


N = int(input())

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

print(gcd_list(A))

# -*- coding: utf-8 -*-
from functools import reduce

def gcd(a, b):
    x = max(a, b)
    y = min(a, b)
    z = y
    while x%y != 0:
        z = x%y
        x = y
        y = z
    else:
        return z
            

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


N = int(input())

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

print(gcd_list(A))

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n=int(input())
a=[map(int,input().split()) for i in range(n)]
b=a[0]
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x

for i in a:
  b=gcd(b,i)
print(b)

n=int(input())
a=[int(i) for i in input().split()]
b=a[0]
def gcd(x,y):
  while y:
    x,y=y,x%y
  return x

for i in a:
  b=gcd(b,i)
print(b)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
def gcd(a,b):
  a,b=max(a,b),min(a,b)
  if b==0:
    return a
  else:
    return gcd(b,a%b)
 
n=int(input())
arr=list(map(int,input().split()))
for i in range(n-1):
  tmp=gcd(arr[i],arr[i+1])
print(tmp)

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

n=int(input())
arr=list(map(int,input()))
for i in range(n-1):
  tmp=gcd(arr[i],arr[i+1])
print(tmp)

def gcd(a,b):
  a,b=max(a,b),min(a,b)
  if b==0:
    return a
  else:
    return gcd(b,a%b)
 
n=int(input())
arr=list(map(int,input()))
tmp=gcd(arr[0],arr[1])
for i in range(1,n):
  tmp=gcd(tmp,arr[i])
print(tmp)

def gcd(a,b):
  a,b=max(a,b),min(a,b)
  if b==0:
    return a
  else:
    return gcd(b,a%b)
 
n=int(input())
arr=list(map(int,input().split()))
tmp=gcd(arr[0],arr[1])
for i in range(1,n):
  tmp=gcd(tmp,arr[i])
print(tmp)

Verdicts: Wrong Answer

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from math import gcd
n = int(input())
a = list(map(int,input().split()))

g = a[0]
for i in a:
    g = gcd(g,i)

print(i)


from math import gcd
n = int(input())
a = list(map(int,input().split()))

g = a[0]
for i in a:
    g = gcd(g,i)

print(g)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())
A=list(map(int,input().split()))

while len(A)!=1:

    A.sort()
    if A.count(0):A.remove(0)
    for i in range(len(A)-1):            
        A[i+1]=A[i+1]%A[0]

print(max(A))

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

while len(set(A)) != 1:
    A.sort()
    print(A)
    B=list(map(lambda i:i%min(A), A[1:]))
    B.append(A[0])
    print(B)
    while B.count(0):
        B.remove(0)
    print(B)
    A=B
print(max(A))

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

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

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

Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
N=int(intput())
M=list(map(int, input().split()))
ans=min(M)
for m in M:
  if m%ans!=0:
    ans=1
    break
print(ans)

N=int(input())
M=list(map(int, input().split()))
ans=min(M)
mn=Min(M)
from math import gcd
for m in M:
  if m%ans!=0:
    ans=min(ans, gcd(mn,m))
print(ans)

N=int(input())
M=list(map(int, input().split()))
ans=min(M)
mn=Min(M)
from math import gcd
for m in M:
  if m%ans!=0:
    ans=min(ans, gcd(mn,m))
    break


N=int(input())
M=list(map(int, input().split()))
ans=min(M)
mn=Min(M)
for m in M:
  if m%ans!=0:
    ans=min(ans, gcd(mn,m))
    break

N=int(input())
M=list(map(int, input().split()))
ans=min(M)
mn=min(M)
from math import gcd
for m in M:
  if m%mn!=0:
    ans=min(ans, gcd(mn,m))
print(ans)


Verdicts: Runtime Error

Runtime Error

Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
# coding: utf-8
import sys


# import math
# import itertools

import numpy as np


"""Template"""


class IP:
    

    def __init__(self):
        self.input = sys.stdin.readline

    def I(self):
        
        return int(self.input())

    def S(self):
        
        return self.input()

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

    def SL(self):
        
        return list(map(str, self.input().split()))

    def ILS(self, n):
        
        return [int(self.input()) for _ in range(n)]

    def SLS(self, n):
        
        return [self.input() for _ in range(n)]

    def SILS(self, n):
        
        return [self.IL() for _ in range(n)]

    def SSLS(self, n):
        
        return [self.SL() for _ in range(n)]


class Idea:
    def __init__(self):
        pass

    def HF(self, p):
        
        return sorted(set(p[i] + p[j] for i in range(len(p)) for j in range(i, len(p))))

    def Bfs2(self, a):
        
        
        # https://blog.rossywhite.com/2018/08/06/bit-search/
        
        value = []
        for i in range(1 << len(a)):
            output = []

            for j in range(len(a)):
                if self.bit_o(i, j):
                    
                    # output.append(a[j])
                    output.append(a[j])
            value.append([format(i, 'b').zfill(16), sum(output)])

        value.sort(key=lambda x: x[1])
        bin = [value[k][0] for k in range(len(value))]
        val = [value[k][1] for k in range(len(value))]
        return bin, val

    def S(self, s, r=0, m=-1):
        
        r = bool(r)
        if m == -1:
            s.sort(reverse=r)
        else:
            s.sort(reverse=r, key=lambda x: x[m])

    def bit_n(self, a, b):
        
        return bool((a >> b & 1) > 0)

    def bit_o(self, a, b):
        
        return bool(((a >> b) & 1) == 1)

    def ceil(self, x, y):
        
        return -(-x // y)

    def ave(self, a):
        
        return sum(a) / len(a)

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





def main():
    
    r, e = range, enumerate
    ip = IP()
    id = Idea()

    
    n = ip.I()
    a = ip.IL()
    a = np.array(a)
    i = 2
    k = a
    while k.dtype == "int32":
        k = a / [i] * n
        i += 1

    print(i - 1)
    

main()


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


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



ans = min(gcd(a[0], x) for x in a)

print(ans)


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n= int(input())
a_list = list(map(int, input().split()))
gcd = a_list[0]
for i in range(1,n):
    gcd = math.gcd(gcd,a_list[i])
    
    
print(gcd)

import math
n= int(input())
a_list = list(map(int, input().split()))
gcd = a_list[0]
for i in range(1,n):
    gcd = math.gcd(gcd,a_list[i])
    
    
print(gcd)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import math
 
N = int(input())
A = [int(i) for i in input().split()] 

 
print(math.gcd(A))

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

N = int(input())
A = [int(i) for i in input().split()]
g = A[0]
for n in range(1,N):
    g = gcd(g,A[n])

print(g)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
N=int(input())
a_list=[]
a_list = list(map(int, input().split())) 
min_num=min(a_list)
nokori_list=[i%min_num for i in a_list if i%min_num!=0]
answer=0
if len(nokori_list)==0:
    print(min_num)
else:
    can_min=min(nokori_list)
    futuer_min=min_num%can_min
    while futuer_min>0:
        big=max(can_min,futuer_min)
        small=min(can_min,futuer_min)
        futuer_min=big%small
        if futuer_min==0:
            answer=small
            break
    	answer=small
    print(answer)

N=int(input())
a_list=[]
a_list = list(map(int, input().split())) 
min_num=min(a_list)
nokori_list=[i%min_num for i in a_list if i%min_num!=0]
if len(nokori_list)==0:
    print(min_num)
else:    
    while len(nokori_list)!=0:
        if len(nokori_list)==0:
            answer=min_num
            break
        else:
            nokori_list.append(min_num)
            min_num=min(nokori_list)
            new_list=[i%min_num for i in nokori_list if i%min_num!=0]
            nokori_list=new_list
        answer=min_num
    print(answer)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
A = list(map(int,input().split()))




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


x = A[0]
for i in a[1:]:
	x = gcd(x,i)
print(x)

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




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


x = A[0]
for i in A[1:]:
	x = gcd(x,i)
print(x)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input())
a = list(map(int, input().split()))
if max(a) != min(a):
    while a.count(0) != len(a)-1:
        print(a)
        a.sort()
        b = [a[0]]
        for i in a[1:]:
            if i%a[0] != 0:
                b.append(i%a[0])
        a = b
    print(max(a))
else:
    print(a[0])

n = int(input())
a = list(map(int, input().split()))
if max(a) != min(a):
    while a.count(0) != len(a)-1:
        a.sort()
        b = [a[0]]
        for i in a[1:]:
            if i%a[0] != 0:
                b.append(i%a[0])
        a = b
    print(max(a))
else:
    print(a[0])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import math
from functools import reduce
n = int(input())
li = list(map(int,input().split())
print(reduce(math.gcd,li))


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

def gcd(x,y):
    if y > x:
        x,y = y,x
    if x%y == 0:
        return y
    else:
        return gcd(y,x%y)
        
from functools import reduce
ans = reduce(gcd,L)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np

n = int(input())

a = input().split(' ')

a = np.array(a).astype(int)


while a[a>0].shape[0] > 1:
  not_0_a = a[a!=0]
  min_ = not_0_a.min()
  min_i = np.where(a == min_)
  a = a % min_
  a[min_i[0][0]] = min_
  print(a)

  """
  if a[a>0].shape[0] == 1:
    not_0_a = a[a!=0]
    min_ = not_0_a.min()
  """
  
print(min_)

import numpy as np

n = int(input())

a = input().split(' ')

a = np.array(a).astype(int)


while a[a>0].shape[0] > 1:
  not_0_a = a[a!=0]
  min_ = not_0_a.min()
  min_i = np.where(a == min_)
  a = a % min_
  a[min_i[0][0]] = min_

  """
  if a[a>0].shape[0] == 1:
    not_0_a = a[a!=0]
    min_ = not_0_a.min()
  """
  
print(min_)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
# ABC118c
from fractions import gcd
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
a = list(map(int, input().split()))
#from functools import reduce


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


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


# ABC118c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

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


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


Verdicts: Runtime Error

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
def f(a, m):
  if a % m == 0:
    return m
  else:
    return a % m

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

print(solve())


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

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

print(solve())


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input()) 
a = list(map(int, input().split()))
y = a[0]
for i in range(1,n):
    x = a[i]
    if(x < y):
        c = x
        x = y
        y = c
    while(y != 0):
        print(x,y)
        c = x % y
        x = y
        y = c
    y = x
    if(y == 1):
        break
print(y)

n = int(input()) 
a = list(map(int, input().split()))
y = a[0]
for i in range(1,n):
    x = a[i]
    if(x < y):
        c = x
        x = y
        y = c
    while(y != 0):
        c = x % y
        x = y
        y = c
    y = x
    if(y == 1):
        break
print(y)

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import numpy as np
i = input()
N = list(map(int, input().split(' ')))
def one_turn(l):
  l.sort()
  n = l[0]
  n2 = l[1]
  
  return np.array([n,n2]+[ i-n for i in l[2:] if ((i%n != 0)or(i%n2 != 0)) ])

if len(set(N)) == 1 :
  print(N[0])
else :
  N = np.array(N)
  while True :
    N = one_turn(N)
    if N[0] == 1 :
      print(1)
      break
    if len(N) == 1 :
      print(N[0])
      break

import numpy as np

N= int(input())

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

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

r = 0
for i in A:
  r = gcd(i,r)
print(r)
  

Verdicts: Time Limit Exceeded

Accepted
Problem: 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.

Submission attempts (in order):
import math

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

    b = min(A)
    for a in A:
        while True:
            if a%b == 0:
                break
            a,b = b, a%b
    print(b)

main()

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
import fractions
def main():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    ans = a[0]
    for i,a_i in enumerate(a,1):
        if ans == a_i:
            continue
        elif ans % a_i == 0 or a_i % ans == 0:
            ans = min(ans, fractions.gcd(ans,a_i))
        elif ans % 2 == 0 and a_i % 2 == 0:
            ans = 2
        else:
            ans = 1
            print(ans)
            return
    print(ans)
if __name__=='__main__':
    main()


import math
def main():
    n = int(input())
    a = list(map(int,input().split()))
    a.sort()
    ans = a[0]
    tmp = 0
    while True:
        for i in range(1,n):

            a[i] %= ans
            if a[i] != 0:
                tmp = min(ans,a[i])
        if sum(a) == ans:
            print(ans)
            return
        a.sort()
        ans = tmp
        a[0] = tmp

if __name__=='__main__':
    main()


Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
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

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

monsters.sort()  
minnum = monsters[0]

cnt = len(monsters)
minidx = 0
while cnt > 1:
    for i in range(cnt - 1, 0, -1):
        monsters[i] = monsters[i] % monsters[0]

        if monsters[i] == 0:
            del monsters[i]

        elif monsters[i] == 1:
            print('1')
            quit()

    workmin = min(monsters)
    minidx = monsters.index(min(monsters))
    monsters[minidx] = monsters[0]
    monsters[0] = workmin

    cnt = len(monsters)

print(monsters[0])

Verdicts: Wrong Answer

Accepted
Problem: 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.

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

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

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

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

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

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

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

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

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

Verdicts: Wrong Answer

Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):
n = int(input()) # the num of monster

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

ls.sort()

for i in range(len(ls)-1):
  if(len(ls)==1):
    print(len[0])
  for j in range(1, len(ls)):
    if(ls[j] % ls[i] == 0):
      ls.remove(ls[j])



n = int(input()) # the num of monster
 
ls = list(map(int, input().split()))
n = len(ls)
ans = math.gcd(ls[0], ls[1])

for i in range(n):
    ans = math.gcd(ans, ls[i])
    
print(ans)

n = int(input()) # the num of monster
 
ls = list(map(int, input().split()))
n = len(ls)

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

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

  

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
mina = max(a)
a.sort()
for i in range(n-1):
    mina = min(mina,math.gcd(a[i],a[i+1]))
print(mina)


from fractions import gcd
n = int(input())
a = list(map(int,input().split()))
mina = max(a)
for i in range(n-1):
    mina = min(mina,math.gcd(a[i],a[i+1]))
print(mina)


n = int(input())
a = list(map(int,input().split()))
mina = max(a)
def gcd(x,y):
    if y==0:
        return x
    else:
        return gcd(y,x%y)
a.sort()
for i in range(n-1):
    mina = min(mina,gcd(a[i],a[i+1]))
print(mina)

Verdicts: Runtime Error

Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
while len(h)>1:
    kh=[]
    for i in range(len(h)):
        mn = min(h)
        md=h[i]%mn
        if md!=0:
            kh.append(md)
        kh.append(mn)
    h=list(set(kh))
print(mn)

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

n=int(input())
a=list(map(int,input().split()))
ans=a[0]
for ak in a[1:]:
    ans=gcd(ans,ak)
print(ans)

Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
from fraction import gcd

n = int(input())
a = list(map(int, input().split()))
x = a[0]
for i in range(1, n):
    x = gcd(x, a[i])
    if x == 1:
        break
print(x)


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

n = int(input())
a = list(map(int, input().split()))
x = a[0]
for i in range(1, n):
    x = gcd(x, a[i])
print(x)


Verdicts: Runtime Error

Accepted
Problem: 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.

Submission attempts (in order):
import math
n=int(input())
lis=list(map(int,input().split()))
i=0
while len(lis)<i:
  lis+=math.gcd(lis[i],lis[i+1])
print(lis[-1])

def gcd(a,b):
  if b==0:
    return a
  else:
    return gcd(b,a%b)
n=int(input())
lis=list(map(int,input().split()))
i=0
while len(lis)-1>i:
  lis+=[gcd(lis[i],lis[i+1])]
  i+=2
print(lis[-1])

Verdicts: Wrong Answer

Accepted
Problem: 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.

Submission attempts (in order):


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




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

    while True:
        A.sort()

        before_min = A[0]
        after_min = before_min
        for i in range(1, N):
            A[i] = (A[i] % A[0]) if A[i] % A[0] != 0 else A[i]
            after_min = min(after_min, A[i])

        # print(A)
        if before_min == after_min:
            print(before_min)
            exit()

main()


Verdicts: Wrong Answer

Accepted