Problem:


Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

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

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

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

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

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

Print the string S.

If such a string does not exist, print UNRESTORABLE.  

Constraints

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

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

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

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

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

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

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



Sample input:
?tc????
coder


Sample output:
atcoder

Submission status: Runtime Error

Solution code:
import copy
S_dash = input()
T = input()

len_S = len(S_dash)
len_T = len(T)

candidate0 = list(S_dash)


ans = "z"*51

if len_S >= len_T:
  for s in range(len_S):
    cha_S = S_dash[s]
    if cha_S != "?" and cha_S in list(T):
      for t in range(len_T):
        cha_T = T[t]
        if cha_S == cha_T:
          S_cut = S_dash[s-t:s-t+len_T]
          
          candidate1 = copy.deepcopy(candidate0)
          
          for x in range(len_T):
            if S_cut[x] == "?":
              candidate1[s-t+x] = T[x]
            elif  S_cut[x] != T[x]:
              break
          
          else:
            if candidate1[s-t:s-t+len_T].count("?") == 0:
              if ans > "".join(candidate1).replace('?', 'a'):
                ans = "".join(candidate1).replace('?', 'a')
                
if ans == "z"*51:
  ans = "UNRESTORABLE"
print(ans)

Submission status: Runtime Error

Solution code:
import copy
S_dash = input()
T = input()

len_S = len(S_dash)
len_T = len(T)

candidate0 = list(S_dash)


ans = "z"*51

if len_S >= len_T:
  for s in range(len_S):
    cha_S = S_dash[s]
    if cha_S != "?" and cha_S in list(T):
      for t in range(len_T):
        cha_T = T[t]
        if cha_S == cha_T:
          S_cut = S_dash[s-t:s-t+len_T]
          
          candidate1 = copy.deepcopy(candidate0)
          
          for x in range(len_T):
            if S_cut[x] == "?":
              candidate1[s-t+x] = T[x]
            elif  S_cut[x] != T[x]:
              break
          
          else:
            if candidate1[s-t:s-t+len_T].count("?") == 0:
              if ans > "".join(candidate1).replace('?', 'a'):
                ans = "".join(candidate1).replace('?', 'a')
                
if ans = "z"*51:
  ans = "UNRESTORABLE"
print(ans)

Submission status: Runtime Error

Solution code:
from copy import deepcopy
S = list(input())
T = list(input())
s_num = len(S)
t_num = len(T)
S_copy = deepcopy(S)
if s < t:
  print('UNRESTORABLE')
else:
  for i in range(s_num-t_num, -1, -1):
    s_key = S[i:i+t_num]
    judge = 0
    for s, t in zip(s_key, T):
      if s=='?':
        judge += 1
      elif s == t:
        judge += 1
    if judge == t_num:
      S_copy[i:i+t_num] = T
  if S == S_copy:
    print('UNRESTORABLE')
  else:
    for i in S_copy:
      if i == '?':
        print('a', end='')
      else:
        print(i, end='')

Submission status: Runtime Error

Solution code:
s = input()
t = input()
sn = len(s)
tn = len(t)
for i in range(sn-tn, -1, -1):
    matched = True
    for j in range(tn):
        if s[i+j] != t[j] and s[i+j] != '?':
            matched = False
            break
    if matched:
        break
if not matched:
    print("UNRESTORABLE")
    quit()

ans = ['a'] * sn
for j in range(0, i):
    if s[j] != '?':
        ans[j] = s[j]
for j in range(tn):
    ans[i + j] = t[j]
for j in range(i + tn, sn):
    if s[j] != '?':
        ans[j] = s[j]

print("".join(ans))

Submission status: Runtime Error

Solution code:
c=input()
t=input()
lic=list(c)
lit=list(t)
ans=[]
lia=[]
n=len(c)-len(t)
End=False
for i in range(n+1):
    hantei=True
    s='?'*i+t+'?'*(n-i)
    lis=list(s)
    for j in range(len(c)): 
        p=lic[j]
        q=lis[j]
        a=(p==q)
        if a==False and (p!='?' and q!='?'):
            hantei = False
            break
    if hantei == True:
        End = True
        ans=lis
        
    if End==True:
        for i in range(len(c)):
            if lic[i]=='?':
                lic[i]=ans[i]
        for i in range(len(c)):
            if lic[i]=='?':
                lic[i]='a'
        
        lia.append(''.join(lic))
