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 = str(input())
t = str(input())
ans = "NG"
for i in reversed(range(len(s))):
    if ans == "OK":
        ind = i+1
        break
    if s[i] == t[0]:
        a = 0
        while a < len(t):
            if s[i+a] == t[0+a] or s[i+a] == "?":
                a += 1
            else:
                break
        else:
            ans = "OK"
else:
    ans = "NG"

if ans == "NG":
    print("UNRESTORABLE")
else:
    list_s = list(s)
    for j in range(len(t)):
        list_s[ind + j] = t[j]
    for i in range(len(list_s)):
        if list_s[i] == "?":
            list_s[i] = "a"
    print("".join(list_s))

Submission status: Runtime Error

Solution code:
S = input()
T = input()
s = 'T'
for i in range(len(S)-len(T)+1):
    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):]
        s = s.replace('?', 'a')
        print(s)
        break
if s ='T':
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:

S = input()
T = input()
res = ''

for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        end = i + j
        if S[i+j] == T[j]:
            flag = 1
        elif S[i+j] == '?':
            flag = 1
        else:
            flag = -1
            break
    if flag == 1:
        break
            
if start == -1:
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Submission status: Runtime Error

Solution code:
S = input()
T = input()
res = ''
end = -1
for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        
        if S[i+j] == T[j]:
            end = i + j
            flag = 1
        elif S[i+j] == '?':
            end = i + j
            flag = 0
        else:
          	flag = 0
            pass
            break
    if flag == 1:
        break
            
if end == -1:
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Submission status: Runtime Error

Solution code:
S = input()
T = input()
res = ''
end = -1
for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        
        if S[i+j] == T[j]:
            end = i + j
            flag == 1
        elif S[i+j] == '?':
            end = i + j
            flag == 1
        else:
            pass
            break
    if flag == 1:
        break
            
if end == -1:
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Submission status: Runtime Error

Solution code:
S = input()
T = input()
res = ''
end = -1
for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        
        if S[i+j] == T[j]:
            end = i + j
        elif S[i+j] == '?':
            end = i + j        
        else:
            pass
            break
    if flag == 1:
        break
            
if end == -1:
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Submission status: Runtime Error

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

for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        end = i + j
        if S[i+j] == T[j]:
            flag = 1
        elif S[i+j] == '?':
            flag = 0
        else:
            flag = -1
            break
    if flag == 1:
        break
            
if flag == -1:
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Submission status: Runtime Error

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

for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        end = i + j
        if S[i+j] == T[j]:
            flag = 1
        elif S[i+j] == '?':
            flag = 0
        else:
            flag = -1
            break
    if flag == 1:
        break
            
if start == 0 and end == 0 and flag == -1:
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Submission status: Runtime Error

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

for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        end = i + j
        if S[i+j] == T[j]:
            flag = 1
        elif S[i+j] == '?':
            flag = 0
        else:
            flag = -1
            break
    if flag == 1:
        break
            
if (start == 0) and (end == 0) and (flag == -1):
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Submission status: Runtime Error

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

for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        end = i + j
        if S[i+j] == T[j]:
            flag = 1
        elif S[i+j] == '?':
            flag = 0
        else:
            start = 0
            end = 0
            flag = -1
            break
    if flag == 1:
        break
            
if flag == -1:
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Submission status: Runtime Error

Solution code:
S = input()
T = input()
tmp = ''
res = ''

count = 0
for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        end = i + j
        if S[i+j] == T[j]:
            flag = 1
        elif S[i+j] == '?':
            flag = 0
        else:
            start = 0
            end = 0
            flag = -1
            break
    if flag == 1:
        break
            
if flag == -1:
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Submission status: Runtime Error

Solution code:
S = input()
T = input()
tmp = ''
res = ''

count = 0
for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        end = i + j
        if S[i+j] == T[j]:
            flag = 1
        elif S[i+j] == '?':
            flag = 0
        else:
            start = 0
            end = 0
            flag = 0
            break
    if flag == 1:
        break
            
