Problem:


Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

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

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

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

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

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

Print the string S.

If such a string does not exist, print UNRESTORABLE.  

Constraints

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

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

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

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

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

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

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



Sample input:
?tc????
coder


Sample output:
atcoder

Submission status: Runtime Error

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

sl = len(s)
tl = len(t)

lst = []
for i in range(sl):
    if s[i] == t[0]:
        lst.append(i)
        
k = []

for i in lst:
    cnt = 0
    for j in range(tl):
        if s[i+j]==t[j] or s[i+j]=='?':
            cnt += 1
    if cnt == tl:
        ans = s[:i] + t + s[i+tl:]
        ans = ans.replace('?','a')
        k.append(ans)

if len(k)==0:
    print('UNRESTORABLE')
else:
    
    kk = sorted(k)
    print(kk[0])

Submission status: Runtime Error

Solution code:
S = list(input())
T = list(input())
for i in range(len(S)):
    if S[i] == T[0] or S[i] == '?':
        for j in range(len(T)):
            #print(T[j], S[i+j])
            if T[j] != S[i+j] and S[i+j] != '?':
                break
        else:
            for k in range(len(T)):
                S[i+k] = T[k]
            for k in range(len(S)):
                if S[k] == '?':
                    print('a',end="")
                else:
                    print(S[k],end="")
            print("")
            exit(0)
print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S = input()[::-1]
T = input()[::-1]

s = len(S)
t = len(T)

i = 0
j = 0
flag = 0
while True:
    if S[i] == '?' or S[i] == T[0]:
        p = i
        j = 0
        while True:
            if S[p] != '?' and S[j] != T[j]:
                break

            p += 1
            j += 1
            if j == t:
                flag = 1
                ind = i
                break
        if flag:
            break

    i += 1
    if s == i:
        break

ans = ''

if not flag:
    print('UNRESTORABLE')
else:
    i = 0
    while True:
        if i == ind:
            ans += T
            i += t
        elif S[i] == '?':
            ans += 'a'
            i += 1
        else:
            ans += S[i]
            i += 1

        if i == s:
            print(ans[::-1])
            exit()

Submission status: Runtime Error

Solution code:
S = input()[::-1]
T = input()[::-1]

s = len(S)
t = len(T)

i = 0
j = 0
flag = 0
while True:
    if S[i] == '?' or S[i] == T[0]:
        j = 0
        while True:
            if S[j] != '?' and S[j] != T[j]:
                break

            j += 1
            if j == t:
                flag = 1
                ind = i
                break
        if flag:
            break

    i += 1
    if s == i:
        break

ans = ''

if not flag:
    print('UNRESTORABLE')
else:
    i = 0
    while True:
        if i == ind:
            ans += T
            i += t
        elif S[i] == '?':
            ans += 'a'
            i += 1
        else:
            ans += S[i]
            i += 1

        if i == s:
            print(ans[::-1])
            exit()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import sys
import copy
import collections
from bisect import bisect_left
from bisect import bisect_right
from collections import defaultdict
from heapq import heappop, heappush
import math

# NO, PAY-PAY
#import numpy as np
#import statistics
#from statistics import mean, median,variance,stdev

def inputInt(): return int(input())
def inputMap(): return map(int, input().split())
def inputList(): return list(map(int, input().split()))
 
def main():
    S = list(input())
    T = list(input())
    
    isOk = False
    for i in range(len(S)):
        if S[i] == "?":
            continue
        
        flg = True
        for j in range(len(T)):
            
            #print("{} {}".format(S[i+j], T[i]))
            
            if S[i+j] != T[j]:
                if S[i+j] != "?":
                    flg = False
                    break
                
        if flg == True:
            isOk = True
            for j in range(len(T)):
                S[i+j] = T[j]
    
    if isOk == False:
        print("UNRESTORABLE")
    else:
        for i in range(len(S)):
            if S[i] == "?":
                S[i] = "a"
        print("".join(S))
    
            	
