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: Accepted

Solution code:
# -*- coding: utf-8 -*-
s = input()
t = input()
result = []
for i in range(len(s)-len(t)+1):
    restorable = True
    for j in range(len(t)):
        if (s[i+j] != "?") & (s[i+j] != t[j]):
            restorable = False
            break
    if restorable:
        tmp_s = []
        tmp_s.append(s[0:i].replace("?", "a"))
        tmp_s.append(t)
        tmp_s.append(s[i+len(t):len(s)+1].replace("?", "a"))
        result.append("".join(tmp_s))

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

Submission status: Accepted

Solution code:
s=input()
t=input()
if len(s)<len(t):
	print("UNRESTORABLE")
	exit()
d=[]
for i in range(len(s)-len(t)+1):
	cnt=0
	for j in range(len(t)):
		if s[i+j]=="?" or s[i+j]==t[j]:
			cnt+=1
		else:
			break
	if cnt==len(t):
		p=""
		for j in range(i):
			if s[j]=="?":
				p+="a"
			else:
				p+=s[j]
		for j in range(i,len(t)+i):
			p+=t[j-i]
		for j in range(len(t)+i,len(s)):
			if s[j]=="?":
				p+="a"
			else:
				p+=s[j]
		d.append(p)
if len(d)==0:
	print("UNRESTORABLE")
else:
	print(min(d))

Submission status: Accepted

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

N, M = len(S), len(T)

if N < M:
    print('UNRESTORABLE')
else:
    for i in range(max(0,N-M), -1, -1):
        # 今着目しているSの部分
        # 後ろから探査
        now = S[i:i+M]

        # nowにTを入れられるかチェック
        for j in range(M):
            if now[j] == '?' or now[j] == T[j]:
                continue
            else:
                break
        else:
            # 入れられるならその部分をTに置換
            S = S[0:i] + T + S[i+M:N]
            # 残った?をaに置換
            S = S.replace('?', 'a')
            print(S)
            break
    else:
        # どこにもTを入れられなかったら
        print('UNRESTORABLE')

Submission status: Accepted

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


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

    A = []
    for i in range(len(S)-len(T)+1):
        flg = True
        for j in range(len(T)):
            if S[i+j:i+j+1] not in [T[j:j+1], '?']:
                flg = False
        
        if flg:
            K = S[:i] + T + S[i+len(T):]
            A.append(K.replace('?', 'a'))
    
    if len(A)==0 or len(S)<len(T):
        print('UNRESTORABLE')
        return
    print(min(A))


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if len(S)>=len(T):
    emptylists=[]
    flag=True
    for x in range(len(S)+1-len(T)):
        judgement=1 if all(  S[-(x+j)]=="?" or S[-(x+j)]==T[-j] for j in range(1,len(T)+1)) else 0
        if judgement==1:
            flag=False
            if x==0:
                words=str(S[:-len(T)]+T)
                changed=words.replace("?","a")
                emptylists.append(changed)
                
                
            else:
                words=S[:-len(T)-x]+T+S[-x:]
                changed=words.replace("?","a")
                emptylists.append(changed)
        else:
            continue
        ans=sorted(emptylists)

    if flag:
        print("UNRESTORABLE")
    else:
        print(ans[0])
        
if len(S)<len(T):
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    s = list(str(input().rstrip('\n')))
    t = str(input().rstrip('\n'))
    for i in range(len(s) - len(t), -1, -1):
        ts = s[i:i + len(t)]
        b = True
        for j in range(len(t)):
            if ts[j] != "?" and ts[j] != t[j]:
                b = False
                break
        if b:
            for j in range(len(t)):
                s[i + j] = t[j]
            for j in range(len(s)):
                if s[j] == "?":
                    s[j] = "a"
            print("".join(s))
            exit()
    print("UNRESTORABLE")


if __name__ == '__main__':
    slove()

Submission status: Accepted

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

