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:
S=input()
T=input()

for i in reversed(range(len(S)-len(T)+1)):
    st=S[i:i+len(T)]
    t=1
    for j in range(len(T)):
        if(st[j]!='?' and st[j]!=T[j]):
            t=0
            break
    if(t==1):
        S=S.replace('?','a')
        print(S[:i]+T+S[i+len(T):])
        exit()
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s=list(input())
t=list(input())
ans=[0 for _ in range(len(s))]
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
    if cnt==len(t):
        ans[i]=i+1
mark=ans.index(max(ans))
if sum(ans)!=0:
    for j in range(len(s)):
        if mark<=j and j<mark+len(t):
            s[j]=t[j-mark]
        elif s[j]=='?':
            s[j]='a'
    print(''.join(s))
else:print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def check(sp, s):
    
    for i in range(len(s)):
        if sp[i] != '?' and s[i] is not None and sp[i] != s[i]:
            return False
    return True

def main():
    sp = input()
    n = len(sp)
    t = input()
    s = [None] * n

    for i in range(n):
        if sp[i] != '?':
            s[i] = sp[i]
    anss = list()
    # i~ i+len(t)文字目までをtとした場合
    for i in range(n-len(t)+1):
        p = [None]*n
        for j in range(len(t)):
            p[i+j] = t[j]
        if check(sp, p):
            ans = str()
            for i in range(n):
                if p[i] is None:
                    if sp[i] == '?':
                        ans += 'a'
                    else:
                        ans += sp[i]
                else:
                    ans += p[i]
            anss.append(ans)
    if anss:
        anss.sort()
        print(anss[0])
        return
    print('UNRESTORABLE')
    return
            

    #print(check(sp, 'atcoder'))

if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3

import sys

DEBUG = False

def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().rstrip().split(sep)]

def read_int():
    return int(sys.stdin.readline())

def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return

def solve(s, t):
    if len(t) > len(s):
        return "UNRESTORABLE"

    ans = None
    for i in range(0, len(s)):
        can_insert = True
        for j in range(0, len(t)):
            pos = i + j
            if pos >= len(s) or (s[pos] != '?' and s[pos] != t[j]):
                can_insert = False
                break
        if not can_insert:
            continue
        inserted = s[0:i] + t + s[i + len(t):]
        inserted = inserted.replace("?", "a")

        if ans is None or inserted < ans:
            ans = inserted

    if ans is None:
        return "UNRESTORABLE"
    return ans


def main():
    s = sys.stdin.readline().rstrip()
    t = sys.stdin.readline().rstrip()
    print(solve(s, t))
    

if __name__ == "__main__":
    main()

Submission status: Accepted

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

ans1 = "z"*len(S)
pos = ""
num = 0
for i in range(len(S)-len(T)+1):
    sl = ""
    sl = S[i:(i+len(T))]
    for j in range(len(T)):
        pos = ""
        if(sl[j] != "?" and sl[j] != T[j]):
            break
    else:
        pos += S[:i]+T+S[(i+len(T)):]
        if(ans1 > pos):
            ans1 = pos
            Flg = True
                
if(Flg == True):
    ans1 = ans1.replace("?", "a") 
    print(ans1)
else:
    print("UNRESTORABLE")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def check(a, b):
    for j in range(len(a)):
        if b[j] == a[j] or a[j] == '?':
            continue
        else:
            return False
    return True

ans_list = []
s_prime = input()
t = input()
for i in range(len(s_prime) - len(t) + 1):
    if check(s_prime[i:i+len(t)], t):
        s = s_prime[:i] + t + s_prime[i+len(t):]
        ans = s.replace('?', 'a')
        ans_list.append(ans)
ans_list.sort()
if len(ans_list) > 0:
    print(ans_list[0])
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
bag = []
for i in range(len(s)-len(t)+1):
  st = False
  for j in range(len(t)):
    if j==0 and (s[i+j]==t[j] or s[i+j]=='?'):
      st = True 
    elif st==True and (s[i+j]==t[j] or s[i+j]=='?'):
      pass 
    elif st==True and (s[i+j]!=t[j] and s[i+j]!='?'):
      st = False 
      break 

  if st:
    bag += [i]