if __name__ == "__main__":
	main()

Submission status: Runtime Error

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

n=len(T)
Thatena=[[T[j] if (i>>j)&1 else "?" for j in range(n)] for i in range(2**n)] #Tのうち0文字以上を?に置き換えたものの集合
#print(Thatena)
#print(len(Thatena))
ans=[]
for t in Thatena:
    if S.find("".join(t))!=-1:
        anslist.append(S.rfind("".join(t)))
        break
if anslist==[]:
    print("UNRESTORABLE")
    exit()
#print(anslist[0],anslist[0]+len(T))
ans=S[:anslist[0]]+T+S[anslist[0]+len(T):]
print("".join([c if c!="?" else "a" for c in ans]))

Submission status: Runtime Error

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

n=len(T)
Thatena=[[T[j] if (i>>j)&1 else "?" for j in range(n)] for i in range(2**n)] #Tのうち0文字以上を?に置き換えたものの集合
#print(Thatena)
#print(len(Thatena))
anslist=[S.find("".join(t)) for t in Thatena if S.find("".join(t))!=-1]

#print(anslist[0],anslist[0]+len(T))
ans=S[:anslist[0]]+T+S[anslist[0]+len(T):]
print("".join([c if c!="?" else "a" for c in ans]))

Submission status: Runtime Error

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

def insert_hint(item,hintindex,S):
  for i in hintindex:
    item.insert(i,S[i])
  return item
  
hintindex=[n for _,n in enumerate(range(len(S))) if S[n]!="?"]

zenbu=list(itertools.permutations(
  list("abcdefghijklmnopqrstuvwxyz"),
  len(S)-len(hintindex)
))
zenbu=[insert_hint(list(item),hintindex,S) for item in zenbu]
#print(zenbu[-1])

anslist=[item for item in zenbu if "".join(item).find(T)!=-1]

#print(anslist)
print("".join(sorted(anslist)[0]))

Submission status: Runtime Error

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

def insert_hint(item,hintindex,S):
  for i in hintindex:
    item.insert(i,S[i])
  return item
  
hintindex=[n for _,n in enumerate(range(len(S))) if S[n]!="?"]

zenbu=list(itertools.permutations(
  list("abcdefghijklmnopqrstuvwxyz"),
  len(S)-len(hintindex)
))
zenbu=[insert_hint(list(item),hintindex,S) for item in zenbu]
#print(zenbu[-1])

anslist=[item for item in zenbu if "".join(item).find(T)!=-1]

print(anslist)
print("".join(sorted(anslist)[0]))

Submission status: Runtime Error

Solution code:
s = input()
t = input()
passlist = []
for i in reversed(range(1,len(s)-len(t)+2)):
	u = s[i-1:i+len(t)-1]
	flag = True
	for i in range(len(u)):
		if(u[i] != '?' and u[i] != t[i]):
			flag = False
	if flag:
		text = (s[:i-2] + t + s[-1+len(t)-1+i:]).replace('?','a')
		passlist.append(text)

passlist.sort()
print(passlist[0])

Submission status: Runtime Error

Solution code:
s=input()
t=input()
u=''
v=[]
count=0

for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if t[j]==s[i+j] or s[i+j]=='?':
            count+=1
    if count==len(t):
        for k in range(len(s)):
            if k>=i:
                u+=t[k-i]
            elif s[k]=='?':
                u+='a'
            else:
                u+=s[k]
                    
                    
        v.append(u)
        u=''
    count=0
if v==[]:
    print('UNRESTORABLE')
else:
    print(min(v))

Submission status: Runtime Error

Solution code:
s=input()
t=input()
u=''
v=[]
count=0

for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if t[j]==s[i+j] or s[i+j]=='?':
            count+=1
    if count==len(t):
        for k in range(len(s)):
            if k>=i:
                u+=t[k-i]
            elif s[k]=='?':
                u+='a'
            else:
                u+=s[k]
                    
                    
        v.append(u)
        u=''
    count=0
    