if (start == 0) and (end == 0):
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Submission status: Runtime Error

Solution code:
S = input()
T = input()
tmp = ''
res = ''

count = 0
for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        end = i + j
        if S[i+j] == T[j]:
            tmp += T[j]
        elif S[i+j] == '?':
            tmp += '?'
        else:
            start = 0
            end = 0
            break
            
if (start == 0) and (end == 0):
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Submission status: Runtime Error

Solution code:
S = input()
T = input()
tmp = ''
start = 0
result_list = []
for i, s in enumerate(S):
    if s == '?':
        start = i
        tmp += s
    elif s == T[len(tmp)]:
        start = i
        tmp += s
    else:
        tmp = ''
    if len(tmp) == len(T):
        while start + 1 <= len(S) and S[start + 1] == '?':
            start += 1
        result = S[:start - len(T) + 1] + T + S[start + 1:]
        result_list.append(result.replace('?', 'a'))
        tmp = ''
if len(result_list) == 0:
    print('UNRESTORABLE')
else:
    print(result_list[-1])

Submission status: Runtime Error

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

t_length = len(T)

tmp = ''
result = ''
start = 0
result_list = []
for i, s in enumerate(S):
    if s == '?':
        start =i
        tmp += s
        result += s
    elif s == T[len(tmp)]:
        start = i
        tmp += s
    else:
        tmp = ''
        result += s
    if len(tmp) == len(T):
        while S[start+1] == '?':
            start += 1
        result = S[:start-len(T)+1] + T + S[start+1:]
        result_list.append(result.replace('?', 'a'))
        tmp = ''
if len(result_list) == 0:
    print('UNRESTORABLE')
else:
    print(result_list[-1])

Submission status: Runtime Error

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

N = len(S2)

index = -1
q_num = 0
q_index = -1
tmp = 0
for i in range(N):
    if S2[i] == '?':
        tmp += 1
        q_num = max(q_num, tmp)
        if len(T) <= q_num:
            q_index = i - q_num + 1
    else:
        tmp = 0
    if S2[i] == T[0] and i + len(T) <= N:
        index = i

if len(T) > N:
    S = list('UNRESTORABLE')
elif len(T) <= q_num:
    S = list(S2)
    S[q_index:q_index + len(T)] = list(T)
    for i in range(N):
        if S[i] == '?':
            S[i] = 'a'
elif index == -1:
    S = list('UNRESTORABLE')
else:
    S = [None] * N
    for i in range(len(S)):
        if i > index:
            if S2[i] == T[i - index]:
                S[i] = S2[i]
            elif S2[i] == '?':
                S[i] = T[i - index]
            else:
                S = list('UNRESTORABLE')
        else:
            if S2[i] == '?':
                S[i] = 'a'
            else:
                S[i] = S2[i]
print(''.join(S))

Submission status: Runtime Error

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

index = S2.find(T[0])
if index == -1:
    S = list('UNRESTORABLE')
elif len(S2) - index < len(T):
    S = list('UNRESTORABLE')
else:
    S = [None] * len(S2)
    for i in range(len(S)):
        if i > index:
            if S2[i] == T[i - index]:
                S[i] = S2[i]
            elif S2[i] == '?':
                S[i] = T[i - index]
            else:
                S = list('UNRESTORABLE')
        else:
            if S2[i] == '?':
                S[i] = 'a'
            else:
                S[i] = S2[i]
print(''.join(S))

Submission status: Runtime Error

Solution code:
s = input()
t = input()
a =[]
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
    if f == True:
        a.append(i)

s = s.replace('?','a')

print(s[:a[-1]]+t+s[a[-1]+len(t):])

Submission status: Runtime Error

