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 bisect
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = input()
t = input()
ss = []
for i in range(0, len(s) - len(t) + 1):
    for j in range(len(t)):
        if s[i+j] not in ('?', t[j]):
            break
    else:
        c = s[:i] + t + s[i+len(t):]
        ss.append(c.replace('?', 'a'))
if ss:
    print(min(ss))
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
import collections 
import sys,heapq,bisect,math,itertools,string,queue,datetime
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpl_str(): return list(sys.stdin.readline().split())

s = list(input())
t = list(input())
ans = []

for i in range(len(s)-len(t)+1)[::-1]:
    bb = True
    for j in range(len(t)):
        if s[i+j] == '?':
            continue
        else:
            if s[i+j] != t[j]:
                bb = False
    if bb == True:
        ss = s[:]
        for _ in range(len(s)):
            if _ < i:
                if ss[_] == '?':
                    ss[_] = 'a'
            elif _ < i + len(t):
                ss[_] = t[_-i]
            else:
                if ss[_] == '?':
                    ss[_] = 'a'
        ans.append(''.join(ss))

if ans == []:
    print('UNRESTORABLE')
else:
    ans.sort
    print(ans[0])

Submission status: Accepted

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

T_idx = 0
def can_apply(s, t):
    for i in range(len(t)):
        if s[i] == t[i] or s[i] == '?':
            continue
        else:
            return False
    return True

start_idx = -1
for i in range(len(S)-len(T)+1):
    if can_apply(S[i:i + len(T)], T):
        start_idx = i

if start_idx < 0:
    print("UNRESTORABLE")
    os.sys.exit()
ans = [S[i] for i in range(len(S))]
for i in range(len(T)):
    if ans[start_idx + i] == '?':
        ans[start_idx + i] = T[i]

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

ans_str = ""
for _a in ans:
    ans_str += _a
print(ans_str)

Submission status: Accepted

Solution code:
ss = input()
tt = input()
ans = ''
for i in range(len(ss)-len(tt)+1):
    flag = True
    for s,t in zip(ss[i:],tt):
        if s != '?' and s != t:
            flag = False
            break
    if flag:
        ans = ss[:i] + tt + ss[i+len(tt):]

if ans !='':
    print(ans.replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Accepted

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

exit_flag = True
for i in range(len(s_) - len(t) + 1):
    flag = True
    for j in range(len(t)):
        if (s_[i+j] != '?') and (s_[i+j] != t[j]):
            flag = False
    
    if flag:
        h = ''
        for index in range(len(s_)):
            if (i <= index <= i + len(t) -1):
                h += t[index - i]
            else:
                h += s_[index]
        exit_flag = False

if exit_flag:
    print('UNRESTORABLE')
    exit()

h = h.replace('?', 'a')
print(h)

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = [i for i in input()]
T = [i for i in input()]
size_s = len(S)
size_t = len(T)
kouho = []
if size_t > size_s :
    print("UNRESTORABLE")
else :
    for i in range(size_s-size_t+1):
        p = [i for i in S]
        for j in range(size_t):
            if S[i+j] == T[j] or S[i+j] == "?" :
                continue   
            else :
                break 
        else :
            for j in range(size_s):
                if S[j] == "?" :
                    p[j] = "a"
            for j in range(size_t):
                p[i+j] = T[j]
            kouho.append("".join(p))

    if len(kouho) == 0 :
        print("UNRESTORABLE")
    else:
        kouho.sort()
        print(kouho[0],end = " ")

Submission status: Accepted

Solution code:
s = input()
t = input()
lt = len(t)
ls = len(s)
li = []
if ls < lt:
    ans = "UNRESTORABLE"
else:
    for i in range(ls-lt+1):
        subs = s[i:i+lt]
        for c,d in zip(subs,t):
            if c == d or c == "?":
                continue
            else:
                break
        else:
            li.append((s[0:i]+t+s[i+lt:]).replace("?","a"))
    li.sort()
    ans = li[0] if li else "UNRESTORABLE"
print(ans)

Submission status: Accepted

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

ans = ['?' for i in range(len(s))]
start_pos = 0
cond = False
count = 0

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] == t[j] or s[i+j] == "?":
                count += 1
        if count == len(t):
            start_pos = i
            cond = True
        count = 0
    if cond:
        ans = list(s)
        for k in range(len(t)):
            ans[start_pos+k] = t[k]
        ans = "".join(ans)
        ans = ans.replace("?", "a")
        print(ans)
    else:
        print('UNRESTORABLE')

