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

Fixed submission:
def main():
    import sys
    input = lambda: sys.stdin.buffer.readline().rstrip()
    n, w_max = map(int, input().split())
    import numpy as np

    v,w = [],[]
    for i in range(n):
        w_, v_ = map(int, input().split())
        v.append(v_)
        w.append(w_)
    dp = np.array([10**10]*(10**5+1),dtype=int)
    dp[0] = 0
    for i in range(n):
        dp[v[i]:] = np.minimum(dp[v[i]:], w[i]+dp[:-v[i]])
    ans = 0
    for i,w in enumerate(dp):
        if w<= w_max:
            ans = i
    print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input = lambda: sys.stdin.buffer.readline().rstrip()
    n, w_max = map(int, input().split())
    import numpy as np

    dp = np.zeros(w_max+1, dtype=int)
    v,w = [],[]
    for i in range(n):
        w_, v_ = map(int, input().split())
        v.append(v_)
        w.append(w_)
    for i in range(n):
        print(np.maximum(dp[w[i]:], v[i]+dp[:-w[i]]))
        dp[w[i]:] = np.maximum(dp[w[i]:], v[i]+dp[:-w[i]])
    print(dp[-1]) 

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys
    input = lambda: sys.stdin.buffer.readline().rstrip()
    n, w_max = map(int, input().split())
    import numpy as np

    dp = np.zeros(w_max+1, dtype=int)
    v,w = [],[]
    for i in range(n):
        v_, w_ = map(int, input().split())
        v.append(v_)
        w.append(w_)
    for i in range(n):
        dp[w[i]:] = np.maximum(dp[w[i]:], v[i]+dp[:-w[i]])
    print(dp[-1]) 

if __name__ == '__main__':
    main()
Problem p03169 (python)

Fixed submission:
import sys
from collections import Counter as cc
from numba import njit
import numpy as np

def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())

# sys.setrecursionlimit(10**4)
n = ii()
a = li()
c = cc(a)
N = sum(c.values())
cache = np.full((N+1, N+1, N+1), -1, dtype=float)
cache[0][0][0] = 0
@njit(cache=True)
def dfs(x, y, z, N, cache):
    if x+y+z==0:
        return 0
    if cache[x][y][z]>=0:
        return cache[x][y][z]
    tmp = 1
    if x > 0:
        tmp += dfs(x-1, y, z,N, cache)*x/N
    if y > 0:
        tmp += dfs(x+1, y-1, z, N, cache)*y/N
    if z > 0:
        tmp += dfs(x, y+1, z-1, N, cache)*z/N
    tmp *= N/(x+y+z)
    cache[x][y][z] = tmp
    return tmp

dfs(c[1], c[2], c[3], N, cache)
print(cache[c[1]][c[2]][c[3]])

Buggy submission (verdict: Runtime Error):
import sys
from collections import Counter as cc
from functools import lru_cache
def input(): return sys.stdin.readline().rstrip()
def ii(): return int(input())
def mi(): return map(int, input().split())
def li(): return list(mi())


def main():
    sys.setrecursionlimit(10**4)
    n = ii()
    a = li()
    c = cc(a)
    N = sum(c.values())
    
    @lru_cache
    def dfs(x, y, z):
        if x== 0 and y == 0 and z == 0:
            return 0
        tmp = 1
        if x > 0:
            tmp += dfs(x-1, y, z)*x/N
        if y> 0:
            tmp += dfs(x+1, y-1, z)*y/N
        if z > 0:
            tmp += dfs(x, y+1, z-1)*z/N
        tmp *= N/(x+y+z)
        return tmp
    
    print(dfs(c[1], c[2], c[3]))

    

if __name__ == '__main__':
    main()
Problem p03197 (python)

Fixed submission:

        
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    flag = 0
    for i in range(n):
        a = int(input())
        if a%2 == 1:
            print('first')
            return
    print('second')


    




                
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):

        
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    flag = 0
    for i in range(n):
        a = int(intput())
        flag &= (a%2 == 1)
    if flag:
        print('first')
    else:
        print('second')

    




                
