qyliang/CodeNanoFix huggingface dataset:
Buggy code:
from copy import deepcopy


def calc_key_str(aps_S, T):
    S = deepcopy(aps_S)

    for i in range(len(aps_S) - len(T) + 1):
        matched_flag = True
        for j in range(len(T)):
            if aps_S[-i-j-1] != T[-j-1] and aps_S[i-j] != '?':
                matched_flag = False
                continue

        if matched_flag:
            S_list = list(S)
            S_list[-i-len(T):len(S)-i] = T
            S = "".join(S_list)
            S = S.replace('?', 'a')
            print(S)
            break

    if not matched_flag:
        print('UNRESTORABLE')


def main():
    aps_S = input()
    T = input()

    if len(aps_S) < len(T):
        print('UNRESTORABLE')
    else:
        calc_key_str(aps_S, T)


if __name__ == '__main__':
    main()


Fixed code:
from copy import deepcopy


def calc_key_str(aps_S, T):
    S = deepcopy(aps_S)

    for i in range(len(aps_S) - len(T) + 1):
        matched_flag = True
        for j in range(len(T)):
            if aps_S[-i-j-1] != T[-j-1] and aps_S[-i-j-1] != '?':
                matched_flag = False
                continue

        if matched_flag:
            S_list = list(S)
            S_list[-i-len(T):len(S)-i] = T
            S = "".join(S_list)
            S = S.replace('?', 'a')
            print(S)
            break

    if not matched_flag:
        print('UNRESTORABLE')


def main():
    aps_S = input()
    T = input()

    if len(aps_S) < len(T):
        print('UNRESTORABLE')
    else:
        calc_key_str(aps_S, T)


if __name__ == '__main__':
    main()
Buggy code:
s = input()
t = list(input())
import sys
ans ='UNRESTORABLE'
for i in range(len(s)):
  S = list(s)
  if S[len(s)-len(t)-i] == t[0] or '?':
    m = int(len(s)-len(t)-i)
    for j in range(len(t)):
      if S[m+j] == t[j] or S[m+j] == '?':
        S[m+j] = t[j]
        if j == len(t)-1:
          #print(S)
          for i in range(len(S)):
            if S[i] == '?':
              S[i] = 'a'
          ans = (''.join(S))
          break
      else:
        S = list(s)
        break
print(ans)

Fixed code:
s = input()
t = list(input())
import sys
ans = []
for i in range(len(s)):
  S = list(s)
  if S[len(s)-len(t)-i] == t[0] or '?':
    m = int(len(s)-len(t)-i)
    #print(m)
    if m >= 0:
      for j in range(len(t)):
        if S[m+j] == t[j] or S[m+j] == '?':
          S[m+j] = t[j]
          if j == len(t)-1:
            #print(S)
            for i in range(len(S)):
              if S[i] == '?':
                S[i] = 'a'
            ans.append(''.join(S))
            break
        else:
          S = list(s)
          break
if ans == []:
  print('UNRESTORABLE')
else:
  ans.sort()
  print(ans[0])
Buggy code:
from itertools import permutations
import re


def main():
    s = input().replace('?', '.')
    t = input()

    for i in reversed(range(len(s) - len(t) + 1)):
        print(s[i:i + len(t)])
        if re.search(s[i:i + len(t)], t):
            result = (s[:i] + t + s[i + len(t):]).replace('.', 'a')
            print(result)
            return

    print('UNRESTORABLE ')

main()


Fixed code:
from itertools import permutations
import re


def main():
    s = input().replace('?', '.')
    t = input()

    for i in reversed(range(len(s) - len(t) + 1)):
        # print(s[i:i + len(t)])
        if re.search(s[i:i + len(t)], t):
            result = (s[:i] + t + s[i + len(t):]).replace('.', 'a')
            print(result)
            return

    print('UNRESTORABLE')

main()
Buggy code:
Sd = input()
T = input()

def check(A, B):
    for a, b in zip(A, B):
        if a != '?' and a != b:
            return False
    return True

for i in range(len(Sd) - len(T) + 1):
    if check(Sd[i:i + len(T)], T):
        print((Sd[:i] + T + Sd[i + len(T):]).replace('?', 'a'))
        break
else:
    print('UNRESTORSBLE')
        

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

def check(A, B):
    for a, b in zip(A, B):
        if a != '?' and a != b:
            return False
    return True

for i in range(len(Sd) - len(T) + 1)[::-1]:
    if check(Sd[i:i + len(T)], T):
        print((Sd[:i] + T + Sd[i + len(T):]).replace('?', 'a'))
        break
