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

Fixed submission:
n = int(input())
w = [input() for i in range(n)]

if n != len(set(w)):
    print('No')
    exit()
for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        print('No')
        exit()

print('Yes')

Buggy submission (verdict: Runtime Error):
n = int(input())
w = [input() for i in range(N)]

if n != len(set(w)):
    print('No')
    exit()
for i in range(n-1):
    if w[i][-1] != w[i+1][0]:
        print('No')
        exit()

print('Yes')

Buggy submission (verdict: Runtime Error):
def check_words(w):
    if len(w) != len(set(w)):
        return False
    for i in range(n-1):
        if w[i][-1] != w[i+1][0]:
            return False
    return True

n = int(input())
w = list(map(str, input().split()))
if check_words(w):
    ret = 'Yes'
else:
    ret = 'No'
print(ret)

Buggy submission (verdict: Runtime Error):
def check_words(w):
    if len(w) != len(set(w)):
        return False
    for i in range(n-1):
        if w[i][-1] != w[i+1][0]:
            return False
    return True

n = int(input())
w = list(map(str, input().split()))
ret = 'Yes' if check_words(w) else 'No'
print(ret)

Buggy submission (verdict: Runtime Error):
def check_words(w):
    if len(w) != len(set(w)):
        return False
    for i in range(n-1):
        if w[i][-1] != w[i+1][0]:
            return False
    return True

n = int(input())
w = list(map(str, input().split()))
ret = 'Yes' if check_words(w) else 'No'
print(ret)
Problem p03262 (python)

Fixed submission:
import math
import fractions
from functools import reduce

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

n,x = list(map(int, input().split()))
pos = list(map(int, input().split()))

pos.append(x)
pos.sort()

dist = []
for i in range(len(pos)-1):
    dist.append(pos[i+1]-pos[i])

print(gcd_list(dist))

Buggy submission (verdict: Runtime Error):
import math
from functools import reduce

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

n,x = list(map(int, input().split()))
pos = list(map(int, input().split()))

pos.append(x)
pos.sort()

dist = []
for i in range(len(pos)-1):
    dist.append(pos[i+1]-pos[i])

print(gcd_list(dist))
Problem p04043 (python)

Fixed submission:
input_num = input().split()
numbers = {'5':0,'7':0}
for num in input_num:
  if(num=='5' or num=='7'):
    numbers[num] +=1

if(numbers['5']==2 and numbers['7']==1):
  print('YES')
else:
  print('NO')

Buggy submission (verdict: Runtime Error):
n,k = input().split()
hate_num = input().split()
num = int(n)
boo = False
while(boo == False):
  dec = []
  for i in str(num):
    dec.append(i not in hate_num)
    
  if(False not in dec):
    boo = True
  num += 1
    
print(num-1)
Problem p02709 (python)

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

a = list(enumerate(a))
a.sort(key = lambda x: x[1])

DP = [[0 for i in range(n+1)] for j in range(n+1)]
DP[0][0] = 0
for i in range(1, n+1):
    pos, val = a.pop()
    pos = pos + 1

    DP[0][i] = DP[0][i-1] + abs(val * (n - i + 1 - pos))
    DP[i][0] = DP[i-1][0] + abs(val * (pos - i))
    for x in range(1, i):
        y = i - x
        DP[x][y] = max(DP[x-1][y] + abs(val * (pos - x)),  \
            DP[x][y-1] + abs(val * (n - y + 1 - pos)))

ans = 0
for i in range(n+1):
    ans = max(ans, DP[i][n-i])

print(ans)

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

a = list(enumerate(a))
a.sort(key = lambda x: x[1], reverse=True)

for i in range(n):
    a[i][0] = a[i][0] + 1

DP = [[0 for i in range(n+1)] for j in range(n+1)]
DP[0][0] = 0
for i in range(1, n+1):
    DP[0][i] = DP[0][i-1] + abs(a[i-1][1] * (n - i + 1 - a[i-1][0]))
    DP[i][0] = DP[i-1][0] + abs(a[i-1][1] * (a[i-1][0] - i))
    for x in range(1, i):
        y = i - x
        DP[x][y] = max(DP[x-1][y] + abs(a[i-1][1] * (a[i-1][0] - x)),  \
            DP[x][y-1] + abs(a[i-1][1] * (n - y + 1 - a[i-1][0])))

ans = 0
for i in range(n+1):
    ans = max(ans, DP[i][n-i])

