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: Accepted

Solution code:
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(map(int,input().split()))
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
INF = 10**9
mod = 10**9+7

S = list(s())
T = list(s())
l1 = len(S)
l2 = len(T)
Flag =  0
for i in range(l1-l2+2):
    if S[i:i+l2] == T:
        Flag = 1
        break
if Flag == 1:
    for i in range(l1):
        if S[i] == '?':
            S[i] = 'a'
    print(''.join(S))
    exit()
for i in range(l1-l2,-1,-1):
    s = S[i:i+l2]
    Flag = 1
    for j in range(l2):
        if s[j] != T[j] and s[j] != '?':
            Flag = 0
            break
    if Flag:
        for j in range(i,i+l2):
            if S[j] == '?':
                S[j] = T[j-i]
        for i in range(l1):
            if S[i] == '?':
                S[i] = 'a'
        print(''.join(S))
        exit()
print('UNRESTORABLE')

Submission status: Accepted

Solution code:
import copy
S=input()
N=len(S)
SS=[]
for i in range(N):
    SS.append(S[i])

T=input()
M=len(T)
TT=[]

for i in range(M):
    TT.append(T[i])

if N<M:
    print("UNRESTORABLE")
else:
    for i in range(N-M+1):
        flag=True
        tmp=copy.deepcopy(SS)
        for j in range(M):
            #print(SS[N-1-i-j],TT[M-1-j])
            if SS[N-1-i-j]==TT[M-1-j] or SS[N-1-i-j]=="?":
                tmp[N-1-i-j]=TT[M-1-j]
            else:
                flag=False
                break
        
        if flag==True:
            Z=[str(a) for a in tmp]
            Z="".join(Z)
            #print(Z)

            ans=Z.replace("?","a")
            print(ans)
            exit()
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import re
Sp = input().replace('?','.')
T = input()
flag = 0
for i in range(len(Sp)-len(T),-1,-1):
    if re.match(Sp[i:i+len(T)],T):
        Sp = Sp[:i]+T+Sp[i+len(T):]
        flag = 1
        break
if flag == 1:
    print(Sp.replace('.','a'))
else:
    print('UNRESTORABLE')

Submission status: Accepted

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

if len(S_) < len(T):
  print('UNRESTORABLE')
  exit()

i_ = -1

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
    if j == len(T) - 1:
      i_ = i

if i_ == -1:      
  print('UNRESTORABLE')
else: 
  if i_ + len(T) == len(S_):
    print(S_[:i_].replace('?','a')+T)
  else:
    print(S_[:i_].replace('?','a')+T+S_[i_+len(T):].replace('?','a'))

Submission status: Accepted

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

if len(s)<l:
    print('UNRESTORABLE')   
    exit() 
for i in range(len(s),-1+l,-1):
    tmp = s[i-l:i]
    tmp_flag = False
    for j in range(l):
        if tmp[j]=='?':
            tmp_flag = True
        elif tmp[j]!=t[j]:
            tmp_flag = False
            break
        else:
            tmp_flag = True
    if tmp_flag:
        t = list(t)
        s = list(s)
        s[i-l:i] = t
        break

if tmp_flag:
    for i in range(len(s)):
        if s[i]=='?':
            s[i] = 'a'
    print(''.join(s))
else:
    print('UNRESTORABLE')

Submission status: Accepted

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

if len(S_dash) < len(T):
    print("UNRESTORABLE")
    exit()

else:
    res = "UNRESTORABLE"
    rev_S = S_dash[::-1]
    rev_T = T[::-1]
    for i in range(len(rev_S)-len(rev_T)+1):
        check = rev_S[i:i+len(rev_T)]
        t_ok = [False] * len(rev_T)
        for j, (c, t) in enumerate(zip(check, rev_T)):
            if c == t or c == "?":
                t_ok[j] = True
        if sum(t_ok) == len(t_ok):
            res = list(rev_S)
            for j,t in enumerate(rev_T):
                res[i+j] = t
            res = "".join(res[::-1])
            res = res.replace("?", "a")
            print(res)
            exit()

    print(res)

Submission status: Accepted

