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_d=input()
t=input()
if len(s_d) < len(t):
    print("UNRESTORABLE")
    exit()
for i in range(len(s_d)-len(t),-1,-1):
    flag = True
    for j,k in zip(s_d[i:i+len(t)],t):
        if j != k:
            flag=False
            break
    if flag:
        s_d = s_d[:i]+t+s_d[i+len(t):]
        break
if not flag:
    for i in range(len(s_d) - len(t), -1, -1):
        flag = True
        for j, k in zip(s_d[i:i + len(t)], t):
            if j != "?" and j != k:
                flag = False
                break
        if flag:
            s_d = s_d[:i] + t + s_d[i + len(t):]
            print(flag)
            break
if not flag:
    print("UNRESTORABLE")
else:
    for i in s_d:
        if i == "?":
            print("a",end="")
        else:
            print(i,end="")

Submission status: Wrong Answer

Solution code:
s_d=input()
t=input()
if len(s_d) < len(t):
    print("UNRESTORABLE")
    exit()
for i in range(len(s_d)-len(t),-1,-1):
    flag = True
    for j,k in zip(s_d[i:i+len(t)],t):
        if j != "?" and j != k:
            flag=False
            break
    if flag:
        s_d = s_d[:i]+t+s_d[i+len(t)+1:]
        break
if not flag:
    print("UNRESTORABLE")
else:
    for i in s_d:
        if i == "?":
            print("a",end="")
        else:
            print(i,end="")

Submission status: Wrong Answer

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

i = len(S) - 1
ti = len(T) - 1
match = 0
flag = False
while 0 <= i:
    if S[i] == T[ti] or S[i] == '?':
        match += 1
        ti -= 1
    else:
        match = 0
        ti = len(T) - 1
    if match == len(T):
        k = 0
        for j in range(i, i + len(T)):
            S[j] = T[k]
            k += 1
        flag = True
        break
    i -= 1

# print(S)
# print(T)

if flag == True:
    for i in range(len(S)):
        if S[i] == '?':
            S[i] = 'a'
    print(''.join(S))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ls = len(s)
lt = len(t)
s = s[ls::-1]
t = t[lt::-1]
cnt = 0
idx = -1

for i in range(ls):
    if s[i] == t[cnt] or s[i] == "?":
        cnt += 1
    elif s[i] == t[0]:
        cnt = 1
    else:
        cnt = 0
        
    if cnt == lt:
        idx = i-lt+1
        break

if idx == -1:
    ans = "UNRESTORABLE"
else:
    r = s[:idx]+t+s[idx+lt:]
    ans = (r[ls::-1]).replace("?","a")

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ls = len(s)
lt = len(t)
s = s[ls::-1]
t = t[lt::-1]
cnt = 0
idx = -1

for i in range(ls):
    if s[i] == t[cnt] or s[i] == "?":
        cnt += 1
        if cnt == lt:
            idx = i-lt+1
            break
    elif s[i] == t[0]:
        cnt = 1
    else:
        cnt = 0

if idx == -1:
    ans = "UNRESTORABLE"
else:
    r = s[:idx]+t+s[idx+lt:]
    ans = (r[ls::-1]).replace("?","a")

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ls = len(s)
lt = len(t)
s = s[ls::-1]
t = t[lt::-1]
cnt = 0
idx = -1

for i in range(ls):
    if s[i] == t[cnt] or s[i] == "?":
        cnt += 1
        if cnt == lt:
            idx = i-lt+1
            break
    else:
        cnt = 0

if idx == -1:
    ans = "UNRESTORABLE"
else:
    r = s[:idx]+t+s[idx+lt:]
    ans = (r[ls::-1]).replace("?","a")

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import os
if sys.platform=="darwin":
	base = os.path.dirname(os.path.abspath(__file__))
	name = os.path.normpath(os.path.join(base, '../Documents/input.txt'))
	#print(name)
	sys.stdin = open(name)

def checkstr(i,j,s1,s2):
	#print(i,j)
	if j == len(s2):
		#print("yap")
		return True
	if s1[i]=="?" or s1[i]==s2[j]:
		if checkstr(i+1,j+1,s1,s2):
			return True
	else:
		return False

s1 = input()
s2 = input()

j=0

#print(len(s1),len(s2))

for i in range(len(s1)-len(s2),-1,-1):
	#print(i)
	if checkstr(i,j,s1,s2):
		#print("yah",i,j)
		s=s1[:i]+s2+s1[i+len(s2):]
		#print(s)
		print(s.replace('?', 'a'))
		exit()
	if i==0:
		print("UNRESTORABLE")

