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:
s = input()[::-1]
t = input()[::-1]
for i,c in enumerate(s):
  if c == t[0] and (i+len(t) < len(s)):
    for j in range(len(t)):
      if t[j] != s[i+j] and s[i+j] != '?':
        break
    else:
      for j in range(len(t)):
        s[i+j] =  t[j]
      print(s.replace('?', 'a'))
      break
else:
  print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
s = input()[::-1]
t = input()[::-1]
for i,c in enumerate(s):
  if c == t[0]:
    for j in range(len(t)):
      if t[j] != s[i+j] and s[i+j] != '?':
        break
    else:
      for j in range(len(t)):
        s[i+j] =  t[j]
print(s.replace('?', 'a'))

Submission status: Runtime Error

Solution code:
nt = len(t)

if ns < nt:
    print("UNRESTORABLE")
else:
    for i in range(ns - nt + 1):
        if all([s[i + j] == "?" or s[i + j] == t[j] for j in range(nt)]):
            ans = s[:i] + t + s[i + nt:]
            ans = ans.replace("?", "a")
            print(ans)
            exit()
print("UNRESTORABLE")

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
input_A = input()
input_T = input()
input_A, input_T = list(input_A), list(input_T)

if len(input_A) >= len(input_T):
    for i in range(len(input_A)-len(input_T), -1, -1):
        clear_flg = True
        for j in range(len(input_T)):
            if not (input_A[i + j] == '?' or input_A[i + j] == input_T[j]):
                clear_flg = False
                break

        if clear_flg is True:
            input_A[i:i + len(input_T)] = input_T
            input_A = ''.join(input_A).replace('?', 'a')
            break
        else:
            input_A = 'UNRESTORABLE'
else:
    input_A = 'UNRESTORABLE'
print(input_A)

Submission status: Runtime Error

Solution code:
input_A = input()
input_T = input()
input_A, input_T = list(input_A), list(input_T)

for i in range(len(input_A)-len(input_T), 0, -1):
    clear_flg = True
    for j in range(len(input_T)):
        if not (input_A[i + j] == '?' or input_A[i + j] == input_T[j]):
            clear_flg = False
            break

    if clear_flg is True:
        input_A[i:i + len(input_T)] = input_T
        input_A = ''.join(input_A).replace('?', 'a')
    else:
        input_A = 'UNRESTORABLE'
print(input_A)

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

s = list(input())
t = list(input())

slen = len(s)
tlen = len(t)

cand = []
for i in range(slen - tlen + 1):
    match = True
    for j in range(tlen):
        if s[i + j] == "?" or s[i + j] == t[j]:
            pass
        else:
            match = False
    if match:
        cand.append(i)

if len(cand) != 0:
    cand.reverse()
    ans = ""
    for i in range(slen):
        if not (cand[0] <= i <= cand[0] + tlen):
            if s[i] == "?":
                ans += "a"
            else:
                ans += s[i]
        else:
            ans += t[i - cand[0]]        
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S = list(input())
T = list(input())
i = len(S) - 1
j = len(T) - 1
start_T = 100
while i >= 0:
	if S[i] == T[j] or S[i] == "?":
		j -= 1
		i -= 1

		if j == -1:
			start_T = i + 1
			break
	else:
		j = len(T) - 1
		i -= 1

if start_T == 100:
	ans = UNRESTORABLE
else:
	ans = ""
	k = 0
	while k < len(S):
		if k == start_T:
			for j in range(len(T)):
				ans += str(T[j])
			k += len(T)
		elif S[k] == "?":
			ans += "a"
			k += 1
		else:
			ans += str(S[k])
			k += 1
			
print(ans)

Submission status: Runtime Error

