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

Submission status: Runtime Error

Solution code:
S = input()
T = input()
n = len(S)
m = len(T)

ans = 'UNRESTORABLE'
for i in range(n - m + 1):
    for j in range(m):
        if S[i + j] != '?' and S[i + j] != T[j]:
            break
    else:
        S2 = S[: i] + T + S[i + m :]
ans = S2.replace('?', 'a')
        
print(ans)

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]:
            flag = False
    if flag:
        break
            
if flag:
    res = ''
    for i in range(len(S)):
        if S[i] == '?':
            res += 'a'
        else:
            res += S[i]
            
    print(res)
    
else:
    tmp = -1
    for i in range(len(S) - len(T) + 1):
        start = -1
        for j in range(len(T)):
            if S[i+j] == T[j] or S[i+j] == '?':
                start = i
            else:
                start = -1
                break
                
        
        if start != -1:
                tmp = i
    if tmp == -1:
        print('UNRESTORABLE')
    else:
        res = ''
        count = 0
        for i in range(len(S)):
            if tmp <= i < tmp + len(T):
                res += T[count]
                count += 1
            elif S[i] == '?':
                res += 'a'
            else:
                res += S[i]

        print(res)

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]:
            flag = False
    if flag:
        break
            
if flag:
    res = ''
    for i in range(len(S)):
        if S[i] == '?':
            res += 'a'
        else:
            res += S[i]
            
    print(res)
    
else:
    tmp = -1
    for i in range(len(S) - len(T) + 1):
        start = -1
        for j in range(len(T)):
            if S[i+j] == T[j] or S[i+j] == '?':
                start = i
            else:
                start = -1
                break
                
        
        if start != -1:
                tmp = i
if tmp == -1:
    print('UNRESTORABLE')
else:
    res = ''
    count = 0
    for i in range(len(S)):
        if tmp <= i < tmp + len(T):
            res += T[count]
            count += 1
        elif S[i] == '?':
            res += 'a'
        else:
            res += S[i]
            
    print(res)

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]:
            flag = False
    if flag:
        break
            
if flag:
    res = ''
    for i in range(len(S)):
        if S[i] == '?':
            res += 'a'
        else:
            res += S[i]
            
    print(res)
    
else:
    tmp = -1
    for i in range(len(S) - len(T) + 1):
        start = -1
        for j in range(len(T)):
            if S[i+j] == T[j] or S[i+j] == '?':
                start = i
            else:
                start = -1
                break
                
        
        if start != -1:
                tmp = i
if tmp == -1:
    print('UNRESTORABLE')
else:
    res = ''
    count = 0
    for i in range(len(S)):
        if start <= i <= start + len(T):
            res += T[count]
            count += 1
        elif S[i] == '?':
            res += 'a'
        else:
            res += S[i]
            
    print(res)

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]:
            flag = False
    if flag:
        break
            
if flag:
    res = ''
    for i in range(len(S)):
        if S[i] == '?':
            res += 'a'
        else:
            res += S[i]
            
    print(res)
    
else:
    tmp = -1
    for i in range(len(S) - len(T) + 1):
        start = -1
        for j in range(len(T)):
            if S[i+j] == T[j] or S[i+j] == '?':
                start = i
            else:
                start = -1
                break
                
        
        if start != -1:
                tmp = i
if tmp == -1:
    print('UNRESTORABLE')
else:
    res = ''
    count = 0
    for i in range(len(S)):
        if start <= i < start + len(T):
            res += T[count]
            count += 1
        elif S[i] == '?':
            res += 'a'
        else:
            res += S[i]
            
    print(res)

Submission status: Runtime Error

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

tmp1 = 0
tmp2 = 0
res = ''
flag = False
for i in range(len(S) - len(t)+1):
    h = True
    for j in range(len(t)):
        if S[i+j] != t[j]:
            h = False
    if h == True:
        flag = True
        break
        
if h != True:
            
    while True:
        if S[-tmp1 - 1] == t[-tmp2 - 1]  or S[-tmp1 - 1] == '?':
            res = t[-tmp2 - 1] + res
            tmp1 += 1
            tmp2 += 1
        else:
            if tmp2 == 0:
                tmp1 += 1
            tmp2 = 0
            res = ''


        if tmp2 == len(t):
            flag = True
            break

        if tmp1 == len(S):
            break
      
