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:
import sys
s = input()
t = input()
ns = len(s)
nt = len(t)

if ns < nt:
    print("UNRESTORABLE")
else:
    for i in range(ns - nt + 1):
        if all([s[i + j] == "?" or s[i + j] == t[j] for j in range(nt)]):
            ans = s[:i] + t + s[i + nt:]
            ans = ans.replace("?", "a")
            print(ans)
            sys.exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ns = len(s)
nt = len(t)

if ns < nt:
    print("UNRESTORABLE")
else:
    for i in range(ns - nt + 1):
        if all([s[i + j] == "?" or s[i + j] == t[j] for j in range(nt)]):
            ans = s[:i] + t + s[i + nt:]
            ans = ans.replace("?", "a")
            print(ans)
            exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)


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

if s == "":
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)



cnt = 0
for i in range(n - m + 1):
    cnt = 0
    for j in range(m):
      if s_dash[i + j] == t[j] or s_dash[i+j] == "?":
        cnt += 1
      else:
        break
    if cnt == m:
      s = s_dash[:i] + t + s_dash[i+m:]
      s = s.replace("?","a")
      print(s)
      exit()
      """
      ans = list(s_dash)
      ans[i:i+m] = list(t)
      ans = "".join(ans).replace("?", "a")
      print(ans)
      exit()
      """
      
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)


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

for i in range(n - m + 1):
    flag = True
    for j in range(m):
      if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
        flag = False
        break
    if flag:
      ans = list(s_dash)
      ans[i:i+m] = list(t)
      ans = "".join(ans).replace("?", "a")
      print(ans)
      exit()
      
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)

for i in range(n - m + 1):
    flag = True
    for j in range(m):
      if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
        flag = False
        break
    if flag:
      ans = list(s_dash)
      ans[i:i+m] = list(t)
      ans = "".join(ans).replace("?", "a")
      print(ans)
      exit()
      
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)

for i in range(n - m + 1):

    for j in range(m):
      if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
        flag = False
        break
    else:
      ans = list(s_dash)
      ans[i:i+m] = list(t)
      ans = "".join(ans).replace("?", "a")
      print(ans)
      exit()
      
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)

for i in range(n - m + 1):
    flag = True
    for j in range(m):
      if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
        flag = False
        break
    if flag:
      ans = list(s_dash)
      ans[i:i+m] = list(t)
      ans = "".join(ans).replace("?", "a")
      print(ans)
      exit()
      
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)


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


for i in range(n - m + 1):
    flag = True
    for j in range(m):
        if s_dash[i+j] != '?' and s_dash[i+j] != t[j]:
            flag = False
            break
    if flag:
    #範囲外をaに置き換える
      s_dash = list(s_dash)
      s_dash[i:i+m] = list(t)
      s_dash = "".join(s_dash).replace("?", "a")
      print(s_dash)
      exit()
        
      
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)


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


for i in range(n - m + 1):
    flag = True
    for j in range(m):
        if s_dash[i+j] != '?' and s_dash[i+j] != t[j]:
            flag = False
            break
    if flag:
    #範囲外をaに置き換える
      ans = list(s_dash)
      ans[i:i+m] = list(t)
      ans = "".join(ans).replace("?", "a")
      print(ans)
      exit()
        
      
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)


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


for i in range(n-m+1):
  flag = True
  for j in range(m):
    if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:

      flag = False
      break

  if flag:
    #範囲外をaに置き換える
    ans = list(s_dash)
    ans[i:i+m] = list(t)
    ans = "".join(ans).replace("?", "a")
    print(ans)
    exit()
        
      
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)


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

ans = []
for i in range(n-m+1):
  flag = True
  for j in range(m):
    if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:

      flag = False
      break

  if flag:
    #範囲外をaに置き換える
    ans.append(s_dash[:i].replace("?", "a") + t + s_dash[i+m:].replace("?", "a"))
    ans.sort()
    print(ans[0])
    #print("".join(ans))
    exit()
        
      
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)


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

