Problem:


Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.

He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.  

One more thing he found is a sheet of paper with the following facts written on it:  

Condition 1: The string S contains a string T as a contiguous substring.

Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.

Print the string S.

If such a string does not exist, print UNRESTORABLE.  

Constraints

1 \leq |S'|, |T| \leq 50

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

If such a string does not exist, print UNRESTORABLE instead.  

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

There are 26 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder.
Among them, the lexicographically smallest is atcoder, so we can say S = atcoder.

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

There is no string that satisfies Condition 1, so the string S does not exist.



Sample input:
?tc????
coder


Sample output:
atcoder

Submission status: Runtime Error

Solution code:
import re
s1 = input()
t = input()
pre = ""
count = 0
ans = ""
start = 0
end = 0
it = ""


for w in s1:
  if count > len(t) - 1:
    dif = count - (len(t) - 1)
    count -= dif
    it = it[dif:]
  print(f"count is{count}" )
  if w == t[count]:
    count += 1
    it += w
  elif pre == "?" and w == t[0]:
    count = 1
    it = w
  elif w != "?" and pre == "?":
    pre = w
    count = 0
    it = ""
  elif w == "?" and pre == "?":
    count += 1
    it += w
  else:
    if w == "?":
      pre = w
      count += 1
      it += w

print(f"count is {count}")
print(f"it is {it}")
  # if count >= len(t):
  #   print("きたよ")
  #   print(w)
  #   end = s1.index(w)
  #   start = end - len(t)
#print(f"count is {count}")
#print("endは" + end)
#replace = "?" * len(t)
#print("replace is" + it)
if count >= len(t):
  it = it.replace("?","\?")
  # 合致した最も後方のものを置換
  ans = re.sub(it,t,s1)
  ans = ans.replace("?","a")
  #print(ans)
  # if end < len(s1) - 1:
  #   ans = s1[:start] + t + s1[end+1:]
  #   # 全てaに置換
  #   ans = ans.replace("?","a")
  #   print(ans)
  # else:
  #   ans = s1[:start] + t
  #   ans = ans.replace("?","a")
  print(ans)
else:
  print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import re
s1 = input()
t = input()
pre = ""
count = 0
ans = ""
start = 0
end = 0
it = ""

for w in s1:
  if w == t[count]:
    count += 1
    it += w
  elif pre == "?" and w == t[0]:
    count += 1
    it += w
  elif w != "?" and pre == "?":
    pre = w
    count = 0
    it = ""
  elif w == "?" and pre == "?":
    count += 1
    it += w
  else:
    if w == "?":
      pre = w
      count += 1
      it += w
  # if count >= len(t):
  #   print("きたよ")
  #   print(w)
  #   end = s1.index(w)
  #   start = end - len(t)
#print(f"count is {count}")
#print("endは" + end)
#replace = "?" * len(t)
#print("replace is" + it)
if count >= len(t):
  it = it.replace("?","\?")
  # 合致した最も後方のものを置換
  ans = re.sub(it,t,s1)
  ans = ans.replace("?","a")
  #print(ans)
  # if end < len(s1) - 1:
  #   ans = s1[:start] + t + s1[end+1:]
  #   # 全てaに置換
  #   ans = ans.replace("?","a")
  #   print(ans)
  # else:
  #   ans = s1[:start] + t
  #   ans = ans.replace("?","a")
  print(ans)
else:
  print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import re
s1 = input()
t = input()
pre = ""
count = 0
ans = ""
start = 0
end = 0
it = ""

for w in s1:
  if w == t[count]:
    count += 1
    it += w
  elif pre == "?" and w == t[0]:
    count = 1
    it += w
  elif w != "?" and pre == "?":
    pre = w
    count = 0
    it = ""
  elif w == "?" and pre == "?":
    count += 1
    it += w
  else:
    if w == "?":
      pre = w
      count += 1
      it += w
  # if count >= len(t):
  #   print("きたよ")
  #   print(w)
  #   end = s1.index(w)
  #   start = end - len(t)
