qyliang/CodeNanoFix huggingface dataset:
Buggy code:
S = input()
T = input()
Ns = len(S)
Nt = len(T)
if Ns<Nt:
   print("UNRESTORABLE")
else:
   S_merge=""
   for i in range(Ns-Nt,0,-1):
      isok = True
      # print(S[i:i+Nt], T)
      for j in range(Nt):
         if not (S[i+j] == T[j] or S[i+j]=="?"):
            isok = False
            continue
      if isok:
         # print(S[i:i+Nt], T)
         # print(S[:i]+T)
         S_merge = S[:i]+T
         continue
   if not isok:
      print("UNRESTORABLE")
   else:
      S_ans =""
      for i in range(Ns):
         if S_merge[i]=="?":
            S_ans = S_ans+'a'
         else:
            S_ans = S_ans+S_merge[i]
      print(S_ans)



Fixed code:
S = input()
T = input()
Ns = len(S)
Nt = len(T)
if Ns<Nt:
   print("UNRESTORABLE")
else:
   S_merge=""
   isok = True
   for i in range(Ns-Nt,-1,-1):
      isok = True
      # print(S[i:i+Nt], T)
      for j in range(Nt):
         if not (S[i+j] == T[j] or S[i+j]=="?"):
            isok = False
            break
      if isok:
         # if i > 0:
         S_merge = S[:i]+T+S[i+Nt:]
         # else:
         #    S_merge = T
         break
   if not isok:
      print("UNRESTORABLE")
   else:
      # print(S_merge)
      S_ans =""
      for i in range(Ns):
         if S_merge[i]=="?":
            S_ans = S_ans+'a'
         else:
            S_ans = S_ans+S_merge[i]
      print(S_ans)
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)], t):
    print(s[:i].replace('.','a')+t+s[i+len(t):].replace('.','a'))
    break
else:
  print('UNRESTOREABLE')

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

if len(s) < len(t):
    print('UNRESTORABLE') 
elif len(s) == len(t):
  cnt=0
  for i in range(len(s)):
    if s[i] == t[i]:
      cnt+=1
    elif s[i] == '?':
      cnt+=1
  if len(t)==cnt:
    print(t)
  else:
    print('UNRESTORABLE') 
else:
  flag1=0
  for j in range(len(s)):
    cnt=0
    for i in range(len(t)):
      if s[i+j]==t[i]:
        cnt+=1
      elif s[i+j]=='?':
        cnt+=1
    if cnt==len(t):
      flag1=1
      if j==0:
        s=t+s[len(t):]
      if 0 < j < len(s)-len(t)+1:
        s=s[0:j]+t+s[j+len(t):]
      if j == len(s)-len(t)+1:
        s=s[0:j]+t      
      s=s.replace('?','a')
      print(s)
    
  if flag1==0:
    print('UNRESTORABLE') 

Fixed code:
s=input()
t=input()
#print(s,t)

if len(s) < len(t):
    print('UNRESTORABLE') 
elif len(s) == len(t):
  cnt=0
  for i in range(len(s)):
    if s[i] == t[i]:
      cnt+=1
    elif s[i] == '?':
      cnt+=1
  if len(t)==cnt:
    print(t)
  else:
    print('UNRESTORABLE') 
else:
  flag1=0
  for j in range(len(s)-len(t),-1,-1):
    cnt=0
    for i in range(len(t)):
      if s[i+j]==t[i]:
        cnt+=1
      elif s[i+j]=='?':
        cnt+=1
    if cnt==len(t):
      flag1=1
      if j==0:
        s=t+s[len(t):]
      if 0 < j < len(s)-len(t)+1:
        s=s[0:j]+t+s[j+len(t):]
      if j == len(s)-len(t)+1:
        s=s[0:j]+t      
      s=s.replace('?','a')
      print(s)
    
  if flag1==0:
    print('UNRESTORABLE')
