Problem:


Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

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

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

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

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

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

Print the string S.

If such a string does not exist, print UNRESTORABLE.  

Constraints

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

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

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

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

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

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

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



Sample input:
?tc????
coder


Sample output:
atcoder

Submission status: Runtime Error

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

s=input()
t=input()

for i in range(len(s)-len(t)+1):
    flag=0
    n= len(s)-i-len(t)
    temp=s[n:n+len(t)]
    for j in range(len(t)):
        if temp[j]!=t[j] and temp[j]!="?":
            flag=1
    if flag==0:
        break

if flag==1:
    print("UNRESTORABLE")
    exit()
temp=s[:n]+t+s[n+len(t):]
print(temp.replace("?","a"))

Submission status: Runtime Error

Solution code:
s = input()
t = input()
ans = s
for i in range(len(t)):
    for j in range(len(s)):
        ans = list(s)
        flag = True
        if t[i] == s[j]:
            for k in range(i + 1, len(t)):
                if t[i + k] != s[j + k] and s[j + k] != "?":
                    flag = False
                    break
                ans[j + k] = t[i + k]
            for k in range(0, i):
                if t[i + k] != s[j + k] and s[j + k] != "?":
                    flag = False
                    break
                ans[j + k] = t[i + k]

            
            if flag == True:
                for i in range(len(ans)):
                    if ans[i] == "?":
                        ans[i] = "a"

                print("".join(ans))
                exit()

print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import sys  
import numpy as np

input = sys.stdin.readline

S_ = input()
T = input()

S_ = list(S_)[:-1]
T = list(T)[:-1]

for i in range(len(S_)-len(T)+1):
    if i==0:
        part = S_[-len(T):]
    else :
        part = S_[-len(T)-i:-i]
    j = False
    for k in range(len(part)-1,-1,-1):
        if part[k] == "?":
            if k==0:
                j = True
            continue
        elif part[k] == T[k]:
            if k==0:
                j = True
        else:
            break
    if j:
        break


if j:
    for p in range(len(T)):
        S_[len(S_)-len(T)-i+p] = T[p]
    # print("*",S_)
    for k in range(len(S_)):
        if S_[k] == "?":
            S_[k] = "a"

    print("".join(S_))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import sys  
import numpy as np

input = sys.stdin.readline

S_ = input()
T = input()

S_ = list(S_)[:-1]
T = list(T)[:-1]

for i in range(len(S_)-len(T)+1):
    part = S_[-len(T)-i:-i]
    j = False
    for k in range(len(part)-1,-1,-1):
        if part[k] == "?":
            if k==0:
                j = True
        elif part[k] == T[k]:
            if k==0:
                j = True

        else:

            break
    if j:
        break


if j:
    for p in range(len(T)):
        S_[len(S_)-len(T)-i+p] = T[p]
    # print("*",S_)
    for k in range(len(S_)):
        if S_[k] == "?":
            S_[k] = "a"

    print("".join(S_))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import sys  
import numpy as np

input = sys.stdin.readline

S_ = input()
T = input()

S_ = list(S_)[:-1]
T = list(T)[:-1]

for i in range(len(S_)-len(T)+1):
    part = S_[-len(T):]
    j = False
    for k in range(len(part)-1,-1,-1):
        if part[k] == "?":
            if k==0:
                j = True
        elif part[k] == T[k]:
            if k==0:
                j = True

        else:
            break
    if j:
        break


if j:
    for p in range(len(T)):
        S_[len(S_)-len(T)-i+p] = T[p]
    # print("*",S_)
    for k in range(len(S_)):
        if S_[k] == "?":
            S_[k] = "a"

    print("".join(S_))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import sys  
import numpy as np

input = sys.stdin.readline

S_ = input()
T = input()

S_ = list(S_)[:-1]
T = list(T)[:-1]

for i in range(len(S_)-len(T)+1):
    part = S_[-len(T):]
    j = False
    for k in range(len(part)-1,-1,-1):
        if part[k] == "?":
            continue
        elif part[k] == T[k]:
            if k==0:
                j = True

        else:
            break
    if j:
        break