Submission status: Wrong Answer

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


flag = False
for i in range(len(s)-len(t)+1):
    count = 0
    for j in range(len(t)):
        if s[i+j] == t[j] or s[i+j] == '?':
            count += 1
        else:
            break
    if count == len(t):
        flag = True
        list_s = list(s)
        list_t = list(t)
        list_s[i:i+len(t)] = list_t
        s = ''.join(list_s).replace('?', 'a')
        break
if flag:
    print(s)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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


flag = False
for i in range(len(s)-len(t)+1):
    count = 0
    for j in range(len(t)):
        if s[i+j] == t[j] or s[i+j] == '?':
            count += 1
        else:
            break
    if count == len(t):
        flag = True
        list_s = list(s)
        list_t = list(t)
        list_s[i:i+len(t)] = list_t
        s = ''.join(list_s).replace('?', 'a')
if flag:
    print(s)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
# ABC076 C - Dubious Document 2
S=input()
T=input()
ls=len(S)
lt=len(T)

if lt>ls:
    print('UNRESTORABLE')
    exit()

if S.count(T)>0:
    S=S.replace('?','a')
    print(S)
    exit()

for i in range(ls-lt+1):
    NG_flg=False
    t_str=S[ls-lt-i:ls-i]
    for j,tt in enumerate(t_str):
        if tt==T[i:i+1] or tt=='?':
            pass
        else:
            NG_flg=True
            break
    if NG_flg==False:
        S=list(S)
        T=list(T)
        for k in range(lt):
            S[ls-lt-i+k:ls-lt-i+1+k]=T[k:k+1]
        break

if NG_flg==True:
    print('UNRESTORABLE')
    exit()

ans=''
for ss in S:
    ans+=ss
ans=ans.replace('?','a')

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
flag = False
tq = '?'*len(t)
start = []
for i in range(len(s)-len(t)+1):
    if s[i] == t[0]:
        start.append(i)
        for j in range(len(t)):
            if s[i+j] == t[j] or s[i+j] == '?':
                continue
            else:
                start.pop(-1)
                break
    if s[i:i+len(t)] == tq:
        start.append(i)
stal = []
if start:
    for i in start:
        stal.append(s[:i].replace('?','a') + t + s[i+len(t):].replace('?','a'))
    stal.sort()
    print(stal[0])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
flag = False
tq = '?'*len(t)
start = -1
for i in range(len(s)-len(t)+1):
    if s[i] == t[0]:
        start = i
        flag = True
        for j in range(len(t)):
            if s[i+j] == t[j] or s[i+j] == '?':
                continue
            else:
                flag = False
    if s[i:i+len(t)] == tq:
        start = max(start,i)
        flag = True