ans = []
for i in range(n - m + 1):
    flag = True
    for j in range(m):
        if s_dash[i+j] != '?' and s_dash[i+j] != t[j]:
            flag = False
            break
    if flag:
        ans.append(s_dash[:i].replace('?', 'a') + t + s_dash[i+m:].replace('?', 'a'))
    print("".join(ans))
    exit()
        
      
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)


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

ans = []
for i in range(n-m+1):
  flag = True
  for j in range(m):
    if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
      flag = False
      break

  if flag:
    #範囲外をaに置き換える
    ans.append(s_dash[:i].replace("?", "a") + t + s_dash[i+m:].replace("?", "a"))
    #ans.append(s_dash[:i].replace('?', 'a') + t + s_dash[i+m:].replace('?', 'a'))
    print("".join(ans))
    exit()
        
      
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s_dash = input()
t = input()
n = len(s_dash)
m = len(t)


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

ans = []
for i in range(n-m+1):
  flag = True
  for j in range(m):
    if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
      flag = False
      break

  if flag:
    #範囲外をaに置き換える
    ans.append(s_dash[:i].replace("?", "a") + t + s_dash[i+m:].replace("?", "a"))
    ans.append(s_dash[:i].replace('?', 'a') + t + s_dash[i+m:].replace('?', 'a'))
    print("".join(ans))
    exit()
        
      
print("UNRESTORABLE")

Submission status: Wrong Answer

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


ans = []
for i in range(len(s_dash)-len(t)+1):
  flag = True
  for j in range(len(t)):
    if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
      flag = False
      break

  if flag:
    #範囲外をaに置き換える
    ans.append(s_dash[:i].replace("?", "a") + t + s_dash[i+len(t):].replace("?", "a"))
    print("".join(ans))
    exit()
        
      
print("UNRESTORABLE")

Submission status: Wrong Answer

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


ans = []
for i in range(len(s_dash)-len(t)+1):
  cnt = 0
  for j in range(len(t)):
    if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
      cnt = 0
      break
    else:
      cnt += 1
      continue
  if cnt == len(t):
    #範囲外をaに置き換える
    ans.append(s_dash[:i].replace("?", "a") + t + s_dash[i+len(t):].replace("?", "a"))
    print("".join(ans))
    exit()
        
      
print("UNRESTORABLE")

Submission status: Wrong Answer

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

cnt = 0
ans = []
for i in range(len(s_dash)-len(t)+1):
  cnt = 0
  for j in range(len(t)):
    if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
      cnt = 0
      break
    else:
      cnt += 1
  if cnt == len(t):
    #範囲外をaに置き換える
    ans.append(s_dash[:i].replace("?", "a") + t + s_dash[i+len(t):].replace("?", "a"))
    print("".join(ans))
    exit()
        
      
print("UNRESTORABLE")

Submission status: Wrong Answer

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

flag = True
ans = []
for i in range(len(s_dash)-len(t)+1):
  flag = True
  for j in range(len(t)):
    if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
      cnt = 0
      break

  if flag:
    #範囲外をaに置き換える
    ans.append(s_dash[:i].replace("?", "a") + t + s_dash[i+len(t):].replace("?", "a"))
    print("".join(ans))
    exit()
        
      
print("UNRESTORABLE")

Submission status: Wrong Answer

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

cnt = 0
ans = []
for i in range(len(s_dash)-len(t)+1):
  for j in range(len(t)):
    if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
      cnt = 0
      break
    else:
      cnt += 1
    if cnt == len(t):
      #範囲外をaに置き換える
      ans.append(s_dash[:i].replace("?", "a") + t + s_dash[i+len(t):].replace("?", "a"))
      print("".join(ans))
      exit()
        
      
print("UNRESTORABLE")

Submission status: Wrong Answer

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

cnt = 0
ans = []
for i in range(len(s_dash)-len(t)+1):
  cnt = 0
  for j in range(len(t)):
    if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
      cnt = 0
      break
    else:
      cnt += 1
    if cnt == len(t):
      #範囲外をaに置き換える
      ans.append(s_dash[:i].replace("?", "a") + t + s_dash[i+len(t):].replace("?", "a"))
      print("".join(ans))
      exit()
        
      
print("UNRESTORABLE")