Buggy code:
s=input()
t=input()
for i in range(len(t),len(s))[::-1]:
    if s[i]==t[-1] or s[i]=="?":
        if all(s[i-j]==t[-1-j] or s[i-j]=="?" for j in range(len(t))):
            s=s.replace("?","a")
            print(s[:i-len(t)]+t+s[i+1:])
            print(i)
            exit()
print("UNRESTORABLE")

Fixed code:
s=input()
t=input()
for i in range(len(t)-1,len(s))[::-1]:
    if s[i]==t[-1] or s[i]=="?":
        if all(s[i-j]==t[-1-j] or s[i-j]=="?" for j in range(len(t))):
            s=s.replace("?","a")
            print(s[:i-len(t)+1]+t+s[i+1:])
            exit()
print("UNRESTORABLE")
Buggy code:
s = input()
t = input()

s = [x for x in s[::-1]]
t = [x for x in t[::-1]]    

for i in range(len(s)-len(t)):
  flg = False
  cnt = 0
  for j in range(i+len(t)):
    if s[i+j] == '?':
      cnt += 1
      continue
    if s[i+j] == t[j]:
      flg = True
    else:
      flg = False
      break
  if flg or cnt == len(t):
    s[i:i+len(t)] = t
  else:
    print('UNRESTORABLE')
    exit()

ans = ''
s = [x for x in s[::-1]]
for i in range(len(s)):
  if s[i] == '?':
    s[i] = 'a'
  ans += s[i]
print(ans)


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

if len(s) < len(t):
    print('UNRESTORABLE')
    exit()

s = [x for x in s[::-1]]
t = [x for x in t[::-1]]    

for i in range(len(s)-len(t)+1):
  flg = False
  cnt = 0
  for j in range(len(t)):
    if s[i+j] == '?':
      cnt += 1
      continue
    if s[i+j] == t[j]:
      flg = True
    else:
      flg = False
      break
  if flg or cnt == len(t):
    s[i:i+len(t)] = t
    flg = True
    break

if not flg:
    print('UNRESTORABLE')
    exit()

ans = ''
s = [x for x in s[::-1]]
for i in range(len(s)):
  if s[i] == '?':
    s[i] = 'a'
  ans += s[i]
print(ans)
Buggy code:
s = list(input())
t = list(input())
ans = []
ok = -1
f = -1
for i in range(len(s)-len(t)+1):
    # print(s[i])
    a = 0
    if s[i] == '?' or s[i] == t[0]:
        if f is -1:
            f=i
        for j in range(len(t)):
            # print(i,j,s[i+j],t[j])
            if s[i+j] != '?' and s[i+j] != t[j]:
                break
            a = j
        if ok == -1 and a == len(t)-1:
            ok = i
if ok == -1:
    print('UNRESTORABLE')
    exit()
else:
    for i in range(len(s)):
        if s[i] == '?':
            s[i] = 'a'
        if  ok<= i <= ok+len(t)-1:
            s[i] = t[i-ok]

print(s)


Fixed code:
s = list(input())
t = list(input())
ans = []
ok = -1
f = -1
if len(s)<len(t):
    print('UNRESTORABLE')
    exit()

for i in range(len(s)-len(t)+1):
    # print(s[i])
    a = 0
    if s[i] == '?' or s[i] == t[0]:
        if f is -1:
            f=i
        for j in range(len(t)):
            # print(i,j,s[i+j],t[j])
            if s[i+j] != '?' and s[i+j] != t[j]:
                break
            a = j
        if a == len(t)-1:
            ok = i
if ok == -1:
    print('UNRESTORABLE')
    exit()
else:
    for i in range(len(s)):
        if s[i] == '?':
            s[i] = 'a'
        if  ok<= i <= ok+len(t)-1:
            s[i] = t[i-ok]