if flag:
    if start == 0:
        print(t + s[len(t):].replace('?','a'))
    else:
        print(s[:start].replace('?','a') + t + s[start+len(t):].replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
flag = False
for i in range(len(s)-len(t)+1):
    if s[i] == t[0]:
        start = i
        flag = True
        for j in range(len(t)):
            if s[i+j] == t[j] or s[i+j] == '?':
                continue
            else:
                flag = False
if flag:
    if start == 0:
        print(t + s[len(t):].replace('?','a'))
    else:
        print(s[:start].replace('?','a') + t + s[start+len(t):].replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:

def main():
  S_=input()
  T=input()
  ans=''
  if len(S_)<len(T):
    print('UNRESTORABLE')
    return
  for i in range(len(S_)-len(T)+1):
    flag=True
    for j in range(len(T)):
      if S_[i+j]!='?' and S_[i+j]!=T[j]:
        flag=False
        break
    if flag:
      S=['a']*len(S_)
      for k in range(i):
        if S_[k]!='?':
          S[k]=S_[k]
      for k in range(i,i+len(T)):
        S[k]=T[k-i]
      for k in range(i+len(T),len(S_)):
        if S[k]!='?':
          S[k]=S_[k]
      if ans=='':
        ans=''.join(S)
      elif ans>''.join(S):
        ans=''.join(S)
  if ans=='':
    print('UNRESTORABLE')
  else:
    print(ans)
  return

main()

Submission status: Wrong Answer

Solution code:

def main():
  S_=input()
  T=input()
  U=[]
  if len(S_)<len(T):
    print('UNRESTORABLE')
    return
  for i in range(len(S_)-len(T)+1):
    flag=True
    for j in range(len(T)):
      if S_[i+j]!='?' and S_[i+j]!=T[j]:
        flag=False
        break
    if flag:
      S=['a']*len(S_)
      for k in range(i):
        if S_[k]!='?':
          S[k]=S_[k]
      for k in range(i,i+len(T)):
        S[k]=T[k-i]
      for k in range(i+len(T),len(S_)):
        if S[k]!='?':
          S[k]=S_[k]
      U.append(''.join(S))
  if len(U)==0:
    print('UNRESTORABLE')
  else:
    print(sorted(U)[0])
  return

main()

Submission status: Wrong Answer

Solution code:

def main():
  S_=input()
  T=input()
  if len(S_)<len(T):
    print('UNRESTORABLE')
    return
  for i in range(len(S_)-len(T)+1):
    flag=True
    for j in range(len(T)):
      if S_[i+j]!='?' and S_[i+j]!=T[j]:
        flag=False
        break
    if flag:
      S=['a']*len(S_)
      for k in range(i):
        if S_[k]!='?':
          S[k]=S_[k]
      for k in range(i,i+len(T)):
        S[k]=T[k-i]
      for k in range(i+len(T),len(S_)):
        if S[k]!='?':
          S[k]=S_[k]
      print(''.join(S))
      return
  print('UNRESTORABLE')
  return

main()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc076/tasks/abc076_c

S_ = input()    # ?入りの文字
T = input()     # 部分文字列


len_S_ = len(S_)
len_T = len(T)

for i in reversed(range(len_S_)):
    S = ''

    if i + len_T <= len_S_:
        S = S_[:i] + T + S_[i + len_T:]

        # 残った「?」を全部aにする(条件2)
        for j in range(len(S)):
            if S[j] != S_[j] or S_[j] != '?':
                break

            if S[j] == '?':
                S = S[:j] + 'a' + S[j + 1:]

            if S.find('?') == -1 and len(S) != 0:
                print(S)
                exit()
        else:
            continue
    else:
        continue
        
print('UNRESTORABLE')

Submission status: Wrong Answer

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

S1 = S[::-1]
T1 = T[::-1]
count = 0
for i in range(len(S)-len(T)):
    count = 0

    for j in range(len(T1)):
        
        if S1[i+j] == "?" or S1[i+j] == T1[j]:
            

            count += 1

    
    if count == len(T1):
        
        for k in range(len(T1)):
            S1[k+i] = T1[k]
            
        S2 = S1[::-1]

        for i in S2:
            if i == "?":
                print("a",end="")
            else:
                print(i,end="")
        exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

if m > n:
    print('UNRESTORABLE')
    quit()
i = 0
while i < n-m+1:
    if (s[i] == t[0]) or (s[i] == '?'):
        j = i
        flg = True
        while j-i < m:
            if (s[j] == t[j-i]) or (s[j] == '?'):
                j += 1
            else:
                flg = False
                break
        if flg:
            j -= 1
            break
    i += 1
if not flg:
    print('UNRESTORABLE')
    quit()
ans = ''
cnt = 0
for k in range(n):
    if k < i:
        if s[k] == '?':
            ans += 'a'
        else:
            ans += s[k]
    elif i <= k <= j:
        ans += t[cnt]
        cnt += 1
    else:
        if s[k] == '?':
            ans += 'a'
        else:
            ans += s[k]
print(ans)

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

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

cnt = 0
for i in range(n-m+1):
    if s[i] == t[0]:
        cnt = 1
        flg = False
        while (s[i+cnt] == t[cnt]) or (s[i+cnt] == '?'):
            cnt += 1
            if cnt == m:
                flg = True
                break
        if flg:
            break
if cnt == 0:
    print('UNRESTORABLE')
    quit()
    
ans = ''
for j in range(n):
    if j < i:
        if s[j] == '?':
            ans += 'a'
        else:
            ans += s[j]
    elif j == i:
        ans += t
    elif i+cnt < j:
        if s[j] == '?':
            ans += 'a'
        else:
            ans += s[j]
print(ans)

Submission status: Wrong Answer

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    T=ST()
    N=len(S)
    M=len(T)
    ans = []
    for i in range(N-M+1)[::-1]:
        can = True
        for s,t in zip(S[i:],T):
            if s!=t and s!="?":
                can = False
        if can:
            for j,s in enumerate(S):
                if j<i:
                    if s=="?":
                        ans.append("a")
                    else:
                        ans.append(s)
                else:
                    if len(T)>j-i:
                        ans.append(T[j-i])
                    else:
                        ans.append(S[j])
            break
    if ans:
        print(*ans,sep="")
    else:
        print("UNRESTORABLE")
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def solve():
    S = list(input())
    ans = S[:]
    T = input()
    Sn = len(S)
    Tn = len(T)
    
    if Sn < Tn:
        print('UNRESTORABLE')
        exit()
    
    restorable = False
    for i in range(Sn - Tn, -1, -1):
        flag = True
        if S[i] == T[0]:
            for j in range(Tn):
                if S[i+j] != T[j] and S[i+j] != '?':
                    flag = False
                    break
            if flag:
                restorable = True
                for j in range(Tn):
                    ans[i+j] = T[j]
                break
    
    if not restorable:
        print('UNRESTORABLE')
    else:
        for i in range(Sn):
            if ans[i] == '?':
                ans[i] = 'a'
        print(''.join(ans))


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
def solve():
    S = list(input())
    ans = S[:]
    T = input()
    Sn = len(S)
    Tn = len(T)
    
    restorable = False
    for i in range(Sn - Tn, -1, -1):
        flag = True
        if S[i] == T[0]:
            for j in range(Tn):
                if S[i+j] != T[j] and S[i+j] != '?':
                    flag = False
                    break
            if flag:
                restorable = True
                for j in range(Tn):
                    ans[i+j] = T[j]
                break
    
    if not restorable:
        print('UNRESTORABLE')
    else:
        for i in range(Sn):
            if ans[i] == '?':
                ans[i] = 'a'
        print(''.join(ans))


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:

from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations
import sys
import bisect
import string
import math
import time
from fractions import gcd
#import random


def I(): return int(input())


def MI(): return map(int, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


YN = ['Yes', 'No']
MOD = 10**9+7
inf = float('inf')
IINF = 10**19
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)


# show_flg = False
show_flg = True


def main():
    S = input()
    T = input()
    canditates = []

    for i in range(len(S)):
        if S[i] == T[0]:
            idx = 1
            for j in range(i+1, len(S)):
                if idx < len(T) and (S[j] == T[idx] or S[j] == '?'):
                    idx += 1
                else:
                    break

            # print(idx, S, len(T))
            if idx == len(T):
                canditates.append(S[:i] + T + S[i+len(T):])

    if len(canditates) > 0:
        canditates = [c.replace("?", "a") for c in canditates]
        canditates.sort()
        print(canditates[0])
    else:
        print("UNRESTORABLE")

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
ind = 0
w = ""
if T in S:
  if "?" not in S:
    print(S)
  else:
    for i in range(len(S)):
      if S[i] == "?":
        ans = S.replace("?", "a")
    print(ans)
else:
  for i in range(len(S)):
    if S[i] == "?" or S[i] == T[ind]:
      ind += 1
      if ind == len(T):
        w += T
        for j in range(i+1,len(S)):
          w += S[j]
        break
    else:
      for k in range(ind, 0 , -1):
        w += S[i-k]
      ind = 0
      if S[i] == T[ind]:
        ind += 1
        continue
      w += S[i]
  if ind < len(T):
    print("UNRESTORABLE")
  else:
    if "?" not in w:
      print(w)
    else:
      for i in range(len(w)):
        if w[i] == "?":
          ans = w.replace("?", "a")
      print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
ind = 0
w = ""
if T in S:
  if "?" not in S:
    print(S)
  else:
    for i in range(len(S)):
      if S[i] == "?":
        ans = S.replace("?", "a")
    print(ans)
  exit()
for i in range(len(S)):
  if S[i] == "?" or S[i] == T[ind]:
    ind += 1
    if ind == len(T):
      w += T
      for j in range(i+1,len(S)):
        w += S[j]
      break
  else:
    for k in range(ind, 0 , -1):
      w += S[i-k]
    ind = 0
    w += S[i]
if ind < len(T):
  print("UNRESTORABLE")
else:
  if "?" not in w:
    print(w)
  else:
    for i in range(len(w)):
      if w[i] == "?":
        ans = w.replace("?", "a")
    print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
ind = 0
w = ""
if len(S) < len(T):
  print("UNRESTORABLE")
  exit()
for i in range(len(S)):
  if S[i] == "?" or S[i] == T[ind]:
    ind += 1
    if ind == len(T):
      w += T
      for j in range(i+1,len(S)):
        w += S[j]
      break
  else:
    for k in range(ind, 0 , -1):
      w += S[i-k]
    ind = 0
    w += S[i]
if ind < len(T):
  print("UNRESTORABLE")
else:
  if "?" not in w:
    print(w)
  else:
    for i in range(len(w)):
      if w[i] == "?":
        ans = w.replace("?", "a")
    print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
ind = 0
w = ""
if len(S) < len(T):
  print("UNRESTORABLE")
  exit()
for i in range(len(S)):
  if S[i] == "?" or S[i] == T[ind]:
    ind += 1
    if ind == len(T):
      w += T
      for j in range(i+1,len(S)):
        w += S[j]
      break
  else:
    for k in range(ind, 0 , -1):
      w += S[i-k]
    ind = 0
    w += S[i]
if ind < len(T):
  print("UNRESTORABLE")
else:
  print(w)
  if "?" not in w:
    print(w)
  else:
    for i in range(len(w)):
      if w[i] == "?":
        ans = w.replace("?", "a")
    print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
ind = 0
w = ""
for i in range(len(S)):
  if S[i] == "?" or S[i] == T[ind]:
    ind += 1
    if ind == len(T):
      w += T
      for j in range(i+1,len(S)):
        w += S[j]
      break
  else:
    for k in range(ind, 0 , -1):
      w += S[i-k]
    ind = 0
    w += S[i]
if ind < len(T):
  print("UNRESTORABLE")
else:
  if "?" not in w:
    print(w)
  else:
    for i in range(len(w)):
      if w[i] == "?":
        ans = w.replace("?", "a")
    print(ans)

Submission status: Wrong Answer

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

ans = "UNRESTORABLE"

i = 0

if len(s) >= len(t):
    while i < len(s)-len(t)+1:
        flag = False
        if s[i] == t[0] or s[i] == "?":
            for j in range(1,len(t)):
                if s[i+j] == "?" or s[i+j] == t[j]:
                    flag = True
                else:
                    flag = False
                    break
            if flag:
                tmps = ""
                k = 0
                while k < len(s):
                    if k < i or k >= i+len(t):
                        if s[k] == "?":
                            tmps += "a"
                            k += 1
                        else:
                            tmps += s[k]
                            k += 1
                    else:
                        tmps += t
                        k += len(t)
                ans = tmps
        i += 1

print(ans)

Submission status: Wrong Answer

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

ans = "UNRESTORABLE"

i = 0

while i < len(s)-len(t)+1:
    flag = False
    if s[i] == t[0] or s[i] == "?":
        for j in range(1,len(t)):
            if s[i+j] == "?" or s[i+j] == t[j]:
                flag = True
            else:
                flag = False
                break
        if flag:
            tmps = ""
            k = 0
            while k < len(s):
                if k < i or k >= i+len(t):
                    if s[k] == "?":
                        tmps += "a"
                        k += 1
                    else:
                        tmps += s[k]
                        k += 1
                else:
                    tmps += t
                    k += len(t)
            ans = tmps
    i += 1

print(ans)

Submission status: Wrong Answer

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

ans = "UNRESTORABLE"

anls = []

i = 0

while i < len(s)-len(t)+1:
    flag = False
    if s[i] == t[0] or s[i] == "?":
        for j in range(1,len(t)):
            if s[i+j] == "?" or s[i+j] == t[j]:
                flag = True
            else:
                flag = False
                break
        if flag:
            tmps = ""
            k = 0
            while k < len(s):
                if k < i or k >= i+len(t):
                    if s[k] == "?":
                        tmps += "a"
                        k += 1
                    else:
                        tmps += s[k]
                        k += 1
                else:
                    tmps += t
                    k += len(t)
            anls.append(tmps)
    i += 1

anls.sort()

if len(anls) == 0:
    print(ans)
else:
    print(anls[0])

Submission status: Wrong Answer

Solution code:
import sys
import re



def check(Sda, T, Slen, Tlen):
    matarr=[]
    endarr=[]

    getS = 'UNRESTORABLE'

    if(Slen<Tlen):
        return getS

    for i in reversed(range(0, Slen-Tlen+1)):


        mat = re.match(Sda[i:i+Tlen],T)
        try:
            if(mat.group() == T):
                matarr.append(Sda[:i]+T+Sda[i+Tlen:])

        except AttributeError:
            pass

        mat = 'None'

    if(matarr != []):
        print(matarr)
        for x in matarr:
            x = x.replace('.', 'a')
            endarr.append(x)

        getS = min(endarr)

    return getS



def main():
    Sda = input()
    T = input()
    Slen = len(Sda)
    Tlen = len(T)

    Sda = Sda.replace('?', '.')

    print(check(Sda, T, Slen, Tlen))


main()

Submission status: Wrong Answer

Solution code:
import sys
import re



def check(Sda, T, Slen, Tlen):
    matarr=[]
    getS = 'UNRESTORABLE'

    if(Slen<Tlen):
        return getS

    for i in reversed(range(0, Slen-Tlen+1)):


        mat = re.match(Sda[i:i+Tlen],T)
        try:
            if(mat.group() == T):
                matarr.append(Sda[:i]+T+Sda[i+Tlen+1:])

        except AttributeError:
            pass

        mat = 'None'

    if(matarr != []):
        mingetS = min(matarr)
        getS = mingetS.replace('.', 'a')

    return getS



def main():
    Sda = input()
    T = input()
    Slen = len(Sda)
    Tlen = len(T)

    Sda = Sda.replace('?', '.')

    print(check(Sda, T, Slen, Tlen))


main()

Submission status: Wrong Answer

Solution code:
import sys

s_prime, t = sys.stdin.read().split()
s = list(s_prime)
ls = len(s)
lt = len(t)

def main():
    ng = 'UNRESTORABLE'

    if ls < lt:
        return ng

    for i in range(ls-lt+1):
        t_prime = s[i:i+lt]
        for j in range(lt):
            letter = t_prime[j]
            if (letter != '?') and (letter != t[j]):
                break
        else:
            for j in range(lt):
                s[i+j] = t[j]
            break
    else:
        return ng
    
    ans = ''.join(s).replace('?', 'a')
    return ans
    
if __name__ == '__main__':
    ans = main()
    print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
ls=len(s)
lt=len(t)
if ls<lt:
    print('UNRESTORABLE')
    exit()
n=ls-lt+1
for i in range(n):
    tt='?'*i+t+'?'*(n-i-1)
    ans=''
    for j in range(ls):
        if tt[j]!='?':
            if tt[j]!=s[j] and s[j]!='?':
                break
            ans+=tt[j]
        else:
            if s[j]=='?':
                ans+='a'
            else:
                ans+=s[j]
    else:
        print(ans)
        break
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
s = ""
for i in range(len(S)):
  if T[0] == S[i] or S[i] == "?":
    cnt = 0
    for k in range(i+1, i+len(T)):
      if k >= len(S):
        break
      if S[k] == "?":
        cnt += 1
        if cnt == len(T)-1:
          s += T
      else:
        s += "a"
        break
    if S[i:i+len(T)] == T:
      s += T
  else:
    s += S[i]
if T in s:
  print(s)
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
result = ''
length = len(s)-len(t)
while length>=0:
  skip = False
  for i in range(len(t)):
    if s[length+i]!='?' and s[length+i]!=t[i]:
      skip = True
      break
  if skip==False:
    break
  length-=1
    
if length<0:
  print("UNRESTORABLE")
else:
  i = 0
  while i<len(s):
    if i==length:
      result+=t
      i+=len(t)
    else:
      if s[i]=='?':
        result+='a'
      else:
        result+=s[i]
    i+=1
  print(result)

Submission status: Wrong Answer

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

len_s = len(S)
len_t = len(T)

match = -1

for i in range((len_s - len_t), 0, -1):
    for j in range(len_t):
        if T[j] != S[i+j] and S[i+j] != "?":
            break

        if j == len_t-1:
            match = i

    if match != -1:
        break

if match == -1:
    print("UNRESTORABLE")
    exit()

list_s = list(S)

for i in range(match, match+len_t):
    list_s[i] = T[i - match]

list_s = [x if x != "?" else "a" for x in list_s]

print("".join(list_s))

Submission status: Wrong Answer

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

len_s = len(S)
len_t = len(T)

match = -1

for i in range((len_s - len_t), 0, -1):
    print("i", i)
    for j in range(len_t):
        if T[j] != S[i+j] and S[i+j] != "?":
            break

        if j == len_t-1:
            match = i

    if match != -1:
        break

if match == -1:
    print("UNRESTORABLE")
    exit()

list_s = list(S)

for i in range(match, match+len_t):
    list_s[i] = T[i - match]

list_s = [x if x != "?" else "a" for x in list_s]

print("".join(list_s))

Submission status: Wrong Answer

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

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

for i in range(n - m, -1, -1):
    t_kamo = sd[i:i + m]

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

print("UNRESTORABLE")

Submission status: Wrong Answer

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