Solution code:
#文字列Tを突っ込むのはできるだけ最後の方が良い(残りは全てaにしないと辞書順で負けうる。)
#if 文字列が入らない→UNRESTORABLE
#if 文字列が入ったら全部aを入れられる。(ん？これってここまでやったら絶対に一番最初のやつになるのでは?)
#※すでに文字が入っていたら、文字列を入れずに全てaを突っ込む
#文字列をどうやって探すか。
#Tの長さと同じだけ?が連続している場所があるならいける
#というか一文字ずつみて(その文字or?ならオーケー)失敗したらindexを戻していけばいいので

def strProduct(S,T):
    Tindex = 0#Tのindex失敗するたびに0に戻る
    lt = len(T) #Tの文字列の長さ
    flag = False#Tの材料に ?がなければFalse
    reasonable = False#文字を作れるかどうか
    translateIndex = [] #SがTの文字列になる場所の初めの位置
    S.reverse()
    T.reverse()
    for si in range(len(S)):
        s = S[si]
        if s == T[Tindex] or s == "?":
            if Tindex == 0:#初めての一致
                translateIndex.append(si)
            if s == "?":#?をつかって文字列をつくる時と作らない時で異なるし、?を使わないのがあればそれを優先するべき
                flag = True
                if len(translateIndex) > 1:#すでに一つ完成している時はそっちを優先する
                    translateIndex.pop()#translateIndexには残らない
            Tindex += 1
            if Tindex == lt:#全てmatchingした時
                reasonable = True
                if not flag:#?を使わないなら優先的にそれを使う
                    break
                #初期化して次のを探す
                Tindex = 0
                flag = False
        else: #一回でも失敗すれば初期化
            Tindex = 0
            flag = False
            #translateIndexはあまり関係ない
    if flag:#?を使わないとできないなら変更します。
        for j in range(translateIndex[len(translateIndex)-1],translateIndex[len(translateIndex)-1]+lt):
            S[j] = T[j-translateIndex[len(translateIndex)-1]]
    S.reverse()
    #T.reverse()
    if not reasonable:
        return "UNRESTORABLE"
    else:
        for si in range(len(S)):
            if S[si] == "?":
                S[si] = "a"
        modifiedS = ''.join(S)
        return modifiedS

S = list(input())
T = list(input())
#print(S)
#print(T)
print(strProduct(S,T))

Submission status: Runtime Error

Solution code:
if __name__ == '__main__':
    hidden_key = input()
    flag_string = input()

    key_length = len(hidden_key)
    flag_length = len(flag_string)

    key_list = list(hidden_key.replace('?', 'a'))

    for i in reversed(range(key_length - flag_length + 1)):
        part_key = hidden_key[i:i + flag_length]
        is_match = True

        for j in range(flag_length):
            if part_key[j] != '?' and part_key[j] != flag_string[j]:
                is_match = False
                break
            
        if is_match:
            for k in range(flag_length):
                key_list[i + k] = flag_string[k]
            print(''.join(key_list))
            break

    if not is_match:
        print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
import copy
S=list(input())
S1 = "".join(S)
T=list(input())
T1 = "".join(T)
F = ["?"]*len(T)
F1 = "".join(F)
l =[]
M =[]
index =[]
B = copy.deepcopy(S)
while -1<S1.find(F1):
    a = S1.find(F1)
    index.append(a)
    B[a] ="a"
    S1="".join(B)
S1 ="".join(S)
for i in range(len(S)-len(T)+1):
    if S[i]==T[0]:
        l.append(i)
if 0<len(l):
    for i in l:
        A = copy.deepcopy(S)
        c = A[i:len(T)+i]
        while "?" in c:
            c[c.index("?")] = T[c.index("?")]
        if c==T:
            A = copy.deepcopy(S)
            A[i:len(T)+i] = c
            while "?"in A:
                A[A.index("?")]="a"
            M.append(A)

for i in range(len(S)-len(T)+1):
    if S[i] =="?":
        A = copy.deepcopy(S)
        c = A[i:len(T)+i]
    while "?" in c:
        c[c.index("?")] = T[c.index("?")]
    if c==T:
        A = copy.deepcopy(S)
        A[i:len(T)+i] = c
        while "?"in A:
            A[A.index("?")]="a"
        M.append(A)