#print(f"count is {count}")
#print("endは" + end)
#replace = "?" * len(t)
#print("replace is" + it)
if count >= len(t):
  it = it.replace("?","\?")
  # 合致した最も後方のものを置換
  ans = re.sub(it,t,s1)
  ans = ans.replace("?","a")
  #print(ans)
  # if end < len(s1) - 1:
  #   ans = s1[:start] + t + s1[end+1:]
  #   # 全てaに置換
  #   ans = ans.replace("?","a")
  #   print(ans)
  # else:
  #   ans = s1[:start] + t
  #   ans = ans.replace("?","a")
  print(ans)
else:
  print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import re
s1 = input()
t = input()
pre = ""
count = 0
ans = ""
start = 0
end = 0
it = ""

for w in s1:
  if w == t[count]:
    count += 1
    it += w
  elif pre == "?" and w == t[0]:
    count = 1
    it = w
  elif w != "?" and pre == "?":
    pre = w
    count = 0
    it = ""
  elif w == "?" and pre == "?":
    count += 1
    it += w
  else:
    if w == "?":
      pre = w
      count += 1
      it += w
  # if count >= len(t):
  #   print("きたよ")
  #   print(w)
  #   end = s1.index(w)
  #   start = end - len(t)
#print(f"count is {count}")
#print("endは" + end)
#replace = "?" * len(t)
#print("replace is" + it)
if count >= len(t):
  it = it.replace("?","\?")
  # 合致した最も後方のものを置換
  ans = re.sub(it,t,s1)
  ans = ans.replace("?","a")
  #print(ans)
  # if end < len(s1) - 1:
  #   ans = s1[:start] + t + s1[end+1:]
  #   # 全てaに置換
  #   ans = ans.replace("?","a")
  #   print(ans)
  # else:
  #   ans = s1[:start] + t
  #   ans = ans.replace("?","a")
  print(ans)
else:
  print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import re
s1 = input()
t = input()
pre = ""
count = 0
ans = ""
start = 0
end = 0
it = ""

for w in s1:
  if w == t[count]:
    count += 1
    it += w
  elif w != "?" and pre == "?":
    pre = w
    count = 0
    it = ""
  elif w == "?" and pre == "?":
    count += 1
    it += w
  else:
    if w == "?":
      pre = w
      count += 1
      it += w
  # if count >= len(t):
  #   print("きたよ")
  #   print(w)
  #   end = s1.index(w)
  #   start = end - len(t)
#print(f"count is {count}")
#print("endは" + end)
#replace = "?" * len(t)
#print("replace is" + it)
if count >= len(t):
  it = it.replace("?","\?")
  # 合致した最も後方のものを置換
  ans = re.sub(it,t,s1)
  ans = ans.replace("?","a")
  #print(ans)
  # if end < len(s1) - 1:
  #   ans = s1[:start] + t + s1[end+1:]
  #   # 全てaに置換
  #   ans = ans.replace("?","a")
  #   print(ans)
  # else:
  #   ans = s1[:start] + t
  #   ans = ans.replace("?","a")
  print(ans)
else:
  print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import re
s1 = input()
t = input()
pre = ""
count = 0
ans = ""
start = 0
end = 0
it = ""

for w in s1:
  if w != "?" and pre == "?":
    pre = w
    count = 0
    it = ""
  elif w == "?" and pre == "?":
    count += 1
    it += w
  elif w == t[count]:
    count += 1
    it += w
  else:
    if w == "?":
      pre = w
      count += 1
      it += w
  # if count >= len(t):
  #   print("きたよ")
  #   print(w)
  #   end = s1.index(w)
  #   start = end - len(t)
#print(f"count is {count}")
#print("endは" + end)
#replace = "?" * len(t)
#print("replace is" + it)
if count >= len(t):
  it = it.replace("?","\?")
  # 合致した最も後方のものを置換
  ans = re.sub(it,t,s1)
  ans = ans.replace("?","a")
  #print(ans)
  # if end < len(s1) - 1:
  #   ans = s1[:start] + t + s1[end+1:]
  #   # 全てaに置換
  #   ans = ans.replace("?","a")
  #   print(ans)
  # else:
  #   ans = s1[:start] + t
  #   ans = ans.replace("?","a")
  print(ans)
