Problem p03565 (python)

Fixed submission:
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 submission (verdict: Runtime Error):
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)

Buggy submission (verdict: Runtime Error):
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(start):
      if w[i]=="?":
        word+="a"
      else:
        word+=w[i]
    for i in range(start,num):
      word+=w1[i-start]
  else:
    word+=w1
    for i in range(num1,num):
      if w[i]=="?":
        word+="a"
      else:
        word+=w[i]
  print(word)

Buggy submission (verdict: Runtime Error):
w=input()
w1=input()
num=len(w)
num1=len(w1)
if num<num1:
  b=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
      break
if not b:
  print("UNRESTORABLE")
else:
  word=""
  if start!=0:
    for i in range(start):
      if w[i]=="?":
        word+="a"
      else:
        word+=w[i]
    for i in range(start,num):
      word+=w1[i-start]
  else:
    word+=w1
    for i in range(num1,num):
      if w[num]=="?":
        word+="a"
      else:
        word+=w[num]
  print(word)

Buggy submission (verdict: Runtime Error):
w=input()
w1=input()
num=len(w)
num1=len(w1)
if num<num1:
  b=False
for i in range(num-num1+1):
  b=True
  for j in range(i,i+num1):
    if w[i+j]=="?" or w[i+j]==w1[j]:
      pass
    else:
      b=False
  if b:
      start=i
      break
if not b:
  print("UNRESTORABLE")
else:
  word=""
  if start!=0:
    for i in range(start):
      if w[i]=="?":
        word+="a"
      else:
        word+=w[i]
    for i in range(start,num):
      word+=w1[i-start]
  else:
    word+=w1
    for i in range(num1,num):
      if w[num]=="?":
        word+="a"
      else:
        word+=w[num]
  print(word)

Buggy submission (verdict: Runtime Error):
w=input()
w1=input()
num=len(w)
num1=len(w1)
for i in range(num-num1+1):
  b=True
  for j in range(i,i+num1):
    if w[i+j]=="?" or w[i+j]==w1[j]:
      pass
    else:
      b=False
  if b:
      start=i
      break
if not b:
  print("UNRESTORABLE")
word=""
else:
  if start!=0:
    for i in range(start):
      if w[i]=="?":
        word+="a"
      else:
        word+=w[i]
    for i in range(start,num):
      word+=w1[i-start]
  else:
    word+=w1
    for i in range(num1,num):
      if w[num]=="?":
        word+="a"
      else:
        word+=w[num]
  print(word)

Buggy submission (verdict: Runtime Error):
S = list(str(input()))
T = list(str(input()))
s = len(S)
t = len(T)

for i in range(t,s+1):
    det = 0
    for j in range(t):
        if S[-i+j] != T[j] and S[-i+j] != "?":
            det = -1
            break
    if s<t:
      det=2
    if det == 0:
        ans = ["X"] * s
        for k in range(t):
            ans[-i+k] = T[k]
        for l in range(s-i):
            if S[l] == "?":
                ans[l] = "a"
            else:
                ans[l] = S[l]
        for l in range(s-i+t,s):
            if S[l] == "?":
                ans[l] = "a"
            else:
                ans[l] = S[l]
        break
if det == -1 or det==2:
    print("UNRESTORABLE")
    
else:
    print("".join(ans))