Submission status: Accepted

Solution code:
S2 = input()
T = input()
for i in reversed(range(0, len(S2)-len(T)+1)):
  s = S2[i:i+len(T)]
  #print(s)
  ok = True
  for j in range(len(T)):
    if not(s[j] == "?" or s[j] == T[j]):
      ok = False
  if ok:
    S = S2[:i] + T + S2[i+len(T):]
    S = S.replace("?", "a")
    print(S)
    exit()
print("UNRESTORABLE")

Submission status: Accepted

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

pos=[]
for i in range(len(S)-l+1):
    s_tmp=S[i:i+l]
    for s,t in zip(s_tmp, T):
        if s==t or s=="?":
            continue
        else:
            break
    else:
        pos.append(i)

if pos:
    p=pos[-1]
    S=S[:p]+T+S[p+l:]
    ans=""
    for s in S:
        if s=="?":
            ans+="a"
        else:
            ans+=s
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Accepted

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

flag = False
idx = 0

for i in range(len(s)-len(t)+1):
    if flag == True:
        break
    for j in range(len(t)):
        if s[len(s)-1-i-j] == '?' or s[len(s)-1-i-j] == t[len(t)-1-j] :
            if j == len(t)-1:
                flag = True
                idx = i
                break
        else:
            break
        
if flag == False:
    print('UNRESTORABLE')
    exit()
    
ans = []
num = 0

idx = len(s)-1-idx-len(t)+1
S1 = s[:idx] + t + s[idx+len(t):]
S1 = S1.replace('?', 'a')
print(S1)

Submission status: Accepted

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

flag = False
idx = 0

for i in range(len(s)-len(t)+1):
    if flag == True:
        break
    for j in range(len(t)):
        if s[len(s)-1-i-j] == '?' or s[len(s)-1-i-j] == t[len(t)-1-j] :
            if j == len(t)-1:
                flag = True
                idx = i
                break
        else:
            break
        
if flag == False:
    print('UNRESTORABLE')
    exit()
    
ans = []
num = 0

for i in range(len(s)):
    if len(s)-1-idx >= i and len(s)-1-idx-len(t)+1 <= i:
        ans.append(t[num])
        num += 1
        #print(num,len(s)-1-idx,len(s)-1-idx-len(t)+1,ans)
    elif s[i] == '?':
        ans.append('a')
    else:
        ans.append(s[i])
#s[1] = '1'
print(*ans,sep='')

Submission status: Accepted

Solution code:
S = input()
T = input()
l = []
for i in range(len(S)-len(T)+1):
    flag = 0
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != "?":
            flag = 1
    if flag == 0:
        S1 = S[:i]+T+S[i+len(T):]
        S2 = S1.replace("?","a")
        l.append(S2)
print(sorted(l)[0] if len(l) > 0 else "UNRESTORABLE")

Submission status: Accepted

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

last = -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
    else :
        last = i

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

Submission status: Accepted

Solution code:

import sys
def input():
	return sys.stdin.readline().strip()

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

for i in range(len(S)-len(T), -1 ,-1):
	judge = 1
	for j in range(len(T)):
		if S[i + j] != T[j] and S[i + j] != '?':
			judge = 0
			break
	if judge == 1:
		S[i:i+len(T)] = T[0:len(T)]
		for j in range(len(S)):
			if S[j] == '?':
				S[j] = 'a'
		print("".join(S))
		exit()

print("UNRESTORABLE")

Submission status: Accepted

