Problem:


Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.

He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.  

One more thing he found is a sheet of paper with the following facts written on it:  

Condition 1: The string S contains a string T as a contiguous substring.

Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.

Print the string S.

If such a string does not exist, print UNRESTORABLE.  

Constraints

1 \leq |S'|, |T| \leq 50

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

If such a string does not exist, print UNRESTORABLE instead.  

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

There are 26 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder.
Among them, the lexicographically smallest is atcoder, so we can say S = atcoder.

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

There is no string that satisfies Condition 1, so the string S does not exist.



Sample input:
?tc????
coder


Sample output:
atcoder

Submission status: Runtime Error

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

sd=list(sts)
t=list(ts)

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": 
    print("UNRESTORABLE")
#elif yn=="": 
#    print("UNRESTORABLE")
#elif yn=="yes":
else:
    s=sd.copy()
    for j in range(len(t)):
        s[ii+j]=t[j]
    for j in range(len(s)):
        if s[j]=="?":
           s[j]="a"
    strt="".join(s)
    print(strt)

Submission status: Runtime Error

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

#sts="?tc????"
#ts="coder"

#sts="??p??d??"
#ts="abc"
#sd=list(sts)
#t=list(ts)

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": 
    print("UNRESTORABLE")
elif yn=="": 
    print("UNRESTORABLE")
elif yn=="yes":
    s=sd.copy()
    for j in range(len(t)):
        s[ii+j]=t[j]
    for j in range(len(s)):
        if s[j]=="?":
           s[j]="a"
    strt="".join(s)
    print(strt)

Submission status: Runtime Error

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

#sts="?tc????"
#ts="coder"

#sts="??p??d??"
#ts="abc"
#sd=list(sts)
#t=list(ts)

for i in range(len(sd)-len(t)):
    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": 
    print("UNRESTORABLE ")
elif yn=="": 
    print("UNRESTORABLE ")
elif yn=="yes":
    s=sd.copy()
    for j in range(len(t)):
        s[ii+j]=t[j]
    for j in range(len(s)):
        if s[j]=="?":
           s[j]="a"
    strt="".join(s)
    print(strt)

Submission status: Runtime Error

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

#sts="?tc????"
#ts="coder"

#sts="??p??d??"
#ts="abc"
#sd=list(sts)
#t=list(ts)

for i in range(len(sd)-len(t)):
    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": 
    print("UNRESTORABLE")
elif yn=="": 
    print("UNRESTORABLE")
elif yn=="yes":
    s=sd.copy()
    for j in range(len(t)):
        s[ii+j]=t[j]
    for j in range(len(s)):
        if s[j]=="?":
           s[j]="a"
    strt="".join(s)
    print(strt)

Submission status: Runtime Error

Solution code:
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+1)] != t[-(j+1)] and s[-(j+i+1)] != '?':
            f = False
    if f == True:
        s = s[:-(len(t)+i)] + t + s[len(s)-1-i:0]
        s = s.replace('?','a')
        ans.append(s)



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

Submission status: Runtime Error

Solution code:
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))

Submission status: Runtime Error

Solution code:
import re
s = input()
s = s.replace('?', '.')
t = input()
r = []
if len(t) > len(s):
  print("UNRESTORABLE")
else:
  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(sorted(r)[0])

Submission status: Runtime Error

Solution code:
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"
      
    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)

Submission status: Runtime Error

Solution code:
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])]

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"
      
    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)

Submission status: Runtime Error

Solution code:
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])]

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"
      
  for j in range(1,n_s):
    if s[j] == "?":
      s[j] = "a"
    ans = ans + s[j]
    
elif last_num == -1:
  ans = "UNRESTORABLE"
  
print(ans)

Submission status: Runtime Error

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

tLen = len(t)

"""
sの中の?を.に置換する
"""
s.replace("?",".")

print(s)

for i in range(tLen,len(s)+1):
  #[-i:(-i+tLen)]の区間の文字列が、tにマッチするかを調べる。マッチするなら置換する。

Submission status: Runtime Error

Solution code:
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")

Submission status: Runtime Error

Solution code:
from collections import deque
original_S=deque(input())
original_T=deque(input())

S=original_S.copy()
T=original_T.copy()
restored_S=deque()

