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
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

S = list(sys.stdin.readline().rstrip())
T = sys.stdin.readline().rstrip()
SL = len(S)
TL = len(T)

SR = S[::-1]
O_SR = SR[:]
TR = T[::-1]

for i in range(0, SL - TL + 1):
    PSR = SR[i:TL + i:]
    equal = True
    for s, t in zip(PSR, TR):
        if s == t or s == '?':
            pass
        else:
            equal = False
            break
    if equal:
        for j, t in zip(range(i, TL + 1), TR):
            SR[j] = t

if SR == O_SR:
    print("UNRESTORABLE")
else:
    print(''.join(SR[::-1]).replace('?','a'))

Submission status: Wrong Answer

Solution code:
s = input()
T = input()
ab = 0
if T in s:
    print(s.replace('?', 'a'))
    exit()
if len(T) > len(s):
    print('UNRESTORABLE')
    exit()
U = list(reversed(list(s)))
for i in range(len(T)):
    for j in range(len(U)):
        if T[i] == U[j]:
            V = s[len(s)-j-1:len(s)-j-1+len(T)]
            flag = 0
            for v,t in zip(V, T):
                if v == '?':
                    pass
                elif v != t:
                    break
                flag += 1
                if flag == len(T):
                    s = s[:len(s)-j-1] + T + s[len(s)-j-1+len(T):]
                    ab += 1
                    break
if ab == 0:
    print('UNRESTORABLE')
    exit()
for i in s:
    if i == '?':
        print('a', end='')
    else:
        print(i, end='')
print()

Submission status: Wrong Answer

Solution code:
s = input()
T = input()
ab = 0
if T in s:
    print(s.replace('?', 'a'))
    exit()

U = list(reversed(list(s)))
for i in range(len(T)):
    for j in range(len(U)):
        if T[i] == U[j]:
            V = s[len(s)-j-1:len(s)-j-1+len(T)]
            flag = 0
            for v,t in zip(V, T):
                if v == '?':
                    pass
                elif v != t:
                    break
                flag += 1
                if flag == len(T):
                    s = s[:len(s)-j-1] + T + s[len(s)-j-1+len(T):]
                    ab += 1
                    break
if ab == 0:
    print('UNRESTORABLE')
    exit()
for i in s:
    if i == '?':
        print('a', end='')
    else:
        print(i, end='')
print()

Submission status: Wrong Answer

Solution code:
def resolve():
    ss = input()
    t = input()

    Srev = ss[::-1]
    Trev = t[::-1]

    initial_T = -1

    for i in range(len(Srev) - len(Trev)):
        flg = True
        for j in range(len(Trev)):
            if Srev[i + j] != Trev[j] and Srev[i + j] != '?':
                flg = False
                break

        if flg:
            initial_T = i
            break

    Srep = Srev[:initial_T] + Trev + Srev[initial_T + len(Trev):]
    ans = Srep.replace('?', 'a')[::-1]

    if len(Srev) == len(Trev):
        print(Srev.replace('?', 'a')[::-1])
    elif initial_T == -1:
        print('UNRESTORABLE')
    else:
        print(ans)
        
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    ss = input()
    t = input()

    Srev = ss[::-1]
    Trev = t[::-1]

    initial_T = -1

    for i in range(len(Srev) - len(Trev)):
        flg = True
        for j in range(len(Trev)):
            if Srev[i + j] != Trev[j] and Srev[i + j] != '?':
                flg = False
                break

        if flg:
            initial_T = i
            break

    Srep = Srev[:initial_T] + Trev + Srev[initial_T + len(Trev):]
    ans = Srep.replace('?', 'a')[::-1]

    if initial_T == -1:
        print('UNRESTORABLE')
    else:
        print(ans)
        
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    ss = input()
    t = input()

    Srev = ss[::-1]
    Trev = t[::-1]

    initial_T = -1

    for i in range(len(Srev) - len(Trev)):
        flg = True
        for j in range(len(Trev)):
            if Srev[i + j] != Trev[j] and Srev[i + j] != '?':
                flg = False
                break

        if flg:
            initial_T = i

    Srep = Srev[:initial_T] + Trev + Srev[initial_T + len(Trev):]
    ans = Srep.replace('?', 'a')[::-1]

    if initial_T == -1:
        print('UNRESTORABLE')
    else:
        print(ans)
        
resolve()

Submission status: Wrong Answer

Solution code:
import re
S_ = input()
T = input()