if len(bag)==0:
  print('UNRESTORABLE')
  exit()
else:
  idx = max(bag)
  s[idx:idx+len(t)] = t 

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

print(''.join(s))

Submission status: Accepted

Solution code:
b = list(input())
t = list(input())
kouho = []
if len(b) < len(t):
  print("UNRESTORABLE")
else:
  for i in range(len(b)-len(t)+1):
    a = b[:]
    ok = True
    for j in range(len(t)):
      if a[i+j] == "?" or a[i+j] == t[j]:
        a[i+j] = t[j]
      else:
        ok = False
    if ok:
      for j in range(len(a)):
        if a[j] == "?":
          a[j] = "a"
      kouho.append("".join(a))
  if kouho:
    kouho.sort()
    print(kouho[0])
  else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import numpy as np
S = np.array(list(input()))
T = np.array(list(input()))
for i in range(len(S), -1, -1):
    subset = S[i:(i + len(T))]
    if len(subset) == len(T):
        # print('subset', subset)
        # print((subset == '?') | (subset == T))
        # print('all', np.all((subset == '?') | (subset == T)))
        if np.all((subset == '?') | (subset == T)):
            S[i:(i + len(T))] = T
            S[S == '?'] = 'a'
            # print('S', S)
            print(''.join(S))
            break
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
def matching(s,t):
    ret = True
    for s_, t_ in zip(s,t):
        if not (s_ == t_ or s_ == '?'):
            ret = False
            break
            
    return ret

def solve():
    S = input()
    T = input()
    L_S = len(S)
    L_T = len(T)
    pos = -1
    match = False
    for i in range(L_S-L_T+1)[::-1]:
        if matching(S[i:i+L_T],T):
            pos = i
            break
            
    if pos >= 0:
        result = ''.join(list(map(lambda x: 'a' if x=='?' else x, S)))
        print(result[:pos]+T+result[pos+L_T:])
    else:
        print('UNRESTORABLE')
        
solve()

Submission status: Accepted

Solution code:
import re

S = input()
T = input()

for i in range(len(S) - len(T), -1, -1):
    if re.fullmatch(S[i:i+len(T)].replace('?', '.'), T):
        print((S[:i] + T + S[i+len(T):]).replace('?', 'a'))
        break
else:
    print('UNRESTORABLE')

Submission status: Accepted

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

n = len(S)-len(T)+1
ans = []
for i in range(n):
    SS = list("?"*(i) + T + "?"*(n-i-1))
    flag = True
    for i in range(len(S)):
        if S[i]=="?" or S[i]==SS[i]:
            pass
        elif S[i]!="?" and SS[i]=="?":
            SS[i]=S[i]
        else:
            flag = False
    if flag:
        ans.append("".join(SS).replace("?","a"))

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

Submission status: Accepted

Solution code:
S = input()
T = input()
koho = []

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:
        koho.append(S[:i]+T+S[i+len(T):])
result = sorted([s.replace('?', 'a') for s in koho])
print('UNRESTORABLE' if result == [] else result[0])

Submission status: Accepted

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

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

for i in range(len(s) - len(t), -1, -1):
  if not match(i):
    continue

  for j in range(i):
    print('a' if s[j] == '?' else s[j], end='')
  print(t, end='')
  for j in range(i+len(t), len(s)):
    print('a' if s[j] == '?' else s[j], end='')
  print()
  exit()
    
print('UNRESTORABLE')

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
checker = 0
for i in range(len(s)-len(t), -1, -1):
    if all(s[i+j]==t[j] or s[i+j]=="?" for j in range(len(t))):
        checker = 1
        for j in range(len(t)):
            s[i+j] = t[j]
        s = ["a" if s[I]=="?" else s[I] for I in range(len(s))]
        break
if checker:
    print("".join(s))