if __name__ == '__main__':
    main()
Problem p03438 (python)

Fixed submission:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    s = 0
    sm = 0
    for x, y in zip(a,b):
        tmp = y-x
        sm += tmp
        if tmp > 0:
            tmp //= 2
        s += tmp
    if s >= 0 and sm >= 0:
        print('Yes')
    else:
        print('No')

    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    s = 0
    sm = 0
    for x, y in zip(a,b):
        tmp = x-y
        sm += tmp
        if tmp == -1
            tmp = 0
        if tmp > 0:
            tmp *= 2
        s += tmp
    if s > 0 or sm > 0:
        print('No')
    else:
        print('Yes')

    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    s = 0
    sm = 0
    for x, y in zip(a,b):
        tmp = x-y
        sm += tmp
        if tmp == -1
            tmp = 0
        if tmp > 0:
            tmp *= 2
        s += tmp
    if s > 0 or a > 0:
        print('No')
    else:
        print('Yes')

    
if __name__ == '__main__':
    main()
Problem p03565 (python)

Fixed submission:
s = input()
t = input()
s = s[::-1]
t = t[::-1]
for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if s[i+j] != t[j] and s[i+j] != '?':
      break
  else:
    break
else:
  print('UNRESTORABLE')
  exit(0)
s = s[:i] + t + s[i+len(t):]
s = s.replace('?','a')
s = s[::-1]
print(s)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
s = s[::-1]
t = t[::-1]
for i in range(len(s)):
  for j in range(len(t)):
    if s[i+j] != t[j] and s[i+j] != '?':
      break
  else:
    break
else:
  print('UNSTORERABLE')
  exit(0)
s = s[:i] + t + s[i+len(t):]
s = s.replace('?','a')
s = s[::-1]
print(s)

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
s = s[::-1]
t = t[::-1]
for i in range(len(s)):
  for j in range(len(t)):
    if s[i+j] != t[j] and s[i+j] != '?':
      break
  else:
    break
s = s[:i] + t + s[i+len(t):]
s = s.replace('?','a')
s = s[::-1]
print(s)
Problem p03569 (python)

Fixed submission:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    s = input()
    n = len(s)
    sr = s.replace('x', '')
    if sr == '':
        print(0)
        return
    elif sr != sr[::-1]:
        print(-1)
        return
    cur_l = 0
    cur_r = n-1
    ans = 0
    cnt = 0
    while cur_l < cur_r:
        while s[cur_l] == 'x':
            cnt += 1
            cur_l += 1
        while s[cur_r] != s[cur_l]:
            cur_r-=1
            cnt -= 1
        ans += abs(cnt)
        cur_l += 1
        cur_r -= 1
        cnt = 0
        
    print(ans)   
    
        

if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    s = input()
    n = len(s)
    cur_l = 0
    cur_r = n-1
    ans = 0
    cnt = 0
    while cur_l < cur_r:
        while s[cur_l] == 'x':
            cnt += 1
            cur_l += 1
        while s[cur_r] != s[cur_l]:
            if s[cur_r] != 'x':
                print(-1)
                return
            cur_r -= 1
            cnt -= 1
        ans += abs(cnt)
        cur_l += 1
        cur_r -= 1
        cnt = 0
        
    print(ans)   
    
        

if __name__ == '__main__':
    main()
Problem p03651 (python)

Fixed submission:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

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

    n, k =map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    c = a[0]
    for i in range(n):
        c = gcd(a[i], c)
    if k%c == 0 and k <= a[0]:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
    

    
if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

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

    n, k =map(int, input().split())
    a = list(map(int, input().split()))
    a.sort(reverse=True)
    c = a[0]
    for i in range(n):
        c = gcd(a[i], c)
    if k%c == 0:
        print('POSSIBLE')
    else:
        print('IMPOSSIBLE')
    

    
if __name__ == '__main__':
    main()
Problem p03695 (python)