print(min(v))

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python3
#ABC76 C

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

ns = len(s)
nt = len(t)
f = 0
for i in range(ns):
    if s[i] in t:
        ind = t.index(s[i])
        for j in range(i-ind,i-ind+nt):
            if s[j] == t[j-i+ind] or s[j] == '?':
                continue
            else:
                break
        else:
            f = 1
            s[i-ind:i-ind+nt] = t
            break
    if s[i] == '?':
        for j in range(i,i+nt):
            if s[j] == t[j-i] or s[j] == '?':
                continue
            else:
                break
        else:
            f = 1
            s[i:i+nt] = t
            break 
if f:
    for i in range(ns):
        if s[i] == '?':
            s[i] = 'a'
    print(''.join(s))
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
S = input()
T = input()
slide_num = len(S) - len(T)
if slide_num < 0:
    exit()
for slide in range(slide_num+1):
    for j in range(len(S)-slide):
        if S[j+slide] == T[j] or S[j+slide] == '?':
            None
        else:
            break
    else:
        print((S[:slide] + T + S[slide+len(T):]).replace('?', 'a'))
        exit()
print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
S = input()
T = input()
slide_num = len(S) - len(T)
if slide_num < 0:
    exit()
for slide in range(slide_num+1):
    for j in range(len(S)-slide):
        if S[j+slide] == T[j] or S[j+slide] == '?':
            None
        else:
            break
    else:
        print((S[:2] + T + S[2+len(T):]).replace('?', 'a'))
        exit()
print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
S = input()
T = input()
slide_num = len(S) - len(T)
if slide_num < 0:
    pass
for slide in range(slide_num+1):
    for j in range(len(S)-slide):
        if S[j+slide] == T[j] or S[j+slide] == '?':
            None
        else:
            break
    else:
        print((S[:2] + T + S[2+len(T):]).replace('?', 'a'))
        exit()
print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
def output(S,T,i,j):
  op = ""
  for k in S[:j-i]:
    if k == "?":
      op += "a"
    else:
      op += k
  op += T
  if j-i+len(T) < len(S):
    for k in S[j-i+len(T):]:
      if k == "?":
        op += "a"
      else:
        op += i
  return op


S = input()
T = input()
SS = len(S)
TT = len(T)
cand = []
if TT > SS:
  print("UNRESTORABLE")
else:
  for i,t in enumerate(T):
    for j,s in enumerate(S):
      c = 0
      if ((t == s) or (s == "?")) and (i <= j) and (TT - i <= SS - j):
        for ss, tt in zip(S[j-i:], T):
          if ss != tt and ss != "?":
            break
          else:
            c += 1
        if c == TT:
          cand.append(output(S,T,i,j))
  cand.sort()
  cand.append("UNRESTORABLE")
  print(cand[0])

Submission status: Runtime Error

Solution code:
def output(S,T,i,j):
  op = ""
  for k in S[:j-i]:
    if k == "?":
      op += "a"
    else:
      op += k
  op += T
  if j-i+len(T) < len(S):
    for k in S[j-i+len(T):]:
      if k == "?":
        op += "a"
      else:
        op += i
  return op


S = input()
T = input()
SS = len(S)
TT = len(T)
cand = []
if TT > SS:
  print("UNRESTORABLE")
else:
  for i,t in enumerate(T):
    for j,s in enumerate(S):
      c = 0
      if ((t == s) or (s == "?")) and (i <= j) and (TT - i <= SS - j):
        for ss, tt in zip(S[j-i:j-i+TT+1], T):
          if ss != tt and ss != "?":
            break
          else:
            c += 1
        if c == TT:
          cand.append(output(S,T,i,j))
  cand.sort()
  cand.append("UNRESTORABLE")
  print(cand[0])

Submission status: Runtime Error

