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.

Solution (Python):
S = input()
T = input()
S_LEN = len(S)
T_LEN = len(T)
ans_li = []
if S_LEN - T_LEN < 0:
    print("UNRESTORABLE")
else:
    for i in range(S_LEN - T_LEN + 1):
        is_ok = True
        for j in range(T_LEN):
            if S[i + j] != "?" and S[i + j] != T[j]:
                is_ok = False
                break
        if is_ok:
            tmp = S[:i] + T + S[i + T_LEN:]
            ans_li.append(tmp.replace("?", "a"))
    print(sorted(ans_li)[0]) if ans_li != [] else print("UNRESTORABLE")

Solution (Python):
S=input()
T=input()
l_s=len(S)
l_t=len(T)
ans=[]
i=0
while i+l_t<=l_s:
  j=0
  while j<l_t:
    if S[i+j]=="?" or S[i+j]==T[j]:
      j+=1
    else:
      break
  if j==l_t:
    A=S[:i]+T+S[i+l_t:]
    A=A.replace("?","a")
    ans.append(A)
  i+=1
print(sorted(ans)[0] if ans else "UNRESTORABLE")

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

ins = -1
for i in range(0,len(S)-len(T)+1,1):
    
    isOk = True
    for j in range(i,i+len(T),1):
        if not(T[j-i]==S[j] or S[j]=="?"):
            isOk = False
            break
        
    if isOk:
        ins = i

if ins == -1:
    print("UNRESTORABLE")
    exit()

ans = list(S)
for i in range(len(T)):
    ans[ins+i]=T[i]

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

print("".join(ans))

Solution (Python):
S = input()
N = len(S)
T = input()
M = len(T)

st = -1

for i in range(N-M, -1, -1):
  if all(S[i+j] in (T[j], "?") for j in range(M)):
    st = i
    break

newS = S.replace("?", "a")

if st == -1:
  print("UNRESTORABLE")
else:
  ans = ""
  for i in range(N):
    if st <= i <= st+M-1:
      ans += T[i-st]
    else:
      ans += newS[i]
  print(ans)

Solution (Python):
sd = input()
t = input()
ls = len(sd)
lt = len(t)
ans=[]
for i in range(ls-lt,-1,-1):
  for j, k in zip(sd[i:i+lt], t):
    if j != "?" and j != k:
      break
  else:
    temp = sd[:i] + t + sd[i+lt:]
    ans.append(temp.replace("?","a"))

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

Solution (Python):
import sys
S = list(input())
T = list(input())

def Ispossible(a,b):
  
  if len(a) != len(b):
    return False
  flag = True
  for i in range(len(a)):
    if not(a[i]==b[i] or a[i]=="?"):
      flag = False
      break
  return flag

for i in range(1,len(S)-len(T)+2):
  q = S[-i:-i-len(T):-1].copy()
  r = T[-1:-len(T)-1:-1].copy()
  if Ispossible(q, r):
    for j in range(len(T)):
      S[-i-j] = T[-1-j]
      
      
    for j in range(len(S)):
      if S[j] == "?":
        S[j] = "a"
    print("".join(S))
    sys.exit()
print("UNRESTORABLE")

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

pos = False
rep = list(range(len(s)-len(t)+1))
rep.reverse()
for i in rep:
    flag = True
    for j in range(len(t)):
        if s[i+j] == '?':
            pass
        elif s[i+j] == t[j]:
            pass
        else:
            flag = False

    if flag == False:
        continue
    for j in range(len(t)):
        s[i+j] = t[j]
    pos = True
    break

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

Solution (Python):
S=input()
T=input()
ns=len(S)
nt=len(T)
ans=[]
i=0
while i+nt<=ns:
    j=0
    while j<nt:
        if S[i+j]=='?' or S[i+j]==T[j]:
            j+=1
        else:
            break
    if j==nt:
        A=S[:i]+T+S[i+nt:]
        A=A.replace('?','a')
        ans.append(A)
    i+=1
    
if ans:
    print(sorted(ans)[0])
else:
    print('UNRESTORABLE')