else:
    print("UNRESTORABLE")

Submission status: Accepted

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

s1 = len(s)
t1 = len(t)

ans = []

for i in range(s1 - t1 + 1):
    s_tmp = s[i:i+t1]
    flag = True
    for j in range(t1):
        if s_tmp[j] != '?' and s_tmp[j] != t[j]:
            flag = False
    if flag:
        s_tmp2 = s[:i] + t + s[i+t1:]
        s_tmp3 = ''
        for j in range(s1):
            if s_tmp2[j] == '?':
                s_tmp3 += 'a'
            else:
                s_tmp3 += s_tmp2[j]
        ans.append(s_tmp3)

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

Submission status: Accepted

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

S_l = len(Sd)
T_l = len(T)

ans_list = []

for i in range(S_l-T_l+1):
    flag = 0
    for j in range(T_l):
        if Sd[i+j] != '?':
            if Sd[i+j] != T[j]:
                flag = 1
                break

    if flag == 0:
        ans = Sd[:i] + T + Sd[i+T_l:]
        ans_list.append(ans.replace('?', 'a'))

if len(ans_list) == 0:
    print('UNRESTORABLE')
else:
    print(sorted(ans_list)[0])

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
sl = len(S)
tl = len(T)


# 辞書順最小の文字列を出力するため、
# できるだけ’?'は'a'で置き換えたいので、後ろから探索する
flag = False
for i in range(sl - tl, -1, -1):
    P = S[i:i+tl]
    for p, t in zip(P, T):
        if p != '?' and p != t:
            break
    else:  #合致する文字列が存在した
        S[i:i+tl] = T
        flag = True
        break

if flag:        
    print(''.join(['a' if s == '?' else s for s in S]))
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
import re

sp=input()
t=input()

strlst=[]

def makeStrLex(i):
    s=sp[:i]+t+sp[i+len(t):]
    s=s.replace('?','a')

    return s

for i in range(len(sp)-len(t)+1):
    spat=sp[i:i+len(t)].replace('?','.')
    repat=re.compile(spat)
    
    if repat.match(t):
        strlst.append(makeStrLex(i))

if len(strlst)>0:
    print(sorted(strlst)[0])
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    s = readline().strip()
    t = readline().strip()
    ls = len(s)
    lt = len(t)

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

    ind = -1
    for i in range(ls-lt+1):
        flag = True
        for j,t_ in enumerate(t):
            if s[i+j] == "?":
                continue
            if t_ != s[i+j]:
                flag = False
        if flag:
            ind = i
    
    if ind == -1:
        print("UNRESTORABLE")
        exit()
    
    ans = s[:ind] + t + s[ind+lt:]
    ans = ans.replace("?", "a")
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
S=input()
T=input()
N=len(S)
n=len(T)
core=[]
for i in range(N-n,-1,-1):
    S1=S
    time=0
    for j in range(i,i+n):
        if S[j]=="?":
            time+=1
            continue
        elif S[j]==T[j-i]:
            time+=1
            continue
        else:
            break
    if time==n:
        S1=S1[:i]+T+S1[i+n:]
        S1=S1.replace("?","a")
        core.append(S1)

if len(core)==0:
    print("UNRESTORABLE")
else:
    core.sort()
    print(core[0])

Submission status: Accepted

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

n = len(s)
m = len(t)

s.reverse()
t.reverse()

ans = []
for i in range(n-m+1):
    flg = True
    for j in range(m):
        if s[i+j] != '?' and s[i+j] != t[j]:
            flg = False

    if flg == True:
        s2 = s
        for j in range(n):
            if s[j] == '?':
                s2[j] = 'a'
        for j in range(m):
            s2[i+j] = t[j]
        ans.append(s2)
    #print(flg)
#print(ans)
ans.sort()
if len(ans) == 0:
    print('UNRESTORABLE')
else:
    print(''.join(reversed(ans[0])))

Submission status: Accepted