sorted(lia)
print(lia[0])
if len(lia)==0:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S = list(input())
T = list(input())
pos = []
for i in range(len(S)):
    if S[i] == T[0]:
        flag = 1
        for j in range(len(T)):
            if not T[j] == S[i+j] and not S[i+j] == '?':
                flag = 0
                break
        if flag:
            pos.append(i)

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

words = []
for p in pos:
    word = S[0:p] + T + S[p+len(T):]
    for i in range(len(word)):
        if word[i] == '?':
            word[i] = 'a'
    words.append(word)
words.sort()
print("".join(words[0]))

Submission status: Runtime Error

Solution code:
s = list(input())
t = list(input())
ans = ["UNRESTORABLE"]
for i in range(len(s)):
    if s[i] != "?":
        for j in reversed(range(len(t))):
            if t[j] == s[i]:
                f = True
                for k in range(len(t)):
                    if not 0 <= i - j + k < len(t):
                        f = False
                        break
                    f %= (s[i - j + k] == "?" or s[i - j + k] == t[k])
                if f:
                    ans = s.copy()
                    for l in range(len(t)):
                        ans[i - j + l] = t[l]


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

Submission status: Runtime Error

Solution code:
s = list(input())
t = list(input())
ans = ["UNRESTORABLE"]
for i in range(len(s)):
    if s[i] != "?":
        for j in reversed(range(len(t))):
            if t[j] == s[i]:
                f = True
                for k in range(len(t)):
                    if not 0 <= i - j + k < len(t):
                        break
                    f %= (s[i - j + k] == "?" or s[i - j + k] == t[k])
                if f:
                    ans = s.copy()
                    for l in range(len(t)):
                        ans[i - j + l] = t[l]


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

Submission status: Runtime Error

Solution code:
s = list(input())
t = list(input())
ans = ["UNRESTORABLE"]
for i in range(len(s)):
    if s[i] != "?":
        for j in reversed(range(len(t))):
            if t[j] == s[i]:
                f = True
                for k in range(len(t)):
                    f &= (s[i - j + k] == "?" or s[i - j + k] == t[k])
                if f:
                    ans = s.copy()
                    for l in range(len(t)):
                        ans[i - j + l] = t[l]


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

Submission status: Runtime Error

Solution code:

def main():
        
    S_part = list(input())
    T_hint = list(input())
 
    N = len(S_part)
    ans = []
 
    for i in range(N):
        index_init = i
            
        if (index_init + len(T_hint) <= N):
            s = S_part[index_init:index_init + len(T_hint)]
            module = ''.join(S_part[index_init + len(T_hint)])
            
 
            if ('?' in s):
                FLAG = True
                
                for j in range(len(s)):
                    if (T_hint[j] != s[j] and s[j] == '?'):
                        s[j] = T_hint[j]
                    
                    elif (T_hint[j] != s[j] and s[j] != '?'):
                        FLAG = False
                        break
                
                
                if (FLAG):
                    ans_left = ''.join(S_part[:index_init])
                    ans_right = ''.join(s)
                                        
                    # tmp_ans = ans_left + ans_right
                    tmp_ans = ans_left + ans_right + module


                    tmp_ans = tmp_ans.replace('?', 'a')
                    
                    ans.append(tmp_ans)
 
    ans.sort()

    if (S_part.count('?') == 0):
        print(S_part)
    elif (len(ans) > 0):
        print(ans[0])
 
    else:
        print('UNRESTORABLE')
 
 
 
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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

count=0
idx=0
ok=0
for i in range(len(S)):
  if S[i]==T[count] or S[i] == '?':
    count += 1
  else:
    count = 0
  if count == len(T):
    idx = i-count+1
    ok=1
    
if not ok:
  print('UNRESTORABLE')
  exit()

ans=[]
for i in range(len(S)):
  if i in range(idx,idx+count):
    ans.append(T[i-idx])
  else:
    if S[i]=='?':
      ans.append('a')
    else:
      ans.append(S[i])
      
print(''.join(ans))

Submission status: Runtime Error

Solution code:
S = input()
T = input()
def func(s_tmp, T):
    flag = True
    for si, ti in zip(s_tmp, T):
        if si == '?':
            pass
        elif si == ti:
            pass
        else:
            flag = False
            break
    return flag