tmp3 = ''
k = 0
for i in range(len(S)):
    if len(S) - tmp1 <= i < len(S) - tmp1 + len(t):
        tmp3 += t[k]
        k += 1
    elif S[i] == '?':
        tmp3 += 'a'
    else:
        tmp3 += S[i]
        
res = tmp3 
 
if flag:
    print(res)
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

tmp1 = 0
tmp2 = 0
res = ''
flag = False
for i in range(len(S) - len(t)+1):
    h = True
    for j in range(len(t)):
        if S[i+j] != t[j]:
            h = False
    if h == True:
        flag = True
        break
        
if h != True:
            
    while True:
        if S[-tmp1 - 1] == t[-tmp2 - 1]  or S[-tmp1 - 1] == '?':
            res = t[-tmp2 - 1] + res
            tmp1 += 1
            tmp2 += 1
        else:
            #tmp1 += 1
            tmp2 = 0
            res = ''


        if tmp2 == len(t):
            flag = True
            break

        if tmp1 == len(S):
            break
      
tmp3 = ''
k = 0
for i in range(len(S)):
    if len(S) - tmp1 <= i < len(S) - tmp1 + len(t):
        tmp3 += t[k]
        k += 1
    elif S[i] == '?':
        tmp3 += 'a'
    else:
        tmp3 += S[i]
        
res = tmp3 
 
if flag:
    print(res)
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

tmp1 = 0
tmp2 = 0
res = ''
flag = False
for i in range(len(S) - len(t)+1):
    h = True
    for j in range(len(t)):
        if S[i+j] != t[j]:
            h = False
    if h == True:
        flag = True
        break
        
if h != True:
            
    while True:
        if S[-tmp1 - 1] == t[-tmp2 - 1]  or S[-tmp1 - 1] == '?':
            res = t[-tmp2 - 1] + res
            tmp1 += 1
            tmp2 += 1
        else:
            tmp1 += 1
            tmp2 = 0
            res = ''


        if tmp2 == len(t):
            flag = True
            break

        if tmp1 == len(S):
            break
      
tmp3 = ''
k = 0
for i in range(len(S)):
    if len(S) - tmp1 <= i < len(S) - tmp1 + len(t):
        tmp3 += t[k]
        k += 1
    elif S[i] == '?':
        tmp3 += 'a'
    else:
        tmp3 += S[i]
        
res = tmp3 
 
if flag:
    print(res)
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

tmp1 = 0
tmp2 = 0
res = ''
flag = False
for i in range(len(S) - len(t)):
    h = True
    for j in range(len(t)):
        if S[i+j] != t[j]:
            h = False
    if h == True:
        flag = True
        break
        
if h != True:
            
    while True:
        if S[-tmp1 - 1] == t[-tmp2 - 1]  or S[-tmp1 - 1] == '?':
            res = t[-tmp2 - 1] + res
            tmp1 += 1
            tmp2 += 1
        else:
            tmp1 += 1
            tmp2 = 0
            res = ''


        if tmp2 == len(t):
            flag = True
            break

        if tmp1 == len(S):
            break
      
tmp3 = ''
k = 0
for i in range(len(S)):
    if len(S) - tmp1 <= i < len(S) - tmp1 + len(t):
        tmp3 += t[k]
        k += 1
    elif S[i] == '?':
        tmp3 += 'a'
    else:
        tmp3 += S[i]
        
res = tmp3 
 
if flag:
    print(res)
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

tmp1 = 0
tmp2 = 0
res = ''
flag = False
for i in range(len(S) - len(t)):
    h = True
    for j in range(len(t)):
        if S[i] != t[j]:
            h = False
    if h == True:
        flag = True
        break
        
if h != True:
            
    while True:
        if S[-tmp1 - 1] == t[-tmp2 - 1]  or S[-tmp1 - 1] == '?':
            res = t[-tmp2 - 1] + res
            tmp1 += 1
            tmp2 += 1
        else:
            tmp1 += 1
            tmp2 = 0
            res = ''


        if tmp2 == len(t):
            flag = True
            break

        if tmp1 == len(S):
            break
      
tmp3 = ''
k = 0
for i in range(len(S)):
    if len(S) - tmp1 <= i < len(S) - tmp1 + len(t):
        tmp3 += t[k]
        k += 1
    elif S[i] == '?':
        tmp3 += 'a'
    else:
        tmp3 += S[i]
        