Solution code:
s = input()
t = input()
for i in range(len(s)-len(t),-1,-1):
	#print (i)
	flg = True
	for j, k in enumerate(list(t)):
		#print (j, k)
		if s[i:i+len(t)][j] == "?":
			continue
		if k != s[i:i+len(t)][j]:
			flg = False
			break
	if flg == True:
		x = s[:i].replace("?","a") + t + s[i+len(t):].replace("?","a")
		print (x)
		exit()
print ("UNRESTORABLE")

Submission status: Accepted

Solution code:
import sys
from itertools import permutations
import math
from operator import itemgetter

s=input()
t=input()

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

flag2=True
for i in reversed(range(len(s)-len(t)+1)):
    if (s[i]==t[0]) | (s[i]=='?'):
        flag=True
        for j in range(1,len(t)):
            if (s[i+j]!=t[j]) & (s[i+j]!='?'):
                flag=False
        if flag:
            s=s[:i]+t+s[i+len(t):] 
            s=s.replace('?','a')
            print(s)
            flag2=False
            sys.exit()

if flag2:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
#!/usr/bin/env pypy3
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
import copy

def main():
    mod=10**9+7
    S=list(input())
    T=list(input())
    ns=len(S)
    nt=len(T)
    
    ans=[]#ここに候補を突っ込む，残りの?は全部aにしておく，最後にソートして一番小さいのを出力
    
    #Sのn文字目からTが始まるとして，行ける？
    def match(n):
        for i in range(nt):
            #文字不一致かつ?じゃないならダメ
            if S[n+i]!=T[i]:
                if S[n+i]!="?":
                    return False
                    
        return True
    
    #Sのn文字目からTに変更
    def make(n):
        temp=copy.deepcopy(S)
        for i in range(nt):
            temp[n+i]=T[i]
        for i in range(ns):
            if temp[i]=="?":
                temp[i]="a"
               
        a=(''.join(map(str, temp)))
        return a
    
    
    
    for i in range(ns-nt+1):
        if match(i):
            ans.append(make(i))
            
    if len(ans)!=0:      
        ans.sort()
        print(ans[0])
    else:
        print("UNRESTORABLE")
        

    

main()

Submission status: Accepted

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

## 辞書順最小、を満たすために後ろから探索する
for s in range(len(S)-1, len(T)-2, -1):
  ## 1.一番後ろの文字が条件を満たした
  if (S[s] == T[-1]) or S[s] == '?':
    
    ## 2.そのまま、後ろから順に条件を満たすかを確認していく
    for t in range(1,len(T),1):
      if (S[s-t] != T[-t-1]) and S[s-t] != '?':
        break
    ## 条件をクリアしたindexが見つかった場合
    else:
      ## 全ての?をaに置き換えて
      S = S.replace('?', 'a')
      ## 条件をクリアしたindexをTと置換する
      ans = S[:s-len(T)+1] + T + S[s+1:]
      
      ## loopを抜ける
      break
else:
  ans = 'UNRESTORABLE'

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

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

    for pre in range(i):
        if s[pre]=="?":
            kouho.append("a")
        else:
            kouho.append(s[pre])

    for j in range(len(t)):
        if s[i+j]=="?":
            kouho.append(t[j])
        elif s[i+j] == t[j]:
            kouho.append(t[j])
        else:
            match=False
            break

    for post in range(i+j+1,len(s)):
        if s[post]=="?":
            kouho.append("a")
        else:
            kouho.append(s[post])
    if match:
        ans.append(kouho)

if len(ans)==0:
    print("UNRESTORABLE")
else:
    ans.sort()
    print(*ans[0],sep="")

Submission status: Accepted

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

ls = len(sp)
lt = len(t)
ok = 1
s = list(sp)
for i in range(ls-1, -1, -1):
    ok = 1
    for j in range(lt):
        if i + j >= ls:
            ok = 0
            break
        if (sp[i+j] == t[j]) or (sp[i+j] == '?'):
            continue
        ok = 0
        break
    if ok == 1:
        for si in range(i, i+lt):
            s[si] = t[si - i]
        break

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

