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: Wrong Answer

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 ans_list[l][k] == "?":
        ans_list[l][k] = "a"
  ans_list.sort()
  print("".join(ans_list[0]))
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

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[k] == "?":
        s[k] = "a"
  ans_list.sort()
  print("".join(ans_list[0]))
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

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

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

print('UNRESTORABLE')

Submission status: Wrong Answer

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

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:
        ans = S[:i] + T + S[i+len(T)+1:]
        print(ans.replace('?','a'))
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

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 start == -1:
    ans = 'UNRESTORABLE'
else:
    S = S.replace('?', 'a')
    if start == len(S)-len(T):
        ans = S[:start] + T
    elif start == 0:
        ans = T + S[start+len(T)+1:]
    else:
        ans = S[:start] + T + S[start+len(T)+1:]

print(ans)

Submission status: Wrong Answer

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 start == -1:
    ans = 'UNRESTORABLE'
else:
    S = S.replace('?', 'a')
    if start == len(S)-len(T):
        ans = S[:start] + T
    else:
        ans = S[:start] + T + S[start+len(T)+1:]

print(ans)

Submission status: Wrong Answer

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 start == -1:
    ans = 'UNRESTORABLE'
else:
    S = S.replace('?', 'a')
    ans = S[:start] + T + S[start+len(T)+1:]

print(ans)

Submission status: Wrong Answer

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"))
      exit()
    if x[j]=="?":
      continue
    elif x[j]!=t[j]:
      break
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def main():
    S = [s for s in input()]
    T = [t for t in input()]
    L = len(S)
    M = len(T)
    flag = 0
    for i in range(L-M+1):
        tmp = list(S[i:i+M])
        cnt = 0
        num = tmp.count('?')
        for j in range(M):
            if tmp[j] != '?' and tmp[j] != T[j]:continue
            elif tmp[j] == T[j]:
                cnt += 1
        if cnt == M-num:
            flag = 1
            for k in range(M):
                S[i+k] = T[k]
            break
    if flag:
        for i in range(L):
            if S[i] == '?':
                S[i] = 'a'
        print(''.join(S))
    else:
        print('UNRESTORABLE')

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = [s for s in input()]
    T = [t for t in input()]
    L = len(S)
    M = len(T)
    flag = 0
    for i in range(L-M+1):
        tmp = S[i:i+M]
        cnt = 0
        for j in range(M):
            if tmp[j] != '?' and tmp[j] != T[j]:continue
            else:
                cnt += 1
        if cnt == M:
            flag = 1
            for k in range(M):
                S[i+k] = T[k]
    if flag:
        for i in range(L):
            if S[i] == '?':
                S[i] = 'a'
        print(''.join(S))
    else:
        print('UNRESTORABLE')

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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 flag_2 == 1:
  for i in range(n):
    if s[i] == "?":
      s[i] = "a"
  print("".join(s))
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

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]
    else:
      flag += 1
  else:
    flag = 0
if flag_2 == 1:
  for i in range(n):
    if s[i] == "?":
      s[i] = "a"
  print("".join(s))
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

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

l = len(T)

ind = 51
for i in range(len(S)-l+1):
    flag = 0
    for j in range(l):
        if S[i+j]!='?' and S[i+j]!=T[j]:
            flag = 1
    if flag==0:
        ind = i

if ind == 51:
    print('UNRESTORABLE')
    exit()

print(S[:i].replace('?','a')+T+S[i+j:].replace('?','a'))

Submission status: Wrong Answer

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

s_reversed = list(reversed(S))
T_reversed = list(reversed(T))
F = 0

for i in range(len(S)-len(T)+1):
    s = s_reversed[i:i+len(T)]
    flag = 0
    for j in range(len(T)):
        if s[j] == T_reversed[j] or s[j] == '?':
            continue
        else:
            flag += 1
            break
    if flag ==0:
        F += 1
        for j in range(len(T)):
            s_reversed[i+j] = T_reversed[j]
        break

if F ==0:
    print('UNRESTORABLE')