t = float('inf')
for i in range(len(S2)-len(T), -1, -1):
    flag = True
    for j in range(len(T)):
        if S2[i+j] == '?':
            continue
        if S2[i+j] != T[j]:
            flag = False
            break
    if flag:
        t = i
        break
        
if t == float('inf'):
    print('UNRESTORABLE')
    exit()
else:
    S2 = S2.replace('?', 'a')
    answer = S2[:t] + T + S2[t+len(T):]
    print(answer)

Submission status: Accepted

Solution code:
S,T=input(),input()
N=len(S)
M=len(T)
U=[]

ans="UNRESTORABLE"
if N>=M:
  for i in range(N-M+1):
    cnt=0
    for j in range(M):
      if S[i+j]==T[j] or S[i+j]=="?":
        cnt+=1
        #print(cnt)
    if cnt==M:
      U.append((S[:i]+T+S[i+M:]).replace("?","a"))
U.sort()
#print(U)

if len(U)>0:
  ans=U[0]
print(ans)

Submission status: Accepted

Solution code:
S = str(input())
T = str(input())
ans = []
for i in range(len(S) - len(T) + 1):
  for j in range(len(T)):
    if S[i+j] not in ('?', T[j]):
      break
  else:
    U = S[:i] + T + S[i+len(T):]
    ans.append(U.replace('?', 'a'))
print(min(ans) if ans else 'UNRESTORABLE')

Submission status: Accepted

Solution code:
D = list(input())
T = list(input())

d_len = len(D)
t_len = len(T)

flag = 0
p = -1

#後ろの?から入れられるかを試す
#入れられた最短の後ろに入れる
#それ以外の文字は?とする
#入れられる場所がなければUNRESTORABLEを表示

for i in range(d_len - t_len, -1, -1):
        #i文字目に対してチェック
        for j in range(t_len):
            if flag == 1:
                break

            if D[i+j] == '?' or D[i+j] == T[j]:
                if j == t_len - 1:
                    flag = 1
                    p = i
                    break
            else:
                break
    
if flag == 1:
    #他の?を全て置換して表示
    c = 0

    while True:
        if c == p:
            print("".join(T),end="")
            c += t_len
        elif c >= d_len:
            break
        elif D[c] == '?':
            print("a",end="")
            c += 1
        else:
            print(D[c],end="")
            c += 1
    
    print()

else:
    print("UNRESTORABLE")

Submission status: Accepted

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

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

Submission status: Accepted

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

for i in range(-1,len(T)-len(S)-2,-1):
  f=1
  for j in range(-1,-1*len(T)-1,-1):
    if S[i+j+1]==T[j] or S[i+j+1]=="?":pass
    else:f=0
  if f==1:
    S=list(S)
    for j in range(-1,-1*len(T)-1,-1):
      S[i+j+1]=T[j]
    for k in range(len(S)):
      if S[k]=="?":S[k]="a"
    print("".join(S))
    exit(0)
print("UNRESTORABLE")

Submission status: Accepted

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

S.reverse()
T.reverse()


cnt=False
cnti = 0

for i in range(0, len(S)-len(T)+1):
    if cnt:break
    for j in range(len(T)):
        if S[i+j]=='?' or S[i+j]==T[j]:
            cnt = True
            cnti=i
        else:
            cnt=False
            break

if not cnt:print('UNRESTORABLE')
else:
    for i in range(len(T)):
        S[i+cnti] =T[i]

    S.reverse()
    S = ''.join(S)
    print(S.replace('?', 'a'))

Submission status: Accepted

Solution code:
S = list(input())[::-1]
T = list(input())[::-1]
UNRESTORABLE = True

for i in range(len(S) - len(T) + 1):
    if all((S[i+j] == "?" or S[i+j] == T[j]) for j in range(len(T))):
        UNRESTORABLE = False
        break
if UNRESTORABLE:
    print("UNRESTORABLE")
else:
    ans = []
    for k in range(len(S)):
        if i <= k <= i + len(T) - 1:
            ans.append(T[k-i])
        elif S[k] == '?':
            ans.append('a')
        else:
            ans.append(S[k])

    print(''.join(ans[::-1]))

