Problem:


Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

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

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

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

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

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

Print the string S.

If such a string does not exist, print UNRESTORABLE.  

Constraints

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

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

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

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

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

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

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



Sample input:
?tc????
coder


Sample output:
atcoder

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if len(s)<l:
    print('UNRESTORABLE')   
    exit() 
for i in range(len(s),-1+l,-1):
    tmp = s[i-l:i]
    print(tmp)
    tmp_flag = False
    for j in range(l):
        if tmp[j]=='?':
            tmp_flag = True
        elif tmp[j]!=t[j]:
            tmp_flag = False
            break
        else:
            tmp_flag = True
    if tmp_flag:
        t = list(t)
        s = list(s)
        s[i-l:i] = t
        break

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

Submission status: Wrong Answer

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

if len(s)<l:
    print('UNRESTORABLE')   
    exit() 
for i in range(len(s),-1+l,-1):
    tmp = s[i-l:i]
    tmp_flag = False
    for j in range(l):
        if tmp[j]=='?':
            tmp_flag = True
        elif tmp[j]!=t[j]:
            tmp_flag = False
            break
    if tmp_flag:
        t = list(t)
        s = list(s)
        s[i-l:i] = t
        break

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

Submission status: Wrong Answer

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

if len(s)<l:
    print('UNRESTORABLE')   
    exit() 
for i in range(len(s)-l+1):
    tmp = s[i:i+l]
    tmp_flag = False
    for j in range(l):
        if tmp[j]=='?':
            tmp_flag = True
        elif tmp[j]!=t[j]:
            tmp_flag = False
            break
    if tmp_flag:
        t = list(t)
        s = list(s)
        s[i:i+l] = t
        break

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

Submission status: Wrong Answer

Solution code:
import re
S = input()
T = input()
if not re.match(r"^.*("+T[0]+"\?"*(len(T)-1)+")",S):
  print("UNRESTORABLE")
else:
  startN=re.match(r"^.*("+T[0]+"\?"*(len(T)-1)+")",S).span(1)[0]
  S=S[:startN]+T+S[startN+len(T):]
  S=S.replace("?","a")
  print(S)

Submission status: Wrong Answer

Solution code:
import re
S = input()
T = input()
if not re.match(r"^.*("+"\?"*(len(T)-1)+")",S):
  print("UNRESTORABLE")
else:
  startN=re.match(r"^.*("+"\?"*(len(T)-1)+")",S).span(1)[0]
  S=S[:startN]+T[1:]+S[startN+len(T)-1:]
  S=S.replace("?","a")
  print(S)

Submission status: Wrong Answer

Solution code:
import re
S = input()
T = input()
if not re.match(r"^.*("+"\?"*(len(T)-1)+")",S):
  print("UNRESTORABLE")
else:
  startN=re.match(r"^.*("+"\?"*(len(T)-1)+")",S).span(1)[0]
  S=S[:startN-1]+T[1:]+S[startN+len(T)-1:]
  S=S.replace("?","a")
  print(S)

Submission status: Wrong Answer

Solution code:
import re
S = input()
T = input()
if not re.match(r"^.*("+"\?"*len(T)+")",S):
  print("UNRESTORABLE")
else:
  startN=re.match(r"^.*("+"\?"*len(T)+")",S).span(1)[0]
  S=S[:startN-1]+T+S[startN+len(T):]
  S=S.replace("?","a")
  print(S)

Submission status: Wrong Answer

Solution code:
#n,m = map(int,input().split())
#s,t = map(str,input().split())
#a = list(map(int,input().split()))
#m = list(map(str,input().split()))
#n = int(input())
#s = list(str(input()))
#s = str(input())
#t = str(input())

s_dash = list(str(input()))
t = list(str(input()))

lt = len(t)
ls = len(s_dash)
msg = "UNRESTORABLE"

#Tの方が長ければ不可能
if ls < lt:
    print(msg)

