Problem p03565 (python)

Fixed submission:
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]


from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

s = input()
t = input()

if len(s) >= len(t):
    ans_l = []
    for i in range(0, len(s)-len(t)+1):
        s_s = s[i:len(s)-1+i]
        flag = True
        for ssi, ti in zip(s_s, t):
            if ssi == "?":
                continue
            if ssi != ti:
                flag = False
                break
        if flag:
            ans_l.append(i)

    d = []
    for ans_i in ans_l:
        tmp_s = (s[:ans_i]+t+s[len(t)+ans_i:]).replace("?", "a")
        d.append(tmp_s)
    d = sorted(d)
    if len(d) > 0:
        print(d[0])
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]


from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

s = input()
t = input()

for i in range(0, len(s)-len(t)+1):
    s_s = s[i:len(s)-1+i]
    flag = True
    for ssi, ti in zip(s_s, t):
        if ssi == "?":
            continue
        if ssi != ti:
            flag = False
            break
    if flag:
        ans_i = i
        break

if flag:
    print((s[0:ans_i]+t+s[len(s)+ans_i:]).replace("?", "a"))
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]


from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

s = input()
t = input()

for i in range(0, len(s)-len(t)+1):
    s_s = s[i:len(s)-1+i]
    flag = True
    for ssi, ti in zip(s_s, t):
        if ssi == "?":
            continue
        if ssi != ti:
            flag = False
            break
    if flag:
        ans_i = i
        break

if flag:
    print((s[0:i]+t+s[i+len(t):len(s)-len(t)-1]).replace("?", "a"))
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
# https://qiita.com/_-_-_-_-_/items/34f933adc7be875e61d0
# abcde	s=input()	s='abcde'
# abcde	s=list(input())	s=['a', 'b', 'c', 'd', 'e']
# 5(1つだけ)	a=int(input())	a=5
# 1 2	| x,y = map(int,input().split())   |	x=1,y=2
# 1 2 3 4 5 ... n 　	li = input().split()	li=['1','2','3',...,'n']
# 1 2 3 4 5 ... n 　	li = list(map(int,input().split()))	li=[1,2,3,4,5,...,n]
# FFFTFTTFF 　	li = input().split('T')	li=['FFF', 'F', '', 'FF']

# INPUT
# 3
# hoge
# foo
# bar
# ANSWER
# n=int(input())
# string_list=[input() for i in range(n)]


from collections import defaultdict, Counter
import math
from bisect import bisect_left, bisect_right
import numpy as np

s = input()
t = input()

for i in range(0, len(s)-len(t)+1):
    s_s = s[i:len(s)-1+i]
    flag = True
    for ssi, ti in zip(s_s, t):
        if ssi == "?":
            continue
        if ssi != ti:
            flag = False
            break
    if flag:
        ans_i = i
        break

if flag:
    print((s[0:i]+t+s[i:len(s)-len(t)-1]).replace("?", "a"))
else:
    print("UNRESTORABLE")