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:
SS=list(map(str,input()))
T=list(map(str,input()))
T1=len(T)
T2=T1-1
f=0
p=-1
j=0

#print(SS)
#print(T)
for i in range(len(SS)-T1+1):
  if SS[i]==T[j] or SS[i]=="?" :
    p=i
    f=f+1
    #print(SS[i],T[j],i,j,f)
    j=j+1
    
    
    if f==T1 and p!=-1:
      break
  else:
    p=-1
    f=0
    j=0
  
#print(p,j,f,T1,len(SS),i)
for i in range(p,p+T1):
  SS[i]=T[i-p]
for i in range(len(SS)):
  if SS[i]=="?":
    SS[i]="a"

if p==-1:
  print("UNRESTORABLE")
else:
  print("".join(map(str,SS)))

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
len_s, len_t = len(s), len(t)
switch = 1
s_i = 0
while s_i < len_s - len_t + 1:
    for t_i in range(len_t):
        if s[s_i+t_i] == "?" or s[s_i+t_i] == t[t_i]:
            if t_i == len_t - 1:
                switch = 0
                s_i += 1
                break
            else:
                continue
        else:
            s_i += 1
            break
if switch: print("UNRESTORABLE")
else:
    s_i -= 1
    s = list(s)
    for j in range(len_t):
        s[s_i+j] = t[j]
    for j in range(len_s):
        if s[j] == "?": s[j] = "a"
    print("".join(s))

Submission status: Wrong Answer

Solution code:
#-------------------------------------------------------------------------------
# Name:        module9
# Purpose:
#
# Author:      user
#
# Created:     02/02/2020
# Copyright:   (c) user 2020
# Licence:     <your licence>
#-------------------------------------------------------------------------------


def is_same(s,t):
    for i in range(len(s)):
        if s[i] == t[i] or s[i] == "?":
            continue
        else:
            return False
    return True

def change_question_mark(s):
    t = ""
    for c in s:
        if c == "?":
            t += "a"
        else:
            t += c
    return t

def solve(s,t):
    len_t = len(t)
    len_s = len(s)
    for i in range(len_s-len_t+1):
        #print(s[i:i+len_t])
        if is_same(s[i:i+len_t],t):
            list_s = list(s)
            for a,b in [(i + temp,temp) for temp in range(len_t)]:
                list_s[a] = t[b]
            list_s = "".join(list_s)

            return change_question_mark(list_s)
    return "UNRESTORABLE"




def main():
    s = input()
    t = input()
    print(solve(s,t))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import re

# S' カギとなる文字列
s = input()

# T 含まれる文字列
t = input()

s = s.replace("?", ".")

match = False
for i in range(len(s)-len(t)+1):
    st = s[i:i+len(t)]
    if len(st) < len(t):
        break
    pattern = re.compile(r"%s" % st)
    if re.match(pattern, t):
        match = True
        break

if match:
    cut = i + len(t)
    return_string = s[:i] + t + s[cut:]
    return_string = return_string.replace(".", "a")
    print(return_string)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

ns = len(S)
nt = len(T)
idx = None

for i in range(ns - nt + 1):
    for j in range(nt):
        if S[i+j] != T[j] and S[i+j] != '?':
            break
    else:
        idx = i