Solution code:
def main():
    S = input()
    T = input()
    ns, nt = len(S), len(T)
    if nt > ns: return "UNRESTORABLE"
    cand = []
    for i in range(ns-nt+1):
        isFound = True
        for j in range(nt):
            if S[i+j] != "?" and S[i+j] != T[j]:
                isFound = False
                break
        if isFound:
            cand.append(S[:i] + T + S[i+nt:])
    if len(cand) == 0:
        return "UNRESTORABLE"
    else:
        filled = []
        for s in cand:
            t = ""
            for c in s:
                t += "a" if c == "?" else c
            filled.append(t)
        filled = sorted(filled)
        return filled[0]


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

Submission status: Accepted

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

ans = []

for i in range(len(S) + 1 - len(T)):
	if S[i] == T[0] or S[i] == '?':
		s = ''
		flag = True
		
		for j in range(i):
			if S[j] == '?':
				s += 'a'
			else:
				s += S[j]
		
		for j in range(i, i + len(T)):
			if S[j] == T[j - i] or S[j] == '?':
				s += T[j - i]
			else:
				flag = False
				break
		
		if flag:
			for j in range(i + len(T), len(S)):
				if S[j] == '?':
					s += 'a'
				else:
					s += S[j]
			ans.append(s)

if len(ans) > 0:
	ans.sort()
	print(ans[0])
else:
	print('UNRESTORABLE')

Submission status: Accepted

Solution code:
S = input()
T = input()
Sa = S.replace('?', 'a')

def match(N):
  St = S[N:N + len(T)]
  for st, t in zip(St, T):
    if st == '?':
      continue
    elif t != st:
      return False
  return True

point = -1
for i in range(len(S) - len(T) + 1):
  if match(i):
    point = i
    
if point != -1:
  print(Sa[:point] + T + Sa[point + len(T):])

else:
  print('UNRESTORABLE')

Submission status: Accepted

Solution code:
S=input()
T=input()
for i in range(len(S)-len(T),-1,-1):
    for j in range(len(T)):
        if S[i+j]!=T[j] and S[i+j]!="?":
            break
    else:
        s=""
        for j in range(i):
            if S[j]=="?":
                s+="a"
            else:
                s+=S[j]
        for j in range(len(T)):
            s+=T[j]
        for j in range(i+len(T),len(S)):
            if S[j]=="?":
                s+="a"
            else:
                s+=S[j]
        break
else:
    s="UNRESTORABLE"
print(s)

Submission status: Accepted

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

found = False
for i in range(len(s) - len(t) + 1):
    ok = True
    for j in range(len(t)):
        if s[i + j] != "?" and s[i + j] != t[j]:
            ok = False
            break
    if ok:
        found = True
        s = s[:i] + t + s[i + len(t):]
        break

s = s[::-1]
if found:
    print(s.replace("?", "a"))
else:
    print("UNRESTORABLE")

Submission status: Accepted

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

N = len(S)
M = len(T)

i_a = 0
for i in reversed(range(N-M+1)):
    ans = 0
    for j in range(M+1):
        if j == M:
            print((S[:i]+T+S[i+M:]).replace('?','a'))
            exit()
        if T[j] == S[i+j] or S[i+j] == '?':
            continue
        else:
            break

print('UNRESTORABLE')

Submission status: Accepted

Solution code:
import sys, re
INPUT = lambda: sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 9)


def main():
    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")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S=input()
T=input()
S=list(S)
T=list(T)
flag=0
k=0
p=100
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]!='?':
            k=1
    if k==0:
        flag=1
        p=i
    k=0
if flag==0:
    print('UNRESTORABLE')
else:
    for i in range(len(S)):
        if i==p:
            for j in range(len(T)):
                S[i+j]=T[j]
            i+=len(T)
        else:
            if S[i]=='?':
                S[i]='a'
    S="".join(S)
    print(S)

Submission status: Accepted

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

def matchFound(s, t):
    for i in range(len(t)):
        if s[i] != "?" and s[i] != t[i]:
            return False
    return True

res = "UNRESTORABLE"
for i in range(len(Sp)-len(T), -1, -1):
    #print(i)
    if matchFound(Sp[i:], T):
        Sp = Sp[:i] + T + Sp[i+len(T):]
        res = Sp.replace("?", "a")
        break;
        
print(res)

Submission status: Accepted

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