if j:
    for p in range(len(T)):
        S_[len(S_)-len(T)-i+p] = T[p]
    # print("*",S_)
    for k in range(len(S_)):
        if S_[k] == "?":
            S_[k] = "a"

    print("".join(S_))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S_dash = list(input())
M = len(S_dash)

T = list(input())
N = len(T)

match = [False for _ in range(M)]

last_match = -100
for i in range(M - N + 1):
    for j in range(N):
        if S_dash[i+j] == "?":
            continue
        elif S_dash[i+j] == T[j]:
            continue
        elif S_dash[i+j] != T[j]:
            break
    else:
        match[i] = True
        last_match = i
S = S_dash.copy()

if last_match == -100:
    print("UNRESTORABLE")
else:
    for i in range(N):
        S[last_match+i] = T[i]
    for i in range(M):
        if S[i] == "?":
            S[i] = "a"
    print("".join(str(x) for x in (S)))

Submission status: Runtime Error

Solution code:
S_dash = list(input())
M = len(S_dash)

T = list(input())
N = len(T)

match = [False for _ in range(M)]

last_match = -100
for i in range(M - N + 1):
    for j in range(N):
        if S_dash[i+j] == "?":
            continue
        elif S_dash[i+j] == T[j]:
            continue
        elif S_dash[i+j] != T[j]:
            break
    else:
        match[i] = True
        last_match = i
S = S_dash.copy()

if last_match == -100:
    print("UNRESTORABLE")
else:
    for i in range(N):
        S[last_match+i] = T[i]
    for i in range(M):
        if S[i] == "?":
            S[i] = "a"
    print(s)

Submission status: Runtime Error

Solution code:
S = list(input())
T = list(input())
N = len(S)
M = len(T)
l = []
flag = 0
exist = 0
for i in range(N-M+1):
    flag = 0
    for j in range(M):
        if T[j] != S[i+j] and S[i+j] != "?":
            flag += 1

    if flag == 0:
        tmp = S.copy()
        for k in range(M):
            tmp[i+k] = T[k]
        l.append(tmp)
        exist = 1

a = []
if exist == 1: 
    L = len(l)
    for i in range(L):
        tmp = l[i].copy()
        for j in range(N):
            if tmp[j] == "?":
                tmp[j] = "a"
        a.append(tmp)
    a.sort()
    ans = "".join(a[0])
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

s = [x for x in s[::-1]]
t = [x for x in t[::-1]]    

for i in range(len(s)-len(t)):
  flg = False
  cnt = 0
  for j in range(len(t)):
    if s[i+j] == '?':
      cnt += 1
      continue
    if s[i+j] == t[j]:
      flg = True
    else:
      flg = False
      break
  if flg or cnt == len(t):
    s[i:i+len(t)] = t
    flg = True
    break

if not flg:
    print('UNRESTORABLE')
    exit()

ans = ''
s = [x for x in s[::-1]]
for i in range(len(s)):
  if s[i] == '?':
    s[i] = 'a'
  ans += s[i]
print(ans)

Submission status: Runtime Error

Solution code:
s=list(input())
t=list(input())
S,T=len(s),len(t)
t=t+['?']
if S<T:
  print('UNRESTORABLE')
  exit()
c,p=[0]*S,s[::-1]
for i in range(T+1):
  if t[i] in p:
    x=S-p.index(t[i])-1
    c[x-i]=1 if all(s[x-i+j]=='?' or s[x-i+j]==t[j] for j in range(T)) else 0
if max(c)==0:
  print('UNRESTORABLE')
  exit()
c=c[::-1]
x,j=S-c.index(1)-1,0
for i in range(S):
  if (i<x or i>x+T-1):
    s[i]='a' if s[i]=='?' else s[i]
  else:
    s[i],j=t[j],j+1
print(''.join(s))

Submission status: Runtime Error

Solution code:
s=list(input())
t=list(input())
a=-1