Solution code:
#include <bits/stdc++.h>
using namespace std;
int main(){
    string a,b;
    cin>>a>>b;
    for(int i=a.size()-1;i>=b.size()-1;i--){
        int fail=0;
        for(int j=b.size()-1;j>=0;j--){
            if(a[i+j-b.size()+1]=='?'||a[i+j-b.size()+1]==b[j]){

            }
            else{
                fail=1;
                break;
            }
        }
        if(!fail){
            for(int j=b.size()-1;j>=0;j--){
                a[i+j-b.size()+1]=b[j];
            }
            for(char c:a){
                if(c=='?')putchar('a');
                else putchar(c);
            }
            return 0;
        }
    }
    puts("UNRESTORABLE");
}

Submission status: Runtime Error

Solution code:
s = input()
t = input()
ans = ''
for i in range(len(s)-len(t), -1, -1):
    s_tmp = s[i:i+len(t)]
    flag = 0
    for j in range(len(t)):
        if s_tmp[j] == '?':
            s_tmp = t[:j+1] + s_tmp[j+1:]
        elif s_tmp[j] != t[j]:
            flag = 1
            break
    if flag == 0:
        ans = s[:i] + t + s[i+len(t):]
        break
if flag == 0:
    for i in range(len(ans)):
        if ans[i] == '?':
            ans = ans[:i] + 'a' + ans[i+1:]
    print(ans)
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
s=input()
t=input()
if len(s)<len(t):
    print("UNRESTORABLE")
else:
    x=[]
    for i in range(len(s)-len(t)+1):
        k=0
        for j in range(len(t)):
            if s[i+j]!=t[j] and s[i+j]!="?":
                k+=1
        if k==0:
            x.append((s[:i]+t+s[(i+len(t)):]).replace("?","a"))
if len(x)==0:
    print("UNRESTORABLE")
else:
    x.sort()
    print(x[0])

Submission status: Runtime Error

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

ans = "UNRESTORABLE"

memo = -1

for i in range(len(s)):
    for j in range(len(t)):
        count = 0
        if s[i+j] == t[j] or t[j] == "?":
            count += 1
        else:
            count = 0
            break
        if count == len(t):
            ans = s[i:i+len(t)]
            memo = i
            count = 0

if ans == "UNRESTORABLE":
    print(ans)
else:
    ans1 = ""
    for word in t:
        if word == "?":
            ans1 += "a"
        else:
            ans1 += word
    ans1[memo:memo+len(t)] = ans
    print(ans1)

Submission status: Runtime Error

Solution code:
S_ = input()
T = input()
a = S_
b = T
def fit(pat, word):
    return all([pi==wi for pi, wi in zip(pat, word) if pi != '?'])

for i in reversed(range(len(a)-len(b)+1)):
    if fit(a[i:i+len(b)], b):
        ret = a[:i]+b+a[i+len(b):]
        break    
print(ret.replace('?', 'a'))

Submission status: Runtime Error

Solution code:
S_ = input()
T = input()
a = S_
b = T
def fit(pat, word):
    and([pi==wi for pi, wi in zip(pat, w) if s != '?'])
for i in reversed(range(len(a)-len(b)+1)):
    if fit(a[i:i+len(b)], b):
        ret = a[:i]+b+a[i+len(b):]
    
