qyliang/CodeNanoFix huggingface dataset:
Buggy code:
Sp = input()
T = input()

if len(T) > len(Sp):
	print("UNRESTORABLE")
	exit()
	
oklist = []
for i in range(len(Sp) - len(T), -1, -1):
	for j in range(len(T)):
		if Sp[i + j] != "?" and Sp[i + j] != T[j]:
			break
	else:
		print(i)
		okpre = ["a" if Sp[k] == "?" else Sp[k] for k in range(i)]
		oksuf = ["a" if Sp[k] == "?" else Sp[k] for k in range(i + len(T), len(Sp))] 
		oklist.append("".join(okpre) + T + "".join(oksuf))

if oklist:
	print(min(oklist))
else:
	print("UNRESTORABLE")

Fixed code:
Sp = input()
T = input()

if len(T) > len(Sp):
	print("UNRESTORABLE")
	exit()
	
oklist = []
for i in range(len(Sp) - len(T), -1, -1):
	for j in range(len(T)):
		if Sp[i + j] != "?" and Sp[i + j] != T[j]:
			break
	else:
		okpre = ["a" if Sp[k] == "?" else Sp[k] for k in range(i)]
		oksuf = ["a" if Sp[k] == "?" else Sp[k] for k in range(i + len(T), len(Sp))] 
		oklist.append("".join(okpre) + T + "".join(oksuf))

if oklist:
	print(min(oklist))
else:
	print("UNRESTORABLE")
Buggy code:
S = input()
T = input()

LEN_S = len(S)
LEN_T = len(T)

if LEN_S < LEN_T:
  print('UNRESTORABLE')
  exit()

def isEquals(s):
  for i in range(LEN_T):
    if T[i] == s[i] or s[i] == '?':
      pass
    else:
      return False
  return True

answers = []
for i in range(LEN_S - LEN_T+1):
  if isEquals(S[i:i+LEN_T]):
    text = S[:i] + T + S[i+LEN_T+1:]
    answers.append(text.replace('?', 'a'))
  else:
    pass

print(answers)

if 0 < len(answers):
  answers = sorted(answers)
  print(answers[0])
  
else:
  print('UNRESTORABLE')

Fixed code:
S = input()
T = input()

LEN_S = len(S)
LEN_T = len(T)

if LEN_S < LEN_T:
  print('UNRESTORABLE')
  exit()

def isEquals(s):
  for i in range(LEN_T):
    if T[i] == s[i] or s[i] == '?':
      pass
    else:
      return False
  return True

answers = []
for i in range(LEN_S - LEN_T+1):
  if isEquals(S[i:i+LEN_T]):
    text = S[:i].replace('?', 'a') + T + S[i+LEN_T:].replace('?', 'a')
    answers.append(text)
  else:
    pass

if 0 < len(answers):
  answers = sorted(answers)
  print(answers[0])
  
else:
  print('UNRESTORABLE')
Buggy code:
s = input()
t = input()
n = len(s)
m = len(t)
ans = []
for i in range(n-m+1):
    flag = True
    for j in range(m):
        if s[i+j]!="?" and s[i+j]!=t[j]:
            flag = False
            break
    if flag:
        tmp = (s[:i]+t+s[(i+m):]).raplace("?","a")
        ans.append(tmp)
ans.sort()

if ans:
    print(ans[0])
else:
    print("UNRESTORABLE")

Fixed code:
s = input()
t = input()
n = len(s)
m = len(t)
ans = []
for i in range(n-m+1):
    flag = True
    for j in range(m):
        if s[i+j]!="?" and s[i+j]!=t[j]:
            flag = False
            break
    if flag:
        tmp = (s[:i] + t + s[(i+m):])
        a = []
        for j in range(n):
            if tmp[j]=="?":
                a.append("a")
            else:
                a.append(tmp[j])
        tmp = "".join(a)
        ans.append(tmp)

ans.sort()

if len(ans)>0:
    print(ans[0])