for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[j+i]!=t[j] and s[j+i]!='?':
            break
        if (s[j+i]==t[j] or s[j+i]=='?') and j==len(t)-1:
            a=i

if a<0:
    print('UNRESTORABLE')
else:
    for i in range(len(s)):
        if i>=a:
            s[i]=t[i-a]
        if s[i]=='?':
            s[i]='a'
    print(''.join(s))

Submission status: Runtime Error

Solution code:
s=list(input())
t=list(input())
a=-1

for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[j+i]!=t[j] and s[j+i]!='?':
            break
        if (s[j+i]=='?' or s[j+i]=='?') and j==len(t)-1:
            a=i

if a<0:
    print('UNRESTORABLE')
else:
    for i in range(len(s)):
        if i>=a:
            s[i]=t[i-a]
        if s[i]=='?':
            s[i]='a'
    print(''.join(s))

Submission status: Runtime Error

Solution code:
s=input()
t=input()
n=len(s)
m=len(t)
li=[]
for i in range(n-m+1):
  u=s[i:i+m]
  c=0
  for j in range(m):
    if u[j]!="?" and u[j]!=t[j]:
      c=1
      break
  if c==0:
    if i==0:
      v=t+s[i+m]
    elif i==n-m:
      v=s[:i]+t
    else:
      v=s[:i]+t+s[i+m]
    for k in range(n):
      if v[k]=="?":
        v=v[:k]+"a"+v[k+1:]
    li.append(v)
if li==[]:
  print("UNRESTORABLE")
else:
  li.sort()
  print(li[0])

Submission status: Runtime Error

Solution code:
=input()
t=input()
n=len(s)
m=len(t)
li=[]
for i in range(n-m+1):
  u=s[i:i+m]
  c=0
  for j in range(m):
    if u[j]!="?" and u[j]!=t[j]:
      c=1
      break
  if c==0:
    if i==0:
      v=t+s[i+m]
    elif i==n-m:
      v=s[:i]+t
    else:
      v=s[:i]+t+s[i+m]
    for k in range(n):
      if v[k]=="?":
        v=v[:k]+"a"+v[k+1:]
    li.append(v)
if li==[]:
  print("UNRESTORABLE")
else:
  li.sort()
  print(li[0])

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
import copy

S = list(input())
T = input()

ans = ''
for i in range(len(S)):
    if S[i] == T[0] or S[i] == '?':
        j = 0
        while S[i + j] == T[j] or S[i + j] == '?':
            #print(i, j)
            j += 1
            if i + j >= len(S):
                break
            if j == len(T) - 1 and (S[i + j] == T[j] or S[i + j] == '?'):
                #print(i, j, 'find')
                temp = copy.copy(S)
                for k in range(j + 1):
                    temp[i + k] = T[k]
                for i in range(len(S)):
                    if temp[i] == '?':
                        temp[i] = 'a'
                ans = temp
                break
if ans:
    #print(dct)
    print(''.join(ans))
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

sl = len(S)
tl = len(T)

for i in range(sl-tl+1):
    s = S[i:i+tl]
    flag = True
    for j in range(tl):
        if s[j] == '?':
            continue
        elif s[j] == T[j] and s[j] != '?':
            continue
            
        flag = False
        break
            
    if flag == True:
        ans = S[:i] + T + s[i+tl:]
        break
        
if flag == False:
    print('UNRESTORABLE')
else:
    print(ans.replace('?','a'))

Submission status: Runtime Error

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

sl = len(S)
tl = len(T)

for i in range(sl-tl+1):
    s = S[i:i+tl]
    flag = True
    for j in range(tl):
        if s[j] == T[j]:
            continue
        elif s[j] == '?':
            continue
        elif s[j] != T[j] and s[j] != '?':
            flag = False
            break
            
    if flag == True:
        ans = S[:i] + T + s[i+tl:]
        break
        
if flag == False:
    print('UNRESTORABLE')
else:
    print(ans.replace('?','a'))

Submission status: Runtime Error

