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())
flag = False
for i in range(len(S)):
  for j in range(len(T)):
    if (i+j >= len(S)):
      flag = False
      break
    elif S[i+j]==T[j] or S[i+j] == "?":
      flag = True
    else:
      flag = False
      break
  if (flag):
    for k in range(len(T)):
      S[i+k] = T[k]
    break
if (flag):
  print("".join(S).replace("?","a"))
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

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

n = len(s)
m = len(t)

for i in range(n-m, -1, -1):
  if s[i] == t[0]:
    if all(s[i+j] == "?" or s[i+j] == t[j] for j in range(1,m)):
      s = s[:i]+t+s[i+m:]
      print(s.replace("?", "a"))
      exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
n, m = len(s), len(t)

for i in range(n - m, -1, -1):
    match = True
    for j in range(m):
        if s[i + j] == '?' or s[i + j] == t[j]:
            continue
        else:
            match = False
            break

    if match:
        ans = ""
        for j in range(i):
            if s[j] == '?':
                ans += 'a'
            else:
                ans += s[j]
        print(ans + t)
        exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

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

n = len(s)
m = len(t)

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

for i in range(n-m, -1, -1):
  if s[i] == t[0]:
    if all(s[i+j] == "?" or s[i+j] == t[j] for j in range(1,m)):
      s = s[:i]+t+s[:i+m]
      print(s.replace("?", "a"))
      exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

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

n = len(s)
m = len(t)
for i in range(n-m, -1, -1):
  if s[i] == t[0]:
    if all(s[j] == "?" for j in range(i+1, i+m)):
      s = s[:i]+t
      print(s.replace("?", "a"))
      exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:

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

if S.count("?") == len(S):
    print("a"*(len(S)-len(T))+T)
    exit(0)

for k in range(len(S)-len(T),-1,-1):
    f = 1
    c = 0
    for i in range(len(T)):
        if S[k+i] != "?":
            if S[k+i] != T[i]:
                f = 0
                break
            else:
                c += 1
    if f == 1 and c > 0:
        ans = ""
        for i in range(k):
            if S[i] == "?":
                ans += "a"
            else:
                ans += S[i]
        ans += T
        for i in range(k+len(T),len(S)):
            if S[i] == "?":
                ans += "a"
            else:
                ans += S[i]
        print(ans)
        exit(0)
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:

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

if S.count("?") == len(S):
    print("a"*(len(S)-len(T))+T)
    exit(0)

for k in range(len(S)-len(T)+1):
    f = 1
    c = 0
    for i in range(len(T)):
        if S[k+i] != "?":
            if S[k+i] != T[i]:
                f = 0
                break
            else:
                c += 1
    if f == 1 and c > 0:
        ans = ""
        for i in range(k):
            if S[i] == "?":
                ans += "a"
            else:
                ans += S[i]
        ans += T
        for i in range(k+len(T),len(S)):
            if S[i] == "?":
                ans += "a"
            else:
                ans += S[i]
        print(ans)
        exit(0)
print("UNRESTORABLE")

Submission status: Wrong Answer

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


def main():
    s_dash = input()
    t = input()
    s_count = len(s_dash)
    t_count = len(t)

    if t_count > s_count:
        print('UNRESTORABLE')

    for i in range(s_count - t_count + 1):
        si = s_dash[i:i + t_count]

        count = 0

        for sj, tj in zip(si, t):
            if sj == '?':
                count += 1
            elif sj == tj:
                count += 1

        if count == t_count:
            s = s_dash[:i] + t + s_dash[i + count:]
            print(s.replace('?', 'a'))
            exit()

    print('UNRESTORABLE')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


def main():
    s_dash = input()
    t = input()
    s_count = len(s_dash)
    t_count = len(t)

    for i in range(s_count - t_count + 1):
        si = s_dash[i:i + t_count]

        count = 0

        for sj, tj in zip(si, t):
            if sj == '?':
                count += 1
            elif sj == tj:
                count += 1

        if count == t_count:
            s = s_dash[:i] + t + s_dash[i + count:]
            print(s.replace('?', 'a'))
            exit()

    print('UNRESTORABLE')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ls = len(s)