print(''.join(s))
Buggy code:
s,y=(input() for i in range(2))
ans="{"*len(s);pa=ans
for i in range(len(s)-len(y)):
  for j in range(len(y)):
    if s[i+j]!='?' and s[i+j]!=y[j]:break
  else:ans=min(ans,s[:i].replace("?","a")+y+s[i+len(y):].replace("?","a"))
if pa==ans:print("UNRESTORABLE")
  
else:print(ans)

Fixed code:
s,y=(input() for i in range(2))
ans="{"*len(s);pa=ans
for i in range(len(s)-len(y)+1):
  for j in range(len(y)):
    if s[i+j]!='?' and s[i+j]!=y[j]:break
  else:ans=min(ans,s[:i].replace("?","a")+y+s[i+len(y):].replace("?","a"))
if pa==ans:print("UNRESTORABLE")
  
else:print(ans)
Buggy code:
S_prime = list(map(str, input()))
T = list(map(str, input()))

len_S = len(S_prime)
len_T = len(T)

un = 1

for i in reversed(range(0, len_S - len_T + 1)):
	match = 1
	for j in range(i, i + len_T):
		# print(S_prime[j], T[j - i])
		if S_prime[j] == "?": continue
		if not S_prime[j] == T[j - i]:
			match = 0
			break
	if match:
		un = 0
		# print(i)
		init = i
		break
		
if un:
	print("UNRESTORABLE")
else:
	for i in range(init, init + len_T):
		S_prime[i] = T[i - init]
	
	for i in range(len_S):
		if S_prime[i] == "?":
			S_prime[i] = "a"
	
	print(S_prime)

Fixed code:
S_prime = list(map(str, input()))
T = list(map(str, input()))

len_S = len(S_prime)
len_T = len(T)

un = 1

for i in reversed(range(0, len_S - len_T + 1)):
	match = 1
	for j in range(i, i + len_T):
		# print(S_prime[j], T[j - i])
		if S_prime[j] == "?": continue
		if not S_prime[j] == T[j - i]:
			match = 0
			break
	if match:
		un = 0
		# print(i)
		init = i
		break
		
if un:
	print("UNRESTORABLE")
else:
	for i in range(init, init + len_T):
		S_prime[i] = T[i - init]
	
	for i in range(len_S):
		if S_prime[i] == "?":
			print("a", end = "")
		else:
			print(S_prime[i], end = "")
Buggy code:
s=input()
t=input()

if len(s) < len(t):
  print("UNRESTORABLE")
  exit()

c=len(s)-len(t)

flg=False
while True:
  if c<0:
    break
  
  flg2=True
  for i in range(len(t)):
    if s[c+i]!=t[i] and s[c+i]!="?":
      flg2=False
  if flg2:
    flg=True
    break
# c-=1
#print(c)



if flg:
  print((s[:c]+t+s[c+len(t):]).replace("?","a"))
else:
  print("UNRESTORABLE")


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

if len(s) < len(t):
  print("UNRESTORABLE")
  exit()

c=len(s)-len(t)

flg=False
while True:
  if c<0:
    break
  
  flg2=True
  for i in range(len(t)):
    if s[c+i]!=t[i] and s[c+i]!="?":
      flg2=False
  if flg2:
    flg=True
    break
  c-=1
#print(c)



if flg:
  print((s[:c]+t+s[c+len(t):]).replace("?","a"))
else:
  print("UNRESTORABLE")
Buggy code:
S = input()
T = input()
match = False
start = -1
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] == T[j] or S[i+j] == "?":
            match = True
    if match:
        start = i
    
    
if start == -1:
    print('UNRESTORABLE')
else:
    result = S[:start] + T + S[start+len(T):]
    print(result.replace("?", "a"))


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

start = -1
for i in range(len(S)-len(T)+1):
    match = True
    for j in range(len(T)):
        if not (S[i+j] == T[j] or S[i+j] == "?"):
            match = False
    if match:
        start = i


if start == -1:
    print('UNRESTORABLE')
