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: Accepted

Solution code:
s1 = input()
t = input()

ans = list("UNRESTORABLE")
for i in range(len(s1) - len(t), -1, -1):
    if all(list(map(lambda j: s1[i + j] == '?' or s1[i + j] == t[j], range(len(t))))):
        ans = list(s1)
        for j in range(len(t)):
            ans[i + j] = t[j]
        for j in range(len(s1)):
            if ans[j] == '?':
                ans[j] = 'a'
        break

print(''.join(ans))

Submission status: Accepted

Solution code:
#!/usr/bin/env python
#-*- coding: utf-8 -*-

from collections import defaultdict
from math import factorial as f
from fractions import gcd as g

s = raw_input ()
t = raw_input ()
w = s

def solve (s, t):
    if len (t) > len (s): return -1
    N = len (s)
    s += "*" * 50
    ret = -1
    for i in range (N):
        ok = True
        for j in range (len (t)):
            if s [i + j] == "?": continue
            if s [i + j] == t [j]: continue
            ok = False
            break
        if ok:
            ret = max (ret, i)
    return ret

x = solve (s, t)
if x != -1:
    w = w [:x] + t + w [x + len (t):]
    w = w.replace ("?", "a")
    print w
else:
    print "UNRESTORABLE"

Submission status: Accepted

Solution code:
# coding: utf-8
def get_ln_inputs():
    return input().split()


def map_list(fn, xs):
    return list(map(fn, xs))


def get_ln_int_inputs():
    return map_list(int, get_ln_inputs())


def possible_to_insert(S, T, index):
    if index + len(T) > len(S):
        return False
    for i in range(len(T)):
        if S[index + i] != "?" and S[index + i] != T[i]:
            return False
    return True


def main():
    S = get_ln_inputs()[0]
    T = get_ln_inputs()[0]

    ins_idx = -1
    for i in range(len(S)):
        if possible_to_insert(S, T, i):
            ins_idx = i

    if ins_idx == -1:
        print("UNRESTORABLE")
        return

    S = S[:ins_idx] + T + S[ins_idx + len(T):]
    print(S.replace("?", "a"))

    return


main()

Submission status: Accepted

Solution code:
S = input()
T = input()
ss = []
for i in range(0, len(S) - len(T) + 1):
    for j in range(len(T)):
        if S[i+j] not in ('?', T[j]):
            break
    else:
        s = S[:i] + T + S[i+len(T):]
        ss.append(s.replace('?', 'a'))
if ss:
    print(min(ss))
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:

def match(s_, t_):
    for s__, t__ in zip(s_, t_):
        if s__ == '?':
            continue

        if s__ != t__:
            return False

    return True


s = input()
t = input()

lens = len(s)
lent = len(t)

cnds = []

for i in range(lens-lent+1):
    if match(s[i:i+len(t)], t):
        # print(s[i:i+len(t)])
        # print(t)
        matched = s[:i] + t + s[i+len(t):]
        matched = matched.replace('?', 'a')
        cnds.append(matched)

if len(cnds) == 0:
    print('UNRESTORABLE')

else:
    print(list(sorted(cnds))[0])

Submission status: Accepted

Solution code:
S = raw_input()
T = raw_input()
ans = "z"*100
for i in range(len(S)-len(T)+1):
    ok = True
    for j in range(len(T)):
        if S[i+j]!="?" and S[i+j]!=T[j]:
            ok = False
    if ok:
        s = S[:i]+T+S[i+len(T):]
        ans = min(ans, s.replace("?", "a"))
if ans=="z"*100:
    print "UNRESTORABLE"
else:
    print ans

Submission status: Accepted

Solution code:
Sp = input()
T= input()
flag =False
ans_list = []
for i,s in enumerate(Sp):
    if i> len(Sp) - len(T):
        break
    for j,t in enumerate(T):
        if Sp[i+j]==t or Sp[i+j] =="?":
            flag=True
            continue
        else:
            flag =False
            break
    if flag:
        ans_list.append(i)

#print(ans_list)
n_ans_list = []
for i in ans_list:
    n_ans_list.append(
        (Sp[:i]+ T+Sp[i+len(T):]).replace("?","a"))
#print(n_ans_list)
n_ans_list.sort()
if n_ans_list:
    print(n_ans_list[0])
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = list(ns().strip())
t = ns().strip()


