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

Fixed submission:
def main():
  X,N = list(map(int, input().split()))
  P = list(map(int, input().split()))
  #allowed elements
  Q = set([i for i in range(0,101+1)])
  for p in P:
    Q.remove(p)
  Q = sorted(Q)
  # distance from X
  D = [abs(q-X) for q in Q]
  # find smallest minimizer
  minD = min(D)
  for d,q in zip(D,Q):
    if d==minD:
      break
  print(q)
    
if __name__=='__main__':
  main()

Buggy submission (verdict: Runtime Error):
def main():
  X,N = list(map(int, input().split()))
  P = list(map(int, input().split()))
  # handle corner case:
  if N==0: return
  #allowed elements
  Q = set([i for i in range(1,100+1)])
  for p in P:
    Q.remove(p)
  Q = sorted(Q)
  # distance from X
  D = [abs(q-X) for q in Q]
  # find smallest minimizer
  minD = min(D)
  for d,q in zip(D,Q):
    if d==min(D):
      break
  print(q)
    
if __name__=='__main__':
  main()

Buggy submission (verdict: Runtime Error):
def main():
  X,N = list(map(int, input().split()))
  if N==0: return
  #forbidden elements
  P = list(map(int, input().split()))
  #allowed elements
  Q = set([i for i in range(1,100+1)])
  for p in P:
    Q.remove(p)
  Q = sorted(Q)
  # distance from X
  D = [abs(q-X) for q in Q]
  # find smallest minimizer
  minD = min(D)
  for d,q in zip(D,Q):
    if d==min(D):
      break
  return q
    
main()
Problem p04047 (python)

Fixed submission:
N=int(input())
inp=input()
L=[int(val) for val in inp.split()]
L=sorted(L,reverse=True)
total=0
start=0
for _ in range(N):
  total+=min(L[start],L[start+1])
  start+=2
print(total)

Buggy submission (verdict: Runtime Error):
N=int(input())
array=input()
L=[int(val) for val in array.split()]
L=sorted(L)
total=0
start=0
P=[L for val in L]
for _ in range(N):
  total+=min(P[start],P[start+1])
  P.pop(start)
  P.pop(start+1)
  start+=2
print(total)
Problem p02628 (python)

Fixed submission:
n,k=map(int,input().split())
p=list(map(int,input().split()))
print(sum(sorted(p)[:k]))