Solution code:
def output(S,T,i,j):
  op = ""
  for k in S[:j-i]:
    if k == "?":
      op += "a"
    else:
      op += k
  op += T
  if j-i+len(T) < len(S):
    for k in S[j-i+len(T):]:
      if k == "?":
        op += "a"
      else:
        op += i
  return op


S = input()
T = input()
SS = len(S)
TT = len(T)
cand = []
for i,t in enumerate(T):
    for j,s in enumerate(S):
      c = 0
      if ((t == s) or (s == "?")) and (i <= j) and (TT - i <= SS - j):
        for ss, tt in zip(S[j-i:j-i+TT+1], T):
          if ss != tt and ss != "?":
            break
          else:
            c += 1
        if c == TT:
          cand.append(output(S,T,i,j))
cand.sort()
cand.append("UNRESTORABLE")
print(cand[0])

Submission status: Runtime Error

Solution code:
S = list(input())
T = list(input())
if len(S)<len(T):
    print("UNRESTORABLE")
    exit()
l = 0
S = S[::-1]
T = T[::-1]
for s in range(len(S)-len(T)+1):
    if S[s]=="?" or S[s] == T[0]:
        k = 0
        for t in range(len(T)):
            if S[s+t]!="?" and S[s+t]!=T[t]:
                break
            else:
                k+=1
    if k==len(T):
        l = s
        break
if k<len(T):
    print("UNRESTORABLE")
else:
    ans = []
    for i in range(len(S)):
        if l <= i and i < k:
            ans.append(T[i-l])
        elif S[i]=="?":
            ans.append("a")
        else:
            ans.append(S[i])
    print("".join(ans[::-1]))

Submission status: Runtime Error

Solution code:
S = list(input())
T = list(input())
if len(S)<len(T):
    print("UNRESTORABLE")
    exit()
l = 0
for s in range(len(S)-len(T)+1):
    if S[s]=="?" or S[s] == T[0]:
        k = 0
        for t in range(len(T)):
            if S[s+t]!="?" and S[s+t]!=T[t]:
                break
            else:
                k+=1
    if k==len(T):
        l = s
        break
if k<len(T):
    print("UNRESTORABLE")
else:
    ans = []
    for i in range(len(S)):
        if l <= i and i < i+k:
            ans.append(T[i-l])
        elif S[i]=="?":
            ans.append("a")
        else:
            ans.append(S[i])
    print("".join(ans))

Submission status: Runtime Error

Solution code:
S = list(input())
T = list(input())
l = 0
for s in range(len(S)-len(T)+1):
    if S[s]=="?" or S[s] == T[0]:
        k = 0
        for t in range(len(T)):
            if S[s+t]!="?" and S[s+t]!=T[t]:
                break
            else:
                k+=1
    if k==len(T):
        l = s
        break
if k<len(T):
    print("UNRESTORABLE")
else:
    ans = []
    for i in range(len(S)):
        if l <= i and i < i+k:
            ans.append(T[i-l])
        elif S[i]=="?":
            ans.append("a")
        else:
            ans.append(S[i])
    print("".join(ans))

Submission status: Runtime Error

Solution code:
import re

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

ls = len(s)
lt = len(t)

if ls < lt:
    print('UNRESTORABLE')
else:
    ans = []
    for i in range(len(s) - len(t) + 1):
        m = re.match(s[i:i + lt], t)
        if m is None:
            continue
        ans.append((s[:i]+t+s[i+lt:]).replace('?', 'a'))
    if not ans:
        print('UNRESTORABLE')
    else:
        print(min(ans))

Submission status: Runtime Error

Solution code:
N=int(input())
F=[]
P=[]
for _ in range(N):
    F.append(list(map(int,input().split())))
for _ in range(N):
    P.append(list(map(int,input().split())))

m=2**10
gain=-10**8
for i in range(1,2**10):
    x=list(map(int,format(i,'b').zfill(10)))
    sumP=0
    for j in range(N):
        total=sum([a*b for a,b in zip(x,F[j])])
        sumP+=P[j][total]
    gain=max(gain,sumP)