lt = len(t)

if ls < lt:
    print('UNRESTORABLE')
    exit()
for i in range(ls-lt+1):
    flag = True
    for j in range(lt):
        if s[i+j] != '?' and s[i+j] != t[j]:
            flag = False
    if flag:
        x = s[:i] + t + s[i+lt:]
        print(x.replace('?','a'))
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s,t=input(),input()
for i in range(len(s)-len(t)+1):
  judge = True
  for j in range(len(t)):
    if not (s[i+j]==t[j] or s[i+j]=='?'):
      judge = False
    if not judge:
      break
  else:
    r=['a' if i=='?' else i for i in s[:i]]
    print(''.join(r)+t)
    exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
for i in range((len(s))-(len(t)),-1,-1):
    for j in range(len(t)):
        if s[i+j] == "?":
            continue
        if s[i+j] != t[j]:
            break
    else:
        for k in range(len(t)):
            s[i+k] = t[k]
        for l in range(len(s)):
            if s[l] == "?":
                s[l] = "a"
        print("".join(s))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S,T = open(0).read().split()
S = list(S)
T = list(T)
S_l = len(S)
T_l = len(T)
N = ''
for i in range(S_l-T_l,-1,-1):
    flag = True
    for p,k in enumerate(T):
        if k!=S[p+i] and S[p+i]!='?':
            flag = False
    if flag:
        for j,t in enumerate(S):
            if i<=j<i+T_l:
                N+=T[j-i]
            elif t == '?':N+='a'
            else:N+=t
if N:print(N)
else:print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S_dash  =   list(input())
len_s   =   len(S_dash)
T       =   list(input())
len_t   =   len(T)

if len_s < len_t:
    print('UNRESTORABLE')
else:
    flag_i = 0
    # if flag_i = 1, it means restorable. if not, unrestorable
    for i in range( len_s - len_t + 1 ):
        flag_j = 0
        # if flag_j = 1 , it means unrestorable
        check_s = S_dash[ len_s - len_t - i : len_s - i ]
        for j in range( len_t ):
            if ( check_s[j] != '?' and check_s[j] != T[j] ):
                flag_j = 1
                break
        if flag_j == 0:
            flag_i = 1
            break
    if flag_i == 0:
        print('UNRESTORABLE')
    else:
        S_dash[ len_s - len_t - i : len_s - i ] = T
        for i in range( len_s ):
            if S_dash[i] == '?':
                S_dash[i] = 'a'
        print(S_dash)

Submission status: Wrong Answer

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

len_S = len(S_dash)
len_T = len(T)

candidate0 = list(S_dash)


ans = "z"*51

if len_S >= len_T:
  for s in range(len_S):
    cha_S = S_dash[s]
    if cha_S != "?" and cha_S in list(T):
      for t in range(len_T):
        cha_T = T[t]
        if cha_S == cha_T and 0<= s-t < len_S and  0< s-t+len_T <= len_S:
          S_cut = S_dash[s-t:s-t+len_T]
          
          candidate1 = copy.deepcopy(candidate0)
          
          for x in range(len_T):
            if S_cut[x] == "?":
              candidate1[s-t+x] = T[x]
            elif  S_cut[x] != T[x]:
              break
          
          else:
            if "".join(candidate1[s-t:s-t+len_T]) == T:
              if ans > "".join(candidate1).replace('?', 'a'):
                ans = "".join(candidate1).replace('?', 'a')
                
if ans == "z"*51:
  ans = "UNRESTORABLE"
print(ans)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
S = list(input())
T = list(input())
s_num = len(S)
t_num = len(T)
S_copy = deepcopy(S)
if s_num < t_num:
  print('UNRESTORABLE')