else:
    print("UNRESTORABLE")
Buggy code:
s = input()[::-1]
t = input()[::-1]
for i,c in enumerate(s):
  if (c == t[0] or c == '?') and (i+len(t) < len(s)-1):
    for j in range(len(t)):
      if t[j] != s[i+j] and s[i+j] != '?':
        break
    else:
      for j in range(len(t)):
        s[i+j] =  t[j]
      print(s.replace('?', 'a')[::-1])
      break
else:
  print('UNRESTORABLE')



Fixed code:
s = input()[::-1]
t = input()[::-1]
for i,c in enumerate(s):
  if (c == t[0] or c == '?') and (i+len(t) < len(s)+1):
    for j in range(len(t)):
      if t[j] != s[i+j] and s[i+j] != '?':
        break
    else:
      str_list = list(s)
      for j in range(len(t)):
        str_list[i+j] =  t[j]
      s = ''.join(str_list)
      print(s.replace('?', 'a')[::-1])
      break
else:
  print('UNRESTORABLE')
Buggy code:
S = input()
T = input()

ls = len(S)
lt = len(T)

for i in range(ls-lt+1):
    for j in range(lt):
        if S[i] != "?" and S[i] != T[j]:
            break
    else:
       left = i

ans = S[:i]+T+S[i+lt:]
print(ans.replace("?","a"))

Fixed code:
S = input()
T = input()

ls = len(S)
lt = len(T)
left = -1

for i in range(ls-lt+1):
    for j in range(lt):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break
    else:
       left = i
if left == -1:
    ans = "UNRESTORABLE"
else:
    ans = S[:left]+T+S[left+lt:]
    ans = ans.replace("?", "a")
print(ans)
Buggy code:
import sys
input = sys.stdin.readline


def read():
    S = input().strip()
    T = input().strip()
    return S, T


def solve(S, T, INF = 100000):
    S = '.' + S
    T = '.' + T
    dp = [[INF for j in range(len(T))] for i in range(len(S))]
    
    offset = -1
    for i in range(len(S)):
        dp[i][0] = 0
    for j in range(len(T)):
        dp[0][j] = 0
    for i in range(1, len(S)):
        for j in range(1, len(T)):
            if S[i] == '?' or T[j] == '?' or S[i] == T[j]:
                dp[i][j] = dp[i-1][j-1] + 1
                if dp[i][j] == len(T)-1:
                    offset = i - (len(T)-1)
            else:
                dp[i][j] = 0
    
    if offset == -1:
        return 'UNSORTABLE'
    U = [s if s != '?' else 'a' for s in S[1:]]
    for i in range(len(T)-1):
        U[offset + i] = T[i+1]
    return ''.join(U)
            

if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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


def read():
    S = input().strip()
    T = input().strip()
    return S, T


def solve(S, T, INF = 100000):
    S = '.' + S
    T = '.' + T
    dp = [[INF for j in range(len(T))] for i in range(len(S))]
    
    offset = -1
    for i in range(len(S)):
        dp[i][0] = 0
    for j in range(len(T)):
        dp[0][j] = 0
    for i in range(1, len(S)):
        for j in range(1, len(T)):
            if S[i] == '?' or T[j] == '?' or S[i] == T[j]:
                dp[i][j] = dp[i-1][j-1] + 1
                if dp[i][j] == len(T)-1:
                    offset = i - (len(T)-1)
            else:
                dp[i][j] = 0
    
    if offset == -1:
        return 'UNRESTORABLE'
    U = [s if s != '?' else 'a' for s in S[1:]]
    for i in range(len(T)-1):
        U[offset + i] = T[i+1]
    return ''.join(U)
            

if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))
Buggy code:
S = input()
T = input()
L = len(S)
K = len(T)
ans = S
flag = 0
for i in range(L-1,-1,-1):
    for j in range(K-1,-1,-1):
        a = K-1-j
        print(S[i-a],T[j])
        if i-a < 0 or (S[i-a] != "?" and S[i-a] != T[j]):
            break
    else:
        ans = ans[:i-K+1] + T + ans[i+K:]
        flag = 1
        break