print(gain)

Submission status: Runtime Error

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



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    St = list(input())
    T = input()

    # print(len(T))
    f = False
    for i in range(len(St)):
        if(St[i] == T[0]):
            cnt = 0
            for j in range(len(T)):
                if(T[j] == St[i+j] or St[i+j] == '?'):
                    # if(cnt == len(T)-1):
                    #     St[i:i+j] = T[j]
                    cnt += 1
                else:
                    break
            if(cnt == len(T)):
                for j in range(len(T)):
                    St[i+j] = T[j]
                f = True
    # print(St)
    if(f):
        print(''.join(St).replace('?', 'a'))
    else:
        print('UNRESTORABLE')
    
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

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



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    St = list(input())
    T = input()

    # print(len(T))
    f = False
    for i in range(len(St)):
        if(St[i] == T[0]):
            cnt = 0
            for j in range(len(T)):
                if(T[j] == St[i+j] or St[i+j] == '?'):
                    # if(cnt == len(T)-1):
                    #     St[i:i+j] = T[j]
                    continue
                else:
                    break
            if(cnt == len(T[j])-1):
                for j in range(len(T)):
                    St[i+j] = T[j]
                f = True
    # print(St)
    if(f):
        print(''.join(St).replace('?', 'a'))
    else:
        print('UNRESTORABLE')
    
    
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
s=list(input())
t=list(input())
if len(s)<len(t):print('UNRESTORABLE')
else:
	for i in range(len(s)-len(t)+1):
		for j in range(len(t)):
			if s[i+j] not in ['?',t[j]]:break
		else:
			s[i:i+len(t)]=t
			break
	else:
		print('UNRESTORABLE')
        exit()
print(''.join(s).replace('?','a'))

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
hoge=input()
key=input()
ans=[]
for i in range(len(hoge)-len(key)+1):
  flag=0
  for j in range(len(key)):
    if(hoge[i+j]==key[j] or hoge[i+j]=="?"):
      flag+=1
  if(flag==len(key)):
    kari=hoge[:i]+key+hoge[i+len(key):]
    ans.append(kari.replace("?","a"))
    
ans.sort()
print(ans[0])

Submission status: Runtime Error

Solution code:
S = list(input())[::-1]
T = list(input())[::-1]

i, c = 0, False

while True:
	f = False
	for j, t in enumerate(T):
		if t == S[i + j]:
			f = True
			continue
		if "?" == S[i + j]:
			continue
		break
	else:
		if f:
			S[i:i + len(T)] = T
			i += len(T) - 1
			c = True
			#print(S)
	i += 1
	if (len(S) - len(T)) <= i:
		break

if c:
	print("".join(S[::-1]).replace("?", "a"))
else:
	print("UNRESTORABLE")

Submission status: Runtime Error

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

cont = 0
y = s[::-1]
for i,x in enumerate(y):
    print(i,y[i])
    if x == "?":
        cont += 1
        if cont == len(t):
            break
        elif (cont == len(t)-1)&(y[i+1] == t[0]):
            break
    else:
        cont = 0
            
if cont == 0:
    print("UNRESTORABLE")
else:
    print((s[:len(s)-i-1]+t+s[len(s)-i+len(t):]).replace("?","a"))

Submission status: Runtime Error

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

y = s[::-1]
for i,x in enumerate(y):
    print(i,y[i])
    if x == "?":
        cont += 1
        if cont == len(t):
            break
        elif (cont == len(t)-1)&(y[i+1] == t[0]):
            break
    else:
        cont = 0
            
if cont == 0:
    print("UNRESTORABLE")
else:
    print((s[:len(s)-i-1]+t+s[len(s)-i+len(t):]).replace("?","a"))

Submission status: Runtime Error

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

words= list(input())
target = list(input())
for i in reversed(range(len(words)-len(target)+1)):
    # print(words[i],i)
    flag = True
    for j in range(len(target)):
        if not(words[i+j] == target[j] or words[i+j] == '?'):
            flag = False
            break
    if flag is True:
        words[i:i+len(target)] = target
        for k,word in enumerate(words):
            if word == '?':
                words[k]='a'
        break