Fixed submission:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n = int(input())
    a = list(map(int, input().split()))
    rate = [0]*8
    cnt = 0
    for x in a:
        r = x//400
        if r > 7:
            cnt += 1
        elif not rate[r]:
            rate[r] = 1
    s = sum(rate)
    mins = s
    if cnt > 0:
        mins += 1
        if s > 0:
            mins -=1
    maxs = s+cnt
    print(mins, maxs)        
        
            



if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()
    
    n = int(input())
    a =list(map(int, input().split()))
    rate = [0]*8
    cnt = 0
    for x in a:
        r = x//400
        if r > 7:
            cnt += 1
        if not rate[r]:
            rate[r] = 1
    s = sum(rate)
    mins = s+max(0, cnt-s)
    maxs = s+cnt
    print(mins, maxs)        
        
            



if __name__ == '__main__':
    main()
Problem p03848 (python)

Fixed submission:
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    a = list(map(int, input().split()))
    mod = 10**9 + 7
    a.sort()
    check = [i+1 - (i+n)%2 for i in range(n)]
    if a != check:
        print(0)
        return
    else:
        ans = pow(2, n//2, mod)
        print(ans)




if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    a = map(int, input().split())
    mod = 10**9 + 7
    a.sort()
    check = [i+1 - (i+n)%2 for i in range(n)]
    if a != check:
        print(0)
        return
    else:
        ans = pow(2, n//2, mod)
        print(ans)




if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
def main():
    import sys

    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    mod = 10**9 + 7
    a.sort()
    check = [i+1 - (i+n)%2 for i in range(n)]
    if a != check:
        print(0)
        return
    else:
        ans = pow(2, n//2, mod)
        print(ans)




if __name__ == '__main__':
    main()
Problem p03971 (python)

Fixed submission:
def main():
    import sys
    def input(): return sys.stdin.readline().rstrip()
    n, a, b = map(int, input().split())
    s = input()
    for ch in s:
        ans = 'Yes'
        if ch == 'c':
            ans = 'No'
        elif ch == 'a':
            if a > 0:
                a -=1
            elif b > 0:
                b -= 1
            else:
                ans = 'No'
        else:
            if b > 0:
                b -= 1
            else:
                ans = 'No'
        print(ans)


if __name__ == '__main__':
    main()

Buggy submission (verdict: Runtime Error):
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i++)
typedef long long ll;
using namespace std;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int total = a + b;
    string s; cin >> s;
    int cnt = 0, cntb = 0;
    rep(i,n){
        string ans = "Yes";
        if (s[i] == 'c') {
            ans = "No";
        }
        else if (s[i] == 'a')
        {
            if (cnt < a+b) cnt++;
            else ans = "No";
        }
        else {
            cntb++;
            if (cnt < a+b && cntb <= b) cnt++;
            else ans = "No";
        }
        cout << ans << endl;
    }
}

Buggy submission (verdict: Runtime Error):
#include<bits/stdc++.h>
#define rep(i, n) for (int i=0; i < n; i++)
typedef long long ll;
using namespace std;

int main()
{
    int n, a, b;
    cin >> n >> a >> b;
    int total = a + b;
    string s; cin >> s;
    int cnt = 0, cntb = 0;
    rep(i,n){
        string ans = "Yes";
        if (s[i] == 'c') {
            ans = "No";
        }
        else if (s[i] == 'a')
        {
            if (cnt < a+b) cnt++;
            else ans = "No";
        }
        else {
            cntb++;
            if (cnt < a+b and cntb <= b) cnt++;
            else ans = "No";
        }
        cout << ans << endl;
    }
}
Problem p02945 (python)

Fixed submission:
import math
a,b=map(int,input().split())
print(max(a+b,a-b,a*b))

Buggy submission (verdict: Runtime Error):
import math
a,b,c=map(int,input().split())
print(max(a+b,a-b,a*b))
Problem p03210 (python)

Fixed submission:
x=int(input())
 
if x==3 or x==5 or x==7:
  print("YES"+"\n")
else:
  print("NO"+"\n")

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

if x==3||x==5||x==7:
  print("YES"+"\n")
else:
  print("NO"+"\n")
Problem p02715 (python)

Fixed submission:
MOD = 1000000007

n, k = map(int, input().split())
ans = [0 for i in range(k+1)]
for i in range(k,0,-1):
    t = 0
    for j in range(2*i, k+1, i):
        t = (t + ans[j]) % MOD
    ans[i] = (pow(k//i, n, MOD) - t + MOD) % MOD
sm = 0
for i in range(1, k+1):
    sm = (sm + (i*ans[i]) % MOD) % MOD
print(sm % MOD)

Buggy submission (verdict: Runtime Error):
def gcd(x, y):
    while (y):
        x, y = y, x % y
    return x
MOD = int(10e9 + 7)

n, k = map(int, input().split())
mem = {}
def dp(at, cur):
    if at == n:
        return cur
    if (at,cur) in mem:
        return mem[(at,cur)]
    sm = 0
    for i in range(1, k+1):
        sm += dp(at+1,gcd(cur, i))
    mem[(at,cur)] = sm % MOD
    return sm % MOD

sm = 0
for i in range(1, k+1):
    sm += dp(1, i)
print(sm % MOD)
Problem p02720 (python)

Fixed submission:
import sys

sys.setrecursionlimit(100010)
k = int(input())


def islunlun(l):
    for x in range(1,len(l)):
        if abs(ord(l[x])-ord(l[x-1])) > 1:
            return False
    return True

s = set()
mx = 3234566667
def generate(l):
    val = None
    if l == []:
        val = 0
    else:
        val = int("".join(list(map(str,l))))
    #print(l, val)
    if mx < val:
        return
    else:
        if l != []:
            s.add(val)
    if len(l) == 0:
        for x in range(1,10):
            l.append(x)
            generate(l.copy())
            l.pop(len(l)-1)
    else:
        #print(max(0, l[len(l) - 1] - 1), min(9,l[len(l)-1]+1)+1)
        for x in range(max(0,l[len(l)-1]-1), min(9,l[len(l)-1]+1)+1):
            l.append(x)
            generate(l)
            l.pop(len(l)-1)

"""def bt(l):
    for x in range(10):
        l.append()"""

generate([])
l = []
for x in s:
    l.append(x)
l.sort()
print(l[k-1])

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(100010)
k = int(input())


def islunlun(l):
    for x in range(1,len(l)):
        if abs(ord(l[x])-ord(l[x-1])) > 1:
            return False
    return True

s = set()
mx = 3234566667
def generate(l):
    val = None
    if l == []:
        val = 0
    else:
        val = int("".join(list(map(str,l))))
    #print(l, val)
    if mx < val:
        return
    else:
        if l != []:
            s.add(val)
    if len(l) == 0:
        for x in range(1,10):
            l.append(x)
            generate(l.copy())
            l.pop(len(l)-1)
    else:
        #print(max(0, l[len(l) - 1] - 1), min(9,l[len(l)-1]+1)+1)
        for x in range(max(0,l[len(l)-1]-1), min(9,l[len(l)-1]+1)+1):
            l.append(x)
            generate(l)
            l.pop(len(l)-1)

"""def bt(l):
    for x in range(10):
        l.append()"""

generate([])
l = []
for x in s:
    l.append(x)
l.sort()
print(l[k-1])

Buggy submission (verdict: Runtime Error):
import sys

sys.setrecursionlimit(100000000)
k = int(input())


def islunlun(l):
    for x in range(1,len(l)):
        if abs(ord(l[x])-ord(l[x-1])) > 1:
            return False
    return True

s = set()
mx = 3234566667
def generate(l):
    val = None
    if l == []:
        val = 0
    else:
        val = int("".join(list(map(str,l))))
    #print(l, val)
    if mx < val:
        return
    else:
        if l != []:
            s.add(val)
    if len(l) == 0:
        for x in range(1,10):
            l.append(x)
            generate(l.copy())
            l.pop(len(l)-1)
    else:
        #print(max(0, l[len(l) - 1] - 1), min(9,l[len(l)-1]+1)+1)
        for x in range(max(0,l[len(l)-1]-1), min(9,l[len(l)-1]+1)+1):
            l.append(x)
            generate(l)
            l.pop(len(l)-1)

"""def bt(l):
    for x in range(10):
        l.append()"""

generate([])
l = []
for x in s:
    l.append(x)
l.sort()
print(l[k-1])
Problem p02630 (python)

Fixed submission:
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[list(map(int,input().split())) for i in range(Q)]

dp=[0 for i in range(1,10**6)]
for i in A:
    dp[i]+=1
S=sum(A)
for i in B:
    S+=(i[1]-i[0])*dp[i[0]]
    print(S)
    dp[i[1]]+=dp[i[0]]
    dp[i[0]]=0

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[list(map(int,input().split())) for i in range(Q)]

dp=[0 for i in range(1,10**5+1)]
for i in A:
    dp[i]+=1
S=sum(A)
for i in B:
    S+=(i[1]-i[0])*dp[i[0]]
    print(S)
    dp[i[1]]+=dp[i[0]]
    dp[i[0]]=0

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[list(map(int,input().split())) for i in range(Q)]

dp=[0 for i in range(1,10**5+1)]
for i in A:
    dp[i]+=1
S=sum(A)
for i in B:
    S+=(i[1]-i[0])*dp[i[0]]
    print(S)
    dp[i[1]]+=dp[i[0]]
    dp[i[0]]=0

Buggy submission (verdict: Runtime Error):
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
B=[list(map(int,input().split())) for i in range(Q)]
from bisect import bisect_left,bisect_right
# def 二分探索(リスト, 要素)
def index(lst, e):
    # Step 1. bisect_left して
    i = bisect_left(lst, e)
    
    # Step 2. 変な値を ValueError で弾いて
    if i == len(lst):
        return -1
    if lst[i] != e:
        return -1
    # Step 3. 値を返す。
    return i
def index2(lst, e):
    # Step 1. bisect_left して
    i = bisect_right(lst, e)
    
    # Step 2. 変な値を ValueError で弾いて
    if i == len(lst)+1:
        return -1
    if lst[i-1] != e:
        return -1
    # Step 3. 値を返す。
    return i
def count_sort(arr):
    max_num = max(arr)
    min_num = min(arr)
    count = [0] * (max_num - min_num + 1)
    for ele in arr:
        count[ele - min_num] += 1

    return [ele for ele, cnt in enumerate(count, start=min_num) for __ in range(cnt)]

A=count_sort(A)

for i in B:
    j=index(A,i[0])
    if not j==-1:
        k=index2(A,i[0])
        del A[k:l]
        for i in range(j,k)
            A.append(i[1])
            
    A=count_sort(A)
    print(sum(A))
Problem p02641 (python)

Fixed submission:
from bisect import bisect_left
import sys
X,N=list(map(int,input().split()))
if N==0:
    print(X)
    sys.exit()
P=list(map(int,input().split()))
P=sorted(P)
x=bisect_left(P,X)
if x>=len(P):
    print(X)
    sys.exit()
if P[x]!=X:
    print(X)
    sys.exit()
A=X
B=X
while True:
    A-=1
    B+=1
    x1=bisect_left(P,A)
    x2=bisect_left(P,B)
    if x1<len(P) and P[x1]!=A:
        print(A)
        break
    if x2<len(P) and P[x2]!=B:
        print(B)
        break
    if x2==len(P):
        print(B)
        break

Buggy submission (verdict: Runtime Error):
P=list(map(int,input().split()))
P=sorted(P)
x=bisect_left(P,X)
if x>=len(P):
    print(X)
    sys.exit()
if P[x]!=X:
    print(X)
    sys.exit()
A=X
B=X
while True:
    A-=1
    B+=1
    x1=bisect_left(P,A)
    x2=bisect_left(P,B)

    if x1<len(P) and P[x1]!=A:
        print(A)
        break
        
    if x2<len(P) and P[x2]!=B:
        print(B)
        break

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
import sys
X,N=list(map(int,input().split()))
if N==0:
    print(X)
    sys.exit()

P=list(map(int,input().split()))
P=sorted(P)
x=bisect_left(P,X)
if x>=len(P):
    print(X)
    sys.exit()
if P[x]!=X:
    print(X)
    sys.exit()
A=X
B=X
while True:
    A-=1
    B+=1
    x1=bisect_left(P,A)
    x2=bisect_left(P,B)

    if P[x1]!=A:
        print(A)
        break
        
    if P[x2]!=B:
        print(B)
        break

Buggy submission (verdict: Runtime Error):
from bisect import bisect_left
import sys
X,N=list(map(int,input().split()))
if N==0:
    print(X)
    sys.exit()
P=list(map(int,input().split()))
P=sorted(P)
x=bisect_left(P,X)
if P[x]!=X:
    print(X)
    sys.exit()

A=X
B=X

while True:
    A-=1
    B+=1
    x1=bisect_left(P,A)
    x2=bisect_left(P,B)
    if P[x1]!=A:
        print(A)
        break
    if P[x2]!=B:
        print(B)
        break
Problem p02664 (python)

Fixed submission:
T=input()
new_T=''
for i in T:
    if i=='?':
        i='D'
    new_T=new_T+i
print(new_T)

Buggy submission (verdict: Runtime Error):
import re
T=input()
N=len(re.findall(r'\?',T))
A=[]
def dfs(nums,length):
    if length==N:
        A.append(nums)
        return
    for i in range(0,2):
        new_nums=nums+[i]
        dfs(new_nums,length+1)
dfs([],0)
D={0:'P',1:'D'}
ans=0
ans2=''
for i in A:
    count=0
    new_T=''
    for j in T:
        if j=='?':
            j=D[i[count]]
            count+=1
        new_T=new_T+j
    if ans<=len(re.findall(r'PD',new_T))+len(re.findall(r'D',new_T)):
        ans2=new_T
print(ans2)
Problem p02678 (python)

Fixed submission:
from collections import deque
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
graph=[[]for i in range(N+1)]
for i in range(M):
    u,v=A[i]
    graph[u].append(v)
    graph[v].append(u)

stack=deque([1])
visited=[-1 for i in range(N+1)]
visited2=[-1 for i in range(N+1)]
visited[1]=0

while stack:
    x=stack.popleft()
    for i in graph[x]:
        if visited[i]==-1:
            visited[i]=visited[x]+1
            visited2[i]=x
            stack.append(i)
print('Yes')
print(*visited2[2:],sep='\n')

Buggy submission (verdict: Runtime Error):
from collections import deque
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
graph=[[]for i in range(N+1)]
for i in range(N):
    u,v=A[i]
    graph[u].append(v)
    graph[v].append(u)

stack=deque([1])
visited=[-1 for i in range(N+1)]
visited2=[-1 for i in range(N+1)]
visited[1]=0
while stack:
    x=stack.popleft()
    for i in graph[x]:
        if visited[i]==-1:
            visited[i]=visited[x]+1
            visited2[i]=x
            stack.appendleft(i)
print('Yes')
print(*visited2[2:],sep='\n')

Buggy submission (verdict: Runtime Error):
from collections import deque
N,M=list(map(int,input().split()))
A=[list(map(int,input().split())) for i in range(M)]
graph=[[]for i in range(N+1)]
for i in range(N):
    u,v=A[i]
    graph[u].append(v)
    graph[v].append(u)

stack=deque([1])
visited=[-1 for i in range(N+1)]
visited2=[-1 for i in range(N+1)]
visited[1]=0
while stack:
    x=stack.popleft()
    for i in graph[x]:
        if visited[i]==-1:
            visited[i]=visited[x]+1
            visited2[i]=x
            stack.append(i)
print('Yes')
print(*visited2[2:],sep='\n')