if flag == 0:
    ans = "UNRESTORABLE"
print(ans.replace("?","a"))

Fixed code:
S = input()
T = input()
L = len(S)
K = len(T)
ans = S
flag = 0
for i in range(L-1,-1,-1):
    for j in range(K-1,-1,-1):
        a = K-1-j
        if i-a < 0 or (S[i-a] != "?" and S[i-a] != T[j]):
            break
    else:
        ans = ans[:i-K+1] + T + ans[i+1:]
        flag = 1
        break
if flag == 0:
    ans = "UNRESTORABLE"
print(ans.replace("?","a"))
Buggy code:
s = list(input())
t = list(input())
for i in range((len(s))-(len(t)),-1,-1):
    for j in range(len(t)):
        if s[i+j] == "?":
            continue
        if s[i+j] != t[j]:
            break
    else:
        for k in range(len(t)):
            s[i+k] = t[k]
        for l in range(len(s)):
            if s[l] == "?":
                s[l] = "a"
        print("".join(s))
else:
    print("UNRESTORABLE")

Fixed code:
s = list(input())
t = list(input())
for i in range((len(s))-(len(t)),-1,-1):
    for j in range(len(t)):
        if s[i+j] == "?":
            continue
        if s[i+j] != t[j]:
            break
    else:
        for k in range(len(t)):
            s[i+k] = t[k]
        for l in range(len(s)):
            if s[l] == "?":
                s[l] = "a"
        print("".join(s))
        break
else:
    print("UNRESTORABLE")
Buggy code:
S = "???"
T = "abc"

S_length = len(S)
T_length = len(T)

if S_length < T_length:
    print("UNRESTORABLE")
    
elif S_length == T_length:
    for i in range(T_length):
        if S[i] != "?" and S[i] != T[j]:
            break
    else:
        print(T)
    
else:
    flag = 0
    for i in range(S_length - T_length):
        for j in range(T_length):
            if S[S_length - T_length - i + j] != "?" and S[S_length - T_length - i + j] != T[j]:
                break
        else:
            flag = 1
            S = S[:S_length - T_length - i] + T + S[S_length - i:]
            break
            
    if flag == 1:
        ans = S.replace("?", "a")
        print(ans)
        
    elif flag == 0:
        print("UNRESTORABLE")

Fixed code:
S = input()
T = input()

S_length = len(S)
T_length = len(T)

if S_length < T_length:
    print("UNRESTORABLE")
    
elif S_length == T_length:
    for i in range(T_length):
        if S[i] != "?" and S[i] != T[i]:
            print("UNRESTORABLE")
            break
    else:
        print(T)
    
else:
    flag = 0
    for i in range(S_length - T_length):
        for j in range(T_length):
            if S[S_length - T_length - i + j] != "?" and S[S_length - T_length - i + j] != T[j]:
                break
        else:
            flag = 1
            S = S[:S_length - T_length - i] + T + S[S_length - i:]
            break
            
    if flag == 1:
        ans = S.replace("?", "a")
        print(ans)
        
    elif flag == 0:
        print("UNRESTORABLE")
Buggy code:
import re
S=input().replace("?", ".")
T=input()
for i in range(len(S)-len(T)-1):
    if re.match(S[i:i+len(T)], S):
        S.replace(".", "a")
        print(S[:i]+T+S[i+len(T):])
        break
else:
    print("UNRESTORABLE")

Fixed code:
import re
S=input().replace("?", ".")
T=input()
for i in range(len(S)-len(T), -1, -1):
    if re.match(S[i:i+len(T)], T):
        S = S.replace(".", "a")
        print(S[:i]+T+S[i+len(T):])
        break
else:
    print("UNRESTORABLE")