Submission status: Accepted

Solution code:
s = input().rstrip()
t = input().rstrip()
s = s[::-1]
t = t[::-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:
        res = s[:i] + t + s[i + len(t):]
        print(res.replace('?', 'a')[::-1])
        exit()
print('UNRESTORABLE')

Submission status: Accepted

Solution code:
s=input()
t=input()
f=0
e=len(t)
flg=0
while e<=len(s):
  tmp=s[f:e]
  for i in range(len(t)):
    if tmp[i]!=t[i] and tmp[i]!='?':
      break
    if i==len(t)-1:
      ans=s[:f]+t+s[e:]
      flg=1
  f+=1
  e+=1
if flg==0:
  print('UNRESTORABLE')
else:
  print(ans.replace('?','a'))

Submission status: Accepted

Solution code:
import re
S_ = input()
T = input()
Tr = T[::-1]
Sr = S_[::-1]
reg = "".join(map(lambda x: "[{}?]".format(x), Tr))
ans = re.sub(reg, Tr, Sr, count=1)
if ans.count(Tr)==1:
    print(ans.replace("?", "a")[::-1])
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import sys
from pprint import pprint

s = sys.stdin.readline().strip()
t = sys.stdin.readline().strip()

len_s = len(s)
len_t = len(t)
# print(len_s, len_t)

cand = []
for i in range(0, len_s - len_t + 1):
    a = list(s)
    flag = True
    for j in range(len_t):
        # print(s[i+j], t[j])
        if s[i+j] == "?":
            a[i+j] = t[j]
        elif s[i+j] != t[j]:
            flag = False
            break
    if flag:
        cand.append(a)

if cand:
    print("".join(cand[-1]).replace("?", "a"))
    sys.exit()
else:
    print("UNRESTORABLE")

Submission status: Accepted

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

li=[]
for i in range(len(s)-len(t)+1):
    if s[i]==t[0] or s[i]=='?':
        check=1
        tid=1
        if len(t)==1:
            li.append(s[:i-len(t)+1]+t+s[i+1:])
        else:

            while True:
                if s[i+1] ==t[tid] or s[i+1]=='?':

                    check+=1
                    i+=1
                    tid+=1

                    if check==len(t):
                        li.append(s[:i-len(t)+1]+t+s[i+1:])
                        break
                else:
                    break

li2=[]      

for i in li:

    li2.append(i.replace('?','a'))
    

li2.sort()


print(li2[0] if li2 else 'UNRESTORABLE')

Submission status: Accepted

Solution code:
import sys
from bisect import *
from collections import *
from copy import deepcopy
from heapq import *
from itertools import *
from math import *
from operator import *
from pprint import *

sys.setrecursionlimit(10**8)

input = sys.stdin.readline

def main():
    """ main """
    S = input().rstrip()
    T = input().rstrip()
    slen = len(S)
    tlen = len(T)
    if slen < tlen:
        print('UNRESTORABLE')
        return 0

    changable_idx = None
    for i in range(slen-tlen+1):
        for idx,t in enumerate(T):
            if S[i+idx] != '?' and S[i+idx] != t:
                break
        else:
            changable_idx = i

    if changable_idx != None:
        S = S[:changable_idx] + T + S[changable_idx+tlen:]
        print(S.replace('?','a'))
    else:
        print('UNRESTORABLE')
        return 0

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def matchtest(S,T):
    tlen = len(T)
    slen = len(S)

    ans = -1
    for i in range(slen-tlen,-1,-1):
        found = True
        for j in range(tlen):
            if S[i+j] == '?' or S[i+j] == T[j]:
                pass
            else:
                found = False
                break
        if found == True:
            ans = i
            break
    return ans

S = input()
T = input()

pos = matchtest(S,T)
if pos == -1:
    ans = 'UNRESTORABLE'
else:
    ans = ''
    for i in range(len(S)):
        if pos <= i and i < pos+len(T):
            ans += T[i-pos]
        else:
            if S[i] != '?':
                ans += S[i]
            else:
                ans += 'a'

print(ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
L = len(S)
LL = len(T)

anslist = []
for i in range(L):
    if (S[i] == T[0] or S[i] == "?") and i+LL<=L:
        flag = 0
        for j in range(1,LL):
            if not(S[i+j] == T[j] or S[i+j] == "?"):
                flag = 1
        if flag == 0:
            anslist.append(i)

ans = "z"*51
LLL = len(anslist)
for i in range(LLL):
    j = anslist[i]
    tmp = ""
    for k in range(j):
        if S[k] == "?":
            tmp += "a"
        else:
            tmp += S[k]
    tmp += T
    for k in range(j+LL,L):
        if S[k] == "?":
            tmp += "a"
        else:
            tmp += S[k]
    if tmp < ans:
        ans = tmp
if ans == "z"*51:
    print("UNRESTORABLE")
else:
    print(ans)

Submission status: Accepted

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

for i in range(len(S)-len(T),-1,-1):
  flag = True
  for j in range(len(T)):
    if S[i+j] != '?' and S[i+j] != T[j]:
      flag = False
  if flag:
    S = S[:i]+T+S[i+len(T):]
    S = S.replace('?','a')
    print(S)
    exit()

print('UNRESTORABLE')

Submission status: Accepted

Solution code:
import bisect


def main(S, T):
    for i in range(len(S)-len(T), -1, -1):
        flag = True
        for j in range(len(T)):
            if not (S[i+j] == '?' or S[i+j] == T[j]):
                flag = False
                break
        if flag:
            for k, c in enumerate(S):
                if i <= k <= i+j:
                    S[k] = T[k-i]
                elif S[k] == '?':
                    S[k] = 'a'
            return ''.join(S)
    return 'UNRESTORABLE'


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

Submission status: Accepted

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

    top = -1
    for head in range(len(S) - len(T)+1):
        for i in range(len(T)):
            if T[i] == S[head + i] or S[head + i] == "?":
                continue
            else:
                break
        else:
            top = head

    if top == -1:
        print("UNRESTORABLE")
    else:
        password = S[:top] + T + S[top + len(T):]
        password = password.replace("?", "a")
        print(password)


if __name__ == "__main__":
    main()

Submission status: Accepted

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 = sys.stdin.readline().rstrip()
T = sys.stdin.readline().rstrip()
SL = len(S)
TL = len(T)

# 置換不要なパターン
for i in range(SL - TL + 1):
    PS = S[i:TL + i]
    if PS == T:
        print(S.replace('?', 'a'))
        exit()

S = list(S)
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 + i), TR):
            SR[j] = t
        break

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