Srev = "".join(reversed(S_))
Trev = "".join(reversed(T))

pattern = "".join(["[{}?]".format(t) for t in Trev])
ans = re.sub(pattern, Trev, Srev, count=1)
ans = "".join(reversed(ans.replace("?", "a")))
if ans.count(T):
    print("".join(reversed(ans.replace("?", "a"))))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
S_ = input()
T = input()

Srev = "".join(reversed(S_))
Trev = "".join(reversed(T))

pattern = "".join(["[{}?]".format(t) for t in Trev])
ans = re.sub(pattern, Trev, Srev, count=1)
if ans==Srev:
    print("UNRESTORABLE")
else:
    print("".join(reversed(ans.replace("?", "a"))))

Submission status: Wrong Answer

Solution code:
S,T=input(),input();l,m=len(S),len(T)
for i in range(l-m):
 if all(c in"?"+d for c,d in zip(S[-i-m:],T)):S=S.replace("?","a");print(S[:-i-m]+T+S[l-i:]);quit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S,T=open(0);l,m=len(S),len(T)
for i in range(l-m):
 if all(c in"?"+d for c,d in zip(S[-i-1-m:],T)):S=S.replace("?","a");print(S[:-i-1-m]+T+S[l-i:]);quit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S_ = input()
T = input()
ans = list(S_)
for i in reversed(range(len(T))):
    if T[i] in S_:
        id = S_.index(T[i])
        flag = True
        for j in range(i+1, len(T)):
            if S_[id + j - i] == T[i] or S_[id + j - i] == "?":
                continue
            else:
                flag = False
                break
            for j in reversed(range(i)):
                if S_[id - j - 1] == T[i - j - 1] or S_[id - j - 1] == "?":
                    continue
                else:
                    flag = False
                    break
        if flag:
            ans[id - i:id - i + len(T)] = T
            for i in range(len(ans)):
                if ans[i] == "?":
                    ans[i] = "a"
            print("".join(ans))
            exit(0)


print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S_ = input()
T = input()
ans = list(S_)
count = 0
for i in range(len(T)):
    if T[i] in S_:
        id = S_.index(T[i])
        flag = True
        for j in range(i+1, len(T)):
            if S_[id + j - i] == T[i] or S_[id + j - i] == "?":
                continue
            else:
                flag = False
                break
            for j in reversed(range(i)):
                if S_[id - j - 1] == T[i - j - 1] or S_[id - j - 1] == "?":
                    continue
                else:
                    flag = False
                    break
        if flag:
            ans[id - i:id - i + len(T)] = T
            for i in range(len(ans)):
                if ans[i] == "?":
                    ans[i] = "a"
            print("".join(ans))
            exit(0)
    else:
        count += 1

print("UNRESTORABLE")

Submission status: Wrong Answer

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

def main(S_,T):
    S = []
    for i in range(len(S_)-len(T)+1):
        flag = True
        for j in range(len(T)):
            if(S_[i+j]==T[j] or S_[i+j]=="?"):
                continue
            else:
                flag = False
                break
        if flag:
            S.append(S_[:i]+T+S_[i+len(T):])
                
    if len(S)>0:
        print("".join(S).replace("?","a"))
    else:
        print("UNRESTORABLE")
        
if __name__ == '__main__':
    S_ = input()
    T = input()
    main(S_,T)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
N = len(S)
M = len(T)

judge = False
for i in range(N):
    c = i
    for j,t in enumerate(T):
        if c > N-1:
            break
        if t == S[c] or S[c] == "?":
            c += 1
            if j == M-1:
                judge = True
        else:
            break
    if judge:
        S= S[:i]+T+S[i+M:]
        break
#出力
if judge:
    for i in range(N):
        print(S[i] if S[i] != "?" else "a",end="")
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
c = -1
U = '?'*len(T)
for i in range(len(S)):
    if S[i] == T[0]:
        s_new = S[i:i+len(T)]
        flag = 0
        for j in range(len(s_new)):
            if s_new[j] == '?':
                flag += 1
                continue
            else:
                if s_new[j] == T[j]:
                    flag += 1
                    continue
                else:
                    break
        if len(s_new) == flag:
            c = i
if c == -1:
    for i in range(len(S)-len(T)+1):
        if S[i:i+len(T)] == U:
            c = i

if c == -1:
    print('UNRESTORABLE')
else:
    S = S[:c] + T + S[c+len(T):]
    for s in S:
        if s == '?':
            print('a', end = '')
        else:
            print(s, end = '')

