Harryxun/GPT-100-sft-dataset huggingface dataset:
Problem p02658 (python)

Fixed submission:
N = int(input())
#A = list(reversed(sorted(list(map(int, input().split())))))
A = sorted(list(map(int, input().split())))
assert len(A) == N
mul = 1
for a in A:
  mul *= a
#  print(a, mul)
  if a == 0:
    print(0)
    break
  if mul > (10 ** 18):
    print(-1)
    break
else:
  print(mul)

Buggy submission (verdict: Runtime Error):
N = int(input())
A = reversed(sorted(map(int, input().split())))
assert len(A) == N
mul = 1
for a in A:
  mul *= a
  if mul >= 10 ** 18:
    print(-1)
    break
else:
  print(mul)
Problem p02714 (python)

Fixed submission:
N = int(input())
S = input()
assert len(S) == N
count = 0

# j-i = k-jを探す
for i in range(0, len(S)-2):
  for j in range(i+1, len(S)-1):
    k = j + (j - i)
    if k < len(S):
      if S[i] != S[j] and S[j] != S[k] and S[k] != S[i]:
        count += 1
numR = 0
numG = 0
numB = 0
for s in S:
  if s == 'R':
    numR += 1
  elif s == 'G':
    numG += 1
  else:
    numB += 1

print(numR * numG * numB - count)

Buggy submission (verdict: Runtime Error):
N = int(input())
S = input()
assert len(S) == N
count = 0
for i in range(0, len(S)-2):
  for j in range(i+1, len(S)-1):
    if S[i] == S[j]:
      continue
    SiSj = Si + Sj
    if 'R' not in SiSj:
      Sk = 'R'
    elif 'G' not in SiSj:
      Sk = 'G'
    else:
      Sk = 'B'
    for k in range(j+1, len(S)):
      # RGBのどれかになるはず
      if Sk == S[k]:
        if j - i != k - j:
          count += 1
print(count)
Problem p02718 (python)

Fixed submission:
N, M =  map(int, input().split())
A = list(map(int, input().split()))
assert len(A) == N
# 商品iは得票Ai
# 総得票数の1/4M以上の商品をM個選ぶ
total = sum(A)
import math
thres = math.ceil(total / (4 * M))
count = len([i for i in range(N) if A[i] >= thres])
if count >= M:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
N, M =  map(int, input().split())
A = list(map(int, input().split()))
assert len(A) == N
# 商品iは得票Ai
# 総得票数の1/4M以上の商品をM個選ぶ
total = sum(A)
thres = math.ceil(total / (4 * M))
count = len([i for i in range(N) if A[i] >= thres])
if count >= M:
  print('Yes')
else:
  print('No')
Problem p02911 (python)

Fixed submission:
N, K, Q = map(int, input().split())
A = tuple([int(input()) for q in range(Q)])
# N人参加、初期状態で全員がKポイント
# 誰かが正解すると、それ以外の全員が1ポイント下がる
# i番目に正解したのはAi
counts = [0 for i in range(N)]
for a in A:
  counts[a-1] += 1

for i in range(N):
  print('Yes' if (K - (Q - counts[i])) >= 1 else 'No')

Buggy submission (verdict: Runtime Error):
N, K, Q = map(int, input().split())
A = tuple([int(input()) for q in range(Q)])
# N人参加、初期状態で全員がKポイント
# 誰かが正解すると、それ以外の全員が1ポイント下がる
# i番目に正解したのはAi
counts = [0 for i in range(Q)]
for a in A:
  counts[a-1] += 1

for i in range(N):
  print('Yes' if (K - (Q - counts[i])) >= 1 else 'No')
Problem p02554 (python)

Fixed submission:
n = int(input())
r = (10**n)-2*(9**n)+8**n
r%=(10**9+7)
print(r)