len_s = len(S)
len_t = len(T)
inv_S = S[::-1]
inv_T = T[::-1]

if len_s-len_t > 0:
    for start_pos in range(len_s-len_t-1):
        tmp_s = inv_S[start_pos:start_pos+len_t]
        flag = func(tmp_s, inv_T)
        if flag:
            break
    if flag:
        inv_S = inv_S[:start_pos] + inv_T + inv_S[start_pos+len_t:]
        inv_S_true = ''
        for s in inv_S:
            if s == '?':
                inv_S_true += 'a'
            else:
                inv_S_true += s
        print(inv_S_true[::-1])
    else:
        print('UNRESTORABLE')

else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
S = input()
T = input()
def func(s_tmp, T):
    flag = True
    for si, ti in zip(s_tmp, T):
        if si == '?':
            pass
        elif si == ti:
            pass
        else:
            flag = False
            break
    return flag

len_s = len(S)
len_t = len(T)
inv_S = S[::-1]
inv_T = T[::-1]

if len_s-len_t >= 0:
    for start_pos in range(len_s-len_t):
        tmp_s = inv_S[start_pos:start_pos+len_t]
        flag = func(tmp_s, inv_T)
        if flag:
            break
    if flag:
        inv_S = inv_S[:start_pos] + inv_T + inv_S[start_pos+len_t:]
        inv_S_true = ''
        for s in inv_S:
            if s == '?':
                inv_S_true += 'a'
            else:
                inv_S_true += s
        print(inv_S_true[::-1])
    else:
        print('UNRESTORABLE')

else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

if len(t) > len(s):
    print('UNRESTORABLE')
    exit()

lis = []
flag = 0
for i in range(len(s)):
    if s[i] == t[0]:
        for j in range(i+1, i+len(t)-1):
            if s[j] == '?' or s[j] == t[j-i]:
                flag = 1
            else:
                flag = 0
                break
    
    if flag:
        lis.append(i)
        flag = 0

if len(lis) == 0:
    print('UNRESTORABLE')
    exit()

tmp = max(lis)
s[tmp:tmp+len(t)+1] = t

for k in range(len(s)):
    if s[k] == '?':
        s[k] = 'a'


print(''.join(s))

Submission status: Runtime Error

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

if len(t) > len(s):
    print('UNRESTORABLE')
    exit()

flag = 0
for i in range(len(s)):
    if s[i] == t[0]:
        for j in range(i+1, i+len(t)-1):
            if s[j] == '?':
                flag = 1
            else:
                flag = 0
                break
    
    if flag:
        s[i:i+len(t)+1] = t
        break

if flag == 0:
    print('UNRESTORABLE')
    exit()

for k in range(len(s)):
    if s[k] == '?':
        s[k] = 'a'


print(''.join(s))

Submission status: Runtime Error

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

flag = 0
for i in range(len(s)):
    if s[i] == t[0]:
        for j in range(i+1, i+len(t)-1):
            if s[j] == '?':
                flag = 1
            else:
                flag = 0
                break
    
    if flag:
        s[i:i+len(t)+1] = t
        break

if flag == 0:
    print('UNRESTORABLE')
    exit()

for k in range(len(s)):
    if s[k] == '?':
        s[k] = 'a'


print(''.join(s))

Submission status: Runtime Error

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

Rs=list(S)[::-1]
Rt=list(T)[::-1]
N=len(S)
M=len(T)
i=0
while i+M<N:
    j=0
    while j<M:
        if Rs[i+j]=='?' or Rs[i+j]==Rt[j]:
            j+=1
        else:
            i+=1
            break
    if j==M:
        break

if j!=M:
    ans='UNRESTORABLE'
else:
    for t in Rt:
        Rs[i]=t
        i+=1
    ans=''.join(Rs[::-1]).replace('?','a')
print(ans)

Submission status: Runtime Error

Solution code:
s,t=input(),input();l,m=len(s),len(t)
for i in range(l-m+1):
 if all(c in"?"+d for c,d in zip(S[-i-m:],t)):s=s.replace(*"?a");exit(print(s[:-i-m]+t+s[l-i:]))
print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
ss = input()[::-1] #s'
t = input()[::-1]
s = '?' *len(ss)

for k in range(len(ss)):
  if ss[k]!="?":
    break