if flag is True:
    print(''.join(words))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

words= list(input())
target = list(input())
for i in reversed(range(len(words)-len(target)+1)):
    # print(words[i])
    flag = True
    for j in range(len(target)):
        if not(words[i+j] == target[j] or words[i+j] == '?'):
            flag = False
            break
    if flag is True:
        if i==0:
            words[len(words)-len(target)+1:]=target
        else:
            words[i:i+len(target)] = target
        for k,word in enumerate(words):
            if word == '?':
                words[k]='a'
        break

if flag is True:
    print(''.join(words))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

if len(s)<len(t):
    print("UNRESTORABLE")
else:
    sn=len(s)
    tn=len(t)
    for i in range(sn-tn+1):
        flag=True
        for k in range(tn):
            if s[i+k]==t[k] or s[i+k]=="?":
                pass
            else:
                flag=False
                break
        if flag:
            for k in range(tn):
                s[i+k]=t[k]
            break
        else:
            pass
if flag:
    for i in range(sn):
        if s[i]=="?":
            s[i]="a"
    print("".join(s))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

if len(s) < len(t):
  print("UNRESTORABLE")
  exit()

c=len(s)-len(t)

flg=False
while True:
  if c<0:
    break
  
  flg2=True
  for i in range(len(t)):
    if s[c+i]!=t[i] and s[c+i]!="?":
      flg2=False
  if flg2:
    flg=True
    break
 c-=1
#print(c)



if flg:
  print((s[:c]+t+s[c+len(t):]).replace("?","a"))
else:
  print("UNRESTORABLE")

Submission status: Runtime Error

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

# Tが当てはまる？
s = 0 # Tが当てはまる最初のインデックス
for i in range(len(S)-len(T)+1):
    flag = 1
    for j in range(len(T)):
        if S[i+j] != "?" and S[i+j] != T[j]:
            flag = 0
    if flag:
        s = i
        break

if not flag:
    print("UNRESTORABLE")
else: # Tが当てはまった場合
    S = S[:s] + T + S[s+len(T):]
    # "?"を"a"で埋める
    S = S.replace("?", "a")
    print(S)

Submission status: Runtime Error

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

ptr = []

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

print(ans)

Submission status: Runtime Error

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

words= list(input())
target = list(input())
i=len(words)-len(target)
for i in reversed(range(len(words)-len(target)+1)):
    # print(words[i])
    flag = True
    for j in range(len(target)):
        if not(words[i+j] == target[j] or words[i+j] == '?'):
            flag = False
            break
    if flag is True:
        words[i:i+len(target)] = target
        for k,word in enumerate(words):
            if word == '?':
                words[k]='a'
        break

if flag is True:
    print(''.join(words))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

words= list(input())
target = list(input())
i=len(words)-len(target)
while(0<=i):
    flag = True
    for j in range(len(target)):
        if not(words[i+j] == target[j] or words[i+j] == '?'):
            flag = False
            break
    if flag is True:
        words[i:i+len(target)] = target
        for k,word in enumerate(words):
            if word == '?':
                words[k]='a'
        break
    i-=1

if flag is True:
    print(''.join(words))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

words= list(input())
target = list(input())
i=len(words)-len(target)
while(0<=i):
    flag = True
    for j in range(len(target)):
        if not(words[i+j] == target[j] or words[i+j] == '?'):
            flag = False
    if flag is True:
        words[i:i+len(target)] = target
        for i,word in enumerate(words):
            if word == '?':
                words[i]='a'
        break
    i-=1

if flag is True:
    print(''.join(words))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