Solution code:
S = input()
T = input()
#文字列判定
if len(S)<len(T):
    #TがSより長いとき、Tが入るSは見当たらない
    print("UNRESTORABLE")
#len(S) == len(T)のとき
elif len(S) == len(T):
    flag = 0
    #かぶったら加算をおこなうフラグ関数
    for i in range(len(S)):
        if S[i] == T[i] or S[i] == "?":
            continue
        else:
            print("UNRESTORABLE")
            flag += 1
    if flag == 0:
        print(T)
#len(S)<len(T)のとき
else:
    now = 0
    #現在の文字の位置を示すflag関数
    flag = 0
    #flag = 1のときTと一致しているかを判定中
    flag_2 = 0
    #TあるいはTに値する文字列が存在したとき1になる
    k_start = 0
    k_end = 0
    for i in range(len(S)):
        if S[i] == T[now]:
            if flag == 0:
                now += 1
                flag = 1
                k_start = i
            else:
                now += 1
        elif S[i] == "?":
            if flag == 1:
                now += 1
        else:
            now = 0
            flag = 0
        if now == len(T):
            flag_2 += 1
            k_end = i
            break
    if flag_2 == 0:
        print("UNRESTORABLE")
    else:
        ans = ""
        now_2 = 0
        #出力する文字列
        for i in range(len(S)):
            if k_start<=i<=k_end+1:
                ans += T[now_2]
                now_2 += 1
            elif S[i] == "?":
                ans += "a"
            else:
                ans += S[i]
        print(ans)

Submission status: Runtime Error

Solution code:
S = input()
T = input()
#文字列判定
if len(S)<len(T):
    #TがSより長いとき、Tが入るSは見当たらない
    print("UNRESTORABLE")
#len(S) == len(T)のとき
elif len(S) == len(T):
    flag = 0
    #かぶったら加算をおこなうフラグ関数
    for i in range(len(S)):
        if S[i] == T[i] or S[i] == "?":
            continue
        else:
            print("UNRESTORABLE")
            flag += 1
    if flag == 0:
        print(T)
#len(S)<len(T)のとき
else:
    now = 0
    #現在の文字の位置を示すflag関数
    flag = 0
    #flag = 1のときTと一致しているかを判定中
    flag_2 = 0
    #TあるいはTに値する文字列が存在したとき1になる
    k_start = 0
    k_end = 0
    for i in range(len(S)):
        if S[i] == T[now]:
            if flag == 0:
                now += 1
                flag = 1
                k_start = i
            else:
                now += 1
        elif S[i] == "?":
            if flag == 1:
                now += 1
        else:
            now = 0
            flag = 0
        if now == len(T)-1:
            flag_2 += 1
            k_end = i
            break
    if flag_2 == 0:
        print("UNRESTORABLE")
    else:
        ans = ""
        now_2 = 0
        #出力する文字列
        for i in range(len(S)):
            if k_start<=i<=k_end+1:
                ans += T[now_2]
                now_2 += 1
            elif S[i] == "?":
                ans += "a"
            else:
                ans += S[i]
        print(ans)

Submission status: Runtime Error

Solution code:
S = input()
T = input()
flag_1 = 0
now = 0
count = 0
position = 0
position_2 = 0
flag_2 = 0
flag_3 = 0
if len(S)<len(T):
    flag_3 += 1
for i in range(len(S)):
    if S[i] == T[now]:
        now += 1
        flag_1 = 1
        position = i
    elif S[i] == "?":
        count += 1
        if flag_1 == 0:
            position = i
            flag_1 = 1
        else:
            if count+now == len(T):
                flag_2 += 1
                position_2 = i
                break
    else:
        count = 0
        now = 0
if flag_2 == 0:
    print("UNRESTORABLE")
elif flag_3 == 1:
    print("UNRESTORABLE")