Submission status: Accepted

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    S, T = args
    candidates = []
    for i in range(len(S)-len(T)+1):
        text = S[:i]

        for j in range(len(T)):
            if S[i+j] != T[j] and S[i+j] != '?':
                text = ''
                break
            text += T[j]

        if text:
            text += S[len(text):]
            candidates.append(text.replace('?', 'a'))

    candidates.sort()

    return candidates[0] if candidates else 'UNRESTORABLE'


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Accepted

Solution code:
def main():
    s=list(input())
    t=list(input())
    n=len(s)
    l=len(t)
    
    judge=False
    for i in range(n-l,-1,-1):
        flag=True
        for j,st in enumerate(s[i:i+l]):
            if st!='?' and st!=t[j]:
                flag=False
                break
        if flag:
            s[i:i+l]=t
            judge=True
            break
    
    if judge:
        for i in range(n):
            if s[i]=='?':
                s[i]='a'
        print(''.join(s))
    else:
      print('UNRESTORABLE')
        
if __name__=='__main__':
    main()

Submission status: Accepted

Solution code:
import copy
def solve():
    S_d = list(input())
    T = list(input())

    end = len(S_d) - 1
    first = end - len(T) + 1
    while first >= 0:
        t_i = 0 
        for s_i in range(first, end+1):
            if T[t_i] != S_d[s_i] and S_d[s_i] != '?':
                break
            t_i += 1
        else:
            break

        first -= 1
        end -= 1

    else:
        print('UNRESTORABLE')
        exit(0)
    
    ans = copy.deepcopy(S_d)
    t_i = 0
    for i in range(first, end+1):
        ans[i] = T[t_i]
        t_i += 1
    
    ans = ''.join(ans).replace('?','a')
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Accepted

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

ans = []

for index, s in enumerate(S):
  if s == '?' or s == T[0]:
    if index+len(T)-1 > len(S)-1:
        break

    for indexs, t in enumerate(T):
      if S[index+indexs] != t and S[index+indexs] != '?':
        break
    else:
      ans.append(S[0:index]+T+S[index+len(T):])


if len(ans) == 0:
  print("UNRESTORABLE")
else:
  ans.sort()
  print(ans[0].replace('?', 'a'))

Submission status: Accepted

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

LEN_S = len(S)
LEN_T = len(T)

if LEN_S < LEN_T:
  print('UNRESTORABLE')
  exit()

def isEquals(s):
  for i in range(LEN_T):
    if T[i] == s[i] or s[i] == '?':
      pass
    else:
      return False
  return True

answers = []
for i in range(LEN_S - LEN_T+1):
  if isEquals(S[i:i+LEN_T]):
    text = S[:i].replace('?', 'a') + T + S[i+LEN_T:].replace('?', 'a')
    answers.append(text)
  else:
    pass

if 0 < len(answers):
  answers = sorted(answers)
  print(answers[0])
  
else:
  print('UNRESTORABLE')

Submission status: Accepted

Solution code:
import itertools
import math
import sys
import heapq
from collections import Counter
from collections import deque
from fractions import gcd
from functools import reduce
sys.setrecursionlimit(4100000)
from functools import lru_cache
INF = 1 << 60

#ここから書き始める
s = input()
t = input()
index = INF
for i in reversed(range(len(s) - len(t) + 1)):
    flag = True
    for j in range(i, i + len(t)):
        if s[j] != "?" and s[j] != t[j - i]:
            flag = False
    if flag:
        index = i
        break
    if flag:
        break
if index == INF:
    print("UNRESTORABLE")
else:
    s = s[:index] + t + s[index + len(t):]
    s = s.replace("?", "a")
    print(s)

Submission status: Accepted

Solution code:
def check(a, b):
    for i, j in zip(a, b):
        if i == "?" or i == j:
            pass
        else:
            return False
    return True


def make(a):
    x = ""
    for i in a:
        if i == "?":
            x += "a"
        else:
            x += i
    return x