#Sの候補を探す
candidate = []
for i in range(ls-lt+1):
    is_matched = True#TとS'の部分文字列が一致する可能性があるか
    tmp = s_dash.copy()

    for j in range(lt):
        if t[j] == s_dash[i+j] or s_dash[i+j] == '?':
            tmp[i+j] = t[j]
        else:
            is_matched = False
            break

    if is_matched == True:#一致する可能性があれば
        for j in range(ls):#残った'?'は'a'に置換
            if tmp[j] == '?':
                tmp[j] = 'a'
        
        cand = str("")
        for c in tmp:
            cand += c
        candidate.append(cand)

if len(candidate) == 0:
    print(msg)
else:
    candidate.sort()
    print(candidate[0])

Submission status: Wrong Answer

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

lt = len(t)
ls = len(s_dash)
ans = "UNRESTORABLE"

#Tの方が長ければ不可能
if ls < lt:
    print(ans)

#Sの候補を探す
candidate = []
for i in range(ls-lt+1):
    is_matched = True#TとS'の部分文字列が一致する可能性があるか
    tmp = s_dash.copy()

    for j in range(lt):
        if t[j] == s_dash[i+j] or s_dash[i+j] == '?':
            tmp[i+j] = t[j]
        else:
            is_matched = False
            break

    if is_matched == True:#一致する可能性があれば
        for j in range(ls):#残った'?'は'a'に置換
            if tmp[j] == '?':
                tmp[j] = 'a'
        
        cand = str("")
        for c in tmp:
            cand += c
        candidate.append(cand)

if len(candidate) == 0:
    print(ans)
else:
    candidate.sort()
    print(candidate[0])

Submission status: Wrong Answer

Solution code:
#n,m = map(int,input().split())
#s,t = map(str,input().split())
#a = list(map(int,input().split()))
#m = list(map(str,input().split()))
#n = int(input())
#s = list(str(input()))
#s = str(input())
#t = str(input())

s_dash = list(str(input()))
t = list(str(input()))

lt = len(t)
ls = len(s_dash)
ans = "UNRESTORABLE"

#Tの方が長ければ不可能
if ls < lt:
    print(ans)

#Sの候補を探す
candidate = []
for i in range(ls-lt+1):
    is_matched = True#TとS'の部分文字列が一致する可能性があるか

    for j in range(lt):
        if t[j] == s_dash[i+j] or s_dash[i+j] == '?':
            pass
        else:
            is_matched = False
            break

    if is_matched:#一致する可能性があれば
        tmp = s_dash

        for j in range(lt):
            tmp[i+j] = t[j]#S'の対応する文字をTの文字に置換

        for j in range(ls):#残った'?'は'a'に置換
            if tmp[j] == '?':
                tmp[j] = 'a'
        
        cand = str("")
        for c in tmp:
            cand += c
        candidate.append(cand)

if len(candidate) == 0:
    print(ans)