else:
    print('UNRESTORABLE')
Buggy code:
S = input()
T = input()

N = len(S)
M = len(T)

if N < M:
    print('UNRESTORABLE')
    exit()

ans = 'UNRESTORABLE'
for i in range(N-M+1):
    anss = S[:i] + T + S[i+M:]
    print(anss)
    make = 1
    anss = list(anss)
    for j in range(N):
        if anss[j] == '?':
            if S[j] == '?':
                anss[j] = 'a'
            else:
                anss[j] = S[j]
        else:
            if anss[j] != S[j] and S[j] != '?':
                make = 0
                break
    if make:
        ans = ''.join(anss)
print(ans)


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

N = len(S)
M = len(T)

if N < M:
    print('UNRESTORABLE')
    exit()

ans = 'UNRESTORABLE'
for i in range(N-M+1):
    anss = S[:i] + T + S[i+M:]
    make = 1
    anss = list(anss)
    for j in range(N):
        if anss[j] == '?':
            if S[j] == '?':
                anss[j] = 'a'
            else:
                anss[j] = S[j]
        else:
            if anss[j] != S[j] and S[j] != '?':
                make = 0
                break
    if make:
        ans = ''.join(anss)
print(ans)
Buggy code:
S = input()
T = input()
len_T = len(T)

lst = []
for x in range(len(S) - len_T + 1):
    flg = True
    s = S[x:len_T+x]    
    for idx in range(len_T):
        if s[idx] != '?' and s[idx] != T[idx]:
            flg = False
            break
    if flg:
        tmp = S[:x] + T + S[x + len_T:]
        print(tmp)
        tmp = tmp.replace('?', 'a')
        lst.append(tmp)


if len(lst) == 0:
    print('UNRESTORABLE')
else:
    print(min(lst))


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

lst = []
for x in range(len(S) - len_T + 1):
    flg = True
    s = S[x:len_T+x]    
    for idx in range(len_T):
        if s[idx] != '?' and s[idx] != T[idx]:
            flg = False
            break
    if flg:
        tmp = S[:x] + T + S[x + len_T:]
        tmp = tmp.replace('?', 'a')
        lst.append(tmp)


if len(lst) == 0:
    print('UNRESTORABLE')
else:
    print(min(lst))
Buggy code:
SS = list(input())
T = list(input())
nt = len(T)
un = 'UNRESTORABLE'
flag = False
for i in reversed(range(len(SS))):
    if i < nt-1:
        break

    for j in range(nt):
        if SS[i-j] == T[nt-1-j] or SS[i-j] == '?':
            pass
        else:
            break
    for k in range(nt):
        SS[i+1-nt+k] = T[k]
    flag = True
    break
if flag:
    for s in range(len(SS)):
        if SS[s] == '?':
            SS[s] = 'a'
    print(''.join(SS))
else:
    print(un)


Fixed code:
SS = list(input())
T = list(input())
nt = len(T)
un = 'UNRESTORABLE'
flag = False
for i in reversed(range(len(SS))):
    if i < nt-1:
        break
    flag2 = True
    for j in range(nt):
        if (SS[i-j] == T[nt-1-j] or SS[i-j] == '?') and flag2:
            continue
        else:
            flag2 = False
            break
    if flag2:
        for k in range(nt):
            SS[i+1-nt+k] = T[k]
        flag = True
        break
if flag:
    for s in range(len(SS)):
        if SS[s] == '?':
            SS[s] = 'a'
    print(''.join(SS))
else:
    print(un)
Buggy code:
S = input()
T = input()

ans = []
for i in range(len(S) - len(T) + 1):
    c = ""
    for j in range(len(T)):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break
        c += T[j]
    if len(c) == len(T):
        print(S[:i], c, S[i+len(T):])
        ans.append((S[:i] + c + S[i+len(T):]).replace("?", "a"))
print(min(ans) if ans else "UNRESTORABLE")


Fixed code:
S = input()
T = input()
ans = []
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:
        tmp = S[:i] + T + S[i+len(T):]
        ans.append(tmp.replace('?', 'a'))
if ans:
    print(ans[-1])
else:
    print("UNRESTORABLE")
Buggy code:
from math import floor
from decimal import Decimal

S = list(input())
T = list(input())

isSuccess = False

