qyliang/CodeNanoFix huggingface dataset:
Buggy code:
s = input()
t = input()

x = "UNRESTORABLE"

sl = len(s)
tl = len(t)


if sl < tl:
    print(x)
    exit()

flag =0

for i in range(sl-tl,-1,-1):
    temp = s[i:i+tl]
    print(temp)
    for j in range(tl):
        if temp[j] == t[j] or temp[j] =="?":
            if j == tl-1:
                x = s[:i] + t + s[i+tl:]
                flag = 1
                break            
        else:
            break

    if flag ==1:
        break

x = x.replace("?","a")

print(x)

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

x = "UNRESTORABLE"

sl = len(s)
tl = len(t)


if sl < tl:
    print(x)
    exit()

flag =0

for i in range(sl-tl,-1,-1):
    temp = s[i:i+tl]
    for j in range(tl):
        if temp[j] == t[j] or temp[j] =="?":
            if j == tl-1:
                x = s[:i] + t + s[i+tl:]
                flag = 1
                break            
        else:
            break

    if flag ==1:
        break

x = x.replace("?","a")

print(x)
Buggy code:
import copy
import sys
li = list('abcdefghijklmnopqrstuvwxyz')
r = []
for i in range(len(s)-len(t)+1):
    ss = list(s)
    print(i)
    lo = [1 if ((s[i + j] == t[j]) or (s[i + j] == '?')) else 0 for j in range(len(t))]
    print(lo)
    if all(lo):
        ss[i:i+ len(t)] = t
        rs = ''.join(ss)
        rs = rs.replace('?','a')
        r += [rs]

if len(r) == 0:
    print('UNRESTORABLE')
    sys.exit()
r = sorted(r)
print(r[0])

Fixed code:
import copy
import sys

s = input()
t = input()
li = list('abcdefghijklmnopqrstuvwxyz')
r = []
for i in range(len(s)-len(t)+1):
    ss = list(s)
#     print(i)
    lo = [1 if ((s[i + j] == t[j]) or (s[i + j] == '?')) else 0 for j in range(len(t))]
#     print(lo)
    if all(lo):
        ss[i:i+ len(t)] = t
        rs = ''.join(ss)
        rs = rs.replace('?','a')
        r += [rs]

if len(r) == 0:
    print('UNRESTORABLE')
    sys.exit()
r = sorted(r)
print(r[0])
Buggy code:
s_d = [i for i in input()]
t = input()
flg = True

for i in range(len(s_d)-1, -1, -1):
    if len(s_d) - i >= len(t) and s_d[i] == '?' or s_d[i] == t[0]:
        j, n = i+1, 1
        while j < len(s_d) - 1:
            if s_d[j] == '?' or s_d[j] == t[n]:
                j += 1
                n += 1
            else:
                break

        if n >= len(t):
            s_d[i:j] = t
            break
else:
    print("UNRESTORABLE")
    flg = False

if flg:
    for i in range(len(s_d)):
        if s_d[i] == '?':
            s_d[i] = 'a'

    print("".join(s_d))


Fixed code:
s_d = [i for i in input()]
t = input()
flg = True

for i in range(len(s_d)-1, -1, -1):
    if len(s_d) - i >= len(t) and s_d[i] == '?' or s_d[i] == t[0]:
        j, n = i+1, 1
        while j <= len(s_d) - 1 and n <= len(t) - 1:
            if s_d[j] == '?' or s_d[j] == t[n]:
                j += 1
                n += 1
            else:
                break

        if n >= len(t):
            s_d[i:i+len(t)] = t
            break
else:
    print("UNRESTORABLE")
    flg = False

if flg:
    for i in range(len(s_d)):
        if s_d[i] == '?':
            s_d[i] = 'a'

    print("".join(s_d))
Buggy code:
s = input()
t = input()
l = []
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:
        print(s[:i]+t+s[i+j+1:])
        l.append(s[:i]+t+s[i+j+1:])
if len(l) == 0:
    print("UNRESTORABLE")
    exit()
l.sort()
print(l[0].replace("?", "a"))

Fixed code:
s = input()
t = input()
l = []
for i in range(len(s)-len(t)+1):
    for j in range(i, i+len(t)):
        if s[j] != "?" and s[j] != t[j-i]:
            break
    else:
        l.append(s[:i]+t+s[i+len(t):])
if len(l) == 0:
    print("UNRESTORABLE")
    exit()