Buggy code:
hoge=input()
key=input()
ans=[]
for i in range(len(hoge)-len(key)+1):
  flag=0
  for j in range(len(key)):
    if(hoge[i+j]==key[j] or hoge[i+j]=="?"):
      flag+=1
  if(flag==len(key)):
    kari=hoge[:i]+key+hoge[i+len(key):]
    ans.append(kari.replace("?","a"))
    
ans.sort()
print(ans[0])

Fixed code:
hoge=input()
key=input()
ans=[]
for i in range(len(hoge)-len(key)+1):
  flag=0
  for j in range(len(key)):
    if(hoge[i+j]==key[j] or hoge[i+j]=="?"):
      flag+=1
  if(flag==len(key)):
    kari=hoge[:i]+key+hoge[i+len(key):]
    ans.append(kari.replace("?","a"))
    
if(len(ans)>0):
  ans.sort()
  print(ans[0])
else:
  print("UNRESTORABLE")
Buggy code:
s = list(input())
slen = len(s)
t = list(input())
tlen = len(t)
box = []
phase = 0


def check(wh, phase=1):
    if wh + phase >= slen:
        return False
    
    if s[wh + phase] == "?" or s[wh + phase] == t[phase]:
        if phase + 1 == tlen:
            return True
        return check(wh, phase + 1)
    return False


def ume(arr):
    tmp = [e for e in arr]
    for i, e in enumerate(arr):
        if e == "?":
            tmp[i] = "a"
    return tmp



for i, e in enumerate(s):
    if e == t[0]:
        print("ge")
        if check(i):
            box.append(ume(s[:i] + t + s[i + tlen:]))

if not box:
    print("UNRESTORABLE")
else:
    box.sort
    print("".join(box[0]))


Fixed code:
s = list(input())
slen = len(s)
t = list(input())
tlen = len(t)
box = []


def check(wh, phase=0):
    if wh + phase >= slen:
        return False
    if s[wh + phase] == "?" or s[wh + phase] == t[phase]:
        if phase + 1 == tlen:
            return True
        return check(wh, phase + 1)
    return False


def ume(arr):
    tmp = [e for e in arr]
    for i, e in enumerate(arr):
        if e == "?":
            tmp[i] = "a"
    return tmp



for i, e in enumerate(s):
    if check(i):
        box.append(ume(s[:i] + t + s[i + tlen:]))

if not box:
    print("UNRESTORABLE")
else:
    box.sort
    print("".join(box[-1]))
Buggy code:
s=input()
t=input()
n=len(s)
m=len(t)
ans='UNRESTORABLE'
a=[]
for i in range(n-m+1):
  if s[i]==t[0]:
    for j in range(m):
      if s[i+j]!=t[j] and s[i+j]!='?':
        break
    else:
      an=''
      for k in range(i):
        if s[k]=='?':
          an+='a'
        else:ans+=s[k]
      an+=t
      for k in range(i+m,n):
        if s[k]=='?':
          an+='a'
        else: an+=s[k]
      a.append(an)
if len(a):
  print(min(a))
else:print(ans)

Fixed code:
s=input()
t=input()
n=len(s)
m=len(t)
ans='UNRESTORABLE'
a=[]
for i in range(n-m+1):
  if s[i]==t[0] or s[i]=='?':
    for j in range(m):
      if s[i+j]!=t[j] and s[i+j]!='?':
        break
    else:
      an=list(s[:i]+t+s[i+j+1:])
      for k in range(n):
        if an[k]=='?':
          an[k]='a'
      an=''.join(an)
      a.append(an)
if len(a):
  print(min(a))
else:print(ans)
Buggy code:
s=input()
t=input()
u=''
v=[]
count=0

for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if t[j]==s[i+j] or s[i+j]=='?':
            count+=1
    if count==len(t):
        for k in range(len(s)):
            if k>=i:
                u+=t[k-i]
            elif s[k]=='?':
                u+='a'
            else:
                u+=s[k]
                    
                    
        v.append(u)
        u=''
    count=0
    