if 0<len(index):
    for i in index:
        A = copy.deepcopy(S)
        A[i:len(T)+i] = T
        while "?"in A:
            A[A.index("?")]="a"
        M.append(A)
if 0<len(M):
    M.sort()
    print("".join(M[0]))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import copy
S=list(input())
S1 = "".join(S)
T=list(input())
T1 = "".join(T)
F = ["?"]*len(T)
F1 = "".join(F)
l =[]
M =[]
index =[]
B = copy.deepcopy(S)
while -1<S1.find(F1):
    a = S1.find(F1)
    index.append(a)
    B[a] ="a"
    S1="".join(B)
S1 ="".join(S)
for i in range(len(S)-len(T)+1):
    if S[i]==T[0]:
        l.append(i)
if 0<len(l):
    for i in l:
        c = S[i:len(T)+i]
        while "?" in c:
            c[c.index("?")] = T[c.index("?")]
        if c==T:
            A = copy.deepcopy(S)
            A[i:len(T)+i] = c
            while "?"in A:
                A[A.index("?")]="a"
            M.append(A)

for i in range(len(S)-len(T)+1):
    if S[i] =="?":
        c = S[i:len(T)+i]
    while "?" in c:
        c[c.index("?")] = T[c.index("?")]
    if c==T:
        A = copy.deepcopy(S)
        A[i:len(T)+i] = c
        while "?"in A:
            A[A.index("?")]="a"
        M.append(A)
if 0<len(index):
    for i in index:
        A = copy.deepcopy(S)
        A[i:len(T)+i] = T
        while "?"in A:
            A[A.index("?")]="a"
        M.append(A)
if 0<len(M):
    M.sort()
    print("".join(M[0]))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import copy
S=list(input())
S1 = "".join(S)
T=list(input())
T1 = "".join(T)
F = ["?"]*len(T)
F1 = "".join(F)
l =[]
M =[]
index =[]
B = copy.deepcopy(S)
while -1<S1.find(F1):
    a = S1.find(F1)
    index.append(a)
    B[a] ="a"
    S1="".join(B)
S1 ="".join(S)
for i in range(len(S)-len(T)+1):
    if S[i]==T[0]:
        l.append(i)
if 0<len(l):
    for i in l:
        c = S[i:len(T)+i]
        while "?" in c:
            c[c.index("?")] = T[c.index("?")]
        if c==T:
            A = copy.deepcopy(S)
            A[i:len(T)+i] = c
            while "?"in A:
                A[A.index("?")]="a"
            M.append(A)
else :
    for i in range(len(S)-len(T)+1):
        if S[i] =="?":
            c = S[i:len(T)+i]
        while "?" in c:
            c[c.index("?")] = T[c.index("?")]
        if c==T:
            A = copy.deepcopy(S)
            A[i:len(T)+i] = c
            while "?"in A:
                A[A.index("?")]="a"
            M.append(A)
if 0<len(index):
    for i in index:
        A = copy.deepcopy(S)
        A[i:len(T)+i] = T
        while "?"in A:
            A[A.index("?")]="a"
        M.append(A)
if 0<len(M):
    M.sort()
    print("".join(M[0]))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S=input()
T=input()
flag=False
for i in range(len(S)-len(T)+1):
    dif=0
    same=0
    s=S[i:i+len(T)]#len(T)
    for j in range(len(T)):
        if s[j]!='?':#sが言葉の時
            if s[j]!=T[j]:
                #print("st",s[i],T[i])
                dif+=1
            else:
                same+=1
#                flag=True

        #else:#?のとき
    if dif==0:
        #dst=S.replace(s,T)
        flag=True
        memo=i#複数replace対策
    


S=''.join(S)

if flag==False:
    print("UNRESTORABLE")
else:
    S=list(S)
    for i in range(len(T)):
        S[i+memo]=T[i]
    S=S.replace('?','a')
    print(S)

Submission status: Runtime Error