Submission status: Wrong Answer

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

def main(S_,T):
    if(len(T)>len(S_)):
        idx = -1
    else:
        for i in range(len(S_)-len(T)+1):
            cnt = 0
            idx = -1
            for j in range(len(T)):
                if(S_[i+j]==T[j] or S_[i+j]=="?"):
                    cnt += 1
                    if cnt == len(T):
                        idx = i+j-len(T)+1
                    else:
                        continue
                else:
                    break
                
    if idx == -1:
        print("UNRESTORABLE")
    else:
        for i in range(len(T)):
            S_[idx+i] = T[i]
        for i in range(len(S_)):
            if S_[i] == "?":
                S_[i] = "a"
        print("".join(S_))

if __name__ == '__main__':
    S_ = list(input())
    T = list(input())
    main(S_,T)

Submission status: Wrong Answer

Solution code:
def solve():
    s = input()
    t = input()
    ls = len(s)
    lt = len(t)
    for i in range(ls - lt + 1):
        if all([cc == tc or cc == "?" for cc, tc in zip(s[i:i + lt], t)]):
            return (s[:i] + t + s[i + lt:]).replace("?", "a")
    return "UNRESTORABLE"


def resolve():
    print(solve())


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

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

ls = len(S)
lt = len(T)

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

for i in range(ls - lt + 1):
    match = True
    for s, t in zip(S[i:lt + i], T):
        if s != t and s != '?':
            match = False
            break
    if match:
        ans = ''
        ans += S[:i]
        ans += T
        ans += S[i+lt:]
        print(ans.replace('?', 'a'))
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
s=''.join(list(reversed(input())))
t=''.join(list(reversed(input())))
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j]!='?' and s[i+j]!=t[j]:
            break
        else:
            print(''.join(list(reversed((s[:i]+t+s[i+j+1:]).replace('?','a')))))
            sys.exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
s=''.join(list(reversed(input())))
t=''.join(list(reversed(input())))
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j]!='?' and s[i+j]!=t[j]:
            break
        else:
            print(''.join(list(reversed((s[:i]+t+s[i+j+1:]).replace('?','a')))))
            exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s=''.join(list(reversed(input())))
t=''.join(list(reversed(input())))
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j]!='?' and s[i+j]!=t[j]:
            break
        else:
            print(''.join(list(reversed((s[:i]+t+s[i+len(t):]).replace('?','a')))))
            exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
s=''.join(list(reversed(input())))
t=''.join(list(reversed(input())))
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j]!='?' and s[i+j]!=t[j]:
            break
        else:
            print(''.join(list(reversed((s[:i]+t+s[i+len(t):]).replace('?','a')))))
            sys.exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
s=input()[::-1]
t=input()[::-1]
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j]!='?' and s[i+j]!=t[j]:
            break
        else:
            print(''.join(list(reversed((s[:i]+t+s[i+len(t):]).replace('?','a')))))
            sys.exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s=input()[::-1]
t=input()[::-1]
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j]!='?' and s[i+j]!=t[j]:
            break
        else:
            print(''.join(list(reversed((s[:i]+t+s[i+len(t):]).replace('?','a')))))
            exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()[::-1]
t=input()[::-1]
for i in range(len(s)-len(t)-1):
    for j in range(len(t)):
        if s[i+j]!='?' and s[i+j]!=t[j]:
            break
        else:
            print(''.join(list(reversed((s[:i]+t+s[i+len(t):]).replace('?','a')))))
            exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
s=input()[::-1]
t=input()[::-1]
for i in range(len(s)-len(t)-1):
    for j in range(len(t)):
        if s[i+j]!='?' and s[i+j]!=t[j]:
            break
        else:
            print(''.join(list(reversed((s[:i]+t+s[i+len(t):]).replace('?','a')))))
            sys.exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
t = input()[::-1]
idx = -1
for si in range(len(s)):
    if si + len(t) >= len(s): break

    find = True
    for ti in range(len(t)):
        if s[si + ti] != '?' and s[si + ti] != t[ti]:
            find = False
            break
    if find:
        idx = si
        break

if idx < 0:
    print('UNRESTORABLE')
    exit()

p1 = s[:idx] if idx > 0 else ''
p2 = s[idx + len(t):]
print((p1 + t + p2).replace('?', 'a')[::-1])

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]!="?" and T[j]!=S[i+j]:break
  else:
    print((S[:i]+T+S[i+j+1:]).replace("?","a"))
    exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