Solution code:
#n,m = map(int,input().split())
#s,t = map(str,input().split())
#a = list(map(int,input().split()))
#m = list(map(str,input().split()))
#n = int(input())
#s = list(str(input()))
#s = str(input())
#t = str(input())

s_dash = list(str(input()))
t = list(str(input()))

lt = len(t)
ls = len(s_dash)
msg = "UNRESTORABLE"

#Tの方が長ければ不可能
if ls < lt:
    print(msg)
    exit()

#Sの候補を探す
candidate = []
for i in range(ls-lt+1):
    is_matched = True#TとS'の部分文字列が一致する可能性があるか
    tmp = s_dash.copy()

    for j in range(lt):
        if t[j] == s_dash[i+j] or s_dash[i+j] == '?':
            tmp[i+j] = t[j]
        else:
            is_matched = False
            break

    if is_matched == True:#一致する可能性があれば
        for j in range(ls):#残った'?'は'a'に置換
            if tmp[j] == '?':
                tmp[j] = 'a'
        
        cand = str("")
        for c in tmp:
            cand += c
        candidate.append(cand)

if len(candidate) == 0:
    print(msg)
else:
    candidate.sort()
    print(candidate[0])

Submission status: Accepted

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    s = s_input()
    t = s_input()

    len_s = len(s)
    len_t = len(t)

    if len_s < len_t:
        print('UNRESTORABLE')
        exit()

    ans_list = []

    flag = False
    for i in range(len_s-len_t+1):
        tmp_s = s[i:i+len_t]
        for j in range(len_t):
            if tmp_s[j] != t[j] and tmp_s[j] != '?':
                break
        else:
            flag = True
            ans_s = s[0:i] + t + s[i+len_t:len_s]
            ans_list.append(ans_s.replace('?', 'a'))

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

    ans_list.sort()

    print(ans_list[0])
 
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
S = input().strip()
N=len(S)
T = input().strip()
M=len(T)
A = []
for i in range(N-M+1):
    flag = 0
    for j in range(i,i+M):
        if S[j]=="?" or S[j]==T[j-i]:continue
        else:
            flag=1
            break
    if flag==0:
        X = list(S)
        for j in range(i,i+M):
            X[j] = T[j-i]
        for i in range(N):
            if X[i]=="?":
                X[i]="a"
        A.append(X)
if len(A)==0:
    print("UNRESTORABLE")
else:
    A = sorted(A)
    print("".join(A[0]))

Submission status: Accepted

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

n = len(s_)
m = len(t)

if m > n:
    print('UNRESTORABLE')
    exit()

import copy
ans = []
for i in range(n-m+1):
    if s_[i] == t[0] or s_[i] == '?':
        temp = copy.copy(s_)
        for j in range(i, i+m):
            #print(i, temp)
            if s_[j] == '?':
                temp[j] = t[j-i]
            elif s_[j] == t[j-i]:
                continue
            else:
                break
        else:
            for k in range(n):
                if temp[k] == '?':
                    temp[k] = 'a'
            ans.append(''.join(temp))
if ans:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
S = input().replace('?','.')
T = input()
for i in range(len(S)-len(T),-1,-1):
    if re.match(S[i:i+len(T)],T):
        S = S.replace('.','a')
        print(S[:i] + T + S[i+len(T):])
        exit()
print('UNRESTORABLE')

Submission status: Accepted

Solution code:
s_prime = input()
t = input()
s_length = len(s_prime)
t_length = len(t)
t_start = -1 # tが入る最初のindex
for i in range(s_length-t_length+1):
    for j in range(t_length):
        flag = True
        # print(i, j, s_prime[i+j], t[j])
        if s_prime[i+j] == '?' or s_prime[i+j] == t[j]:
            pass
        else:
            flag = False
            break
    if flag:
        t_start = i

if t_start == -1:
    print('UNRESTORABLE')
    exit()
s = []
i = 0
while i < s_length:
    if i == t_start:
        s.append(t)
        i += t_length
    elif s_prime[i] == '?':
        s.append('a')
        i += 1
    else:
        s.append(s_prime[i])
        i += 1