Submission status: Accepted

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

import re

s = s.replace("?", ".")[::-1]
t = t[::-1]

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

else:
    ans = "UNRESTORABLE"

print(ans)

Submission status: Accepted

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

found = False
for i in range(len(sd) - len(t), -1, -1):
    for j in range(len(t)):
        if sd[i+j] != "?" and sd[i+j] != t[j]:
            break
    else:
        ans = sd[:i] + t + sd[i+len(t):]
        ans = ans.replace("?", "a")
        break
else:
    ans = "UNRESTORABLE"

print(ans)

Submission status: Accepted

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) + 1):
        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: Accepted

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(ans)
else:
    print("UNRESTORABLE")

Submission status: Accepted

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

# 後ろから見ていく
for i in range(len(S)-len(T), -1, -1):
  flag = True
  for di in range(len(T)):
    if S[i+di] == '?' or S[i+di] == T[di]:
      continue
    else:
      flag = False
      break
  if flag:
    ans = [None]*len(S)
    for j in range(len(S)):
      if i <= j < i+len(T):
        ans[j] = T[j-i]
      elif S[j] == '?':
        ans[j] = 'a'
      else:
        ans[j] = S[j]
    print(*ans, sep='')
    exit()
print('UNRESTORABLE')

Submission status: Accepted

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