else:
  print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    T = inputs[1]
    sn = len(S)
    tn = len(T)

    start = None

    for ti in range(tn):
        t_c = T[ti]
        for si in range(ti, sn):
            s_c = S[si]
            if (tn - ti) > (sn - si):
                return "UNRESTORABLE"
            if t_c == s_c:
                sj = si - ti
                start = sj
                for tj in range(tn):
                    sj_c = S[sj]
                    tj_c = T[tj]
                    if not (tj_c == sj_c or sj_c == '?'):
                        start = None
                        break
                    sj += 1
                if start is not None:
                    created_s = []
                    tj = 0
                    for sj in range(sn):
                        sj_c = S[sj]
                        tj_c = T[tj]
                        if sj >= start and sj <= start + tn:
                            created_s.append(tj_c)
                            tj += 1
                        else:
                            if sj_c == '?':
                                created_s.append('a')
                            else:
                                created_s.append(sj_c)
                    return ''.join(created_s)
    return "UNRESTORABLE"


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
import re
No = "UNRESTORABLE"

def main():
    S = input()
    T = input()
    T_LEN = len(T)
    match_index = []

    for i in range(len(S) - T_LEN + 1):
        for idx in range(T_LEN):
            if S[i:i+T_LEN][idx] == T[idx] or S[i:i+T_LEN][idx] == "?":
                continue
            else:
                break
        else:
            match_index.append(i)
    
    if not match_index:
        print(No)
    
    else:
        answer = list(S)
        answer[match_index[0]:match_index[0] + T_LEN] = list(T)
        answer = "".join(answer)

        if len(match_index) == 1:
            answer = answer.replace("?","a")
            print(answer)

        else:
            for i in match_index[1:]:
                tmp_ans = answer = list(S)
                tmp_ans[match_index[i]:match_index[i] + T_LEN] = list(T)
                tmp_ans = "".join(tmp_ans)
                tmp_ans = tmp_ans.replace("?","a")
                answer = min(tmp_ans,answer)

            print(answer)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[j]!=t[j] and s[j]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    #print(0)
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    #print(0)
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    print(0)
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))

Submission status: Runtime Error

Solution code:
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[j]!=t[j] and s[j]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    print(0)
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    #print(0)
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))

Submission status: Runtime Error

Solution code:
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[j]!=t[j] and s[j]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    print(0)
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))

Submission status: Runtime Error

Solution code:
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[j]!=t[j] and s[j]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))

Submission status: Runtime Error

Solution code:
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[j]!=t[j-i] and s[j]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))

Submission status: Runtime Error

Solution code:
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[j]!=t[j-i] and s[j]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    x=0
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                x=1
                break
            if j==i+lt-1:
                if i==0:
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))
    if x==0:
        print(min(sa))
    else:
        print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
def slove():
    import sys
    import bisect
    import collections
    import fractions
    import heapq
    import itertools
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    t = str(input().rstrip('\n'))
    if len(t) <= len(s):
        for i in range(len(s) - len(t), -1, -1):
            b = True
            for j in range(len(t)):
                if s[i+j] != t[j] and s[i+j] != "?":
                    b = False
                    break
            if b:
                ls = []
                for j in range(len(s)):
                    if j < i:
                        if s[j] != "?":
                            ls.append(s[j])
                        else:
                            ls.append("a")
                    else:
                        ls.append(t[j-i])
                print("".join(ls))
                exit()
    print("UNRESTORABLE")


if __name__ == '__main__':
    slove()

Submission status: Runtime Error

Solution code:
def slove():
    import sys
    import bisect
    import collections
    import fractions
    import heapq
    import itertools
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    t = str(input().rstrip('\n'))
    for i in range(len(s) - len(t), -1, -1):
        b = True
        for j in range(len(t)):
            if s[i+j] != t[j] and s[i+j] != "?":
                b = False
                break
        if b:
            ls = []
            for j in range(len(s)):
                if j < i:
                    if s[j] != "?":
                        ls.append(s[j])
                    else:
                        ls.append("a")
                else:
                    ls.append(t[j-i])
            print("".join(ls))
            exit()
    print("UNRESTORABLE")