Solution code:
S=input()
T=input()
flag=False
for i in range(len(S)-len(T)+1):
    dif=0
    same=0
    s=S[i:i+len(T)]#len(T)
    for j in range(len(T)):
        if s[j]!='?':#sが言葉の時
            if s[j]!=T[j]:
                #print("st",s[i],T[i])
                dif+=1
            else:
                same+=1
#                flag=True

        #else:#?のとき
    if dif==0:
        #dst=S.replace(s,T)
        flag=True
        memo=i#複数replace対策
S=list(S)
for i in range(len(T)):
    S[i+memo]=T[i]

S=''.join(S)

if flag==False:
    print("UNRESTORABLE")
else:
    S=S.replace('?','a')
    print(S)

Submission status: Runtime Error

Solution code:
s=list(input())
t=list(input())
ls=len(s)
lt=len(t)
m=ls-lt
if m<0:
  print('UNRESTORABLE')
else:
  for i in range(m,-1,-1):
    l=s[i:]
    for j in range(lt):
      if t[j]==l[j] or l[j]=='?':
        A=True
      else:
        A=False
        break
    if A:
      if i==0:
        s=t+s[lt:]
        s=s.translate(str.maketrans('?','a'))
        B=True
        break
      else:
        s=s[:i]+t
        s=''.join(s)
        s=s.translate(str.maketrans('?','a'))
        B=True
        break
    else:
      B=False
if B:
  print(s)
else:
  print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
s=list(input())
t=list(input())
ls=len(s)
lt=len(t)
m=ls-lt
if m<0:
  print('UNRESTORABLE')
else:
  for i in range(m,-1,-1):
    l=s[i:]
    for j in range(lt):
      if t[j]==l[j] or l[j]=='?':
        A=True
      else:
        A=False
        break
    if A:
      s=s[:i]+t
      s=''.join(s)
      s=s.translate(str.maketrans('?','a'))
      B=True
      break
    else:
      B=False
if B:
  print(s)
else:
  print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

s=input()
t=input()
if len(s)-len(t)<0:
    flg=False
else:
    for i in range(len(s)-len(t)):
        ans=s
        for j in range(len(t)):
            flg=True
            if t[-1-j]==s[-1-j-i] or s[-1-j-i]=='?':
                #print(ans)
                ans=ans[:-1-j-i]+t[-1-j]+('' if -1-i-j+1==0 else ans[-1-i-j+1:])
            else:
                flg=False
                break
        if flg==True:
            break
ans=ans.replace('?','a')
print(ans if flg else 'UNRESTORABLE')

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!

s=input()
t=input()

for i in range(len(s)-len(t)):
    ans=s
    for j in range(len(t)):
        flg=True
        if t[-1-j]==s[-1-j-i] or s[-1-j-i]=='?':
            #print(ans)
            ans=ans[:-1-j-i]+t[-1-j]+('' if -1-i-j+1==0 else ans[-1-i-j+1:])
        else:
            flg=False
            break
    if flg==True:
        break
ans=ans.replace('?','a')
print(ans if flg else 'UNRESTORABLE')

Submission status: Runtime Error

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

ls=len(s)
lt=len(t)
if ls < lt:
    print(errorword)
else:
    for i in range(ls-lt,-1,-1):
        is_matched = True
        s_slice = slice(i, lt+2)

        for s_char, t_char in zip(s[s_slice], t):
            # 文字が不一致かつ？以外の場合は文字列不一致のためbreak
            if (s_char != t_char) and s_char != '?':
                is_matched = False
                break
                
        # ここまでbreakせずに来たら文字列一致のため文字列Sを出力
        if is_matched:
            temp_sl1 = slice(0, i)
            temp_sl2 = slice(i+lt, ls+1)
            out_str = '{}{}{}'.format(s[temp_sl1], t, s[temp_sl2])
            print(out_str.replace('?', 'a'))
            break
    
    if not is_matched:
        print(errorword)

Submission status: Runtime Error

Solution code:
s=input()
t=input()
#print(s,t)