else:
    x = []
    y = []
    ans = ""
    now_2 = 0
    for i in range(len(S)):
        x.append(S[i])
    for j in range(len(T)):
        y.append(T[j])
    for i in range(len(x)):
        if position<=i<=position_2:
            x[i] = T[now_2]
            now_2 += 1
            ans += x[i]
        elif x[i] == "?":
            ans += "a"
        else:
            ans += x[i]
    print(ans)

Submission status: Runtime Error

Solution code:
S = input()
T = input()
flag_1 = 0
now = 0
count = 0
position = 0
position_2 = 0
flag_2 = 0
for i in range(len(S)):
    if S[i] == T[now]:
        now += 1
        flag_1 = 1
        position = i
    elif S[i] == "?":
        count += 1
        if flag_1 == 0:
            position = i
            flag_1 = 1
        else:
            if count+now == len(T):
                flag_2 += 1
                position_2 = i
                break
    else:
        count = 0
if flag_2 == 0:
    print("UNRESTORABLE")
else:
    x = []
    y = []
    ans = ""
    now_2 = 0
    for i in range(len(S)):
        x.append(S[i])
    for j in range(len(T)):
        y.append(T[j])
    for i in range(len(x)):
        if position<=i<=position_2:
            x[i] = T[now_2]
            now_2 += 1
            ans += x[i]
        elif x[i] == "?":
            ans += "a"
        else:
            ans += x[i]
    print(ans)

Submission status: Runtime Error

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

result = []
for i in range(len(s)-len(t)+1):
    temp = '?'*i + t + '?'*(len(s)-len(t)-i)
    
    ans = ''
    flag = True
    for j in range(len(s)):
        if s[j] == '?' or s[j] == temp[j]:
            ans += temp[j]
        elif s[j] != '?' and temp[j] == '?':
            ans += s[j]
        else:
            flag = False

    if flag:
        result.append(ans)

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

Submission status: Runtime Error

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

count = 0
n = 0
ans = []
flag = 0
while n <len(s)-len(t)+1:
    count = 0
    for m in range(len(t)):
        if s[n+m] == "?" or s[n+m]==t[m]:
            count += 1
    if count == len(t):
        flag = 1
        ans = s[0:n+m+1]
        break
    n += 1
#print(n,m)
if flag == 1:
    for i in range(n):
        if ans[i] == "?":
            ans[i] = "a"
    for i in range(m+1):
        ans[n+i] =t[i]
    for _ in ans:
        #print(*_,end="")
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
s=input().replace('\n', '')
t=input().replace('\n', '')
begin, end = len(s) - len(t), len(s)
ans=''
while begin>=0:
    origin = s[begin:end]
    flag=1
    for i in range(len(t)):
        if origin[i]!=t[i] and origin[i]!='?':
            flag=0
            break
    if flag:
        ans = s[:begin]+t+s[end:]
    begin-=1
    end-=1
print("UNRESTORABLE" if flag else ans.replace('?', 'a'))

Submission status: Runtime Error

Solution code:
s=input().replace('\n', '')
t=input().replace('\n', '')
begin, end = len(s) - len(t), len(s)
ans=''
while begin>=0:
    origin = s[begin:end]
    print(origin)
    flag=1
    for i in range(len(t)):
        if origin[i]!=t[i] and origin[i]!='?':
            flag=0
            break
    if flag:
        ans = s[:begin]+t+s[end:]
    begin-=1
    end-=1
print("UNRESTORABLE" if flag else ans.replace('?', 'a'))

Submission status: Runtime Error

Solution code:
from copy import deepcopy


aps_S = input()
T = input()

S = deepcopy(aps_S)

for i in range(len(aps_S) - len(T) + 1):
    matched_flag = True
    for j in range(len(T)):
        if aps_S[-i-j-1] != T[-j-1] and aps_S[i-j] != '?':
            matched_flag = False
            continue

    if matched_flag:
        S[-i-len(T)-1:-i-1] = T
        S = S.replace('?', 'a')
        print(S)
        break

if not matched_flag:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
import sys

s = input()
t = input()

tl = len(t) ; sl = len(s)

