Problem p03565 (python)

Fixed submission:
S = input()
T = input()
if len(S) < len(T):
    print("UNRESTORABLE")
    exit()
for i in range(len(S) - len(T), -1, -1):
    for s, t in zip(S[i:i+len(T)], T):
        if s != "?" and s != t:
            break
    else:
        S = list(S)
        S[i:i+len(T)] = list(T)
        S = "".join(S).replace("?", "a")
        print(S)
        exit()
print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)


f n < m:
    print("UNRESTORABLE")
    exit()

for i in range(n - m + 1):
    flag = True
    for j in range(m):
      if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
        flag = False
        break
    if flag:
      ans = list(s_dash)
      ans[i:i+m] = list(t)
      ans = "".join(ans).replace("?", "a")
      print(ans)
      exit()
      
print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s_dash = input()
t = input()
n = len(s)
m = len(t)

for i in range(n - m + 1):
    flag = True
    for j in range(m):
      if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
        flag = False
        break
    if flag:
      ans = list(s_dash)
      ans[i:i+m] = list(t)
      ans = "".join(ans).replace("?", "a")
      print(ans)
      exit()
      
print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s_dash = input()
t = input()
n = len(s)
m = len(t)

for i in range(n - m + 1):
    flag = True
    for j in range(m):
      if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
        flag = False
        break
    if flag:
      ans = list(s_dash)
      ans[i:i+m] = list(t)
      ans = "".join(ans).replace("?", "a")
      print(ans)
      exit()
      
print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s = input()
t = input()
n = len(s)
m = len(t)

for i in range(n - m + 1):
    flag = True
    for j in range(m):
      if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
        flag = False
        break
    if flag:
      ans = list(s_dash)
      ans[i:i+m] = list(t)
      ans = "".join(ans).replace("?", "a")
      print(ans)
      exit()
      
print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
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:
        ans.append(s[:i].replace('?', 'a') + t + s[i+m:].replace('?', 'a'))
if ans == []:
    print('UNRESTORABLE')
else:
    ans.sort()
    print(ans[0])
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:
        ans.append(s[:i].replace('?', 'a') + t + s[i+m:].replace('?', 'a'))
if ans == []:
    print('UNRESTORABLE')
else:
    ans.sort()
    print(ans[0])

Buggy submission (verdict: Runtime Error):
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)


if n < m:
    print("UNRESTORABLE")
    exit()


for i in range(n - m + 1):
    flag = True
    for j in range(m):
        if s_dash[i+j] != '?' and s_dash[i+j] != t[j]:
            flag = False
            break
    if flag:
    #範囲外をaに置き換える
    ans = list(s_dash)
    ans[i:i+m] = list(t)
    ans = "".join(ans).replace("?", "a")
    print(ans)
    exit()
        
      
print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)


if n < m:
    print("UNRESTORABLE")
    exit()

ans = []
for i in range(n-m+1):
  flag = True
  for j in range(m):
    if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
    if s_dash[i+j] != '?' and s_dash[i+j] != t[j]:
      flag = False
      break

  if flag:
    #範囲外をaに置き換える
    ans.append(s_dash[:i].replace("?", "a") + t + s_dash[i+m:].replace("?", "a"))
    ans.sort()
    print(ans[0])
    #print("".join(ans))
    exit()
        
      
print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
s_dash = input()
t = input()


ans = []
for i in range(len(s_dash)-len(t)+1):
  flag = True
  for j in range(len(t)):
    if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
      flag = false
      break

  if flag:
    #範囲外をaに置き換える
    ans.append(s_dash[:i].replace("?", "a") + t + s_dash[i+len(t):].replace("?", "a"))
    print("".join(ans))
    exit()
        
      
print("UNRESTORABLE")