for i in range(k+len(t)):
  cnt=0
  for j in range(len(t)):
    if ss[i+j]==t[j] or ss[i+j]=="?":
      cnt+=1
  if cnt==len(t):
    break

if cnt==len(t):
  s=ss[:i]+t+ss[i+len(t):]
#  print(s[::-1])
  print(s.replace('?', 'a')[::-1])
else:
  print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
ss = input()[::-1] #s'
t = input()[::-1]
s = '?' *len(ss)

for k in range(len(ss)):
  if ss[k]!="?":
    break

for i in range(k-len(t)+1,k+len(t)):
  cnt=0
  for j in range(len(t)):
    if ss[i+j]==t[j] or ss[i+j]=="?":
      cnt+=1
  if cnt==len(t):
    break

if cnt==len(t):
  s=ss[:i]+t+ss[i+len(t):]
#  print(s[::-1])
  print(s.replace('?', 'a')[::-1])
else:
  print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
ss = input()[::-1] #s'
t = input()[::-1]
s = '?' *len(ss)

for i in range(len(ss)-len(t)+1):
  cnt=0
  for j in range(len(t)):
    if ss[i+j]==t[j] or ss[i+j]=="?":
      cnt+=1
  if cnt==len(t):
    break

if cnt==len(t):
  s=ss[0:i]+t+ss[i+len(t):]
  print(s.replace('?', 'a')[::-1])
else:
  print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
ss = input() #s'
t = input()
s = '?' *len(ss)

for i in range(len(ss)-len(t)+1):
  cnt=0
  for j in range(len(t)):
    if ss[i+j]==t[j] or ss[i+j]=="?":
      cnt+=1
  if cnt==len(t):
    break

if cnt==len(t):
  s=ss[0:i]+t+ss[i+len(t):]
  print(s.replace('?', 'a'))
else:
  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,-1,-1) :
    x=S[i:i+m]
    for j in range(m+1):
        if j==m :
            print((S[:i]+T+S[i+m:]).replace("?","a"))
            exit()
        if x[j]=="?" :
            continue
        elif x[j]!=T[j] :
            break
 
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,-1,-1) :
    x=S[i:i+m]
    print(x)
    for j in range(m+1):
        if j==m :
            print((S[:i]+T+S[i+m:]).replace("?","a"))
            exit()
        if x[j]=="?" :
            continue
        elif x[j]!=T[j] :
            break
 
print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S = input()
s = len(S)
T = input()
t = len(T)
key = 0
for i in range(0,s-t+1):
    for j,k in enumerate(S[i:i+t]):
        if k == T[j] or k =="?":
            pass
        else:
            break
    else:
        key = i
        break
    key = 100
if key == 100:
    print("UNRESTORABLE")
else:
    ans = S[0:i]+T+S[i+t:]
    ans = ans.replace("?","a")
    print(ans)

Submission status: Runtime Error

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

s = len(S)
t = len(T)
for i in range(s-t+1):
  num = s-t-i
  tmp = S[num:num+t]
  flag = True
  for j in range(t):
    if (tmp[j]!='?') and (T[j]!=tmp[j]):
      flag = False
      break
  if flag:
    if 0 < num < s-t:
      ans = S[:num] + T + S[num+t:]
    elif num == 0:
      ans = T + S[num+t:]
    else:
      ans = S[:num] + T
    break
    
if flag:
  ans = ans.replace('?', 'a')
  print(ans)
else:
  print('UNRESTORABLE')

Submission status: Runtime Error

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

s = len(S)
t = len(T)
for i in range(s-t+1):
  num = s-t-i
  tmp = S[num:num+t]
  flag = True
  for j in range(t):
    if (tmp[j]!='?') and (T[j]!=tmp[j]):
      flag = False
      break
  if flag:
    ans = S[:num] + T + S[num+t:]
    break
    
if flag:
  ans = ans.replace('?', 'a')
  print(ans)
else:
  print('UNRESTORABLE')

Submission status: Runtime Error

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

s_num = len(s)
t_num = len(t)

ans_list = []

if s_num<t_num:
    ans_list.append('UNRESTORABLE')
else:
    ind_list = []
    for i in range(s_num -t_num + 1):
        flg = True
        for j in range(t_num):
            if s[i+j] == '?':
                pass
            elif s[i+j]==t[j]:
                pass
            else:
                flg=False
                break
        if flg:
            ind_list.append(i)
if len(ind_list) ==0:
    ans_list.append('UNRESTORABLE')