for i in reversed(range(len(S) - len(T) + 1)):
    T_str = S[i: i + len(T)]
    for j in range(len(T)):
        if T_str[j] != T[j] and T_str[j] != "?":
        break
    else:
        isSuccess = True
        S[i:i + len(T)] = T
        break
if isSuccess == False:
    print("UNRESTORABLE")
else:
    string = ",".join(S)
    string = string.replace('?', 'a')
    S = string.split(',')
    print("".join(map(str,S)))

Fixed code:
from math import floor
from decimal import Decimal

S = list(input())
T = list(input())

isSuccess = False

for i in reversed(range(len(S) - len(T) + 1)):
    T_str = S[i: i + len(T)]
    for j in range(len(T)):
        if T_str[j] != T[j] and T_str[j] != "?":
        	break
    else:
        isSuccess = True
        S[i:i + len(T)] = T
        break
if isSuccess == False:
    print("UNRESTORABLE")
else:
    string = ",".join(S)
    string = string.replace('?', 'a')
    S = string.split(',')
    print("".join(map(str,S)))
Buggy code:
s=[x for x in input()]
t=[x for x in input()]
ans=[]
for i in range(len(s)):
  cnt=0
  nowi=i
  fi=i
  for j in range(len(t)):
    if s[nowi]==t[j] or s[nowi]=="?":
      cnt+=1
    else:
      break
    if cnt==len(t):
      ans.append((s[:fi]+t+s[nowi+1:]))
    if nowi+1<=len(s)-1:
      nowi+=1
    else:
      break

A=[]
if len(ans)==0:
  print("UNRESTORABLE")
else:   
  for i in ans:
    moji=""
    for m in i:
      if m=="?":
        moji+="a"
      else:
        moji+=m
    A.append(moji)
  print(A)
  A.sort()
  print(A[0])

Fixed code:
s=[x for x in input()]
t=[x for x in input()]
ans=[]
for i in range(len(s)):
  cnt=0
  nowi=i
  fi=i
  for j in range(len(t)):
    if s[nowi]==t[j] or s[nowi]=="?":
      cnt+=1
    else:
      break
    if cnt==len(t):
      ans.append((s[:fi]+t+s[nowi+1:]))
    if nowi+1<=len(s)-1:
      nowi+=1
    else:
      break

A=[]
if len(ans)==0:
  print("UNRESTORABLE")
else:   
  for i in ans:
    moji=""
    for m in i:
      if m=="?":
        moji+="a"
      else:
        moji+=m
    A.append(moji)
  A.sort()
  print(A[0])
Buggy code:
S=input()
T=input()
ls=len(S)
lt=len(T)

ans='UNRESTORABLE'

if ls<lt:
    print(ans)
    exit()
for i in range(ls-lt,0,-1):
    c=0
    for j in range(lt):
        if T[j]==S[i+j] or S[i+j]=='?':
            continue
        else:
            c=1
            break
    if c==0:
        ans=S.replace('?','a')
        ans=ans[:i] +z T + ans[i+lt:]
print(ans)


Fixed code:
S=input()
T=input()
ls=len(S)
lt=len(T)

ans='UNRESTORABLE'

if ls<lt:
    print(ans)
    exit()
for i in range(ls-lt,-1,-1):
    c=0
    for j in range(lt):
        if T[j]==S[i+j] or S[i+j]=='?':
            continue
        else:
            c=1
            break
    if c==0:
        ans=S.replace('?','a')
        ans=ans[:i] + T + ans[i+lt:]
        break
print(ans)
Buggy code:
s=input()
t=input()
strs=[]
S=len(s)
T=len(t)
for i in range(S-T+1):
  flag=0
  for j in range(T):
    if S[i+j]=="?":
      continue
    if S[i+j]!=T[j]:
      flag=1;break
  if flag==0:
    posstr=s[:i]+t+s[i+T:]
    posstr.replace("?","a")
    strs.append(posstr)
if strs==[]:print("UNRESTORABLE")
else:print(strs[0])

Fixed code:
s=input()
t=input()
strs=[]
S=len(s)
T=len(t)
for i in range(S-T+1):
  flag=0
  for j in range(T):
    if s[i+j]=="?":
      continue
    if s[i+j]!=t[j]:
      flag=1;break
  if flag==0:
    posstr=s[:i]+t+s[i+T:]
    strs.append(posstr.replace("?","a",50))
strs.sort()
if strs==[]:print("UNRESTORABLE")
else:print(strs[0])
Buggy code:
S = list(input())[:-1]
T = list(input())[:-1]