Submission status: Wrong Answer

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

cnt = 0
ans = []
for i in range(len(s_dash)-len(t)+1):
  cnt = 0
  for j in range(len(t)):
    if s_dash[i+j] != "?" and s_dash[i+j] != t[j]:
      cnt = 0
      break
    elif s_dash[i+j] == t[j] or s_dash[i+j] == "?":
      cnt += 1
    if cnt == len(t):
      #範囲外をaに置き換える
      ans.append(s_dash[:i].replace("?", "a") + t + s_dash[i+len(t):].replace("?", "a"))
      print("".join(ans))
      exit()
        
      
print("UNRESTORABLE")

Submission status: Wrong Answer

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

LS = len(S)
LT = len(T)
bb = False
SSS = []
for i in range(LS - LT + 1):
  f = LS - LT - i
  b = True
  for j in range(LT):
    if S[f+j] != '?':
      if S[f+j] != T[j]:
        b = False
  if b:
    s = S[:]
    s[f:f+LT+1] = T
    s = ''.join(s).replace('?', 'a')
    SSS += [s]
    bb = True

if bb:
  print(min(SSS))
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

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

LS = len(S)
LT = len(T)
bb = False
SSS = []
for i in range(LS - LT + 1):
  f = LS - LT - i
  b = True
  for j in range(LT):
    if S[f+j] != '?':
      if S[f+j] != T[j]:
        b = False
  if b:
    s = S[:]
    s[f:f+LT+1] = T
    s = ''.join(S).replace('?', 'a')
    SSS += [s]
    bb = True

if bb:
  print(min(SSS))
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

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

LS = len(S)
LT = len(T)
bb = False
for i in range(LS - LT + 1):
  f = LS - LT - i
  b = True
  for j in range(LT):
    if S[f+j] != '?':
      if S[f+j] != T[j]:
        b = False
  if b:
    S[f:f+LT+1] = T
    bb = True
    break
if bb:
  print(''.join(S).replace('?', 'a'))
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    return

#B
def B():
    return

#C
def C():
    s = S()
    t = S()
    s = s[::-1]
    t = t[::-1]
    ans = (0,0)
    anslis = deque()
    for i in range(len(s)):
        for j in range(len(t)):
            if 0 <= i + j < len(s) and (s[i + j] == t[j] or s[i + j] == "?"):
                continue
            break
        else:
            ans = (i, i + j)
            break
    if ans == (0,0):
        print("UNRESTORABLE")
        return
    else:
        for num in range(len(s)):
            i = s[num]
            if ans[0] <= num <= ans[1]:
                i = t[num-ans[0]]
            anslis.appendleft(i)
    for i in anslis:
        if i == "?":
            print("a", end="")
        else:
            print(i, end="")
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


#A
"""
r = I()
g = I()
print(2*g-r)
"""

#B
"""
n = I()
k = I()
ans = 1
for i in range(n):
    ans = min(ans * 2, ans + k)
print(ans)
"""



    


#D
"""
n = I()
t = LI()
v = LI()
"""
if __name__ == "__main__":
    C()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