lens = len(s)
lent = len(t)
if lens < lent:
  print("UNRESTORABLE")
else:
  for i in reversed(range(lens - lent + 1)):
    isallmatch = True
    for j in range(lent):
      if not s[i + j] in [t[j], "?"]:
        isallmatch = False
    if isallmatch == True:
      for j in range(lent):
        s[i + j] = t[j]
      ss = "".join(s).replace("?", "a")
      print(ss)
      exit()
  print("UNRESTORABLE")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-

if __name__ == '__main__':
    S_ = input()
    T = input()
    save = []

    for i in range(len(S_)-len(T)+1):
        target = S_[i:i+len(T)]

        flag = True
        for j in range(len(T)):
            if target[j]=='?':
                continue
            elif target[j]==T[j]:
                continue
            else:
                flag = False
                break

        if flag:
            S = S_[:i] + T + S_[i+len(T):]
            S = S.replace('?', 'a')
            save.append(S)

    if len(save)>0:
        save.sort()
        print(save[0])
    else:
        print('UNRESTORABLE')

Submission status: Accepted

Solution code:
S = input()
T = input()
candidates = []
for i in range(0,len(S)-len(T)+1):
    cnt = 0
    for j in range(len(T)):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
    if cnt == len(T):
        candidate = S[:i] + T + S[i+len(T):]
        candidates.append(candidate)
#print(candidates)

if len(candidates) == 0:
    ans = "UNRESTORABLE"
else:
    candidates.sort()
    ans = candidates[0].replace("?","a")