Solution (Python):
s=list(input())
t=list(input())
ans='U'
for i in range(len(s)-len(t),-1,-1):
  if s[i]==t[0] or s[i]=='?':
    cnt=1
    for j in range(1,len(t)):
      if s[i+j]==t[j] or s[i+j]=='?':
        cnt+=1
    if cnt==len(t):
      s[i:i+len(t)]=t
      u=''
      for k in s:
        u+=k
      u=u.replace('?','a')
      print(u)
      exit()
      
print('UNRESTORABLE')

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

anss = []
for tpos in range(len(sd) - len(t) + 1):
    check = True
    for i in range(len(t)):
        if t[i] != sd[(i + tpos)] and sd[(i + tpos)] != '?':
            check = False
            break
    if check == True:
        cand = sd[:tpos] + t + sd[(tpos + len(t)):]
        anss.append(cand.replace('?', 'a'))

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

Solution (Python):
import sys
sp=input()
t=input()

m=len(sp)
n=len(t)
for i in range(m-n,-1,-1):
  cand=sp[:i].replace('?','a')+t+sp[i+n:].replace('?','a')
  for j,w in enumerate(t):
    if sp[j+i]!=w and sp[j+i]!='?':
      break
  else:
    print(cand)
    sys.exit()
print('UNRESTORABLE')

Solution (Python):
import sys
S = input()
T = input()

S_len = len(S)
T_len = len(T)

if T_len > S_len:
    print("UNRESTORABLE")
    sys.exit()


candidate = []
for i in range(0, S_len-T_len+1):

    isOkay = True
    for j in range(T_len):
        if S[i+j] == "?":
            continue

        if S[i+j] == T[j]:
            continue
        else:
            isOkay = False

    if isOkay:
        candidate.append((S[0:i] + T + S[i+T_len:]).replace("?", "a"))

if len(candidate):
    candidate.sort()
    print(candidate[0])
else:
    print("UNRESTORABLE")

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    T = readline().strip()

    N, M = len(S), len(T)
    ans = []

    for i in range(N - M + 1):
        ok = True
        s = list(S)
        for j in range(M):
            if S[i + j] == '?':
                s[i + j] = T[j]
            elif S[i + j] != T[j]:
                ok = False
                break
        if ok:
            ans.append(''.join(s).replace('?', 'a'))

    if ans:
        print(min(ans))
    else:
        print('UNRESTORABLE')

    return


if __name__ == '__main__':
    main()

Solution (Python):
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    S = readline().strip()
    T = readline().strip()

    N, M = len(S), len(T)
    ans = []

    for i in range(N - M + 1):
        ok = True
        s = list(S)
        for j in range(M):
            if S[i + j] == '?':
                s[i + j] = T[j]
            elif S[i + j] != T[j]:
                ok = False
                break
        if ok:
            ans.append(''.join(s).replace('?', 'a'))

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

    return


if __name__ == '__main__':
    main()

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

lst=[]
for i in range(len(s)-len(t)+1):
  ss=s[i:i+len(t)]
  f=True
  for a,b in zip(ss,t):
    if a!=b and a!="?":
      f=False
      break
  if f:
    st=s[:i]+t+s[i+len(t):]
    lst.append(st.replace("?","a"))
if lst==[]:
  print("UNRESTORABLE")
else:
  lst.sort()
  print(lst[0])

Solution (Python):
s = list(input())
t = list(input())
n = len(s)
m = len(t)

ans = []
for i in range(n - m + 1):
    flag = True
    for j in range(m):
        if s[i+j] == t[j] or s[i+j] == '?':
            continue
        flag = False
    if flag:
        ans.append("".join(s[:i] + t + s[i+m:]).replace('?', 'a'))

if ans:
    print(min(ans))
else:
    print("UNRESTORABLE")

Solution (Python):
S = input()[::-1]
T = input()[::-1]
ns, nt = len(S), len(T)
ans = None
for i in range(ns-nt+1):
    _S = S[i:i+nt]
    f = True
    for s,t in zip(_S,T):
        if not (s=='?' or s==t):
            f = False
            break
    if f:
        ans = S[:i].replace('?', 'a')+T+S[i+nt:].replace('?', 'a')
        break
print("UNRESTORABLE" if not ans else ans[::-1])