import itertools
sys.setrecursionlimit(10**5)
stdin = sys.stdin
bisect_left = bisect.bisect_left
bisect_right = bisect.bisect_right
def LI(): return list(map(int, stdin.readline().split()))
def LF(): return list(map(float, stdin.readline().split()))
def LI_(): return list(map(lambda x: int(x)-1, stdin.readline().split()))
def II(): return int(stdin.readline())
def IF(): return float(stdin.readline())
def LS(): return list(map(list, stdin.readline().split()))
def S(): return list(stdin.readline().rstrip())
def IR(n): return [II() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def FR(n): return [IF() for _ in range(n)]
def LFR(n): return [LI() for _ in range(n)]
def LIR_(n): return [LI_() for _ in range(n)]
def SR(n): return [S() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
mod = 1000000007
inf = float('INF')

#A
def A():
    return

#B
def B():
    return

#C
def C():
    s = S()
    t = S()
    s = s[::-1]
    t = t[::-1]
    ans = (0,0)
    anslis = deque()
    for i in range(len(s)):
        for j in range(len(t)):
            if 0 <= i + j < len(s) and (s[i + j] == t[j] or s[i + j] == "?"):
                continue
            break
        else:
            ans = (i, i + j)
    if ans == (0,0):
        print("UNRESTORABLE")
        return
    else:
        for num in range(len(s)):
            i = s[num]
            if ans[0] <= num <= ans[1]:
                i = t[num-ans[0]]
            anslis.appendleft(i)
    for i in anslis:
        if i == "?":
            print("a", end="")
        else:
            print(i, end="")
    return

#D
def D():
    return

#E
def E():
    return

#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == '__main__':
    A()


#A
"""
r = I()
g = I()
print(2*g-r)
"""

#B
"""
n = I()
k = I()
ans = 1
for i in range(n):
    ans = min(ans * 2, ans + k)
print(ans)
"""



    


#D
"""
n = I()
t = LI()
v = LI()
"""
if __name__ == "__main__":
    C()

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import itertools
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
"""
r = I()
g = I()
print(2*g-r)
"""

#B
"""
n = I()
k = I()
ans = 1
for i in range(n):
    ans = min(ans * 2, ans + k)
print(ans)
"""

#C
from collections import deque
s = S()
t = S()
s = s[::-1]
t = t[::-1]
ans = (0,0)
anslis = deque()
for i in range(len(s)):
    for j in range(len(t)):
        if 0 <= i + j < len(s) and (s[i + j] == t[j] or s[i + j] == "?"):
           continue
        break
    else:
        ans = (i, i + j)
if ans == (0,0):
    print("UNRESTORABLE")
else:
    for num in range(len(s)):
        i = s[num]
        if ans[0] <= num <= ans[1]:
            i = t[num-ans[0]]
        anslis.appendleft(i)
for i in anslis:
    if i == "?":
        print("a", end="")
    else:
        print(i, end="")

    


#D
"""
n = I()
t = LI()
v = LI()
"""

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
t = len(T)
ind = -1
for i in range(len(S) - t+1):
    for j, s in enumerate(S[i:i+t]):
        if s == '?':
            continue
        if s != T[j]:
            break
    else:
        ind = i
        break
if ind == -1:
    print('UNRESTORABLE')
else:
    ans = ''
    for i, s in enumerate(S):
        if i == ind:
            ans += T
        elif ind < i < ind + t:
            continue
        elif s == '?':
            ans += 'a'
        else:
            ans += s
    print(ans)

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

S = input()
T = input()
if len(S) < len(T):
    print('UNRESTORABLE')
    exit()
for sidx, s in enumerate(S):
    #  print('sidx,s', sidx, s)
    # どこから始めるかで考える
    if sidx + len(T) > len(S):
        print('UNRESTORABLE')
        exit()
    for tidx, t in enumerate(T):
        #  print('tidx, t', tidx, t)
        if S[sidx+tidx] == '?':
            continue
        if t != S[sidx+tidx]:
            # 一致しない場合はこれではない
            break
    else:
        # 鍵発見
        #  print('sidx', sidx)
        ans = S[:sidx] + T
        if sidx + len(T) < len(S):
            ans += S[sidx+len(T):]
        ans = ans.replace('?', 'a')
        print(ans)
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

S = input()
T = input()

for sidx, s in enumerate(S):
    #  print('sidx,s', sidx, s)
    # どこから始めるかで考える
    if sidx + len(T) > len(S):
        print('UNRESTORABLE')
        exit()
    for tidx, t in enumerate(T):
        #  print('tidx, t', tidx, t)
        if S[sidx+tidx] == '?':
            continue
        if t != S[sidx+tidx]:
            # 一致しない場合はこれではない
            break
    else:
        # 鍵発見
        #  print('sidx', sidx)
        ans = S[:sidx] + T
        if sidx + len(T) < len(S):
            ans += S[sidx+len(T):]
        ans = ans.replace('?', 'a')
        print(ans)
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

S = input()
T = input()

for sidx, s in enumerate(S):
    #  print('sidx,s', sidx, s)
    # どこから始めるかで考える
    if sidx + len(T) > len(S):
        print('UNRESTORABLE')
        exit()
    for tidx, t in enumerate(T):
        #  print('tidx, t', tidx, t)
        if S[sidx+tidx] == '?':
            continue
        if t != S[sidx+tidx]:
            # 一致しない場合はこれではない
            break
    else:
        # 鍵発見
        #  print('sidx', sidx)
        ans = S[:sidx] + T + S[sidx+len(T)+1:]
        ans = ans.replace('?', 'a')
        print(ans)
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

S = input()
T = input()

for sidx, s in enumerate(S):
    #  print('sidx,s', sidx, s)
    # どこから始めるかで考える
    if sidx + len(T) > len(S):
        print('UNRESTORABLE')
        exit()
    for tidx, t in enumerate(T):
        #  print('tidx, t', tidx, t)
        if S[sidx+tidx] == '?':
            continue
        if t != S[sidx+tidx]:
            # 一致しない場合はこれではない
            break
    else:
        # 鍵発見
        #  print('sidx', sidx)
        ans = S[:sidx] + T + S[sidx+len(T):]
        ans = ans.replace('?', 'a')
        print(ans)
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import math, string, itertools, fractions, heapq, collections, re,  array, bisect, sys, random, time, copy, functools
sys.setrecursionlimit(10**7)
inf = 10 ** 20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1, 0), (0, 1), (1, 0), (0, -1)]
ddn = [(-1, 0), (-1, 1), (0, 1), (1, 1), (1, 0), (1, -1), (0, -1), (-1, -1)]
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def _F(): return float(sys.stdin.readline())
def _pf(s): return print(s, flush=True)