for i in range(sl,tl-1,-1) :
  st = s[i-tl:i]
  c = 0
  for j in range(tl) :
    if st[j] == '?' :
      continue
    elif st[j] != '?' and st[j] == t[j] :
      continue
    c = 1
    break
  if c == 0 :
    s = s[:i-tl] + t + s[i:]
    break

if c == 1 :
  print('UNRESTORABLE')
else : 
  print(s.replace('?', 'a'))

Submission status: Runtime Error

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

tl = len(t)
sl = len(s)
for i in range(sl,tl,-1) :
  st = s[i-tl:i]
  c = 0
  for j in range(tl) :
    if st[j] == '?' :
      continue
    elif st[j] != '?' and st[j] == t[j] :
      continue
    c = 1
    break
  if c == 0 :
    s = s[:i-tl] + t + s[i:]
    break

if c == 1 :
  print('UNRESTORABLE')
else : 
  print(s.replace('?', 'a'))

Submission status: Runtime Error

Solution code:
import re

s = input().replace('?', '.')
t = input()

for i in range(len(s)-len(t)+1):
  check_str = s[len(s)-len(t)-i:len(s)-i]
  if re.match(check_str, t):
    break

if i==len(s)-len(t):
  print('UNRESTORABLE')
else:
  ans = s[:len(s)-len(t)-i] + t + s[len(s)-i:]
  ans = ans.replace('.', 'a')
  print(ans)

Submission status: Runtime Error

Solution code:
# import sys
# readline = sys.stdin.buffer.readline

# from collections import deque
# from copy import copy,deepcopy
# from itertools import permutations,combinations
# from pprint import pprint

# def myinput():
#     return map(int,input().split())

# def mycol(data,col):
#     return [ row[col] for row in data ]

# def mysort(data,col):
#     data.sort(key=lambda x:x[col],reverse=False)
#     return data

s = input()
t = input()

for i in reversed(range(len(s)-len(t)+1)):
    flag = False
    for j in range(len(t)):
        if j==(len(t)-1):
            if s[i+j]=="?":
                flag = True
            elif s[i+j]==t[j]:
                flag = True
            else:
                flag = False
        elif s[i+j]=="?":
            pass
        elif s[i+j]==t[j]:
            pass
        else:
            flag = False
            break
    if flag:
        break
    else:
        continue

if flag:
    pass
else:
    print("UNRESTORABLE")
    exit()

ans = list(s)

for l in range(len(t)):
    ans[i+l] = t[l]

ans2 = "".join(ans)

# if "?" in ans2:
ans3 = ans2.replace("?","a")
print(ans3)

Submission status: Runtime Error

Solution code:
# import sys
# readline = sys.stdin.buffer.readline

# from collections import deque
# from copy import copy,deepcopy
# from itertools import permutations,combinations
# from pprint import pprint

# def myinput():
#     return map(int,input().split())

# def mycol(data,col):
#     return [ row[col] for row in data ]

# def mysort(data,col):
#     data.sort(key=lambda x:x[col],reverse=False)
#     return data

s = input()
t = input()

for i in reversed(range(len(s)-len(t)+1)):
    flag = False
    for j in range(len(t)):
        if j==(len(t)-1):
            if s[i+j]=="?":
                flag = True
            elif s[i+j]==t[j]:
                flag = True
            else:
                flag = False
        elif s[i+j]=="?":
            pass
        elif s[i+j]==t[j]:
            pass
        else:
            flag = False
            break
    if flag:
        break
    else:
        continue

if flag:
    pass
else:
    print("UNRESTORABLE")
    exit()

ans = list(s)

for l in range(len(t)):
    ans[i+l] = t[l]

ans2 = "".join(ans)

if "?" in ans2:
    ans3 = ans2.replace("?","a")
print(ans3)

Submission status: Runtime Error

Solution code:
# import sys
# readline = sys.stdin.buffer.readline

# from collections import deque
# from copy import copy,deepcopy
# from itertools import permutations,combinations
# from pprint import pprint

# def myinput():
#     return map(int,input().split())

# def mycol(data,col):
#     return [ row[col] for row in data ]