else:
  for i in range(s_num-t_num, -1, -1):
    s_key = S[i:i+t_num]
    judge = 0
    for s, t in zip(s_key, T):
      if s=='?':
        judge += 1
      elif s == t:
        judge += 1
    if judge == t_num:
      S_copy[i:i+t_num] = T
      break
  if S == S_copy:
    print('UNRESTORABLE')
  else:
    for i in S_copy:
      if i == '?':
        print('a', end='')
      else:
        print(i, end='')

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
S = list(input())
T = list(input())
s_num = len(S)
t_num = len(T)
S_copy = deepcopy(S)
if s_num < t_num:
  print('UNRESTORABLE')
else:
  for i in range(s_num-t_num, -1, -1):
    s_key = S[i:i+t_num]
    judge = 0
    for s, t in zip(s_key, T):
      if s=='?':
        judge += 1
      elif s == t:
        judge += 1
    if judge == t_num:
      S_copy[i:i+t_num] = T
  if S == S_copy:
    print('UNRESTORABLE')
  else:
    for i in S_copy:
      if i == '?':
        print('a', end='')
      else:
        print(i, end='')

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
S = list(input())
T = list(input())
s_num = len(S)
t_num = len(T)
S_copy = deepcopy(S)
for i in range(s_num-t_num, -1, -1):
  s_key = S[i:i+t_num]
  judge = 0
  for s, t in zip(s_key, T):
    if s=='?':
      judge += 1
    elif s == t:
      judge += 1
  if judge == t_num:
    S_copy[i:i+t_num] = T
if S == S_copy:
  print('UNRESTORABLE')
else:
  for i in S_copy:
    if i == '?':
      print('a', end='')
    else:
      print(i, end='')

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
ns = len(s)
nt = len(t)
start = -1
for i in range(nt):
    for j in range(ns):
        if t[i] == s[j] or s[j] == '?':
            j_temp = j - i
            if j_temp < 0:
                continue
            if t[i] != s[j_temp] and s[j_temp] != '?':
                continue
            i_temp = 0
            is_ok = True
            while i_temp < nt:
                i_temp += 1
                j_temp += 1
                if j_temp >= ns:
                    is_ok = False
                    break
                if s[j_temp] == '?' or s[j_temp] == t[i_temp]:
                    if i_temp == nt - 1:
                        break
                    continue
                if s[j_temp] != t[i_temp]:
                    is_ok = False
                    break
            if is_ok:
                start = max(j, start)
ans = ""
if start == -1:
    print("UNRESTORABLE")
    exit()
for i in range(ns):
    if start <= i < start + nt:
        ans += t[i - start]
    elif s[i] == "?":
        ans += "a"
    else:
        ans += s[i]
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
ns = len(s)
nt = len(t)
start = -1
for i in range(nt):
    for j in range(ns):
        if t[i] == s[j] or s[j] == '?':
            j_temp = j - i
            if j_temp < 0:
                continue
            if t[i] != s[j_temp] and s[j_temp] != '?':
                continue
            i_temp = 0
            is_ok = True
            while i_temp < nt:
                i_temp += 1
                j_temp += 1
                if j_temp >= ns:
                    is_ok = False
                    break
                if s[j_temp] == '?' or s[j_temp] == t[i_temp]:
                    if i_temp == nt - 1:
                        break
                    continue
                if s[j_temp] != t[i_temp]:
                    is_ok = False
                    break
            if is_ok:
                start = j
ans = ""
if start == -1:
    print("UNRESTORABLE")
    exit()
for i in range(ns):
    if start <= i < start + nt:
        ans += t[i - start]
    elif s[i] == "?":
        ans += "a"
    else:
        ans += s[i]
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
ns = len(s)
nt = len(t)
start = -1
for j in range(ns):
    if t[0] == s[j] or s[j] == '?':
        i = 0
        j_temp = j
        is_ok = True
        while i < nt:
            i += 1
            j_temp += 1
            if j_temp >= ns:
                is_ok = False
                break
            if s[j_temp] == '?' or s[j_temp] == t[i]:
                if i == nt - 1:
                    break
                continue
            if s[j_temp] != t[i]:
                is_ok = False
                break
        if is_ok:
            start = j
ans = ""
if start == -1:
    print("UNRESTORABLE")
    exit()