ans_list=[]
for i in range(len(S)-len(T)+1):
    S_temp=S.copy()
    serch_S=S_temp[i:i+len(T)]
#     print(serch_S)
    count=0
    for t in range(len(T)):
        if serch_S[t] in [T[t],'?']:
#             print(serch_S[t])
            count+=1
        else:
            break
        
        if count==len(T):
            S_temp[i:i+len(T)]=T

            for s in range(len(S_temp)):
                if S_temp[s]=='?':
                    S_temp[s]='a'
                    
            S_temp_str=''
            for s_t in S_temp:
                S_temp_str+=s_t

            ans_list.append(S_temp_str)

if len(ans_list)>0:
    
    ans_list.sort()
    ans=ans_list[0]
else:
    ans='UNRESTORABLE'
    
print(ans)

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

ans_list=[]
for i in range(len(S)-len(T)+1):
    S_temp=S.copy()
    serch_S=S_temp[i:i+len(T)]
    count=0
    for t in range(len(T)):
        if serch_S[t] in [T[t],'?']:
            count+=1
        else:
            break
        
        if count==len(T):
            S_temp[i:i+len(T)]=T

            for s in range(len(S_temp)):
                if S_temp[s]=='?':
                    S_temp[s]='a'
                    
            S_temp_str=''
            for s_t in S_temp:
                S_temp_str+=s_t

            ans_list.append(S_temp_str)

if len(ans_list)>0:
    
    ans_list.sort()
    ans=ans_list[0]
else:
    ans='UNRESTORABLE'
    
print(ans)
Buggy code:
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
print(ls, lt)
if ls < lt:
    print("UNRESTORABLE")
else:
    res = []
    for i in range(ls-lt+1):
        res.append(s[i:i+lt])
    tmp = []
    for i in range(len(res)):
        flag = True
        for j in range(lt):
            if res[i][j] == t[j] or res[i][j] == '?':
                pass
            else:
                flag = False
                break
        if flag:
            tmp.append(i)
    ans = []
    for i in tmp:
        q = []
        for j in range(0, i):
            q.append(s[j])
        for j in range(0, lt):
            q.append(t[j])
        for j in range(i+lt, ls):
            q.append(s[j])
        for j in range(ls):
            if q[j] == '?':
                q[j] = 'a'
        ans.append(''.join(q))
    if ans:
        print(min(ans))
    else:
        print("UNRESTORABLE")

Fixed code:
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
if ls < lt:
    print("UNRESTORABLE")
else:
    res = []
    for i in range(ls-lt+1):
        res.append(s[i:i+lt])
    tmp = []
    for i in range(len(res)):
        flag = True
        for j in range(lt):
            if res[i][j] == t[j] or res[i][j] == '?':
                pass
            else:
                flag = False
                break
        if flag:
            tmp.append(i)
    ans = []
    for i in tmp:
        q = []
        for j in range(0, i):
            q.append(s[j])
        for j in range(0, lt):
            q.append(t[j])
        for j in range(i+lt, ls):
            q.append(s[j])
        for j in range(ls):
            if q[j] == '?':
                q[j] = 'a'
        ans.append(''.join(q))
    if ans:
        print(min(ans))
    else:
        print("UNRESTORABLE")
Buggy code:
s = input()
t = input()

ans_list = []
if t in s:
    print(s.replace('?', 'a'))
else:
    for i in range(0 , len(s) - len(t)+1)[::-1]:
        flag = True
        for j in range(len(t)):
            if s[i+j] == t[j] or s[j] == '?':
                continue
            else:
                flag = False
                break
        if flag ==  True:
            tmp = s
            tmp = tmp.replace(tmp[i : i+len(t)] , t)
            ans_list.append(tmp.replace('?', 'a'))
    if len(ans_list) == 0:
        print('UNRESTORABLE')
    else:
        ans_list.sort()
        print(ans_list[0])

Fixed code:
s = input()
t = input()

ans_list = []
if t in s:
    print(s.replace('?', 'a'))
else:
    for i in range(0 , len(s) - len(t)+1):
        flag = True
        for j in range(i , i + len(t)):
            if s[j] == t[j - i] or s[j] == '?':
                continue
            else:
                flag = False
                break
        if flag ==  True:
            tmp = s
            tmp = tmp[:i] + t + tmp[i + len(t):]
            ans_list.append(tmp.replace('?', 'a'))
    if len(ans_list) == 0:
        print('UNRESTORABLE')
    else:
        ans_list.sort()
        print(ans_list[0])