print(ans)
Problem p03469 (python)

Fixed submission:
s=input()
r=s[4:]
print("2018%s"%(r))

Buggy submission (verdict: Runtime Error):
s=input()
s[0]='2'
s[1]='0'
s[2]='1'
s[3]='8'
print(s)
Problem p03473 (python)

Fixed submission:
a=int(input())
print(48-a)

Buggy submission (verdict: Runtime Error):
print(48-int(input().split())

Buggy submission (verdict: Runtime Error):
print(48-int(input())
Problem p02614 (python)

Fixed submission:
h, w, k = map(int, input().split())
c = [list(input()) for i in range(h)]
ans = 0
for p in range(1<<h):
    for q in range(1<<w):
        black = 0
        for m in range(h):
            for n in range(w):
                if (p>>m)&1 == 0 and (q>>n)&1 == 0 and c[m][n] == "#":
                    black += 1
        if black == k:
            ans += 1
print(ans)

Buggy submission (verdict: Runtime Error):
h, w, k = map(int, input().split())
c = []
for i in range(h):
    c.append(list(map(str, input().split())))
ans = 0
for j in range(1<<h):
    for k in range(1<<w):
        black = 0
        for m in range(h):
            for n in range(w):
                if ((j>>m) & 1) == 0 and ((k>>n) & 1) == 0 and c[m][n] == "#":
                    black += 1
        if black == k:
            ans += 1
print(ans)
Problem p02657 (python)

Fixed submission:
A, B = map(int, input().split())
print(A*B)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
x = 1
if 0 in a:
    x = 0
else:
    for j in a:
        x = j*x
        if x > 10**18:
            x = -1
            break
print(x)

Buggy submission (verdict: Runtime Error):
n = int(input())
a = list(map(int, input().split()))
x = 1
if 0 in a:
    x = 0
for j in a:
    x = j*x
    if x > 10**18:
        x = -1
        break
print(x)
Problem p02719 (python)

Fixed submission:
n, k = map(int, input().split())
print(min(n%k, k-n%k))

Buggy submission (verdict: Runtime Error):
n, m = map(int, input().split())
a = list(map(int, input().split()))
num = sum(a)
cnt = 0
for i in range(n):
    if a[i] < num/(4*m):
        continue
    else:
        cnt += 1
if cnt >= m:
    print("Yes")
else:
    print("No")
Problem p03086 (python)

Fixed submission:
s = input()
x = list()
cnt = 0
for i in range(len(s)):
    if s[i] == "A" or s[i] == "T" or s[i] == "G" or s[i] == "C":
        cnt += 1
        if i == len(s) - 1:
            x.append(cnt)
    else:
        x.append(cnt)
        cnt = 0
print(max(x))

Buggy submission (verdict: Runtime Error):
s = input()
x = list()
cnt = 0
for i in range(len(s)):
    if s[i] == "A" or s[i] == "T" or s[i] == "G" or s[i] == "C":
        cnt += 1
    else:
        x.append(cnt)
        cnt = 0
print(max(x))
Problem p03407 (python)

Fixed submission:
a, b, c = map(int, input().split())
if a+b < c:
  print("No")
else:
  print("Yes")

Buggy submission (verdict: Runtime Error):
n = int(input())
blue = list()
for i in range(n):
    blue.append(input())
m = int(input())
red = list()
for j in range(m):
    red.append(input())
ans = 0
for p in range(n):
    cnt = 0
    for q in range(n):
        if blue[p] == blue[q]:
            cnt += 1
    for r in range(m):
        if blue[p] == red[r]:
            cnt -= 1
    ans = max(ans, cnt)
print(ans)
Problem p02576 (python)

Fixed submission:

from sys import stdin
from math import ceil

N,X,T = [int(x) for x in stdin.readline().rstrip().split()]

result = ceil( N / X ) * T

print(result)

Buggy submission (verdict: Runtime Error):
import sys
import math


test = int(stdin.readline().rstrip())

result = math.ceil( test[0] / test[1] ) * test[2]

print(result)

Buggy submission (verdict: Runtime Error):
import sys
import math


test = sys.stdin

result = math.ceil( test[0] / test[1] ) * test[2]

print(result)
Problem p02582 (python)

Fixed submission:
from sys import stdin


test = list(stdin.readline().rstrip())

count = [0,0,0]
i=0
before = 'R'

for str in test:
    if str=='R':
        count[i] += 1
    else:
        i = i + 1

print(max(count))

Buggy submission (verdict: Runtime Error):
from sys import stdin

test = list(stdin.readline().lstrip().rstrip())

count = [0,0]
i=0
before = 'R'

for str in test:
    if str=='R':
        count[i] += 1
    else:
        i = i + 1

print(max(count))
Problem p02789 (python)

Fixed submission:
n, m = list(map(int, input().split()))
if n*n == m*n:
  print('Yes')
else:
  print('No')

Buggy submission (verdict: Runtime Error):
n, m = list(map(int, input()))
if n*n == m*n:
  print('Yes')
else:
  print('No')
Problem p03407 (python)

Fixed submission:
A,B,C=map(int,input().split() )
if A+B>=C:
    print("Yes\n")
else:
    print("No\n")

Buggy submission (verdict: Runtime Error):
#print("Hello World!")
A,B,C=map(int,raw_input().split() )
#print("end")
if A+B>=C:
    print("Yes\n")
else:
    print("No\n")
Problem p02646 (python)

Fixed submission:
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if v > w:
    # 1秒あたり距離はv-wだけ縮まる
    # t秒の時の距離は(v-w)*t
    # それが|a-b| の距離に間に合うor追い越せるかどうか
    if abs(a - b) <= (v - w) * t:
    # if t <= abs(a - b):
        print("YES")
    else:
        print("NO")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

if v > w:
    # 1秒あたり距離はv-wだけ縮まる
    # t秒の時の距離は(v-w)*t
    # それが|a-b| の距離に間に合うor追い越せるかどうか
    if abs(a - b) <= (v - w) * t
    # if t <= abs(a - b):
        print("YES")
    else:
        print("NO")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
import math
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

a = abs(a)
b = abs(b)

if a > b:
    w = a
    a = b
    b = a

# 鬼と逃げる人がぶつかる場所
meetingplace = int(lcm(a, b) + lcm(v, w))

requiredtime = int((meetingplace - v) / a) // v

if v > w:
    if t >= requiredtime:
        print("YES")
    else:
        print("NO")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
import math
a, v = map(int, input().split())
b, w = map(int, input().split())
t = int(input())

def lcm(x, y):
    return (x * y) // math.gcd(x, y)

if abs(a) > abs(b):
    mostabs = abs(a)
else:
    mostabs = abs(b)

if a < 0 or b < 0:
    a += mostabs
    b += mostabs


# 鬼と逃げる人がぶつかる場所
meetingplace = int(lcm(a, b) + lcm(v, w))

requiredtime = int((meetingplace - v) / a)

if v > w:
    if t >= requiredtime:
        print("YES")
    else:
        print("NO")
else:
    print("NO")
Problem p02747 (python)

Fixed submission:
s = input()
n = len(s) // 2
lst = [(i + j) for (i, j) in zip(s[::2], s[1::2])]

check = 0
for i in range(n):
    if lst[i] == 'hi':
        check = 1
    else:
        check = 0
        break

if len(s) % 2 == 1:
    check = 0

if check == 1:
    print("Yes")
else:
    print("No")

Buggy submission (verdict: Runtime Error):
s = input()
n = len(s) // 2
lst = [(i + j) for (i, j) in zip(s[::2], s[1::2])]

for i in range(n):
    if lst[i] == 'hi':
        check = 1
    else:
        check = 0
        break

if check == 1:
    print("Yes")
else:
    print("No")
Problem p03001 (python)

Fixed submission:
W, H, x, y = map(int, input().split())
bigarea = W * H

j = (bigarea/2.000000)

# print('{:6f}'.format(bigarea/2))

if W /2 == x and H / 2 == y:
    k = '1'
else:
    k = '0'

# print(j, k)
# j = str(j)
print('{:6f} {:}'.format(j,k))

Buggy submission (verdict: Runtime Error):


W, H, x, y = map(int, input().split())
bigarea = W * H

j = (bigarea/2.000000)

# print('{:6f}'.format(bigarea/2))

if j % 2 ==0:
    k = '1'
elif W /2 == x and H / 2 == y:
    k = '0'

if x == 0 and y == 0:
    j = 0

# print(j, k)
# j = str(j)
print('{:6f} {:}'.format(j,k))

Buggy submission (verdict: Runtime Error):


W, H, x, y = map(int, input().split())
bigarea = W * H

j = (bigarea/2.000000)

# print('{:6f}'.format(bigarea/2))

if j % 2 ==0:
    k = '1'
elif W /2 == x and H / 3 == y:
    k = '0'

if x == 0 and y == 0:
    j = 0

# print(j, k)
# j = str(j)
print('{:6f} {:}'.format(j,k))
Problem p03455 (python)

Fixed submission:
a, b = map(int, input().split())
x = a * b
if x % 2 == 1:
    print("Odd")
else:
    print("Even")

Buggy submission (verdict: Runtime Error):
a, b = int(input().split())
x = a * b
if x % 2 == 1:
  print("Odd")
else:
  print("Even")
Problem p03493 (python)

Fixed submission:
s = input()
print(s.count("1"))

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
x = a + b + c
print(x)

Buggy submission (verdict: Runtime Error):
a, b, c = map(int, input().split())
x = a + b + c
print(x)
Problem p02574 (python)

Fixed submission:
#高速素因数分解  osa_k法 
def osa_k(a):
    tmp = set()
    while a > 1:
        tmp.add(sieve[a])
        a //= sieve[a]
    return tmp

    # 初期入力
import math
import sys
from bisect import bisect_left
from functools import reduce
input = sys.stdin.readline  #文字列では使わない
N = int(input())
A = list(map(int, input().split()))
used =set()

#not coprimeの判定
gcd_a =reduce(math.gcd,A)
if gcd_a !=1:
    ans ="not coprime"

#pairwise coprimeの判定
else:
    MAXN =10**6 +10
    #osa_k法
    sieve = [i for i in range(MAXN+1)]
    p = 2
    while p*p <= MAXN:
        if sieve[p] == p:
            for q in range(2*p,MAXN+1,p):
                if sieve[q] == q:
                    sieve[q] = p
        p += 1
    
    ans ="pairwise coprime"
    for a in A:
        aa =osa_k(a)
        if used & aa:
            ans ="setwise coprime"
            break #共通要素があったらpair_wではない→set_w
        used |=aa
    
print(ans)

Buggy submission (verdict: Runtime Error):
# 自然数m以下の素数を返す（SETでRETURN）
import math
def prime_numbers(m):
    # 素数を保持するset
    primes = []

    # 2以上m以下の素数を数え上げる
    n = 2
    while n <= m:
        # 自身より小さい全ての素数で割り切れなければ、素数とみなせる
        if all(n % i != 0 for i in primes):
            primes.append(n)
        n += 1
    return primes

#素因数分解（10**6まで）
def soinsu_bunkai(m):
    pf=set()

    for i in pri_num:
        if i >m:
            break
        elif m%i==0:
            pf.add(i)

    return pf

    # 初期入力
import sys
from collections import Counter
from functools import reduce
input = sys.stdin.readline  #文字列では使わない
N = int(input())
A = list(map(int, input().split()))

# 10**6までの素因数分解するために、「10**6のルート」までの素数を列挙
pri =10**6 +10
sq_pri =int(math.sqrt(pri))
pri_num =prime_numbers(sq_pri +10)

#not coprimeの判定
gcd_a =reduce(math.gcd,A)
if gcd_a !=1:
    ans ="not coprime"

#pairwise coprimeの判定
else:
    intersect =set()
    used =set()
    pair_w =set()
    set_w =set()
    for a in A:
        aa =soinsu_bunkai(a)
        if intersect & aa:
            pair_w.add(0)
        else:
            pair_w.add(1)
        intersect |=aa

if 1 in pair_w and 0 not in pair_w:
    ans ="pairwise coprime"
else:
    ans ="setwise coprime"
print(ans)
Problem p02641 (python)

Fixed submission:
# 初期入力
import sys
input = sys.stdin.readline
X,N = (int(i) for i in input().split())
if N !=0:
    p = list(map(int, input().split()))
elif N ==0:
    p=[-1]
p.sort()
#
ans =[]
for i in range(-1,102):
    if i not in p:
        ans.append((abs(i-X),i))
ans.sort()
print(ans[0][1])

Buggy submission (verdict: Runtime Error):
# 初期入力
import sys
input = sys.stdin.readline
X,N = (int(i) for i in input().split())
if N !=0:
    p = list(map(int, input().split()))
else:
    p=[-1]
#
ans =[]
for i in range(1,101):
    if i not in p:
        ans.append((abs(i-X),i))
ans.sort()
print(ans[0][1])

Buggy submission (verdict: Runtime Error):
# 初期入力
import sys
input = sys.stdin.readline
X,N = (int(i) for i in input().split())
if N !=0:
    p = list(map(int, input().split()))
else:
    p=[-1]
#
ans =[]
for i in range(1,101):
    if i not in p:
        ans.append((abs(i-X),i))
ans.sort()
print(ans[0][1])
aa=0
Problem p02642 (python)

Fixed submission:

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

	

from collections import Counter
import bisect
N = int(input())
A = list(map(int,input().split()))
cnt = Counter(A)
A.sort()
ans = 0
MX = 10**6
P = [0] * (MX+1)
for a in A:
    if P[a]==0:
        for i in range(MX+1):
            x = a*i
            if x > MX:
                break
            P[x] = 1
        if cnt[a]==1:
            ans+=1
print (ans)

Buggy submission (verdict: Runtime Error):
# 初期入力
import numpy as np 
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
A.sort()
A_np =np.array(A,dtype=np.int64)
A_set =set(A)
count =set()
for i in range(N):
    if np.count_nonzero(A[i] %A_np[:i] ==0) >=1:
            count.add(A[i])
ans =len(A_set - count)
print(ans)
"""
Problem p02647 (python)

Fixed submission:
# imos法
# 長さNの1次元配列において、「ある連続する区間に、ある数vを足す」という操作をK回繰り返した結果を高速で求める
# 
    
# 初期入力
    
import sys
input = sys.stdin.readline
N,K = (int(i) for i in input().split())
A = list(map(int, input().split()))
    
    
l =0
r =N
cumulative_sum =[0]*N
#操作数が電球の数より多いとき
if N <=K:
    A=[N]*N
# imos法
else:
    for j in range(K):
        B =[0]*(N+1)
        for i in range(N):
            index =A[i]
            if i-index <0:
                l=0
            else:
                l =i -index
            if i +index +1 >=N:
                r =N 
            else:
                r =i +index +1
            B[l] +=1 
            B[r] -=1
        #累積和(imos法) 
        from itertools import accumulate
        del B[-1]
        A =list(accumulate(B))
        if sum(A) ==N*N:
            print(*A)
            sys.exit(0)
    
print(*A)

Buggy submission (verdict: Runtime Error):
# imos法
# 長さNの1次元配列において、「ある連続する区間に、ある数vを足す」という操作をK回繰り返した結果を高速で求める
import numpy as np
# 初期入力
import sys
input = sys.stdin.readline
N,K = (int(i) for i in input().split())
A = list(map(int, input().split()))


l =0
r =N
cumulative_sum =[0]*N
#操作数が電球の数より多いとき
if N <=K:
    B=[N]*N
# imos法
else:
    for j in range(K):
        B =[0]*(N+1)
        for i in range(N):
            index =A[i]
            if i-index <0:
                l=0
            else:
                l =i -index
            if i +index >N:
                r =N 
            else:
                r =i +index +1
            B[l] +=1 
            B[r] -=1
        #累積和(imos法) 
        cumulative_sum[0] =B[0]       
        for i in range(1,N):
            cumulative_sum[i] =cumulative_sum[i-1] +B[i]

        A =cumulative_sum
        if sum(A) ==N*N:
            print(*A)
            sys.exit(0)
        cumulative_sum =[0]*N
    
print(*A)
Problem p02658 (python)

Fixed submission:
# 初期入力
import numpy as np
import sys
input = sys.stdin.readline
N = int(input())
A = list(map(int, input().split()))
ans =1
if 0 in A:
    ans =0
else:
    for i in A:
        ans *=i
        if 10**18 < ans :
            ans = -1
            break
print(ans)

Buggy submission (verdict: Runtime Error):
import numpy as np 
N = int(input())
A = list(map(int, input().split()))
A =np.array(A,dtype=np.int64)

#
ans =0
if 0 in A:
    ans =0:
else:
    ans =np.prod(A)
    if ans >10**18:
        ans =-1
print(ans)
Problem p02664 (python)

Fixed submission:
# 初期入力
import sys
input = sys.stdin.readline
T =list(input().strip())

    
if T[0] =="?":
    if len(T) ==1 :
        T[0] ="D"
    elif T[1] =="?":
        T[0] ="P"
        T[1] ="D"
    elif T[1] =="D":
        T[0] ="P"
    else:
        T[0] ="D"


for i in range(1,len(T)-1):
    if T[i] =="?":
        if T[i-1] =="P":
            T[i] ="D"
        if T[i-1] =="D" and T[i+1] =="D":
            T[i] ="P"
        if T[i-1] =="D" and T[i+1] =="P":
            T[i] ="D"
        if T[i-1] =="D" and T[i+1] =="?":
            T[i] ="P"

if T[-1] =="?":
    T[-1] ="D"

print("".join(T))

Buggy submission (verdict: Runtime Error):
# 初期入力
import sys
input = sys.stdin.readline
T =list(input().strip())
if T[0] =="?":
    if T[1] =="?":
        T[0] ="P"
        T[1] ="D"
    elif T[1] =="D":
        T[0] ="P"
    else:
        T[0] ="D"


for i in range(1,len(T)-1):
    if T[i] =="?":
        if T[i-1] =="P":
            T[i] ="D"
        if T[i-1] =="D" and T[i+1] =="D":
            T[i] ="P"
        if T[i-1] =="D" and T[i+1] =="P":
            T[i] ="D"
        if T[i-1] =="D" and T[i+1] =="?":
            T[i] ="P"

if T[-1] =="?":
    T[-1] ="D"

print("".join(T))

Buggy submission (verdict: Runtime Error):
# 初期入力
import sys
input = sys.stdin.readline
T =list(input().strip())
if T[0] =="?":
    if T[1] =="?":
        T[0:2] ="PD"
    elif T[1] =="D":
        T[0] ="P"
    else:
        T[0] ="D"


for i in range(1,len(T)-1):
    if T[i] =="?":
        if T[i-1] =="P":
            T[i] ="D"
        if T[i-1] =="D" and T[i+1] =="D":
            T[i] ="P"
        if T[i-1] =="D" and T[i+1] =="P":
            T[i] ="D"
        if T[i-1] =="D" and T[i+1] =="?":
            T[i] ="P"

if T[-1] =="?":
    T[-1] ="D"

print("".join(T))

Buggy submission (verdict: Runtime Error):
# 初期入力
import sys
input = sys.stdin.readline
T =list(input().strip())
if T[0] =="?":
    if T[1] =="?":
        T[0:2] ="PD"
    elif T[1] =="D":
        T[0] ="P"
    else:
        T[0] ="D"


for i in range(1,len(T)-1):
    if T[i] =="?":
        if T[i-1] =="P":
            T[i] ="D"
        if T[i-1] =="D" and T[i+1] =="D":
            T[i] ="P"
        if T[i-1] =="D" and T[i+1] =="P":
            T[i] ="D"
        if T[i-1] =="D" and T[i+1] =="?":
            T[i:i+2] ="PD"

if T[-1] =="?":
    T[-1] ="D"

print("".join(T))
Problem p02678 (python)

Fixed submission:

from collections import deque
import sys
input = sys.stdin.readline
N,M = (int(x) for x in input().split())
connection ={i:set() for i in range(1,N+1)}

#構造入力
for i in range(1,M+1):
    a,b = (int(x) for x in input().split())
    connection[a].add(b)
    connection[b].add(a)

#幅優先探索
dq =deque()
dq.append(1)
parent ={i:-1 for i in range(1,N+1)} #1につながっている＝答え
parent[1] =0
while dq:
    now =dq.popleft()
    for next in connection[now]:
        if parent[next] !=-1:
            continue
        else:
            parent[next] =now
            dq.append(next)
if -1 not in parent.values():
    del parent[1]
    print("Yes")
    print(*parent.values(),sep="\n")

Buggy submission (verdict: Runtime Error):
from collections import deque
N,Q = (int(x) for x in input().split())
connection ={i:[] for i in range(1,N+1)}
#木の構造
for i in range(1,N):
    a,b = (int(x) for x in input().split())
    connection[a].append(b)
    connection[b].append(a)

#各頂点のポイント入力
point ={i:0 for i in range(1,N+1)}
for i in range(1,Q+1):
    p,x = (int(x) for x in input().split())
    point[p] =x

#深さ優先探索
dq =deque()
dq.append(1)
passed ={i:0 for i in range(1,N+1)} #各頂点を通過チェック、０は未通過
while dq:
    now =dq.pop()
    passed[now] =1
    for next in connection[now]:
        if passed[next] ==1:
            continue
        point[next] +=point[now]
        dq.append(next)
        #print(next,end=" ")
print(*point.values())