Solution (Python):
s,t=open(0)
m=len(t:=t[:-1])
for i in range(51):
 if all(c in'?'+d for c,d in zip(s[-i-m:],t)):s=s.replace(*'?a');exit(print(s[:-i-m]+t+s[-i:]))
print('UNRESTORABLE')

Solution (Python):
s,t=open(0)
m=len(t:=t[:-1])
for i in range(len(s)):
 if all(c in'?'+d for c,d in zip(s[-i-m:],t)):s=s.replace(*'?a');exit(print(s[:-i-m]+t+s[-i:]))
print('UNRESTORABLE')

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

Solution (Python):
import re
s,t=input().replace(*"?."),input()
l,m,*c=len(s),len(t)
for i in range(l-m+1):
 if re.match(s[i:i+m],t):c+=(s[:i]+t+s[i+m:]).replace(*".a"),
print(c and min(c)or"UNRESTORABLE")

Solution (Python):
import re
s, t = input().replace(*"?."), input()
l, m = len(s), len(t)

can = []
for i in range(l - m + 1):
    if re.match(s[i:i+m], t):
        can += (s[:i] + t + s[i+m:]).replace(*".a"),
print(min(can) if can else "UNRESTORABLE")

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

found = False
res = ""
len_S = len(S)
len_T = len(T)
found = False

for i in range(len_S):
    cnt = 0
    if i == len_S - len_T + 1: break
    for j in range(len_T):
        if T[j] == S[i+j] or S[i+j] == "?":
            cnt+=1
        if cnt == len_T:
            tmps = S[:i]
            tmpt = S[i+len_T:]
            res = S[:i] + T + S[i+len_T:]
            found = True
            break

if found: print(res.replace("?", "a"))
else: print("UNRESTORABLE")

Solution (Python):
s=list(list(input())[::-1])
t=list(list(input())[::-1])
s_len=len(s)
t_len=len(t)
for i in range(s_len-t_len+1):
    for j in range(t_len):
        if s[i+j]!="?" and t[j]!=s[i+j]:
            break
    else:
        s[i:i+t_len]=t 
        for k in range(s_len):
            if s[k]=="?":
                s[k]="a"
        print("".join(s[::-1]))
        exit()
print("UNRESTORABLE")

Solution (Python):
S = input()
T = input()
f = "UNRESTORABLE"


S_r = S[::-1]
T_r = T[::-1]
for i in range(len(T),len(S)+1):
    S_ = S_r[i-len(T):i]
    flg = True
    for t,s in zip(T_r, S_):
        if s != "?" and s != t:
            flg = False
    if flg:
        ans = S_r[:i-len(T)] + T_r + S_r[i:]
        print(ans[::-1].replace("?","a"))
        exit()
print(f)

Solution (Python):
def resolve():
    Sd = list(input())
    T = input()
    res = ""
    for i in range(len(Sd)):
        for j in range(len(T)):
            if i + j >= len(Sd):
                break
            if Sd[i + j] != "?" and Sd[i + j] != T[j]:
                break
        else:
            tmp = "".join(Sd[:i]) + T + "".join(Sd[i + len(T):])
            if res == "":
                res = tmp
            else:
                if res > tmp:
                    res = tmp
    if res == "":
        print("UNRESTORABLE")
        return
    for s in res:
        if s == "?":
            s = "a"
        print(s, end="")
    print()

resolve()

Solution (Python):
import sys
import itertools

import time
import math
import heapq
from collections import defaultdict
sys.setrecursionlimit(10 ** 7)
 
INF = 10 ** 18
MOD = 10 ** 9 + 7
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines


S = input()
T = input()

ls = len(S)
lt = len(T)
ans = []
for i in range(ls -lt, -1, -1):
    ss = list(S)
    ok = True
    for j in range(lt):
        if S[i + j] != '?' and S[i + j] != T[j]:
            ok = False
            break
        if S[i + j] == '?':
            ss[i + j] = T[j]
    if not ok:
        continue

    for j in range(ls):
        if ss[j] == '?':
            ss[j] = 'a'
    print("".join(ss))
    break
else:
    print("UNRESTORABLE")

Solution (Python):
S=input()
T=input()
n=len(S)
m=len(T)