res = tmp3 
 
if flag:
    print(res)
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
S=input()
T=input()
s=0
flag1=False
for i in range(len(S)-len(T)+1):
    flag2=True
    for j in range(len(T)):
        if S[i+j]!=T[j] and S[i+j]!='?':
            flag2=False
    if flag2==True:
        flag1=True
        s=i
if flag1==False:
    print('UNRESTORABLE')
else:
    for i in range(len(S)):
        if i>=s:
            print(T[i-s],end='')
        elif S[i]=='?':
            print('a',end='')
        else:
            print(S[i],end='')

Submission status: Runtime Error

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

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


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

s = input()
t = input()

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

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

Submission status: Runtime Error

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

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


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

s = input()
t = input()

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

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

Submission status: Runtime Error

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

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


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

s = input()
t = input()

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

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

Submission status: Runtime Error

Solution code:
S,T=input(),input()
s_list,t_list=list(reversed(list(S))),list(reversed(list(T)))
i=0
num=0
count=0
str=''
for i,s in enumerate(s_list):
    if num==len(T):
        end,start=i-1,i-len(T)
        break
    if s=='?' or s==t_list[num]:
        num+=1
        str+=s
    else:
        num,str=0,''
    if i==len(s_list)-1 and num<len(T):
        print('UNRESTORABLE')
        exit()
s_list[start:end+1]=t_list
print(''.join(s_list).replace('?','a')[::-1])

Submission status: Runtime Error

Solution code:
S,T=input(),input()
s_list,t_list=list(reversed(list(S))),list(reversed(list(T)))
i=0
num=0
count=0
str=''
for i,s in enumerate(s_list):
    if num==len(T):
        end,start=i-1,i-len(T)
        break
    if s=='?' or s==t_list[num]:
        num+=1
        str+=s
    elif len(str)!=len(T):
        num,str=0,''
    if i==len(s_list)-1 and num<len(T):
        print('UNRESTORABLE')
        exit()
s_list[start:end+1]=t_list
print(''.join(s_list).replace('?','a')[::-1])

Submission status: Runtime Error

Solution code:
import bisect
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
t = S()

for i in range(len(s)-len(t),-1,-1):
	cnt = 0
	for j in range(i,i+len(t)-1):
		if s[j] == t[j-i] or s[j] == "?":
			cnt += 1
			continue
		else:
			break
	if cnt == len(t)-1:
		print(s.translate(str.maketrans({'?':'a'}))[:A]+t+s.translate(str.maketrans({'?':'a'}))[A+len(t)-1:])
		exit()

print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import bisect
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

s = S()
t = S()

for i in range(len(s)-len(t),-1,-1):
	cnt = 0
	for j in range(i,i+len(t)-1):
		if s[j] == t[j-i] or s[j] == "?":
			cnt += 1
			continue
		else:
			break
	if cnt == len(t)-1:
		print(ans[:i]+t+ans[i+len(t)-1:])
		exit()

print("UNRESTORABLE")

Submission status: Runtime Error

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

len_S = len(S)
len_T = len(T)
for i in range(len_S-len_T, -1, -1):
  if not all(s in ['?', t] for s, t in zip(S[i:i+len_T], T)):
    continue
  print((S[:i] + t + S[i+len_T:]).replace('?','a'))
  exit()
print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S = str(input())
T = str(input())
slist = list(S)
tlist = list(T)
Slen = len(slist)
Tlen = len(tlist)
ANSlist = []
Flag = 0
if Slen < Tlen:
    Flag = 0
else:
    for i in range(Slen-Tlen+1):
        flag = 0
        for j in range(Tlen):
            if slist[i+j] == "?" or slist[i+j] == tlist[j]:
                pass
            else:
                flag = 1
                break
        if flag == 0:
            Skari = ""
            k = 0
            for k in range(i):
                if slist[k] == "?":
                    Skari+="a"
                else:
                    Skari+=slist[k]
            l = 0
            for l in range(Tlen):
                Skari+=tlist[l]
            m = 0
            Skarilen = len(Skari)
            for m in range(Slen-Skarilen):
                M = m+Slen
                if slist[M] == "?":
                    Skari+="a"
                else:
                    Skari+=slist[M]
            ANSlist.append(Skari)
            Flag+=1
        else:
            pass
