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()
flag=1
buf=""
ans=""
sus=[]
piv=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]!="?")and(T[j]!=S[i+j]):
                flag=0
                break
            
        if flag==1:
            sus.append(i)
        flag=1
    if len(sus)<1:
        print("UNRESTORABLE")
    else:
        piv=max(sus)
        for i in range(len(S)):
            if piv<=i<=piv+len(T)-1:
                buf="".join((buf,T[i-piv]))
            else:
                buf = "".join((buf, S[i]))
        
        for i in range(len(S)):
            if buf[i]=="?":
                ans="".join((ans,"a"))
            else:
                ans = "".join((ans, buf[i]))
        print(ans)

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


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


ans = "UNRESTORABLE"
for i in range(len(S)-len(T), -1, -1):
    s = S[i:i+len(T)]
    if comp(s, T):
        S = S[:i] + T + S[i+len(T):]
        for i in range(len(S)):
            if S[i] == "?":
                S = S[:i] + "a" + S[i+1:]
        print(S)
        sys.exit(0)

print(ans)

Solution (Python):

import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect
import re
import queue
from decimal import *


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [input() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    S = Scanner.string()
    T = Scanner.string()
    N = len(S)
    M = set()
    for i in range(N - len(T) + 1):
        flag = True
        for j in range(len(T)):
            if not(S[i + j] == T[j] or S[i + j] == '?'):
                flag = False
        if flag:
            A = S[:i] + T + S[i + len(T):]
            A = ['a' if s == '?' else s for s in A]
            M.add(''.join(A))
    if len(M) > 0:
        print(sorted(list(M))[0])
    else:
        print('UNRESTORABLE')


def main():
    
    solve()


if __name__ == "__main__":
    main()

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

res = 'UNRESTORABLE'

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

flg = False

for i in range(len(s)-len(t), -1, -1):
	L = len(t)
	sub = s[i:L+i]
	if check(sub,t):
		new = s[:i] + t + s[L+i:]
		flg = True
		break


if flg:
	print(new.replace('?', 'a'))
else:
	print(res)

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

ans = ""
if len(T) > len(S):
    print("UNRESTORABLE")
else:
    ls = len(S)
    lt = len(T)
    for i in reversed(range(ls-lt+1)):
        tmp = S[i:i+lt]
        flag = True
        for j in range(lt):
            if tmp[j] != "?":
                if tmp[j] != T[j]:
                    flag = False
                    break
        if flag:
            ans = ""
            for h in range(i):
                if S[h] == "?":
                    ans += "a"
                else:
                    ans += S[h]
            ans += T
            for h in range(i+lt,ls):
                if S[h] == "?":
                    ans += "a"
                else:
                    ans += S[h]
            print(ans)
            exit()
    print("UNRESTORABLE")

Solution (Python):










_S = list(input())
T = list(input())

def calculate(_S,T):
    _sl = len(_S)
    tl = len(T)

    result = []
    for startIndex in range(0,_sl - tl + 1):

        isOk = True
        for j in range(tl):
            _SValue = _S[startIndex+j]
            if (_SValue != "?") and (_SValue != T[j]):
                isOk = False
                break


        if isOk:
            copyS = _S.copy()
            copyS[startIndex:startIndex + tl] = T
            res = "".join(copyS).replace("?","a")
            result.append(res)


    if len(result) == 0:
        print("UNRESTORABLE")
    else:
        result = sorted(result)
        print(result[0])

calculate(_S,T)

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

offset = len(S) - len(T)

ans = []
for d in range(offset + 1):
    A = ''
    Td = '?' * d + T
    for i in range(len(S)):
        if i < len(Td) and S[i] != Td[i] and '?' not in [S[i], Td[i]]:
            break
        else:
            c = Td[i] if i < len(Td) and Td[i] != '?' else S[i]
            A += c
    else:
        ans.append(A.replace('?', 'a'))

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

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

offset = len(Sx) - len(T)

ans = 'UNRESTORABLE'
if len(Sx) >= len(T):
    for d in range(offset, -1, -1):
        for j in range(len(T)):
            if Sx[d + j] not in ['?', T[j]]:
                break
        else:
            break
    else:
        print('UNRESTORABLE')
        exit()

    ans = ''
    for i in range(len(Sx)):
        if i < d or d + (len(T) - 1) < i:
            c = Sx[i]
        else:
            c = T[i - d]
        c = 'a' if c == '?' else c

        ans += c

print(ans)

Solution (Python):
S = input()
T = input()
X = sorted((S[:i] + T + S[i + len(T):]).replace('?', 'a')
           for i in range(len(S) - len(T) + 1)
           if all(s == '?' or s == t for s, t in zip(S[i:i + len(T)], T)))
print(X[0] if len(X) > 0 else 'UNRESTORABLE')

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

if len(s) < len(t):
    print('UNRESTORABLE')
    exit()
ansl = []


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

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

Solution (Python):
s=input()
t=input()
n=len(s)
m=len(t)
ind=-1
for i in range(n-m+1):
  f=0
  for j in range(m):
    c=s[n-i-1-j]
    if t[m-1-j]!=c and c!='?':
      break
    else:
      f+=1
  if f==m:
    ind=i
    break

if ind==-1:
  print("UNRESTORABLE")
else:
  s=s[:n-ind-m]+t+s[n-ind:]
  s=s.replace('?','a')
  print(s)

Solution (Python):






def main():
    S = input()
    T = input()

    len_S = len(S)
    len_T = len(T)

    if len_T > len_S:
        return "UNRESTORABLE"
    
    condicates = []
    
    for i in range(len_S - len_T + 1):
        next_i = False
        part = S[i:i+len_T]
        
        for t, p in zip(T, part):
            if p != "?" and t != p:
                next_i = True
                break
        
        if next_i:
            continue
        
        
        condicates.append((S[:i] + T + S[i+len_T:]).replace("?", "a"))
    
    return sorted(condicates)[0] if len(condicates) > 0 else "UNRESTORABLE"


print(main())

Solution (Python):

s = list(input())
t = list(input())
sn = len(s)
tn = len(t)
bag = []

for i in range(sn-tn+1):
  flag = True
  for j in range(tn):
    if s[i+j] == '?' or s[i+j] == t[j]:
      pass 
    else:
      flag = False 

  if flag:
    bag += [i]


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


def fill(ss, idx):
  for i in range(tn):
    ss[idx+i] = t[i]
  for i in range(sn):
    if ss[i] == '?':
      ss[i] = 'a'

  return ''.join(ss)

s_list = []
for idx in bag:
  ss = s[:]
  s_list += [str(fill(ss, idx))]

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

Solution (Python):
Sp = input()
T = input()
len_Sp = len(Sp)
len_T = len(T)
ans = 'UNRESTORABLE'

i = len_Sp - len_T
while(i >= 0):
    isAns = True
    for j in range(len_T):
        if Sp[i + j] != T[j] and Sp[i + j] != '?':
            isAns = False
            break
    if isAns:
        ans = Sp[:i] + T + Sp[i + len_T:]
        ans = ans.replace('?', 'a')
        break
    i -= 1
print(ans)

Solution (Python):
Sp = input()
T = input()
len_Sp = len(Sp)
len_T = len(T)
ans = ''
cnt = 0

i = len_Sp-len_T
while(i >= 0):
    j = len_T-1
    while(j >= 0):
        if Sp[i + j] == T[j] or Sp[i + j] == '?':
            cnt += 1
        else:
            cnt = 0
            break
        j -= 1
    if cnt == len_T:
        Sp_list = list(Sp)
        for k in range(len_T):
            Sp_list[i + k] = T[k]
        ans = ''.join(Sp_list)
        ans = ans.replace('?', 'a')
        print(ans)
        break
    i -= 1
if cnt != len_T:
    print('UNRESTORABLE')

Solution (Python):
Sp = input()
T = input()
len_Sp = len(Sp)
len_T = len(T)
ans = ''
cnt = 0

i = len_Sp-len_T
while(i >= 0):
    j = len_T-1
    while(j >= 0):
        if Sp[i + j] == T[j] or Sp[i + j] == '?':
            cnt += 1
        else:
            cnt = 0
            break;
        j -= 1
    if cnt == len_T:
        Sp_list = list(Sp)
        for k in range(len_T):
            Sp_list[i + k] = T[k]
        ans = ''.join(Sp_list)
        ans = ans.replace('?', 'a')
        print(ans)
        break;
    i -= 1
if cnt != len_T:
    print('UNRESTORABLE')

Solution (Python):
S_ = input()
T = input()
len_s, len_t = len(S_), len(T)
i = len_s - len_t
ans = "UNRESTORABLE"
while i != -1:
    isAns = True
    for j in range(len_t):
        if S_[i + j] != '?' and S_[i + j] != T[j]:
            isAns = False
            break
    if isAns:
        ans = S_[:i] + T + S_[i + len_t:]
        ans = ''.join([c if c != '?' else 'a' for c in ans])
        break
    i -= 1
print(ans)

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

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


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

print("UNRESTORABLE")

Solution (Python):
s=input()
t=input()
n=len(s)
m=len(t)
for i in range(n-1,-1,-1):
    if i+m-1>=n:
        continue
    j=0
    flag=True
    
    while j<m:
        if s[j+i]=='?':
            j+=1
        elif s[j+i]==t[j]:
            j+=1
        else:
            flag=False
            break
    if flag:
     
        for k in range(i):
            if s[k]=='?':
                print('a',end='')
            else:
                print(s[k],end='')
        print(t,end='')
        for k in range(i+m,n):
            if s[k]=='?':
                print('a',end='')
            else:
                print(s[k],end='')
        print()
        import sys
        sys.exit()
print('UNRESTORABLE')

Solution (Python):
s=input()
t=input()
strs=[]
S=len(s)
T=len(t)
for i in range(S-T+1):
  flag=0
  for j in range(T):
    if s[i+j]=="?":
      continue
    if s[i+j]!=t[j]:
      flag=1;break
  if flag==0:
    posstr=s[:i]+t+s[i+T:]
    strs.append(posstr.replace("?","a",50))
strs.sort()
if strs==[]:print("UNRESTORABLE")
else:print(strs[0])

Solution (Python):
import sys

def main():
  S = input()
  T = input()
  lenS = len(S)
  lenT = len(T)
  for i in range(lenS-lenT,-1,-1):
    sub = S[i:i+lenT]
    for j in range(lenT):
      if sub[j]!=T[j] and sub[j]!="?":
        break
    else:
      S = S[:i]+T+S[i+lenT:]
      S=S.replace("?","a")
      print(S)
      sys.exit()
      break
    continue
  print("UNRESTORABLE")

main()

Solution (Python):
import numpy as np
import sys

def main():
  S = input()
  T = input()
  lenS = len(S)
  lenT = len(T)
  for i in range(lenS-lenT,-1,-1):
    sub = S[i:i+lenT]
    for j in range(lenT):
      if sub[j]!=T[j] and sub[j]!="?":
        break
    else:
      S = S[:i]+T+S[i+lenT:]
      S=S.replace("?","a")
      print(S)
      sys.exit()
      break
    continue
  print("UNRESTORABLE")

main()

Solution (Python):
S=list(input())
s=len(S)
T=list(input())
t=len(T)
for i in range(s-t+1):
  a=0
  for j in range(t):
    if S[-1-i-j]=="?":
      continue
    if S[-1-i-j]!=T[-1-j]:
      a=1
  if a==0:
    for j in range(s):
      if S[j]=="?":
        S[j]="a"
    S[s-t-i:s-i]=T
    for j in range(s):
      print(S[j],end="")
    print()
    exit()
print("UNRESTORABLE")

Solution (Python):

s = input()
t = input()
sl = len(s)
tl = len(t)
res = list(s)

def check(s1, s2):
    for i in range(len(s1)):
        if s1[i] == '?':
            continue
        if s1[i] != s2[i]:
            return False
    return True

for i in range(sl-tl, -1, -1):
    if check(s[i: i+tl], t):
        res[i: i+tl] = t
        res = ['a' if s == '?' else s for s in res]
        break
else:
    res = list('UNRESTORABLE')

print(''.join(res))

Solution (Python):


import re


def main():
    S = input()
    T = input()

    S = S.replace("?", ".")[::-1]
    T = T[::-1]

    for i in range(len(S) - len(T) + 1):
        if re.match(S[i:i + len(T)], T):
            s = S[:i].replace(".", "a") + T + S[i + len(T):].replace(".", "a")
            print(s[::-1])
            break
    else:
        print("UNRESTORABLE")


if __name__ == "__main__":
    main()

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

yn=""
for i in range(len(sd)-len(t)+1):
    ii=len(sd)-len(t)-i
    yn=""
    for j in range(len(t)):
        if sd[ii+j]!=t[j] and sd[ii+j]!="?":
            yn="NG"
            break
    if yn=="NG":
        continue
    else:
        yn="yes"
        break
    
if yn=="NG" or yn=="": 
    print("UNRESTORABLE")
else:
    for j in range(len(t)):
        sd[ii+j]=t[j]
    for j in range(len(sd)):
        if sd[j]=="?":
           sd[j]="a"
    strt="".join(sd)
    print(strt)

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

ls, lt = len(s), len(t)
ans_i, ans_j = -1, -1
for i in range(ls-lt+1):
    for j in range(lt):
        if s[i+j] == '?' or s[i+j] == t[j]:
            pass
        else:
            break
        if j == lt-1:
            ans_i = i
            ans_j = j

if ans_i > -1 and ans_j > -1:
    idx = 0
    for i in range(ans_i, ans_i+lt):
        if s[i] == '?':
            s[i] = t[idx]
        idx += 1
    for i in enumerate(s):
        if i[1] == '?':
            s[i[0]] = 'a'
    for i in s:
        print(i, end='')
    print()
else:
    print('UNRESTORABLE')

Solution (Python):
S = input()
T = input()
sl = len(S)
tl = len(T)
res = list(S)

def check(s1, s2):
    for i in range(len(s1)):
        if s1[i] == '?':
            continue
        if s1[i] != s2[i]:
            return False
    return True

for i in range(sl-tl, -1, -1):
    if check(S[i: i+tl], T):
        res[i: i+tl] = T
        res = ['a' if s == '?' else s for s in res]
        break
else:
    res = list('UNRESTORABLE')

print(''.join(res))

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):])
        break