print(min(v))

Fixed code:
s=input()
t=input()
u=''
v=[]
count=0

for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if t[j]==s[i+j] or s[i+j]=='?':
            count+=1
    if count==len(t):
        for k in range(len(s)):
            if i<=k<=i+len(t)-1:
                u+=t[k-i]
            elif s[k]=='?':
                u+='a'
            else:
                u+=s[k]
                    
                    
        v.append(u)
        u=''
    count=0
if v==[]:
    print('UNRESTORABLE')
else:
    print(min(v))
Buggy code:
S = list(input())
T = list(input())
LS = len(S)
LT = len(T)
for i in range(LS - LT + 1):
    for j in range(LT):
        if S[i + j] != T[j] and S[i + j] != "?":
            break
        if j == LT - 1:
            for k in range(LT):
                S[i + k] = T[k]
            s = str(S).replace("?", "a")
            print(S)
            exit()
# S = S.replace("?", "a")
print("UNRESTORABLE")


Fixed code:
S = list(input())
T = list(input())
LS = len(S)
LT = len(T)
a = ""
for i in reversed(range(LS - LT + 1)):
    for j in range(LT):
        if S[i + j] != T[j] and S[i + j] != "?":
            break
        if j == LT - 1:
            for k in range(LT):
                S[i + k] = T[k]
            #print("".join(S))
            s = str("".join(S)).replace("?", "a")
            print(s)
            exit()
# S = S.replace("?", "a")
print("UNRESTORABLE")
Buggy code:
S = input()
T = input()

search_str = ["?" for x in range(len(T))]

last_occ = -1

for i in range(len(S)) :    
    if i < len(S) - len(T) + 1:
        ok_cnt = 0
        for j in range(len(T)) :
            if S[i + j] == T[j] or S[i + j] == "?" :
                ok_cnt += 1

        if ok_cnt == len(T) :
            print("HOGE")
            last_occ = i
            
if last_occ != -1 :
    str_tmp = S[0:last_occ] + T + S[last_occ + len(T):]
    print(str_tmp.replace("?", "a"))
else :
    print("UNRESTORABLE")

Fixed code:
S = input()
T = input()

search_str = ["?" for x in range(len(T))]

last_occ = -1

for i in range(len(S)) :    
    if i < len(S) - len(T) + 1:
        ok_cnt = 0
        for j in range(len(T)) :
            if S[i + j] == T[j] or S[i + j] == "?" :
                ok_cnt += 1

        if ok_cnt == len(T) :
            last_occ = i
            
if last_occ != -1 :
    str_tmp = S[0:last_occ] + T + S[last_occ + len(T):]
    print(str_tmp.replace("?", "a"))
else :
    print("UNRESTORABLE")
Buggy code:
=str(input())
T=str(input())
SL=len(S)
TL=len(T)
a=[]
 
for i in range(SL-TL+1):
 
    count=0
 
    for j in range(TL):
 
        if S[i+j] == '?' or S[i+j]==T[j]:
            count += 1
 
    if count==TL:
        ans = S[:i].replace('?','a')+T+S[i+TL:].replace('?','a')
        a.append(ans)
 
if len(a)==0:
    print('UNRESTORABLE')
else:
    a.sort()
    print(ans)

Fixed code:
S=str(input())
T=str(input())
SL=len(S)
TL=len(T)
a=[]
 
for i in range(SL-TL+1):
 
    count=0
 
    for j in range(TL):
 
        if S[i+j]=='?' or T[j]=='?' or S[i+j]==T[j]:
            count += 1
 
    if count==TL:
        ans = S[:i].replace('?','a')+T+S[i+TL:].replace('?','a')
        a.append(ans)
 
if len(a)==0:
    print('UNRESTORABLE')
else:
    a.sort()
    print(a[0])
Buggy code:
import sys
s = list(input())
t = list(input())
ss = "".join(s)
tt = "".join(t)
ls = []
if len(tt)>len(ss):
    print("UNRESTORABLE")
    sys.exit()