#入力
S_prime = str(input())
T = str(input())
ans = []

if len(S_prime) >= len(T):
    times = len(S_prime) - len(T) + 1
    for i in range(times):
        count = 0
        for j in range(len(T)):
            if S_prime[i+j] == '?':
                count = count + 1
            elif S_prime[i+j] != T[j]:
                continue
            else:
                count = count + 1
            
        if count == len(T):
            S = S_prime[:i] + T + S_prime[(i+len(T)+1):]
            S = S.replace('?', 'a')
            ans.append(S)


if len(ans) != 0:
    print(min(ans))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

ans = []
for i in range(len(s_dash) - len(t) + 1):
    candidate = []
    for j in range(i):
        candidate.append('a' if s_dash[j] == '?' else s_dash[j])
    found = True
    for j in range(len(t)):
        if s_dash[i + j] == '?' or t[j] == s_dash[i + j]:
            candidate.append(t[j])
        else:
            found = False
            break
    if found:
        ans.append("".join(candidate))
if 0 == len(ans):
    print("UNRESTORABLE")
else:
    print(sorted(ans)[0])

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
ans_bag = []
possible_ans_bag = []
flag = False
for i in range(len(s)-len(t)+1):
  ans = []
  for j in range(len(t)):
    if j == 0:
      for k in range(i):
        ans += s[k]
    if s[i+j] == '?':
      ans += [t[j]]
    elif s[i+j] != t[j]:
      ans += [s[i+j]]
      break
    else:
      ans += [s[i+j]]
  if len(t) <= i+len(t):
    for k in range(i+len(t), len(s)):
      ans += [s[k]]
  if len(ans) == len(s):
    ans_bag += [ans]
    flag = True
    
if flag:
  for possible_ans in ans_bag:
    for i in range(len(s)):
      if possible_ans[i] == '?':
        possible_ans[i] = 'a'
    possible_ans_bag += [possible_ans]

  print(''.join(sorted(possible_ans_bag)[0]))
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
ans = []
flag = False
for i in range(len(s)-len(t)+1):
  ans = []
  for j in range(len(t)):
    if j == 0:
      for k in range(i):
        ans += s[k]
      
    if s[i+j] == '?':
      ans += [t[j]]
    elif s[i+j] != t[j]:
      ans += [s[i+j]]
      break
    else:
      ans += [s[i+j]]

  if len(ans) == len(s):
    flag = True
    break

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

  print(''.join(ans))
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S=list(input())
T=list(input())
# S=list("ab?c")
# T=list("abcd")
# print(T)
flag = False
#文字が入るかの確認
for i in range(len(S)+1-len(T)):
    if S[i]==T[0] or S[i]=="?":
        #文字列判定
        for j in range(len(T)):
            if S[i+j]==T[j] or S[i+j]=="?":
                continue
            else:
                # print("不一致ij",i,j)
                break
        else:
            for j in range(len(T)):
                S[i+j]=T[j]
            break
else:
    flag = True
    print("UNRESTORABLE")

#?のa filling
if flag==False:
    print("".join(S).replace("?","a"))

Submission status: Wrong Answer

Solution code:
# S=list(input())
# T=list(input())
S=list("ab?c")
T=list("abcd")
# print(T)
flag = False
#文字が入るかの確認
for i in range(len(S)+1-len(T)):
    if S[i]==T[0]:
        #文字列判定
        for j in range(len(T)):
            if S[i+j]==T[j] or S[i+j]=="?":
                continue
            else:
                # print("不一致ij",i,j)
                break
        else:
            for j in range(len(T)):
                S[i+j]=T[j]
            break
else:
    flag = True
    print("UNRESTORABLE")

#?のa filling
if flag==False:
    print("".join(S).replace("?","a"))

Submission status: Wrong Answer

Solution code:
S=list(input())
T=list(input())
# S=list("?tc????")
# T=list("coder")
# print(T)
flag = False
#文字が入るかの確認
for i in range(len(S)+1-len(T)):
    if S[i]==T[0]:
        #文字列判定
        for j in range(len(T)):
            if S[i+j]==T[j] or S[i+j]=="?":
                continue
            else:
                # print("不一致ij",i,j)
                break
        if j==len(T)-1:
            # print("一致パターンがありました。代入します。")
            for j in range(len(T)):
                S[i+j]=T[j]
            break
else:
    flag = True
    print("UNRESTORABLE")