Buggy code:
import re
s = input()
t = input()
s = s.replace("?",".")[::-1]
t = t[::-1]

print(s)
print(t)
print(len(s) - len(t) + 1)


for i in range(len(s) - len(t) + 1):
  if re.match(s[i:i+len(t)], t):
    print(s[i:i+len(t)])
    s = s[:i].replace(".","a") + t + s[i+len(t):].replace(".","a")
    print(s[::-1])
    break
  else:
    print("UNRESTORABLE")


Fixed code:
import re
s = input()
t = input()
 
s = s.replace("?", ".")[::-1]
t = t[::-1]
 
for i in range(len(s) - len(t) + 1):
  if re.match(s[i:i+len(t)], t):
    s = s[:i].replace(".","a") + t + s[i+len(t):].replace(".","a")
    print(s[::-1])
    break
else:
  print("UNRESTORABLE")
Buggy code:
S = input()
T = input()
res = []

ok = -1
for i in range(len(S) - len(T) + 1):
    if S[i] == T[0] or S[i] == "?":
        for j in range(len(T)):
            if S[i + j] not in ("?", T[j]):
                break
        else:
            s = S[:i] + T + S[i + len(T):]
            res.append(s.replace("?", "a"))

if res:
    print(res)
else:
    print("UNRESTORABLE")


Fixed code:
S = input()
T = input()
res = []

ok = -1
for i in range(len(S) - len(T) + 1):
    if S[i] == T[0] or S[i] == "?":
        for j in range(len(T)):
            if S[i + j] not in ("?", T[j]):
                break
        else:
            s = S[:i] + T + S[i + len(T):]
            res.append(s.replace("?", "a"))

if res:
    print(min(res))
else:
    print("UNRESTORABLE")
Buggy code:
import copy
def solve():
    S_d = list(input())
    T = list(input())

    first = 0
    end = first + len(T) - 1
    while end <= len(S_d) - 1:
        t_i = 0
        for s_i in range(first, end+1):
            if T[t_i] != S_d[s_i] and S_d[s_i] != '?':
                break
            t_i += 1
        else:
            break
        first += 1
        end += 1
    else:
        print('UNRESTORABLE')
        exit(0)
    
    ans = copy.deepcopy(S_d)
    t_i = 0
    for i in range(first, end+1):
        ans[i] = T[t_i]
        t_i += 1
    print(ans)
    
    ans = ''.join(ans).replace('?','a')
    print(ans)

if __name__ == '__main__':
    solve()

Fixed code:
import copy
def solve():
    S_d = list(input())
    T = list(input())

    end = len(S_d) - 1
    first = end - len(T) + 1
    while first >= 0:
        t_i = 0 
        for s_i in range(first, end+1):
            if T[t_i] != S_d[s_i] and S_d[s_i] != '?':
                break
            t_i += 1
        else:
            break

        first -= 1
        end -= 1

    else:
        print('UNRESTORABLE')
        exit(0)
    
    ans = copy.deepcopy(S_d)
    t_i = 0
    for i in range(first, end+1):
        ans[i] = T[t_i]
        t_i += 1
    
    ans = ''.join(ans).replace('?','a')
    print(ans)

if __name__ == '__main__':
    solve()
Buggy code:
# ABC076C
S = input()
T = input()

for i in range(len(S) - len(T) + 1):
    if S[i] == "?" or S[i] == T[0]:
        k = 1
        flag = True
        while k < len(T):
            if S[i+k] == "?":
                k += 1
            else:
                if S[i + k] == T[k]:
                    k += 1
                else:
                    flag = False
                    break
        if k == len(T) and flag == True:
            check = i

if check != -1:
    S = list(S)
    for i in range(len(T)):
        S[check + i] = T[i]
    S = "".join(S)
    ans = S.replace("?", "a")
    print(ans)
else:
    print("UNRESTORABLE")

Fixed code:
# ABC076C
S = input()
T = input()
check = -1
for i in range(len(S) - len(T) + 1):
    if S[i] == "?" or S[i] == T[0]:
        k = 1
        flag = True
        while k < len(T):
            if S[i+k] == "?":
                k += 1
            else:
                if S[i + k] == T[k]:
                    k += 1
                else:
                    flag = False
                    break
        if k == len(T) and flag == True:
            check = i

if check != -1:
    S = list(S)
    for i in range(len(T)):
        S[check + i] = T[i]
    S = "".join(S)
    ans = S.replace("?", "a")
    print(ans)
else:
    print("UNRESTORABLE")