for i in range(n-m,-1,-1) :
    x=S[i:i+m]
    for j in range(m+1):
        if j==m :
            print((S[:i]+T+S[i+m:]).replace("?","a"))
            exit()
        if x[j]=="?" :
            continue
        elif x[j]!=T[j] :
            break
 
print("UNRESTORABLE")

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

def main():
    S = input()
    T = input()
    s = len(S)
    t = len(T)
    if s < t:
        print("UNRESTORABLE")
        return
    for i in range(s - t, -1, -1):
        correspond = True
        for j in range(t):
            if S[i + j] != '?' and S[i + j] != T[j]:
                correspond = False
                break
        if correspond:
            ans = [S[k] for k in range(s)]
            for j in range(t): ans[i + j] = T[j]
            for k in range(s):
                if ans[k] == '?': ans[k] = 'a'
            print("".join(ans))
            return
    print("UNRESTORABLE")

if __name__ == "__main__":
    main()

Solution (Python):
sd=[c for c in input()]
t=[c for c in input()]
tl=len(t)
for i in range(len(sd)-tl,-1,-1):
    s=sd.copy()
    m=sd[i:i+tl]
    for j in range(tl):
        if m[j]=='?':
            s[i+j]=t[j]
        elif m[j]==t[j]:
            pass
        else:
            break
    if s[i:i+tl]==t:
        print(''.join(['a' if c=='?' else c for c in s]))
        exit()
print('UNRESTORABLE')

Solution (Python):
import sys


Sp = [c for c in input()]
T = [c for c in input()]

sn = len(Sp)
tn = len(T)

match_i = 51
for i in range(sn - tn + 1):
    partial = Sp[i:i+tn]
    for j in range(len(partial)):
        if partial[j] == '?':
            partial[j] = T[j]
    if partial == T:
        match_i = i

if match_i > 50:
    print('UNRESTORABLE')
    sys.exit()

Sp[match_i:match_i+tn] = T
for i in range(sn):
    if Sp[i] == '?':
        Sp[i] = 'a'
S = ''.join(Sp)

print(S)

Solution (Python):
import re
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")

Solution (Python):
S = input()
s = len(S)
T = input()
t = len(T)

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

Solution (Python):
import re

S = input().replace('?', '.')
T = input()

n = len(S)
m = len(T)
j = -1
for i in range(n-m, -1, -1):
    if re.match(S[i:i+m], T):
        j = i
        break

if j == -1:
    print('UNRESTORABLE')
else:
    ans = ''.join(['a' if t == '.' else t for t in S])
    ans = ans[:j] + T + ans[j+m:]
    print(ans)

Solution (Python):
import sys, math
from itertools import product
sys.setrecursionlimit(500000)
MOD = 10**9+7

def input():
    return sys.stdin.readline()[:-1]

def mi():
    return map(int, input().split())

def ii():
    return int(input())

def i2(n):
    tmp = [list(mi()) for i in range(n)]
    return [list(i) for i in zip(*tmp)]


def main():
    S = input()
    T = input()
    l = []
    N, M = len(S), len(T)
    for i in range(N-M+1):
        if all(T[j] == S[i+j] or S[i+j] == '?' for j in range(M)):
            w = S[:i]+T+S[i+M:]
            w = w.replace('?', 'a')
            l.append(w)
    if l:
        print(sorted(l)[0])
    else:
        print('UNRESTORABLE')


if __name__ == '__main__':
    main()

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



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

head_list = []

for i in range(len(Sd) - len(T) + 1):
    sdd = Sd[i:i + len(T)]
    f = True
    for j, sddj in enumerate(sdd):
        if sddj == "?":
            continue
        elif sddj != T[j]:
            f = False
            break
    if f:
        head_list.append(i)


if not head_list:
    print("UNRESTORABLE")
    exit()
else:
    ans_list = []
    for head in head_list:
        ans_list.append((Sd[:head] + T + Sd[head + len(T):]).replace("?", "a"))

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

Solution (Python):
sd = input()
t = input()
oks = []
for i in range(len(sd)-len(t)+1):
    sdd = sd[i:i+len(t)]
    f = True
    for j,sddj in enumerate(sdd):
        if sddj == "?":
            continue
        elif sddj != t[j]:
            f = False
            break
    if f:
        oks.append(i)