#?のa filling
if flag==False:
    print("".join(S).replace("?","a"))

Submission status: Wrong Answer

Solution code:
import sys
import  math
import bisect
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = input()
t = input()
ss = []
for i in range(0, len(s) - len(t) + 1):
    for j in range(len(t)):
        if s[i+j] not in ('?', t[j]):
            break
    else:
        s = s[:i] + t + s[i+len(t):]
        ss.append(s.replace('?', 'a'))
if ss:
    print(min(ss))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
import  math
import bisect
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = input()
t = input()
ls = len(s)
lt = len(t)
ct = 0
li = []
ans = "UNRESTORABLE"
if ls < lt:
    print(ans)
else:
    for i in range(ls)[::-1]:
        if t[-(ct+1)] == s[i] or s[i] == "?":
            ct += 1
            if ct == lt:
                ans = ""
                for j in range(ls):
                    if j == i:
                        ans += t
                    elif i < j < i+lt:
                        continue
                    elif s[j] == "?":
                        ans += "a"
                    else:
                        ans += s[j]
                li.append(ans)
                ct = 0
                i += lt - 1
        else:
            ct = 0
    if len(li) > 0:
        print(min(li))
    else:
        print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys
import  math
import bisect
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = input()
t = input()
ls = len(s)
lt = len(t)
ct = 0
ans = "UNRESTORABLE"
if ls < lt:
    print(ans)
else:
    for i in range(ls)[::-1]:
        if t[-(ct+1)] == s[i] or s[i] == "?":
            ct += 1
            if ct == lt:
                ans = ""
                for j in range(ls):
                    if j == i:
                        ans += t
                    elif i < j < i+lt:
                        continue
                    elif s[j] == "?":
                        ans += "a"
                    else:
                        ans += s[j]
                break
        else:
            ct = 0
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import  math
import bisect
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = input()
t = input()
ls = len(s)
lt = len(t)
ct = 0
ans = "UNRESTORABLE"
if ls < lt:
    print(ans)
else:
    for i in range(ls):
        if t[ct] == s[i] or s[i] == "?":
            ct += 1
            if ct == lt:
                ans = ""
                l = i - lt + 1
                for j in range(ls):
                    if j == l:
                        ans += t
                    elif l < j <= i:
                        continue
                    elif s[j] == "?":
                        ans += "a"
                    else:
                        ans += s[j]
                break
        else:
            ct = 0
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
import  math
import bisect
from statistics import *
from collections import *
from operator import itemgetter
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = input()
t = input()
ls = len(s)
lt = len(t)
ct = 0
ans = "UNRESTORABLE"
for i in range(ls):
    if t[ct] == s[i] or s[i] == "?":
        ct += 1
        if ct == lt:
            ans = ""
            l = i - lt + 1
            for j in range(ls):
                if j == l:
                    ans += t
                elif l < j <= i:
                    continue
                elif s[j] == "?":
                    ans += "a"
                else:
                    ans += s[j]
            break
    else:
        ct = 0
print(ans)

Submission status: Wrong Answer

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

T_idx = 0
def can_apply(s, t):
    for i in range(len(t)):
        if s[i] == t[i] or s[i] == '?':
            continue
        else:
            return False
    return True

start_idx = -1
for i in range(len(S)-len(T)+1):
    if can_apply(S[i:i + len(T)], T):
        start_idx = i
        break

if start_idx < 0:
    print("UNRESTORABLE")
    os.sys.exit()
ans = [S[i] for i in range(len(S))]
for i in range(len(T)):
    if ans[start_idx + i] == '?':
        ans[start_idx + i] = T[i]

for i in range(len(ans)):
    if ans[i] == '?':
        ans[i] = 'a'

ans_str = ""
for _a in ans:
    ans_str += _a
print(ans_str)

Submission status: Wrong Answer

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

T_idx = 0
start_idx = -1
for i in range(len(S)):
    if S[i] == T[T_idx] or S[i] == '?':
        if T_idx == len(T)-1:
            start_idx = i - len(T) + 1
            break
        else:
            T_idx += 1
    else:
        T_idx = 0

if start_idx < 0:
    print("UNRESTORABLE")
    os.sys.exit()
ans = [S[i] for i in range(len(S))]
for i in range(len(T)):
    if ans[start_idx + i] == '?':
        ans[start_idx + i] = T[i]

for i in range(len(ans)):
    if ans[i] == '?':
        ans[i] = 'a'

ans_str = ""
for _a in ans:
    ans_str += _a