l.sort()
print(l[0].replace("?", "a"))
Buggy code:
from re import match
s, t = input().replace('?', '.'), input()

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


Fixed code:
from re import match
s, t = input().replace('?', '.'), input()

for i in range(len(s) - len(t) + 1)[::-1]:
    if match(s[i:i + len(t)], t):
        key = s.replace(s[i:i + len(t)], t).replace('.', 'a')
        s = s.replace('.', 'a')
        print(s[:i] + t + s[i + len(t):])
        #print(key)
        break
else:
    print('UNRESTORABLE')
Buggy code:
s=input()
t=input()
m=len(s)
n=len(t)
check=False
for i in range(m-n,-1,-1):
  for j in range(i,i+n):
    check2=True
    if s[j]=='?' or s[j]==t[j-i]:
      continue
    else:
      check2=False
  if check2:
    check=True
    s=s[:i]+t+s[i+n:]
    s=s.replace('?','a')
    break
print(s if check else 'UNRESTORABLE')
    
      

Fixed code:
s=input()
t=input()
m=len(s)
n=len(t)
check=False
for i in range(m-n,-1,-1):
  check2=True
  for j in range(i,i+n):
    if s[j]=='?' or s[j]==t[j-i]:
      continue
    else:
      check2=False
  if check2:
    check=True
    s=s[:i]+t+s[i+n:]
    s=s.replace('?','a')
    break
print(s if check else 'UNRESTORABLE')
Buggy code:
s = input()
S = input()
flag = False
for i in range(len(s)-len(S)+1):
    if s[i] == S[0] or s[i] == "?":
        a = s[i:i+len(S)]
        for j in range(len(S)):
            if a[j] == S[j] or a[j] == "?":
                continue
            break
        else:
            flag = True
            s = s[0:i]+S+s[i+len(S):]
            print(s)
print(s.replace("?","a") if flag == True else "UNRESTORABLE")

Fixed code:
s = input()
S = input()
ary = []
flag = False
for i in range(len(s)-len(S)+1):
    if s[i] == S[0] or s[i] == "?":
        a = s[i:i+len(S)]
        for j in range(len(S)):
            if a[j] == S[j] or a[j] == "?":continue
            break
        else:
            flag = True
            ary.append(s[:i]+S+s[i+len(S):])
print(sorted(i.replace("?","a") for i in ary)[0] if flag else "UNRESTORABLE")
Buggy code:
s=list(input())
t=list(input())
if len(s)<len(t):print('UNSTORABLE')
else:
	for i in range(len(s)-len(t)+1):
		for j in range(len(t)):
			if s[i+j] not in ['?',t[j]]:break
		else:
			s[i:i+len(t)]=t
			break
	else:
		print('UNSTORABLE')
print(''.join(s).replace('?','a'))

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

ans = "UNRESTORBLE"
if len(S) >= len(T) :
    for i in range(len(S)-len(T)+1) :
        S_ = S[i:i+len(T)]
        #print(S_)
        for j in range(len(T)) :
            if S_[j] == "?" :
                continue
            if S_[j] != T[j] :
                break
        else :
            ans = S[:i] + T + S[i+len(T):]
ans = ans.replace("?","a")
print(ans)


Fixed code:
S = input()
T = input()
S = S[::-1]
T = T[::-1]

ans = "UNRESTORABLE"[::-1]
if len(S) >= len(T) :
    if T in S :
        ans = S
    else :
        for i in range(len(S)-len(T)+1) :
            S_ = S[i:i+len(T)]
            #print(S_)
            for j in range(len(T)) :
                if S_[j] == "?" :
                    continue
                if S_[j] != T[j] :
                    break
            else :
                ans = S[:i] + T + S[i+len(T):]
                break
ans = ans.replace("?","a")
ans = ans[::-1]
print(ans)
Buggy code:
s=input()
t=input()
score = 0
L = []
for i in range(len(s)-len(t)+1):
  cut = s[i:i+len(t)]
  for j in range(len(t)):
    if cut[j] == t[j] or cut[j] =="?":
      score += 1
  if score == len(t):
    s = s[:i] + t + s[i+len(t):]
    L.append(s.replace("?","a"))
  score = 0
if L = []:
  print("UNRESTORABLE")
else:
  L = sorted(L)
  print(L[0])
    