while len(S)>=len(T)>0:
    s=S.pop()
    t=T.pop()

    if s==t or s=='?':
        restored_S.appendleft(t)

    else:
        copied_S=original_S.copy()
        re_restored_S=deque()
        for n in range(len(restored_S)):
            s2=copied_S.pop()
            if s2=='?':
                re_restored_S.appendleft('a')
            else:
                re_restored_S.appendleft(s2)
        restored_S=re_restored_S
        S.append(s)
        T=original_T.copy()

if len(T)>0:
    print('UNRESTORABLE')

else:
    while len(S)>0:
        s=S.pop()
        if s=='?':
            restored_S.appendleft('a')
        else:
            restored_S.appendleft(s)
    print(''.join(list(restored_S)))

Submission status: Runtime Error

Solution code:
from collections import deque
original_S=deque(input())
original_T=deque(input())

S=original_S.copy()
T=original_T.copy()
restored_S=deque()

while len(S)>=len(T)>0:
    s=S.pop()
    t=T.pop()

    if s==t or s=='?':
        restored_S.appendleft(t)

    else:
        re_restored_S=deque()
        for n in range(len(restored_S)):
            s=original_S.pop()
            if s=='?':
                re_restored_S.appendleft('a')
            else:
                re_restored_S.appendleft(s)
        restored_S=re_restored_S
        T=original_T.copy()

if len(S)<len(T):
    print('UNRESTORABLE')

else:
    while len(S)>0:
        s=S.pop()
        if s=='?':
            restored_S.appendleft('a')
        else:
            restored_S.appendleft(s)
    print(''.join(list(restored_S)))

Submission status: Runtime Error

Solution code:
import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
flg = False
#cnt = 0

if len(s)-len(t)+1<0:
	print("UNRESTOABLE")
    sys.exit(0)
 
for i in range(len(s)-len(t)+1):
    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j] or s[i+j] == '?':
            cnt+=1
        #print(cnt,len(t))
    if cnt == len(t):
        cnt=i
        flg = True
        #print(cnt)
        break
 
if not flg:
    print("UNRESTORABLE")
else:
    li = list(s.replace("?","a"))
    #print(li)
    for j in range(len(t)):
        #print(li[cnt+j], t[j])
        li[cnt+j] = t[j]
    print("".join(li))

Submission status: Runtime Error

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


import sys
input = sys.stdin.readline
s = input()
t = input()
flg = False
cnt = 0

for i in range(len(s)-len(t)+1):

    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j] or s[i+j] == '?':
            cnt += 1
            continue

    if cnt == len(t):
        flg = True
        print(cnt)
        break

if not flg:
    print("UNRESTORABLE")
else:
    li = list(s)
    for j in range(len(t)):
        li[cnt+j]=t[j]
    print("".join(li))

Submission status: Runtime Error

Solution code:
import re
s, t = input().replace('?', '.'), input()
l, m = len(s), len(t)

if l < m:
    print("UNRESTORABLE")
    exit()

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

Submission status: Runtime Error

Solution code:
SS=input()
T=input()
listT=[a for a in T]
TN=len(listT)
listSS=[b for b in SS]
SSN=len(listSS)
n=SSN-TN
numbers=[]
suuji=0
if n<0:
    print('UNRESTORABLE')
else:
    for c in range(n + 1):
        number = 0
        e=0
        for d in range(TN):
            if listSS[c + d] == listT[d] or listSS[c + d] == '?':
                number += 1
            if number == TN:
                e += c
                suuji += number
                numbers.append(e)

    if suuji ==0:
        print('UNRESTORABLE')
    else:
        mojiretu = []
        for a in range(TN):
            for b in numbers:
                listSS[b+ a] = listT[a]
                moji = ''
                mojiretu=[]
                for a in listSS:
                    moji += a
                answer = moji.replace('?', 'a')
                mojiretu.append(answer)
                kotae=sorted(mojiretu)
        print(kotae[0])

Submission status: Runtime Error

Solution code:
s = list(input())
t = list(input())
s_copy = s
ans_list = []
n = len(s)
m = len(t)
flag = 0
flag_2 = 0
for i in range(n):
  if s[i] == "?" or s[i] == t[flag]:
    if flag == m-1:
      flag_2 = 1
      for j in range(flag,-1,-1):
        s[i-(m-1-j)] = t[j]
      ans_list.append(s)
      s = s_copy
    else:
      flag += 1
  else:
    flag = 0
