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_prime = input()
t = input()
s_length = len(s_prime)
t_length = len(t)
t_start = -1 
for i in range(s_length-t_length+1):
    for j in range(t_length):
        flag = True
        
        if s_prime[i+j] == '?' or s_prime[i+j] == t[j]:
            pass
        else:
            flag = False
            break
    if flag:
        t_start = i

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

Solution (Python):
import sys
MOD = 10**9 + 7


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

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

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

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



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

    if flag:
        index = i


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

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

Solution (Python):
import re

S = input()
T = input()

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

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

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

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

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

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

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

    print("UNRESTORABLE")

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

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

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

print("UNRESTORABLE")

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

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

Solution (Python):
from sys import stdin
input = stdin.readline


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

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

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

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

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

  print(ret_s)


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

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

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

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


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

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

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

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

answers=[]
for j in kouho:

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

    answers.append(tmp_ans)

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

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

Solution (Python):
import numpy as np

S = input()
T = input()

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

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

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

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

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

flag = 0

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

        if(flag == 1):
            break

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

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

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

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

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

Solution (Python):
import re

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

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

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

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

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

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

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

Solution (Python):
import numpy as np
from copy import deepcopy


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

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

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

print(''.join(ans))

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

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

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


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

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

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

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

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

found = []


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

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

ans = 'z'  * 51

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

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

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

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

ans = 'z'  * 51

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

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

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

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

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

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

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

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

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

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

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

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

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

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

if __name__ == "__main__":
    resolve()

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

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

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

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

if __name__ == "__main__":
    resolve()

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

for i in range(len(S) - len(T) + 1):
  if (S[i] != T[0]) and (S[i] != "?"):
    continue
  else:
    p = 0
    now = i
    j = 0
    index_i = -1
    while p == 0:
      if (S[now] != T[j]) and (S[now] != "?"):
        p = 1
      else:
        now += 1
        j += 1
      
      if j == len(T):
        index_i = i
        p = 1
    if index_i != -1:
      index.append(index_i)
      

if (len(index) == 0):
  print("UNRESTORABLE")
else:
  ans_index = index[-1]
  ans = [0] * len(S)
  q = 0
  for i in range(len(S)):
    if i == ans_index:
      ans[i] = T[0]
      q = 1
    elif (q != 0):  
      ans[i] = T[q]
      q += 1
      if q == len(T):
        q = 0
    else:
      if S[i] != "?":
        ans[i] = S[i]
      else:
        ans[i] = "a"
    
  
  
  
  for i in range(len(ans)):
    print(ans[i], end = "")
  print("")

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

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

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

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

Solution (Python):
def match(s,t):
  for i in range(m):
    if s[i]==t[i] or s[i]=='?':
      continue
    return False
  return True
s = list(input())
t = list(input())
n = len(s)
m = len(t)
i = n-m
found = False
while i >= 0:
  if match(s[i:i+m],t):
    found = True
    for j in range(i,i+m):
      s[j] = t[j-i]
    break
  i-=1
if found:
  for i in s:
    if i=='?':
      print('a',end='')
    else:
      print(i,end='')
  print()
else:
  print("UNRESTORABLE")

Solution (Python):
from copy import deepcopy
def main():
    s = list(input())
    t = list(input())
    tlen = len(t)
    kohos = []
    for i1 in range(len(s) - tlen + 1):
        s_range = s[i1:i1 + tlen]
        flag = 1
        for i2 in range(tlen):
            if s_range[i2] != '?' and s_range[i2] != t[i2]:
                flag = 0
        if flag:
            s_koho = deepcopy(s)
            s_koho[i1:i1 + tlen] = t
            kohos.append(s_koho)
    if kohos:
        kohos.sort()
        koho0 = deepcopy(kohos[0])
        koho0 = ['a' if c == '?' else c for c in koho0]
        r = "".join(koho0)
        print(r)
    else:
        print('UNRESTORABLE')

if __name__ == '__main__':
    main()