S = input()
T = input()

for sidx, s in enumerate(S[:-1]):
    #  print('sidx,s', sidx, s)
    # どこから始めるかで考える
    if sidx + len(T) > len(S):
        print('UNRESTORABLE')
        exit()
    for tidx, t in enumerate(T):
        #  print('tidx, t', tidx, t)
        if S[sidx+tidx] == '?':
            continue
        if t != S[sidx+tidx]:
            # 一致しない場合はこれではない
            break
    else:
        # 鍵発見
        #  print('sidx', sidx)
        ans = S[:sidx] + T + S[sidx+len(T):]
        ans = ans.replace('?', 'a')
        print(ans)
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

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

s = list(input())
t = list(input())

slen = len(s)
tlen = len(t)

cand = []
for i in range(slen - tlen + 1):
    match = True
    for j in range(tlen):
        if s[i + j] == "?" or s[i + j] == t[j]:
            pass
        else:
            match = False
    if match:
        cand.append(i)

if len(cand) != 0:
    cand.reverse()
    ans = ""
    for i in range(slen):
        if not (cand[0] <= i < cand[0] + tlen):
            if s[i] == "?":
                ans += "a"
            else:
                ans += s[i]
        else:
            print(ans)
            ans += t[i - cand[0]]
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

Sd = Sd[::-1]
T = T[::-1]
flg = False
for s in range(len(Sd) - len(T)+1):
    # print(Sd[s:s + len(T)])
    cnt = 0
    for t in range(len(T)):
        # print(Sd[s+t:s + t+1], T[t])
        if Sd[s+t:s + t+1] == T[t] or Sd[s+t:s + t+1] == "?":
            cnt += 1
        else:
            continue
    if cnt == len(T):
        S = Sd.replace(Sd[s:s + len(T)], T, 1)
        S = S.replace("?", "a")
        print(S[::-1])
        flg = True

if flg is False:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

#Sd = Sd[::-1]
#T = T[::-1]
flg = False
for s in range(len(Sd) - len(T)+1):
    # print(Sd[s:s + len(T)])
    cnt = 0
    for t in range(len(T)):
        # print(Sd[s+t:s + t+1], T[t])
        if Sd[s+t:s + t+1] == T[t] or Sd[s+t:s + t+1] == "?":
            cnt += 1
        else:
            continue
    if cnt == len(T):
        S = Sd.replace(Sd[s:s + len(T)], T, 1)
        S = S.replace("?", "a")
        print(S)
        flg = True

if flg is False:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