else:
    R = ''.join(list(reversed(s_reversed)))
    print(R)
    print(R.replace('?','a'))

Submission status: Wrong Answer

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

s_reversed = list(reversed(S))
T_reversed = list(reversed(T))
F = 0

for i in range(len(S)-len(T)+1):
    s = s_reversed[i:i+len(T)]
    flag = 0
    for j in range(len(T)):
        if s[j] == T_reversed[j] or s[j] == '?':
            continue
        else:
            flag += 1
            break
    if flag:
        F += 1
        for j in range(len(T)):
            s_reversed[i+j-1] = T_reversed[j]
        break

if F:
    print('UNRESTORABLE')
else:
    R = ''.join(list(reversed(s_reversed)))
    print(R.replace('?','a'))

Submission status: Wrong Answer

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]
        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: Wrong Answer

Solution code:
import copy
S_original = input()
T = input()

lis_t = list(T)
T_size = len(T)
S_size = len(S_original)
hantei = 0
lis = []

if T_size > S_size:
    print ("UNRESTORABLE")
else:
    for start_index in range(S_size - T_size + 1):

        S_prime = copy.deepcopy(S_original)
        hantei = 0
        for i in range(T_size):
            if S_prime[start_index+i] == T[i]:
                continue
            elif S_prime[start_index+i] == "?":
                s_lis = list(S_prime)
                s_lis[start_index+i] = lis_t[i]
                S_prime = "".join(s_lis)
            elif S_prime[start_index+i] != T[i]:
                hantei = 1
                break
        if hantei == 0:
            for j in range(S_size):
                if S_prime[j] != "?":
                    continue
                else:
                    s_lis = list(S_prime)
                    s_lis[j] = "a"
                    S_prime = "".join(s_lis)
            lis.append(S_prime)

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

Submission status: Wrong Answer

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

S_dash = input()
T = input()

S_dash_list = list(S_dash)
T_list = list(T)

ei = len(S_dash_list)
si = ei - len(T_list)

insert_flag = False
while si >= 0:
    #print('si: {}, ei: {}'.format(si, ei))
    target = S_dash_list[si:ei]
    flag = True
    #print(S_dash_list[si:ei])
    for i in range(len(T_list)):
        if S_dash_list[si + i] != T_list[i] and S_dash_list[si + i] != '?':
            flag = False
            # ここでsiとeiを更新
            ei = si + i
            si = ei - len(T_list)
            break
    if flag:
        for i in range(len(T_list)):
            S_dash_list[si + i] = T_list[i]
        insert_flag = True
        break

if not insert_flag:
    print('UNRESTORABLE')
else:
    ans = ''.join(S_dash_list)
    #print(ans)

    # '?'をaで埋める
    print(ans.replace('?', 'a'))

Submission status: Wrong Answer

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

S_dash = input()
T = input()

S_dash_list = list(S_dash)
T_list = list(T)

ei = len(S_dash_list)
si = ei - len(T_list)

insert_flag = False
while si >= 0:
    #print('si: {}, ei: {}'.format(si, ei))
    target = S_dash_list[si:ei]
    flag = True
    #print(S_dash_list[si:ei])
    for i in range(len(T_list)):
        if S_dash_list[si + i] != T_list[i] and S_dash_list[si + i] != '?':
            flag = False
            break
    if flag:
        for i in range(len(T_list)):
            S_dash_list[si + i] = T_list[i]
        insert_flag = True
        break
    else:
        # siとeiを更新
        ei = si
        si = si - len(T_list)

if not insert_flag:
    print('UNRESTORABLE')
else:
    ans = ''.join(S_dash_list)
    #print(ans)

    # '?'をaで埋める
    print(ans.replace('?', 'a'))

Submission status: Wrong Answer

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

S_dash = input()
T = input()

S_dash_list = list(S_dash)
T_list = list(T)

ei = len(S_dash_list)
si = ei - len(T_list)