for i in range(len(s)):
    print(s[i], end='')
print()

Submission status: Accepted

Solution code:
import sys
MOD = 10**9 + 7
# import io, os
# input = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
def input():
    return sys.stdin.readline()[:-1]

def main():
    s = input()
    t = input()
    for k in range(len(s)-len(t),-1,-1):
        f = 1
        for i in range(len(t)):
            if s[k+i] != "?":
                if s[k+i] != t[i]:
                    f = 0
                    break
        if f == 1:
            print(s[:k].replace("?","a") + t + s[k+len(t):].replace("?","a"))
            exit()
    print("UNRESTORABLE")
if __name__ == '__main__':
    main()

Submission status: Accepted

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

if len(S) < len(T):
    print("UNRESTORABLE")
    exit()

##一つ一つパターンマッチさせる

ls = len(S)
lt = len(T)
index = -1
for i in range(ls-lt+1):
    cnd = S[i:i+lt]
    flag = True
    for s,t in zip(cnd,T):
        if s != "?":
            if s != t:
                flag = False
                break

    if flag:
        index = i


if index == -1:
    print("UNRESTORABLE") 
else:
    tmp = S.replace("?","a")
    print(tmp[:index]+T+tmp[index+lt:])

Submission status: Accepted

Solution code:
s=input()
t=input()
ans=[]
for i in range(len(s)-len(t)+1):
  failflag=0
  for j in range(len(t)):
    if s[i+j]!=t[j] and s[i+j]!='?':
      failflag=1
      break
  if failflag==0:
    k=[]
    for j in range(i):
      if s[j]!='?':
        k.append(s[j])
      else:
        k.append('a')
    for j in range(len(t)):
      k.append(t[j])
    for j in range(i+len(t),len(s)):
      if s[j]!='?':
        k.append(s[j])
      else:
        k.append('a')
    ans.append(''.join(k))
if len(ans)==0:
  print('UNRESTORABLE')
else:
  ans.sort()
  print(ans[0])

Submission status: Accepted

Solution code:
import re

S = input()
T = input()

flag = False
for i in range(len(S) - len(T), -1, -1):
    pattern = S[i:i+len(T)].replace('?', '.')
    m = re.search(pattern, T)
    if m:
        # result = re.sub(pattern, T, S)
        result = S[:i] + T + S[i+len(T):]
        flag = True
        break

if flag > 0 :
    output = result.replace('?', 'a')
    
else :
    output = 'UNRESTORABLE'
    
print(output)

Submission status: Accepted

Solution code:
s = input()[::-1]
t = input()[::-1]

for i in range(len(s) - len(t) + 1):
    check = True
    for j in range(len(t)):
        if s[i+j] == t[j]:
            pass
        elif s[i+j] == "?":
            pass
        else:
            check = False
            break
        
    if check:
        s = list(s)
        t = list(t)
        s[i:i+len(t)] = t
        s = "".join(s)
        s = s.replace("?","a",50)
        print(s[::-1])
        exit()
            
print("UNRESTORABLE")

Submission status: Accepted

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

if len(S) < len(T):
    print("UNRESTORABLE")
else:
    for i in reversed(range(len(S)-len(T)+1)):
        flg = True
        for j in range(len(T)):
            if S[i+j] != "?":
                if S[i+j] != T[j]:
                    flg = False
        if flg:
            list_s = list(S)
            for j in range(len(T)):
                list_s[i+j] = T[j]

            for j in range(len(list_s)):
                if list_s[j] == "?":
                    list_s[j] = "a"
            print(*list_s, sep="")
            exit()

    print("UNRESTORABLE")

Submission status: Accepted

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

n = len(sd)
m = len(t)
s = []

for i in range(n-m, -1, -1):
    t_p = sd[i:i+m]
    for j in range(m+1):
        if j == m:
            print((sd[:i] + t + sd[i + len(t):]).replace("?", "a"))
            exit()
        else:
            if t_p[j] == "?":
                continue
            elif t_p[j] != t[j]:
                break

print("UNRESTORABLE")

Submission status: Accepted