def ok(s, t):
    if len(s) < len(t):
        return False
    for i in range(len(s) - len(t) + 1):
        o = 1
        for j in range(len(t)):
            if s[i + j] != '?' and s[i + j] != t[j]:
                o = 0
        if o == 1:
            return True
    return False


if not ok(s, t):
    print("UNRESTORABLE")
    sys.exit(0)

for i in range(len(s)):
    if s[i] == '?':
        for j in range(97,97+26):
            s[i] = chr(j)
            if ok(s, t):
                break

print("".join(s))

Submission status: Accepted

Solution code:
S = raw_input()
T = raw_input()
N = len(S)
M = len(T)
ans = '{'

for i in xrange(N-M+1):
    if all(S[i+j] == T[j] or S[i+j] == '?' for j in xrange(M)):
        tmp = list(S)
        for j in xrange(M):
            tmp[i+j] = T[j]
        tmp = ''.join(tmp)
        tmp = tmp.replace('?', 'a')
        ans = min(ans, tmp)

print ans if ans != '{' else 'UNRESTORABLE'

Submission status: Accepted

Solution code:
s = input().strip()
t = input().strip()

candidates = []
for i in range(len(s) - len(t) + 1):
    tfr = i
    tto = i + len(t)
    u = ''
    ok = True
    for p in range(len(s)):
        if tfr <= p < tto:
            if s[p] in ['?', t[p - i]]:
                u += t[p - i]
            else:
                ok = False
                break
        else:
            if s[p] == '?':
                u += 'a'
            else:
                u += s[p]
    if ok:
        candidates.append(u)

if candidates:
    print(min(candidates))
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    sa = ''
    for c in s:
        if c == '?':
            sa += 'a'
        else:
            sa += c
    t = S()
    r = None
    l = len(t)
    for i in range(len(s)-l+1):
        f = True
        for j in range(l):
            if s[i+j] != '?' and s[i+j] != t[j]:
                f = False
                break
        if f:
            tr = sa[:i] + t + sa[i+j+1:]
            if not r or r > tr:
                r = tr

    if not r:
        return 'UNRESTORABLE'
    return r


print(main())

Submission status: Runtime Error

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

S = v()
T = v()
len_s = len(S)
len_t = len(T)
check = False
ans = []

if len_s<len_t:
    print("UNRESTORABLE")
    sys.exit()

for i in range(len_s):
    if S[i] == "?":
        cnt += 1
        if cnt >= len_t:
            aaa = S.replace("?","a")
            ans.append(aaa[:i-len_t+1]+T+aaa[i+1:])
    elif S[i] in T:
        cnt = 0
        place = T.index(S[i])
        a = i
        for j in range(a-place,len_t+a-place):
            if T[j-(a-place)] == S[j] or S[j] == "?":
                check = True
            else:
                check = False
                continue
        if check:
            aaa = S.replace("?","a")
            ans.append(aaa[:i-place]+T+aaa[i+len_t:])
    else:
        cnt = 0

if len(ans)>0:
    ans.sort()
    print(ans[0])
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

S = v()
T = v()
len_s = len(S)
len_t = len(T)
check = False
ans = []

if len_s<len_t:
    print("UNRESTORABLE")
    sys.exit()

for i in range(len_s):
    if S[i] == "?":
        cnt += 1
        if cnt >= len_t:
            aaa = S.replace("?","a")
            ans.append(aaa[:i-len_t]+T+aaa[i:])
    if S[i] in T:
        cnt = 0
        place = T.index(S[i])
        a = i
        for j in range(a-place,len_t+a-place):
            if T[j-(a-place)] == S[j] or S[j] == "?":
                check = True
            else:
                check = False
                continue
        if check:
            aaa = S.replace("?","a")
            ans.append(aaa[:i-place]+T+aaa[i+len_t:])
    else:
        cnt = 0
if ans:
    ans.sort()
    print(ans[0])
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

for i in range(ls-lt,-1,-1):
  f=True
  for j in range(lt):
    if not(s[i+j]=="?" or s[i+j]==t[j]):
      f=False
      break
  if f:
    ns=s[:i]+t+s[i+lt:]
    print("".join(map(lambda x:"a" if x=="?" else x,list(ns))))
    break
if not f:
  print("UNRESTORABLE")

Submission status: Runtime Error

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

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

for i in range(ls-lt+1):
    for j in range(lt):
        if S[i] != "?" and S[i] != T[j]:
            break
    else:
       left = i