Buggy submission (verdict: Runtime Error):
n,k=map(int,input().split())
p=list(map(int,input().split()))
print(sum(sorted(p)[:K])
Problem p02621 (python)

Fixed submission:
a = int(input())

print(a + a*a + a*a*a)

Buggy submission (verdict: Runtime Error):
a = input()

print(a + a*a + a*a*a)
Problem p02909 (python)

Fixed submission:
a = {'Sunny' : 'Cloudy', 'Cloudy': 'Rainy', 'Rainy': 'Sunny'}
s = input()
print(a[s])

Buggy submission (verdict: Runtime Error):
a = {'Sunny' : 'Cloudy', 'Cloudy': 'Rainy', 'Rainy': 'Sunny')
s = input()
print(a[s])
Problem p02921 (python)

Fixed submission:
s = input()
t = input()
ans = 0
for i in range(len(s)):
  if s[i] == t[i]:
    ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()

ans = 0
for i in range(len(s)):
  if s[i] == t[i]:
    ans += 1
print ans

Buggy submission (verdict: Runtime Error):
s = input()
t = input()

ans = 0
for i in len(s):
  if s[i] == t[i]:
    ans += 1
print ans
Problem p02936 (python)

Fixed submission:

n, q = map(int, input().split())

ct = [0] * (n+1)
o = [0] * (n+1)
g = [[] for _ in range(n+1)]

for i in range(n-1):
  a,b= map(int, input().split())
  g[a].append(b)
  g[b].append(a)

for i in range(q):
  p,x= map(int, input().split())
  o[p] += x

todo = [1]
seen = [False] * (n+1)
while todo:
  p = todo.pop(-1)
  ct[p] += o[p]
  seen[p] = True
  for i in g[p]:
    if seen[i]:
      ct[p] += ct[i]
    else:
      todo.append(i)

print(*ct[1:])

Buggy submission (verdict: Runtime Error):
from sys import setrecursionlimit
setrecursionlimit(10000000)
n, q = map(int, input().split())

ct = [0] * (n+1)
o = [0] * (n+1)
g = [[] for _ in range(n+1)]

for i in range(n-1):
  a,b= map(int, input().split())
  g[a].append(b)
  g[b].append(a)

for i in range(q):
  p,x= map(int, input().split())
  o[p] += x

def dfs(p, parent):
  ct[p] += o[p] + ct[parent]
  for i in g[p]:
    if i != parent:
      dfs(i, p)
dfs(1, 0)
print(*counter[1:])

Buggy submission (verdict: Runtime Error):
# -*- condig:utf-8 -*-

import sys
import collections

n, q = map(int, input().split())

counter = [0 for _ in range(n+1)]
o = collections.defaultdict(int)
g = collections.defaultdict(list)

for i in range(n-1):
  a,b= map(int, input().split())
  g[a].append(b)
  g[b].append(a)

for i in range(q):
  p,x= map(int, input().split())
  o[p] += x


def dfs(p, parent):
  counter[p] += o[p]
  for i in g[p]:
    if i == parent:
      counter[p] += counter[i]
    else:
      dfs(i, p)
 
dfs(1, 0)
print(*counter[1:])

Buggy submission (verdict: Runtime Error):
# -*- condig:utf-8 -*-

def dfs(p, parents, count):
  parents.append(p)
  count += o.get(p, 0)
  for i in g[p]:
    if not i in parents:
      dfs(i, parents, count)
  counter[p] = counter.get(p, 0) + count
  parents.remove(p)
 

n, q = map(int, input().split())

g = {}
o = {}
counter = {}
for i in range(n-1):
  a,b= map(int, input().split())
  if not g.get(a, False):
    g[a] = [b]
  else:
    if not b in g[a]:
      g[a].append(b)
  if not g.get(b, False):
    g[b] = [a]
  else:
    if not a in g[b]:
      g[b].append(a)

for i in range(q):
  p,x= map(int, input().split())
  if not o.get(p, False):
    o[p] = x
  else:
    o[p] = o[p] + x

dfs(1, [], 0)
for i in range(1, n+1):
  print(counter.get(i, 0), end=' ')
Problem p02952 (python)

Fixed submission:
# -*- coding: utf-8 -*-
 
n = int(input())
if n == 100000:
  print(90909)
elif n / 10000 >= 1:
  print(9 + 900 + n - 10000 + 1)
elif n / 1000 >= 1:
  print(909)
elif n / 100 >= 1:
  print(9 + n - 100 + 1)
elif n / 10 >= 1:
  print(9)
elif n < 10:
  print(n)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-
 
n = int(input())
if n / 10000 >= 1:
  print(9 + 900 + n - 10000 + 1)
else if n / 100 >= 1:
  print(9 + n - 100 + 1)
else if n / 10 >= 1:
  print(9)
else if n < 10:
  print(n)
Problem p02953 (python)

Fixed submission:
# -*- coding: utf-8 -*-
 
n = int(input())
h = list(map(int, input().split()))
h.reverse()
limit = h[0]
r = 'Yes'
for i in range(n-1):
    if h[i] < limit:
      limit = h[i]
    if h[i+1] > limit + 1:
      r = 'No'
      break
    
print(r)

Buggy submission (verdict: Runtime Error):
# -*- coding: utf-8 -*-

n = int(input())
h = input().split()
h.reverse()
for i in range(n):
  for j in range(i+1, n) 
    if h[j] > h[i] + 1:
      print('No')
      return
print('Yes')
Problem p02628 (python)

Fixed submission:
x, y = list(map(int, input().split()))
arr = list(map(int, input().split()))


def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr
    if(1 <= x, y <= 1000 and 1 <= max(arr) <= 1000 and 1 <= min(arr) <= 1000):
        ref = arr[0]
        ref_count = 0

        for ele in arr:
            if ele < ref:
                left.append(ele)
            elif ele > ref:
                right.append(ele)
            else:
                ref_count += 1
        left = quick_sort(left)
        right = quick_sort(right)
        return left + [ref] * ref_count + right


sorted_list = quick_sort(arr)

result = 0

for i in range(0, y):
    result += sorted_list[i]


print(result)

Buggy submission (verdict: Runtime Error):
x, y = list(map(int, input().split()))
arr = list(map(int, input().split()))


def quick_sort(arr):
    left = []
    right = []
    if len(arr) <= 1:
        return arr
    if(1 <= x, y <= 1000 and 1 <= max(arr) <= 1000 and 1 <= min(arr) <= 1000):
        # データの状態に左右されないためにrandom.choice()を用いることもある。
        # ref = random.choice(arr)
        ref = arr[0]
        ref_count = 0

        for ele in arr:
            if ele < ref:
                left.append(ele)
            elif ele > ref:
                right.append(ele)
            else:
                ref_count += 1
        left = quick_sort(left)
        right = quick_sort(right)
        return left + [ref] * ref_count + right


sorted_list = quick_sort(arr)

result = sorted_list[0] + sorted_list[1] + sorted_list[2]

print(result)

Buggy submission (verdict: Runtime Error):
x, y = list(map(int, input().split()))
arr = list(map(int, input().split()))


def bubble_sort(arr):
    change = True
    while(change):
        change = False
        if(1 <= x, y <= 1000 and 1 <= max(arr) <= 1000 and 1 <= min(arr) <= 1000):
            for i in range(len(arr) - 1):
                if arr[i] > arr[i + 1]:
                    arr[i], arr[i + 1] = arr[i + 1], arr[i]
                    change = True
    return arr


sorted_list = bubble_sort(arr)

result = sorted_list[0] + sorted_list[1] + sorted_list[2]

print(result)
Problem p02640 (python)

Fixed submission:
# 動物の数がX匹、　足の総数がY本
X,Y = map(int,input().split())
#print(X,Y)
turu = 2
kame = 4
flag = False
for i in range(0, X + 1): # 0, 1, 2, 3
    #print("亀が{0}匹の場合".format(i))
    turu_num = X - i
    #print("鶴は{0}匹".format(turu_num))
    leg_total = kame * i + turu_num * turu
    #print("足の総数は{0}".format(leg_total))
    if(leg_total == Y):
      flag = True
      break
#    for q in range(0, X - i + 1):
#        print("鶴は{0}匹".format(q))
#        if kame * i + turu * q == Y and (i + q) <= X:
#            flag += 1
if flag:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
turu = 2
kame = 4
flag =0

for x in range(a + 1):
    for y in range(a + 1):
        if turu * x + kame * y == b and x + y <= a:
            flag += 1

if flag == 0:
    print("No")
else:
    print("Yes")
Problem p03220 (python)

Fixed submission:
a = int(input())
x  = 0
lists = []
ass =[]
#bが気温c、standardが平均気温の基準
b,standard = map(int,input().split())
#標高
elev = list(map(int,input().split()))

for i in range(a):
    lists.append(abs(b - elev[i] * 0.006 - standard))

m = min(lists)
mindex = lists.index(m)
print(mindex + 1)

Buggy submission (verdict: Runtime Error):
a = int(input())
x  = 0
lists = []
ass =[]
#bが気温c、standardが平均気温の基準
b,standard = map(int,input().split())
#標高
elev = list(map(int,input().split()))

for i in range(a):
    lists.append(abs(b - elev[i] * 0.006 - standard))

m = min(lists)
mindex = lists.index(1.0)
print(mindex + 1)

Buggy submission (verdict: Runtime Error):
a = int(input())
x  = 0
lists = []
ass =[]
#bが気温c、standardが平均気温の基準
b,standard = map(int,input().split())
#標高
elev = list(map(int,input().split()))

for i in range(a):
    lists.append(abs(b - elev[i] * 0.006 - standard))
    print(lists)

m = min(lists)
mindex = lists.index(1.0)
print(mindex + 1)
Problem p03254 (python)

Fixed submission:
N,x = map(int,input().split())
a = list(map(int,input().split()))
count = 0
#昇順に並べ替える
# sort_a = sorted(a)
a.sort(reverse=False)
for i in range(N):
    if x >= a[i]:
        count += 1
        x -= a[i]
    else:
        break

if (x!=0)and(count == N):
    count -= 1
print(count)

Buggy submission (verdict: Runtime Error):
for i in range(N):
    print(i)
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
        # print(x)
        continue
    break
print(count)

Buggy submission (verdict: Runtime Error):
N,x = map(int,input().split())
# a=[int(input()) for i in range(4)]
a = list(map(int,input().split()))
count = 0
#昇順に並べ替える
sort_a = sorted(a)

for i in range(len(N)):
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
    break
print(count)

Buggy submission (verdict: Runtime Error):
N,x = map(int,input().split())
# a=[int(input()) for i in range(4)]
a = list(map(int,input().split()))
count = 0
#昇順に並べ替える
sort_a = sorted(a)

for i in range(len(N)):
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
        print(x)
        continue
    break
print(count)

Buggy submission (verdict: Runtime Error):
N,x = map(int,input().split())
a=[int(input()) for i in range(N)]
# a = list(map(int,input().split()))
count = 0
#昇順に並べ替える
sort_a = sorted(a)

for i in range(len(a)):
    if x >= sort_a[i]:
        count += 1
        x -= sort_a[i]
        continue
    break
print(count)
Problem p03644 (python)

Fixed submission:

N=int(input())
k=0
while 2**k <= N:
    ans = 2**k
    k += 1
print(ans)

Buggy submission (verdict: Runtime Error):
a = input()
x = 0
while 2**x <=a:
    boxs = 2 ** x
    x += 1
print(boxs)
Problem p02687 (python)

Fixed submission:
s = str(input())
print('ABC') if s == 'ARC' else print('ARC')

Buggy submission (verdict: Runtime Error):
import collections


x = int(input())

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

prime = prime_factorize(x)[0]

a,b = 0,-prime
while True:
    if x == a**5 - (b)**5:
        print(a,b)
        break
    else:
        a += 1
        b += 1
Problem p03085 (python)

Fixed submission:
# coding: utf-8

s = input()

a1 = ['A','T']
a2 = ['C','G']

if s in a1:
    l = a1
else:
    l = a2

t = l.pop(l.index(s))
print(l[0])

Buggy submission (verdict: Runtime Error):
# coding: utf-8

s = input()

a1 = ['A','T']
a2 = ['C','G']

print(s)
if s in a1:
    l = a1
else:
    l = a2

l.discard(s)

print(l[0])
Problem p03087 (python)

Fixed submission:
# coding: utf-8

n, q = map(int, input().split())
s = input()

t = [0]*(n+1)
for i in range(n):
    if s[i:i+2] == 'AC':
        t[i+1] = t[i] + 1
    else:
        t[i+1] = t[i]

for i in range(q):
    l,r = (map(int, input().split()))
    ans = t[r-1] - t[l-1]
    print(ans)

Buggy submission (verdict: Runtime Error):
# coding: utf-8

n, q = map(int, input().split())
s = input()

[0]*(n+1)
for i in range(n):
    if s[i:i+2] == 'AC':
        i[i+1] = i[i] + 1
    else:
        i[i+1] = i[i]

for i in range(q):
    l,r = (map(int, input().split()))
    ans = t[r-1] - t[l-1]
    print(ans)
Problem p03145 (python)

Fixed submission:
# coding: utf-8

a, b, c = map(int, input().split())
M = max(a,b,c)
x = a*b*c//(M*2)
print(x)

Buggy submission (verdict: Runtime Error):
a = sorted(list(int, input().split()))

print(a[0]*b[1])
Problem p03146 (python)

Fixed submission:
# coding: utf-8

n = int(input())

i = 1
while n > 0:
    if n == 4 or n == 2 or n == 1:
        break
    i += 1
    if n % 2 == 0:
        n = n / 2
    else:
        n = n*3+1

print(i+3)

Buggy submission (verdict: Runtime Error):
# coding: utf-8

s = int(input())

i = 0
while n > 0:
    if n % 2 == 0:
        n = n / 2
    else:
        n = 3n+1
    if n == 4:
        break
    else:
        i += 1

print(i+4)

Buggy submission (verdict: Runtime Error):
# coding: utf-8

s = int(input())

i = 0
while n > 0:
    if n % 2 = 0:
        n = n / 2
    else:
        n = 3n+1
    if n == 4:
        break
    else:
        i += 1

print(i+4)
Problem p03239 (python)

Fixed submission:
N,T = map(int, input().split())

c_list = []

for i in range(N):
    c,t = map(int, input().split())
    if t <= T: c_list.append(c)

print(min(c_list)) if len(c_list) > 0 else print('TLE')

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

c_list = []

for i in range(N):
    c,t = map(int, input().split())
    if t <= T: c_list.append(c)

print(min(c_list))
Problem p02924 (python)

Fixed submission:
N=int(input())
print(int(N*(N-1)//2))

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

N_sum=list(range(N))
print(sum(N_sum))
Problem p04019 (python)

Fixed submission:
# coding: UTF-8
s = raw_input()

if 'N' in s and 'W' in s and 'S' in s and 'E' in s:
    print "Yes"
elif 'N' in s and not 'W' in s and 'S' in s and not 'E' in s:
    print "Yes"
elif not 'N' in s and 'W' in s and not 'S' in s and 'E' in s:
    print "Yes"
else :
    print "No"

Buggy submission (verdict: Runtime Error):
# coding: UTF-8
s = raw_input()

if 'N' in s and 'W' in s and 'S' in s and 'E' in s:
    print "Yes"
elif 'N' in s and not 'W' in s and 'S' in s and not 'E' in s:
    print "Yes"
elif not 'N' in s and 'W' in s and not 'S' in s and 'E' in s:
else :
    print "No"
Problem p02706 (python)

Fixed submission:
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
s = sum(a)
if(n>=s):
  print(n-s)
else:
  print("-1")

Buggy submission (verdict: Runtime Error):
n,m = map(int,input().split())
a = [int(i) for i in input().split()]
s = sum(a)
if(n=>s):
  print(n-s)
else:
  print("-1")
Problem p03037 (python)

Fixed submission:
n, m = [int(x) for x in input().split()]
l = [0] * m
r = [0] * m
for i in range(m):
    l[i], r[i] = map(int, input().split())

L = max(l)
R = min(r)

if L <= R:
    print(R - L + 1)
else:
    print(0)

Buggy submission (verdict: Runtime Error):
n, m = [int(x) for x in input().split()]
l = [0] * m
r = [0] * m
for i in range(m):
    l[i], m[i] = map(int, input().split())

L = max(l)
R = min(r)

if L <= R:
    print(R - L + 1)
else:
    print(0)
Problem p02665 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
temp=1
summ=0
cont=0
templist=[1]
for i in range(N+1):
  #print(temp)
  if A[i]<temp:
    if i<N:
      summ+=temp
      temp=2*(temp-A[i])
      templist.append(temp)
    elif i==N:
      summ+=temp
      cont+=1
  elif A[i]==temp:
    if i==N:
      summ+=temp
      #templist.append(temp)
      cont+=1
    else:
      print("-1")
      break
  else:
    print("-1")
    break
    
if cont==1:
  if A[N]==temp:
  	print(summ)
  else:
    #print(templist)
    #print(A)
    comp=A[-1]
    for i in range(N):
      summ-=(templist[-(i+1)]-comp)
      comp+=A[-(i+2)]
      #print(comp)
      #print(templist[-(i+2)])
      #print(summ)
      if comp>templist[-(i+2)]:
        print(summ)
        break
      if i==N-1:
        print(summ)
        break

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
temp=1
summ=0
cont=0
templist=[1]
for i in range(N+1):
  #print(temp)
  if A[i]<temp:
    if i<N:
      summ+=temp
      temp=2*(temp-A[i])
      templist.append(temp)
    if i==N:
      summ+=temp
      cont+=1
  elif A[i]==temp:
    if i==N:
      summ+=temp
      #templist.append(temp)
      cont+=1
    else:
      print("-1")
      break
  else:
    print("-1")
    break
    
if cont==1:
  #if A[N]==temp:
  #  print(summ)
  #else:
  #print(templist)
  #print(A)
  comp=A[-1]
  for i in range(N+1):
    summ-=(templist[-(i+1)]-comp)
    comp+=A[-(i+2)]
    #print(comp)
    #print(templist[-(i+2)])
    #print(summ)
    if comp>templist[-(i+2)]:
      print(summ)
      break

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
temp=1
summ=0
cont=0
templist=[1]
for i in range(N+1):
  #print(temp)
  if A[i]<temp:
    if i<N:
      summ+=temp
      temp=2*(temp-A[i])
      templist.append(temp)
    if i==N:
      summ+=temp
      cont+=1
  elif A[i]==temp:
    if i==N:
      summ+=temp
      #templist.append(temp)
      cont+=1
    else:
      print("-1")
      break
  else:
    print("-1")
    break
    
if cont==1:
  if A[N]==temp:
    print(summ)
  else:
    #print(templist)
    #print(A)
    comp=A[-1]
    for i in range(N+1):
      summ-=(templist[-(i+1)]-comp)
      comp+=A[-(i+2)]
      #print(comp)
      #print(templist[-(i+2)])
      #print(summ)
      if comp>templist[-(i+2)]:
        print(summ)
        break
Problem p02678 (python)

Fixed submission:
from collections import deque

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

g = [[] for _ in range(N+1)] # 隣接リスト

for _ in range(M):
    a, b = [int(x) for x in input().split()]
    #print(a,b,g)
    g[a].append(b)
    g[b].append(a)

#road_list=[]
#for i in range(M):
#  road_list.append(list(map(int,input().split())))

queue = deque([1])
d = [None] * (N+1) # uからの距離の初期化
d[1] = 0 # 自分との距離は0
while queue:
  v = queue.popleft()
  for i in g[v]:
    if d[i] is None:
      d[i] = v
      queue.append(i)

#print(d)


#ans_dict=dict([])
#before_room=[1]
#while True:
#  temp_room=[]
#  for j in range(len(before_room)):
#    for i in road_list:
#      if i[0]==before_room[j]:
#        if i[1] not in ans_dict:
#          ans_dict[i[1]]=before_room[j]
#          temp_room.append(i[1])
#      if i[1]==before_room[j]:
#        if i[0] not in ans_dict:
#          ans_dict[i[0]]=before_room[j]
#          temp_room.append(i[0])
#  before_room=temp_room
#  if len(ans_dict)==N:
#    break
    
d[0]=0
if None in d:
  print("No")
else:
  print("Yes")
  for i in range(2,N+1):
    print(d[i])

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

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

g = [[] for _ in range(N+1)] # 隣接リスト

for _ in range(M):
    a, b = [int(x) for x in input().split()]
    print(a,b,g)
    g[a].append(b)
    g[b].append(a)

#road_list=[]
#for i in range(M):
#  road_list.append(list(map(int,input().split())))

queue = deque([1])
d = [None] * (N+1) # uからの距離の初期化
d[1] = 0 # 自分との距離は0
while queue:
  v = queue.popleft()
  for i in g[v]:
    if d[i] is None:
      d[i] = v
      queue.append(i)

#print(d)


#ans_dict=dict([])
#before_room=[1]
#while True:
#  temp_room=[]
#  for j in range(len(before_room)):
#    for i in road_list:
#      if i[0]==before_room[j]:
#        if i[1] not in ans_dict:
#          ans_dict[i[1]]=before_room[j]
#          temp_room.append(i[1])
#      if i[1]==before_room[j]:
#        if i[0] not in ans_dict:
#          ans_dict[i[0]]=before_room[j]
#          temp_room.append(i[0])
#  before_room=temp_room
#  if len(ans_dict)==N:
#    break
    
d[0]=0
if None in d:
  print("No")
else:
  print("Yes")
  for i in range(2,N+1):
    print(d[i])
Problem p02684 (python)

Fixed submission:
N, K = list(map(int, input().split()))
A = list(map(int, input().split()))
 
check=[-1 for i in range(N)]
  
temp=1
circle=[]
for i in range(K):
  temp=A[temp-1]
  if check[temp-1]==-1:
    check[temp-1]=i
  else:
    circle.append(i-check[temp-1])
    #print(circle)
    break
  #print("temp",temp)
#print((K-i)%len(circle)-1)
if len(circle)!=0:
  amari=(K-i)%circle[0]
  temp=1
  for j in range(i+amari):
    temp=A[temp-1] 

print(temp)

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

def func1(lst, value):
    return [i for i, x in enumerate(lst) if x == value]
  
temp=1
trace=[1]
for i in range(K):
  temp=A[temp-1]
  ans=func1(trace,temp)
  if len(ans)==1:
    #print(temp)
    #print(trace.index(temp))
    #start=trace.index(temp)
    circle=trace[ans[0]:]
    #print(circle)
    break
  trace.append(temp)
  #print("temp",temp)
#print((K-i)%len(circle)-1)
amari=(K-i)%len(circle)-1
print(circle[amari])

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

temp=1
trace=[1]
for i in range(K):
  temp=A[temp-1]
  if temp in trace:
    #print(temp)
    #print(trace.index(temp))
    start=trace.index(temp)
    circle=trace[start:]
    #print(circle)
    break
  trace.append(temp)
  #print("temp",temp)
#print((K-i)%len(circle)-1)
amari=(K-i)%len(circle)-1
print(circle[amari])
Problem p02713 (python)

Fixed submission:
import math
from functools import reduce
import itertools
import numpy as np

K = int(input())



ans = 0
for i in range(1, K + 1):
    for j in range(i, K + 1):
        for k in range(j, K + 1):
            if i == j and j == k:
                dup_num = 1
            elif i == j or j == k:
                dup_num = 3
            else:
                dup_num = 6
            ans += math.gcd(math.gcd(i, j), k) * dup_num

print(ans)

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce
import itertools
import numpy as np


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


K = int(input())

l = [i for i in range(1, K + 1)]

temp_1 = np.array([])
for j in itertools.combinations(l, 3):
    temp_1=np.append(temp_1,gcd_list(list(j)))

a=np.sum(temp_1)*6

temp_2 = np.array([])

for j in itertools.combinations(l, 2):
    temp_2=np.append(temp_2,gcd_list(list(j[0],j[0],j[1])))
    temp_2=np.append(temp_2,gcd_list(list(j[0],j[1],j[1])))
    
b=np.sum(temp_2)*3

temp_3 = np.array([])
for i in l:
    temp_3 = np.append(temp_3, gcd_list([i, i, i]))

print(int(np.sum(temp_3)+a+b))