Harryxun/testdata huggingface dataset:
Buggy python submission (verdict: Runtime Error):
from fractions import gcd

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

s = input()
t = input()

# accept
# a c p
# a  e

# 最小公倍数。被ったらNG
l = n * m // gcd(n, m)
x = [None] * l
for i, c in enumerate(s):
    if i*l//n >= l:
        break
    x[i*l//n] = c

for i, c in enumerate(t):
    if i*l//m >= l:
        break
    
    a = x[i*l//m]
    if a is None:
        continue
    elif a != c:
        print(-1)
        exit()

print(l)


Fixed submission:
from fractions import gcd

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

s = input()
t = input()

# accept
# a c p
# a  e

g = gcd(n, m)
a = n // g
b = m // g
for i in range(g):
    if s[i*a] != t[i*b]:
        print(-1)
        exit()

print(n*m//g)

Buggy python submission (verdict: Runtime Error):
from fractions import gcd

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

s = input()
t = input()

# accept
# a c p
# a  e

# 最小公倍数。被ったらNG
l = n * m // gcd(n, m)
x = [None] * (n*m)
for i, c in enumerate(s):
    x[i*l//n] = c

for i, c in enumerate(t):
    a = x[i*l//m]
    if a is None:
        continue
    elif a != c:
        print(-1)
        exit()

print(l)


Fixed submission:
from fractions import gcd

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

s = input()
t = input()

# accept
# a c p
# a  e

g = gcd(n, m)
a = n // g
b = m // g
for i in range(g):
    if s[i*a] != t[i*b]:
        print(-1)
        exit()

print(n*m//g)

Buggy python submission (verdict: Runtime Error):
from fractions import gcd

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

s = input()
t = input()

# accept
# a c p
# a  e

# 最小公倍数。被ったらNG
l = n * m // gcd(n, m)
x = [None] * l
for i, c in enumerate(s):
    x[i*l//n] = c

for i, c in enumerate(t):
    a = x[i*l//m]
    if a is None:
        continue
    elif a != c:
        print(-1)
        exit()

print(l)


Fixed submission:
from fractions import gcd

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

s = input()
t = input()

# accept
# a c p
# a  e

g = gcd(n, m)
a = n // g
b = m // g
for i in range(g):
    if s[i*a] != t[i*b]:
        print(-1)
        exit()

print(n*m//g)
Buggy python submission (verdict: Runtime Error):
N, M = list(map(int,input().split()))

def divisor(n):
    if n == 1:
        return 1
    
    ans = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            ans.append(i)
            if n % n//i == 0:
                ans.append(n//i)

    ans.sort()
    return ans

d = divisor(M)
ans = 1
for x in d:
    m = M
    m -= x * (N - 1)
    if m > 0 and m % x == 0:
        ans = x

print(ans)


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

def divisor(n):
    res = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            res.append(i)
            if n % n//i == 0:
                res.append(n//i)

    res.sort()
    return res

d = divisor(M)
ans = 1
for x in d:
    m = M
    m -= x * (N - 1)
    if m > 0 and m % x == 0:
        ans = x

print(ans)

Buggy python submission (verdict: Runtime Error):
from fractions import gcd

def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return [i for i in range(n + 1) if is_prime[i]]

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

prime = reversed(primes(m))

for p in prime:
    x = m - p
    if gcd(x, n-1) % p == 0:
        print(p)
        exit()

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

def divisor(n):
    res = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            res.append(i)
            if n % n//i == 0:
                res.append(n//i)

    res.sort()
    return res

d = divisor(M)
ans = 1
for x in d:
    m = M
    m -= x * (N - 1)
    if m > 0 and m % x == 0:
        ans = x

print(ans)
Buggy python submission (verdict: Runtime Error):
s = input()
k = int(input())

notone = 101
for i, n in enumerate(s):
    if n != "1":
        notone = int(n)
        notonei = i
        break

if k < notonei:
    print(1)
else:
    print(notone)

Fixed submission:
s = input()
k = int(input())

notone = 1
notonei = 101
for i, n in enumerate(s):
    if n != "1":
        notone = int(n)
        notonei = i
        break

if k <= notonei:
    print(1)
else:
    print(notone)
Buggy python submission (verdict: Runtime Error):
import sys
# input = sys.stdin.readline

def main():
    N = int(input())
    S = input()
    
    for i in range(1, N-1):
        left = set(S[:i])
        right = set(S[i:])

        yield len(left & right)


print(max(main()))

Fixed submission:
import sys
# input = sys.stdin.readline

def main():
    N = int(input())
    S = input()
    
    for i in range(N):
        left = set(S[:i])
        right = set(S[i:])

        yield len(left & right)


print(max(main()))
Buggy python submission (verdict: Time Limit Exceeded):
import math
import sys
from functools import reduce
input = sys.stdin.readline

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

    for i in range(A, B+1):
        if i - A < K or B - i < K:
            print(i)

main()

Fixed submission:
a, b, k = map(int, input().split())

def it():
    for i in range(a, min(a+k, b)):
        yield i

    for i in range(max(b-k+1, a), b+1):
        yield i

for i in sorted(set(it())):
    print(i)
Buggy python submission (verdict: Runtime Error):
from itertools import product
a,b,c,d=list(input())
for o,p,q in product("-+",repeat=3):
    if eval(a+o+b+p+c+q+d)==7:
        print(a+o+b+p+c+q+d+"=7")
        break

Fixed submission:
a, b, c = sorted(map(int, input().split()))

diff1 = c - b
a += diff1
diff2 = c - a
if diff2 % 2 == 0:
    diff2 //= 2
else:
    diff2 += 1
    diff2 //= 2
    diff2 += 1

print(diff1 + diff2)
Buggy python submission (verdict: Runtime Error):
import sys
input = sys.stdin.readline

X = 0
D = 0

def loop():
    i=1
    a = int(input())
    while i*a+1 <= D:
      	yield 1
        i += 1

def readlines():
    global X, D
    N = int(input())
    D, X = map(int, input().split())
    for _ in range(N):
        yield 1+sum(loop())

def main():
    return sum(readlines()) + X
	
if __name__ == "__main__":
    print(main())


Fixed submission:
import sys
input = sys.stdin.readline

X = 0
D = 0

def loop():
    i=1
    a = int(input())
    while True:
        if i*a+1 <= D:
            yield 1
        else:
            break
        i += 1

def readlines():
    global X, D
    N = int(input())
    D, X = map(int, input().split())
    for _ in range(N):
        yield 1+sum(loop())

def main():
    return sum(readlines()) + X
	
if __name__ == "__main__":
    print(main())
Buggy python submission (verdict: Runtime Error):
import sys
#input = sys.stdin.readline
from collections import deque

H, W = map(int, input().split())

initial = 0
grid = []
for _ in range(H):
    row = input()
    initial += row.count("#")
    grid.append(row)

def bfs():
    dire = [(1,0),(0,1),(-1,0),(0,-1)]
    q = deque()
    q.append((0, 0, 1))
    explored = set()
    explored.add((0, 0))
    while q:
        y, x, count = q.popleft()
        for h, w in dire:
            yh = y + h
            xw = x + w
            if yh < 0 or yh >= H or xw < 0 or xw >= W or grid[yh][xw] == "#" or (yh, xw) in explored:
                continue
            
            if (yh, xw) == (H-1, W-1):
                return count+1

            explored.add((yh, xw))
            q.append((yh, xw, count+1))

path_count = bfs()

print(H*W - path_count - initial)

            
            

Fixed submission:
import sys
#input = sys.stdin.readline
from collections import deque

H, W = map(int, input().split())

initial = 0
grid = []
for _ in range(H):
    row = input()
    initial += row.count("#")
    grid.append(row)

def bfs():
    dire = [(1,0),(0,1),(-1,0),(0,-1)]
    q = deque()
    q.append((0, 0, 1))
    explored = set()
    explored.add((0, 0))
    while q:
        y, x, count = q.popleft()
        for h, w in dire:
            yh = y + h
            xw = x + w
            if yh < 0 or yh >= H or xw < 0 or xw >= W or grid[yh][xw] == "#" or (yh, xw) in explored:
                continue
            
            if (yh, xw) == (H-1, W-1):
                return count+1

            explored.add((yh, xw))
            q.append((yh, xw, count+1))

    return -1

path_count = bfs()

if path_count == -1:
    print(-1)
else:
    print(H*W - path_count - initial)
Buggy python submission (verdict: Runtime Error):
from collections import deque
import sys
input = sys.stdin.readline
import bisect as bi
from operator import mul
from functools import reduce
import math
from itertools import accumulate

def readlines(n):
    for _ in range(n):
        a, b = map(int, input().split())
        yield a, b

def prime(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    return is_prime

def main():
    q = int(input())
    is_prime = prime(100)

    def p(total, x):
        return total + (1 if is_prime[x] and is_prime[(x+1)//2] else 0)

    cumsum = list(accumulate(range(100), p))
    for l, r in readlines(q):
        print(cumsum[r] - cumsum[l-1])


main()


Fixed submission:
from collections import deque
import sys
input = sys.stdin.readline
import bisect as bi
from operator import mul
from functools import reduce
import math
from itertools import accumulate

def readlines(n):
    for _ in range(n):
        a, b = map(int, input().split())
        yield a, b

def prime(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]:
            continue
        for j in range(i*2, n+1, i):
            is_prime[j] = False
    return is_prime

def main():
    q = int(input())
    is_prime = prime(10**5)

    def p(total, x):
        return total + (1 if is_prime[x] and is_prime[(x+1)//2] else 0)

    cumsum = list(accumulate(range(10**5), p))
    for l, r in readlines(q):
        print(cumsum[r] - cumsum[l-1])


main()
Buggy python submission (verdict: Time Limit Exceeded):
def main():
    n = int(input())
    b = []
    for a in map(int, input().split()):
        b.append(str(a))
        b.reverse()

    print(" ".join(b))

main()

Fixed submission:
from collections import deque

def main():
    input()
    A = list(enumerate(input().split()))
    size = len(A)
    b = deque()
    for i, a in A:
        if i % 2 == 0:
            if size % 2 == 0:
                b.append(a)
            else:
                b.appendleft(a)    
        else:
            if size % 2 == 0:
                b.appendleft(a)
            else:
                b.append(a)

    print(" ".join(list(b)))

main()
Buggy python submission (verdict: Runtime Error):
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
asum = [0]*(n+1)
bsum = [0]*(m+1)
for i in range(n):
	asum[i+1] = a[i] + asum[i]
for j in range(m): 
	bsum[i+1] = b[j] + bsum[j]
j = m
res = 0
for i in range(n+1):
	if asum[i] > k:
		break
	while asum[i] + bsum[j] > k:
		j-=1
	res = max(res,i+j)
print(res) 



Fixed submission:
n,m,k = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
asum = [0]*(n+1)
bsum = [0]*(m+1)
for i in range(n):
	asum[i+1] = a[i] + asum[i]
for j in range(m): 
	bsum[j+1] = b[j] + bsum[j]
j = m
res = 0
for i in range(n+1):
	if asum[i] > k:
		break
	while asum[i] + bsum[j] > k:
		j-=1
	res = max(res,i+j)
print(res)
Buggy python submission (verdict: Time Limit Exceeded):
from math import *
from collections import defaultdict
GLOBAL = {}
def roots(n):
	res = set()
	for i in range(1,int(sqrt(n))+1):
		if n%i == 0:
			res.add(i)
			res.add(n//i)
	return len(res)

n = int(input())
cnt = 0
for i in range(1,n+1):
	try:
		cnt+=i*GLOBAL[i]
	except:
		GLOBAL[i]=roots(i)
		cnt+=i*GLOBAL[i]
print(cnt)


Fixed submission:
from math import *
from collections import defaultdict
GLOBAL = {}
def roots(n):
	res = set()
	for i in range(1,int(sqrt(n))+1):
		if n%i == 0:
			res.add(i)
			res.add(n//i)
	return len(res)

n = int(input())
cnt = 0
for i in range(1,n+1):
	y = n//i
	cnt+=((y)*(y+1)*(i))//2
print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
def fun(d):
	cnt = 0
	for i in d:
		cnt+= i*d[i]
	return cnt

from collections import defaultdict
d = defaultdict(int)
n = int(input())
A = list(map(int,input().split()))
for i in range(n):
	d[A[i]]+=1
q = int(input())
for i in range(q):
	b,c = map(int,input().split())
	if b in d:
		d[c]+=d[b]
		d[b]=0
	print(fun(d))



Fixed submission:
def fun(d):
	cnt = 0
	for i in d:
		cnt+= i*d[i]
	return cnt

from collections import defaultdict
d = defaultdict(int)
n = int(input())
A = list(map(int,input().split()))
for i in range(n):
	d[A[i]]+=1
q = int(input())
cnt = sum(A)
for i in range(q):
	b,c = map(int,input().split())
	if b in d:
		cnt+=(-b*d[b] + c*d[b])
		d[c]+=d[b]
		d[b]=0
		#print(cnt,d)
	print(cnt)
Buggy python submission (verdict: Runtime Error):
n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n+1):
	for x in [1,-1]:
		y = n + x*i
		if y not in a:
			print(y)
			exit(1)

Fixed submission:
n,k = map(int,input().split())
a = list(map(int,input().split()))
for i in range(n+1):
	for x in [-1,+1]:
		y = n + x*i
		if y not in a:
			print(y)
			exit(0)
Buggy python submission (verdict: Runtime Error):
a,b = map(str,input().split())
print(b+c)


Fixed submission:
a,b = map(str,input().split())
print(b+a)
Buggy python submission (verdict: Time Limit Exceeded):
a,b,k = map(int,input().split())
for i in range(k):
	if a - 1 >= 0:
		a = a-1
	elif b-1 >= 0:
		b = b-1
print(a,b)


Fixed submission:
a,b,k = map(int,input().split())
if k <= a:
	print(a-k,b)
elif k <= a+b:
	print(0,b-(k-a))
else:
	print(0,0)
Buggy python submission (verdict: Runtime Error):
S = input()
Slist = list(S)
res = 0
for i in Slist:
  res += int(i)
print(int(S) % res = 0)

Fixed submission:
S = int(input())
Slist = list(str(S))
res = 0
for i in Slist:
  res += int(i)
if S % res == 0:
  print("Yes")
else:
  print("No")
Buggy python submission (verdict: Runtime Error):
str = input()
flg=0
for n in range(0,len(str)-2):
  if(str[n]==str[n+1]):
    print(n+1,n+2)
    flg =1
    break
  elif (str[n]==str[n+2]):
    print(n+1,n+3)
    flg=1
    break
if flg =0:
  print(-1,-1)

Fixed submission:
str = input()
flg=0
for n in range(0,len(str)-2):
  if(str[n]==str[n+1]):
    print(n+1,n+2)
    flg =1
    break
  elif (str[n]==str[n+2]):
    print(n+1,n+3)
    flg=1
    break
if flg ==0:
  if str[len(str)-2]== str[len(str)-1]:
    print(len(str)-1,len(str))
  else:
    print(-1,-1)
Buggy python submission (verdict: Time Limit Exceeded):
n,k,q = map(int,input().split())

a = [int(input()) for i in range(q)]

m = [k] * n

for c in a :
    for e in range(n) :
        if(not(c-1 == e)) :
            m[e] -= 1

for j in range(n) :
    if(m[j] > 0) :
        print('Yes')
    else :
        print('No')

Fixed submission:
n,k,q = map(int,input().split())

a = [int(input()) for i in range(q)]
m = [k-q] * n

for c in a :
    m[c-1] += 1

for j in range(n) :
    if(m[j] > 0) :
        print('Yes')
    else :
        print('No')
Buggy python submission (verdict: Runtime Error):
n = int(input())

print(pow(n, 3)

Fixed submission:

n = int(input())

print(pow(n, 3))
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())
h = [int(x) for x in input().split(' ')]

a = 0
for c in range(n) :
    cnt = 0
    z = h[c]
    for d in range(c+1,n) :
        if (z >= h[d]) :
            cnt += 1
            z = h[d]
        else :
            break
    if a < cnt :
        a = cnt

print(a)

Fixed submission:
n = int(input())
h = [int(x) for x in input().split(' ')]

cnt = 0
a = 0
for c in range(n-1) :
    if (h[c] >= h[c+1]) :
        cnt += 1
    else :
        if a < cnt :
            a = cnt
        cnt = 0

if a < cnt :
    a = cnt


print(a)
Buggy python submission (verdict: Time Limit Exceeded):
n = int(input())

cnt = 0

for c in range(n) :
    cnt += c
print(cnt)

Fixed submission:
n = int(input())

cnt = 0

if (n-1)%2 == 0 :
    cnt = ((n-1)//2) * (n)
else :
    cnt = ((n-1)//2) * (n) + n//2

print(cnt)
Buggy python submission (verdict: Time Limit Exceeded):
s = (input())
l = len(s)
c = 0
ans = [0] * l
answk = [1] * l

for x in range(10000) :
    ans = [0] * l

    for c in range(l) :
        if s[c] == 'R':
            ans[c+1] = ans[c+1] + answk[c]
        elif s[c] == 'L':
            ans[c-1] = ans[c-1] + answk[c]

    answk = ans.copy()

#print(ans)
print(str(ans).replace(',','').replace('[','').replace(']',''))

Fixed submission:

s = (input())
l = len(s)
c = 0
ans = [0] * l
answk = [1] * l
cnt = 0
for c in range(l) :
    if s[c] == 'R':
        cnt += 1
    elif s[c] == 'L':
        ans[c-1] += cnt // 2 + cnt % 2
        ans[c] += cnt // 2
        cnt = 0
    

for d in range(l-1,-1,-1) :
    if s[d] == 'L':
        cnt += 1
    elif s[d] == 'R':
        ans[d+1] += cnt // 2 + cnt % 2
        ans[d] += cnt // 2
        cnt = 0

#print(ans)
print(str(ans).replace(',','').replace('[','').replace(']',''))
Buggy python submission (verdict: Runtime Error):
def yo():
    l,r = map(int,input().split())

    a = l*r%2019
    for i in range(l,r) :
        for j in range(i+1,r+1):
            ij = i*j%2019
 
            if(ij==0) :
                return a

            if (a > ij) :
                a = ij


    return a



print(yo())

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

if( a*n < b ) :
    print(a*n)
else :
    print(b)
Buggy python submission (verdict: Time Limit Exceeded):
def yo():
    l,r = map(int,input().split())

    a = l*r%2019
    for i in range(l,r) :
        for j in range(i+1,r+1):
            if (a > i*j%2019) :
                a = i*j%2019
                if(a==0) :
                    return a

    return a



print(yo())

Fixed submission:
def yo():
    l,r = map(int,input().split())

    a = l*r%2019
    for i in range(l,r) :
        for j in range(i+1,r+1):
            ij = i*j%2019
            
            if (a > ij) :
                a = ij

            if(a==0) :
                return a

    return a



print(yo())

Buggy python submission (verdict: Time Limit Exceeded):
l,r = map(int,input().split())

a = l*r%2019
for i in range(l,r) :
    for j in range(i+1,r+1):
        if (a > i*j%2019) :
            a = i*j%2019


print(a)

Fixed submission:
def yo():
    l,r = map(int,input().split())

    a = l*r%2019
    for i in range(l,r) :
        for j in range(i+1,r+1):
            ij = i*j%2019
            
            if (a > ij) :
                a = ij

            if(a==0) :
                return a

    return a



print(yo())
Buggy python submission (verdict: Runtime Error):
w,h,x,y = map(int,input().split())

if(2*x == w and 2*y ==h) :
    ff = 1
else :
    ff = 0

print(str(w * h / 2) + " " + str(ff))



Fixed submission:
x,a = map(int,input().split())
if ( x < a ) :
    print(0)
else :
    print(10)

Buggy python submission (verdict: Runtime Error):
w,h,x,y = map(int,input().split())

hx = h * x
hx2 = h * (w-x)
wy = w * y
wy2 = w * (h-y)

if(hx > hx2) :
    d1 = hx2
else :
    d1 = hx

if(wy > wy2) :
    d2 = wy2
else :
    d2 = wy


if(d1 == d2) :
    ff = 0
else :
    ff = 0

if(d1 > d2) :
    print(str(d1) + " " + str(ff))
else :
    print(str(d2) + " " + str(ff))

Fixed submission:
x,a = map(int,input().split())
if ( x < a ) :
    print(0)
else :
    print(10)
Buggy python submission (verdict: Runtime Error):
hx = h * x
hx2 = h * (w-x)
wy = w * y
wy2 = w * (h-y)

if(hx > hx2) :
    d1 = hx2
else :
    d1 = hx

if(wy > wy2) :
    d2 = wy2
else :
    d2 = wy


if(d1 == d2) :
    ff = 1
else :
    ff = 0

if(d1 > d2) :
    print(str(d1) + " " + str(ff))
else :
    print(str(d2) + " " + str(ff))

Fixed submission:
w,h,x,y = map(int,input().split())

if(2*x == w and 2*y ==h) :
    ff = 1
else :
    ff = 0

print(str(w * h / 2) + " " + str(ff))
Buggy python submission (verdict: Runtime Error):
a, v = map(int,input().split())
b, w = map(int,input().split())
t =int(input())

s = abs(b-a)
y = (v-w)

if y <= 0:
    print('NO')
else:
    m = s % y
    u = s //y
    if m == 0 and u <= t
            print('YES')
    else:
        print('NO') 

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

s = abs(b-a)
y = (v-w)

if y <= 0:
    print('NO')
else:
    m = s % y
    u = s //y
    if m == 0 and u <= t:
            print('YES')
    elif m != 0 and u + 1 <= t:
            print('YES')
    else:
        print('NO')
Buggy python submission (verdict: Time Limit Exceeded):
import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)
n = int(input())
a = list(map(int,input().split()))
ans = int(prod(a))
print(ans if ans <= 10**18 else -1)

Fixed submission:
import functools
import operator
prod = functools.partial(functools.reduce, operator.mul)
n = int(input())
a = list(map(int,input().split()))
if 0 in a:
    print(0)
    exit()
ans = a[0]
for i in range(1, n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()
    
print(ans)
Buggy python submission (verdict: Runtime Error):
t = input()
m=len(t)
s = ''
if t[0] =='?':
    if t[1] =='D':
        s= s+'P'
    else:
        s= s+'D'
for i in range(1, m-1):
    if t[i] == 'P' or t[i] == 'D':
        s = s + t[i]
    elif t[i] == '?' and t[i-1] =='P' :
        s = s + 'D'
    elif t[i] == '?' and t[i +1] == 'D' :
        s = s + 'P'
    else:
        s = s + 'D'
if t[m-1] =='?':
    s = s +'D'
else:
    s = s + t[-1]

print(s)

Fixed submission:
t = input()
m=len(t)
s = ''
for i in range(len(t)):
    if t[i] == 'P' or t[i] == 'D':
        s = s + t[i]
         
    if t[i] =='?':
        s = s+'D'
print(s)

Buggy python submission (verdict: Runtime Error):
t = input()
s = ''
for i in range(len(t)):
    if t[i] == 'P' or t[i] == 'D':
        s = s + t[i]
    elif t[i] == '?' and t[i-1] =='P':
        s = s + 'D'
    elif t[i] == '?' and t[i +1] == 'D':
        s = s + 'P'
    else:
        s = s + 'D'
print(s)

Fixed submission:
t = input()
m=len(t)
s = ''
for i in range(len(t)):
    if t[i] == 'P' or t[i] == 'D':
        s = s + t[i]
         
    if t[i] =='?':
        s = s+'D'
print(s)