x = len(ans_list)
if flag_2 == 1:
  for l in range(x):
    for k in range(n):
      if s[l][k] == "?":
        s[l][k] = "a"
  ans_list.sort()
  print("".join(ans_list[0]))
else:
  print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import copy
s=list(map(str,input()))
t=list(map(str,input()))
def converta(s):
  for i in range(len(s)):
    if s[i]=='?':
      s[i]='a'
  return s
res=[]
for i in range(len(s)-len(t)+1):
    c=copy.copy(s)
    ok=True
    for j in range(len(t)):
        if t[j]!=s[i+j] and s[i+j]!='?':
            ok=False
            break
        else:
            c[i+j]=t[j]
    if ok:
        res.append(converta(c))
ans=min(res)
if res==[]:
  print('UNRESTORABLE')
else:
  print(''.join(ans))

Submission status: Runtime Error

Solution code:
#coding: utf-8
import math
import heapq
import bisect
import numpy as np
from collections import Counter
#from scipy.misc import comb

S = input()
T = input()

start = -1
for i in range(len(S)-len(T),-1,-1):
    flg = 1
    for j in range(len(T)):
        if S[i+j] != '?' and S[i+j] != T[j]:
            flg = 0
            break
    if flg:
        start = i
        break

if flg == -1:
    ans = 'UNRESTORABLE'
else:
    S = S.replace('?', 'a')
    ans = S[:start] + T + S[start+len(T)+1:]

print(ans)

Submission status: Runtime Error

Solution code:
s=input()
t=input()
f=1
tmp=0
if len(s)<len(t):
  print("UNRESTORABLE")
  exit()
n=len(s)
m=len(t)
for i in range(n-m+1):
  x=s[i:i+m]
  for j in range(m+1): #
    if j==m:
      print((s[:i]+t+s[i+m:]).replace("?","a"))
    if x[j]=="?":
      continue
    elif x[j]!=t[j]:
      break
print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
s = list(input())
t = list(input())
n = len(s)
m = len(t)
flag = 0
flag_2 = 0
for i in range(n):
  if s[i] == "?" or s[i] == t[flag]:
    if flag == m-1:
      flag_2 = 1
      for j in range(flag,-1,-1):
        s[i-(m-1-j)] = t[j]
      break
    else:
      flag += 1
  else:
    flag = 0
if n<m:
  flag_2 = 0
if flag_2 == 1:
  for k in range(n):
    if s[k] == "?":
      s[k] = "a"
  print("".join(s))
else:

Submission status: Runtime Error

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

Submission status: Runtime Error

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


def t_index_is_valid(t_index, start, end):
    if S[t_index+start:t_index+end]:
        for j, t_ in enumerate(T):
            if S[t_index+start+j] == "?" or S[t_index+start+j] == t_:
                pass
            else:
                return False
        return True
    else:
        return False


ok = False
replace_index = (0, 0)
for i, t in enumerate(T):
    if ok:
        break
    if t in S:
        t_indexes = [n for n, v in enumerate(S) if v == t]
        t_indexes.reverse()
        start = - i
        end = len_t - i + 1
        for t_index in t_indexes:
            if t_index_is_valid(t_index, start, end):
                replace_index = (t_index+start, t_index+end)
                ok = True
                break

if not ok:
    print("UNRESTORABLE")
else:
    S = list(S)
    for j, i in enumerate(range(replace_index[0], replace_index[1]-1)):
        S[i] = T[j]
    for i in range(len(S)):
        if S[i] == "?":
            S[i] = "a"
    print("".join(S))

Submission status: Runtime Error

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def is_ok(sd, st, t):
	if len(sd) < st+len(t):
		return False
	for i, c in enumerate(sd[st:st+len(t)]):
		if c != '?' and t[i] != c:
			return False
	return True
	
def to_aaa(a_str):
	rr=list(a_str)
	for i, c in enumerate(rr):
		rr[i] = 'a' if c == '?' else c
	ret = ''.join(rr)
	return ret

def mk_s(a_s_dash, i, t):
	front = to_aaa(a_s_dash[:i])
	back = to_aaa(a_s_dash[i+len(t):])
	ret = front+t+back
	#pa((i,t,front,t,back,ret))
	return ret
			