Buggy submission (verdict: Runtime Error):
n = int(input())
x = n*(n-1)%1000000007
y = 10**(n-2)%1000000007
print((x*y)%1000000007
Problem p02741 (python)

Fixed submission:
Term = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
K = int(input())
print(Term[K-1])

Buggy submission (verdict: Runtime Error):
import math

a,b,c = input().split()

left = int(a) + int(b)
right = int(c)

a = math.sqrt(int(a))
b = math.sqrt(int(b))
#c = math.sqrt(int(c))

left = left + 2*a*b


ans = ""

if(left< right):
    ans = "Yes"
else:
    ans = "No"

print(ans)

Buggy submission (verdict: Runtime Error):

H , W = input().split()
W = int(W)
H = int(H)
ans = int(0)

#Wが偶数なら(W//2)*H
#W.Hが奇数なら((W+1)//2)*((H+1)//2) + ((W - 1)//2*(H - 1)//2)
#Wが奇数Hが偶数(W+1)//2*(H//2) + ((W - 1)//2)*(H//2)

if(W == 1 or H == 1):
    ans = 1
elif(W%2 == 0):
    ans = (W//2)*H
elif(W%2 == 1 and H%2==1):
    ans = (((W+1)//2)*((H+1)//2)) + (((W - 1)//2)*((H - 1)//2))
elif(W%2 == 1 and H%2 ==0):
    ans = (((W+1)//2)*(H//2)) + (((W - 1)//2)*(H//2))
print(ans)
Problem p02742 (python)

Fixed submission:

H , W = input().split()
W = int(W)
H = int(H)
ans = int(0)

#Wが偶数なら(W//2)*H
#W.Hが奇数なら((W+1)//2)*((H+1)//2) + ((W - 1)//2*(H - 1)//2)
#Wが奇数Hが偶数(W+1)//2*(H//2) + ((W - 1)//2)*(H//2)

if(W == 1 or H == 1):
    ans = 1
elif(W%2 == 0):
    ans = (W//2)*H
elif(W%2 == 1 and H%2==1):
    ans = (((W+1)//2)*((H+1)//2)) + (((W - 1)//2)*((H - 1)//2))
elif(W%2 == 1 and H%2 ==0):
    ans = (((W+1)//2)*(H//2)) + (((W - 1)//2)*(H//2))
print(ans)

Buggy submission (verdict: Runtime Error):

H , W = input().split()
W = (W)
H = int(H)
ans = int(0)

#Wが偶数なら(W//2)*H
#W.Hが奇数なら((W+1)//2)*((H+1)//2) + ((W - 1)//2*(H - 1)//2)
#Wが奇数Hが偶数(W+1)//2*(H//2) + ((W - 1)//2)*(H//2)

if(W == H == 1):
    ans =1
elif(W%2 == 0):
    ans = (W//2)*H
elif(W%2 == 1 and H%2==1):
    ans = (((W+1)//2)*((H+1)//2)) + (((W - 1)//2)*((H - 1)//2))
elif(W%2 == 1 and H%2 ==0):
    ans = (((W+1)//2)*(H//2)) + (((W - 1)//2)*(H//2))
print(ans)
Problem p02743 (python)

Fixed submission:
import math

a,b,c = map(int,input().split())
ans = ""

if((4*a*b)<(c-a-b)*(c-a-b) and c-a-b>0):
    ans = "Yes"
else:
    ans = "No"

print(ans)

Buggy submission (verdict: Runtime Error):
import math

a,b,c = map(int,input().split())
ans = ""

if(c -a - b < 0 and 4*a*b>(c-a-b)*)*(c-a-b)):
    ans = "Yes"
else:
    ans = "No"

print(ans)

Buggy submission (verdict: Runtime Error):
import math

a,b,c = input().split()

ans = ""

if(c -a - b < 0 and 4*a*b>(c-a-b)*)*(c-a-b)):
    ans = "Yes"
else:
    ans = "No"

print(ans)

Buggy submission (verdict: Runtime Error):
import math

a,b,c = input().split()

left = a + b
right = c

a = math.sqrt(int(a))
b = math.sqrt(int(b))
#c = math.sqrt(int(c))

left = left + 2*a*b


ans = ""

if(left< right):
    ans = "Yes"
else:
    ans = "No"

print(ans)
Problem p03826 (python)

Fixed submission:
a,b,c,d=map(int,input().split())
print(max([a*b,c*d]))

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int,input().parse())
print(max([a*b,c*d]))

Buggy submission (verdict: Runtime Error):
a,b,c,d=map(int,input().parse())
print(max(a*b,c*d))
Problem p02657 (python)

Fixed submission:
a, b = map(int, input().split(" "))
print(a*b)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = map(int, input().split())
ans = 1
for i in a:
    ans *= i
if ans > 1e18:
    print(-1)
else:
    print(ans)
Problem p03448 (python)

Fixed submission:
A = int(input())
B = int(input())
C = int(input())
X = int(input())

pat = 0
for a in range(A+1):
	for b in range(B+1):
		for c in range(C+1):
			if a*500+b*100+c*50 == X:
				pat += 1
print(pat)

Buggy submission (verdict: Runtime Error):
A = int(input())
B = int(input())
C = int(input())
X = int(input())

pat = 0
for a in range(A):
	for b in range(B):
    	for c in range(C):
          if a*500+B*100+c*50 == X:
            pat += 1
print(pat)
Problem p03470 (python)

Fixed submission:
N = int(input())

d=[]
for i in range(N):
	d.append(int(input()))

dset = set(d)
print(len(dset))

Buggy submission (verdict: Runtime Error):
N = int(input())

for i in range(N):
	d = int(input())

dset = set(d)
print(len(dset))
Problem p03478 (python)

Fixed submission:
N,A,B = list(map(int,input().split()))

cnt = 0
for n in range(1,N+1):
    val = n % 10
    tmp = n
    while tmp // 10 > 0:
        
        tmp = tmp // 10
        val += tmp % 10
    if val >= A and val <= B:
        cnt += n
print(cnt)

Buggy submission (verdict: Runtime Error):
N,A,B = list(map(int,input().split()))

cnt = 0
for n range(1,N):
    val = 0
    tmp = N
    while tmp // N > 0:
        val = tmp % 10
        tmp = tmp // 10
    
    if val >= A and val <= B:
        cnt += 1
print(cnt)

Buggy submission (verdict: Runtime Error):
from math import log10

cnt = 0
for n range(1,N):
    val = 0
    tmp = N
    while tmp // N > 0:
        val = tmp % 10
        tmp = tmp // 10
    
    if val >= A and val <= B:
        cnt += 1
print(cnt)
Problem p03494 (python)

Fixed submission:
num = int(input())
 
vals = list(map(int,input().split()))
 
cnt = 0
flag = True
while(flag):
	for i in range(num):
		if vals[i] % 2 == 1:
			print(cnt)
			flag = False
			break
		else:
			vals[i] = vals[i] / 2
	cnt += 1

Buggy submission (verdict: Runtime Error):
num = int(input())

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

cnt = 0
while(True)
	for i in range(num):
    	if vals[i] % 2 == 1:
        	print(cnt)
        	break
        else:
    		vals[i] = vals[i] / 2
        cnt += 1
Problem p02772 (python)

Fixed submission:
n = int(input())
li = list(map(int,input().split()))
error = 0
for i in range(n):
  if li[i]%2 == 0:
    if li[i]%3 == 0 or li[i]%5 == 0:
      pass
    else:
      error = 1
  else:
    pass
if error:
  print('DENIED')
else:
  print('APPROVED')

Buggy submission (verdict: Runtime Error):
li = list(map(int,input().split()))
error = 0
for i in range(li[0]):
  if i == 1:
  else:
    if li[i]%2 == 0:
      if li[i]%3 == 0 or li[i]%5 ==0:
      else:
        error = 1:
    else:
if error:
  print('DENIED')
else:
  print('APPROVED')
Problem p02845 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
ans=1
c=[0,0,0]
for i in range(n):
  if a[i] not in c:
    ans=0
  else:
    ans*=c.count(a[i])
    ans%=1000000007
    c[c.index(a[i])]+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=1
c=[0,0,0]
for i in range(n):
  ans*=c.count(a[i])
  c[c.index(a[i])]+=1
print(ans%1000000007)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=1
c=[0,0,0]
for i in range(n):
  ans*=c.count(a[i])
  ans%=1000000007
  c[c.index(a[i])]+=1
print(ans)

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
ans=1
c=[0,0,0]
for i in range(n-1):
  ans*=c.count(a[i])
  ans%=1000000007
  c[c.index(a[i])]+=1
print(ans)
Problem p02854 (python)

Fixed submission:
import itertools
n = int(input())
a = list(itertools.accumulate(list(map(int, input().split()))))
sum_a = a[-1]
res = 2020202020
for i in range(n):
  res = min(res, abs(sum_a - a[i]*2))
print(res)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
res = 2020202020
for i in range(n):
  res = min(res, abs(a[:i] - a[i:]))
print(res)
Problem p03085 (python)

Fixed submission:
s = input()
if s == "A":
  print("T")
elif s == "C":
  print("G")
elif s == "G":
  print("C")
elif s == "T":
  print("A")

Buggy submission (verdict: Runtime Error):
s = input()
if s = "A":
  print("T")
elif s = "C":
  print("G")
elif s = "G":
  print("C")
elif s = "T":
  print("A")
Problem p03102 (python)

Fixed submission:
import numpy as np
n,m,c = map(int, input().split())
b = np.array(list(map(int, input().split())))
res = 0
for i in range(n):
  a = np.array(list(map(int, input().split())))
  if sum(a * b) + c > 0:
    res += 1
print(res)

Buggy submission (verdict: Runtime Error):
n,m,c = map(int, input().split())
b = list(map(int, input().split()))
res = 0
for i in range(n):
  a = list(map(int, input().split()))
  if sum(a * b) + c > 0:
    res += 1
print(res)
Problem p03129 (python)

Fixed submission:
n,k=map(int,input().split())
if (n+1)//2>=k:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
n,k=map(int,input())
if (n+1)//2>=k:
  print('YES')
else:
  print('NO')
Problem p03151 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
d=[]
for i in range(n):
  if a[i]>b[i]:
    c.append(a[i]-b[i])
  elif a[i]<b[i]:
    d.append(b[i]-a[i])
c.sort(reverse=True)
if sum(c)<sum(d):
  print(-1)
elif sum(c)==sum(d):
  print(len(c)+len(d))
else:
  ans=0
  if len(c)==1:
    print(1+len(d))
  else:
    for i in range(len(c)):
      if sum(c[:i])>=sum(d):
        ans=i
        break
    print(ans+len(d))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
d=[]
for i in range(n):
  if a[i]>b[i]:
    c.append(a[i]-b[i])
  elif a[i]<b[i]:
    d.append(b[i]-a[i])
c.sort(reverse=True)
if sum(c)<sum(d):
  print(-1)
else:
  ans=0
  for i in range(len(c)):
    if sum(c[:i])>=sum(d):
      ans=i
      break
print(ans+len(d))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
d=[]
for i in range(n):
  if a[i]>b[i]:
    c.append(a[i]-b[i])
  elif a[i]<b[i]:
    d.append(b[i]-a[i])
c.sort(reverse=True)
if sum(c)<sum(d):
  print(-1)
else:
  ans=0
  while sum(c[:ans])<sum(d):
    ans+=1
print(ans+len(d))

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
c=[]
d=[]
for i in range(n):
  if a[i]>b[i]:
    c.append(a[i]-b[i])
  elif a[i]<b[i]:
    d.append(b[i]-a[i])
c.sort(reverse=True)
if sum(c)<sum(d):
  print(-1)
else:
  ans=0
  while sum(c[:ans])<sum(d):
    ans+=1
print(ans+len(d))
Problem p03369 (python)

Fixed submission:
s = input()
tmp = 700
if s[0] == "o":
  tmp += 100
if s[1] == "o":
  tmp += 100
if s[2] == "o":
  tmp += 100
print(tmp)

Buggy submission (verdict: Runtime Error):
s = input()
tmp = 700
if s[0] == o:
  tmp += 100
if s[1] == o:
  tmp += 100
if s[2] == o:
  tmp += 100
print(tmp)
Problem p03370 (python)

Fixed submission:
n,x = map(int,input().split())
a = []
for i in range(n):
  a.append(int(input()))
print(n + (x-sum(a))//min(a))

Buggy submission (verdict: Runtime Error):
n,x = int(input())
a = []
for i in range(n):
  a.append(int(input()))
print(n + (x-sum(a))//min(a))
Problem p03386 (python)

Fixed submission:
a,b,k=map(int,input().split())
if 2*k >= b-a+1:
  print(*list(range(a,b+1)),sep='\n')
else:
  print(*list(range(a,a+k)),sep='\n')
  print(*list(range(b-k+1,b+1)),sep='\n')

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
arr=list(range(a,b+1))
for i in range(b-a+1):
  if i < k or i >= len(arr) - k:
    print(arr[i])

Buggy submission (verdict: Runtime Error):
a,b,k=map(int,input().split())
arr=list(range(a,b+1))
for i in range(b-a+1):
  if i <= k or len(arr)-i >= k:
    print(arr[i])
Problem p03424 (python)

Fixed submission:
n = int(input())
a = list(map(str, input().split()))
if a.count('Y') == 0:
  print('Three')
else:
  print('Four')

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
if a.count('Y') == 0:
  print('Three')
else:
  print('Four')
Problem p03474 (python)

Fixed submission:
n,m = map(int, input().split())
s = input()
num = '0123456789'
flg = 0
for i in range(len(s)):
  if i < n-1:
    if s[i] not in num:
      flg = 1
  elif i == n:
    if s[i] != '-':
      flg = 1
  else:
    if s[i] not in num:
      flg = 1
if flg == 0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())
s = input()
num = '0123456789'
flg = 0
for i in range(len(s)):
  if i < n-1:
    if s[i] not in num:
      flg = 1
  elif i == a:
    if s[i] != '-':
      flg = 1
  else:
    if s[i] not in num:
      flg = 1
if flg == 0:
  print('Yes')
else:
  print('No')
Problem p03502 (python)

Fixed submission:
n = int(input())
tmp = 0
for i in range(len(str(n))):
  tmp += int(str(n)[i])
if n % tmp == 0:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n = int(input())
tmp = 0
for i in range(len(str(n))):
  tmp += str(n)[i]
if n % tmp == 0:
  print('Yes')
else:
  print('No')
Problem p03556 (python)

Fixed submission:
n = int(input())
ans = 0
for i in range(int(pow(n,1/2))+1):
  if i**2 <= n:
    ans = i**2
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(input())
ans = 0
for i in range(pow(n,1/2)+1):
  if i**2 <= n:
    ans = i**2
print(ans)
Problem p03564 (python)

Fixed submission:
n = int(input())
k = int(input())
ans = 1
for i in range(n):
  if ans <= k:
    ans *= 2
  else:
    ans += k
print(ans)

Buggy submission (verdict: Runtime Error):
n = int(intput())
k = int(input())
ans = 1
for i in range(n):
  if ans <= k:
    ans *= 2
  else:
    ans += k
print(ans)
Problem p03611 (python)

Fixed submission:
n = int(input())
a = list(map(int, input().split()))
b = [0] * (pow(10,5) + 1)
for i in range(n):
  if a[i] == 0:
    b[0] += 1
    b[1] += 1
  elif a[i] == pow(10,5):
    b[pow(10,5) - 1] += 1
    b[pow(10,5)] += 1
  else:
    b[a[i]] += 1
    b[a[i] - 1] += 1
    b[a[i] + 1] += 1
print(max(b))

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
b = [0] * pow(10,5)
for i in range(n):
  if a[i] == 0:
    b[0] += 1
    b[1] += 1
  elif a[i] == pow(10,5):
    b[pow(10,5) - 1] += 1
    b[pow(10,5)] += 1
  else:
    b[a[i]] += 1
    b[a[i] - 1] += 1
    b[a[i] + 1] += 1
print(max(b))
Problem p03672 (python)

Fixed submission:
s = input()
for i in range(len(s)):
  s = s[:-1]
  if len(s) % 2 == 0:
    if s[:len(s)//2] == s[len(s)//2:]:
      print(len(s))
      break

Buggy submission (verdict: Runtime Error):
s = input()
for i in range(len(s)):
  s.pop(-1)
  if len(s) % 2 == 0:
    if s[:len(s)//2] == s[len(s)//2:]:
      print(len(s))
      break
Problem p03720 (python)

Fixed submission:
n,m = map(int, input().split())
a = [0]*n
for i in range(m):
  b,c = map(int, input().split())
  a[b-1] += 1
  a[c-1] += 1
[print(i) for i in a]

Buggy submission (verdict: Runtime Error):
n,m = map(int, input().split())
a = [0]*n
for i in range(m):
  b,c = map(int, input().split())
  a[b] += 1
  a[c] += 1
[print(i) for i in a]
Problem p03738 (python)

Fixed submission:
a = int(input())
b = int(input())
if a > b:
  print('GREATER')
elif a < b:
  print('LESS')
else:
  print('EQUAL')

Buggy submission (verdict: Runtime Error):
a = int(input())
b = int(intpu())
if a > b:
  print('GREATER')
elif a < b:
  print('LESS')
else:
  print('EQUAL')
Problem p03807 (python)

Fixed submission:
n = int(input())
arr = list(map(int, input().split()))
tmp = 0
for i in range(n):
  if arr[i] % 2 == 1:
    tmp += 1
if tmp % 2 == 0:
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input()))
odd=0
even=0
for i in range(n):
  if a[i]%2 == 0:
    even += 1
  else:
    odd += 1
if odd % 2 == 0:
  if (even + odd//2) % 2 == 0:
    print('YES')
  else:
    print('NO')
else:
  print('NO')
Problem p03845 (python)

Fixed submission:
n=int(input())
a=list(map(int,input().split()))
m=int(input())
sum_a=sum(a)
for i in range(m):
  s,t=map(int,input().split())
  print(sum_a+t-a[s-1])

Buggy submission (verdict: Runtime Error):
n=int(input())
a=list(map(int,input().split()))
m=int(input())
sum_a=sum(a)
for i in range(m):
  s,t=map(int,input().split())
  print(sum_a+t-a[s])
Problem p03909 (python)

Fixed submission:
h,w = map(int, input().split())
l = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for i in range(h):
  tmp = list(map(str, input().split()))
  if tmp.count('snuke') == 1:
    a = l[tmp.index('snuke')]
    b = str(i + 1)
print(a + b)

Buggy submission (verdict: Runtime Error):
h,w = map(int, input().split())
l = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
for i in range(w):
  tmp = list(map(str, input().split()))
  if tmp.count('snuke') == 1:
    a = l[tmp.index('snuke')]
    b = str(i + 1)
print(a + b)
Problem p03992 (python)

Fixed submission:
s = input()
print(s[:4] + ' ' + s[4:])

Buggy submission (verdict: Runtime Error):
print(input().insert(4,' '))
Problem p02574 (python)

Fixed submission:
N = int(input())
A = [int(x) for x in input().split()]

# M以下の整数の素因数分解を高速に
# 前処理O(MloglogM)
# 一計算O(logK)
def mae_syori(M):
    D = [0] * (M + 1)
    for i in range(2, M+1):
        if D[i] != 0: continue
    #     print(i, list(range(i*2, M + 1, i)))
        for j in range(i*2, M+1, i):
            if D[j] == 0:
                D[j] = i
    return D

def p_bunkai(K):
    assert 2 <= K <= len(D)-1
    k = K
    ret = []
    while True:
        if k == 1:
            break
        if D[k] == 0:
            ret.append((k, 1))
            break
        else:
            p = D[k]
            count = 0
            while k % p == 0:
                count += 1
                k //= p
            ret.append((p, count))
    return ret
 

# 最大公約数
# ユークリッドの互除法
def my_gcd(a, b):
    if b == 0:
        return a
    else:
        return my_gcd(b, a%b)

c_gcd = A[0]
for a in A:
    c_gcd = my_gcd(c_gcd, a)

if c_gcd == 1:
    max_A = max(A)
    D = mae_syori(max_A)
    yakusu = set()
    ok = True
    for a in A:
        if a == 1: continue
        p_bunkai_result = p_bunkai(a)
        p_list = [p[0] for p in p_bunkai_result]
        for p in p_list:
            if p not in yakusu:
                yakusu.add(p)
            else:
                ok = False
        if not ok:
            break
    if ok:
        print('pairwise coprime')
    else:
        print('setwise coprime')
else:
    print('not coprime')

Buggy submission (verdict: Runtime Error):
N = int(input())
A = [int(x) for x in input().split()]

# M以下の整数の素因数分解を高速に
# 前処理O(MloglogM)
# 一計算O(logK)
def mae_syori(M):
    D = [0] * (M + 1)
    for i in range(2, M+1):
        if D[i] != 0: continue
    #     print(i, list(range(i*2, M + 1, i)))
        for j in range(i*2, M+1, i):
            if D[j] == 0:
                D[j] = i
    return D

def p_bunkai(K):
    assert 2 <= K <= len(D)-1
    k = K
    ret = []
    while True:
        if k == 1:
            break
        if D[k] == 0:
            ret.append((k, 1))
            break
        else:
            p = D[k]
            count = 0
            while k % p == 0:
                count += 1
                k //= p
            ret.append((p, count))
    return ret
 

# 最大公約数
# ユークリッドの互除法
def my_gcd(a, b):
    if b == 0:
        return a
    else:
        return my_gcd(b, a%b)

c_gcd = A[0]
for a in A:
    c_gcd = my_gcd(c_gcd, a)

if c_gcd == 1:
    max_A = max(A)
    D = mae_syori(max_A)
    yakusu = set()
    ok = True
    for a in A:
        p_bunkai_result = p_bunkai(a)
        p_list = [p[0] for p in p_bunkai_result]
        for p in p_list:
            if p not in yakusu:
                yakusu.add(p)
            else:
                ok = False
        if not ok:
            break
    if ok:
        print('pairwise coprime')
    else:
        print('setwise coprime')
else:
    print('not coprime')
Problem p02678 (python)

Fixed submission:
from collections import deque

N, M = map(int, input().split())
con = [[] for _ in range(N)]
for i in range(M):
    A, B = map(int, input().split())
    con[A-1].append(B-1)
    con[B-1].append(A-1)
    
d = deque()
houmon = [False] * N
ans = [0] * (N-1)

houmon[0] = True
d.append(0)
while d:
#     print(d, houmon, ans)
    room = d.popleft()
#     houmon[room] = True
#     print(room)
    
    for next_room in con[room]:
        if not houmon[next_room]:
            ans[next_room-1] = room+1
            d.append(next_room)
            houmon[next_room] = True
    
print('Yes\n' + '\n'.join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
from collections import deque

N, M = map(int, input().split())
con = [[] for _ in range(M)]
for i in range(M):
    A, B = map(int, input().split())
    con[A-1].append(B-1)
    con[B-1].append(A-1)
    
d = deque()
houmon = [False] * N
ans = [0] * (N-1)

houmon[0] = True
d.append(0)
while d:
#     print(d, houmon, ans)
    room = d.popleft()
#     houmon[room] = True
#     print(room)
    
    for next_room in con[room]:
        if not houmon[next_room]:
            ans[next_room-1] = room+1
            d.append(next_room)
            houmon[next_room] = True
    
print('Yes\n' + '\n'.join(map(str, ans)))

Buggy submission (verdict: Runtime Error):
from collections import deque

N, M = map(int, input().split())
con = [[] for _ in range(M)]
for i in range(M):
    A, B = map(int, input().split())
    con[A-1].append(B-1)
    con[B-1].append(A-1)
    
d = deque()
houmon = [False] * N
ans = [0] * (N-1)

houmon[0] = True
d.append(0)
while d:
#     print(d, houmon, ans)
    room = d.popleft()
#     houmon[room] = True
#     print(room)
    
    for next_room in con[room]:
        if not houmon[next_room]:
            ans[next_room-1] = room+1
            d.append(next_room)
            houmon[next_room] = True
    
print('Yes\n' + '\n'.join(map(str, ans)))