# def mysort(data,col):
#     data.sort(key=lambda x:x[col],reverse=False)
#     return data

s = input()
t = input()

for i in reversed(range(len(s)-len(t)+1)):
    flag = False
    for j in range(len(t)):
        if j==(len(t)-1):
            if s[i+j]=="?":
                flag = True
            elif s[i+j]==t[j]:
                flag = True
            else:
                flag = False
        elif s[i+j]=="?":
            pass
        elif s[i+j]==t[j]:
            pass
        else:
            flag = False
            break
    if flag:
        break
    else:
        continue

if flag:
    pass
else:
    print("UNRESTORABLE")
    exit()

ans = list(s)

for l in range(len(t)):
    ans[i+l] = t[l]

ans = "".join(ans)

if "?" in ans:
    ans2 = ans.replace("?","a")
print(ans2)

Submission status: Runtime Error

Solution code:
# import sys
# readline = sys.stdin.buffer.readline

# from collections import deque
# from copy import copy,deepcopy
# from itertools import permutations,combinations
# from pprint import pprint

# def myinput():
#     return map(int,input().split())

# def mycol(data,col):
#     return [ row[col] for row in data ]

# def mysort(data,col):
#     data.sort(key=lambda x:x[col],reverse=False)
#     return data

s = input()
t = input()

for i in reversed(range(len(s)-len(t)+1)):
    flag = False
    for j in range(len(t)):
        if j==(len(t)-1):
            if s[i+j]=="?":
                flag = True
            elif s[i+j]==t[j]:
                flag = True
            else:
                flag = False
        elif s[i+j]=="?":
            pass
        elif s[i+j]==t[j]:
            pass
        else:
            flag = False
            break
    if flag:
        break
    else:
        continue

if flag:
    pass
else:
    print("UNRESTORABLE")
    exit()

ans = list(s)

for l in range(len(t)):
    ans[i+l] = t[l]

ans = "".join(ans)

ans2 = ans.replace("?","a")
print(ans2)

Submission status: Runtime Error

Solution code:
# import sys
# readline = sys.stdin.buffer.readline

# from collections import deque
# from copy import copy,deepcopy
# from itertools import permutations,combinations
# from pprint import pprint

# def myinput():
#     return map(int,input().split())

# def mycol(data,col):
#     return [ row[col] for row in data ]

# def mysort(data,col):
#     data.sort(key=lambda x:x[col],reverse=False)
#     return data

s = input()
t = input()

for i in reversed(range(len(s)-len(t)+1)):
    flag = False
    for j in range(len(t)):
        if j==(len(t)-1):
            if s[i+j]=="?":
                flag = True
            elif s[i+j]==t[j]:
                flag = True
            else:
                flag = False
        elif s[i+j]=="?":
            pass
        elif s[i+j]==t[j]:
            pass
        else:
            flag = False
            break
    if flag:
        break
    else:
        continue

if flag:
    pass
else:
    print("UNRESTORABLE")
    exit()

ans = copy(s)
ans = list(ans)

for l in range(len(t)):
    ans[i+l] = t[l]

ans = "".join(ans)

ans2 = ans.replace("?","a")
print(ans2)

Submission status: Runtime Error

Solution code:
import sys
readline = sys.stdin.buffer.readline

from collections import deque
from copy import copy,deepcopy
from itertools import permutations,combinations
from pprint import pprint

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

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

s = input()
t = input()

for i in reversed(range(len(s)-len(t)+1)):
    # print(i)
    flag = False
    for j in range(len(t)):
        if j==(len(t)-1):
            if s[i+j]=="?":
                flag = True
            elif s[i+j]==t[j]:
                flag = True
            else:
                flag = False
        elif s[i+j]=="?":
            pass
        elif s[i+j]==t[j]:
            pass
        else:
            flag = False
            break
    if flag:
        break
    else:
        continue

# print(i,j)

if flag:
    pass
else:
    print("UNRESTORABLE")
    exit()

# k = len(s) - len(t) - i
# print(k)