def main():
	s_dash = input()
	t=input()
	dd='UNRESTORABLE'
	qq='?'
	
	aa=[]
	for i, _ in enumerate(s_dash[:len(t)+1]):
		if is_ok(s_dash,i,t):
			aa.append(mk_s(s_dash, i, t))
			#pa(aa)
			
	if len(aa)>0:
		
		aa.sort()
		ret = aa[0]
		print(ret)
		return
	aa=aa.copy()
	print(dd)
	return
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Runtime Error

Solution code:
##Hint for matching: We get the one that has the most match

#For each space in the interval: Match each blank and count it (The T is given to have at most n-1 matches where n is the length of T)

#For absolute match: it has n-1 matches
#For local match: it has the maximum matches

#For no match: The T belongs to the last

#The code is unrestorable if:
    #1) T > S
    #2) code doesn't fit anywhere(?)

S = input()
T = input()
code = S
match = 0
maxmatch = 0
maxmatchloc = -1
hasmatch = False
if (len(T) == 1):
    for x in range(len(S)-1,0,-1):
        if (S[x] == '?'):
            S = S[:x] + T + S[x+1:]
            break
    code = S
    for x in range(len(S)):
        if (S[x] == '?'):
            code = code[:x] + 'a' + code[x+1:]
    print(code)
Missing function: When none of the letters of T match the one in a, thenit finds the farthest point to land on
elif '?' in S:
    if (len(T) <= len(S)):
            for x in range(len(S)-(len(T)-1)):
                match = 0
                for i in range(len(T)):                
                    if (S[x+i] == T[i]):##when i add (or S[x+i] == '?') it solves 8 it makes an error on the others
                        if (maxmatch == -1):
                            maxmatch = 0
                        match += 1
                    elif (S[x+i] != T[i] and S[x+i] != '?'):
                        maxmatch = -1
                        break
                    elif (S[x+i] != T[i] and S[x+i] == '?'):
                        match += 1
                        
                if (maxmatch == -1 and hasmatch == False):
                    continue
                #if match
                if (match >= maxmatch and maxmatch != -1 and match < len(T)):
                    hasmatch = True 
                    maxmatch = match
                    maxmatchloc = x
            #Building the code#
            for x in range(len(S)):
                if (S[x] == '?'):
                    code = code[:x] + 'a' + code[x+1:] 
            if (maxmatch == 0):
                code = code[:len(S)-len(T)] + T
                print(code)
            elif(maxmatchloc >= 0):
                code = code[:maxmatchloc] + T + code[maxmatchloc + len(T):]
                print(code)
            elif(maxmatchloc == -1):
                print('UNRESTORABLE')
            else:
                print('UNRESTORABLE')
    else:
        print('UNRESTORABLE')
else:
    print(S)

Submission status: Runtime Error

Solution code:
##Hint for matching: We get the one that has the most match

#For each space in the interval: Match each blank and count it (The T is given to have at most n-1 matches where n is the length of T)

#For absolute match: it has n-1 matches
#For local match: it has the maximum matches

#For no match: The T belongs to the last

#The code is unrestorable if:
    #1) T > S
    #2) code doesn't fit anywhere(?)

S = input()
T = input()
code = S
match = 0
maxmatch = 0
maxmatchloc = -1
hasmatch = False
##if (len(T) == 1):
##    for x in range(len(S)-1,0,-1):
##        if (S[x] == '?'):
##            S = S[:x] + T + S[x+1:]
##            break
##    code = S
##    for x in range(len(S)):
##        if (S[x] == '?'):
##            code = code[:x] + 'a' + code[x+1:]
##    print(code)
##Missing function: When none of the letters of T match the one in a, thenit finds the farthest point to land on
elif '?' in S:
    if (len(T) <= len(S)):
            for x in range(len(S)-(len(T)-1)):
                match = 0
                for i in range(len(T)):                
                    if (S[x+i] == T[i]):##when i add (or S[x+i] == '?') it solves 8 it makes an error on the others
                        if (maxmatch == -1):
                            maxmatch = 0
                        match += 1
                    elif (S[x+i] != T[i] and S[x+i] != '?'):
                        maxmatch = -1
                        break
                    elif (S[x+i] != T[i] and S[x+i] == '?'):
                        match += 1
                        
                if (maxmatch == -1 and hasmatch == False):
                    continue
                #if match
                if (match >= maxmatch and maxmatch != -1 and match < len(T)):
                    hasmatch = True 
                    maxmatch = match
                    maxmatchloc = x
            #Building the code#
            for x in range(len(S)):
                if (S[x] == '?'):
                    code = code[:x] + 'a' + code[x+1:] 
            if (maxmatch == 0):
                code = code[:len(S)-len(T)] + T
                print(code)
            elif(maxmatchloc >= 0):
                code = code[:maxmatchloc] + T + code[maxmatchloc + len(T):]
                print(code)
            elif(maxmatchloc == -1):
                print('UNRESTORABLE')
            else:
                print('UNRESTORABLE')
    else:
        print('UNRESTORABLE')