for i in range(ns):
    if start <= i < start + nt:
        ans += t[i - start]
    elif s[i] == "?":
        ans += "a"
    else:
        ans += s[i]
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
ns = len(s)
nt = len(t)
start = -1
for j in range(ns):
    if t[0] == s[j] or s[j] == '?':
        i = 0
        j_temp = j
        is_ok = True
        while i < nt:
            i += 1
            j_temp += 1
            if j_temp >= ns:
                is_ok = False
                break
            if s[j_temp] == '?' or s[j_temp] == t[i]:
                if i == nt - 1:
                    break
                continue
            if s[j_temp] != t[i]:
                is_ok = False
                break
        if is_ok:
            start = j
ans = ""
if start == -1:
    print("UNRESTORABLE")
    exit()
for i in range(ns):
    if start <= i < start + nt:
        ans += t[i - start]
    elif s[i] == "?":
        ans += "a"
    else:
        ans += s[i]
print(start)
print(ans)

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
w = "UNRESTORABLE"
for i in range(len(s)-len(t)+1):
    num = 0
    for h in range(len(t)):
        if s[i+h] == t[h] or s[i+h] == '?':
            num += 1
        elif s[i+h] != t[h]:
            break
    if num == len(t):
        w2 = s[0:i] + t
        w = ""
        for j in range(len(w2)):
            if w2[j] == "?":
                w += "a"
            else:
                w += w2[j]
print(w)

Submission status: Wrong Answer

Solution code:
c=input()
t=input()
lic=list(c)
lit=list(t)
ans=[]
lia=[]
n=len(c)-len(t)
End=False
for i in range(n+1):
    hantei=True
    s='?'*i+t+'?'*(n-i)
    lis=list(s)
    for j in range(len(c)): 
        p=lic[j]
        q=lis[j]
        a=(p==q)
        if a==False and (p!='?' and q!='?'):
            hantei = False
            break
    if hantei == True:
        End = True
        ans=lis
        
    if End==True:
        for i in range(len(c)):
            if lic[i]=='?':
                lic[i]=ans[i]
        for i in range(len(c)):
            if lic[i]=='?':
                lic[i]='a'
        
        lia.append(''.join(lic))

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

Submission status: Wrong Answer

Solution code:
c=input()
t=input()
lic=list(c)
lit=list(t)
ans=[]
lia=[]
n=len(c)-len(t)
End=False
for i in range(n+1):
    hantei=True
    s='?'*i+t+'?'*(n-i)
    lis=list(s)
    for j in range(len(c)): 
        p=lic[j]
        q=lis[j]
        a=(p==q)
        if a==False and (p!='?' and q!='?'):
            hantei = False
            break
    if hantei == True:
        End = True
        ans=lis
        
    if End==True:
        for i in range(len(c)):
            if lic[i]=='?':
                lic[i]=ans[i]
        for i in range(len(c)):
            if lic[i]=='?':
                lic[i]='a'
        
        lia.append(''.join(lic))
        sorted(lia)
        print(lia[0])
if len(lia)==0:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
c=input()
t=input()
lic=list(c)
lit=list(t)
ans=[]
n=len(c)-len(t)
End=False
for i in range(n+1):
    if End == True:
        break
    hantei=True
    s='?'*i+t+'?'*(n-i)
    lis=list(s)
    for j in range(len(c)): 
        p=lic[j]
        q=lis[j]
        a=(p==q)
        if a==False and (p!='?' and q!='?'):
            hantei = False
            break
    if hantei == True:
        End = True
        ans=lis
        
if End==True:
    for i in range(len(c)):
      if lic[i]=='?':
          lic[i]=ans[i]
    for i in range(len(c)):
      if lic[i]=='?':
          lic[i]='a'
    print(''.join(lic))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
ans = ''
for i in range(len(S)):
  flag = True
  if S[i] == "?" or S[i] == T[0]:
    tmp = S[i:i+len(T)]
    if len(tmp) != len(T):
      continue
    for j in range(len(T)):
      if tmp[j] != '?' and T[j] != tmp[j]:
        flag = False
        break
    if flag:
      ans = S[:i] + T
      for i in range(len(ans)):
        if ans[i] == '?':
          ans[i] = 'a'