Solution code:
sd = input()
t = input()
sn = len(sd)
tn = len(t)
s = []
for i in range(sn-tn, -1, -1):
    t_kamo = sd[i: i+tn]
    for j in range(tn+ 1):
        if j == tn:
            print((sd[:i] + t + sd[i+tn:]).replace("?", "a"))
            exit()
        elif t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s = str(input())
t = str(input())
ans = []
for i in range(len(s) - len(t) + 1):
    if s[i] == t[0] or s[i] == '?':
        for j in range(len(t)):
            if not(s[i+j] == t[j] or s[i+j] == '?'):
                break
        else:
            news = s[:i] + t + s[i+len(t):]
            news = news.replace('?', 'a')
            ans.append(news)
ans.sort()
if ans:
    print(ans[0])
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
from sys import stdin
input = stdin.readline


def main():
  S = input()[:-1]
  T = input()[:-1]

  t_start_idx = []
  for si, s in enumerate(S):
    # print(f's:{s}')
    if not(s == T[0]) and not(s == '?'):
      continue
    cur_si = si
    for t in T:
      # print(f't:{t}')
      if cur_si >= len(S): break
      if not(t == S[cur_si]) and not(S[cur_si] == '?'):
        break
      cur_si += 1
    else:
      t_start_idx.append(si)
      continue

  if not len(t_start_idx):
    print('UNRESTORABLE')
    return

  new_S = S[:t_start_idx[-1]] + T + S[t_start_idx[-1]+len(T):]
  # print(new_S)

  ret_s = ''
  for s in new_S:
    if s == '?':
      ret_s += 'a'
    else:
      ret_s += s

  print(ret_s)


if(__name__ == '__main__'):
  main()

Submission status: Accepted

Solution code:
s = input()
t = input()
result = []
st = len(s) - len(t)
for i in range(st+1):
    _ = s[:i]
    flg = False
    for j in range(i, i+len(t)):
        if s[j] == t[j-i]:
            _ += t[j-i]
        elif s[j] == '?':
            _ += t[j-i]
        else:
            flg = True
    
    if flg == False:
        _ += s[i+len(t):]
        _ = _.replace('?', 'a')
        result.append(_)

if len(result) != 0:
    result.sort()
    print(result[0])
else:
    print('UNRESTORABLE')

Submission status: Accepted

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


kouho=[]
for i in range(len(s)-len(t)+1):
    ans=s[:i]
    tmp=s[i:(i+len(t))]

    for j in range(len(t)):
        if tmp[j]==t[j]:
            ans+=t[j]
        elif tmp[j]=='?': 
            ans+=t[j]
        elif tmp[j]!='?' and tmp[j]!=t[j]:
            break
    ans=ans+s[(i+len(t)):]

    if len(ans)==len(s):
        kouho.append(ans)

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

answers=[]
for j in kouho:

    tmp_ans=''
    for k in range(len(j)):
        if j[k]=='?':
            tmp_ans+='a'
        else:
            tmp_ans+=j[k]

    answers.append(tmp_ans)

answers=sorted(answers)
print(answers[0])

Submission status: Accepted

Solution code:
s = input()
t = input()
import sys
revs = list(reversed(s))
revt = list(reversed(t))
if len(s) < len(t):
    print("UNRESTORABLE")
else:
    cur = 0
    for _ in range(len(s)-len(t)+1):
        char = revs[cur:cur+len(t)]
        charcopy = char.copy()
        for i,c in enumerate(char):
            if (i == len(char)-1) & ((c == "?") | (c == revt[i])):
                revs[cur:cur+len(t)] = revt
                for j in range(len(revs)):
                    if revs[j] == "?":
                        revs[j] = "a"
                print("".join(list(reversed(revs))))
                sys.exit()
            elif (c == "?") | (c == revt[i]):
                char[i] == revt[i]
            else:
                cur += 1
                break
        else:
            char = charcopy      
    else:
        print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import numpy as np

S = input()
T = input()

m = len(S)
n = len(T)
for i in range(m-n, -1, -1):
  if np.prod([s in [t, '?'] for s, t in zip(S[i:i+m], T)]):
    ans = S[:i] + T + S[i+n:]
    ans = ans.replace('?', 'a')
    break