else:
    candidate.sort()
    print(candidate[0])

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    s = s_input()
    t = s_input()

    len_s = len(s)
    len_t = len(t)

    if len_s < len_t:
        print('UNRESTORABLE')
        exit()

    ok_index = -1
    for i in range(len_s-len_t+1):
        tmp_s = s[i:i+len_t]
        for j in range(len_t):
            if tmp_s[j] != t[j] and tmp_s[j] != '?':
                break
        else:
            ok_index = i

    if ok_index == -1:
        print('UNRESTORABLE')
        exit()

    ans_s = s[0:i] + t

    print(ans_s.replace('?', 'a'))
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, re
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline 
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_list(N): return [s_list() for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    s = s_input()
    t = s_input()

    len_s = len(s)
    len_t = len(t)

    ok_index = -1
    for i in range(len_s-len_t+1):
        tmp_s = s[i:i+len_t]
        for j in range(len_t):
            if tmp_s[j] != t[j] and tmp_s[j] != '?':
                break
        else:
            ok_index = i

    if ok_index == -1:
        print('UNRESTORABLE')
        exit()

    ans_s = s[0:i] + t

    print(ans_s.replace('?', 'a'))
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
w = []
if len(s) < len(t):
    print("UNRESTORABLE")
else:
    for i in range(len(s) - len(t) + 1):
        f = True
        sx = s[i:i + len(t)]
        for si, ti in zip(sx, t):
            if si != ti and si != "?":
                f = False
        #print((s[:i] + t).replace("?", "a"),i)
        if f:
            w.append((s[:i] + t).replace("?", "a"))
    if w == []:
        print("UNRESTORABLE")
    else:
        w.sort()
        print(w[0])

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
w = []
if len(s) < len(t):
    print("UNRESTORABLE")
else:
    for i in range(len(s) - len(t) + 1):
        f = True
        sx = s[i:i + len(t)]
        for si, ti in zip(sx, t):
            if si != ti and si != "?":
                f = False
        print((s[:i] + t).replace("?", "a"),i)
        if f:
            w.append((s[:i] + t).replace("?", "a"))
    if w == []:
        print("UNRESTORABLE")
    else:
        w.sort()
        print(w[0])

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
w = []
for i in range(len(s) - len(t) + 1):
    f = True
    sx = s[i:i + len(t)]
    for si, ti in zip(sx, t):
        if si != ti and si != "?":
            f = False
        else:
            pass
    if f:
        w.append((s[:i] + t).replace("?", "a"))
if w == []:
    print("UNRESTORABLE")
else:
    w.sort()
    print(w[0])

Submission status: Wrong Answer

Solution code:
S = list(input())
Ns = len(S)
T = list(input())
Nt = len(T)
ans = 'UNRESTORABLE'
for i in range(Ns-Nt+1):
  A = S[i:i+Nt]
  a = 0
  for j in range(Nt):
    if A[j] == '?' or A[j] == T[j]:
      continue
    else:
      a = 1
      break
  if a == 0:
    ans = S[:i] + T + S[i+Nt:]
    break
if ans == 'UNRESTORABLE':
  print(ans)
else:
  n = len(ans)
  for i in range(n):
    if ans[i] == '?':
      ans[i] = 'a'
  ans = ''.join(ans)
  print(ans)

Submission status: Wrong Answer

Solution code:
S = input().strip()
N=len(S)
T = input().strip()
M=len(T)
A = []
for i in range(N-M+1):
    flag = 0
    for j in range(i,i+M):
        if S[j]=="?" or S[j]==T[j-i]:continue
        else:
            flag=1
            break
    if flag==0:
        X = list(S)
        for j in range(i,i+M):
            X[j] = T[j-i]
        for i in range(N):
            if X[i]=="?":
                X[i]="a"
        A.append(X)
if len(A)==0:
    print("UNRESTRABLE")
else:
    A = sorted(A)
    print("".join(A[0]))

Submission status: Wrong Answer

Solution code:
s_ = list(str(input()))
t = list(str(input()))

n = len(s_)
m = len(t)

if m > n:
    print('UNRESTORABLE')

import copy
ans = []
for i in range(n-m+1):
    if s_[i] == t[0] or s_[i] == '?':
        temp = copy.copy(s_)
        for j in range(i, i+m):
            #print(i, temp)
            if s_[j] == '?':
                temp[j] = t[j-i]
            elif s_[j] == t[j-i]:
                continue
            else:
                break
        else:
            for k in range(n):
                if temp[k] == '?':
                    temp[k] = 'a'
            ans.append(''.join(temp))
if ans:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

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

##一つ一つパターンマッチさせる

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

for i in range(ls-lt+1):
    cnd = S[i:i+lt]
    flag = True
    for s,t in zip(cnd,T):
        if s != "?":
            if s != t:
                flag = False
                break

    if flag:
        tmp = S.replace("?","a")
        print(tmp[:i]+T+tmp[i+lt:])
        exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re

S = input()
T = input()

flag = False
for i in range(len(S) - len(T), -1, -1):
    pattern = S[i:i+len(T)].replace('?', '.')
    m = re.search(pattern, T)
    if m:
        result = re.sub(pattern, T, S)
        flag = True
        break

if flag > 0 :
    output = result.replace('?', 'a')
    
else :
    output = 'UNRESTORABLE'
    
print(output)

Submission status: Wrong Answer

Solution code:
import re

S = input()
T = input()

results = []
for i in range(len(S) - len(T)+1):
    pattern = S[i:len(T) + i].replace('?', '.')
    m = re.search(pattern, T)
    if m:
        result = re.sub(pattern, T, S)
        results.append(result)

if len(results) > 0 :
    results = [ r.replace('?', 'a', 50) for r in results]
    output = sorted(results)[0]
    
else :
    output = 'UNRESTORABLE'
print(output)

Submission status: Wrong Answer

Solution code:
import re

S = input()
T = input()

results = []
for i in range(len(S) - len(T)+1):
    pattern = S[i:len(T) + i].replace('?', '.')
    print(pattern)
    m = re.search(pattern, T)
    if m:
        result = re.sub(pattern, T, S)
        results.append(result)

if len(results) > 0 :
    results = [ r.replace('?', 'a', 50) for r in results]
    output = sorted(results)[0]
    
else :
    output = 'UNRESTORABLE'
print(output)

Submission status: Wrong Answer

Solution code:
import re

S = input()
T = input()

results = []
for i in range(len(S) - len(T)+1):
    pattern = S[i:len(T) + i].replace('?', '.')
    m = re.search(pattern, T)
    if m:
        result = re.sub(pattern, T, S)
        results.append(result)

if len(results) > 0 :
    results = sorted([ r.replace('?', 'a') for r in results])
    output = results[0]
    
else :
    output = 'UNRESTORABLE'
print(output)

Submission status: Wrong Answer

Solution code:
import re

S = input()
T = input()

flag = False
for i in range(len(S) - len(T)+1):
    pattern = S[i:len(T) + i].replace('?', '.')
    m = re.search(pattern, T)
    if m:
        flag = True
        result = re.sub(pattern, T, S)
        break

if flag :
    output = result.replace('?', 'a')
else :
    output = 'UNRESTORABLE'
print(output)

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
t = input()[::-1]

for i in range(len(s) - len(t) + 1):
    check = True
    for j in range(len(t)):
        if s[i+j] == t[j]:
            pass
        elif s[i+j] == "?":
            pass
        else:
            check = False
            break
        
    if check:
        s = s.replace(s[i:i+len(t)], t)
        s = s.replace("?", "a", 500)
        print(s[::-1])
        exit()
            
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
t = input()[::-1]

if len(s) < len(t):
    print("UNRESTORABLE")
    exit()

for i in range(len(s) - len(t) + 1):
    check = True
    for j in range(len(t)):
        if s[i+j] == t[j]:
            pass
        elif s[i+j] == "?":
            pass
        else:
            check = False
        
    if check:
        s = s.replace(s[i:i+len(t)], t)
        s = s.replace("?", "a", 500)
        print(s[::-1])
        exit()
            
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
t = input()[::-1]


for i in range(len(s) - len(t) + 1):
    check = True
    for j in range(len(t)):
        if s[i+j] == t[j]:
            pass
        elif s[i+j] == "?":
            pass
        else:
            check = False
        
    if check:
        s = s.replace(s[i:i+len(t)], t)
        s = s.replace("?", "a", 500)
        print(s[::-1])
        exit()
            
print("UNRESTORABLE")

Submission status: Wrong Answer

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

if len(s) < len(t):
    print("UNRESTORABLE")
    exit()

for i in range(len(s) - len(t) + 1):
    check = True
    for j in range(len(t)):
        if s[i+j] == t[j]:
            pass
        elif s[i+j] == "?":
            pass
        else:
            check = False
        
    if check:
        s = s.replace(s[i:i+len(t)], t)
        s = s.replace("?", "a", 500)
        print(s)
        exit()
            
print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i in range(len(s) - len(t) + 1):
    check = True
    for j in range(len(t)):
        if s[i+j] == t[j]:
            pass
        elif s[i+j] == "?":
            pass
        else:
            check = False
        
    if check:
        s = s.replace(s[i:i+len(t)], t)
        s = s.replace("?", "a", 500)
        print(s)
        exit()
            
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
for i in range(len(s) - len(t) + 1):
    if s[i] == t[0] or s[i] == '?':
        for j in range(len(t)):
            if not(s[i+j] == t[j] or s[i+j] == '?'):
                break
        else:
            ans = s[:i] + t + s[i+len(t):]
            ans = ans.replace('?', 'a')
            print(ans)
            break
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

cnt = 0
for i in range(len(S)- len(T)+1):
    X = S[i:i+len(T)]
    #print(X)
    flag = True
    for j in range(len(T)):
        if X[j] != '?' :
            if X[j] != T[j]:
                flag = False
                break
    if flag :
        s = S[:i] + T + S[i+len(T):]
        print(s.replace('?','a'))
        cnt = 1
if cnt == 0:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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



for i in range(len(s) - len(t) + 1):
    check = True
    for j in range(len(t)):
        if s[i+j] == t[j]:
            pass
        elif s[i+j] == "?":
            pass
        else:
            check = False
        
    if check:
        s = s.replace("?", "a", 500)
        print(s[:i]+t+s[i+len(t):])
        exit()
            
print("UNRESTORABLE")

Submission status: Wrong Answer

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



for i in range(len(s) - len(t) + 1):
    check = True
    for j in range(len(t)):
        if s[i+j] == t[j]:
            pass
        elif s[i+j] == "?":
            pass
        else:
            check = False
        
    if check:
        s = s.replace("?", "a", 50)
        print(s[:i]+t+s[i+len(t):])
        exit()
            
print("UNRESTORABLE")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline


def main():
  S = input()[:-1]
  T = input()[:-1]

  for si, s in enumerate(S):
    # print(f's:{s}')
    if not(s == T[0]) and not(s == '?'):
      continue
    cur_si = si
    for t in T:
      # print(f't:{t}')
      if cur_si >= len(S): break
      if not(t == S[cur_si]) and not(S[cur_si] == '?'):
        break
      cur_si += 1
    else:
      t_start_idx = si
      break
  else:
    print('UNRESTORABLE')
    return

  new_S = S[:t_start_idx] + T + S[t_start_idx+len(T):]
  # print(new_S)

  ret_s = ''
  for s in new_S:
    if s == '?':
      ret_s += 'a'
    else:
      ret_s += s

  print(ret_s)


if(__name__ == '__main__'):
  main()

Submission status: Wrong Answer

Solution code:
from sys import stdin
input = stdin.readline


def main():
  S = input()[:-1]
  T = input()[:-1]

  for si, s in enumerate(S):
    # print(f's:{s}')
    if not(s == T[0]):
      continue
    cur_si = si
    for t in T:
      # print(f't:{t}')
      if not(t == S[cur_si]) and not(S[cur_si] == '?'):
        break
      cur_si += 1
    else:
      t_start_idx = si
      break
  else:
    print('UNRESTORABLE')
    return

  new_S = S[:t_start_idx] + T + S[t_start_idx+len(T):]
  # print(new_S)

  ret_s = ''
  for s in new_S:
    if s == '?':
      ret_s += 'a'
    else:
      ret_s += s

  print(ret_s)


if(__name__ == '__main__'):
  main()

Submission status: Wrong Answer

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


kouho=[]
for i in range(len(s)-len(t)+1):
    ans=s[:i]
    tmp=s[i:(i+len(t))]

    for j in range(len(t)):
        if tmp[j]==t[j]:
            ans+=t[j]
        elif tmp[j]=='?': 
            ans+=t[j]
        elif tmp[j]!='?' and tmp[j]!=t[j]:
            break
    if len(ans)==len(s):
        kouho.append(ans)

if len(kouho)==0:
    print('UNRESTORABLE')
    exit(0)

answers=[]
for j in kouho:

    tmp_ans=''
    for k in range(len(j)):
        if j[k]=='?':
            tmp_ans+='a'
        else:
            tmp_ans+=j[k]

    answers.append(tmp_ans)

answers=sorted(answers)
print(answers[0])

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
result = []
flg = 0
for i in range(len(s)):
    find = s[i] in t    
    if find == True:
        if len(s[i:]) == len(t):
            for index, one_chara in enumerate(s[i:]):
                if i == '?' or i == s[index]:
                    break
            result.append(t)
            result = [i.replace(' ', 'a') for i in result]
            break

    elif s[i] == '?':
        result.append(' ')
    else:
        result.append(s[i])

if ' ' in result:
    print('UNRESTORABLE')
else:
    print(*result, sep='')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
result = []
flg = 0
for i in range(len(s)):
    find = s[i] in t    
    if find == True:
        if len(s[i:]) == len(t):
            for index, one_chara in enumerate(s[i:]):
                if i == '?' or i == s[index]:
                    break
            result.append(t)
            result = [i.replace(' ', 'a') for i in result]
            break

    elif s[i] == '?':
        result.append(' ')
    else:
        result.append(s[i])

if '?' in result:
    print('UNRESTORABLE')
else:
    print(*result, sep='')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
import sys
revs = list(reversed(s))
revt = list(reversed(t))
if len(s) < len(t):
    print("UNRESTORABLE")
else:
    cur = 0
    for _ in range(len(s)-len(t)+1):
        char = revs[cur:cur+len(t)]
        charcopy = char.copy()
        print(revt)
        print(char)
        for i,c in enumerate(char):
            if (i == len(char)-1) & ((c == "?") | (c == revt[i])):
                revs[cur:cur+len(t)] = revt
                for j in range(len(revs)):
                    if revs[j] == "?":
                        revs[j] = "a"
                print("".join(list(reversed(revs))))
                sys.exit()
            elif (c == "?") | (c == revt[i]):
                char[i] == revt[i]
            else:
                cur += 1
                break
        else:
            char = charcopy      
    else:
        print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
import sys
revs = list(reversed(s))
revt = list(reversed(t))
if len(s) < len(t):
    print("UNRESTORABLE")
else:
    cur = 0
    for _ in range(len(s)-len(t)+1):
        char = revs[cur:cur+len(t)]
        charcopy = char.copy()
        for i,c in enumerate(char):
            if (i == len(char)-1) & ((c == "?") | (c == revt[i])):
                revs[cur:cur+len(t)] = revt
                for j in range(len(revs)):
                    if revs[j] == "?":
                        revs[j] = "a"
                print("".join(list(reversed(revs))))
                sys.exit()
            elif (c == "?") | (c == revt[i]):
                char[i] == revt[i]
            else:
                break
        else:
            char = charcopy
            cur += 1        
    else:
        print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import numpy as np

S = input()
T = input()

m = len(S)
n = len(T)

for i in range(m-n, -1, -1):
  if np.prod([s in [t, '?'] for s, t in zip(S[i:i+m], T)]):
    ans = S[:i] + T + S[i+m-1:]
    ans = ans.replace('?', 'a')
    break
else:
  ans = 'UNRESTORABLE'
print(ans)

Submission status: Wrong Answer

Solution code:
import numpy as np

S = input()
T = input()

m = len(S)
n = len(T)

for i in range(m-n, -1, -1):
  if np.prod([s in [t, '?'] for s, t in zip(S[i:i+m], T)]):
    ans = S[:i] + T + S[i+m:]
    ans = ans.replace('?', 'a')
    break
else:
  ans = 'UNRESTORABLE'
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    if len(S) < len(T):
        print('UNRESTORABLE')
        return

    valid_strs = []
    for i in range(len(S)):
        tmp = S[: i].replace('?', 'a')
        for j in range(len(T)):
            if len(S) <= i + j or S[i + j] != '?' and S[i + j] != T[j]:
                break
            tmp += T[j]
        else:
            valid_strs.append(tmp + S[i + j + 1: i + len(T)].replace('?', 'a'))
    print(min(valid_strs) if valid_strs else 'UNRESTORABLE')

if __name__ == "__main__":
    S = input()
    T = input()
    solve()

Submission status: Wrong Answer

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

flag = 0

if(len(t)> len(s)):
    print("UNRESTORABLE")
else:
    for i in range(len(s)-len(t)+1):
        for j in range(len(t)):
            if(s[i+j] == t[j] or s[i+j] == "?"):
                if(j == len(t) -1):
                    flag = 1
                    break
            else:
                break

        if(flag == 1):
            break

    if(flag == 0):
        print("UNRESTORABLE")
    else:
        kotae = list(s[0:i] + t + s[i+len(t):])
        for i in range(len(kotae)):
            if(kotae[i] == "?"):
                kotae[i] = "a"
        kotae = "".join(kotae)
        print(kotae)

Submission status: Wrong Answer

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

flag = 0
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if(s[i+j] == t[j] or s[i+j] == "?"):
            if(j == len(t) -1):
                flag = 1
                break
        else:
            break

    if(flag == 1):
        break

if(flag == 0):
    print("UNRESTORABLE")
else:
    kotae = list(s[0:i] + t + s[i+len(t):])
    for i in range(len(kotae)):
        if(kotae[i] == "?"):
            kotae[i] = "a"
    kotae = "".join(kotae)
    print(kotae)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
if t in s:
    ans = ""
    for i in s:
        if i == '?':
            ans += 'a'
        else:
            ans += i
    print(ans)
    exit()
s = s[::-1]
t = t[::-1]
count = 0
flag = False
for i in range(len(s)):
    if s[i] == '?' or s[i] == t[count]:
        count+=1
        #print(count,i)
        if count == len(t):
            #print(i,count,s[:i-count],t,s[i+1:])
            s = s[:i+1-count] + t + s[i+1:]
            #print(s)
            flag = True
            break
    else:
        count = 0
        if t[0] == s[i]:
            count+=1
#print(flag)
if flag:
    ans = ""
    s = s[::-1]
    for i in s:
        if i == '?':
            ans += 'a'
        else:
            ans += i
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
if t in s:
    ans = ""
    for i in s:
        if i == '?':
            ans += 'a'
        else:
            ans += i
    print(ans)
    exit()
s = s[::-1]
t = t[::-1]
count = 0
flag = False
for i in range(len(s)):
    if s[i] == '?' or s[i] == t[count]:
        count+=1
        if count == len(t):
            #print(i,count,s[:i-count],t,s[i+1:])
            s = s[:i+1-count] + t + s[i+1:]
            #print(s)
            flag = True
            break
    else:
        count = 0
#print(flag)
if flag:
    ans = ""
    s = s[::-1]
    for i in s:
        if i == '?':
            ans += 'a'
        else:
            ans += i
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
s = s[::-1]
t = t[::-1]
count = 0
flag = False
for i in range(len(s)):
    if s[i] == '?' or s[i] == t[count]:
        count+=1
        if count == len(t):
            #print(i,count,s[:i-count],t,s[i+1:])
            s = s[:i+1-count] + t + s[i+1:]
            #print(s)
            flag = True
            break
    else:
        count = 0
#print(flag)
if flag:
    ans = ""
    s = s[::-1]
    for i in s:
        if i == '?':
            ans += 'a'
        else:
            ans += i
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
n=len(s)
m=len(t)
ans='UNRESTORABLE'
a=[]
for i in range(n-m+1):
  if s[i]==t[0] or s[i]=='?':
    for j in range(m):
      if s[i+j]!=t[j] and s[i+j]!='?':
        break
    else:
      an=''
      for k in range(i):
        if s[k]=='?':
          an+='a'
        else:ans+=s[k]
      an+=t
      for k in range(i+m,n):
        if s[k]=='?':
          an+='a'
        else: an+=s[k]
      a.append(an)
if len(a):
  print(min(a))
else:print(ans)