Fixed code:
s=input()
t=input()
score = 0
L = []
for i in range(len(s)-len(t)+1):
  k = s
  cut = k[i:i+len(t)]
  for j in range(len(t)):
    if cut[j] == t[j] or cut[j] =="?":
      score += 1
  if score == len(t):
    
    k = k[:i] + t + k[i+len(t):]
    L.append(k.replace("?","a"))
  score = 0
if L == []:
  print("UNRESTORABLE")
else:
  L = sorted(L)
  print(L[0])
Buggy code:
# C
sd = input()
scnt = len(sd)
t = input()
tcnt = len(t)

point = 0
unrestorable = True
while point <= scnt - tcnt:
    oneroopcorres = True
    for i in range(tcnt):
        anyone = sd[point+i] == '?'
        correspond = sd[point+i] == t[i]
        if not (anyone | correspond):
            flag = False

    if oneroopcorres:
        unrestorable = False
        good_point = point

    point += 1

if unrestorable:
    print('UNRESTORABLE')
    exit()
else:
    sd = list(sd)
    for i in range(tcnt):
        sd[good_point + i] = t[i]
    sd = ''.join(sd)

sd = sd.replace('?', 'a')
print(sd)

Fixed code:
# C
sd = input()
scnt = len(sd)
t = input()
tcnt = len(t)

point = 0
unrestorable = True
while point <= scnt - tcnt:
    oneroopcorres = True
    for i in range(tcnt):
        anyone = sd[point+i] == '?'
        correspond = sd[point+i] == t[i]
        if not (anyone or correspond):
            oneroopcorres = False

    if oneroopcorres:
        unrestorable = False
        good_point = point

    point += 1

if unrestorable:
    print('UNRESTORABLE')
    exit()
else:
    sd = list(sd)
    for i in range(tcnt):
        sd[good_point + i] = t[i]
    sd = ''.join(sd)

sd = sd.replace('?', 'a')
print(sd)
Buggy code:
SD = input()
T = input()

ans = ''

for i in range(0, len(SD) - len(T)+1):
    flg = True
    for j in range(len(T)):
        if SD[i+j] == '?' or SD[i+j] == T[j]:
            continue
        else:
            flg = False
    if flg == True:
        ans = SD[:i] + T + S[i+len(T):]
            
if ans:
    ans = ans.replace('?', 'a')
else:
    ans = 'UNRESTORABLE'
    
print(ans)

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

ans = ''

for i in range(0, len(SD) - len(T)+1):
    flg = True
    for j in range(len(T)):
        if SD[i+j] == '?' or SD[i+j] == T[j]:
            continue
        else:
            flg = False
    if flg == True:
        ans = SD[0:i] + T + SD[i+len(T):]
            
if ans:
    ans = ans.replace('?', 'a')
else:
    ans = 'UNRESTORABLE'
    
print(ans)
Buggy code:
s = input()
t = input()

ans = "UNRESTORABLE"

memo = -1

for i in range(len(s)):
    for j in range(len(t)):
        count = 0
        if s[i+j] == t[j] or t[j] == "?":
            count += 1
        else:
            count = 0
            break
        if count == len(t):
            ans = s[i:i+len(t)]
            memo = i
            count = 0

if ans == "UNRESTORABLE":
    print(ans)
else:
    ans1 = ""
    for word in t:
        if word == "?":
            ans1 += "a"
        else:
            ans1 += word
    ans1[memo:memo+len(t)] = ans
    print(ans1)
        


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

ans = "UNRESTORABLE"

memo = -1

for i in range(len(s) - len(t) + 1):
    count = 0
    for j in range(len(t)):
        if s[i+j] == t[j] or s[i+j] == "?":
            count += 1
        else:
            break
        if count == len(t):
            ans = t
            memo = i

if ans == "UNRESTORABLE":
    print(ans)
else:
    ans1 = ""
    for word in s:
        if word == "?":
            ans1 += "a"
        else:
            ans1 += word
    ans2 = ans1[0:memo] + ans + ans1[memo+len(t):]
    print(ans2)
Buggy code:
s = input()
t = input()

match = -1
for i in range(len(s) - len(t) + 1):
    is_term_match = True
    for j in range(len(t)):
        if s[i + j] != "?" and s[i + j] != t[j]:
            is_term_match = False
            break
    if is_term_match:
        match = i
        break

if match == -1:
    print("UNRESTORABLE")
else:
    s = s[0:match] + t + s[match + len(t):]
    print(match)
    print(s)
    for i in range(len(s)):
        if s[i] == "?":
            s = s[0:i] + "a" + s[i + 1:]
    print(s)


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