print(ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
if len(S) < len(T):
    print("UNRESTORABLE")
    exit()
for i in range(len(S) - len(T), -1, -1):
    for j in range(len(T)):
        if S[i+j] not in ("?", T[j]):
            break
    else:
        ans = S[:i].replace("?", "a") + T + S[i+len(T):].replace("?", "a")
        print(ans)
        exit()
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import re

_S = input()
T = input()

lenS = len(_S)
lenT = len(T)

if lenT > lenS:
	print("UNRESTORABLE")
else:
	S = re.split("([?" + "][?".join(T[::-1]) + "])", _S[::-1])
	if len(S) == 1:
		print("UNRESTORABLE")
	else:
		S[1] = T[::-1]
		S = "".join(S)
		print(S[::-1].replace("?", "a"))

Submission status: Accepted

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

s = input().strip()
t = input().strip()

for i in range(len(s)-len(t),-1,-1):
    for j in range(len(t)):
        if s[i+j] == "?" or s[i+j] == t[j]:
            if j == len(t)-1:
                s = "" + s[:i] + t + s[i+len(t):]
                print(s.replace("?","a"))
                exit()
        else:
            break
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import sys
s = input()
t = input()
if len(t) > len(s):
    print('UNRESTORABLE')
    sys.exit()
elif len(t) == len(s):
    print(t)
    sys.exit()
diff = len(s)-len(t)
for i in range(diff,-1,-1):
    target = s[i:len(t)+i]
    for ta,te in zip(target,t):
        if ta != '?' and ta != te:
            break
    else:
        tmp = list(s)
        tmp[i:len(t)+i] = t
        print(''.join(tmp).replace('?','a'))
        sys.exit()
print('UNRESTORABLE')

Submission status: Accepted

Solution code:
s = input()
t = input()
if len(s) >= len(t):
  temp = -1
  for i in range(len(s) - len(t) + 1)[: : -1]:
    temp = i
    for j in range(len(t)):
  	  #print(s[i + j], t[j])
  	  if (s[i + j] == "?") or (s[i + j] == t[j]):
  	    continue
  	  else: 
  	  	temp = -1
    if temp != -1:
      #print(temp)
      break
  if temp == -1: print("UNRESTORABLE"); exit(0)
  r = (s[: temp] + t + s[temp + len(t): ]).replace("?", "a")
  print(r)
else: print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s=input()
t=input()
key=t[0]
l=[]
for k,v in enumerate(s):
    f=0
    x=s[k:k+len(t)]
    if len(x)==len(t):
        for ke,j in enumerate(x):
            if j=="?":
                continue
            else:
                if x[ke]!=t[ke]:
                    f=1
                    break
        if not f:
            y=(s[:k]+t+s[k+len(t):]).replace("?","a")
            l.append(y)
    else:
        break
if l:
    print(min(l))
else:
    print("UNRESTORABLE")

Submission status: Accepted

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

match = -1
if len(s) >= len(t):
    for i in range(len(s) - len(t) + 1):
        is_term_match = True
        for j in range(len(t)):
            if s[i + j] != "?" and s[i + j] != t[j]:
                is_term_match = False
                break
        if is_term_match:
            match = i

if match == -1:
    print("UNRESTORABLE")
else:
    s = s[0:match] + t + s[match + len(t):]
    for i in range(len(s)):
        if s[i] == "?":
            s = s[0:i] + "a" + s[i + 1:]
    print(s)

Submission status: Accepted

Solution code:
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

S = sys.stdin.readline().rstrip()
T = sys.stdin.readline().rstrip()


def check(i):
    s = list(S)
    for j in range(len(T)):
        if s[i + j] == '?':
            s[i + j] = T[j]
    return ''.join(s).startswith(T, i)


def restore(i):
    s = list(S)
    for j in range(len(T)):
        s[i + j] = T[j]
    for i in range(len(S)):
        s[i] = 'a' if s[i] == '?' else s[i]
    return ''.join(s)


i = 0
ans = []
while i + len(T) <= len(S):
    if check(i):
        ans.append(restore(i))
    i += 1

if ans:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
s = input()
t = input()
cnt = 0
for i in range(len(s) - len(t), -1, -1):
    cnt = 0
    for j in range(len(t)):
        if s[j + i] == "?" or s[j + i] == t[j]:
            cnt += 1
        else:
            break
    if cnt == len(t):
        for j in range(len(s)):
            if i <= j < i + len(t):
                print(t[j - i], end = "")
            elif s[j] == "?":
                print("a", end = "")
            else:
                print(s[j], end = "")
        print()
        break
if cnt != len(t):
    print("UNRESTORABLE")

Submission status: Accepted

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

i_ = -1
if len(s) < len(t):
    print('UNRESTORABLE')
    exit()
for i in range(len(s)-len(t)+1):
    cnt = 0
    for j in range(len(t)):
        if s[i+j]==t[j] or s[i+j]=='?':
            cnt += 1
    if cnt == len(t):
        i_ = i
if i_ == -1:
    print('UNRESTORABLE')
else:
    s = s[:i_]+t+s[i_+len(t):]
    print(s.replace('?','a'))

Submission status: Accepted

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

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

candidate = []

# まず T と一致させられる位置があるかを調べる
for i in range(len_S - len_T + 1):
  # print(S_dash[i:i+len_T])
  tmp = S_dash[i:i+len_T]
  
  count = 0
  for s, t in zip(tmp, T):
    if s == t or s == '?':
      count += 1
  if count == len_T:
    candidate.append(S_dash[:i] + T + S_dash[i+len_T:])
    
if candidate != []:       
  replaced_candidate = [item.replace("?", "a") for item in candidate]
  replaced_candidate.sort()
  print(replaced_candidate[0])
else:
  print("UNRESTORABLE")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import copy
Sd = list(input())
T = list(input())
S = copy.deepcopy(Sd)
ans = []
for i in range(len(Sd)-len(T)+1):
    for j in range(len(T)):
        if Sd[i+j] != '?' and Sd[i+j] != T[j]:
            Sd = copy.deepcopy(S)
            break
        elif Sd[i+j] == '?':
            Sd[i+j] = T[j]
        if j == len(T)-1:
            l = ['a' if i =='?' else i for i in Sd]
            ans.append(''.join(l))
            Sd = copy.deepcopy(S)
if len(ans) == 0:
    print('UNRESTORABLE')
else:
    print(min(ans))

Submission status: Accepted

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

ret = -1


t_len = len(t)


for i in range(len(s)-t_len+1):
    cut_seq = s[i:i+t_len]
    for j in range(t_len):
        if cut_seq[j] != t[j] and cut_seq[j] != '?':
            break
    else:
        ret = max(ret, i)


if ret == -1:
    print('UNRESTORABLE')
else:
    print((s[:ret] + t + s[ret + t_len:]).replace('?', 'a'))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
s = list(input())
t = list(input())
n = len(s)
m = len(t)
for i in range(n - m + 1)[::-1]:
    for j in range(m):
        if s[i + j] != '?' and s[i + j] != t[j]:
            break
    else:
        s[i:i + m] = t
        for k in range(n):
            if s[k] == '?':
                s[k] = 'a'
        print(''.join(s))
        exit()
print('UNRESTORABLE')

Submission status: Accepted

Solution code:
# Dubious Document 2
s_d = list(str(input()))
t = list(str(input()))

def check(s, t):
    flag = True
    for j in range(len(t)):
        if s[j] == t[j] or s[j] == "?":
            continue
        else:
            flag = False
    return flag

flag = False
for i in range(len(s_d) - len(t)+1):
    flag = check(s_d[len(s_d) - i - len(t):len(s_d) - i], t)
    if flag:
        for idx, j in enumerate(range(len(s_d) - i - len(t), len(s_d)-i)):
            s_d[j] = t[idx]
        break
for i in range(len(s_d)):
    if s_d[i] == "?":
        s_d[i] = "a"
if flag:
    print("".join(s_d))
else:
    print("UNRESTORABLE")

Submission status: Accepted

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

ans = 'UNRESTORABLE'
for i in range(len(S) - len(T) + 1):
    if len(S[i:i + len(T)]) == len(T):
        same = True
        for j, s in enumerate(S[i:i + len(T)]):
            if not (s == T[j] or s == '?'):
                same = False
        if same:
            rep = (S[:i] + T + S[i + len(T):]).replace('?', 'a')
            ans = rep if ans == "UNRESTORABLE" else min(ans, rep)

print(ans)

Submission status: Accepted

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

def no():
    print("UNRESTORABLE")

les = len(s)-len(t)
kouho = []
if les < 0:
    no()
else:
    for i in range(les+1):
        flag =True
        for j in range(len(t)):
            if s[i+j] == "?":
                continue
            elif s[i+j] == t[j]:
                continue
            else:
                flag = False
                break
        if flag:
            kouho.append(i)
    if len(kouho) == 0:
        no()
    else:
        temp = []
        for i in range(len(kouho)):
            txt =""
            for j in range(len(s)):
                if s[j] == "?":
                    if j >= kouho[i] and j <= kouho[i]+len(t)-1:
                        txt+=t[j-kouho[i]]
                    else:
                        txt+="a"
                else:
                    txt += s[j]
            temp.append(txt)
        temp.sort()
        print(temp[0])

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
s = len(S)
t = len(T)

check =1
ans = -1
if t > s:
    check = -1


else:
    for i in range(s-t+1):
        c = 1
        for j in range(t):
            if S[i+j] == '?':
                pass
            elif S[i+j] == T[j]:
                pass
            else:
                c = -1
        if c == 1:
            ans = i

#print(ans)

if check == 1:
    if ans != -1:
        S = S[:ans] + T + S[ans+t:]
        #print(S)
        for i in range(s):
            if S[i] == '?':
                S[i] = 'a'
        print(''.join(S))
    else:
        print('UNRESTORABLE')
else:
    print('UNRESTORABLE')

Submission status: Accepted

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

ans = ["UNRESTORABLE"]
for i in range(len(S)-len(T)+1):
	count = 0
	for j in range(len(T)):
		if (S[i+j] == T[j] or S[i+j] == "?"):
			count += 1
	if count == len(T):
		Sa = S[:i]+T+S[i+len(T):]
		pl = Sa.replace("?","a")
		ans.append(pl)

print(ans[-1])

Submission status: Accepted

Solution code:
s = input()
t = input()
tins = False
for i in range(len(s)-len(t),-1,-1):
    et = True
    for j in range(len(t)):
        if s[i+j] != "?" and s[i+j] != t[j]:
            et = False
    if et:
        s = s[0:i]+t+s[i+len(t):len(s)]
        tins = True
        break
if tins:
    s = s.replace("?","a")
    print(s)
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s = input()
t = input()
lens = len(s)
lent = len(t)

check = 0
ansindex = []
for i in range(lens-lent+1):
  for j in range(lent):
    if not((s[i+j]==t[j]) or (s[i+j]=='?')):
      break
    if j ==lent -1:
      ansindex.append(i)
      check +=1
 
 
if check == 0:
  print('UNRESTORABLE')
  exit()
ans =s.replace('?','a')
ans = ans[:ansindex[-1]]+t+ans[ansindex[-1]+lent:]
print(ans)

Submission status: Accepted

Solution code:
s = input()
ls = len(s)
t = input()
lt = len(t)
for i in range( ls - lt + 1 ):
  start = ls - lt - i
  for j in range(lt):
    if s[start + j] != t[j] and s[start + j] != '?':
      break
  else:
    ss = ''
    for k in range(start):
      if s[k] == '?':
        ss += 'a'
      else:
        ss += s[k]
    #for k in range(start,start+lt)
    ss += t
    for k in range(start+lt,ls):
      if s[k] == '?':
        ss += 'a'
      else:
        ss += s[k]
    print(ss)
    break
else:
  print('UNRESTORABLE')

Submission status: Accepted

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

s = input()
t = input()

lens = len(s)
lent = len(t)
check = 0
ansindex = []
for i in range(lens-lent+1):
    for j in range(lent):
        
        if not((s[i+j]==t[j]) or (s[i+j]=='?')):
            break
        if j ==lent -1:
            ansindex.append(i)
            check +=1


if check == 0:
    print('UNRESTORABLE')
    exit()
ans =s.replace('?','a')
ans = ans[:ansindex[-1]]+t+ans[ansindex[-1]+lent:]
print(ans)

Submission status: Accepted

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


def solve(S, T):
    def appliable_at(pos):
        for i, c in enumerate(S[pos:len(T) + pos]):
            if c != T[i] and c != '?':
                return False
        return True

    for i in range(len(S) - len(T), -1, -1):
        if appliable_at(i):
            ans = S[:i] + T + S[i + len(T):]
            return ans.replace('?', 'a')
    return 'UNRESTORABLE'


def main():
    S = input().strip()
    T = input().strip()
    print(solve(S, T))


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s_dash = input()
t = input()
len_s = len(s_dash)
len_t = len(t)
candidates = set()

for i in range(len_s - len_t + 1):
    part_s = s_dash[i:i+len_t+1]
    flag = True
    for j,k in zip(part_s,t):
        if j=='?' or j==k:
            continue
        else:
            flag = False
            break
    if flag:
        candidates.add(s_dash[0:i].replace("?","a")+t+s_dash[i+len_t::].replace("?","a"))

ret = 'UNRESTORABLE'
if len(candidates)>0:
    ret = min(candidates)
print(ret)

Submission status: Accepted

Solution code:
I=input;s,t=I()[::-1],I()[::-1]
l=len(t)
for i in range(len(s)-l+1):
	f=1;j=-1
	for k in s[i:i+l]:
		j+=1
		if "?"!=k!=t[j]:
			f=0
	if f:
		s=s[:i]+t+s[i+l:]
		print(s.replace("?","a")[::-1])
		exit()
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s=input()[::-1];t=input()[::-1]
l=len(t)
for i in range(len(s)-l+1):
	f=1
	for j,k in enumerate(s[i:i+l]):
		if "?"!=k!=t[j]:
			f=0;break
	if f:
		s=s[:i]+t+s[i+l:]
		print(s.replace("?","a")[::-1])
		exit()
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
s_dash = input()
t = input()
len_s = len(s_dash)
len_t = len(t)

candidates = set()

for i in range(len_s-len_t+1):
    part_s = s_dash[i:i+len_t+1]
    flag = True
    for j,k in zip(part_s,t):
        if j == "?" or j==k:
            continue
        else:
            flag = False
            break
    if flag:
        candidates.add(s_dash[0:i].replace("?","a")+t+s_dash[i+len_t::].replace("?","a"))
ret = "UNRESTORABLE"
if len(candidates)>0:
    ret = min(candidates)
print(ret)