if __name__ == '__main__':
    slove()

Submission status: Runtime Error

Solution code:
def slove():
    import sys
    import bisect
    import collections
    import fractions
    import heapq
    import itertools
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    t = str(input().rstrip('\n'))
    for i in range(len(s) - len(t), -1, -1):
        b = True
        for j in range(len(t)):
            print(s[i + j], t[j])
            if s[i+j] != t[j] and s[i+j] != "?":
                b = False
                break
        if b:
            ls = []
            for j in range(len(s)):
                if j < i:
                    if s[j] != "?":
                        ls.append(s[j])
                    else:
                        ls.append("a")
                else:
                    ls.append(t[j-i])
            print("".join(ls))
            exit()
    print("UNRESTORABLE")


if __name__ == '__main__':
    slove()

Submission status: Runtime Error

Solution code:
def slove():
    import sys
    import bisect
    import collections
    import fractions
    import heapq
    import itertools
    input = sys.stdin.readline
    s = str(input().rstrip('\n'))
    t = str(input().rstrip('\n'))
    for i in range(len(s) - len(t), -1, -1):
        b = True
        for j in range(len(t)):
            if s[i+j] != t[j] and s[i+j] != "?":
                b = False
                break
        if b:
            ls = []
            for j in range(len(s)):
                if j < i:
                    if s[j] != "?":
                        ls.append(s[j])
                    else:
                        ls.append("a")
                else:
                    ls.append(t[j-i])
            print("".join(ls))
    print("UNRESTORABLE")


if __name__ == '__main__':
    slove()

Submission status: Runtime Error

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()

if S.count(T) != 0:
    S = S.replace('?', 'a')
    print(S)
    sys.exit()

for i in range(len(S)):
    tmp = True
    s = i
    e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break

    if tmp:
        break
    else:
        s = -1
        e = -1
if s == -1:
    print(ans)
else:
    ans = S.replace('?', 'a')
    ans = ans[:s] + T + ans[e:]
    print(ans)

Submission status: Runtime Error

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'
if S.count(T) != 0:
    S = S.replace('?', 'a')
    print(S)
    sys.exit()

for i in range(len(S) - len(T) + 1):
    tmp = True
    s = i
    e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break

    if tmp:
        break
    else:
        s = -1
        e = -1
if s == -1:
    print(ans)
else:
    ans = S.replace('?', 'a')
    ans = ans[:s] + T + ans[e:]
    print(ans)

Submission status: Runtime Error

Solution 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)

Submission status: Runtime Error

Solution 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(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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
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)

Submission status: Runtime Error

Solution code:
sd = input()
t = input()
li_answer = list()
c_loop = len(sd) - len(t) + 1

for i in range(c_loop):
    if all((w_sd == "?" or w_sd == w_t) for w_sd, w_t in zip(sd[i:i + len(t) + 1], t)):
        s_tmp = str(sd[0:i] + t + sd[i + len(t):]).replace("?", "a")
        li_answer.append(s_tmp)

if li_answer:
    print(sorted(li_answer)[0])
else:
    print("UNRESTORABLE")


                                            ｋ

Submission status: Runtime Error

Solution code:
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))

Submission status: Runtime Error

Solution code:
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 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:
    print("UNRESTORABLE")
else:
    print("".join(ans))

Submission status: Runtime Error

Solution code:
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 det == 0:
        ans = [0] * 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:
    print("UNRESTORABLE")
else:
    print("".join(ans))

Submission status: Runtime Error