if oks:
    k = oks[-1]
    print((sd[:k]+t+sd[k+len(t):]).replace("?","a"))
else:
    print("UNRESTORABLE")

Solution (Python):
sd = input()
t = input()
oks = []
if len(sd) < len(t):
    print("UNRESTORABLE")
else:
    for i in range(len(sd)-len(t)+1):
        sdd = sd[i:i+len(t)]
        f = True
        for j,sddj in enumerate(sdd):
            if sddj == "?":
                continue
            elif sddj != t[j]:
                f = False
                break
        if f:
            oks.append(i)
    if oks:
        k = oks[-1]
        print((sd[:k]+t+sd[k+len(t):]).replace("?","a"))
    else:
        print("UNRESTORABLE")

Solution (Python):
S = input()
T = input()
s = len(S)
t = len(T)
A = []

for i in range(s-t+1):
  if all(S[i+j]==T[j] or S[i+j]=="?" for j in range(t)):
    A.append(S[:i]+T+S[i+t:])

A = [a.replace("?","a") for a in A]

if len(A)==0:
  print("UNRESTORABLE")
else:
  print(min(A))

Solution (Python):
S = input()
T = input()
l = len(S)
m = len(T)

for n in range(l-m+1):
  if all(c in "?"+d for c,d in zip(S[-n-m:],T)):
    S = S.replace("?","a")
    print(S[:-n-m]+T+S[l-n:])
    exit()

print("UNRESTORABLE")

Solution (Python):
S=input()
T=input()
s=len(S)
t=len(T)
cand=[[] for _ in range(s-t+1)]

for i in range(s-t+1):
  S_can=[S[k] for k in range(s)]
  for j in range(t):
    if S[i+j]!=T[j] and S[i+j]!='?':
      break
  else:
    for k in range(t):
      S_can[i+k]=T[k]
    for k in range(s):
      if S_can[k]=='?':
        S_can[k]='a'
    cand[i]=S_can
ans=[i for i in cand if i!=[]]
if ans==[]:
  print('UNRESTORABLE')
else:
  ans.sort()
  print(*ans[0],sep='')

Solution (Python):
s2 = input()
t = input()

lst = []
for i in range(len(s2)-len(t)+1):
    moji = ''
    if s2[i] == t[0] or s2[i] == '?':
        moji = s2[:i]+t[0]

        flg = 0
        for j in range(1,len(t)):
            if s2[i+j] == t[j] or s2[i+j] == '?':
                moji += t[j]
            else:
                flg = 1
                break
        if flg == 0:
            lst.append(moji+s2[i+len(t):])

if not lst:
    print('UNRESTORABLE')
else:
    print(min(lst).replace('?','a'))

Solution (Python):
S = input()
T = input()
s, t = len(S), len(T)
c = "z" * s
for i in range(s - t + 1):
    if all(S[i + j] in (T[j], "?") for j in range(t)):
        c = min(c, S[:i] + T + S[i + t:])
print("UNRESTORABLE" if c == "z" * s else c.replace("?", "a"))

Solution (Python):

s = input()
t = input()
n = len(t)
m = len(s)
c = "z" * m
for i in range(m - n + 1):
    if all(j in (t[k], "?") for k, j in enumerate(s[i:n + i])):
        c = min(c, s[:i] + t + s[i + n:])
print("UNRESTORABLE" if c == "z" * m else c.replace("?", "a"))

Solution (Python):

import re
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


def is_match(a, b):
    for _a, _b in zip(a, b):
        if (_a == _b or _a == '?'):
            continue
        else:
            return False
    return True


s = S()
t = S()




if (t in s):
    print(s.replace('?', 'a'))
    exit()
if (len(s) < len(t)):
    print('UNRESTORABLE')
    exit()


if (is_match(s[-len(t):], t)):
    ans = s[:-len(t)] + t
    ans = ans.replace('?', 'a')
    print(ans)
    exit()
i = 0

for _s in reversed(s[len(t)-1:-1]):
    i += 1
    if (_s == t[-1] or _s == '?'):
        if (is_match(s[-i - len(t): - i], t)):
            ans = s[:-i - len(t)] + t + s[-i:]
            ans = ans.replace('?', 'a')
            print(ans)
            exit()