else:
    print(S)

Submission status: Runtime Error

Solution code:
##Hint for matching: We get the one that has the most match

#For each space in the interval: Match each blank and count it (The T is given to have at most n-1 matches where n is the length of T)

#For absolute match: it has n-1 matches
#For local match: it has the maximum matches

#For no match: The T belongs to the last

#The code is unrestorable if:
    #1) T > S
    #2) code doesn't fit anywhere(?)

S = input()
T = input()
code = S
match = 0
maxmatch = 0
maxmatchloc = -1
hasmatch = False
##if (len(T) == 1):
##    for x in range(len(S)-1,0,-1):
##        if (S[x] == '?'):
##            S = S[:x] + T + S[x+1:]
##            break
##    code = S
##    for x in range(len(S)):
##        if (S[x] == '?'):
##            code = code[:x] + 'a' + code[x+1:]
##    print(code)
##Missing function: When none of the letters of T match the one in a, thenit finds the farthest point to land on
elif '?' in S:
    if (len(T) <= len(S)):
            for x in range(len(S)-(len(T)-1)):
                match = 0
                for i in range(len(T)):                
                    if (S[x+i] == T[i]):##when i add (or S[x+i] == '?') it solves 8 it makes an error on the others
                        if (maxmatch == -1):
                            maxmatch = 0
                        match += 1
                    elif (S[x+i] != T[i] and S[x+i] != '?'):
                        maxmatch = -1
                        break
                    elif (S[x+i] != T[i] and S[i] == '?'):
                        match += 1
                        
                if (maxmatch == -1 and hasmatch == False):
                    continue
                #if match
                if (match >= maxmatch and maxmatch != -1 and match < len(T)):
                    hasmatch = True 
                    maxmatch = match
                    maxmatchloc = x
            #Building the code#
            for x in range(len(S)):
                if (S[x] == '?'):
                    code = code[:x] + 'a' + code[x+1:] 
            if (maxmatch == 0):
                code = code[:len(S)-len(T)] + T
                print(code)
            elif(maxmatchloc >= 0):
                code = code[:maxmatchloc] + T + code[maxmatchloc + len(T):]
                print(code)
            elif(maxmatchloc == -1):
                print('UNRESTORABLE')
            else:
                print('UNRESTORABLE')
    else:
        print('UNRESTORABLE')
else:
    print(S)

Submission status: Runtime Error

Solution code:
S = input()
T = input()
code = S
match = 0
maxmatch = 0
maxmatchloc = -1
hasmatch = False
if (len(T) <= len(S)):
        for x in range(len(S)-(len(T)-1)):
            match = 0
            for i in range(len(T)):                
                if (S[x+i] == T[i]):
                    if (maxmatch == -1):
                        maxmatch = 0
                    match += 1
                if (S[x+i] != T[i] and S[x+i] != '?'):
                    maxmatch = -1
                    break
            if (maxmatch == -1 and hasmatch == false):
                continue
            #if match
            if (match >= maxmatch and maxmatch != -1 and match < len(T)):
                hasmatch = True 
                maxmatch = match
                maxmatchloc = x
        #Building the code#
        for x in range(len(S)):
            if (S[x] == '?'):
                code = code[:x] + 'a' + code[x+1:] 
        if (maxmatch == 0):
            code = code[:len(S)-len(T)] + T
            print(code)
        elif(maxmatchloc >= 0):
            code = code[:maxmatchloc] + T + code[maxmatchloc + len(T):]
            print(code)
        elif(maxmatchloc == -1):
            print('UNRESTORABLE')
        else:
            print('UNRESTORABLE')
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
S = input()
T = input()
code = S
match = 0
maxmatchloc = 0
if (len(T) <= len(S)):
    for x in range(len(S)):
        match = 0
        for i in range(len(T)):
            if (S[x+i] == T[i]):
                match += 1
            if (S[x+i] != T[i] and S[x+i] != '?'):
                match = 0
                break
        if (match > maxmatchloc and match != (len(T))):
            maxmatchloc = x

    #Building the code#
    if (maxmatchloc == 0):
        print('UNRESTORABLE')
    else:
        for x in range(len(S)):
            if (S[x] == '?'):
                code = code[:x] + 'a' + code[x+1:]
        code = code[:maxmatchloc] + T + code[maxmatchloc + len(T):]
        print(code)
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