for i in range(len(ss)-len(tt)+1):
    l = s[i:i+len(tt)]
    print(l)
    for j in range(len(tt)):
        if l[j] != t[j] and l[j] != "?":
            break
        else:
            l[j] = t[j]
    else:
        l = "".join(l)
        l = "".join(s[:i]) + l + "".join(s[i+len(tt):])
        l = l.replace("?","a")
        ls.append(l)
if ls == []:
    print("UNRESTORABLE")
else:
    ls.sort()
    print(ls[0])
            
    
            


Fixed code:
import sys
s = list(input())
t = list(input())
ss = "".join(s)
tt = "".join(t)
ls = []
for i in range(len(ss)-len(tt)+1):
    l = s[i:i+len(tt)]
    for j in range(len(tt)):
        if l[j] != t[j] and l[j] != "?":
            break
        else:
            l[j] = t[j]
    else:
        l = "".join(l)
        l = "".join(s[:i]) + l + "".join(s[i+len(tt):])
        l = l.replace("?","a")
        ls.append(l)
if ls == []:
    print("UNRESTORABLE")
else:
    ls.sort()
    print(ls[0])
Buggy code:
sp = list(input())
t = list(input())
flag = False
cnt = -1
l = len(t)
for i in range(len(sp) - l+1):
    for j in range(l):
        if sp[i+j]  == t[j] or sp[i+j]  == "?":
            pass
        else:
            flag = True
    if flag:
        continue
    else:
        cnt = i
if cnt == -1:
    print("UNRESTORABLE")
else:
    for i in range(len(sp)):
        if sp[i] == "?" :
            if not cnt<= i <cnt+l:
                sp[i] ="a"
            else :
                sp[i] = t[i-cnt]
    print("".join(sp))


Fixed code:
sp = list(input())
t = list(input())
flag = False
cnt = -1
l = len(t)
for i in range(len(sp) - l+1):
    for j in range(l):
        if sp[i+j]  == t[j] or sp[i+j]  == "?":
            pass
        else:
            break
    else:
        cnt = i
if cnt == -1:
    print("UNRESTORABLE")
else:
    for i in range(len(sp)):
        if sp[i] == "?" :
            if not cnt<= i <cnt+l:
                sp[i] ="a"
            else :
                sp[i] = t[i-cnt]
    print("".join(sp))
Buggy code:
S = input()
T = input()

ans = []

for index, s in enumerate(S):
  if s == '?' or s == T[0]:
    if index+len(T)-1 > len(S)-1:
        break

    for indexs, t in enumerate(T):
      if S[index+indexs] != t and S[index+indexs] != '?':
        break
    else:
      ans.append(S[0:index]+T+S[index+len(T):])

print(ans)
if len(ans) == 0:
  print("UNRESTORABLE")
else:
  ans.sort()
  print(ans[0].replace('?', 'a'))

Fixed code:
S = input()
T = input()

ans = []

for index, s in enumerate(S):
  if s == '?' or s == T[0]:
    if index+len(T)-1 > len(S)-1:
        break

    for indexs, t in enumerate(T):
      if S[index+indexs] != t and S[index+indexs] != '?':
        break
    else:
      ans.append(S[0:index]+T+S[index+len(T):])


if len(ans) == 0:
  print("UNRESTORABLE")
else:
  ans.sort()
  print(ans[0].replace('?', 'a'))
Buggy code:
s=input()
t=input()
u=len(t)
for i in (len(s)-u,-1,-1):
    for j in range(u):
        if s[i+j]!="?" and s[i+j]!=t[j]:
            print("W")
            break
    else:
        print(((s[:i]+t)+s[u+i:]).replace("?","a"))
        break
else:
    print("UNRESTORABLE")

Fixed code:
s=input()
t=input()
u=len(t)
for i in range(len(s)-u,-1,-1):
    for j in range(u):
        if s[i+j]!="?" and s[i+j]!=t[j]:
            break
    else:
        print((s[:i]+t+s[u+i:]).replace("?","a"))
        break