print('UNRESTORABLE')

Solution (Python):
S = input()
T = input()
s, t = len(S), len(T)
L = []
for i in range(s-t+1):
  if all(S[i+j]==T[j] or S[i+j]=="?" for j in range(t)):
    L.append(S[:i]+T+S[i+t:])
L = [l.replace("?", "a") for l in L]
print(min(L) if len(L)>0 else "UNRESTORABLE")

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

for i in range(len(S)-len(T),-1,-1):
    S_ = S[i:i+len(T)]
    frag = 1
    for j in range(len(T)):
        if S_[j] == T[j] or S_[j] == '?' :
            
            if not j == len(T)-1:
                continue
        else:
            break
            frag = 0
        if frag == 1:
            
            
            ans = S[0:i] + T + S[len(T)+i:]
            ans = ans.replace('?','a')
            print(ans)
            exit()
print("UNRESTORABLE")

Solution (Python):
S = input()
T = input()
s = len(S)
t = len(T)
for i in range(s - t, -1, -1):
    SS = S[i : i + t]
    for j in range(t):
        if SS[j] != '?' and SS[j] != T[j]:
            break
    else:   
        ans = S.replace('?', 'a')
        ans = ans[0 : i] + T + ans[i + t :]
        break
else:   
    ans = 'UNRESTORABLE'

print(ans)

Solution (Python):
S = input()
T = input()
sl = len(S)
tl = len(T)
ans = "z" * 100
for i in range(sl-tl+1):
    if S[i] == T[0] or S[i] == '?':
        bf = True
        for j in range(tl):
            if S[i+j] != T[j] and S[i+j] != '?':
                bf = False
                break
        if bf:
            new = S[:i] + T + S[i+tl:]
            new = new.replace("?", "a")
            ans = min(ans, new)
if ans == "z" * 100:
    print("UNRESTORABLE")
else:
    print(ans)

Solution (Python):






Sdash = input()
T = input()





length_S = len(Sdash)
length_T = len(T)
if length_S >= length_T:
    for i in range(length_S-length_T+1):
        for j in range(length_T):
            if Sdash[j+length_S-length_T-i] != T[j] and Sdash[j+length_S-length_T-i] != "?":
                break
        else:
            ans = Sdash[:length_S-length_T-i]+T+Sdash[length_S-i:]
            ans = [x if x != "?" else "a" for x in ans]
            print("".join(ans))
            break
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

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

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

import re

if t > s:
	print("UNRESTORABLE")
	exit()

pos = -1
wani = 0

for i in range (0, s-t+1):
	wani = 0
	for j in range (0,t):
		if	S[i+j] != T[j] and S[i+j] !='?':
			wani = 1
	if wani == 0:
		pos = i        
        
if pos == -1:
	print("UNRESTORABLE")
	exit()

A = []
for i in range (0, s):
	A.append(S[i])

for i in range (0, t):
	A[pos+i] = T[i]

for i in range (0, s):
	if A[i] == '?':
		A[i] = 'a'

print(*A, sep='')

Solution (Python):
def main():
    s = input()
    t = input()
    lis = []
    for i in range(len(s)-len(t)+1):
        f=True
        for j in range(len(t)):
            if(s[i+j]==t[j] or s[i+j]=="?"):
                continue
            else:
                f=False
                break
        if(f):
            tmp = s[0:i]+t+s[i+len(t):]
            res = ""
            for k in range(len(tmp)):
                if(tmp[k]=="?"):
                    res += "a"
                else:
                    res+=tmp[k]
            lis.append(res)
    if(len(lis)==0):
        print("UNRESTORABLE")
    else:
        print(sorted(lis)[0])


if __name__ == '__main__':
    main()

Solution (Python):
s=list(input())
t=list(input())
num=len(s)-len(t)
ans1=-1
for i in range(num+1):
    num1=0
    num2=num-i
    for j in range(len(t)):
        if s[num2+j]!=t[j] and s[num2+j]!="?":
            num1=1
            break
    if num1==0:
        ans1=num2
        break
if ans1==-1:
    print("UNRESTORABLE")