s = list(input())
t = list(input())
n = len(t)
ans = []
for i in range(len(s)-n+1):
    if check(s[i:n+i], t):
        w = s[:i] + t + s[n+i:]
        ans.append(make(w))

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

Submission status: Accepted

Solution code:
def main():
    key_str = input()
    substring = input()
    answer = "z" * len(key_str)
    for i in range(len(key_str) - len(substring) + 1):
        if key_str[i] == substring[0] or key_str[i] == "?":
            for j in range(len(substring)):
                if not key_str[i + j] == substring[j] and not key_str[i + j] == "?":
                    break
            else:
                answer = min((key_str[:i] + substring + key_str[i + len(substring):]).replace("?", "a"), answer)
    print(answer if not answer == "z" * len(key_str) else "UNRESTORABLE")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

ls = len(s)
lt = len(t)
match = -1

for i in range(ls-lt+1):
    for j in range(lt):
        if s[i+j] == t[j] or s[i+j] == '?':
            pass
            #continueはここで処理が終わってしまう
        else:
            break
            
        if j == lt - 1:
            match = i
        
for i in range(ls):
    if s[i] == '?':
        s[i] = 'a'
        
for i in range(lt):
    s[match+i] = t[i]
        
if match < 0:
    print("UNRESTORABLE")
else:
    print(''.join(s))

Submission status: Accepted

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

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

ans = ''
for i in range(len(s) - len(t) + 1):
  for j in range(len(t)):
    if s[i+j] in ('?',t[j]):
      continue
    else:
      break
  else:
    ans = s[:i] + t + s[i+len(t):]
    break
else:
  print('UNRESTORABLE')
  
for c in ans[::-1]:
  print('a' if c=='?' else c,end= '')
print()

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S=input()
T=input()
def condition(str,num):
    flag=0
    for i in range(num,num+len(str)):
        if S[i]!='?' and S[i]!=str[i-num]:
            flag=1
    return flag==0
data=[]
for i in range(0,len(S)-len(T)+1):
    if condition(T,i):
        data.append(i)
if data!=[]:
    m=max(data)
    ans=''
    for i in range(0,len(S)):
        if i<m:
            if S[i]!='?':
                ans+=S[i]
            else:
                ans+='a'
        elif m+len(T)-1>=i:
            ans+=T[i-m]
        else:
            if S[i]!='?':
                ans+=S[i]
            else:
                ans+='a'
    print(ans)
else:
    print('UNRESTORABLE')

Submission status: Accepted

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

fir = -1
for i in range(len(s) - len(t) + 1):
    tmp = i
    flg = True
    for j in range(len(t)):
        if s[i + j] == "?" or s[i + j] == t[j]:
            continue
        else:
            flg = False
            break
    if flg:
        fir = tmp
if fir == -1:
    print("UNRESTORABLE")
else:
    ans = s[:fir] + t + s[fir + len(t):]
    print(ans.replace("?", "a"))

Submission status: Accepted

Solution code:

def solve():
    input_string = input()
    part_string = input()

    for i in range(len(input_string) - len(part_string), -1, -1):
        possible_part_string = input_string[i:i+len(part_string)]  # part_stringの可能性のある文字列
        for j in range(len(part_string) + 1):  # 1つ多くループしているのは最後の処理のため
            if j == len(part_string):
                result = input_string[:i] + part_string + input_string[i + len(part_string):]
                result = result.replace("?", "a")
                print(result)
                return  # 今回のテストケースの終了
            if possible_part_string[j] == "?" or possible_part_string[j] == part_string[j]:
                continue
            else:  # 再度ずらして探索する
                break

    print("UNRESTORABLE")
solve()

Submission status: Accepted

Solution code:
def solve():
    input_string = input()
    part_string = input()

    for i in range(len(input_string) - len(part_string), -1, -1):
        possible_part_string = input_string[i:i+len(part_string)]
        for j in range(len(part_string) + 1):  # 1つ多くループしているのは最後の処理のため
            if j == len(part_string):
                result = input_string[:i] + part_string + input_string[i + len(part_string):]
                result = result.replace("?", "a")
                print(result)
                return
            if possible_part_string[j] == "?":
                continue
            elif possible_part_string[j] != part_string[j]:
                break

    print("UNRESTORABLE")