if idx:
    ans = S[:idx] + T + S[idx+nt:]
    print(ans.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

ns = len(S)
nt = len(T)
idx = None

for i in range(ns - nt + 1):
    for j in range(nt):
        if S[i+j] != T[j] and S[i+j] != '?':
            break
    else:
        idx = i
        break

if idx:
    ans = S[:idx] + T + S[idx+nt:]
    print(ans.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

result = ''
for i in range(len(s)-len(t)+1):
  mth = 1
  for j in range(len(t)):
    if s[i+j] != t[j]:
      if s[i+j] == '?':
        pass
      else:
        mth = 0
        break
  if mth == 1:
#    print("i",i)
    result = s[:i]+t+s[i+len(t):]
    print(result.replace('?','a'))
    exit(0)

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
from string import ascii_lowercase

code = input()
hint = input()

def is_match(code, s):
  """
  >>> is_match('abc', 'abc')
  True
  >>> is_match('a?c', 'axc')
  True
  >>> is_match('???', 'xyz')
  True
  >>> is_match('abc', 'abd')
  False
  >>> is_match('abc', 'abcd')
  False
  >>> is_match('?p?', 'abc')
  False
  """
  if len(code) != len(s):
    return False
  for a, b in zip(code, s):
    if not (a == b or a == '?'):
      return False    
  return True


def guess(code, hint):
  """
  >>> guess('?tc????', 'coder')
  'atcoder'
  >>> guess('?p??d??', 'abc')
  'UNRESTORABLE'
  >>> guess('?????er', 'coder')
  'aacoder'
  """
  reversed_code = code[::-1] 
  reversed_hint = hint[::-1] 

  for i in range(len(code)):
    if is_match(reversed_code[i:len(hint)], reversed_hint):
      merged = reversed_code[:i] + reversed_hint + reversed_code[i + len(hint):]
      return merged[::-1].replace('?', 'a')

  return 'UNRESTORABLE'

print(guess(code, hint))

Submission status: Wrong Answer

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

def compareStr(a: str, b: str) -> bool:
    ret = False
    for _a, _b in zip(a, b):
        if _b == "?":
            continue

        if _a == _b:
            ret = True

    return ret

for i in range(len(sd)-len(t)+1):
    if compareStr(t, sd[i:i+len(t)]):
        s = sd.replace("?", "a")
        s = s[:i] + t + s[i+len(t):]
        print(s)
        quit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def solve(s, t):
    start = -1
    for i in range(len(s) - len(t)):
        if all(s[len(s) - len(t) - i + j] in (t[j], '?') for j in range(len(t))):
            start = i
            break
    if start >= 0:
        return s[:len(s) - len(t) - start].replace('?', 'a') + t + s[len(s) - start:].replace('?', 'a')
    else:
        return 'UNRESTORABLE'

_s = input()
_t = input()
print(solve(_s, _t))

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
M = len(S)
N = len(T)
for start in range(M-N,-1,-1):
    for i in range(N):
        if not (S[start+i] == '?' or S[start+i] == T[i]):
            break
    else:
        end = start + N
        pre = ''
        post = ''
        for i in range(start):
            if S[i] == '?':
                pre += 'a'
            else:
                pre += S[i]
        for i in range(end,M):
            if S[i] == '?':
                post += 'a'
            else:
                pre += S[i]
        print(pre + T + post)
        exit()
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

if len(S) < len(T):
    print('UNRESTORABLE')
else:
    pos = []
    # Sのi文字目をスタートとしたときにマッチするか
    for i in range(len(S)-len(T)+1):
        # print('S[i]', S[i])
        match = True
        for j in range(len(T)):
            # print('-', T[j], S[i+j])
            if T[j] == S[i+j] or S[i+j] == '?':
                pass
            else:
                match = False
        if match:
            pos.append(i)

    # print(pos)
    if len(pos) == 0:
        print('UNRESTORABLE')
    else:
        ans = ''
        for i in range(pos[-1]):
            if S[i] == '?':
                ans += 'a'
            else:
                ans += S[i]
        ans += T
        print(ans)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
S=list(input())
T=list(input())
flg=False
S.reverse()
T.reverse()

for i in range(max(0,len(S)-len(T))):
    flg=True
    for j in range(len(T)):
        if not(S[i+j]=="?"):
            if S[i+j]!=T[j]:
                flg=False
    if flg:
        for k in range(len(T)):
            S[i+k]=T[k]
        break    
        

S.reverse()

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

Submission status: Wrong Answer

Solution code:
s = input()
new_s = ''.join(list(reversed(s)))
t = input()
new_t = ''.join(list(reversed(t)))
count = 0
max_count = 0
ans = []
flag = False
new_ans = []
for i in range(len(s)-len(t)+1):
    ans.append(new_s[i:len(t)+i])
for i,j in enumerate(ans):
    for number,k in enumerate(j):
        if k == new_t[number] or k == '?':
            if number == len(k)-1:
                flag = True
                break
        else:
            flag = False
            break

    if flag == True:
        key_number = i
#print(new_s[len(new_t):])
#print(i)
if flag == False:
    print('UNRESTORABLE')
else:
    #ans = new_s[0:key_number] + new_t + new_s[key_number+len(t):]
    ans = new_t + new_s[len(new_t)+i:]
    for i in ans:
        if i=='?':
            new_ans.append('a')
        else:
            new_ans.append(i)
    print(''.join(reversed(new_ans)))

Submission status: Wrong Answer

Solution code:
s = input()
new_s = ''.join(list(reversed(s)))
t = input()
new_t = ''.join(list(reversed(t)))
count = 0
max_count = 0
ans = []
flag = False
new_ans = []
for i in range(len(s)-len(t)+1):
    ans.append(new_s[i:len(t)+i])
for i,j in enumerate(ans):
    for number,k in enumerate(j):
        if k == new_t[number] or k == '?':
            if number == len(k)-1:
                flag = True
                break
        else:
            flag = False
            break

    if flag == True:
        key_number = i
#print(new_s[len(new_t):])
#print(i)
if flag == False:
    print('UNRESTORABLE')
else:
    #ans = new_s[0:key_number] + new_t + new_s[key_number+len(t):]
    ans = new_t + new_s[len(new_t):]
    for i in ans:
        if i=='?':
            new_ans.append('a')
        else:
            new_ans.append(i)
    print(''.join(reversed(new_ans)))

Submission status: Wrong Answer

Solution code:
S_sub,T=input(),input()

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
key = 0
if len(S) < len(T):
    print('UNRESTORABLE')
    exit(0)
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if T[j] == S[j+i] or S[j+i] == '?':
            if j == len(T)-1:
                key = 1
                for k in range(j+1):
                    S[i+k] = T[k]
        else:
            break

if key:
    answer = [s.replace('?', 'a') for s in S]
    print(''.join(answer))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ls = len(s)
lt = len(t)

def match(k):
    for i in range(lt):
        if t[i] != s[i+k] and s[i+k] != '?':
            return False
    return True

c = -1
for i in range(ls-lt+1):
    if match(i):
        c = i

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

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ls = len(s)
lt = len(t)

def match(k):
    for i in range(lt):
        if t[i] != s[i+k] and s[i+k] != '?':
            return False
    return True

c = -1
for i in range(ls-lt+1):
    if match(i):
        c = i

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

ans = s[:c].replace('?', 'a')
ans += t
ans += s[len(ans):]
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
key = 0
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if T[j] == S[j+i] or S[j+i] == '?':
            if j == len(T)-1:
                key = 1
                # print('ok{0},{1}'.format(i, j))
                for k in range(j+1):
                    S[i+k] = T[k]
        else:
            break

if key:
    answer = [s.replace('?', 'a') for s in S]
    print(''.join(answer))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
answer_str = ''
answer = ''
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        # print(T[j], S[j+i])
        if T[j] == S[j+i] or S[j+i] == '?':
            if j == len(T)-1:
                while j+1:
                    S[j+i] = T[j]
                    # print(j+i)
                    j -= 1
                answer_str = S[0:i] + T
                # print(answer_str)
            continue
        else:
            break

# print(S)
if len(answer_str):
    answer = [s.replace('?', 'a') for s in S]
    print(''.join(answer))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
answer_str = ''
answer = ''
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        # print(T[j], S[j+i])
        if T[j] == S[j+i] or S[j+i] == '?':
            if j == len(T)-1:
                while j+1:
                    S[j+i] = T[j]
                    # print(j+i)
                    j -= 1
                answer_str = S[0:i] + T
                # print(answer_str)
            continue
        else:
            break

if len(answer_str):
    answer = [s.replace('?', 'a') for s in answer_str]
    print(''.join(answer))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
answer = ''
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        # print(T[j], S[j+i])
        if T[j] == S[j+i] or S[j+i] == '?':
            if j == len(T)-1:
                # print(i, j)
                # print('OK')
                answer = S[0:i] + T 
            continue
        else:
            break

if len(answer):
    print(answer.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
lenS = len(S)
lenT = len(T)

for i in range(lenS - lenT, -1, -1):
    flag = True
    for ii in range(lenT):
        if S[i+ii] == '?' or S[i+ii] == T[ii]:
            continue
        else:
            flag = False
            break
    if flag == True:
        print((S[:i] + T + S[ii + lenT:]).replace('?', 'a'))
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
lenS = len(S)
lenT = len(T)

for i in range(lenS - lenT, -1, -1):
    flag = True
    for ii in range(lenT):
        if S[i+ii] == '?' or S[i+ii] == T[ii]:
            continue
        else:
            flag = False
            break
    if flag == True:
        print((S[:ii] + T + S[ii + lenT:]).replace('?', 'a'))
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys

input = sys.stdin.readline


def main():
    S = input().strip()
    T = input().strip()
    ans = list(S)

    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] == "?":
                continue
            else:
                break
        else:
            m = 0
            for k in range(i, i + len(T)):
                ans[k] = T[m]
                m += 1
            for k in range(len(ans)):
                if ans[k] == "?":
                    ans[k] = "a"
            print("".join(ans))
            exit()
    else:
        print("UNRESTORABLE")


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

moji = []

for i in range(len(S)):
    j = 0
    cnt = 0
    
    while j < len(T) and i+len(T)-1 < len(S):
        if S[i+j] == T[j] or S[i+j] == '?':
            cnt += 1

        else:
            break
        j += 1
    
    if cnt == len(T):
        moji0 = ''
        if i == 0: moji0 = T+S[i+len(T):len(S)]
        elif i+len(T) > len(S)-1: 
            moji0 = S[0:i]+T
        else:
            moji0 = S[0:i]+T+S[i+len(T):len(S)]

        print(moji, moji0)
        
        moji1 = moji0.replace('?', 'a')
        moji.append(moji1)

print(min(moji) if moji != [] else "UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
S = str(input())
T = str(input())

SS = []
for i in range(len(S)) :
  if i + len(T) <= len(S) :
    cnt = 0
    st = S[0:i]
    for j in range(len(T)) :
      if S[i+j] == T[j] or S[i+j] == "?" :
        cnt += 1
        st += T[j]
    if cnt == len(T) :
      SS.append((st+S[i+len(T)-1:-1]).replace("?", "a"))
#print (SS)
if len(SS) > 0 :
  SS.sort()
  print (SS[0])
else :
  print ("UNRESTORABLE")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
def matches(x, t):
    for j in range(len(t)):
        if x[j] != '?' and x[j] != t[j]:
            return False
    return True

valid = False
for i in range(len(s)-len(t), -1, -1):
    if matches(s[i:], t):
        valid = True
        s = s[:i] + t + s[i+len(t):]

if valid:
    print(s.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
def matches(x, t):
    for j in range(len(t)):
        if x[j] != '?' and x[j] != t[j]:
            return False
    return True

valid = False
for i in range(len(s)-len(t)+1):
    if matches(s[i:], t):
        valid = True
        s = s[:i] + t + s[i+len(t):]

if valid:
    print(s.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
sd = input()
t = input()
def matches(x, t):
    for j in range(len(t)):
        if x[j] != '?' and x[j] != t[j]:
            return False
    return True

s = 'UNRESTORABLE'
for i in range(len(sd) - len(t)+1):
    if matches(sd[i:], t):
        s = sd[:i] + t + sd[i+len(t):]
        s = s.replace('?', 'a')
        break
print(s)

Submission status: Wrong Answer

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

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

ns = len(s)
nt = len(t)
for i in range(0, ns-nt+1):
   x = s[i:i+nt]
   ok = 1
   for j in range(nt):
      if (t[j] != x[j] and x[j] != '?'):
         ok = 0
         break

   if (ok == 1):
      ss = s[0:i] + t
      if (i+nt < ns):
         ss = ss + s[i+nt]
      ss = ss.replace('?', 'a')
      exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S_prime = input()
T = input()
lenS = len(S_prime)
lenT = len(T)
existflag = 0

index = 0
for i in range(lenS - lenT, -1, -1):
    index = i
    # print(index)
    for j in range(lenT):
        flag = 1
        if S_prime[i + j] != "?" and S_prime[i + j] != T[j]:
            flag = 0
            break
    if flag == 1:
        existflag = 1
        index += lenS-lenT-index
        # print(existflag)
        break


# print(index)
if existflag == 0:
    print("UNRESTORABLE")
else:
    S = S_prime[:index] + T + S_prime[index+lenT:]

    print(S.replace("?", "a"))

Submission status: Wrong Answer

Solution code:
S_prime = input()
T = input()
lenS = len(S_prime)
lenT = len(T)
existflag = 0

index = 0
for i in range(lenS - lenT, -1, -1):
    index = i
    for j in range(lenT):
        flag = 1
        if S_prime[i + j] != "?" and S_prime[i + j] != T[j]:
            flag = 0
            break
    if flag == 1:
        existflag = 1
        index += lenS-lenT-index
        # print(existflag)
        break


# print(index)
if existflag == 0:
    print("UNRESTORABLE")
else:
    S = S_prime[:index] + T + S_prime[index+lenT:]

    print(S.replace("?", "a"))

Submission status: Wrong Answer

Solution code:
S_prime = input()
T = input()
lenS = len(S_prime)
lenT = len(T)
existflag = 0

index = 0
for i in range(lenS - lenT, -1, -1):
    index = i
    for j in range(lenT):
        flag = 1
        if S_prime[i + j] != "?" and S_prime[i + j] != T[j]:
            flag = 0
            break
    if flag == 1:
        existflag = 1
        index += lenS-lenT-index
        # print(existflag)
        break


# print(index)
if existflag == 0:
    print("UNRESTORABLE")
else:
    S = ""
    for k in range(lenS):
        if index <= k <= index + lenT-1:
            S += T[k - index]
        else:
            if S_prime[k] == "?":
                S += "a"
            else:
                S += S_prime[k]

    print(S)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

snum=len(s)
tnum=len(t)
chk=False
for i in range(snum-tnum+1):
    #print(s[i:i+tnum])
    cnt=0
    for j in range(i,i+tnum):
        #print(s[j],t[j-i])
        if s[j]==t[j-i]:
            cnt+=1
        elif s[j] =="?":
            cnt+=1
        
    if cnt==tnum:
        s[i:i+tnum]=t
        chk=True
    else:
        if s[i]=="?":
            s[i]="a"

for i in range(snum):
    if s[i]=="?":
        s[i]="a"

if chk==True:
    print("".join(s))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

snum=len(s)
tnum=len(t)
chk=False
for i in range(snum-tnum+1):
    #print(s[i:i+tnum])
    cnt=0
    for j in range(i,i+tnum):
        #print(s[j],t[j-i])
        if s[j]==t[j-i] and s[j] !="?":
            cnt+=1
        elif s[j] =="?":
            cnt+=1
        
    if cnt==tnum:
        s[i:i+tnum]=t
        chk=True
    else:
        if s[i]=="?":
            s[i]="a"
if chk==True:
    print("".join(s))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
a = input()
b = input()
ans = ''
f = 1
a = a[::-1]
b = b[::-1]
for ii in range(len(a)-len(b)+1):
    s =0
    for i,j in zip(a[ii:ii+len(b)+1],b):
        if i==j or i =='?':s+=1
    if s == len(b):
        rec = ii
        f = 2
        break
if f != 2:
    print('UNRESTORABLE')
else:
    for i in range(len(a)):
        if i == rec:ans+=b
        elif i < rec+len(b):continue
        elif a[i] == '?':ans+='a'
        else:ans +=a[i] 
    print(ans[::-1])

Submission status: Wrong Answer

Solution code:
a = input()
b = input()
ans = ''
f = 1
a = a[::-1]
b = b[::-1]
for ii in range(len(a)-len(b)+1):
    s =0
    for i,j in zip(a[ii:ii+len(b)+1],b):
        if i==j or i =='?':s+=1
    if s == len(b):
        rec = ii
        f = 2
        break
if f != 2:
    print('UNRESTORABLE')
else:
    for i in range(len(a)):
        if i == rec:ans+=b
        elif i < rec+len(b):continue
        elif a[i] == '?':ans+='a'
        else:ans +=a[i] 
print(ans[::-1])

Submission status: Wrong Answer

Solution code:
S = str(input())
T = str(input())
N = len(S)-len(T)+1
M = len(T)
ans = None

for i in range(N):
    flag = 0
    for j in range(M):
        if S[i+j]==T[j] or S[i+j] == "?":
            flag += 1
        else:
            break
    if flag == M:
        ans = S[:i]+T+S[i+M:]
        ans = ans.replace('?','a')
        print(ans)

if ans is None:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:

S = input()
T = input()

len_t = len(T)
G = []

for i in range(len(S)-len_t+1):
  valid = True
  onlyQ = True
  for j in range(len_t):
    if S[i+j] != "?" and S[i+j] != T[j]:
      valid = False
    if S[i+j] == T[j]:
      onlyQ = False

  if valid and not onlyQ:
    SL = list(S)
    for j in range(len_t):
      SL[i+j] = T[j]
    SL = list(map(lambda x: "a" if x == "?" else x, SL))
    G.append("".join(SL))

print(min(G, default="UNRESTORABLE"))

Submission status: Wrong Answer

Solution code:
S_prime = list(map(str, input()))
T = list(map(str, input()))

len_S = len(S_prime)
len_T = len(T)

un = 1

for i in reversed(range(0, len_S - len_T + 1)):
	match = 1
	for j in range(i, i + len_T):
		# print(S_prime[j], T[j - i])
		if S_prime[j] == "?": continue
		if not S_prime[j] == T[j - i]:
			match = 0
			break
	if match:
		un = 0
		# print(i)
		init = i
		break
		
if un:
	print("UNRESTORABLE")
else:
	for i in range(init, init + len_T):
		S_prime[i] = T[i - init]
	
	for i in range(len_S):
		if S_prime[i] == "?":
			S_prime[i] = "a"
	
	print(S_prime)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s=input().strip()
t=input().strip()
last=-1
lastsp=-1
for i in range(len(s)-len(t)+1):
    flg=True
    flgsp=True
    for j in range(len(t)):
        #print(s[i+j],t[j])
        #print(flg,flgsp)
        if s[i+j]==t[j]:
            continue
        else:
            flgsp=False

        if s[i+j]=="?":
            continue
        else:
            flg=False
    #print(flgsp,flg)
    if flgsp:
        lastsp=i
    if flg:
        last=i
    #print(lastsp,last,i)
ans=""
if lastsp>=0:
    #print("A")
    for i in range(len(s)):
        if s[i]!="?":
            ans+=s[i]
        else:
            ans+="a"
elif last>=0:
    #print("B")
    for i in range(last):
        if s[i]!="?":
            ans+=s[i]
        else:
            ans+="a"
    ans+=t
    for i in range(len(s)-len(t)-last):
        if s[i]!="?":
            ans+=s[i]
        else:
            ans+="a"
else:
    ans="UNRESTORABLE"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s=input().strip()
t=input().strip()
last=-1
lastsp=-1
for i in range(len(s)-len(t)+1):
    flg=True
    flgsp=True
    for j in range(len(t)):
        #print(s[i+j],t[j])
        #print(flg,flgsp)
        if s[i+j]==t[j]:
            continue
        else:
            flgsp=False

        if s[i+j]=="?":
            continue
        else:
            flg=False
    #print(flgsp,flg)
    if flgsp:
        lastsp=i
    if flg:
        last=i
    #print(lastsp,last,i)
ans=""
if lastsp>=0:
    for i in range(len(s)):
        if s[i]!="?":
            ans+=s[i]
        else:
            ans+="a"
elif last>=0:
    for i in range(last):
        if s[i]!="?":
            ans+=s[i]
        else:
            ans+="a"
    ans+=t
else:
    ans="UNRESTORABLE"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s=input().strip()
t=input().strip()
last=0
lastsp=0
for i in range(len(s)-len(t)+1):
    flg=True
    flgsp=True
    for j in range(len(t)):
        if s[i+j]==t[j]:
            continue
        elif s[i+j]=="?":
            flgsp=False
        else:
            flgsp=False
            flg=False
    if flgsp:
        lastsp=i
    if flg:
        last=i
ans=""
if lastsp:
    for i in range(len(s)):
        if s[i]!="?":
            ans+=s[i]
        else:
            ans+="a"
elif last:
    for i in range(last):
        if s[i]!="?":
            ans+=s[i]
        else:
            ans+="a"
    ans+=t
else:
    ans="UNRESTORABLE"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s=input().strip()
t=input().strip()
last=0
lastsp=0
for i in range(len(s)-len(t)+1):
    flg=True
    flgsp=True
    for j in range(len(t)):
        if s[i+j]==t[j]:
            continue
        elif s[i+j]=="?":
            flgsp=False
        else:
            flg=False
    if flgsp:
        lastsp=i
    if flg:
        last=i
ans=""
if lastsp:
    for i in range(len(s)):
        if s[i]!="?":
            ans+=s[i]
        else:
            ans+="a"
elif last:
    for i in range(last):
        if s[i]!="?":
            ans+=s[i]
        else:
            ans+="a"
    ans+=t
else:
    ans="UNRESTORABLE"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s=input().strip()
t=input().strip()
if len(s)<len(t):
    print("UNRESTORABLE")
    exit()
lis=[]
for i in range(len(s)-len(t)+1):
    flg=True
    for j in range(len(t)):
        if s[i+j]==t[j] or s[i+j]=="?":
            continue
        else:
            flg=False
    if flg:
        lis.append(i)
ans=""
if lis:
    for i in range(lis[-1]):
        if s[i]!="?":
            ans+=s[i]
        else:
            ans+="a"
    ans+=t
else:
    ans="UNRESTORABLE"
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s=input().strip()
t=input().strip()
lis=[]
for i in range(len(s)-len(t)+1):
    flg=True
    for j in range(len(t)):
        if s[i+j]==t[j] or s[i+j]=="?":
            continue
        else:
            flg=False
    if flg:
        lis.append(i)
        last=i
ans=""
if lis:
    for i in range(last):
        if s[i]!="?":
            ans+=s[i]
        else:
            ans+="a"
    ans+=t
else:
    ans="UNRESTORABLE"
print(ans)