if (len(T) > S):
    for x in range(len(S)):
        if (S[x] == '?'):
            code = code[:x] + 'a' + code[x+1:]
    for x in range(len(S)-(len(T)-1),-1,-1):
        if (x == -1):
            print('UNRESTORABLE')
        elif (S[x:x+len(T)] == (('?')*len(T)) or (S[x:x+len(T)] == ( T[0] + (('?')*(len(T)-1))))):
            code = code[:x] + T + code[x+len(T):]
            print(code)
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
def start(S,T):
    for x in range(len(S)-(len(T)-1)):
        if (S[x] == T[0] and (S[x+(len(T)-1)] == (T[len(T)-1]) or (S[x+(len(T)-1)] == '?'))):
            return x
    return len(S)

def delete(A,code):
    for x in range(len(code)):
        if code[x] in A:
            A.remove(code[x])
    return A
    

S = input()
T = input()
code = ''
left = list(map(chr, range(97, 123)))
if (len(S)-(len(T)-1) > 0):
    startingpoint = start(S,T)
    if (startingpoint == len(S)):
        print('UNRESTORABLE')
    else:
        if (S[0] != '?'):  
            code = S[:startingpoint] + T + S[startingpoint+(len(T)):]
        else:
            code = S[:startingpoint] + T + S[startingpoint+(len(T)):]
        left = delete(left,code)
        for x in range(len(code)):
            if (code[x] == '?'):
                if (code[0] != '?'):  
                    code = code[:x] + left[x] + code[x+1:]
                else:
                    code = code[:x] + left[x] + code[x+1:]
                left.remove(left[x])
        print(code)
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
def start(S,T):
    for x in range(len(S)-(len(T)-1)):
        if (S[x] == T[0] and (S[x+(len(T)-1)] == (T[len(T)-1]) or (S[x+(len(T)-1)] == '?'))):
            return x
    return len(S)

def delete(A,code):
    for x in range(len(code)):
        if code[x] in A:
            A.remove(code[x])
    return A
    

S = input()
T = input()
code = ''
left = list(map(chr, range(97, 123)))
if (len(S)-(len(T)-1) > 0):
    startingpoint = start(S,T)
    if (startingpoint == len(S)):
        print('UNRESTORABLE')
    else:
        if (S[0] != '?'):  
            code = S[:startingpoint] + T + S[startingpoint+(len(T))]
        else:
            code = S[:startingpoint] + T + S[startingpoint+(len(T)):]
        left = delete(left,code)
        for x in range(len(code)):
            if (code[x] == '?'):
                if (code[0] != '?'):  
                    code = code[:x] + left[x] + code[x+1:]
                else:
                    code = code[:x] + left[x] + code[x+1:]
                left.remove(left[x])
        print(code)
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
##Dubious Document 2
def start(S,T):
    for x in range(len(S)-(len(T)-1)):
        if (S[x] == T[0] and (S[x+(len(T)-1)] == (T[len(T)-1]) or (S[x+(len(T)-1)] == '?'))):
            return x
    return len(S)

def delete(A,code):
    for x in range(len(code)):
        if code[x] in A:
            A.remove(code[x])
    return A
    

S = input()
T = input()
code = ''
left = list(map(chr, range(97, 123)))
if (len(S)-(len(T)-1) > 0):
    startingpoint = start(S,T)
    if (startingpoint == len(S)):
        print('UNRESTORABLE')
    else:
        if (S[0] != '?'):  
            code = S[:startingpoint] + T + S[startingpoint+len(T)]
        else:
            code = S[:startingpoint] + T + S[startingpoint+(len(T)):]
        left = delete(left,code)
        for x in range(len(code)):
            print(code)
            if (code[x] == '?'):
                if (code[0] != '?'):  
                    code = code[:x] + left[x] + code[x+1:]
                else:
                    code = code[:x] + left[x] + code[x+1:]
                left.remove(left[x])
        print(code)
else:
    print('UNRESTORABLE')