Solution code:
import sys
import os
S = input()
T = input()
cnt = 0 #Tで置き換える必要のある?の個数
i = 1
j = 1
while j < len(S):
    if T[-i] == S[-j]:
        i += 1
    elif S[-j] == "?":
        i += 1
        cnt += 1
    else:
        i, cnt = 1, 0
    j += 1
    if i == len(T) and (T[-i] == S[-j] or S[-j] == "?"):
        for l in range(len(S)):
            if S[l] == "?" and (l <= len(S)-j-1 or len(S)-j-1+len(T) < l):
                print("a",end="")
            elif S[l] == "?":
                print(T[-cnt-1],end="")
                cnt -= 1
            else:
                print(S[l],end="")
        print()
        sys.exit()
print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import sys
import os

S = input()
T = input()
cnt = 0 #Tで置き換える必要のある?の個数
i = 1
j = 1
while j < len(S):
    if T[-i] == S[-j] or S[-j] == "?":
        i += 1
        cnt += 1
    else:
        i, cnt = 1, 1
    j += 1
    if i == len(T) and (T[-i] == S[-j] or S[-j] == "?"):
        for l in range(len(S)):
            if S[l] == "?" and (l <= len(S)-j-1 or len(S)-j-1+len(T) < l):
                print("a",end="")
            elif S[l] == "?":
                print(T[-cnt],end="")
                cnt -= 1
            else:
                print(S[l],end="")
        print()
        sys.exit()
print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import sys
import os
S = input()
T = input()
cnt = 0 #Tで置き換える必要のある?の個数
i = 1
j = 1
while j < len(S):
    if T[-i] == S[-j] or S[-j] == "?":
        i += 1
        cnt += 1
    else:
        i, cnt = 1, 1
    j += 1
    if i == len(T) and (T[-i] == S[-j] or S[-j] == "?"):
        for l in range(len(S)):
            if S[l] == "?" and (l <= len(S)-j-1 or len(S)-j-1+len(T) < l):
                print("a",end="")
            elif S[l] == "?":
                print(T[-cnt],end="")
                cnt -= 1
            else:
                print(S[l],end="")
        print()
        sys.exit()
print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import sys
S = input()
T = input()
cnt = 0 #Tで置き換える必要のある?の個数
i = 0
j = 0
while j < len(S):
    if T[-i] == S[-j] or S[-j] == "?":
        i += 1
        cnt += 1
    else:
        i, cnt = 0, 0
    j += 1
    if i == len(T) and (T[-i] == S[-j] or S[-j] == "?"):
        l = 0
        for l in range(len(S)):
            if S[l] == "?" and l <= len(S)-j-1:
                print("a",end="")
            elif S[l] == "?":
                print(T[-cnt+1],end="")
                cnt -= 1
            else:
                print(S[l],end="")
        print()
        sys.exit()
print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:

S = input()
T = input()

ans = "UNRESTORABLE"
if len(T)>len(S):
    ans = "UNRESTORABLE"
else:
    Slr = list(S[::-1])
    Tlr = list(T[::-1])
    
    for i in range(len(S)-len(T)+1):
        flag = True
        for j in range(len(T)):
            if Slr[i+j]==Tlr[j] or Slr[i+j]=="?":
                pass
            else:
                flag = False
                break
        if flag:
            for j in range(len(T)):
                Slr[i+j] = Tlr[j]
            for j in range(len(S)):
                if Slr[i+j]=="?":
                    Slr[i+j] = "a"
            ans = ("".join(Slr[::-1]))
            break
        else:
            if i==len(S)-len(T):
                ans = "UNRESTORABLE"
                break
print(ans)

Submission status: Runtime Error

Solution code:

S = input()
T = input()

if len(T)>len(S):
    ans = "UNRESTORABLE"
else:
    Slr = list(S[::-1])
    Tlr = list(T[::-1])
    
    for i in range(len(S)-len(T)+1):
        flag = True
        for j in range(len(T)):
            if Slr[i+j]==Tlr[j] or Slr[i+j]=="?":
                pass
            else:
                flag = False
                break
        if flag:
            for j in range(len(T)):
                Slr[i+j] = Tlr[j]
            for j in range(len(S)):
                if Slr[i+j]=="?":
                    Slr[i+j] = "a"
            ans = ("".join(Slr[::-1]))
            break
        else:
            if i==len(S)-len(T):
                ans = "UNRESTORABLE"
                break
print(ans)