insert_flag = False
while si >= 0:
    print('si: {}, ei: {}'.format(si, ei))
    target = S_dash_list[si:ei]
    flag = True
    print(S_dash_list[si:ei])
    for i in range(len(T_list)):
        if S_dash_list[si + i] != T_list[i] and S_dash_list[si + i] != '?':
            flag = False
            break
    if flag:
        for i in range(len(T_list)):
            S_dash_list[si + i] = T_list[i]
        insert_flag = True
        break
    else:
        # siとeiを更新
        ei = si
        si = si - len(T_list)

if not insert_flag:
    print('UNRESTORABLE')
else:
    ans = ''.join(S_dash_list)
    print(ans)

    # '?'をaで埋める
    print(ans.replace('?', 'a'))

Submission status: Wrong Answer

Solution code:
def search(S,T):
    match = 0
    maxmatch = 0
    maxmatchloc = -1
    for x in range(len(S)-(len(T)-1)):
        match = 0
        if (S[x] == T[0] or S[x] == '?'):
            for i in range(0,len(T)):
                print(S[x+i] + '-' + T[i])
                if (S[x+i] == T[i] or S[x+i] == "?"):
                    match += 1
                else:
                    ##print("Entered!")
                    match = 0
                    break
            if (match >= maxmatch and match != 0):
                ##print("ENTERED")
                maxmatchloc = x
                maxmatch = match
        ##print('At x = ' + str(x) + ': maxmatchlocation is ' + str(maxmatchloc) + ' match is ' + str(match) + ' maxmatch is' + str(maxmatch))
    return maxmatchloc

S = input()
T = input()
code = S
if '?' in S:
    if (len(T) <= len(S)):
        startpoint = search(S,T)
        for x in range(len(S)):
            if (S[x] == '?'):
                code = code[:x] + 'a' + code[x+1:] 
        if(startpoint >= 0):
            code = code[:startpoint] + T + code[startpoint + len(T):]
            print(code)
        else:
            print('UNRESTORABLE')
    else:
        print('UNRESTORABLE')
else:
    print(S)

Submission status: Wrong Answer

Solution code:
def search(S,T):
    match = 0
    maxmatch = 0
    maxmatchloc = -1
    for x in range(len(S)-(len(T)-1)):
        match = 0
        if (S[x] == T[0] or S[x] == '?'):
            for i in range(0,len(T)):
                print(S[x+i] + '-' + T[i])
                if (S[x+i] == T[i] or S[x+i] == "?"):
                    match += 1
                else:
                    print("Entered!")
                    match = 0
                    break
            if (match >= maxmatch and match != 0):
                print("ENTERED")
                maxmatchloc = x
                maxmatch = match
        print('At x = ' + str(x) + ': maxmatchlocation is ' + str(maxmatchloc) + ' match is ' + str(match) + ' maxmatch is' + str(maxmatch))
    return maxmatchloc

S = input()
T = input()
code = S
if '?' in S:
    if (len(T) <= len(S)):
        startpoint = search(S,T)
        for x in range(len(S)):
            if (S[x] == '?'):
                code = code[:x] + 'a' + code[x+1:] 
        if(startpoint >= 0):
            code = code[:startpoint] + T + code[startpoint + len(T):]
            print(code)
        else:
            print('UNRESTORABLE')
    else:
        print('UNRESTORABLE')
else:
    print(S)

Submission status: Wrong Answer

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)

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: Wrong Answer

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)

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: Wrong Answer

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)
    
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]):
                        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')
else:
    print(S)

Submission status: Wrong Answer

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 '?' 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] or S[x+i] == '?'):
                        if (maxmatch == -1):
                            maxmatch = 0
                        match += 1
                    if (S[x+i] != T[i] and S[x+i] != '?'):
                        match = -1
                        break
                if (match == -1 and hasmatch == False):
                    continue
                #if match
                if (match >= maxmatch and match != -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: Wrong Answer

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 '?' 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] or S[x+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')
else:
    print(S)

Submission status: Wrong Answer

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 '?' 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]):
                        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')
else:
    print(S)

Submission status: Wrong Answer

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 = 0
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')