print(ans_str)

Submission status: Wrong Answer

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

T_idx = 0
start_idx = -1
for i in range(len(S)):
    if S[i] == T[T_idx] or S[i] == '?':
        if T_idx == len(T)-1:
            start_idx = i - len(T) + 1
        else:
            T_idx += 1
    else:
        T_idx = 0

if start_idx < 0:
    print("UNRESTORABLE")
    os.sys.exit()
ans = [S[i] for i in range(len(S))]
for i in range(len(T)):
    if ans[start_idx + i] == '?':
        ans[start_idx + i] = T[i]

for i in range(len(ans)):
    if ans[i] == '?':
        ans[i] = 'a'

ans_str = ""
for _a in ans:
    ans_str += _a
print(ans_str)

Submission status: Wrong Answer

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

def search(ss,t):
    ans = []
    if len(ss) < len(t):
        return ans
    for i in range(len(ss) - len(t), -1, -1):
        ss_cut = ss[i:len(t)+i]
        ss_copy = ss
        flag = True
        for j in range(len(t)):
            if ss_cut[j] != '?' and ss_cut[j] != t[j]:
                flag = False
        if flag:
            ss_copy = ss_copy.replace(ss_copy[i:len(t)+i], t)
            while '?' in ss_copy:
                ss_copy = ss_copy.replace('?', 'a')
            ans.append(ss_copy)
    return ans

if len(search(ss, t)) == 0:
    print('UNRESTORABLE')
else:
    s = sorted(search(ss, t))
    print(s[0])

Submission status: Wrong Answer

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

def search(ss,t):
    if len(ss) < len(t):
        return 'UNRESTORABLE'
    for i in range(len(ss) - len(t), -1, -1):
        ss_cut = ss[i:len(t)+i]
        flag = True
        for j in range(len(t)):
            if ss_cut[j] != '?' and ss_cut[j] != t[j]:
                flag = False
        if flag:
            ss = ss.replace(ss[i:len(t)+i], t)
            return ss
    return 'UNRESTORABLE'

if search(ss, t) == 'UNRESTORABLE':
    print('UNRESTORABLE')
else:
    s = search(ss, t)
    while '?' in s:
        s = s.replace('?', 'a')
    print(s)

Submission status: Wrong Answer

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

def search(ss,t):
    ans = []
    if len(ss) < len(t):
        return ans
    for i in range(len(ss) - len(t)+1):
        ss_cut = ss[i:len(t)+i]
        flag = True
        for j in range(len(t)):
            if ss_cut[j] != '?' and ss_cut[j] != t[j]:
                flag = False
        if flag:
            ss_ans = ss.replace(ss[i:len(t)+i], t)
            while '?' in ss_ans:
                ss_ans = ss_ans.replace('?', 'a')
            ans.append(ss_ans)
    return ans

if len(search(ss, t)) == 0:
    print('UNRESTORABLE')
else:
    ans_list = sorted(search(ss, t))
    print(ans_list)
    s = ans_list[0]
    print(s)

Submission status: Wrong Answer

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

def search(ss,t):
    ans = []
    if len(ss) < len(t):
        return ans
    for i in range(len(ss) - len(t), -1, -1):
        ss_cut = ss[i:len(t)+i]
        flag = True
        for j in range(len(t)):
            if ss_cut[j] != '?' and ss_cut[j] != t[j]:
                flag = False
        if flag:
            ss_ans = ss.replace(ss[i:len(t)+i], t)
            while '?' in ss_ans:
                ss_ans = ss_ans.replace('?', 'a')
            ans.append(ss_ans)
    return ans

if len(search(ss, t)) == 0:
    print('UNRESTORABLE')
else:
    ans_list = sorted(search(ss, t))
    print(ans_list)
    s = ans_list[0]
    print(s)

Submission status: Wrong Answer

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

def search(ss,t):
    if len(ss) < len(t):
        return 'UNRESTORABLE'
    for i in range(len(ss) - len(t), -1, -1):
        ss_cut = ss[i:len(t)+i]
        flag = True
        for j in range(len(t)):
            if ss_cut[j] != '?' and ss_cut[j] != t[j]:
                flag = False
        if flag:
            ss = ss.replace(ss[i:len(t)+i], t)
            return ss
    return 'UNRESTORABLE'

if search(ss, t) == 'UNRESTORABLE':
    print('UNRESTORABLE')
else:
    ss = search(ss, t)
    s = ss.replace('?', 'a')
    print(s)