else:
    print("UNRESTORABLE")
Buggy code:
S = input().strip()
N=len(S)
T = input().strip()
M=len(T)
A = []
for i in range(N-M+1):
    flag = 0
    for j in range(i,i+M):
        if S[j]=="?" or S[j]==T[j-i]:continue
        else:
            flag=1
            break
    if flag==0:
        X = list(S)
        for j in range(i,i+M):
            X[j] = T[j-i]
        for i in range(N):
            if X[i]=="?":
                X[i]="a"
        A.append(X)
if len(A)==0:
    print("UNRESTRABLE")
else:
    A = sorted(A)
    print("".join(A[0]))

Fixed code:
S = input().strip()
N=len(S)
T = input().strip()
M=len(T)
A = []
for i in range(N-M+1):
    flag = 0
    for j in range(i,i+M):
        if S[j]=="?" or S[j]==T[j-i]:continue
        else:
            flag=1
            break
    if flag==0:
        X = list(S)
        for j in range(i,i+M):
            X[j] = T[j-i]
        for i in range(N):
            if X[i]=="?":
                X[i]="a"
        A.append(X)
if len(A)==0:
    print("UNRESTORABLE")
else:
    A = sorted(A)
    print("".join(A[0]))
Buggy code:
import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
flg = False
#cnt = 0

if len(s)-len(t)+1<0:
	print("UNRESTOABLE")
    sys.exit(0)
 
for i in range(len(s)-len(t)+1):
    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j] or s[i+j] == '?':
            cnt+=1
        #print(cnt,len(t))
    if cnt == len(t):
        cnt=i
        flg = True
        #print(cnt)
        break
 
if not flg:
    print("UNRESTORABLE")
else:
    li = list(s.replace("?","a"))
    #print(li)
    for j in range(len(t)):
        #print(li[cnt+j], t[j])
        li[cnt+j] = t[j]
    print("".join(li))


Fixed code:
import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
flg = False

for i in range(len(s)-len(t)+1):
    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j] or s[i+j] == '?':
            cnt+=1
        #print(cnt,len(t))
    if cnt == len(t):
        temp=i
        flg = True
        #print(cnt)
 
if not flg:
    print("UNRESTORABLE")
else:
    li = list(s.replace("?","a"))
    #print(li)
    for j in range(len(t)):
        #print(li[cnt+j], t[j])
        li[temp+j] = t[j]
    print("".join(li))
Buggy code:
S_d,T = list(input()),list(input())

if len(S_d) < len(T):
  print("UNRESTORABLE");exit()

flag = 1
for i in range(-len(T),-len(S_d)-1,-1):
  key = 0
  for j in range(len(T)):
    if S_d[i+j]=="?" or S_d[i+j]==T[j]:
      key+=1
  if key == len(T):
    st=len(S_d)+i
    break
  else:
    st=-1

if st==-1:
  print(UNRESTORABLE)
else:
  for i in range(len(S_d)):
    if st <= i and i < st+len(T):
      print(T[i-st],end="")
    elif S_d[i]=="?":
      print("a",end="")
    else:
      print(S_d[i],end="")
      

Fixed code:
S_d,T = list(input()),list(input())

if len(S_d) < len(T):
  print("UNRESTORABLE");exit()

flag = 1
for i in range(-len(T),-len(S_d)-1,-1):
  key = 0
  for j in range(len(T)):
    if S_d[i+j]=="?" or S_d[i+j]==T[j]:
      key+=1
    else:
      break
  if key == len(T):
    st=len(S_d)+i
    break
  else:
    st=-1

if st==-1:
  print("UNRESTORABLE")
else:
  for i in range(len(S_d)):
    if st <= i and i < st+len(T):
      print(T[i-st],end="")
    elif S_d[i]=="?":
      print("a",end="")
    else:
      print(S_d[i],end="")