ans = copy(s)
ans = list(ans)
# print(ans)
# print(list(str(t)))

for l in range(len(t)):
    ans[i+l] = t[l]

# print(ans)


ans = "".join(ans)
# print(ans)

ans2 = ans.replace("?","a")
print(ans2)

Submission status: Runtime Error

Solution code:
import sys
readline = sys.stdin.buffer.readline

from collections import deque
from copy import copy,deepcopy
from itertools import permutations,combinations
from pprint import pprint

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

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

s = input()
t = input()

for i in range(len(s)-len(t)):
    print(s[i])
    flag = True
    for j in range(len(t)):
        if s[i]=="?":
            pass
        elif s[i]==t[i+j]:
            pass
        else:
            flag = False
    if flag:
        break
    else:
        continue

if flag==False:
    print("UNRESTORABLE")
    exit()

# print(len(s)-len(t)-i)
# print(j)

k = len(s) - len(t) - i

ans = copy(s)
ans = list(ans)
# print(ans)
# print(list(str(t)))

for l in range(len(t)):
    ans[k+l] = t[l]

# print(ans)


ans = "".join(ans)
# print(ans)

ans2 = ans.replace("?","a")
# print(ans2)

Submission status: Runtime Error

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

offset = len(S) - len(T)

ans = []
for d in range(offset + 1):
    A = ''
    Td = '?' * d + T
    for i in range(len(S)):
        if i < len(Td) and S[i] != Td[i] and '?' not in [S[i], Td[i]]:
            break
        else:
            c = S[i] if Td[i] == '?' else Td[i]
            A += c
    else:        
        ans.append(A.replace('?', 'a'))

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

Submission status: Runtime Error

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

offset = len(Sx) - len(T) + 1
check = [1] * offset

ans = 'UNRESTORABLE'
if len(Sx) >= len(T):
    for d in range(offset):
        for j in range(len(T)):
            check[d] &= (Sx[j + d] == T[j] or Sx[j + d] == '?')
    
    if any(check):
        k = max(k for k, c in enumerate(check) if c)
        ans = ''
        for i in range(len(Sx)):
            if i < k or k + len(T) < i:
                c = Sx[i]
            else:
                c = T[i - k]
            c = 'a' if c == '?' else c

            ans += c

print(ans)

Submission status: Runtime Error

Solution code:
import re 
s = iput().replace("?",".")
t = input()

for i in range(len(s)-len(t)+1):
  if re.match(s[i:i+len(t)],t):
    s = s.replace(".","a")
    print(s[:i] + t + s[i+len(t):])
    exit()
print("UNRESTORABLE")

Submission status: Runtime Error

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

for i in range(len(sd)-len(t)+1):
    ii=len(sd)-len(t)-i
    yn=""
    for j in range(len(t)):
        if sd[ii+j]!=t[j] and sd[ii+j]!="?":
            yn="NG"
            break
    if yn=="NG":
        continue
    else:
        yn="yes"
        break
    
if yn=="NG": 
    print("UNRESTORABLE")
else:
#    s=sd.copy()
    for j in range(len(t)):
        sd[ii+j]=t[j]
    for j in range(len(sd)):
        if sd[j]=="?":
           sd[j]="a"
    strt="".join(sd)
    print(strt)

Submission status: Runtime Error

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

for i in range(len(sd)-len(t)+1):
    ii=len(sd)-len(t)-i
    yn=""
    for j in range(len(t)):
        if sd[ii+j]!=t[j] and sd[ii+j]!="?":
            yn="NG"
            break
    if yn=="NG":
        continue
    else:
        yn="yes"
        break
    
if yn=="NG": 
    print("UNRESTORABLE")
#elif yn=="": 
#    print("UNRESTORABLE")
#elif yn=="yes":
else:
    s=sd.copy()
    for j in range(len(t)):
        s[ii+j]=t[j]
    for j in range(len(s)):
        if s[j]=="?":
           s[j]="a"
    strt="".join(s)
    print(strt)