else:
    result = S[:start] + T + S[start+len(T):]
    print(result.replace("?", "a"))
Buggy code:
S=input()
T=input()
n=len(S)
m=len(T)

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


Fixed code:
S=input()
T=input()
n=len(S)
m=len(T)

for i in range(n-m,-1,-1) :
    x=S[i:i+m]
    for j in range(m+1):
        if j==m :
            print((S[:i]+T+S[i+m:]).replace("?","a"))
            exit()
        if x[j]=="?" :
            continue
        elif x[j]!=T[j] :
            break
 
print("UNRESTORABLE")
Buggy code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = readline().rstrip().decode()
t = read().rstrip().decode()
ans = []
for i in range(len(s) - len(t) + 1):
    for j, (ss, tt) in enumerate(zip(s[i:], t)):
        if ss not in ('?', tt):
            break
    else:
        memo = s[:i] + t + s[i + len(t):]
        ans.append(memo.replace('?', 'a'))
print(min(ans) if ans else 'UNRESTRABLE')


Fixed code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = readline().rstrip().decode()
t = read().rstrip().decode()
ans = []
for i in range(len(s) - len(t) + 1):
    for j, (ss, tt) in enumerate(zip(s[i:], t)):
        if ss not in ('?', tt):
            break
    else:
        memo = s[:i] + t + s[i + len(t):]
        ans.append(memo.replace('?', 'a'))
print(min(ans) if ans else 'UNRESTORABLE')
Buggy code:
S_prime = input()
T = input()

def judge(A,B):
    for i in range(len(A)):
        if A[i] != B[i] and A[i] != "?" and B[i] != "?":
            return False
    return True

def dec(S_prime,T):
    S_cand = []
    for i in range(len(S_prime)-len(T)+1):
        if judge(S_prime[i:i+len(T)],T):
            S_cand.append( S_prime[:i] + T + S_prime[i+len(T):] )
            print(i,S_prime[:i], T, S_prime[i+len(T):])
    return S_cand

def S_change(S):
    S = list(S)
    for i in range(len(S)):
        if S[i] == "?":
            S[i] = "a"
    S = "".join(S)
    return S

if len(dec(S_prime,T)) == 0:
    print("UNRESTORABLE")
else:
    Ans = dec(S_prime,T)
    for i in range(len(Ans)):
        Ans[i] = S_change(Ans[i])
    Ans.sort()
    print(Ans[0])
    


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

def judge(A,B):
    for i in range(len(A)):
        if A[i] != B[i] and A[i] != "?" and B[i] != "?":
            return False
    return True

def dec(S_prime,T):
    S_cand = []
    for i in range(len(S_prime)-len(T)+1):
        if judge(S_prime[i:i+len(T)],T):
            S_cand.append( S_prime[:i] + T + S_prime[i+len(T):] )
    return S_cand

def S_change(S):
    S = list(S)
    for i in range(len(S)):
        if S[i] == "?":
            S[i] = "a"
    S = "".join(S)
    return S

if len(dec(S_prime,T)) == 0:
    print("UNRESTORABLE")
else:
    Ans = dec(S_prime,T)
    for i in range(len(Ans)):
        Ans[i] = S_change(Ans[i])
    Ans.sort()
    print(Ans[0])
Buggy code:
def check(a, b):
    for i, j in zip(a, b):
        if i == "?" or i == j:
            pass
        else:
            return False
    return True


def make(a):
    x = ""
    for i in a:
        if i == "?":
            x += "a"
        else:
            x += i
    return x


s = list(input())
t = list(input())
n = len(t)
ans = []
for i in range(len(s)-n+1):
    if check(s[i:n+i], t):
        w = s[:i] + t + s[n+i:]
        ans.append(make(w))

if len(ans) == 0:
    print("UNRETSORABLE")
else:
    print(min(ans))



Fixed code:
def check(a, b):
    for i, j in zip(a, b):
        if i == "?" or i == j:
            pass
        else:
            return False
    return True