Solution (Python):
def main():
    S = input()
    T = input()
    n = len(T)
    ans = list(S)
    for i in range(len(S) - n, -1, -1):
        s = S[i:i + n]
        for j, t in zip(s, T):
            if j != '?' and j != t:
                break
        else:
            ans[i:i + n] = list(T)
            ans = [a if a != '?' else 'a' for a in ans]
            print(''.join(ans))
            exit()
    print('UNRESTORABLE')



if __name__ == '__main__':
    main()

Solution (Python):
import sys
S = list(input())
T = list(input())
s = len(S)
t = len(T)
if s < t:
    print('UNRESTORABLE')
    sys.exit()
OK = False
P = 0
for i in range(s - t + 1):
    if S[i] != T[0] and S[i] != '?':
        continue
    for j in range(1, t + 1):
        if j == t:
            OK = True
            P = i
            break
        if S[i + j] != T[j] and S[i + j] != '?':
            break
for k in range(t):
    S[P + k] = T[k]
for i in range(s):
    if S[i] == '?':
        S[i] = 'a'
if OK:
    [print(S[i], end='') for i in range(s)]
    print('')
else:
    print('UNRESTORABLE')

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

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

Solution (Python):
def solve():
    S = input()
    T = input()
    
    l = []
    flag = False
    for i in range(len(S)-len(T)+1):
        for s, t in zip(S[i:i+len(T)], T):
            if s != '?' and s != t:
                flag = True
                break
        if flag:
            flag = False
            continue
        
        l.append(S[:i].replace('?', 'a')+T+S[i+len(T):].replace('?', 'a'))
    
    if len(l) == 0:
        return 'UNRESTORABLE'
    else:
        l.sort()
        return l[0]

print(solve())

Solution (Python):
s = input()[::-1]
t = input()[::-1]
for i in range(len(s)):
    for j in range(len(t)):
        if i + j >= len(s):
            break
        if s[i+j] != '?' and s[i+j] != t[j]:
            break
    else:
        tmp = list(s)
        for j in range(len(t)):
            tmp[i+j] = t[j]
        ans = str.replace(''.join(tmp), '?', 'a')[::-1]
        print(ans)
        break
else:
    print('UNRESTORABLE')

Solution (Python):
X = open(0).readlines()
S = X[0].strip()
T = X[1].strip()
m, n = len(T), len(S)
if m > n:
    print('UNRESTORABLE')
else:
    for i in range(n-m, -1, -1):
        U = S[i:i+m]
        if all(u == t or u == '?' for u, t in zip(U, T)):
            V = list(S.replace('?', 'a'))
            for j in range(m):
                V[i+j] = T[j]
            print(''.join(V))
            break
    else:
        print('UNRESTORABLE')

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

Solution (Python):
s = input()
t = input()
n_s = len(s)
n_t = len(t)

ans_li = []
for i in range(n_s-n_t+1):
    u = s[i:i+n_t]
    flag = True
    for j in range(len(u)):
        if (u[j]!='?' and u[j]==t[j]) or u[j]=='?':
            continue
        flag = False
    if flag:
        ans_li.append(s[:i].replace('?','a')+t+s[i+n_t:].replace('?','a'))
if ans_li==[]:
    print('UNRESTORABLE');exit()
ans_li.sort()
print(ans_li[0])

Solution (Python):
s = input()
t = input()
les = len(s)
let = len(t)
hoge = 0
if les < let:
  print('UNRESTORABLE')
  exit()
for i in range(les,let-1,-1):
  sa = s[i-let:i]
  for j in range(len(sa)):
    if sa[j] != t[j] and sa[j] != '?':
      break
    if j == len(sa)-1:
      hoge += 1
  if hoge == 1:
    sb = s[:i-let] + t + s[i:]
    ans = ''
    for v in sb:
      if v == '?':
        ans += 'a'
      else:
        ans += v
    print(ans)
    exit()
print('UNRESTORABLE')

Solution (Python):
def main():
    s = input()
    t = input()
    
    
    ans = []
    for i in range(len(s)-len(t)+1):
        tmp = s[:i]
        flag = False
        for j in range(i,i+len(t)):
            if s[j]==t[j-i]:
                tmp += t[j-i]
                pass
            elif s[j]=='?':
                tmp += t[j-i]
                pass
            else:
                flag = True
                break
        if not flag:
            tmp += s[i+len(t):]
            tmp = tmp.replace('?','a')
            ans.append(tmp)
    if ans:
        ans.sort()
        print(ans[0])
    else:
        print('UNRESTORABLE')