if Flag >= 1:
    print(min(ANSlist))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S = str(input())
T = str(input())
slist = list(S)
tlist = list(T)
Slen = len(slist)
Tlen = len(tlist)
ANSlist = []
Flag = 0
for i in range(Slen-Tlen+1):
    flag = 0
    for j in range(Tlen):
        if slist[i+j] == "?" or slist[i+j] == tlist[j]:
            pass
        else:
            flag = 1
            break
    if flag == 0:
        Skari = ""
        k = 0
        for k in range(i):
            if slist[k] == "?":
                Skari+="a"
            else:
                Skari+=slist[k]
        l = 0
        for l in range(Tlen):
            Skari+=tlist[l]
        m = 0
        Skarilen = len(Skari)
        for m in range(Slen-Skarilen):
            M = m+Slen
            if slist[M] == "?":
                Skari+="a"
            else:
                Skari+=slist[M]
        ANSlist.append(Skari)
        Flag+=1
    else:
        pass
if Flag >= 1:
    print(min(ANSlist))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vp;
typedef map<string, ll> mstrll;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fir first
#define sec second
#define maxs(x, y) (x = max(x, y))
#define mins(x, y) (x = min(x, y))
#define all(x) begin(x), end(x)
#define rall(x) rbegin(x), rend(x)
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
#define out(x) cout << (x)
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
ll gcd(ll a, ll b){return b != 0 ? gcd(b, a % b) : a;}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}
const ll INF = 1e16;
const ll MOD = 1e9 + 7;
ll a, b, c, n, m, x, y, z, w, h, cnt, mx, mn;
string s, t;
vll dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
//vll dx = {-1, 0, 1, -1, 1, -1, 0, 1}, dy = {-1, -1, -1, 0, 0, 1, 1, 1};

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    while(cin >> s >> t){
        string ans = "";
        ll t_start = -1;
        rep(i, s.size() - t.size() + 1){
            if(s[i] == t[0]){
                bool flag = true;
                rep(j, t.size()){
                    if(s[i + j] != t[j] && s[i + j] != '?'){
                        flag = false;
                        break;
                    }
                }
                if(flag){
                    t_start = i;
                }
            }
        }
        if(t_start == -1){
            print("UNRESTORABLE");
            continue;
        }
        rep(i, s.size()){
            if(i >= t_start && i < t_start + t.size()){
                ans += t[i - t_start];
            }else{
                ans += ((s[i] == '?') ? 'a' : s[i]);
            }
        }
        print(ans);
    }
}

Submission status: Runtime Error

Solution code:
S = input()
T = input()
 
ans = 'UNRESTORABLE'
for i in range(len(S) - len(T) + 1):
    s = S[i:i+len(T)+1]
    flag = 1
    for j in range(len(T)):
        if s[j] == T[j] or s[j] == '?':
            pass
        else:
            flag = 0
    if flag:
        ans = S[0:i] + T + S[i+len(T)]
        ans = ans.replace('?', 'a')
print(ans)

Submission status: Runtime Error

Solution code:
S_ = list(input())
T = list(input())
for i in range(len(S_)):
    for j in range(len(T)):
        if S_[i] == T[j]:
            i_ = i
            j_ = 0
            for l in range(i - T.index(T[j]), i - T.index(T[j]) + len(T)):
                if S_[l] != T[j_] and S_[l] != '?':
                    break
            else:
                S_[(i - T.index(T[j])):(i - T.index(T[j]) + len(T))] = T
                for k in range(len(S_)):
                    if S_[k] == '?':
                        S_[k] = 'a'
                S = "".join(S_)
                print(S)
                exit()
print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
_ = list(input())
T = list(input())
for i in range(len(S_)):
    for j in range(len(T)):
        if S_[i] == T[j]:
            i_ = i
            j_ = j
            for k in range(j, len(T)):
                if T[k] != S_[i_] and S_[i_] != '?':
                    break
                i_ += 1
            else:
                S_[i:] = T[j:]
                for l in range(len(S_)):
                    if S_[l] == '?':
                        S_[l] = 'a'
                S = "".join(S_)
                print(S)
                exit()
print("UNRESTORABLE")

Submission status: Runtime Error

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