ans = S[:i]+T+S[i+lt:]
print(ans.replace("?","a"))

Submission status: Runtime Error

Solution code:
S = input()
T = input()
def solve(i):
  flag = True
  for j in range(len(T)):
    if i+j < len(S) and (S[i+j] == "?" or S[i+j] == T[j]):
      continue
    else:
      flag = False
      break
  return flag

for i in range(len(S)):
  if solve(i):
    ansind = i
if ansind:
  ans = S[:ansind] + T + S[ansind+len(T):]
  ans = ans.replace("?", "a")
else:
  ans = "UNRESTORABLE"
print(ans)

Submission status: Runtime Error

Solution code:
s=list(input())
ls=len(s)
t=list(input())
lt=len(t)
can=set()
for i in range(ls-lt,-1,-1):
    ok=0
    for j in range(lt):
        if s[i+j]==t[j] or s[i+j]=='?':
            ok+=1
    if ok==lt:
        c=s
        for k in range(ls):
            if c[k]=='?':
                if k<i:
                    c[k]='a'
                else:
                    c[k]=t[k-i]
        can.add(''.join(c))
if len(can)==0:
    print('UNRESTORABLE')
else:
    print(list(can)[0])

Submission status: Runtime Error

Solution code:
s=list(input())
ls=len(s)
t=list(input())
lt=len(t)
clear=0
for i in range(ls-lt,-1,-1):
    ok=0
    for j in range(lt):
        if s[i+j]==t[j] or s[i+j]=='?':
            ok+=1
    if ok==lt:
        clear=1
        break
if clear==0:
    print('UNRESTORABLE')
else:
    for k in range(ls):
        if s[k]=='?':
            if k<i:
                s[k]='a'
            else:
                s[k]=t[k-i]
    print(''.join(s))

Submission status: Runtime Error

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


def LI(): return list(map(int, sys.stdin.buffer.readline().split()))

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    s = S()
    t = S()
    ans = ""

    for i in range(len(s) - len(t), -1, -1):
        flg = 1
        clipped = s[i:i+len(t)]
        for j in range(len(t)):
            if clipped[j] != t[j] and clipped[j] != "?":
                flg = 0
                break
        if flg:
            ans = s[:i].replace("?", "a") + t + s[i + len(t):]
            break

    if not flg:
        print("UNRESTORABLE")
        return
    print(str(ans))


if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
sd = input()
t = input()

for i in range(len(sd) - len(t) + 1):
    cnt = 0
    q = 0
    for j in range(len(t)):
        if sd[i + j] == '?':
            q += 1
            continue
        if sd[i + j] == t[j]:
            cnt += 1
    if cnt == len(t) - q:
        idx = i
        s = sd[:idx] + t + sd[idx + len(t) + 1:]
        for k in range(len(sd)):
            if s[k] == '?':
                s = s[:k] + 'a' + s[k + 1:]
                print(s)
        break
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
s = input()
n = len(s)
t = input()
m = len(t)

if n < m:
    print("UNRESTORABLE")
    exit()
p = False
for i in reversed(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:
        s = s[:i] + t
        p = True
        break

if not p:
    print("UNRESTORABLE")
    exit()
elif p:
    for i in range(n):
        if s[i] == "?":
            s = s[:i] + "a" + s[i+1:]
print(s)

Submission status: Runtime Error

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    s = input() # 暗号
    t = input() # 含まれる文字

    s_len = len(s)
    t_len = len(t)

    for i in range(s_len - t_len,-1,-1):
        flg = True
        for j in range(t_len):
            if s[i+j] != t[j] and s[i+j] != "?":
                flg = False
                break
        if flg == True:
            flg = i
            break

    if flg == False:
        print("UNRESTORABLE")
        exit()

    ans = ""
    for i in s[:flg]:
        if i == "?":
            ans = ans + "a"
        else:
            ans = ans + i
    ans = ans + t

    for i in s[(flg+t_len):]:
        if i == "?":
            ans = ans + "a"
        else:
            ans = ans + i

    print(ans)














if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
import math
from math import gcd,pi,sqrt
INF = float("inf")

import sys
sys.setrecursionlimit(10**6)
import itertools
from collections import Counter,deque
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]