else:
  ans = 'UNRESTORABLE'
print(ans)

Submission status: Accepted

Solution code:
def solve():
    if len(S) < len(T):
        print('UNRESTORABLE')
        return

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

if __name__ == "__main__":
    S = input()
    T = input()
    solve()

Submission status: Accepted

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

flag = 0

if(len(t)> len(s)):
    print("UNRESTORABLE")
else:
    for i in reversed(range(len(s)-len(t)+1)):
        for j in range(len(t)):
            if(s[i+j] == t[j] or s[i+j] == "?"):
                if(j == len(t) -1):
                    flag = 1
                    break
            else:
                break

        if(flag == 1):
            break

    if(flag == 0):
        print("UNRESTORABLE")
    else:
        kotae = list(s[0:i] + t + s[i+len(t):])
        for i in range(len(kotae)):
            if(kotae[i] == "?"):
                kotae[i] = "a"
        kotae = "".join(kotae)
        print(kotae)

Submission status: Accepted

Solution code:
S=list(input())
T=input()
start=-1
ans=[]
for i in range(len(S)):
    flag=0
    for j in range(len(T)):
        if i+j>=len(S):
            flag=1
            break
        if S[i+j]==T[j] or S[i+j]=="?":
            continue
        else:
            flag=1
            break
    if flag==0:
        start=max(start,i)
for i in range(start,start+len(T)):
    S[i]=T[i-start]
for i in range(len(S)):
    if S[i]=="?":
        ans.append("a")
    else:
        ans.append(S[i])
if start==-1:
    print("UNRESTORABLE")
else:
    print("".join(ans))

Submission status: Accepted

Solution code:
s,t=input(),input()
start=len(s)-len(t)
flag=1
if start<0: print("UNRESTORABLE")
else:
    while start>=0:
        flag=1
        for i in range(len(t)):
            if s[start+i]!="?" and s[start+i]!=t[i]:
                flag=0
                break
        if flag:
            s=s[0:start]+t[:]+s[start+len(t):len(s)]
            s=s.replace("?","a")
            break
        start-=1
    if flag: print(s)
    else: print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
ns = len(s)
nt = len(t)

flag = False
if ns < nt:
    print('UNRESTORABLE')
    exit()
for i in reversed(range(ns-nt+1)):
    for j in range(nt):
        if s[i:i+nt][j] != '?' and s[i:i+nt][j] != t[j]:
            break
    else:
        s[i:i+nt] = t
        flag = True
        break
if flag:
    ans = ''.join(s).replace('?', 'a')
    print(ans)
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
import re

_S = input().replace('?', '_')[::-1]
T = input()[::-1]

pattern = ''
for c in T:
    pattern += '[_' + c + ']'

match = re.search(pattern, _S)
if not match:
    print('UNRESTORABLE')
else:
    S = _S[:match.start()] + T + _S[match.end():]
    S = S.replace('_', 'a')
    print(S[::-1])

Submission status: Accepted

Solution code:
s=input()
t=input()
n=len(s)
m=len(t)
ans='UNRESTORABLE'
a=[]
for i in range(n-m+1):
  if s[i]==t[0] or s[i]=='?':
    for j in range(m):
      if s[i+j]!=t[j] and s[i+j]!='?':
        break
    else:
      an=list(s[:i]+t+s[i+j+1:])
      for k in range(n):
        if an[k]=='?':
          an[k]='a'
      an=''.join(an)
      a.append(an)
if len(a):
  print(min(a))
else:print(ans)

Submission status: Accepted

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

resolved = False
for i in (range(len(s) - len(t) + 1)):
    sliced = s[len(s)-len(t)-i:len(s)-i]
    matched = True
    for j in range(len(sliced)):
        if sliced[j] != t[j] and sliced[j] != '?':
            matched = False
            break
    if matched:
        resolved = True
        s = s[:len(s)-len(t)-i] + t + s[len(s)-i:]
        break