match = -1
if len(s) >= len(t):
    for i in range(len(s) - len(t) + 1):
        is_term_match = True
        for j in range(len(t)):
            if s[i + j] != "?" and s[i + j] != t[j]:
                is_term_match = False
                break
        if is_term_match:
            match = i

if match == -1:
    print("UNRESTORABLE")
else:
    s = s[0:match] + t + s[match + len(t):]
    for i in range(len(s)):
        if s[i] == "?":
            s = s[0:i] + "a" + s[i + 1:]
    print(s)
Buggy code:
s=input()
t=input()
n=len(s)-len(t)+1
lst=[]
for i in range(n):
    tot=0
    ss=s
    for j in range(len(t)):
        if ss[i+j]==t[j] or ss[i+j]=="?":
            tot+=1
    if tot==len(t):
        for j in range(len(t)):
            ss[i+j]=t[j]
        ss=ss.replace("?","a")
        lst.append(ss)
lst.sort()
print(lst[0] if len(lst)!=0 else "UNRESTORABLE" )

Fixed code:
s=input()
t=input()
n=len(s)-len(t)+1
lst=[]
for i in range(n):
    tot=0
    ss=s
    for j in range(len(t)):
        if ss[i+j]==t[j] or ss[i+j]=="?":
            tot+=1
    if tot==len(t):
        ss=list(ss)
        t=list(t)
        for j in range(len(t)):
            ss[i+j]=t[j]
        ss="".join(ss)
        t="".join(t)
        ss=ss.replace("?","a")
        lst.append(ss)
lst.sort()
print(lst[0] if len(lst)!=0 else "UNRESTORABLE" )
Buggy code:
S = input()
T = input()


def f(begin, txt, query):
    for i in range(len(query)):
        if (txt[begin+i] == '?') or (txt[begin+i] == query[i]):
            pass
        else:
            return False
    return True


def g(begin, txt, query):
    tmp = list(txt)
    for i in range(len(tmp)):
        if tmp[i] == '?':
            tmp[i] = 'a'
    for i in range(len(query)):
        tmp[begin+i] = query[i]
    return ''.join(tmp)


flag = False

for i in range(len(S) - len(T)):
    if f(len(S) - i - len(T), S, T):
        S = g(len(S) - i - len(T), S, T)
        flag = True
        break

if flag is False:
    print('UNRESTORED')
else:
    print(S)


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


def f(begin, txt, query):
    for i in range(len(query)):
        if (txt[begin+i] == '?') or (txt[begin+i] == query[i]):
            pass
        else:
            return False
    return True


def g(begin, txt, query):
    tmp = list(txt)
    for i in range(len(tmp)):
        if tmp[i] == '?':
            tmp[i] = 'a'
    for i in range(len(query)):
        tmp[begin+i] = query[i]
    return ''.join(tmp)


flag = False

for i in range(len(S) - len(T) + 1):
    if f(len(S) - i - len(T), S, T):
        S = g(len(S) - i - len(T), S, T)
        flag = True
        break

if flag is False:
    print('UNRESTORABLE')
else:
    print(S)
Buggy code:
s = list(input())
t = list(input())

def eq(s, t):
    for i in range(len(s)):
        if s[i] != t[i] and s[i] != '?':
            return False
    return True

for i in reversed(range(len(s) - len(t)+1)):
    if eq(s[i:i+len(t)], t[:]):
        s[i:i + len(t)] = t[:]
        ans = ''.join(s)
        print(ans.replace('?', 'b'))
        quit()
print('UNRESTORABLE')

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

def eq(s, t):
    for i in range(len(s)):
        if s[i] != t[i] and s[i] != '?':
            return False
    return True

for i in reversed(range(len(s) - len(t)+1)):
    if eq(s[i:i+len(t)], t[:]):
        s[i:i + len(t)] = t[:]
        ans = ''.join(s)
        print(ans.replace('?', 'a'))
        quit()
print('UNRESTORABLE')
Buggy code:
S = input()
T = input()
ans = []

lt = len(T)
for i in range(len(S)-lt+1):
    s = S[i:i+lt]
    for t in range(lt):
        if s[t]=='?':
            pass
        else:
            if s[t]!=T[t]:
                break
            elif t==lt-1:
                ans.append((S[:i]+T+S[i+lt:]).replace('?', 'a'))
                break