ans = ''

for i in range(0, len(SD) - len(T)+1):
    flg = True
    for j in range(len(T)):
        if SD[i+j] == '?' or SD[i+j] == T[j]:
            continue
        else:
            flg = False
    if flg == True:
        ans = SD[0:i] + T + S[i+len(T):]
            
if ans:
    ans = ans.replace('?', 'a')
else:
    ans = 'UNRESTORABLE'
    
print(ans)

Submission status: Runtime Error

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

ans = ''

for i in range(0, len(SD) - len(T)+1):
    flg = True
    for j in range(len(T)):
        if SD[i+j] == '?' or SD[i+j] == T[j]:
            continue
        else:
            flg = False
    if flg == True:
        ans = SD[:i] + T + S[i+len(T):]
            
if ans:
    ans = ans.replace('?', 'a')
else:
    ans = 'UNRESTORABLE'
    
print(ans)

Submission status: Runtime Error

Solution code:
S = input()
T = input()
r_S = S[::-1]
r_T = T[::-1]
if T in S:
    q_ans = r_S
else:
    for i in range(len(r_S)-len(T)+1):
        flag = True
        for j in range(len(T)):
            if r_S[i+j] == '?':
                pass
            elif r_S[i+j] == r_T[j]:
                pass
            elif r_S[i+j] != r_T[j]:
                flag = False
                break
        if flag:
            q_ans = r_S[:i] + r_T + r_S[i+len(T):]
            break
    if not flag:
        print('UNRESTORABLE')
        exit()

q_ans = q_ans[::-1]
ans = ''
for i in q_ans:
    if i == '?':
        ans += 'a'
    else:
        ans += i
print(ans)

Submission status: Runtime Error

Solution code:
s=input()
t=input()
ans=""
k=0
l=0
for i in range(len(s)):
    x=i+k
    y=0
    if x>=len(s):
        break
    if s[i+k]==t[0]:
        for j in range(len(t)):
            if (s[x+j]==t[j] or s[x+j]=="?")and x+j<len(s):
                y+=1
            else:
                break
        if y==len(t):
            ans+=t
            k+=len(t)-1
            l=1
        
    else:
        ans+=s[i+k]

ans=ans.replace("?","a")  
if l==1:
    print(ans)    
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
s=input()
t=input()
ans=""
k=0
l=0
for i in range(len(s)):
    x=i+k
    y=0
    if x>=len(s):
        break
    if s[i+k]==t[0]:
        for j in range(len(t)):
            if (s[x+j]==t[j] or s[x+j]=="?")and x+j<len(s):
                y+=1
            else:
                break
        if y==len(t):
            ans+=t
            k+=len(t)
            l=1
        
    else:
        ans+=s[i]

ans=ans.replace("?","a")  
if l==1:
    print(ans)    
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S1=input()
T1=input()
S=""
T=""
A=""
for i in range(1,len(S1)+1):
    S+=S1[-i]
for i in range(1,len(T1)+1):
    T+=T1[-i]
j=0
i=0
flag = False
while i<=len(S)+1-len(T):
    while j<=len(T)+1:
        if i==len(S)-len(T):
            A="UNRESTORABLE"
            flag=True
            break
        elif j==len(T):
            P=S.replace(S[i:i+len(T)],T,1)
            Q=P.replace("?","a")
            for i in range(1,len(Q)+1):
                A+=Q[-i]
            flag=True
            break
        elif S[i+j]==T[j] or S[i+j]=="?":
            j+=1
        else:
            j=0
            i+=1
    if flag:
        break
print(A)

Submission status: Runtime Error

Solution code:
S=input()
T=input()
j=0
i=-1
flag = False
while i>=-1*len(S)-1+len(T):
    while j>=-1*len(T)-1:
        if i==-1*len(S)-1+len(T):
            A="UNRESTORABLE"
            flag=True
            break
        elif j==-1*len(T):
            if i!=-1:
                P=S.replace(S[i-len(T)+1:i+1],T,1)
                A=P.replace("?","a")
                i=-1*len(S)-1+len(T)
                flag=True
                break
            else:
                P=S.replace(S[i-len(T)+1:],T,1)
                A=P.replace("?","a")
                flag=True
                break
        elif S[i+j]==T[j-1] or S[i+j]=="?":
            j=j-1
        else:
            j=0
            i=i-1
    if flag:
        break