if resolved:
    print(s.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
import numpy as np
from copy import deepcopy


S = np.array([s for s in input()], str)
T = np.array([t for t in input()], str)
nS, nT = map(len, (S, T))
ans = ''
idx = []

if nS < nT:
    ans = 'UNRESTORABLE'
else:
    for i in range(nS - nT + 1):
        s = S[i:i + nT]
        if np.all((s == T) | (s == '?')):
            idx.append(i)

if not idx:
    ans = 'UNRESTORABLE'
else:
    i = idx[-1]
    S[i:i + nT] = T
    ans = np.where(S == '?', 'a', S)

print(''.join(ans))

Submission status: Accepted

Solution code:
import sys
s = list(input())
t = list(input())
ss = "".join(s)
tt = "".join(t)
ls = []
for i in range(len(ss)-len(tt)+1):
    l = s[i:i+len(tt)]
    for j in range(len(tt)):
        if l[j] != t[j] and l[j] != "?":
            break
        else:
            l[j] = t[j]
    else:
        l = "".join(l)
        l = "".join(s[:i]) + l + "".join(s[i+len(tt):])
        l = l.replace("?","a")
        ls.append(l)
if ls == []:
    print("UNRESTORABLE")
else:
    ls.sort()
    print(ls[0])

Submission status: Accepted

Solution code:
import sys
a=input()
b=input()
for i in reversed(range(len(a)-len(b)+1)):
  t=True
  for j in range(len(b)):
    if not(a[i+j]=="?") and not(a[i+j]==b[j]):
      t=False
      break
  if t:
    for p in range(i):
      if a[p]=="?":
        print("a",end="")
      else:
        print(a[p],end="")
    print(b,end="")
    for w in range(i+len(b),len(a)):
      if a[w]=="?":
        print("a",end="")
      else:
        print(a[w],end="")
    sys.exit()
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
def restore():
    for i in range(N - M, -1, -1):
        if all(s == '?' or s == t for s, t in zip(S[i:i + M], T)):
            ans = S[:i] + T + S[i + M:]
            return ''.join('a' if c == '?' else c for c in ans)
    return 'UNRESTORABLE'


S = input()
T = input()
N = len(S)
M = len(T)
print(restore())

Submission status: Accepted

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

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

ans = []
for i in range(s - t + 1):
    flg = 0
    for j in range(t):
        if S[i+j] == T[j]:
            pass
        elif S[i+j] == '?':
            pass
        else:
            flg = 1
            break
    if flg == 0:
        ans.append(S[0:i].replace('?', 'a') + T + S[i+t:].replace('?', 'a'))
if len(ans) == 0:
    print('UNRESTORABLE')
else:
    print(sorted(ans)[0])

Submission status: Accepted

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

found = []

#区間大事。 len(T)がの仕切りを何箇所入れれるか
for i in range(len(S) - len(T) + 1):
  for cs, ct in zip(S[i:], T):
    if cs != '?' and cs != ct:
      break
  else:
    found.append(i)

if not found:
  print("UNRESTORABLE")
  exit()

ans = 'z'  * 51

for i in found:
  tmp = S[:i] + T + S[i+len(T):]
  ans = min(ans, tmp.replace("?", "a"))
print(ans)

Submission status: Accepted

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

found = []
for i in range(len(S) - len(T) + 1):
  for cs, ct in zip(S[i:], T):
    if cs != '?' and cs != ct:
      break
  else:
    found.append(i)

if not found:
  print("UNRESTORABLE")
  exit()

ans = 'z'  * 51

for i in found:
  tmp = S[:i] + T + S[i+len(T):]
  ans = min(ans, tmp.replace("?", "a"))
print(ans)

Submission status: Accepted

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

ans = "z" * 100
for i in range(len(S) - len(T) +1)[::-1]:
  ok = True

  for j in range(len(T)):
    if S[i+j] != "?" and S[i+j] != T[j]:
      ok = False
  if ok:
    s = S[:i] + T + S[i+len(T):]
    s = "".join(s)
    ans = min(ans, s.replace("?", "a"))
    break
if ans == "z" * 100:
  print("UNRESTORABLE")
else:
  print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
c = -1
for i in range(len(s)-len(t)+1):
    sw = 1
    for j in range(len(t)):
        if s[i+j] == "?":
            pass
        elif s[i+j] == t[j]:
            pass
        else:
            sw = 0
            break
    if sw == 1:
        c = i
if c == -1:
    ans = "UNRESTORABLE"
else:
    a = []
    i = 0
    j = 0
    while i < len(s):
        if c <= i < c+len(t):
            a.append(t[j])
            j += 1
        elif s[i] != "?":
            a.append(s[i])
        else:
            a.append("a")
        i += 1
    ans = "".join(a)
print(ans)

Submission status: Accepted

Solution code:
s=input()
t=input()
ans=[]
for i in range(len(s)-len(t)+1):
  start=i
  end=i+len(t)
  ok=True
  for j in range(len(t)):
    if s[start+j]!='?' and s[start+j]!=t[j]:
      ok=False
      break
  if ok:
    a=s[:start]+t+s[end:]
    ans.append(a.replace('?','a'))
if ans:
  ans=sorted(ans)
  print(ans[0])
else:
  print('UNRESTORABLE')

Submission status: Accepted

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

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

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

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

Submission status: Accepted

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

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

    def chk(a, b):
        res = ''
        for j in range(len(b)):
            if a[j] == '?' or a[j] == b[j]:
                res += b[j]
            else:
                return False
        else:
            return res 

    if len(Sd) >= len(T):
        for i in range(len(Sd)- len(T)+1):
            temp_words = r_Sd[i:i+len(T)]
            res = r_Sd[:i]
            
            temp = chk(temp_words, r_T)
            if temp:
                res = res + temp + r_Sd[i+len(T):]                
                print(res.replace('?', 'a')[::-1])
                break
        else:
            print('UNRESTORABLE')
    else:
        print('UNRESTORABLE')

if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

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

    def chk(a, b):
        res = ''
        for j in range(len(b)):
            if a[j] == '?' or a[j] == b[j]:
                res += b[j]
            else:
                return False
        else:
            return res 

    if len(Sd) >= len(T):
        for i in range(len(Sd)- len(T)+1):
            temp_words = r_Sd[i:i+len(T)+1]
            res = r_Sd[:i]
            
            temp = chk(temp_words, r_T)
            if temp:
                res = res + temp + r_Sd[i+len(T):]                
                print(res.replace('?', 'a')[::-1])
                break
        else:
            print('UNRESTORABLE')
    else:
        print('UNRESTORABLE')

if __name__ == "__main__":
    resolve()

Submission status: Accepted

Solution code:
S = str(input())
T = str(input())
index = []

for i in range(len(S) - len(T) + 1):
  if (S[i] != T[0]) and (S[i] != "?"):
    continue
  else:
    p = 0
    now = i
    j = 0
    index_i = -1
    while p == 0:
      if (S[now] != T[j]) and (S[now] != "?"):
        p = 1
      else:
        now += 1
        j += 1
      #print(now, j, len(T), index)
      if j == len(T):
        index_i = i
        p = 1
    if index_i != -1:
      index.append(index_i)
      
#print(index)
if (len(index) == 0):
  print("UNRESTORABLE")
else:
  ans_index = index[-1]
  ans = [0] * len(S)
  q = 0
  for i in range(len(S)):
    if i == ans_index:
      ans[i] = T[0]
      q = 1
    elif (q != 0):  
      ans[i] = T[q]
      q += 1
      if q == len(T):
        q = 0
    else:
      if S[i] != "?":
        ans[i] = S[i]
      else:
        ans[i] = "a"
    #print(ans, S)
  
  #print(ans) 
  #print(ans_index)
  for i in range(len(ans)):
    print(ans[i], end = "")
  print("")

Submission status: Accepted

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

def compare(s, t):
    if len(s) != len(t): return False
    res = True
    for i in range(len(s)):
        res &= (s[i] == t[i] or s[i] == '?')
    return res

n = len(S)
m = len(T)
pos = -1
for i in range(n):
    if compare(S[i:i+m], T):
        pos = i

if pos == -1:
    print('UNRESTORABLE')
else:
    S[pos:pos+m] = T
    S = ''.join(S)
    S = S.replace('?', 'a')
    print(S)