if ans != '':
  print(''.join(ans))
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
s = input()
t = input()
num0, num1 = len(s), len(t)

if num0 < num1:
    print('UNRESTORABLE')
elif len(s) == 1:
    if s == '?' or s == t:
        print(t)
    else:
        print('UNRESTORABLE')
else:
    for i in range(num0-num1, 0, -1):
        for j in range(num1):
            if s[i+j] != t[j] and s[i+j] != '?':
                break
            elif j == num1-1:
                ans = s[:i]+t+s[i+num1:]
                ans = ans.replace('?', 'a')
                print(ans)
                sys.exit()
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
s = input()
t = input()
num0, num1 = len(s), len(t)

if num0 < num1:
    print('UNRESTORABLE')
else:
    for i in range(num0-num1, 0, -1):
        for j in range(num1):
            if s[i+j] != t[j] and s[i+j] != '?':
                break
            elif j == num1-1:
                ans = s[:i]+t+s[i+num1:]
                ans = ans.replace('?', 'a')
                print(ans)
                sys.exit()
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
s = input()
t = input()
num0, num1 = len(s), len(t)

if num0 < num1:
    print('UNRESTORABLE')
else:
    for i in range(num0-num1+1):
        for j in range(num1):
            if s[i+j] != t[j] and s[i+j] != '?':
                break
            elif j == num1-1:
                ans = s[:i]+t+s[i+num1:]
                ans = ans.replace('?', 'a')
                print(ans)
                sys.exit()
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import re
S=input().replace("?", ".")
T=input()
ans=[]
moji = len(T)
for i in range(len(S)-len(T)+1):
  m = re.search(S[i:moji+i], T)
  if m is not None:
    ans.append((S[0:i] + T + S[i+moji:-1]).replace(".", "a"))

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

Submission status: Wrong Answer

Solution code:
import re
S=input().replace("?", ".")
T=input()
ans=[]
moji = len(T)
for i in range(len(S)-len(T)+1):
  m = re.search(S[i:moji+i], T)
  if m is not None:
    ans.append((S[0:i] + T + S[i+moji-1:-1]).replace(".", "a"))

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

Submission status: Wrong Answer

Solution code:
import re
S=input().replace("?", ".")
T=input()
ans=""
moji = len(T)
for i in range(len(S)-len(T)+1):
  m = re.search(S[i:moji+i], T)
  if m is not None:
    ans = S[0:i] + T + S[i+moji-1:-1]
    ans = ans.replace(".", "a")

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

Submission status: Wrong Answer

Solution code:
import re
S=input().replace("?", ".")
T=input()
ans=""
moji = len(T)
for i in range(len(S)-len(T)+1):
  m = re.search(S[i:moji+i], T)
  if m is not None:
    ans = S[0:i] + T + S[i+moji-1:-1]
    ans = ans.replace(".", "a")

if ans:
  print(ans)
else:
  print("UNRESTORABLE1")

Submission status: Wrong Answer

Solution code:
import re
S=input().replace("?", ".")
T=input()
ans=""
moji = len(T)
for i in range(len(S)-len(T)+1):
  m = re.search(S[i:moji+i], T)
  if m is not None:
    ans = S[0:i] + T + S[i+moji-1:-1]
    ans = ans.replace(".", "a")
    break

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

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
ans = ["UNRESTORABLE"]

if "?" not in set(s):
    print("".join(s))

for i in range(ls-lt+1):
    f = True
    for j in range(lt):
        f &= (s[i + j] == "?" or s[i + j] == t[j])

    if f:
        ans = s.copy()
        for j in range(lt):
            ans[i+j] = t[j]


print("".join(ans).replace("?", "a"))

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
ans = ["UNRESTORABLE"]

if len(set(s)) == 1 and s[0] == "?":
    ans = (["a"] * (ls - lt))
    ans.extend(t)
    print("".join(ans))
    exit()