if len(s) < len(t):
    print('UNRESTORABLE') 
elif len(s) == len(t):
  cnt=0
  for i in range(len(s)):
    if s[i] == t[i]:
      cnt+=1
    elif s[i] == '?':
      cnt+=1
  if len(t)==cnt:
    print(t)
  else:
    print('UNRESTORABLE') 
else:
  flag1=0
  for j in range(len(s)):
    cnt=0
    for i in range(len(t)):
      if s[i+j]==t[i]:
        cnt+=1
      elif s[i+j]=='?':
        cnt+=1
    if cnt==len(t):
      flag1=1
      if j==0:
        s=t+s[len(t):]
      if 0 < j < len(s)-len(t)+1:
        s=s[0:j]+t+s[j+len(t):]
      if j == len(s)-len(t)+1:
        s=s[0:j]+t      
      s=s.replace('?','a')
      print(s)
    
  if flag1==0:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
#import re

s=input()
t=input()
#print(s,t)

flag1=0
for j in range(len(s)-len(t)+1):
  flag=0
  for i in range(len(t)):
    if s[i+j]=='?' or s[i+j]==t[i]:
      flag+=1
  if flag==len(t):
    flag1=1
    s=s[0:j]+t[j-2:j+len(t)-2]+s[j+len(t):]
    s=s.replace('?','a')
    print(s)
    
if flag1==0:
  print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
#import re

s=input()
t=input()
#print(s,t)

flag1=0
for j in range(len(s)-len(t)+1):
  flag=0
  for i in range(len(t)):
    if s[i+j]=='?' or s[i+j]==t[i]:
      flag+=1
  if flag==len(t):
    flag1=1
    s=s[0:j]+t[j-1:j+len(t)]+s[j+len(t):]
    s=s.replace('?','a')
    print(s)
    
if flag1==0:
  print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
S=input()
T=input()
def check(i):
    flag=True
    for j in range(len(T)):
        if S[i+j]!='?' and S[i+j]!=T[j]:
            flag=False
            break
    return flag
def search(S,T):
    for i in range(len(S)-len(T),-1,-1):
        if check(i):return i
    return -1
def main(S,T):
    ans=''
    if T not in S:
        idx=search(S,T)
        if idx==-1:
            return 'UNRESTORABLE'
    S=S[:idx]+T+S[idx+len(T):]
    for s in S:
        if s=='?':ans+='a'
        else:ans+=s
    return ans
print(main(S,T))

Submission status: Runtime Error

Solution code:
S = input()
T = input()
change_index = []

for i in range(len(S)-len(T)+1):
    step = 0
    for j in T:
#        if i + step >= len(S):
#            break
        if S[i+step] != j and S[i+step] != '?':
            break
        step += 1
        if step == len(T):
            change_index.append(i)

if len(change_index) or len(T) == 0:
    Sa_list = list(S.replace('?', 'a'))
    for i in change_index[0]:
        step = 0
        for j in T:
            Sa_list[i+step] = j
            step += 1
    Sa = ''.join(Sa_list)
    print(Sa)
else :
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
s=input()
t=input()
ans=[]
for i in range(len(s)):
  s.insert(0,s.pop())
  s=''.join(s)
  m=[]
  flag=True
  for j in range(len(t)):
    if s[j]=='?' or t[j]==s[j]:
      m.append(t[j])
    else:
      flag=False
      break
  if flag:
    for j in range(len(t),len(s)):
      if s[j]=='?':
        m.append(a)
      else:
        m.append(s[j])
    ans.append(''.join(m))
ans.sort()
if len(ans)>0:
  print(ans[0])
else:
  print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
s=input()
t=input()
ans=[]
for i in range(len(s)):
  s.insert(0,s.pop())
  s=''.join(s)
  m=[]
  flag=True
  for j in range(len(t)):
    if s[j]=='?' or t[j]==s[j]:
      m.append(t[j])
    else:
      flag=False
      break
  if flag:
    for j in range(len(t),len(s)):
      if s[j]=='?':
        m.append(a)
      else:
        m.append(s[j])
    ans.append(''.join(m))