def make(a):
    x = ""
    for i in a:
        if i == "?":
            x += "a"
        else:
            x += i
    return x


s = list(input())
t = list(input())
n = len(t)
ans = []
for i in range(len(s)-n+1):
    if check(s[i:n+i], t):
        w = s[:i] + t + s[n+i:]
        ans.append(make(w))

if len(ans) == 0:
    print("UNRESTORABLE")
else:
    print(min(ans))
Buggy code:
s_dash = input()
t = input()
answer = 'UNRESTORABLE'
if s_dash < t:
    pass
else:
    for i in range(len(s_dash)-len(t)+1):
        for j, k in zip(s_dash[i:i+len(t)], t):
            if j != '?' and j != k:
                break
        else:
            answer = s_dash[:i] + t + s_dash[i+len(t):]
            answer = answer.replace('?', 'a')
print(answer)


Fixed code:

s_dash = input()
t = input()
answer = 'UNRESTORABLE'
if len(s_dash) < len(t):
    pass
else:
    for i in range(len(s_dash)-len(t)+1):
        for j, k in zip(s_dash[i:i+len(t)], t):
            if j != '?' and j != k:
                break
        else:
            answer = s_dash[:i] + t + s_dash[i+len(t):]
            answer = answer.replace('?', 'a')
print(answer)
Buggy code:
s=input()
t=input()
ans=[]
for i in range(len(s)-len(t)+1):
  start=i
  end=i+len(t)
  ok=True
  for j in range(len(t)):
    if s[start+j]!='?' and s[start+j]!=t[j]:
      ok=False
      break
  if ok:
    a=s[:start]+t+s[end:]
    ans.append(a.replace('?','a'))
if ans:
  ans=sorted(ans)
  print(ans[0])
else:
  print('UNRESTORALBE')

Fixed code:
s=input()
t=input()
ans=[]
for i in range(len(s)-len(t)+1):
  start=i
  end=i+len(t)
  ok=True
  for j in range(len(t)):
    if s[start+j]!='?' and s[start+j]!=t[j]:
      ok=False
      break
  if ok:
    a=s[:start]+t+s[end:]
    ans.append(a.replace('?','a'))
if ans:
  ans=sorted(ans)
  print(ans[0])
else:
  print('UNRESTORABLE')
Buggy code:
S = input()
T = input()
len_S = len(S)
len_T = len(T)
qc = 0
ans = ''
for i in range(len_S-1, -1, -1):
    print(i, S[i])
    si = S[i]
    if si == '?':
        qc += 1
    else:
        qc = 0
    if qc == len_T:
        ans = ans = S[:i] + T + S[i+len_T:]
        break
    if si == T[0] and len_S - i >= len_T:
        print(T)
        flag = True
        for ii in range(1, len_T):
            print(ii, S[i+ii])
            if T[ii] == S[i+ii] or S[i+ii] == '?':
                continue
            else:
                flag = False
                break
        if flag:
            ans = S[:i] + T + S[i+len_T:]
            break

if ans:
    print(ans.replace('?', 'a'))
else:
    print('UNRESTORABLE')
    

Fixed code:
S = input()
T = input()
len_S = len(S)
len_T = len(T)
qc = 0
ans = ''
for i in range(len_S-1, -1, -1):
    si = S[i]
    if (si == '?' or si == T[0]) and len_S - i >= len_T:
        flag = True
        for ii in range(1, len_T):
            if T[ii] == S[i+ii] or S[i+ii] == '?':
                continue
            else:
                flag = False
                break
        if flag:
            ans = S[:i] + T + S[i+len_T:]
            break

if ans:
    print(ans.replace('?', 'a'))
else:
    print('UNRESTORABLE')
Buggy code:


SD = input()
K = input()

ans_list = []