solve()

Submission status: Accepted

Solution code:
s=str(input())
t=str(input())
s=list(s)
t=list(t)
count2=0
count=0
for i in range(len(s)-len(t),-1,-1):
    for j in range(len(t)):
        #print(s[i+j])
        if s[i+j]!='?' and  s[i+j]!=t[j]:
            count=0
            break
        else:
            count+=1
        #print(count)
    
    if count==len(t):
        for z in range(len(s)):
            if z<i or i+len(t)-1<z:
                if s[z]=='?':
                    print("a",end="")
                else:
                    print(s[z],end="")
            else:
                #print(count2)
                print(t[count2],end="")
                count2+=1
        exit()
    count=0
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
def main():
  
  S=input()
  T=input()
  
  check=False
  ind=[]
  for i,l in enumerate(S):
    if i+len(T)>len(S):
      break
    for j,m in enumerate(T):
      if S[i+j]==m or S[i+j]=="?":
        check=True
      else:
        check=False
        break
    if check==True:
      ind.append(i)
  
  word=[]
  for i in ind:
    w=(S[:i]+T+S[i+len(T):]).replace("?","a")
    word.append(w)
  word.sort()
  
  if len(word)==0:
    print("UNRESTORABLE")
  else:
    print(word[0])

if __name__=="__main__":
  main()

Submission status: Accepted

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

slen = len(s)
Tlen = len(T)
ans = "UNRESTORABLE"
if slen >= Tlen:
    for i in range(slen - Tlen + 1)[::-1]:
        for j in range(Tlen):
            if not s[i+j] in ("?", T[j]):
                break
        else:
            ans = s
            ans = ans[:i] + T + ans[i+Tlen:]
            ans = ans.replace("?", "a")
            break

print(ans)

Submission status: Accepted

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

n = len(sd)
m = len(t)
s = []

# sd を後ろから見ていき、 t の入りそうな場所を探す
for i in range(n - m, -1, -1):
    t_kamo = sd[i:i + m]
    for j in range(m + 1):
        # 1文字ずつ順に入りうるか調べ、最後まで入るなら "?" を "a" に置き換えて出力
        if j == m:
            print((sd[:i] + t + sd[i + len(t):]).replace("?", "a"))
            exit()
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break

print("UNRESTORABLE")

Submission status: Accepted

Solution code:
def solve():
    S = input()
    T = input()
    ls = len(S)
    lt = len(T)
    lst = []
    w_lst = []
    if ls < lt:
        return 'UNRESTORABLE'
    if ls == lt:
        for i in range(ls):
            if S[i] == '?': continue
            elif not S[i] == T[i]: return 'UNRESTORABLE'
        return T
    for d in range(ls - lt + 1):
        eq = True
        for i in range(lt):
            if S[i + d] == '?':
                continue
            elif not S[i + d] == T[i]:
                eq = False
                break
        if eq:
            lst.append(d)
    if len(lst) == 0:
        return 'UNRESTORABLE'
    for d in lst:
        w = S[0:d] + T + S[d + lt:]
        for i in range(ls):
            if w[i] == '?':
                w = w[0:i] + 'a' + w[i + 1:]
        w_lst.append(w)
    return min(w_lst)
if __name__ == '__main__':
    print(solve())

Submission status: Accepted

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

S = S[::-1]
T = T[::-1]

for i in range(len(S)):
    match = True
    for j in range(len(T)):
        if i + j < len(S):
            if not (T[j] == S[i + j] or S[i + j] == '?'):
                match = False
        else:
            match = False
    if match:
        for j in range(len(T)):
            S = S[:i + j] + T[j] + S[i + j + 1:]
        break
else:
    print('UNRESTORABLE')
    sys.exit()

S = S.replace('?', 'a')
print(S[::-1])