ans.sort()
print(ans[0])

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-

s = list(input())
t = list(input())
a = []

for i in range(len(t)-1,len(s)):
    lock = True
    for j in range(len(t)):
        if s[i-len(t)+j+1] == "?":
            pass
        elif s[i-len(t)+j+1] != t[j]:
            lock = False
    if lock:
        a.append(s[:i-len(t)+1] + t[:])

if len(a) == 0:
    print("UNRESTORABLE")
else:
    a.sort()
    for i in range(len(a[0])):
        if a[0][i] == "?":
            a[0][i] = "a"

answer = "".join(a[0])

print(answer)

Submission status: Runtime Error

Solution code:
S = list(input())
T = list(input())
LS = len(S)
LT = len(T)
a = ""
for i in range(LS - LT + 1):
    for j in range(LT):
        if S[i + j] != T[j] and S[i + j] != "?":
            break
        if j == LT - 1:
            for k in range(LT):
                S[i + k] = T[k]
            #print("".join(S))
            s = str("".join(S)).replace("?", "a")
            print(s)
            exit()
# S = S.replace("?", "a")
print("UNRESTORABLE")a

Submission status: Runtime Error

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

for i in range(len(s)-len(t)+1):
  flag=True
  for j in range(len(t)):
    if s[i+j]==t[j] and s[i+j]=="?":
      continue
    else:
      flag=False
  if flag:
    s=s[:i]+t+s[i+len(t):]
    s=s.replace("?","a")