Buggy code:
S = input()
T = input()
N = len(T)

if len(S) < N:
    print("UNRESTORABLE")
    import sys
    sys.exit()

flag = False
pos = 51
ans = ""
for i in range(len(S)-N):
    cnt = 0
    for j in range(N):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break
    if cnt == N:
        pos = i
        flag = True
if flag:
    for i in range(len(S)):
        if pos <= i and i < pos + N:
            ans += T[i-pos]
        elif S[i] == "?":
            ans += "a"
        else:
            ans += S[i]
else:
    ans = "UNRESTORABLE"
print(ans)

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

if len(S) < N:
    print("UNRESTORABLE")
    import sys
    sys.exit()

flag = False
pos = 51
ans = ""
for i in range(len(S)-N+1):
    cnt = 0
    for j in range(N):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break
    if cnt == N:
        pos = i
        flag = True
if flag:
    for i in range(len(S)):
        if pos <= i and i < pos + N:
            ans += T[i-pos]
        elif S[i] == "?":
            ans += "a"
        else:
            ans += S[i]
else:
    ans = "UNRESTORABLE"
print(ans)
Buggy code:
s = list(input())
t = list(input())

ans = []
for i in range(len(s)-len(t)+1):
    if s[i] == '?' or s[i] == t[0]:
        ok = True
        j = 1
        while j < len(t) and ok:
            if s[i+j] == '?' or s[i+j] == t[j]:
                j += 1
                continue
            else:
                ok = False
        if ok:
            f = [x for x in s]
            print(f, t)
            for j in range(len(t)):
                f[i+j] = t[j]
            f = "".join(f)
            f.replace('?', 'a')
            ans.append(f)
        if s[i] == '?':
            s[i] = 'a'
if ans:
    print(sorted(ans)[0])
else:
    print("UNRESTORABLE")


Fixed code:
s = list(input())
t = list(input())

ans = []
for i in range(len(s)-len(t)+1):
    if s[i] == '?' or s[i] == t[0]:
        ok = True
        j = 1
        while j < len(t) and ok:
            if s[i+j] == '?' or s[i+j] == t[j]:
                j += 1
                continue
            else:
                ok = False
        if ok:
            f = [x for x in s]
            for j in range(len(t)):
                f[i+j] = t[j]
            for j in range(i+1,len(s)):
                if f[j] == '?':
                    f[j] = 'a'
            f = "".join(f)
            ans.append(f)
    if s[i] == '?':
        s[i] = 'a'

if ans:
    print(sorted(ans)[0])
else:
    print("UNRESTORABLE")
Buggy code:
s = input()
t = input()

result = []
for i in range(len(s)-len(t)+1):
    temp = '?'*i + t + '?'*(len(s)-len(t)-i)
    
    ans = ''
    flag = True
    for j in range(len(s)):
        if s[j] == '?' or s[j] == temp[j]:
            ans += temp[j]
        elif s[j] != '?' and temp[j] == '?':
            ans += s[j]
        else:
            flag = False

    if flag:
        result.append(ans)

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

Fixed code:
s = input()
t = input()

result = []
for i in range(len(s)-len(t)+1):
    temp = '?'*i + t + '?'*(len(s)-len(t)-i)
    
    ans = ''
    flag = True
    for j in range(len(s)):
        if s[j] == '?' or s[j] == temp[j]:
            ans += temp[j]
        elif s[j] != '?' and temp[j] == '?':
            ans += s[j]
        else:
            flag = False

    if flag:
        result.append(ans.replace('?', 'a'))

if result:
    result.sort()
    print(result[0])
else:
    print("UNRESTORABLE")
Buggy code:
sd=input()
t=input()

n=len(sd)
m=len(t)
s=[]

for i in range(n-m,-1,-1):
    t_kamo=sd[i:i+m]
    for j in range(m+1):
        if j==m:
            print((sd[:i]+t+sd[i+m:]).replace("?","a"))
        if k_kamo[j]=="?":
            continue
        elif k_kamo[j]!=t[j]:
            break
print("UNRESTORABLE")

Fixed code:
sd=input()
t=input()

n=len(sd)
m=len(t)
s=[]

for i in range(n-m,-1,-1):
    t_kamo=sd[i:i+m]
    for j in range(m+1):
        if j==m:
            print((sd[:i]+t+sd[i+m:]).replace("?","a"))
            exit()
        if t_kamo[j]=="?":
            continue
        elif t_kamo[j]!=t[j]:
            break
print("UNRESTORABLE")