def main():
    s = input() # 暗号
    t = input() # 含まれる文字

    s_len = len(s)
    t_len = len(t)

    for i in range(s_len - t_len,-1,-1):
        flg = True
        for j in range(t_len):
            if s[i+j] != t[j] and s[i+j] != "?":
                flg = False
                break
        if flg == True:
            flg = i
            break

    if flg == False:
        print("UNRESTORABLE")
        exit()

    ans = ""
    for i in s[:flg]:
        if i == "?":
            ans = ans + "a"
        else:
            ans = ans + i
    ans = ans + t
    print(ans)

    for i in s[(flg+t_len):]:
        if i == "?":
            ans = ans + "a"
        else:
            ans = ans + i

    print(ans)














if __name__=="__main__":
    main()

Submission status: Runtime Error

Solution code:
import sys

a,b = [input() for i in range(2)]

length = abs(len(a)-len(b))

for i in range(length+1):
    right_length = length - i
    temp = '?'*i+b+'?'*right_length
    
    #判定
    judge = 0
    for j in range(len(a)):
        if a[j] == temp[j] or temp[j] == '?':
            judge += 1
        elif temp[j] != '?' and a[j] == '?':
            judge += 1
    if judge == len(a):
        S = ''
        for k in range(len(temp)):
            if temp[k] == '?':
                S += a[k]
            else:
                S += temp[k]
        
        print(S.replace('?','a'))
        sys.exit()


print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
a,b = [input() for i in range(2)]

length = abs(len(a)-len(b))

for i in range(length+1):
    right_length = length - i
    temp = '?'*i+b+'?'*right_length
    
    #判定
    judge = 0
    for j in range(len(a)):
        if a[j] == temp[j] or temp[j] == '?':
            judge += 1
        elif temp[j] != '?' and a[j] == '?':
            judge += 1
    if judge == len(a):
        S = ''
        for k in range(len(temp)):
            if temp[k] == '?':
                S += a[k]
            else:
                S += temp[k]
        
        print(S.replace('?','a'))
        exit()

    else:
        continue

print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python

sp = input()
t = input()

n = len(sp)
m = len(t)

ok = False
ii = 0 
for i in range(n-m+1):
    for j in range(m):
        if sp[i+j] != '?' and sp[i+j] == t[j]:
            ok = True
            ii = i 
            break
    if ok: 
        break

if not ok: 
    print('UNRESTORABLE')
    exit()

sp = sp[:ii] + t + sp[ii+m+1:]
sp = list(sp)
for i in range(n):
    if sp[i] == '?':
        sp[i] = 'a' 

sp = ''.join(sp)
print(sp)

Submission status: Runtime Error

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

n=len(s)
m=len(t)

sentou=-1
def func(s,t,i):
    if i+m>n:
        return False
    check=0
    for j in range(i,i+m):
        if s[j]==t[j-i] or s[j]=="?":
            check+=1
    if check==m:
        return True
    return False

for i in range(n):
    if func(s,t,i):
        sentou=i

ans=[]
if sentou==-1:
    print("UNRESTORABLE")
else:

    for i in range(n):
        if i>sentou and i<=sentou+m:
            ans.append(t[i-sentou])
        else:
            if s[i]=="?":
                ans.append("a")
            else:
                ans.append(s[i])
    print("".join(ans))

Submission status: Runtime Error

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

n=len(s)
m=len(t)

sentou=-1
def func(s,t,i):
    if i+m>n:
        return False
    check=0
    for j in range(i,i+m):
        if s[j]==t[j-i] or s[j]=="?":
            check+=1
    if check==m:
        return True
    return False

for i in range(n):
    if func(s,t,i):
        sentou=i

ans=[]
if sentou==-1:
    print("UNRESTORABLE")
else:

    for i in range(n):
        if i>sentou and i<=sentou+m:
            ans.append(t[i-sentou])
        else:
            if s[i]=="?":
                ans.append("a")
            else:
                ans.append(s[i])
    print(ans)

Submission status: Runtime Error

Solution code:
import re
S,T=open(0)
S=S.replace('?','.')
s=len(S)
t=len(T)
B='z'*s
c=0
for i in range(s-t+1):
 if re.search(S[i:i+t],T):A=min(A,(S[:i]+T+S[i+t:]).replace('.','a'));c=1
print(A if c else 'UNRESTORABLE')

Submission status: Runtime Error

Solution code:
s = input()
t = input()
s_length = len(s)
t_length = len(t)

ans = ''
keep = ''
check = False
ans_remind = 0