print(s if flag else "UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import copy
def solve():
    S = list(input())
    T = list(input())
    
    tests = []
    for i in range(len(S)):
        if (is_ok(S, T, i)):
            temp = copy.copy(S)
            for j in range(len(T)):
                temp[i + j] = T[j]
            tests.append(afill(temp))
    if (len(tests) == 0):
        print('UNRESTORABLE\n'); return None
    max_temp = ''.join(tests[0])
    for e in tests:
        max_temp = max(max_temp, ''.join(e))
    print(max_temp + '\n')

def afill(string):
    for i in range(len(string)):
        if (string[i] == '?'):
            string[i] = 'a'
    return string

def is_ok(string, target, idx):
    for i in range(len(target)):
        if (string[idx + i] != '?' and string[idx + i] != target[i]):
            return False
    return True

solve()

Submission status: Runtime Error

Solution code:
def solve():
    S = list(input())
    T = list(input())
    
    tests = []
    for i in range(len(S)):
        if (is_ok(S, T, i)):
            temp = S
            for j in range(len(T)):
                temp[i + j] = T[j]
            tests.append(afill(temp))
    if (len(tests) == 0):
        print('UNRESTORABLE\n'); return None
    max_temp = ''.join(tests[0])
    for e in tests:
        max_temp = max(max_temp, ''.join(e))
    print(max_temp + '\n')

def afill(string):
    for i in range(len(string)):
        if (string[i] == '?'):
            string[i] = 'a'
    return string

def is_ok(string, target, idx):
    for i in range(len(target)):
        if (string[idx + i] != '?' and string[idx + i] != target[i]):
            return False
    return True

solve()

Submission status: Runtime Error

Solution code:
def solve():
    S = list(input())
    T = list(input())
    
    tests = []
    for i in range(len(S)):
        if (is_ok(S, T, i)):
            temp = S
            for j in range(len(T)):
                temp[i + j] = T[j]
            tests.append(afill(temp))
    if (len(tests) == 0):
        print('UNRESTORABLE\n'); return None
    max_temp = ''.join(tests[0])
    for e in tests:
        max_temp = max(max_temp, ''.join(e))
     print(max_temp + '\n')

def afill(string):
    for i in range(len(string)):
        if (string[i] == '?'):
            string[i] = 'a'
    return string

def is_ok(string, target, idx):
    for i in range(len(target)):
        if (string[idx + i] != '?' and string[idx + i] != target[i]):
            return False
    return True

solve()

Submission status: Runtime Error

Solution code:
import re
S_ = input()
T = input()

t_len = len(T)-1 if len(T)>1 else 0

if t_len!=0 and len(S_) != 1:
    tt = re.findall(".\?{%d}"%t_len, S_)[0]
    if tt[0] == T[0] and re.search("\?{%d}"%t_len, S_):
        
        text=re.sub("\?{%d}"%t_len,T[1:],S_)
        print(text.replace("?","a"))
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import re
S_ = input()
T = input()
t = T[1:]
ss = re.findall(".\?{%d}"%len(t), S_)[0]

if T[0] == ss[0] and re.search("\?{%d}"%len(t), S_):
    text=re.sub("\?{%d}"%len(t),t,S_)
    text = re.sub("\?","a",text)
    print(text)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S = input()
T = input()
flag = False
for i in range(len(S) - len(T) + 1):
    k = i
    for j in range(len(T)):
        if S[k] == T[j] or S[k] == '?':
            k += 1
        else:
            break
    if k == i + len(T):
        flag = True
        st = i
        break
ret = ""
print(st)
if flag:
    for i in range(st):
        if S[i] == '?':
            ret += 'a'
        else:
            ret += S[i]
    ret += T
    for i in range(st + len(T), len(S)):
        if S[i] == '?':
            ret += 'a'
        else:
            ret += S[i]
else:
    ret = "UNRESTORABLE"
print(ret)

Submission status: Runtime Error

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
def A():
    r,g = IR(2)
    print(2*g-r)

#B
def B():
    n = I()
    k = I()
    a = 1
    for i in range(n):
        if a > k:
            a += k
        else:
            a *= 2
    print(a)
#C
def C():
    def check(a,b):
        for i in range(len(a)):
            if a[i] != b[i] and a[i] != "?":
                return False
        return True
    def f(c):
        if c == "?":return "a"
        return c
    s = S()
    t = S()
    n = len(s)
    l = len(t)
    for i in range(n-l+1)[::-1]:
        if check(s[i:],t):
            ans = [f(s[j]) for j in range(i)]
            ans += t
            for j in range(i+l,n-l):
                ans += f(j)
            for j in ans:
                print(j,end = "")
            print()
            quit()
    print("UNRESTORABLE")
#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    C()

Submission status: Runtime Error

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

l = []

for i in range(len(s)-len(t) + 1):
    f = True
    for j in range(len(t)):
        if s[i+j] != '?' and s[i+j] != t[j]:
            f = False
            break
    if f:
        a = s[:i] + t + s[i+len(t):]
        l.append(a.replace('?','a'))
if len(l)>0:
    print(min(l))
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

l = []

for i in range(len(s)-len(t) - 1):
    f = True
    for j in range(len(t)):
        if s[i+j] != '?' and s[i+j] != t[j]:
            f = False
            break
    if f:
        a = s[:i] + t + s[i+len(t):]
        l.append(a.replace('?','a'))
if len(l)>0:
    print(min(l))
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

l = []

for i in range(len(s)-len(t) - 1):
    f = True
    for j in range(len(t)):
        if s[i+j] != '?' and s[i+j] != t[j]:
            f = False
            break
    if f:
        a = s[i:] + t + s[:i+len(t)]
        l.append(a.replace('?','a'))
if len(l)>0:
    print(min(l))
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

l = []

for i in range(len(s)-len(t) - 1):
    f = True
    for j in range(len(t)):
        if s[i+j] != '?' and s[i+j] != t[j]:
            f = False
            break
    if f:
        a = s[:i] + t + s[:i+len(t)]
        l.append(a.replace('?','a'))
if len(l)>0:
    print(min(l))
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

for i in range(len(S)):
    for j in range(len(T)):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break
    else:
        S = S[:i] + T
        S = S.replace('?', 'a')
        print(S)
        break
else:
    print("UNRESTORABLE")