else:
    print("UNRESTORABLE")

Solution (Python):
import sys

s = input()
t = input()
lenS = len(s)
lenT = len(t)
for i in range(lenS-lenT,-1,-1):
  sub = s[i:i+lenT]
  for j in range(lenT):
    if sub[j]!="?" and sub[j]!=t[j]:
      break
  else:
    s=s.replace("?","a")
    print(s[:i]+t+s[i+lenT:])
    sys.exit()
  continue
  
print('UNRESTORABLE')

Solution (Python):
def compare(sub, t):
    for i in range(len(t)):
        if sub[i] == t[i] or sub[i] == '?':
            continue
        else:
            return False
    return True

clear = False
s = input()
t = input()
if len(s) == len(t):
    clear = compare(s, t)
    s = t
for i in range(len(s)-len(t), 0, -1):
    if compare(s[i:i+len(t)], t):
        clear = True
        s = s[:i] + t + s[i+len(t):]
        break
if clear:
    print(s.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Solution (Python):
S = input()
T = input()
ls, lt = len(S), len(T)    

ans = 'UNRESTORABLE'
for i in range(ls-lt+1):
    for j in range(lt):
      if S[i+j] not in (T[j], '?'):
        break       
    else:
      ans = (S[:i]+T+S[i+lt:]).replace('?','a')
   
print(ans)

Solution (Python):
s = input()
t = input()
ans = 'UNRESTORABLE'
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
    if ok:
        ans = s[:i]+t+s[i+len(t):]
        ans = ans.replace('?','a')
print(ans)

Solution (Python):
s = input()
t = input()
memo = []
 
for i in range(len(s)-len(t)+1):
    p = s[i:(i+len(t))]
    flag = True
    for j in range(len(t)):
        if p[j] != "?" and p[j] != t[j]:
            flag = False
            break
    if flag:
        memo.append((s[0:i]+t+s[(i+len(t)):len(s)]).replace("?","a"))
 
if len(memo) == 0:
    print("UNRESTORABLE")
else:
    print(min(memo))

Solution (Python):
s = input()
t = input()
memo = []

for i in range(len(s)-len(t)+1):
    p = s[i:(i+len(t))]
    flag = True
    for j in range(len(t)):
        if p[j] != "?" and p[j] != t[j]:
            flag = False
            break
    if flag:
        memo.append((s[0:i]+t+s[(i+len(t)):len(s)]).replace("?","a"))

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

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

ans = []
for i in range(len(s)-(len(t)-1)):
    f = True
    for j in range(len(t)):
        if s[j+i] != t[j] and s[j+i] != '?':
            f = False
    if f == True:
        s2 = s[:i] + t + s[i+len(t):]
        s2 = s2.replace('?','a')
        ans.append(s2)



if len(ans) > 0:
    print(min(ans))
else:
    print('UNRESTORABLE')

Solution (Python):
S=input()
T=input()
for i in range(len(S)-len(T),-1,-1):
  a=0
  for j in range(len(T)):
    if S[i+j]=="?":
      continue
    if S[i+j]!=T[j]:
      a=1
      break
  if a==0:
    for j in range(i):
      if S[j]=="?":
        print("a",end="")
      else:
        print(S[j],end="")
    print(T,end="")
    for j in range(i+len(T),len(S)):
      if S[j]=="?":
        print("a",end="")
      else:
        print(S[j],end="")
    exit()
print("UNRESTORABLE")

Solution (Python):
import sys

s = input()
t = input()

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

Solution (Python):



def main():
    
    sp = input()
    t = input()
    ans = "~" * len(sp)
    for i in range(len(sp) - len(t) + 1):
        is_ok = True
        for k in range(len(t)):
            if sp[i + k] != "?" and t[k] != sp[i + k]:
                is_ok = False
                break
        if not is_ok:
            continue
        s = list(sp)
        s[i:i + len(t)] = list(t)
        ans = min(ans, "".join(sc if sc != "?" else "a" for sc in s))
    if ans[0] == "~":
        print("UNRESTORABLE")
    else:
        print(ans)


if __name__ == '__main__':
    main()

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

def match(s,t):
    flag=True
    for i in range(len(s)):
        if s[i]!=t[i] and s[i]!='?':
            flag=False
            break
    return flag
    
cand = []
for i in range(len(S_)-len(T)+1):
    if match(S_[i:i+len(T)], T):
        s = S_[:i]+T+S_[i+len(T):]
        s = s.replace('?','a')
        cand.append(s)

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

Solution (Python):
S_ = input()
T = input()
S__len = len(S_)
T_len = len(T)

for i in range(S__len - T_len, -1, -1):
    t_kamo = S_[i : i + T_len]
    
    for j in range(T_len + 1):
        if j == T_len:
            print((S_[: i] + T + S_[i + T_len :]).replace('?', 'a'))
            quit()
        if t_kamo[j] == '?':
            continue
        elif t_kamo[j] != T[j]:
            break
print('UNRESTORABLE')

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

n = len(sd)
m = len(t)


for i in range(n - m, -1, -1):
    t_kamo = sd[i : i + m]
    for j in range(m + 1):
        if j == m:
            print((sd[: i] + t + sd[i + len(t):]).replace('?', 'a'))
            quit()
        if t_kamo[j] == '?':
            continue
        elif t_kamo[j] != t[j]:
            break
print('UNRESTORABLE')

Solution (Python):
s=input()
l=len(s)
t=input()
k=len(t)
cand=[]
for i in range(l-k+1):
    new=""
    for j in range(l):
        if i<=j<i+k:
            if s[j]=="?":
                new+=t[j-i]
            else:
                if s[j]==t[j-i]:
                    new+=t[j-i]
                else:
                    break
        else:
            if s[j]=="?":
                new+="a"
            else:
                new+=s[j]
    if len(new)==l:
        cand.append(new)
cand.sort()
if len(cand)==0:
    print("UNRESTORABLE")
else:
    print(cand[0])

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

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

Solution (Python):
import re
s = input()
s = s.replace("?", ".")
t = input()
if len(t) > len(s):
  print("UNRESTORABLE")
else:
  r = []
  for i in range(len(s)-len(t)+1):
    m = re.match(s[i:i+len(t)], t)
    if m is None:
      continue
    r.append((s[:i]+t+s[i+len(t):]).replace(".","a"))
  if not r:
    print('UNRESTORABLE')
    quit()
      
  print(min(r))

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

Solution (Python):
s,y=(input() for i in range(2))
ans="{"*len(s);pa=ans
for i in range(len(s)-len(y)+1):
  for j in range(len(y)):
    if s[i+j]!='?' and s[i+j]!=y[j]:break
  else:ans=min(ans,s[:i].replace("?","a")+y+s[i+len(y):].replace("?","a"))
if pa==ans:print("UNRESTORABLE")
  
else:print(ans)

Solution (Python):
s = input()
t = input()
s2 = s.replace('?', 'a')

ans = 'z' * 99
for i in range(len(s) - len(t)+1):
    u = s2[0:i] + t + s2[i + len(t):]

    ok = True
    for x, y in zip(s, u):
        if x != '?' and x != y:
            ok = False
            break
    if ok:
        ans = min(ans, u)

if ans == 'z' * 99:
    ans = 'UNRESTORABLE'

print(ans)

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

n_s = len(s)
n_t = len(t)
last_num = -1

base = [i for i,x in enumerate(s) if x == str(t[0]) or "?"]

if n_s >= n_t:
  for i in base:
    if n_s - i >= n_t:
      sign = 0
      for j in range(i,i+n_t):
        if not ((s[j] == t[j-i]) or (s[j] == "?")):
          sign = 1
        
      if sign == 0:
        last_num = i

  if last_num != -1:
    for i in range(last_num,last_num + n_t):
      if s[i] == "?":
        s[i] = t[i-last_num]
    
    if s[0] == "?":
      ans = "a"
    else:
      ans = str(s[0])
                  
    for j in range(1,n_s):
      if s[j] == "?":
        s[j] = "a"
      ans = ans + s[j]
    
  elif last_num == -1:
    ans = "UNRESTORABLE"

else:
  ans = "UNRESTORABLE"

print(ans)

Solution (Python):
S = list(input())
T = input()
ls = []
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:
        ls.append(i)

if ls:
    for j in range(len(T)):
        S[ls[-1]+j] = T[j]
    print("".join(S).replace("?", "a"))
else:
    print("UNRESTORABLE")

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

res = 'UNRESTORABLE'
for i in range(len(s)-len(t)+1):
    for ss, tt in zip(s[i:i+len(t)], t):
        if ss == '?' or ss == tt:
            continue
        break
    else:
        res = ((s[:i] + t + s[i+len(t):])[::-1]).replace('?', 'a')
        break

print(res)

Solution (Python):
s=input()
t=input()
u=[]
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:
    u.append(s[:i].replace('?','a')+t+s[i+len(t):].replace('?','a'))
if len(u)==0:
  print('UNRESTORABLE')
  exit()
u.sort()
print(u[0])

Solution (Python):


S = input().strip()
T = input().strip()

S=S[::-1]
T=T[::-1]

i=0
ans=""
flag = False
while i < len(S):

    if ( S[i] == T[0] or S[i] == "?" )  and  (len(S) - i) >= len(T):
        for j,word_t in enumerate(T):
            if word_t == S[i+j] or S[i+j] == "?":
                continue
            else:
                ans += S[i]
                i += 1 
                break
        
        else:
            ans += T + S[i+j+1:]
            flag = True
            break
            
            i = len(S)
    
    else:
        ans += S[i]
        i += 1
    
ans=ans[::-1]

if flag:
    ans = ans.replace('?','a')
    print(ans)

else:
    print("UNRESTORABLE")

Solution (Python):
s = list(input())
t = list(input())
ans = [-1, -1]
if len(t) <= len(s):
    for i in range(len(s) - len(t) + 1):
        c = 1
        for j in range(len(t)):
            if s[i + j] != "?" and t[j] != s[i + j]:
                c = 0
                break
        if c == 1:
            ans = [i, i + len(t)]

if ans != [-1, -1]:
    k = []
    for i in range(len(s)):
        if ans[0] <= i < ans[1]:
            k.append(t[i - ans[0]])
        else:
            if s[i] == "?":
                k.append("a")
            else:
                k.append(s[i])
    print("".join(k))
else:
    print("UNRESTORABLE")

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

n=len(s)
k=len(t)
if k>n:
    print('UNRESTORABLE')
    exit()
mozi=[]
for i in range(n-k+1):
    ok=True
    for j in range(k):
        if s[i+j]==t[j] or s[i+j]=='?':
            pass
        else:
            ok=False
    if ok:
        
        
        
        
        
        
        mozi.append(s[:i]+t+s[i+k:])

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

for i in range(len(mozi)):
    mozi[i]=mozi[i].replace('?','a')
mozi.sort()
print(mozi[0])

Solution (Python):
S = input()
T = input()
ans = ""
for i in range(len(S)-len(T)+1):
  u = S[i:i+len(T)]
  flag = True
  for j in range(len(T)):
    if u[j] == T[j] or u[j] == "?":
      continue
    else:
      flag = False
      break
  if flag:
    ans = S[0:i] + T + S[i+len(T):]
if ans != "":
  print(ans.replace("?","a"))
else:
  print("UNRESTORABLE")

Solution (Python):
s = input()
t = input()
flag1 = 0
tmp = ""
for i in range(len(s) - len(t) + 1):
    u = s[i:i + len(t)]
    flag2 = 1
    for j in range(len(t)):
        if u[j] != t[j] and u[j] != "?":
            flag2 = 0
            break
    if flag2 == 1:
        flag1 = 1
        tmp = s[:i] + t + s[i + len(t):]

print(tmp.replace("?", "a")) if flag1 else print("UNRESTORABLE")

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

import fnmatch

if len(s) < len(t):
    print('UNRESTORABLE')
else:
    l = []
    for  i in range(len(s) - len(t)+1):
        if fnmatch.fnmatch(t, s[i:i+len(t)]):
            x = s[0:i] + t + s[i+len(t):]
            l += [x.replace('?', 'a')]

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

Solution (Python):
def main():
    S = input()
    T = input()
    N = len(S)
    M = len(T)
    for i in range(N-M+1)[::-1]:
        if all(s == t or s == "?" for s, t in zip(S[i:i+M], T)):
            return print(S[:i].replace("?", "a") + T + S[i+M:].replace("?", "a"))
    print("UNRESTORABLE")


if __name__ == '__main__':
    main()

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

flag = False
def dfs(x, y):
    if y >= len(T):
        global flag
        flag = True
        return
    elif not S[x] in (T[y], '?'):
        return
    
    dfs(x+1, y+1)


ans = "UNRESTORABLE"
for i in range(len(S) - len(T) + 1)[::-1]:
    if S[i] in (T[0], '?'):
        dfs(i, 0)
        if flag:
            ans = S[:i] + T + S[i+len(T):]
            ans = ans.replace('?', 'a')
            break

print(ans)