print(ret.replace('?', 'a')

Submission status: Runtime Error

Solution code:

S = str(input())
T = str(input())
a = len(S)
b = len(T)
if (a < b):
    print("UNRESTORABLE")
    exit()
m = a-b
B = "UNRESTORABLE"
for i in range(m+1):
    for j in range(b):
        if S[i+j] == T[j]:
            S =S.replace(S[i:i+b+1], T)
            S = S.replace('?', 'a')
            B = S
            break
            
            
print(B)

Submission status: Runtime Error

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

S = []
T = []

S_a = []

for i in range(len(s)):
    S.append(s[i])

for i in range(len(t)):
    T.append(t[i])

for i in range(len(S)):
    if S[i] == T[0]:
        for j in range(len(T)):
            if S[i + j] != T[j] and S[i + j] != "?":
                print('a')
                print(S[i+j] + T[j])
                break
        if j == len(T) - 1:
            string = S[0:i] + T + S[i + len(T)::]
            S_a.append(string)
            for k in range(len(string)):
                if string[k] == "?":
                    string[k] = "a"
S_a.sort()
if S_a == []:
    print("UNRESTORABLE")
else: print(''.join(S_a[0]))

Submission status: Runtime Error

Solution code:
s_d = [i for i in input()]
t = input()
flg = True

for i in range(len(s_d)-1, -1, -1):
    if len(s_d) - i >= len(t) and s_d[i] == '?' or s_d[i] == t[0]:
        j, n = i+1, 1
        while j <= len(s_d) - 1:
            if s_d[j] == '?' or s_d[j] == t[n]:
                j += 1
                n += 1
            else:
                break

        if n >= len(t):
            s_d[i:i+len(t)] = t
            break
else:
    print("UNRESTORABLE")
    flg = False

if flg:
    for i in range(len(s_d)):
        if s_d[i] == '?':
            s_d[i] = 'a'

    print("".join(s_d))

Submission status: Runtime Error

Solution code:
s_d = [i for i in input()]
t = input()
flg = True

for i in range(len(s_d)-1, -1, -1):
    if len(s_d) - i >= len(t) and s_d[i] == '?' or s_d[i] == t[0]:
        j, n = i+1, 1
        while j < len(s_d) - 1:
            if s_d[j] == '?' or s_d[j] == t[n]:
                j += 1
                n += 1
            else:
                break

        if n >= len(t):
            s_d[i:j] = t
            break
else:
    print("UNRESTORABLE")
    flg = False

if flg:
    for i in range(len(s_d)):
        if s_d[i] == '?':
            s_d[i] = 'a'

    print("".join(s_d))

Submission status: Runtime Error

Solution code:
s_d = [i for i in input()]
t = input()
flg = True

for i in range(len(s_d)-1, -1, -1):
    if len(s_d) - i >= len(t) and s_d[i] == '?' or s_d[i] == t[0]:
        j, n = i+1, 1
        while s_d[j] == '?' or s_d[j] == t[n]:
            j += 1
            n += 1
            if j > len(s_d) - 1:
                break

        if n >= len(t):
            s_d[i:j] = t
            break
else:
    print("UNRESTORABLE")
    flg = False

if flg:
    for i in range(len(s_d)):
        if s_d[i] == '?':
            s_d[i] = 'a'

    print("".join(s_d))

Submission status: Runtime Error

Solution code:
s=list(input())
t=list(input())
sl=len(s)
tl=len(t)
for k in range(sl-tl+2):
    judge=True
    for i in range(tl):
        if s[i+k]==t[i] or s[i+k]=="?":
            pass
        else:
            judge=False
            break
    if judge:
        for i in range(tl):
            s[i+k]=t[i]
        for i in range(sl):
            if s[i]=="?":
                s[i]="a"
        print("".join(s))
        exit()
print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
s=list(input())
t=list(input())
sl=len(s)
tl=len(t)
for i in range(sl-tl,-1,-1):
    j=0
    while j<tl:
        if s[j+1]==t[j] or s[j+i]=="?":
            j+=1
        else:
            break
    if j==tl:
        for i in range(tl):
            s[i+k]=t[k]
        for j in range(sl):
            if s[j]=="?":
                s[j]="a"
        print("".join(s))
        exit()
print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
s = list(str(input()))
t = list(str(input()))
ans = []
an = 0
if len(s) < len(t):
    print("UNRESTORABLE")
    exit()
for i in range(len(s)-len(t)+1):
    cou = s[i:i+len(t)]
    for k in range(len(t)):
        if s[i+k] != t[k] and s[i+k] != "?" and t[k] != "?":
            break
        if k == len(t)-1:
            ans.append(s[:i]+t+s[i+len(t):])
for h in range(len(ans)):
    for f in range(len(s)):
        if ans[h][f] == "?":ans[h][f] = "a"
    ans[h] = "".join(ans[h])
ans.sort()
print(ans[0])

Submission status: Runtime Error

Solution code:
s = list(str(input()))
n = list(str(input()))
ans = []
for i in range(len(s)-len(n)+1):
    nu = []
    for m in range(i):nu.append(s[m])
    for k in range(len(n)):
        if s[i + k] != n[k] and s[i+k]!="?" and n[k] != "?":
            break
        if k == len(n)-1:
            nu += n
            for h in range(len(s)-(len(n)+i)):
                nu.append(s[-(len(s)-(len(n)+i)+h)])
            while "?" in nu:nu[nu.index("?")] = "a"
            ans.append("".join(nu))
if ans == []:
    print("UNRESTORABLE")
    exit()
a = sorted(ans)
print(a[0])

Submission status: Runtime Error

Solution code:
s=input()
t=input()
n=len(s)-len(t)+1
lst=[]
for i in range(n):
    tot=0
    ss=s
    for j in range(len(t)):
        if ss[i+j]==t[j] or ss[i+j]=="?":
            tot+=1
    if tot==len(t):
        for j in range(len(t)):
            ss[i+j]=t[j]
        ss=ss.replace("?","a")
        lst.append(ss)
lst.sort()
print(lst[0] if len(lst)!=0 else "UNRESTORABLE" )

Submission status: Runtime Error

Solution code:
s = input()
t = input()
cand = []
if len(s) < len(t):
  print('UNRESTORABLE')
else:
  for i in range(len(s)):
    if s[i] != t[0] and s[i] != '?':
      continue
    else:
      for j in range(len(t)):
        if s[i+j] != t[j] and s[i+j] != '?':
          break
        elif j == (len(t)-1):
          cand.append(i)
  if len(cand) > 0:
    result = max(cand)
    S = s[:result]+t+s[result+len(t):]
    S = S.replace('?','a')
    print(S)
  else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

def match(s1, s2):
    if len(s1) < len(s2):
        return False
    for i, j in zip(s1, s2):
        if i != j and i != "?":
            return False
    return True

result = []
for i in range(50):
    if match(s[i:], t):
        result.append((s[:i] + t + s[i + len(t):]).replace("?", "a"))
result.sort()
print(result[0])

Submission status: Runtime Error

Solution code:
```
def main():
    s = input()
    t = input()

    f(s, t)

def f(s, t):
    l_t =len(t)
    for i in reversed(range(len(s)-l_t+1)):
        b = s[i:i+l_t]
        c = sum(c1 == c2 or c2 == "?" for c1, c2 in zip(t, b))

        if c == len(t):
            print(s[:i], t, s[i+l_t:])
            ans = s[:i].replace("?", "a") + t + s[i+l_t:].replace("?", "a")
            print(ans)
            return

    print("UNRESTORABLE")


if __name__ == "__main__":
    main()
```

Submission status: Runtime Error

Solution code:
Sd = input()
T = input()
if len(Sd) < len(T):
    print("UNRESTORABLE")
else:
    D = []
    for i in range(len(Sd) - len(T) + 1):
        flag = 1
        S = Sd
        for j in range(len(T)):
            if Sd[i+j] == "?" or Sd[i+j] == T[j]:
                S = S[:i+j]+T[j]+S[i+j+1:]
            else:
                flag = 0
        if flag == 1:
            D.append(S.replace("?", "a"))
D.sort()
if len(D) == 0:
    print("UNRESTORABLE")
else:
    print(D[0])

Submission status: Runtime Error

Solution code:
S = list(input())
T = input()
flag = True
tmp_ind = len(T)-1

if len(S)>=len(T):
    for i in range(len(S)-1, -1, -1):
        if(S[i]=='?' or S[i]==T[tmp_ind]) and flag:
            if tmp_ind==0:
                s_ind = i
                flag = False
                break
            tmp_ind -= 1
        else:
            tmp_ind = len(T)-1
else:
    flag = False

if flag:
    print('UNRESTORABLE')
else:
    j = 0
    for i in range(s_ind, s_ind+len(T)):
        print(i)
        S[i] = T[j]
        j += 1
    for i in range(len(S)):
        if S[i]=='?':
            S[i] = 'a'
    print("".join(S))

Submission status: Runtime Error

Solution code:
S = list(input())
T = input()
flag = True
tmp_ind = len(T)-1

for i in range(len(S)-1, -1, -1):
if (S[i]=='?' or S[i]==T[tmp_ind]) and flag:
    if tmp_ind==0:
        s_ind = i
        flag = False
        break
    tmp_ind -= 1
else:
    tmp_ind = len(T)-1

if flag:
    print('UNRESTORABLE')
else:
    j = 0
    for i in range(s_ind, s_ind+len(T)):
        S[i] = T[j]
        j += 1
    for i in range(len(S)):
        if S[i]=='?':
            S[i] = 'a'
    print("".join(S))

Submission status: Runtime Error

Solution code:
S = list(input())
T = input()
flag = True
tmp_ind = len(T)-1

if len(S)>=len(T):
    for i in range(len(S)-1, -1, -1):
        if (S[i]=='?' or S[i]==T[tmp_ind]) and flag:
            if tmp_ind==0:
                s_ind = i
                flag = False
                break
            tmp_ind -= 1
        else:
            tmp_ind = len(T)-1
else:
    flag = False
if flag:
    print('UNRESTORABLE')
else:
    j = 0
    for i in range(s_ind, s_ind+len(T)):
        S[i] = T[j]
        j += 1
    for i in range(len(S)):
        if S[i]=='?':
            S[i] = 'a'
    print("".join(S))

Submission status: Runtime Error

Solution code:
hint = input()
t = input()
s = []
c = 0

for x in hint:
    s.append(x)
found = False

for i in t:
    if hint.rfind(i) > -1:
        for j in range(len(t)):
            if len(t) - t.index(i) <= len(hint) - hint.rfind(i):
                if hint[hint.rfind(i) - t.index(i) + j] == t[j] or "?" == hint[hint.rfind(i) - t.index(i) + j]:
                    found = True
                else:
                    found = False
            else:
                found = False

        if found:
            # initialize s
            s = []
            for x in hint:
                s.append(x)
            for k in range(t.index(i)):
                s[hint.rfind(i) - t.index(i) + k] = t[k]
            for k in range(t.index(i), len(t)):
                s[hint.rfind(i) + k] = t[t.index(i) + k]
            break

ans = ''.join(s)

if ans != hint or found:
    print(str.replace(ans, "?", "a"))

elif hint.rfind('?'*len(t)) > -1:
    for x in t:
        s[hint.rfind('?' * len(t)) + t.index(x)] = x
    ans = ''.join(s)
    print(str.replace(ans, "?", "a"))

else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
hint = input()
t = input()
s = []
c = 0

for x in hint:
    s.append(x)
found = False

for i in t:
    if hint.rfind(i) > -1:
        for j in range(len(t)):
            if len(t) - t.index(i) <= len(hint) - hint.rfind(i):
                if hint[hint.rfind(i) - t.index(i) + j] == t[j] or "?" == hint[hint.rfind(i) - t.index(i) + j]:
                    found = True
                else:
                    found = False
            else:
                found = False

        if found:
            # initialize s
            s = []
            for x in hint:
                s.append(x)
            print(s)
            for k in range(t.index(i)):
                s[hint.rfind(i) - t.index(i) + k] = t[k]
            for k in range(t.index(i), len(t)):
                s[hint.rfind(i) + k] = t[t.index(i) + k]
            break

ans = ''.join(s)

if ans != hint or found:

    print(str.replace(ans, "?", "a"))

elif hint.rfind('?'*len(t)) > -1:
    for x in t:
        s[hint.rfind('?' * len(t)) + t.index(x)] = x
    ans = ''.join(s)
    print(str.replace(ans, "?", "a"))

else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
hint = input()
t = input()
s = []
c = 0

for x in hint:
    s.append(x)
found = False

for i in t:
    if hint.rfind(i) > -1:
        for j in range(len(t)):
            if len(t) - t.index(i) <= len(hint) - hint.rfind(i):
                if hint[hint.rfind(i) - t.index(i) + j] == t[j] or "?" == hint[hint.rfind(i) - t.index(i) + j]:
                    found = True
                else:
                    found = False
            else:
                found = False

        if found:
            # initialize s
            s = []
            for x in hint:
                s.append(x)
            print(s)
            for k in range(t.index(i)):
                s[hint.rfind(i) - t.index(i) + k] = t[k]
            for k in range(t.index(i), len(t)):
                s[hint.rfind(i) + k] = t[t.index(i) + k]
            break

ans = ''.join(s)


if ans != s or found:

    print(str.replace(ans, "?", "a"))

elif hint.rfind('?' * len(t)) > -1:
    for x in t:
        s[hint.rfind('?' * len(t)) + t.index(x)] = x
    ans = ''.join(s)
    print(str.replace(ans, "?", "a"))

else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
hint = input()
t = input()
s = []
c = 0

for x in hint:
    s.append(x)
found = False

for i in t:
    if hint.rfind(i) > -1:
        for j in range(len(t)):
            print(i)
            print(hint.rfind(i))
            print(t.index(i))
            if len(t) - t.index(i) <= len(hint) - hint.rfind(i):
                if hint[hint.rfind(i) - t.index(i) + j] == t[j] or "?" == hint[hint.rfind(i) - t.index(i) + j]:
                    found = True
                else:
                    found = False
            else:
                found = False

        if found:
            # initialize s
            s = []
            for x in hint:
                s.append(x)
            print(s)
            for k in range(t.index(i)):
                s[hint.rfind(i) - t.index(i) + k] = t[k]
            for k in range(t.index(i), len(t)):
                s[hint.rfind(i) + k] = t[t.index(i) + k]
            break

ans = ''.join(s)


if ans != s or found:

    print(str.replace(ans, "?", "a"))

elif hint.rfind('?' * len(t)) > -1:
    for x in t:
        s[hint.rfind('?' * len(t)) + t.index(x)] = x
    ans = ''.join(s)
    print(str.replace(ans, "?", "a"))

else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
hint = input()
t = input()
s = []
c = 0
d = 0
for x in hint:
    s.append(x)
found = False

for i in t:
    if hint.rfind(i) > -1:
        for j in range(t.index(i), len(t)):
            if hint[hint.rfind(i) + d] == t[j] or "?" == hint[hint.rfind(i) + d]:
                d += 1
                found = True
            else:
                found = False

        if found:
            print(s)
            for k in range(t.index(i)):
                s[hint.rfind(i) - t.index(i) + k] = t[k]
            for k in range(t.index(i), len(t)):
                s[hint.rfind(i) + c] = t[k]
                c += 1
            break


ans = ''.join(s)

if ans != hint or found == True:
    print(ans.replace("?", "a"))

elif hint.rfind('?' * len(t)) > -1:
            for x in t:
                s[hint.rfind('?' * len(t)) + t.index(x)] = x
            found = True

else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
hint = input()
t = input()
s = []
c = 0
d = 0
for x in hint:
    s.append(x)
found = False

for i in t:???
        for j in range(t.index(i), len(t)):
            if hint[hint.rfind(i) + d] == t[j] or "?" == hint[hint.rfind(i) + d]:
                d += 1
                found = True
            else:
                found = False

        if found:
            for k in range(t.index(i)):
                s[hint.rfind(i) - t.index(i) + k] = t[k]
            for k in range(t.index(i), len(t)):
                s[hint.rfind(i) + c] = t[k]
                c += 1
            break

    elif hint.rfind('?' * len(t)) > -1:
            for x in t:
                s[hint.rfind('?' * len(t)) + t.index(x)] = x
            found = True

ans = ''.join(s)
if ans != hint or found == True:
    print(ans.replace("?", "a"))

else:
    print('UNRESTORABLE')