print(A)

Submission status: Runtime Error

Solution code:
S=input()
T=input()
j=0
i=-1
flag = False
while i>=-1*len(S)-1+len(T):
    while j>=-1*len(T)-1:
        if i<=-1*len(S)-1+len(T):
            A="UNRESTORABLE"
            flag=True
            break
        elif j==-1*len(T):
            if i!=-1:
                P=S.replace(S[i-len(T):i+1],T,1)
                A=P.replace("?","a")
                i=-1*len(S)-1+len(T)
                flag=True
                break
            else:
                P=S.replace(S[i-len(T):],T,1)
                A=P.replace("?","a")
                flag=True
                break
        elif S[i+j]==T[j-1] or S[i+j]=="?":
            j=j-1
        else:
            j=0
            i=i-1
    if flag:
        break
print(A)

Submission status: Runtime Error

Solution code:
s=input()
t=input()
l=[]
for i in range(len(s)-len(t)+1):
    sl=copy.deepcopy(s)
    for j in range(len(t)):
        if sl[i+j]!=t[j] and sl[i+j]!='?':
            break
    else:
        s = s[:i] + t + s[i+len(t):]
        l.append(s.replace('?', 'a'))
l.sort()
if l:
    print(l[0])
else:
    print('UNRESTRABLE')

Submission status: Runtime Error

Solution code:
Sdash = str(input())
T = str(input())

reslis = []
N = len(Sdash) - len(T) + 1
for i in range(N):
    Tdash = Sdash[i:i+len(T)]
    for j in range(len(T)):
        if Tdash[j] == T[j] or Tdash[j] == "?":
            pass
        else:
            break
    else:
        if i == 0:
            reslis.append(T + Sdash[i+len(T)])
        elif i == N - 1:
            reslis.append(Sdash[:i] + T)
        else:
            reslis.append(Sdash[:i] + T + Sdash[i+len(T)])

if reslis:
    reslis = [st.replace("?","a") for st in reslis]
    reslis.sort()
    print(reslis[0])

else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
Sdash = str(input())
T = str(input())

reslis = []
N = len(Sdash) - len(T) + 1
for i in range(N):
    Tdash = Sdash[i:i+len(T)]
    for j in range(len(T)):
        if Tdash[j] == T[j] or Tdash[j] == "?":
            pass
        else:
            break
    else:
        print(Tdash)
        if i == 0:
            reslis.append(T + Sdash[i+len(T)])
        elif i == N - 1:
            reslis.append(Sdash[:i] + T)
        else:
            reslis.append(Sdash[:i] + T + Sdash[i+len(T)])

if reslis:
    reslis = [st.replace("?","a") for st in reslis]
    reslis.sort()
    print(reslis[0])

else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
sp = list(input())
t = list(input())
n = len(sp)
for i in range(len(t), n + 1):
    flag = True
    for j in range(len(t)):
        if sp[n - i + j] != t[j] and sp[n - i + j] != '?':
            flag = False
            break
    if flag:
        s = ''
        sp[n - i:n - i + len(t)] = t
        for j in range(n):
            if sp[j] == '?':
                s += 'a'
            else:
                s += ss[j]
        print(s)
        exit()
print('UNRESTORABLE')

Submission status: Runtime Error

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

for i in range(len(sd)-len(T),-1,-1):
#    print(i)
    st=sd[i:len(T)+i]
#    print(sd[i:len(T)+i])
    fl=True
    for j in range(len(T)):
        if st[j]!='?':
            if st[j]!=T[j]:
                fl=False
    if fl:
        s=sd[:i]+T+sd[len(T)+i:]
        for k in range(len(s)):
            if s[k]=='?':
                s=s[:k]+'a'+s[k+1:]
        break
if fl:
    print(s)
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

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

if ok:
    print(S.replace('?', 'a'))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
a = input()
t = input()
n = len(a)
m = len(t)
if n<m:
  print(UNRESTORABLE)
  exit()
for i in range(n-m+1)[::-1]:
  flag = True
  for j in range(m):
    if a[i+j] != t[j] and a[i+j] != "?":
      flag = False
  if flag:
    b = a.replace("?","a")
    print(b[:i] + t + b[i+m:])
    exit()
        
print(UNRESTORABLE)