Sd = Sd[::-1]
T = T[::-1]
flg = False
for s in range(len(Sd) - len(T)+1):
    # print(Sd[s:s + len(T)])
    cnt = 0
    for t in range(len(T)):
        # print(Sd[s+t:s + t+1], T[t])
        if Sd[s+t:s + t+1] == T[t] or Sd[s+t:s + t+1] == "?":
            cnt += 1
        else:
            continue
    if cnt == len(T):
        S = Sd.replace(Sd[s:s + len(T)], T)
        S = S.replace("?", "a", 1)
        print(S[::-1])
        flg = True

if flg is False:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
Sd = input()
T = input()
flg = False
for s in range(len(Sd) - len(T)+1):
    # print(Sd[s:s + len(T)])
    cnt = 0
    for t in range(len(T)):
        # print(Sd[s+t:s + t+1], T[t])
        if Sd[s+t:s + t+1] == T[t] or Sd[s+t:s + t+1] == "?":
            cnt += 1
        else:
            continue
    if cnt == len(T):
        S = Sd.replace(Sd[s:s + len(T)], T)
        S = S.replace("?", "a", 1)
        print(S)
        flg = True

if flg is False:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
Sd = input()
T = input()
flg = False
for s in range(len(Sd) - len(T)+1):
    # print(Sd[s:s + len(T)])
    cnt = 0
    for t in range(len(T)):
        # print(Sd[s+t:s + t+1], T[t])
        if Sd[s+t:s + t+1] == T[t] or Sd[s+t:s + t+1] == "?":
            cnt += 1
        else:
            continue
    if cnt == len(T):
        S = Sd.replace(Sd[s:s + len(T)], T)
        S = S.replace("?", "a")
        print(S)
        flg = True

if flg is False:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
Sd = input()
T = input()
flg = False
for s in range(len(Sd) - len(T)+1):
    # print(Sd[s:s + len(T)])
    cnt = 0
    for t in range(len(T)):
        # print(Sd[s+t:s + t+1], T[t])
        if Sd[s+t:s + t+1] == T[t] or Sd[s+t:s + t+1] == "?":
            cnt += 1
        else:
            continue
    if cnt == len(T):
        S = Sd.replace(Sd[s:s + len(T)], T)
        S = S.replace("?", "a")
        print(S)
        flag = True

if flg is False:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

for s in range(len(Sd) - len(T)+1):
    # print(Sd[s:s + len(T)])
    cnt = 0
    for t in range(len(T)):
        # print(Sd[s+t:s + t+1], T[t])
        if Sd[s+t:s + t+1] == T[t] or Sd[s+t:s + t+1] == "?":
            cnt += 1
        else:
            continue
    if cnt == len(T):
        S = Sd.replace(Sd[s:s + len(T)], T)
        S = S.replace("?", "a")
        print(S)
        exit(0)
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
i = len(S) - 1
j = len(T) - 1
start_T = 100
while i >= 0:
	if S[i] == T[j] or S[i] == "?":
		j -= 1
		i -= 1

		if j == -1:
			start_T = i + 1
			break
	else:
		j = len(T) - 1
		i -= 1

if start_T == 100:
	ans = "UNRESTORABLE"
else:
	ans = ""
	k = 0
	while k < len(S):
		if k == start_T:
			for j in range(len(T)):
				ans += str(T[j])
			k += len(T)
		elif S[k] == "?":
			ans += "a"
			k += 1
		else:
			ans += str(S[k])
			k += 1
			
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
i = len(S) - 1
j = len(T) - 1
start_T = 100
while i >= 0:
	if S[i] == T[j] or S[i] == "?":
		j -= 1
		i -= 1

		if j == -1:
			start_T = i + 1
			break
	else:
		j = len(T) - 1
		i -= 1

if start_T == 100:
	ans = -1
else:
	ans = ""
	k = 0
	while k < len(S):
		if k == start_T:
			for j in range(len(T)):
				ans += str(T[j])
			k += len(T)
		elif S[k] == "?":
			ans += "a"
			k += 1
		else:
			ans += str(S[k])
			k += 1
			
print(ans)