else:
    ans=""
    for i in range(len(t)):
        s[ans1+i]=t[i]
    for i in range(len(s)):
        if s[i]=="?":
            s[i]="a"
        ans+=s[i]
    print(ans)

Solution (Python):
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')

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

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

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

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

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

ans_list = []
ind_list = []

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

print(min(ans_list))

Solution (Python):
s = '.'+input()+'.'
t = input()
def onazi(a):
  for i in range(len(t)):
    if a[i] == '?':
      continue
    if a[i] != t[i]:
      return 0
  return 1
cnt=0
for i in range(len(s)-len(t),0,-1):
  if onazi(s[i:i+len(t)])==1:
    cnt+=1
    s = s[:i]+t+s[i+len(t):]
    break
if cnt==0:
  print('UNRESTORABLE')
  exit(0)
g = ''
for i in s[1:-1]:
  if i == '?':
    g+='a'
  else:
    g+=i
print(g)

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

LS=len(S)
LT=len(T)

ans=[]
for i in range(LS-LT+1):
    F=True
    for t in range(LT):
        if T[t]==S[i+t] or S[i+t]=="?":continue
        else:
            F=False
            break
    if F:
        temp=""
        for j in range(LS):
            if j<i and S[j]=="?":
                temp+="a"
            elif i<=j<i+LT:
                temp+=T[j-i]
            elif j>=i+LT and S[j]=="?":
                temp+="a"
            else:
                temp+=S[j]
        ans.append(temp)

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

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

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

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

Solution (Python):
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())[::-1]
slen = len(S)
T = list(input())[::-1]
tlen = len(T)

for i in range(slen):
    for j in range(tlen):
        if i+j>=slen:
            break
        if not (S[i+j]=='?' or S[i+j]==T[j]):
            break
    else:
        for j in range(tlen):
            S[i+j] = T[j]
        S = [s if not s=='?' else 'a' for s in S[::-1]]
        print(''.join(S))
        break
else:
    print('UNRESTORABLE')

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

l1, l2 = len(s), len(t)

res = ['z'] * l1
flag2 = False
for i in range(l1-l2+1):
    tmp_s = s.copy()
    flag1 = True
    for j in range(l1):
        if j < i or i + l2 <= j:
            if tmp_s[j] == '?':
                tmp_s[j] = 'a'
        else:
            if tmp_s[j] == t[j-i]:
                continue
            elif tmp_s[j] == '?':
                tmp_s[j] = t[j-i]
            else:
                flag1 = False

    if flag1:
        flag2 = True
        res = min(res, tmp_s)

if flag2:
    print(''.join(res))
else:
    print('UNRESTORABLE')

Solution (Python):
S = input()
T = input()
if len(S)<len(T):
    print("UNRESTORABLE")
else:
    lenS =len(S)
    lenT = len(T)
    for i in range(lenS-lenT+1):
        if S[lenS-1-i] == "?" or S[lenS-1-i] == T[lenT-1]:
            for j in range(lenT):
                if S[lenS-1-i-j] != T[lenT-1-j] and S[lenS-1-i-j] != "?":
                    flag = 0
                    break
                flag = 1
            if flag == 1:
                for j in range(lenT):
                    S = S[:(lenS-1-i-j)]+T[lenT-1-j]+S[(lenS-i-j):]
                    
                for k in range(lenS):
                    if S[k] == "?":
                        print("a",end="")
                    else:
                        print(S[k],end="")
                print("")
                break
    else:
        print("UNRESTORABLE")

Solution (Python):

import sys

sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read


sys.setrecursionlimit(10**7)









def run():
    S = input()
    T = input()
    ref = 'abcdefghijklmnopqrstuvwxyz'
    ans =[]
    for i in range(len(S)-len(T)+1):
        checked = True
        for j in range(len(T)):
            if S[i+j] == T[j] or S[i+j]=='?':
                continue
            else:
                checked = False
                break
        if checked:
            ret = S[:i].replace('?', 'a') + T + S[i+len(T):].replace('?', 'a')
            ans.append(ret)
    try:
        print(sorted(ans)[0])
    except:
        print('UNRESTORABLE')



if __name__ == "__main__":
    run()