s=input()
t=input()
ans="z"*len(s)
flag=0
for i in range(2**len(t)):
  K=str(bin(i))[2:].zfill(5)
  T=""
  for j in range(len(t)):
    if K[j]=="0":
      T+="?"
    else:
      T+=t[j]
  for k in range(len(s)-len(t)+1):
    if s[k:k+len(t)]==T:
      Key=s[:k]+t+s[k+len(t):]
      ans=min(ans,Key.replace("?","a"))
      flag=1
print(ans if flag==1 else "UNRESTORABLE")

Submission status: Runtime Error

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

flag = False
pos = 51
ans = ""
for i in range(len(S)-4):
    cnt = 0
    for j in range(N):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break
    if cnt == N:
        pos = i
        flag = True
if flag:
    for i in range(len(S)):
        if pos <= i and i < pos + N:
            ans += T[i-pos]
        elif S[i] == "?":
            ans += "a"
        else:
            ans += S[i]
else:
    ans = "UNRESTORABLE"
print(ans)

Submission status: Runtime Error

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

flag = False
pos = 51
ans = ""
for i in range(len(S)-4):
    cnt = 0
    for j in range(N):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break
    if cnt == N:
        pos = i
        flag = True
        break
if flag:
    for i in range(len(S)):
        if pos <= i and i < pos + N:
            ans += T[i-pos]
        elif S[i] == "?":
            ans += "a"
        else:
            ans += S[i]
else:
    ans = "UNRESTORABLE"
print(ans)

Submission status: Runtime Error

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

for i, ch in enumerate(T):
    if ch in SD:
        n = SD.find(ch)
        flag = True
        c = 0
        for j in range(n-1, n-i, -1):
            if j < 0:
                flag = False
                break
            if SD[j] != '?' and SD[j] != T[i-c]:
                flag = False
                break
            flag = True
            c += 1
        if flag:
            c = 0
            for j in range(n+1, n+len(T)-i):
                if j > len(SD)-1:
                    flag = False
                    break
                if SD[j] != '?' and SD[j] != T[i+c]:
                    flag = False
                    break
                flag = True
                c += 1
        if flag:
            remP = SD[:n-i]
            remA = SD[n+1+len(T)-i:]
            for j, rc in enumerate(remP):
                if rc == '?':
                    remP = remP[:j] + 'a' + remP[j+1:]
            for j, rc in enumerate(remA):
            	if rc == '?:
              		remA = remA[:j] + 'a' + remA[j+1:]
            print(remP+T+remA)
            quit()
print('UNRESTORABLE')

Submission status: Runtime Error

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

for i, ch in enumerate(T):
    if ch in SD:
        n = SD.find(ch)
        flag = True
        c = 0
        for j in range(n-1, n-i, -1):
            if j < 0:
                flag = False
                break
            if SD[j] != '?' and SD[j] != T[i-c]:
                flag = False
                break
            flag = True
            c += 1
        if flag:
            c = 0
            for j in range(n+1, n+len(T)-i):
                if j > len(SD)-1:
                    flag = False
                    break
                if SD[j] != '?' and SD[j] != T[i+c]:
                    flag = False
                    break
                flag = True
                c += 1
        if flag:
            remP = SD[:n-i]
            remA = SD[n+1+len(T)-i:]
            for j, rc in enumerate(remP):
                if rc == '?':
                    remP = remP[:j] + 'a' + remP[j+1:]
            for j, rc in enumerate(remA)
            	if rc == '?:
              		remA = remA[:j] + 'a' + remA[j+1:]
            print(remP+T+remA)
            quit()
print('UNRESTORABLE')

Submission status: Runtime Error

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

s = len(S)
t = len(T)


for i in range(s-t, -1, -1):
    n = 0
    for j in range(t-1, -1, -1):
        if S[j+i] != '?' and S[j+i] != T[j]:
            break
        n += 1

    if n == t:
        for x in range(s):
            if i <= x <= i+t:
                print(T[x-i], end='')
            else:
                if S[x] == '?':
                    print('a', end='')
                else:
                    print(S[x], end='')
        exit()

print('UNRESTORABLE')

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

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