if "?" not in set(s):
    print("".join(s))
    exit()

for i in range(ls):
    if s[i] != "?":
        for j in reversed(range(lt)):
            if 0 <= i+j+lt <= ls or 0 <= i-j+lt <= ls:
                if t[j] == s[i]:
                    f = True
                    for k in range(lt):
                        f &= (s[i - j + k] == "?" or s[i - j + k] == t[k])
                    if f:
                        ans = s.copy()
                        for l in range(lt):
                            ans[i - j + l] = t[l]


print("".join(ans).replace("?", "a"))

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
ans = ["UNRESTORABLE"]
for i in range(len(s)):
    if s[i] != "?":
        for j in reversed(range(len(t))):
            if 0 <= i+j+len(t) <= len(s) or 0 <= i-j+len(t) <= len(s):
                if t[j] == s[i]:
                    f = True
                    for k in range(len(t)):
                        f &= (s[i - j + k] == "?" or s[i - j + k] == t[k])
                    if f:
                        ans = s.copy()
                        for l in range(len(t)):
                            ans[i - j + l] = t[l]


print("".join(ans).replace("?", "a"))

Submission status: Wrong Answer

Solution code:
import re
S=input().replace("?", ".")
T=input()
ans=""
moji = len(T)
for i in range(len(S)-len(T)+1):
  m = re.search(S[i:moji+i], T)
  if m is not None:
    ans = S[0:i] + T + S[i+moji-1:-1]
    ans = ans.replace(".", "a")

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

Submission status: Wrong Answer

Solution code:
import re
S=input().replace("?", ".")
T=input()
ans=""
moji = len(T)
for i in range(len(S)-len(T)+1):
  m = re.search(S[i:moji+i], T)
  if m is not None:
    ans = S[0:i] + T + S[i+len(T):-1]
    ans = ans.replace(".", "a")

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

Submission status: Wrong Answer

Solution code:
no="UNRESTORABLE"

s=input()
t=input()
ans=list(s[:])
hatena=[ s[i]=="?" for i in range(len(s))]

left=0 ; right=len(s)
while right>=len(t):
    for i in range(right-len(t), right):
        if s[i]!="?" and s[i]!=t[i-right+len(t)]:
            break
    else:
        # hatena[right-len(t):right]=[i*2 for i in hatena[right-len(t):right]]
        ans[right-len(t):right]=list(t) ; 
        break
    right-=1



# for i in range(len(hatena)):
#     if i==0:
#         s+=s[i]
#     elif i==1:
#         s+="a"
if ans==list(s) and s!=t :print(no);exit()
print( ("".join(ans)).replace("?","a") )

Submission status: Wrong Answer

Solution code:
no="UNRESTORABLE"

s=input()
t=input()
ans=list(s[:])
hatena=[ s[i]=="?" for i in range(len(s))]

left=0 ; right=len(s)
while right>=len(t):
    for i in range(right-len(t), right):
        if s[i]!="?" and s[i]!=t[i-right+len(t)]:
            break
    else:
        # hatena[right-len(t):right]=[i*2 for i in hatena[right-len(t):right]]
        ans[right-len(t):right]=list(t) ; 
        break
    right-=1



# for i in range(len(hatena)):
#     if i==0:
#         s+=s[i]
#     elif i==1:
#         s+="a"
if ans==list(s):print(no);exit()
print( ("".join(ans)).replace("?","a") )

Submission status: Wrong Answer

Solution code:
no="UNRESTORABLE"

s=input()
t=input()
ans=list(s[:])
hatena=[ s[i]=="?" for i in range(len(s))]

left=0 ; right=len(t)
while right<=len(s):
    for i in range(right-len(t), right):
        if s[i]!="?" and s[i]!=t[i-right+len(t)]:
            break
    else:
        # hatena[right-len(t):right]=[i*2 for i in hatena[right-len(t):right]]
        ans[right-len(t):right]=list(t) ; 
        break
    right+=1