print(min(ans) if len(ans)>0 else "UNRESTORABLE")

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

lt = len(T)
for i in range(len(S)-lt+1):
    s = S[i:i+lt]
    for t in range(lt):
        if s[t]=='?':
            if t != lt-1:
                pass
            else:
                ans.append((S[:i]+T+S[i+lt:]).replace('?', 'a'))
        else:
            if s[t]!=T[t]:
                break
            elif t==lt-1:
                ans.append((S[:i]+T+S[i+lt:]).replace('?', 'a'))
                break

print(min(ans) if len(ans)>0 else "UNRESTORABLE")
Buggy code:
s=list(input())
t=list(input())
sl=len(s)
tl=len(t)
for k in range(sl-tl+2):
    judge=True
    for i in range(tl):
        if s[i+k]==t[i] or s[i+k]=="?":
            pass
        else:
            judge=False
            break
    if judge:
        for i in range(tl):
            s[i+k]=t[i]
        for i in range(sl):
            if s[i]=="?":
                s[i]="a"
        print("".join(s))
        exit()
print("UNRESTORABLE")


Fixed code:
s=list(input())
t=list(input())
sl=len(s)
tl=len(t)
for k in range(sl-tl,-1,-1):
    judge=True
    for i in range(tl):
        if s[i+k]==t[i] or s[i+k]=="?":
            pass
        else:
            judge=False
            break
    if judge:
        for i in range(tl):
            s[i+k]=t[i]
        for i in range(sl):
            if s[i]=="?":
                s[i]="a"
        print("".join(s))
        exit()
print("UNRESTORABLE")
Buggy code:
s=input()
t=input()
l=[]
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:
        a=s[:i]+t+s[i+len(t):]
        l.append(a.replace('?', 'a'))
l.sort()
if l:
    print(l[0])
else:
    print('UNRESTRABLE')

Fixed code:
s=input()
t=input()
l=[]
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:
        a=s[:i]+t+s[i+len(t):]
        l.append(a.replace('?', 'a'))
l.sort()
if l:
    print(l[0])
else:
    print('UNRESTORABLE')
Buggy code:
w=input()
w1=input()
num=len(w)
num1=len(w1)
start=-1
if num<num1:
  b1=False
for i in range(num-num1+1):
  b=True
  for j in range(num1):
    if w[i+j]=="?" or w[i+j]==w1[j]:
      pass
    else:
      b=False
  if b:
      start=i
if start==-1:
  print("UNRESTORABLE")
else:
  word=""
  if start!=0:
    for i in range(num):
      if i<start:
        if w[i]=="?":
          word+="a"
        else:
          word+=w[i]
      elif start<=i and i<=start+num1-1:
        word+=w1[i]
      else:
        if w[i]=="?":
          word+="a"
        else:
          word+=w[i]
  print(word)


Fixed code:
w=input()
w1=input()
num=len(w)
num1=len(w1)
start=-1
if num<num1:
  b1=False
for i in range(num-num1+1):
  b=True
  for j in range(num1):
    if w[i+j]=="?" or w[i+j]==w1[j]:
      pass
    else:
      b=False
  if b:
      start=i
if start==-1:
  print("UNRESTORABLE")
else:
  word=""
  for i in range(num):
    if i<start:
      if w[i]=="?":
        word+="a"
      else:
        word+=w[i]
    elif start<=i and i<=start+num1-1:
      word+=w1[i-start]
    else:
      if w[i]=="?":
        word+="a"
      else:
        word+=w[i]
  print(word)
Buggy code:
l = input().split()
S = l[0]
l = input().split()
T = l[0]

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

# print(S, T, len(S), len(T))

found = False

def match(pos, max_pos, src, dst):
    if pos == max_pos:
        return True
    if src[pos] == '?' or src[pos] == dst[pos]:
        return match(pos + 1, max_pos, src, dst)
    return False

for i in range(ls - lt + 1):
    if match(0, lt - 1, S[i:], T):
        S = S[:i] + T + S[i + lt:]
        found = True
        break

if found:
    S = S.replace('?', 'a')
    print(S)
else:
    print('UNRESTORABLE')

Fixed code:
l = input().split()
S = l[0]
l = input().split()
T = l[0]

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

# print(S, T, len(S), len(T))

found = False

def match(pos, max_pos, src, dst):
    if pos == max_pos:
        return True
    if src[pos] == '?' or src[pos] == dst[pos]:
        return match(pos + 1, max_pos, src, dst)
    return False