for i in range(len(SD) - len(K) + 1):
    flag = True
    for j in range(len(K)):
        if SD[i] != K[j] and SD[i] != '?':
            flag = False
            break
    if flag:
        tmp = SD[:i] + K + SD[len(K) + 1:]
        ans_list.append(tmp.replace('?', 'a'))

s_ans_list = sorted(ans_list)
if len(s_ans_list) == 0:
    print('UNRESTORABLE')
else:
    print(s_ans_list[0])



Fixed code:


SD = input()
K = input()

ans_list = []

for i in range(len(SD) - len(K) + 1):
    flag = True
    for j in range(len(K)):
        if SD[i + j] != K[j] and SD[i + j] != '?':
            flag = False
            break
    if flag:
        tmp = SD[:i] + K + SD[len(K) + i:]
        ans_list.append(tmp.replace('?', 'a'))


s_ans_list = sorted(ans_list)
if len(s_ans_list) == 0:
    print('UNRESTORABLE')
else:
    print(s_ans_list[0])
Buggy code:
S = list(input())
T = list(input())
flag1 = 1
for i in range(len(S) - len(T), -1, -1):
    flag2 = 1
    for j in range(len(T)):
        if S[i+j] != '?' and S[i+j] != T[j]:
            flag = 0
    if flag2:
        S[i:i+len(T)] = T[:]
        flag1 = 0
        break

if flag1:
    print('UNRESTORABLE')
else:
    for i in range(len(S)):
        if S[i] == '?':
            S[i] = 'a'
    print(''.join(S))

Fixed code:
S = list(input())
T = list(input())
flag1 = 1
for i in range(len(S) - len(T), -1, -1):
    flag2 = 1
    for j in range(len(T)):
        if S[i+j] != '?' and S[i+j] != T[j]:
            flag2 = 0
    if flag2:
        S[i:i+len(T)] = T[:]
        flag1 = 0
        break

if flag1:
    print('UNRESTORABLE')
else:
    for i in range(len(S)):
        if S[i] == '?':
            S[i] = 'a'
    print(''.join(S))
Buggy code:
s = input()
t = input()

ans = "UNRESTORABLE"

i = 0

while i < len(s)-len(t)+2:
    flag = False
    if s[i] == t[0] or s[i] == "?":
        for j in range(1,len(t)):
            if s[i+j] == "?" or s[i+j] == t[j]:
                flag = True
            else:
                flag = False
                break
        if flag:
            tmps = ""
            k = 0
            while k < len(s):
                if k < i or k >= i+len(t):
                    if s[k] == "?":
                        tmps += "a"
                        k += 1
                    else:
                        tmps += s[k]
                        k += 1
                else:
                    tmps += t
                    k += len(t)
            ans = tmps
    i += 1

print(ans)



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

ans = "UNRESTORABLE"

i = 0

while i < len(s)-len(t)+1:
    if s[i] == t[0] or s[i] == "?":
        flag = True
        for j in range(1,len(t)):
            if s[i+j] == "?" or s[i+j] == t[j]:
                continue
            else:
                flag = False
                break
        if flag:
            tmps = ""
            k = 0
            while k < len(s):
                if k < i or k >= i+len(t):
                    if s[k] == "?":
                        tmps += "a"
                        k += 1
                    else:
                        tmps += s[k]
                        k += 1
                else:
                    tmps += t
                    k += len(t)
            ans = tmps
    i += 1

print(ans)
Buggy code:
S = input()
T = input()

len_s = len(S)
len_t = len(T)

match = -1

for i in range((len_s - len_t), 0, -1):
    print("i", i)
    for j in range(len_t):
        if T[j] != S[i+j] and S[i+j] != "?":
            break

        if j == len_t-1:
            match = i

    if match != -1:
        break

if match == -1:
    print("UNRESTORABLE")
    exit()

list_s = list(S)

for i in range(match, match+len_t):
    list_s[i] = T[i - match]