else:
    for i in ind_list:
        ans = ''
        j=0
        while j <s_num:
            if j==i:
               ans = ans+t
               j = j + t_num
            elif s[j] == '?':
                ans = ans + 'a'
                j = j + 1
            else:
                ans = ans + s[j]
                j = j + 1
        ans_list.append(ans)

print(min(ans_list))

Submission status: Runtime Error

Solution code:
s = input()
t = input()
if len(s) < len(t):
  print("UNRESTORABLE")
  exit()

start = -1
for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if s[i+j] != "?" and s[i+j] != t[j]:
      break
  else:
    start = i

if start == -1:
  print("UNRESTORABLE")
else:
  ans_list = list(s)
  for i in range(len(ans_list)):
    if start <= i <= start+len(t):
      ans_list[i] = t[i-start]
    elif ans_list[i] == "?":
      ans_list[i] = "a"
  print("".join(ans_list))

Submission status: Runtime Error

Solution code:
#include <iostream>
using namespace std;

bool match(string s, string t, int j){
	for (int i=0; i<t.length(); i++){
		if (s[j+i]!='?' and s[j+i]!=t[i]) {
				return false;
		}
	}
	return true;
}


int main() {
	string s, t;//??p??d??, ab
	cin>> s>>t;
	bool matched = false;
	int point = -1;
	for (int i=0; i<=s.length()-t.length(); i++){
		if (match (s, t, i)) {
			matched = true;
			point = i;
			break;
		}
	}
	if (matched==true){
		for (int j=point; j<t.length()+point; j++) s[j]=t[j-point];
			for (int j=0; j<s.length(); j++) if (s[j]=='?') s[j]='a';
			cout << s;
			return 0;
	}
	else cout << "UNRESTORABLE\n";
}

Submission status: Runtime Error

Solution code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
t = input()

if len(s) < len(t):
    ans = "UNRESTORABLE"
else:
    reg = -1
    for i in range(len(s)-len(t),-1,-1):
        for j in range(len(t)):
            if s[i+j] != '?' and s[i+j] != t[j]:
                break
        else:
            reg = i
            break
    if reg == -1:
        ans = "UNRESTORABLE"
    elif reg == len(s)-len(t):
        s = s[:i]+t
        ans = s.replace('?','a')
    else:
        s = s[:i]+t+s[i+len(t):]
print(ans)

Submission status: Runtime Error

Solution code:
import re
S,T = input().split()
if not re.match(r"^.*("+"\?"*len(T)+")",S):
  print("UNRESTORABLE")
else:
  startN=re.match(r"^.*("+"\?"*len(T)+")",S).span(1)[0]
  S=S[:startN-1]+T+S[startN+len(T):]
  S=S.replace("?","a")
  print(S)

Submission status: Runtime Error

Solution code:
import re
S,T = input().split()
startN=re.match(r"^.*("+"\?"*len(T)+")",S).span(1)[0]
S=S[:startN-1]+T+S[startN+len(T):]
S=S.replace("?","a")
print(S)

Submission status: Runtime Error

Solution code:
s = input()
t = input()
w = []
for i in range(len(s) - len(t) + 1):
    f = True
    sx = s[i:i + len(t)]
    for si, ti in zip(sx, t):
        if si != ti and si != "?":
            f = False
        else:
            pass
    if f:
        w.append((s[:i] + t).replace("?", "a"))
if w == []:
    print("UNRESTORABLE")
else
w.sort()
print(w[0])

Submission status: Runtime Error

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


for i in range(len(S)- len(T)+1):
    X = S[i:i+len(T)]
    #print(X)
    flag = True
    for j in range(len(T)):
        if X[j] != '?' :
            if X[j] != T[j]:
                flag = False
                break
if flag == True:
    s = S[:i] + T + S[i+len(T):]
    print(s.replace('?','a'))
else :
    print('UNRESTORABLE')

Submission status: Runtime Error

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

alp='abcdefghijklmnopqrstuvwxyz'
d={}
e={}
for i in range(len(alp)):
    d[i]=alp[i]
    e[alp[i]]=i


c=[]
q=''
for i in range(len(t)+1):
    q=(t[:i] + '?'*(len(t)-i))
    m=s.rfind(q)
    if m==-1:
        continue

    c.append(m)