for i in range(ls - lt + 1):
    index = ls - lt - i
    if match(0, lt, S[index:], T):
        S = S[:index] + T + S[index + lt:]
        found = True
        break

if found:
    S = S.replace('?', 'a')
    print(S)
else:
    print('UNRESTORABLE')
Buggy code:
```
def main():
    s = input()
    t = input()

    f(s, t)

def f(s, t):
    l_t =len(t)
    for i in reversed(range(len(s)-l_t+1)):
        b = s[i:i+l_t]
        c = sum(c1 == c2 or c2 == "?" for c1, c2 in zip(t, b))

        if c == len(t):
            print(s[:i], t, s[i+l_t:])
            ans = s[:i].replace("?", "a") + t + s[i+l_t:].replace("?", "a")
            print(ans)
            return

    print("UNRESTORABLE")


if __name__ == "__main__":
    main()
```

Fixed code:
def main():
    S_ = input()
    T = input()

    f(S_, T)


def f(s, t):
    l_t = len(t)
    for i in reversed(range(len(s)-l_t+1)):
        b = s[i:i+l_t]
        c = sum(c1 == c2 or c2 == "?" for c1, c2 in zip(t, b))

        if c == len(t):
            ans = s[:i].replace("?", "a") + t + s[i+l_t:].replace("?", "a")
            print(ans)
            return

    print("UNRESTORABLE")


if __name__ == '__main__':
    main()
Buggy code:
import sys
import re



def check(Sda, T, Slen, Tlen):
    matarr=[]
    endarr=[]

    getS = 'UNRESTORABLE'

    if(Slen<Tlen):
        return getS

    for i in reversed(range(0, Slen-Tlen+1)):


        mat = re.match(Sda[i:i+Tlen],T)
        try:
            if(mat.group() == T):
                matarr.append(Sda[:i]+T+Sda[i+Tlen:])

        except AttributeError:
            pass

        mat = 'None'

    if(matarr != []):
        print(matarr)
        for x in matarr:
            x = x.replace('.', 'a')
            endarr.append(x)

        getS = min(endarr)

    return getS



def main():
    Sda = input()
    T = input()
    Slen = len(Sda)
    Tlen = len(T)

    Sda = Sda.replace('?', '.')

    print(check(Sda, T, Slen, Tlen))


main()

Fixed code:
import sys
import re



def check(Sda, T, Slen, Tlen):
    matarr=[]
    endarr=[]

    getS = 'UNRESTORABLE'

    if(Slen<Tlen):
        return getS

    for i in reversed(range(0, Slen-Tlen+1)):


        mat = re.match(Sda[i:i+Tlen],T)
        try:
            if(mat.group() == T):
                matarr.append(Sda[:i]+T+Sda[i+Tlen:])

        except AttributeError:
            pass

        mat = 'None'

    if(matarr != []):
        for x in matarr:
            x = x.replace('.', 'a')
            endarr.append(x)

        getS = min(endarr)

    return getS



def main():
    Sda = input()
    T = input()
    Slen = len(Sda)
    Tlen = len(T)

    Sda = Sda.replace('?', '.')

    print(check(Sda, T, Slen, Tlen))


main()
Buggy code:
import copy
s=list(map(str,input()))
t=list(map(str,input()))
def converta(s):
  for i in range(len(s)):
    if s[i]=='?':
      s[i]='a'
  return s
res=[]
for i in range(len(s)-len(t)+1):
    c=copy.copy(s)
    ok=True
    for j in range(len(t)):
        if t[j]!=s[i+j] and s[i+j]!='?':
            ok=False
            break
        else:
            c[i+j]=t[j]
    if ok:
        res.append(converta(c))
ans=min(res)
if res==[]:
  print('UNRESTORABLE')
else:
  print(''.join(ans))

Fixed code:
import copy
s=list(map(str,input()))
t=list(map(str,input()))
def converta(s):
  for i in range(len(s)):
    if s[i]=='?':
      s[i]='a'
  return s
res=[]
for i in range(len(s)-len(t)+1):
    c=copy.copy(s)
    ok=True
    for j in range(len(t)):
        if t[j]!=s[i+j] and s[i+j]!='?':
            ok=False
            break
        else:
            c[i+j]=t[j]
    if ok:
        res.append(''.join(converta(c)))
if res==[]:
  print('UNRESTORABLE')
else:
  print(sorted(res)[0])