for i in range(s_length):
    if s[i] == t[0]:
        check2 = True
        for j in range(t_length):
            if (s[i + j] != t[j]) & (s[i + j] != '?'):
                check2 = False
        if check2:
            check = True
            ans = keep + t
            ans_remind = i + t_length

    if s[i] == '?':
        keep += 'a'
        i += 1
    else:
        keep += s[i]
        i += 1

ans = ans + keep[ans_remind:]
if check:
    print(ans)
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

lt=len(T)
ls=len(S)
S+='%'*lt

for i in range(ls-lt+1):
    # print('***',S[i:i+lt])
    flg=1
    for j in range(i,i+lt):
        s=S[j]
        # print(s,T[j-i])
        if s=='?': continue
        if s=='%' or s!=T[j-i]:
            flg=0
            break
    if flg==1:
        break
if flg:
    print((S[0:i]+T+S[i+lt:ls]).replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
import re

S_hint = input()
T = input()

ans = []
for i in range(len(T)):
    num = S_hint.count(T[i])
    if num == 0:
        continue
    else:
        index = []
        p = -1
        for j in range(num):
            q = S_hint[p+1:].index(T[i])+p+1
            index.append(q)
            p = q
        for j in index:
            points = 0
            for k in range(-i, len(T)-i):
                if S_hint[j+k] == '?' or S_hint[j+k] == T[i+k]:
                    points += 1
            if points == len(T):
                S = re.sub(r'\?','a',S_hint[:j-i])+T+re.sub(r'\?','a',S_hint[j+len(T)-i+1:])
                ans.append(S)
ans.sort()
if len(ans) != 0:
    print(ans[0])
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
Sp = input()
T = input()

if len(T) > len(Sp):
	print("UNRESTORABLE")
	exit()
	
oklist = []
for i in range(len(Sp) - len(T), -1,Sp = input()
T = input()

if len(T) > len(Sp):
	print("UNRESTORABLE")
	exit()
	
oklist = []
for i in range(len(Sp) - len(T), -1, -1):
	for j in range(len(T)):
		if Sp[i + j] != "?" and Sp[i + j] != T[j]:
			break
	else:
		okpre = ["a" if Sp[k] == "?" else Sp[k] for k in range(i)]
		oksuf = ["a" if Sp[k] == "?" else Sp[k] for k in range(i + len(T), len(Sp))] 
		oklist.append("".join(okpre) + T + "".join(oksuf))

if oklist:
	print(min(oklist))
else:
	print("UNRESTORABLE") -1):
	for j in range(len(T)):
		if Sp[i + j] != "?" and Sp[i + j] != T[j]:
			break
	else:
		print(i)
		okpre = ["a" if Sp[k] == "?" else Sp[k] for k in range(i)]
		oksuf = ["a" if Sp[k] == "?" else Sp[k] for k in range(i + len(T), len(Sp))] 
		oklist.append("".join(okpre) + T + "".join(oksuf))

if oklist:
	print(min(oklist))
else:
	print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S=str(input())
T=str(input())
ls=len(S)
lt=len(T)

ans=''
flag=0
for i in range(ls-lt,-1,-1):
  flag=0
  for j in range(lt):
    if not (S[i+j] == T[j] or S[i+j] == '?'):
      flag=1
      break
  if flag==0:
    loc=i
    flag=0
    break

if flag==1:
  print('UNRESTORABLE')
else:
  i=0
  while i<ls:
    if i==loc:
      ans += T
      i += lt
    elif S[i] == '?':
      ans += 'a'
      i += 1
    else:
      ans += S[i]
      i += 1
  print(ans)

Submission status: Runtime Error

Solution code:
S=str(input())
T=str(input())
ls=len(S)
lt=len(T)

ans=''
flag=0
for i in range(ls-lt,-1,-1):
  flag=0
  for j in range(lt):
    if not (S[i+j] == T[j] or S[i+j] == '?'):
      flag=1
      break
  if flag==0:
    loc=i
    break

if flag==0:
  print('UNRESTORABLE')
else:
  i=0
  while i<ls:
    if i==loc:
      ans += T
      i += lt
    elif S[i] == '?':
      ans += 'a'
      i += 1
    else:
      ans += S[i]
      i += 1
  print(ans)

Submission status: Runtime Error

Solution code:
S=str(input())
T=str(input())
ls=len(S)
lt=len(T)

ans=''
for i in range(ls-lt,-1,-1):
  flag=0
  for j in range(lt):
    if not (S[i+j] == T[j] or S[i+j] == '?'):
      flag=1
      break
  if flag==0:
    loc=i
    break

if loc>-1:
  print('UNRESTORABLE')
else:
  i=0
  while i<ls:
    if i==loc:
      ans += T
      i += lt
    elif S[i] == '?':
      ans += 'a'
      i += 1
    else:
      ans += S[i]
      i += 1
  print(ans)

Submission status: Runtime Error

Solution code:
S=str(input())
T=str(input())
ls=len(S)
lt=len(T)

ans=''
for i in range(ls-lt,-1,-1):
  flag=0
  for j in range(lt):
    if not (S[i+j] == T[j] or S[i+j] == '?'):
      flag=1
      break
  if flag==0:
    loc=i
    break

if flag != 0:
  print('UNRESTORABLE')
else:
  i=0
  while i<ls:
    if i==loc:
      ans += T
      i += lt
    elif S[i] == '?':
      ans += 'a'
      i += 1
    else:
      ans += S[i]
      i += 1
  print(ans)

Submission status: Runtime Error

Solution code:
S=str(input())
T=str(input())
ls=len(S)
lt=len(T)
if ls<lt:
  print('UNRESTORABLE')

ans=''
for i in range(ls-lt,-1,-1):
  flag=0
  for j in range(lt):
    if not (S[i+j] == T[j] or S[i+j] == '?'):
      flag=1
      break
  if flag==0:
    loc=i
    break

if flag==1:
  print('UNRESTORABLE')
else:
  i=0
  while i<ls:
    if i==loc:
      ans+=T
      i+=lt
    elif S[i]=='?':
      ans+='a'
      i+=1
    else:
      ans+=S[i]
      i+=1
  print(ans)

Submission status: Runtime Error

Solution code:
S=str(input())
T=str(input())
ls=len(S)
lt=len(T)

ans=''
for i in range(ls-lt,-1,-1):
  flag=0
  for j in range(lt):
    if not (S[i+j] == T[j] or S[i+j] == '?'):
      flag=1
      break
  if flag==0:
    loc=i
    break

if flag==1:
  print('UNRESTORABLE')
else:
  i=0
  while i<ls:
    if i==loc:
      ans+=T
      i+=lt
    elif S[i]=='?':
      ans+='a'
      i+=1
    else:
      ans+=S[i]
      i+=1
  print(ans)

Submission status: Runtime Error

Solution code:
LEEEE
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate, product # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
import math
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#
# my_round_int = lambda x:np.round((x*2 + 1)//2)
# 四捨五入g
import sys
sys.setrecursionlimit(10000000)
#mod = 10**9 + 7
#mod = 9982443453
mod = 998244353
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
S = input()
T = input()
if len(S) < len(T):
    print('UNRESTORABLE')
    exit()
ans = 'z' * 51
for i in range(len(S) - len(T) + 1):
    s = S[i:i+len(T)]
    for a,b in zip(s,T):
        if a == b or a == '?':
            continue
        break
    else:
        cand = S[:i] + T + S[i+len(T):]
        #print(cand)
        ans = min(ans, cand.replace('?', 'a'))
print('UNRESTORABLE' if ans == 'z' * 51 else ans)

Submission status: Runtime Error

Solution code:
Sd = input()
T = input()
Sd = list(Sd)
N = len(Sd)

start_idxs = []
is_t_ing = 0
counter = 0
for i in range(N):
    if counter == len(T):
        is_t_ing = 0
        counter = 0

    if not is_t_ing:
        if Sd[i] == T[0]:
            is_t_ing = 1
            start_idxs.append(i)
            counter = 1
    else:
        if Sd[i] == "?" or Sd[i] == T[counter]:
            counter += 1
        else:
            is_t_ing = 0
            counter = 0
            start_idxs.pop()
S_list = []
if len(start_idxs) > 0:
    for start_idx in start_idxs:
        tmp_string = Sd.copy()
        for i in range(len(T)):
            tmp_string[start_idx + i] = T[i]
        tmp_string = "".join(tmp_string)
        tmp_string = tmp_string.replace("?", "a")
        S_list.append(tmp_string)
    ans = min(S_list)
    print(ans)
else:
    tmp_string = Sd.copy()
    tmp_string = "".join(tmp_string)
    tmp_string = tmp_string.replace("?"*len(T), T)
    if tmp_string == "".join(Sd):
        print("UNRESTORABLE")
    else:
        print(tmp_string.replace("?", "a"))