# for i in range(len(hatena)):
#     if i==0:
#         s+=s[i]
#     elif i==1:
#         s+="a"
if ans==list(s):print(no);exit()
print( ("".join(ans)).replace("?","a") )

Submission status: Wrong Answer

Solution code:
S = input().strip()
T = input().strip()
ans = "UNRESTORABLE"
for i in range(len(S)-len(T), -1, -1):
    ok = True
    for j in range(len(T)):
        if not (S[i+j] == '?' or S[i+j] == T[j]):
            ok = False

    if ok:
        a = S[:i]+T
        a = a.replace("?", "a")
        if ans == "UNRESTORABLE" or a < ans:
            ans = a
print(ans)

Submission status: Wrong Answer

Solution code:
S = input().strip()
T = input().strip()
ans = []
for i in range(len(S)-len(T), -1, -1):
    ok = True
    for j in range(len(T)):
        if not (S[i+j] == '?' or S[i+j] == T[j]):
            ok = False

    if ok:
        a = S[:i]+T
        a = a.replace("?", "a")
        ans.append(a)

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

Submission status: Wrong Answer

Solution code:
S = input().strip()
T = input().strip()
ans = "UNRESTORABLE"
for i in range(len(S)-len(T), -1, -1):
    ok = True
    for j in range(len(T)):
        if not (S[i+j] == '?' or S[i+j] == T[j]):
            ok = False

    if ok:
        ans = S[:i]+T
        ans = ans.replace("?", "a")
        break
print(ans)

Submission status: Wrong Answer

Solution code:

def main():
        
    S_part = list(input())
    T_hint = list(input())

    N = len(S_part)
    ans = []

    for i in range(N):
        index_init = i
        
        if (index_init + len(T_hint) <= N):
            s = S_part[index_init:index_init + len(T_hint)]

            if ('?' in s):
                FLAG = True
                
                for j in range(len(s)):
                    if (T_hint[j] != s[j] and s[j] == '?'):
                        s[j] = T_hint[j]
                    
                    elif (T_hint[j] != s[j] and s[j] != '?'):
                        FLAG = False
                        break
                
                
                if (FLAG):
                    ans_left = ''.join(S_part[:index_init])
                    ans_right = ''.join(s)
                    
                    tmp_ans = ans_left + ans_right
                    tmp_ans = tmp_ans.replace('?', 'a')

                    if (index_init + len(T_hint) < N):
                        module = S_part[index_init + len(T_hint):]
                        module = ''.join(module)
                        module = module.replace('?', 'a')
                        
                        tmp_ans += module


                    ans.append(tmp_ans)

    ans.sort()

    if (S_part.count('?') == 0 and T_hint in S_part):
        print(''.join(S_part))
    
    elif (len(ans) > 0):
        print(ans[0])
    
    else:
        print('UNRESTORABLE')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
        
    S_part = list(input())
    T_hint = list(input())

    N = len(S_part)
    ans = []

    for i in range(N):
        index_init = i
        
        if (index_init + len(T_hint) <= N):
            s = S_part[index_init:index_init + len(T_hint)]

            if ('?' in s):
                FLAG = True
                
                for j in range(len(s)):
                    if (T_hint[j] != s[j] and s[j] == '?'):
                        s[j] = T_hint[j]
                    
                    elif (T_hint[j] != s[j] and s[j] != '?'):
                        FLAG = False
                        break
                
                
                if (FLAG):
                    ans_left = ''.join(S_part[:index_init])
                    ans_right = ''.join(s)
                    
                    tmp_ans = ans_left + ans_right
                    tmp_ans = tmp_ans.replace('?', 'a')

                    if (index_init + len(T_hint) < N):
                        module = S_part[index_init + len(T_hint):]
                        module = ''.join(module)
                        module = module.replace('?', 'a')
                        
                        tmp_ans += module


                    ans.append(tmp_ans)

    ans.sort()

    if (S_part.count('?') == 0 and T_hint in S_part):
        print(S_part)
    
    elif (len(ans) > 0):
        print(ans[0])
    
    else:
        print('UNRESTORABLE')


if __name__ == '__main__':
    main()