list_s = [x if x != "?" else "a" for x in list_s]

print("".join(list_s))


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

len_s = len(S)
len_t = len(T)

match = -1

for i in range((len_s - len_t), -1, -1):
    for j in range(len_t):
        if T[j] != S[i+j] and S[i+j] != "?":
            break

        if j == len_t-1:
            match = i

    if match != -1:
        break

if match == -1:
    print("UNRESTORABLE")
    exit()

list_s = list(S)

for i in range(match, match+len_t):
    list_s[i] = T[i - match]

list_s = [x if x != "?" else "a" for x in list_s]

print("".join(list_s))
Buggy code:
s = input()
t = input()

ans = "UNRESTORABLE"

ls = []

for i in range(len(t)):
    for j in range(i, len(s)-len(t)+i):
        if s[j] == t[i]:
            for k in range(len(t)):
                if t[k] != s[j+k-i] and s[j+k-i] != "?":
                    break
                if k == len(t)-1:
                    tmps = s[:j-i] + t + s[j-i+len(t):]
                    for p in range(len(s)):
                        if tmps[p] == "?":
                            tmps = tmps[:p] + "a" + tmps[p+1:]
                    ls.append(tmps)

ls.sort()
if len(ls) != 0:
    ans = ls[0]

print(ans)


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

ans = "UNRESTORABLE"

ls = []

for i in range(len(t)):
    for j in range(i, len(s)-len(t)+i+1):
        if s[j] == t[i]:
            for k in range(len(t)):
                if t[k] != s[j+k-i] and s[j+k-i] != "?":
                    break
                if k == len(t)-1:
                    tmps = s[:j-i] + t + s[j-i+len(t):]
                    for p in range(len(s)):
                        if tmps[p] == "?":
                            tmps = tmps[:p] + "a" + tmps[p+1:]
                    ls.append(tmps)

for i in range(len(s)-len(t)+1):
    if s[i] == "?":
        if s[i:i+len(t)] == "?"*len(t):
            tmps = s[:i] + t + s[i+len(t):]
            for p in range(len(s)):
                if tmps[p] == "?":
                    tmps = tmps[:p] + "a" + tmps[p+1:]
            ls.append(tmps)

ls.sort()
if len(ls) != 0:
    ans = ls[0]

print(ans)
Buggy code:
S = list(input())
T = list(input())
ans = []

for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        print(S[i+j], T[j])
        if S[i+j] == '?' or S[i+j] == T[j]:
            continue
        else:
            break
    else:
        tmp = str("".join(S[:i] + T + S[i+len(T):]).replace('?','a'))
        ans.append(tmp)
    print(i)
if len(ans) == 0:
    print("UNRESTORABLE")
else:
    ans.sort()
    print(ans[0])

Fixed code:
S = list(input())
T = list(input())
ans = []

for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] == '?' or S[i+j] == T[j]:
            continue
        else:
            break
    else:
        tmp = str("".join(S[:i] + T + S[i+len(T):]).replace('?','a'))
        ans.append(tmp)
if len(ans) == 0:
    print("UNRESTORABLE")
else:
    ans.sort()
    print(ans[0])
Buggy code:
s = input()
t = input()
a =[]
for i in range(len(s)-len(t)+1):
    f = True
    for j in range(len(t)):
        if s[i+j] != '?' and s[i+j] != t[j]:
            f = False
    if f == True:
        a.append(i)

s = s.replace('?','a')

print(s[:a[-1]]+t+s[a[-1]+len(t):])


Fixed code:
s = input()
t = input()
a =[]
for i in range(len(s)-len(t)+1):
    f = True
    for j in range(len(t)):
        if s[i+j] != '?' and s[i+j] != t[j]:
            f = False
    if f == True:
        a.append(i)

s = s.replace('?','a')
if len(a) !=0:
    print(s[:a[-1]]+t+s[a[-1]+len(t):])
else:
    print('UNRESTORABLE')