def check(S1, S2):
    for i in range(len(S1)):
        if S1[i] == S2[i] or S1[i] == "?":
            continue
        else:
            return(False)

    return(True)


ans_list = []
for i in reversed(range(len(S_) - len(T) + 1)):
    result = check(S_[i:i+len(T)], T)
    if result:
        ans = list(S_)
        for j in range(len(T)):
            ans[i+j] = T[j]
        for j in range(len(ans)):
            if ans[j] == "?":
                ans[j] = "a"
        ans_list.append("".join(ans))

if len(ans_list) == 0:
    print("UNRESTORABLE")
else:
    print(min(ans_list))

Submission status: Accepted

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


def check(S1, S2):
    for i in range(len(S1)):
        if S1[i] == S2[i] or S1[i] == "?":
            continue
        else:
            return(False)

    return(True)


for i in reversed(range(len(S_) - len(T) + 1)):
    result = check(S_[i:i+len(T)], T)
    if result:
        for j in range(len(T)):
            ans[i+j] = T[j]
        for j in range(len(ans)):
            if ans[j] == "?":
                ans[j] = "a"
        print("".join(ans))

        exit(0)

print("UNRESTORABLE")

Submission status: Accepted

Solution code:
S,T=input(),input();l,m=len(S),len(T)
for i in range(l-m+1):
 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: Accepted

Solution code:
def chk(a,b):
	if len(a)!=len(b):
		return False
	for i in range(len(a)):
		if a[i]!=b[i] and a[i]!='?' and b[i]!='?':
			return False
	return True

s=list(input())
t=list(input())
ans=[]

l=len(s)-len(t)+1
for i in range(l):
	if chk(s[i:i+len(t)],t):
		ans.append((''.join(s[:i]+t+s[i+len(t):])).replace('?','a'))
if ans==[]:
	print('UNRESTORABLE')
else:
	print(min(ans))

Submission status: Accepted

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

def main(S_,T):
    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")

if __name__ == '__main__':
    S_ = "".join(list(reversed(input())))
    T = "".join(list(reversed(input())))
    main(S_,T)

Submission status: Accepted

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

judge = False
for i in range(N-M+1):
    c = N-M-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[:N-M-i]+T+S[N-i:]
        break
#出力
if judge:
    for i in range(N):
        print(S[i] if S[i] != "?" else "a",end="")
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import copy

S = list(input())
T = list(input())
candidate = []
if len(T) > len(S):
    print("UNRESTORABLE")
    exit()
for i in range(len(S) - len(T) + 1):
    c = 0
    A = copy.copy(S)
    check = False
    for j in range(len(T)):
        if A[i + j] == T[j]:
            c += 1
        elif A[i + j] == "?":
            A[i + j] = T[j]
            c += 1
        else:
            break
        if c == len(T):
            candidate = A
print("".join(candidate).replace("?", "a") if candidate else "UNRESTORABLE")

Submission status: Accepted

Solution code:
def solve():
    s = input()
    t = input()
    ls = len(s)
    lt = len(t)
    for i in range(ls - lt + 1)[::-1]:
        if all([si == ti or si == "?" for si, ti 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: Accepted

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

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

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

for i in reversed(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: Accepted

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

Submission status: Accepted

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: Accepted

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: Accepted

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

def main():
    s = input().strip()
    t = input().strip()
    ans = []
    for i in range(len(s) - len(t) + 1):
        ok = True
        # print(s[i:i+len(t)])
        for j in range(len(t)):
            if s[i+j] == t[j] or s[i+j] == "?":
                pass
            else:
                ok = False
                break
        if ok:
            ans.append((s[:i] + t + s[i+len(t):]).replace("?", "a"))
    if len(ans) > 0:
        print(min(ans))
    else:
        print("UNRESTORABLE")



if __name__ == "__main__":
    main()

Submission status: Accepted

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: Accepted

Solution code:
s = input()
t = input()
li = []

if t in s:
    if "?" in s:
        print(s.replace("?", "a"))
        exit()
    else:
        print(s)
        exit()

for i in range(len(s) - len(t) + 1):
    target = s[i:i+len(t)]
    flag = True
    for j in range(len(t)):
        if target[j] != "?" and target[j] != t[j]:
            flag = False
    if flag:
        li.append(s[:i] + t + s[i+len(t):])

if len(li) == 0:
    print("UNRESTORABLE")
    exit()

li = sorted(li)
print(li[0].replace("?", "a"))

Submission status: Accepted

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)):]
            S = S.replace('?', 'a')
            ans.append(S)


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