main()

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[:i] + t + s[i+len(t):]
        s = s.replace('.', 'a')
        print(s)
        exit(0)
print('UNRESTORABLE')

Solution (Python):
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]!='?' and s[i+j]!=t[j]:
            break
    else:
        print(s[:i].replace('?','a')+t+s[i+len(t):].replace('?','a'))
        break
else:
    print('UNRESTORABLE')

Solution (Python):
S=input()
T=input()
tmp=[]
for i in range(len(S)):
    flag=True
    for j in range(min(len(T),len(S)-i)):
        if S[i+j]==T[j] or S[i+j]=="?" or T[j]=="?":
            continue
        else:
            flag=False
    if flag:
        rec=S[:i]+T+S[i+len(T):]
        if len(rec)==len(S):
            rec=rec.replace("?","a")
            tmp.append(rec)
if tmp==[]:
    print("UNRESTORABLE")
    exit()
tmp.sort()
print(tmp[0])

Solution (Python):
sd = input()
t = input()
n = len(sd)
m = len(t)
s = []
for i in range(n-m, -1, -1):
  ans = 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 ans[j] == '?':
      continue
    elif ans[j] != t[j]:
      break
print("UNRESTORABLE")

Solution (Python):
from math import floor
from decimal import Decimal

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

isSuccess = False

for i in reversed(range(len(S) - len(T) + 1)):
    T_str = S[i: i + len(T)]
    for j in range(len(T)):
        if T_str[j] != T[j] and T_str[j] != "?":
        	break
    else:
        isSuccess = True
        S[i:i + len(T)] = T
        break
if isSuccess == False:
    print("UNRESTORABLE")
else:
    string = ",".join(S)
    string = string.replace('?', 'a')
    S = string.split(',')
    print("".join(map(str,S)))

Solution (Python):
from re import match
s, t = input().replace('?', '.'), input()

for i in range(len(s) - len(t) + 1)[::-1]:
    if match(s[i:i + len(t)], t):
        key = (s[:i] + t + s[i + len(t):]).replace('.', 'a')
        print(key)
        break
else:
    print('UNRESTORABLE')

Solution (Python):
from re import match
s, t = input().replace('?', '.'), input()

for i in range(len(s) - len(t) + 1)[::-1]:
    if match(s[i:i + len(t)], t):
        key = s.replace(s[i:i + len(t)], t).replace('.', 'a')
        s = s.replace('.', 'a')
        print(s[:i] + t + s[i + len(t):])
        
        break
else:
    print('UNRESTORABLE')

Solution (Python):
chr1 = input().rstrip()
chr2 = input().rstrip()

result = []
for i in range(len(chr1)):
    if (chr1[i] == chr2[0] or chr1[i] == "?")and i + len(chr2) <= len(chr1):
        index = 0
        for j in range(len(chr2)):
            if chr1[i+j] == chr2[j] or chr1[i+j] == "?":
                index += 1
            else:
                break
        if index == len(chr2):
            temp = chr1[0:i]+chr2+chr1[i+len(chr2):]
            temp = temp.replace("?", "a")
            result.append(temp)
if len(result) >= 1:
    result.sort()
    print(result[0])
else:
    print("UNRESTORABLE")

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 = str(input())
t = str(input())

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

if ans_ind == -1:
    print('UNRESTORABLE')
else:
    ans = ''
    for i in range(len(s)):
        if ans_ind <= i < ans_ind + len(t):
            ans += t[i-ans_ind]
        else:
            if s[i] == '?': ans += 'a'
            else: ans += s[i]
    print(ans)

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()
t = input()

def match(k):
    flag = True
    for i in range(len(t)):
        if s[i + k] != t[i] and s[i + k] != "?":
            flag = False
            break
    return flag

flag = False
for k in reversed(range(len(s) - len(t) + 1)):
    if match(k):
        s = s[:k] + t + s[k + len(t):]
        flag = True
        break

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