h=[]
for j in range(len(t),len(s)+1,1):
    q='?'*j
    m=s.rfind(q)
    if m==-1:
        continue
    h.append(m)

ans=''
if len(c)==0 and len(h)==0:
    ans='UNRESTORABLE'
elif len(c)>0 and len(h)==0:
    index=max(c)
    j=0
    for i in range(len(s)):
        if i>=index and i<= index+len(t):
            ans+=t[j]
            j+=1
        elif s[i]=='?':
            ans+='a'
        else:
            ans+=s[i]     
elif len(h)>0 and len(c)==0:
    index=max(h)
    j=0
    for i in range(len(s)):
        if i>=index and i<= index+len(t):
            ans+=t[j]
            j+=1
        elif s[i]=='?':
            ans+='a'
        else:
            ans+=s[i] 
else:
    index=max(max(c),max(h))
    j=0
    for i in range(len(s)):
        if i>=index and i<= index+len(t):
            ans+=t[j]
            j+=1
        elif s[i]=='?':
            ans+='a'
        else:
            ans+=s[i] 

print(ans)

Submission status: Runtime Error

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

ck = 0
tl = len(T)
arr = []

for i in range(len(S)):
  a = S[i]
  if a == T[ck] or a == "?":
    ck += 1
  else:
    ck = 0
  if tl == ck:
    arr.append(i-tl+1)
  
if len(arr) == 0:
  print("UNRESTORABLE")
else:
  b = arr[-1]
  ans = ""
  for i in range(len(S)):
    if i == b:
      ans += ''.join(T)
    elif i > b and i <= b + tl:
      continue
    else:
      if S[i] == "?":
        ans += "a"
      else:
        ans += S[i]
  print(ans)

Submission status: Runtime Error

Solution code:
s = input()
t = input()
num_s = len(s)
num_t = len(t)
idx_t = []

def match(s,i):
	if s[i] == t[0]:
		for j in range(num_t):
			if s[i+j] not in (t[j],'?'):
				return False
		else:
			return i
	else:
		return False

for i in range(num_s-num_t+1):
	idx = match(s,i)
	if idx != False:
		idx_t.append(idx)

if len(idx_t) == 0:
	print('UNRESTORABLE')
else:
	s0 = s
	s_l = []
	for i in idx_t:
		if i+num_t < num_s:
		  s0 = s0[:i] + t + s0[i+t:]
		else:
			s0 = s0[:i] + t
		s_l.append(s0)
	ans = min(s_l)
	print(ans.replace('?','a',100))

Submission status: Runtime Error

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

r_Sd = Sd[::-1]
r_T = T[::-1]

for i in range(len(Sd)- len(T)):
    temp_words = r_Sd[i:i+len(T)]
    res = r_Sd[0:i] + ''
    for j in range(len(T)):
        if temp_words[j] == '?' or temp_words[j] == r_T[j]:
            res+=r_T[j]
        else:
            break
    else:
        res = res + r_Sd[i+len(T):]
        break
else:
    print('UNRESTORABLE')

print(res.replace('?', 'a')[::-1])

Submission status: Runtime Error

Solution code:
def resolve():
    '''
    code here
    '''
    Sd = input()
    T = input()

    r_Sd = Sd[::-1]
    r_T = T[::-1]

    for i in range(len(Sd)- len(T)):
        temp_words = r_Sd[i:i+len(T)]
        res = r_Sd[0:i] + ''
        for j in range(len(T)):
            if temp_words[j] == '?' or temp_words[j] == r_T[j]:
                res+=r_T[j]
            else:
                break
        else:
            res = res + r_Sd[i+len(T):]
            break
    else:
        print('UNRESTORABLE')

    print(res.replace('?', 'a')[::-1])

if __name__ == "__main__":
    resolve()

Submission status: Runtime Error

Solution code:
S = list(input())
T = list(input())
s = len(S)
t = len(T)
OK = False
P = 0
for i in range(s - t + 1):
    if S[i] != T[0] and S[i] != '?':
        continue
    for j in range(1, t):
        if S[i + j] != T[j] and S[i + j] != '?':
            break
        if j == t - 1:
            OK = True
            P = i
for k in range(t):
    S[P + k] = T[k]
for i in range(s):
    if S[i] == '?':
        S[i] = 'a'