Submission status: Accepted

Solution code:
def main():
    s = input()
    t = input()
    s_len = len(s)
    t_len = len(t)
    def t_check(t_true,t_can):
            for tt,tc in zip(t_true,t_can):
                if tc != '?' and tt != tc:
                    return False
            else:
                return True

    if s_len < t_len:
        print('UNRESTORABLE')
    elif s_len == t_len:
        if t_check(t,s):
            print(t)
        else:
            print('UNRESTORABLE')
    else:
        ans = ""
        for i in range(s_len - t_len + 1)[::-1]:
            if t_check(t,s[i:i+t_len]):
                ans = s[:i] + t + s[i+t_len:]
                ans = ans.replace('?','a')
                print(ans)
                break
        else:
            print('UNRESTORABLE')
if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
SS = input()
T = input()
ans = "z"*(len(SS)+1)

for i in range(len(SS) - len(T) + 1):
	temp = "?"*i + T + "?"*(len(SS)-i-len(T))
	cond = True
	for i in range(len(SS)):
		if SS[i] == "?" or temp[i] == "?":
			continue
		else:
			if SS[i] != temp[i]:
				cond = False
	if cond:
		temp_2 = []
		for i in range(len(SS)):
			if SS[i] == "?" and temp[i] == "?":
				temp_2.append("a")
			elif SS[i] == "?" and temp[i] != "?":
				temp_2.append(temp[i])
			else:
				temp_2.append(SS[i])
		temp_3 = "".join(temp_2)
		if temp_3 <= ans:
			ans = temp_3

if ans == "z"*(len(SS)+1):
	print("UNRESTORABLE")
else:
	print(ans)

Submission status: Accepted

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:
        for j in range(len(t) + i, len(s_dash)):
            candidate.append('a' if s_dash[j] == '?' else s_dash[j])
        ans.append("".join(candidate))
if 0 == len(ans):
    print("UNRESTORABLE")
else:
    print(sorted(ans)[0])

Submission status: Accepted

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 = []
  check = True
  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]]
      check = False
      break
    else:
      ans += [s[i+j]]
  if len(t) <= i+len(t) and check:
    for k in range(i+len(t), len(s)):
      ans += [s[k]]
  if len(ans) == len(s) and check:
    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: Accepted

Solution code:
s_d = input()
t = input()
if len(s_d) >= len(t):
    for i in range(len(s_d) - len(t), -1, -1):
        possible = True
        for j in range(len(t)):
            if s_d[i + j] == t[j] or s_d[i + j] == "?":
                continue
            else:
                possible = False
                break
        if possible == False:
            continue
        else:
            s = s_d[:i] + t + s_d[i+len(t):]
            for k in range(len(s)):
                if s[k] == "?":
                    s = s[:k] + "a" + s[k+1:]
            break
else:
    possible = False
if possible == True:
    print(s)
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import copy

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:
            result=copy.copy(S)
            for j in range(len(T)):
                flag=True
                result[i+j]=T[j]
                

# print("=================")
if flag==True:
    print("".join(result).replace("?","a"))
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
S = input()
T = input()
s_list = []
for i in range(len(S)):
    if i+len(T) > len(S):
        break
    j=0
    for _ in range(len(T)):
        if S[i+j] == '?' or S[i+j] == T[j]:
            j+=1
            continue
        break
    if j==len(T):
        s_list.append(S[:i] + T + S[i+len(T):])
if len(s_list) > 0:
    s_list.sort()
    print(s_list[0].replace('?', 'a'))
else:
    print("UNRESTORABLE")