if OK:
    [print(S[i], end='') for i in range(s)]
    print('')
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
S = list(input())
T = list(input())
s = len(S)
t = len(T)
OK = False
P = 0
for i in range(s - t + 1):
    if S[i] != T[0] and S[i] != '?':
        continue
    for j in range(1, t):
        if S[i + j] != T[j] and S[i + j] != '?':
            OK = False
            break
        if j == t - 1:
            OK = True
            P = i
for k in range(t):
    S[P + k] = T[k]
for i in range(s):
    if S[i] == '?':
        S[i] = 'a'
if OK:
    [print(S[i], end='') for i in range(s)]
    print('')
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
from math import floor
from decimal import Decimal

S = list(input())
T = list(input())

isSuccess = False

for i in reversed(range(len(S) - len(T) + 1)):
    T_str = S[i: i + len(T)]
    for j in range(len(T)):
        if T_str[j] != T[j] and T_str[j] != "?":
        break
    else:
        isSuccess = True
        S[i:i + len(T)] = T
        break
if isSuccess == False:
    print("UNRESTORABLE")
else:
    string = ",".join(S)
    string = string.replace('?', 'a')
    S = string.split(',')
    print("".join(map(str,S)))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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

flag = 0
if t in s:
  s = s.replace('?', 'a')
  print(s)
  flag = 1
if '?' * len(t) in s:
  s = s[::-1]
  s = s.replace((t[:i] + '?' * (len(t) - i))[::-1], t[::-1], 1)
  s = s.replace('?', 'a')
  print(s[::-1])
  flag = 1          

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

Submission status: Runtime Error

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

termi = len(S)
tab= len(T)
result = []
def rec(r,st):
    if r  >= termi:
        result.append(st)
    else:
        if S[r] =='?':
            rec(r+1,st+'a')
        elif S[r] == T[0]:
            rec(r+tab,st+T)
            rec(r+1,st+'a')
        else:
            rec(r+1,st+S[r])

rec(0,'')
result2 = []

for item in result:
    f = True
    if len(item) != termi or (T not in item):
        f = False
    for k,ss in enumerate(item):
        if S[k] != "?" and S[k] != ss:
            f = False

    if f:
        result2.append(item)
if len(result2) == 0:
    print('UNRESTORABLE')
else:
    ans = min(result2)
    print(ans)

Submission status: Runtime Error

Solution code:
S = list(input())
N = len(S)
T = input()
M = len(T)

ans = "UNRESTORABLE"

def changehatena(S):
    S = "".join(S)
    S = S.replace("?", "a")
    return S

def check_after(S, i):
    try:
        if S[i+1] == T[-1]:
            return True
        else:
            return False
    except:
        return False

def check_before(S, i):
    if i-M+2 < 0:
        return False
    try:
        if S[i-M+2] == T[0]:
            return True
        else:
            return False
    except:
        return False


for i in reversed(range(N)):
    hatena_num = 0
    if S[i] == "?":
        hatena_num = 1
        for j in reversed(range(i)):
            if S[j] == "?":
                hatena_num += 1
            else:
                break
        if hatena_num > M-1:
            if check_after(S, i):
                # print("check1")
                tmp = 0
                for k in reversed(range(M-1)):
                    S[i-tmp] = T[k]
                    tmp += 1
                ans = changehatena(S)
                break
            elif check_before(S, i):
                # print("check2")
                tmp = 0
                for k in reversed(range(M-1)):
                    S[i-tmp] = T[k]
                    tmp += 1
                ans = changehatena(S)
                break
            tmp = 0
            for k in reversed(range(M)):
                S[i-tmp] = T[k]
                tmp += 1
            ans = changehatena(S)
            break
        elif hatena_num == M-1:
            try:
                if S[i+1] == T[-1]:
                    # print("check3")
                    tmp = 0
                    for k in reversed(range(M-1)):
                        S[i-tmp] = T[k]
                        tmp += 1
                    ans = changehatena(S)
                    break
            except:
                pass
            try:
                if S[i-M+1] == T[0]:
                    # print("check4")
                    tmp = 0
                    for k in reversed(range(1, M)):
                        S[i-tmp] = T[k]
                        tmp += 1
                    ans = changehatena(S)
                    break
            except:
                pass
        elif hatena_num == M-2:
            raise
            if check_after(S, i) and check_before(S, i):
                S[i-M+3:i+1] = T[1:-1]
                ans = changehatena(S)
                break
print(ans)