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:
sp = input()
t = input()
len_t = len(t)
len_s = len(sp)
cand = []
part_start = -1

for i in range(len_s - len_t + 1):
    num = 0
    for j in range(len_t):
        if (sp[i + j] == '?' or sp[i + j] == t[j]):
            num += 1
    
    if (num == len_t):
        part_start = i

if part_start != -1:
    # 部分文字列は最後にあったほうがいい?はaで最小化できる可能性があり、文字列の先頭に近い部分にそれらがあったほうがよい
    ans = sp[:part_start] + t + sp[part_start + len_t:]
    ans = ans.replace('?', 'a')
    print(ans)
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
if __name__ == '__main__':
    hidden_key = input()
    flag_string = input()

    key_length = len(hidden_key)
    flag_length = len(flag_string)

    if key_length < flag_length:
        print('UNRESTORABLE')
        exit()

    key_list = list(hidden_key.replace('?', 'a'))

    for i in reversed(range(key_length - flag_length + 1)):
        part_key = hidden_key[i:i + flag_length]
        is_match = True

        for j in range(flag_length):
            if part_key[j] != '?' and part_key[j] != flag_string[j]:
                is_match = False
                break
            
        if is_match:
            for k in range(flag_length):
                key_list[i + k] = flag_string[k]
            print(''.join(key_list))
            break

    if not is_match:
        print('UNRESTORABLE')

Submission status: Accepted

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

pushable = [1] * (len(s) - len(t) + 1) 
for i in range(len(s) - len(t) + 1):
    for j in range(len(t)):
        if s[i+j] != t[j] and s[i+j] != "?":
            pushable[i] = 0
            break

if 1 not in pushable:
    print("UNRESTORABLE")
    exit()

ans = []
for i, p in enumerate(pushable):
    cand = s
    if p:
        for j in range(len(t)):
            cand = cand[:i+j] + t[j] + cand[i+j+1:]
        for j in range(len(s)):
            if cand[j] == "?":
                cand = cand[:j] + "a" + cand[j+1:]
        ans.append(cand)

print(sorted(ans)[0])

Submission status: Accepted

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

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

print('UNRESTORABLE')

Submission status: Accepted

Solution code:
import copy
S=list(input())
S1 = "".join(S)
T=list(input())
T1 = "".join(T)
F = ["?"]*len(T)
F1 = "".join(F)
l =[]
M =[]
index =[]
B = copy.deepcopy(S)
for i in range(len(S)-len(T)+1):
    A = copy.deepcopy(S)
    c = A[i:len(T)+i]
    while "?" in c:
        c[c.index("?")] = T[c.index("?")]
    if c==T:
        A = copy.deepcopy(S)
        A[i:len(T)+i] = c
        while "?"in A:
            A[A.index("?")]="a"
        M.append(A)
if 0<len(M):
    M.sort()
    print("".join(M[0]))
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
S=input()
T=input()
flag=False
for i in range(len(S)-len(T)+1):
    dif=0
    same=0
    s=S[i:i+len(T)]#len(T)
    for j in range(len(T)):
        if s[j]!='?':#sが言葉の時
            if s[j]!=T[j]:
                #print("st",s[i],T[i])
                dif+=1
            else:
                same+=1
#                flag=True

        #else:#?のとき
    if dif==0:
        #dst=S.replace(s,T)
        flag=True
        memo=i#複数replace対策
    



if flag==False:
    print("UNRESTORABLE")
else:
    S=list(S)
    for i in range(len(T)):
        S[i+memo]=T[i]
    
    S=''.join(S)    
    S=S.replace('?','a')
    print(S)

Submission status: Accepted

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

len_Sp = len(Sp)
len_T = len(T)
restorable = False
max_i = 0
if len_Sp >= len_T:
    for i in range(len_Sp - len_T + 1):
        for j in range(len_T):
            if Sp[i + j] != '?' and Sp[i + j] != T[j]:
                break
        else:
            restorable = True
            max_i = i
if restorable:
    Sp[max_i : max_i + len_T] = T
    print(''.join(Sp).replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Accepted

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

len_Sp = len(Sp)
len_T = len(T)
restorable = False
max_i = 0
if len_Sp >= len_T:
    for i in range(len_Sp - len_T, -1, -1):
        for j in range(len_T):
            if Sp[i + j] != '?' and Sp[i + j] != T[j]:
                break
        else:
            #Sp[i : i + len_T] = T
            max_i = max(max_i, i)
            restorable = True
if restorable:
    Sp[max_i : max_i + len_T] = T
    print(''.join(Sp).replace('?', 'a'))
else:
    print('UNRESTORABLE')
#print(''.join(Sp).replace('?', 'a') if restorable else 'UNRESTORABLE')

Submission status: Accepted

Solution code:
a=input()
b=input()
la=len(a)
lb=len(b)
ans="UNRESTORABLE"
for i in range(la-lb+1):
  k=1
  for j in range(lb):
    if a[i+j]=="?":
      continue
    if a[i+j]!=b[j]:
      k=0
  if k==1:
    ans=i
if ans=="UNRESTORABLE":
  print(ans)
else:
  ans=a[:ans]+b+a[ans+lb:]
  print(ans.replace("?","a"))

Submission status: Accepted

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

Tplace = {i:False for i in range(N)}
#print(Tplace)

for i in range(N-len(T)+1):
  counter = 0
  for j in range(len(T)):
    if S2[i+j] == T[j] or S2[i+j] == "?":     
      counter += 1
#      print(S2[i+j],T[j],counter)
      continue
    else:
#      print(2,i,j,S2[i+j])
      break
#  print(3)
  if counter == len(T):
    Tplace[i] = True
#print(Tplace)

ans = []

for key, value in Tplace.items():
  if value:
    tmp = S2[:key] + T + S2[key+len(T):] 
    tmp2 = tmp.replace('?', 'a')
    ans.append(tmp2)
ans.sort()
print(ans[0] if len(ans) > 0 else "UNRESTORABLE")

Submission status: Accepted

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

Submission status: Accepted

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

sl = len(s)
Tl = len(T)
res = "UNRESTORABLE"
for i in range(sl)[::-1]:
    piece = s[i:i+Tl]
    if len(piece)<Tl:
        continue
    flag = True
    for j in range(Tl): 
        if piece[j]!='?' and piece[j]!=T[j]:
            flag = False 
            break
    if flag:
        res = s[:i]+T+s[i+Tl:]
        res = res.replace("?","a")
        break
print(res)

Submission status: Accepted

Solution code:
ss=input();t=input();lens,lent=len(ss),len(t);k=[]
def sst(sss):
  global t
  for i in range(lent):
    if sss[i]!=t[i] and sss[i]!="?":return -1
  return 0
def ch(s):
  ans=""
  for i in s:ans+=(i if i!="?"else"a")
  return ans
for i in range(lens-lent+1):
  if sst(ss[i:i+lent])==0:k.append(ch(ss[:i]+t+ss[i+lent:]))
if len(k)==0:print("UNRESTORABLE");exit()
k.sort();print(k[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

s=input()
t=input()
b=[]

if len(s)-len(t)<0:
    flg=False
else:
    for i in range(len(s)-len(t)+1):
        ans=s
        for j in range(len(t)):
            flg=True
            if s[i+j]=='?' or s[i+j]==t[j]:
                #print(ans)
                ans=ans[:i+j]+t[j]+('' if i+j+1>len(s) else ans[i+j+1:])
            else:
                flg=False
                break
        if flg==True:
            b.append(ans.replace('?','a'))
#print(b)
b.sort()

print(b[0] if len(b)>0 else 'UNRESTORABLE')

Submission status: Accepted

Solution code:
s=input()
t=input()
#print(s,t)

if len(s) < len(t):
    print('UNRESTORABLE') 
elif len(s) == len(t):
  cnt=0
  for i in range(len(s)):
    if s[i] == t[i]:
      cnt+=1
    elif s[i] == '?':
      cnt+=1
  if len(t)==cnt:
    print(t)
  else:
    print('UNRESTORABLE') 
else:
  flag1=0
  for j in range(len(s)-len(t),-1,-1):
    cnt=0
    for i in range(len(t)):
      if s[i+j]==t[i]:
        cnt+=1
      elif s[i+j]=='?':
        cnt+=1
    if cnt==len(t):
      flag1=1
      s=s[0:j]+t+s[j+len(t):]
      s=s.replace('?','a')
      print(s)
    
  if flag1==0:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
s = input()
t = input()
# s = 'c?????a'
# t = 'coder'
errorword = 'UNRESTORABLE'

ls=len(s)
lt=len(t)
if ls < lt:
    print(errorword)
else:
    for i in range(ls-lt,-1,-1):
        is_matched = True
        s_slice = slice(i, i+lt)

        for s_char, t_char in zip(s[s_slice], t):
            # 文字が不一致かつ？以外の場合は文字列不一致のためbreak
            if (s_char != t_char) and s_char != '?':
                is_matched = False
                break
                
        # ここまでbreakせずに来たら文字列一致のため文字列Sを出力
        if is_matched:
            temp_sl1 = slice(0, i)
            temp_sl2 = slice(i+lt, ls+1)
            out_str = '{}{}{}'.format(s[temp_sl1], t, s[temp_sl2])
            print(out_str.replace('?', 'a'))
            break
    
    if not is_matched:
        print(errorword)

Submission status: Accepted

Solution code:
def solve(string):
    s, t = string.split()
    s, t = s[::-1], t[::-1]
    for i in range(len(s)):
        for j in range(min(len(t), len(s) - i)):
            if s[i + j] != t[j] and s[i + j] != "?":
                break
            if j == len(t) - 1:
                return (s[:i] + t + s[i + len(t):])[::-1].replace("?", "a")
    return "UNRESTORABLE"


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
def solve(string):
    s, t = string.split()
    s, t = s[::-1], t[::-1]
    for i, _ in enumerate(s):
        for j, _ in enumerate(t):
            if not (i + j < len(s)) or (s[i + j] != t[j] and s[i + j] != "?"):
                break
            if j == len(t) - 1:
                return (s[:i] + t + s[i + len(t):])[::-1].replace("?", "a")
    return "UNRESTORABLE"


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
def solve(string):
    s, t = string.split()
    s, t = s[::-1], t[::-1]
    for i, _ in enumerate(s):
        if s[i] != t[0] and s[i] != "?":
            continue
        for j, _ in enumerate(t):
            if not (i + j < len(s)) or (s[i + j] != t[j] and s[i + j] != "?"):
                break
            if j == len(t) - 1:
                return (s[:i] + t + s[i + len(t):])[::-1].replace("?", "a")
    return "UNRESTORABLE"


if __name__ == '__main__':
    print(solve('\n'.join([input(), input()])))

Submission status: Accepted

Solution code:
s=input()
t=input()
#print(s,t)

if len(s) < len(t):
    print('UNRESTORABLE') 
elif len(s) == len(t):
  cnt=0
  for i in range(len(s)):
    if s[i] == t[i]:
      cnt+=1
    elif s[i] == '?':
      cnt+=1
  if len(t)==cnt:
    print(t)
  else:
    print('UNRESTORABLE') 
else:
  flag1=0
  for j in range(len(s)-len(t),-1,-1):
    cnt=0
    for i in range(len(t)):
      if s[i+j]==t[i]:
        cnt+=1
      elif s[i+j]=='?':
        cnt+=1
    if cnt==len(t):
      flag1=1
      if j==0:
        s=t+s[len(t):]
      if 0 < j < len(s)-len(t)+1:
        s=s[0:j]+t+s[j+len(t):]
      if j == len(s)-len(t)+1:
        s=s[0:j]+t      
      s=s.replace('?','a')
      print(s)
    
  if flag1==0:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
s = len(S)
t = len(T)
ans = ""

for i in reversed(range(s-t+1)):
    for j in range(t):
        if S[i+j] != T[j] and S[i+j] !="?":
            break
        if j == t-1:
            for k in range(t):
                S[i+k] = T[k]
            s = str("".join(S).replace("?","a"))
            print(s)
            exit()
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import re

S=input().replace('?','.')
T=input()

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

for i in range(len(S)-len(T)+1): #8-5: 0,1,2,3
  l = len(S)-len(T)-i
  r = len(S)-i
  if re.match(S[l:r], T):
    s = S[:l] + T + S[r:]
    print(s.replace('.','a'))
    exit()

print('UNRESTORABLE')

Submission status: Accepted

Solution code:
S=input()
T=input()
def check(i):
    flag=True
    for j in range(len(T)):
        if S[i+j]!='?' and S[i+j]!=T[j]:
            flag=False
            break
    return flag
def search(S,T):
    for i in range(len(S)-len(T),-1,-1):
        if check(i):return i
    return -1
def main(S,T):
    ans=''
    if T not in S:
        idx=search(S,T)
        if idx==-1:
            return 'UNRESTORABLE'
        S=S[:idx]+T+S[idx+len(T):]
    for s in S:
        if s=='?':ans+='a'
        else:ans+=s
    return ans
print(main(S,T))

Submission status: Accepted

Solution code:
import sys
S = input()
T = input()
Slen = len(S)
Tlen = len(T)
if Tlen > Slen:
    print('UNRESTORABLE')
    sys.exit()
start = Slen + 1
for i in range(Slen - Tlen + 1):
    flg = True
    for j in range(Tlen):
        #print("i:j:S[i+j]:T[j]",i,j,S[i+j],T[j])
        if flg == True:
            if (S[i+j] == T[j]) or (S[i+j] == '?'):
                if j == (Tlen -1) and flg == True:
                    start = i
            else:
                flg = False
if start == (Slen + 1):
    print('UNRESTORABLE')
else:
    S2 = S[:start] + T + S[start+Tlen:]
    S3 = S2.replace("?","a")
    print(S3)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
LS = len(S)
LT = len(T)
a = ""
for i in reversed(range(LS - LT + 1)):
    for j in range(LT):
        if S[i + j] != T[j] and S[i + j] != "?":
            break
        if j == LT - 1:
            for k in range(LT):
                S[i + k] = T[k]
            #print("".join(S))
            s = str("".join(S)).replace("?", "a")
            print(s)
            exit()
# S = S.replace("?", "a")
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
LS = len(S)
LT = len(T)
for i in reversed(range(LS - LT + 1)):
    for j in range(LT):
        if S[i + j] != T[j] and S[i + j] != "?":
            break
        if j == LT - 1:
            for k in range(LT):
                S[i + k] = T[k]
            s = str("".join(S)).replace("?", "a")
            print(s)
            exit()
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
LS = len(S)
LT = len(T)
a = ""
for i in reversed(range(LS - LT + 1)):
    for j in range(LT):
        if S[i + j] != T[j] and S[i + j] != "?":
            break
        if j == LT - 1:
            for k in range(LT):
                S[i + k] = T[k]
            #print("".join(S))
            s = str("".join(S)).replace("?", "a")
            print(s)
            exit()
# S = S.replace("?", "a")
print("UNRESTORABLE")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
T = input()
ns = len(S)
nt = len(T)
if ns - nt < 0:
    print('UNRESTORABLE')
    exit()
answer = []
for i in range(ns - nt + 1):
    ans = ''
    t = True
    for j in range(ns):
        if j < i:
            if S[j] == "?":
                ans = ans + 'a'
            else:
                ans = ans + S[j]
        elif j - i >= nt:
            if S[j] == "?":
                ans = ans + 'a'
            else:
                ans = ans + S[j]

        else:
            if S[j] == "?":
                ans = ans + T[j-i]
            else:
                if S[j] == T[j-i]:
                    ans = ans + T[j-i]
                else:
                    t = False
                    break
    if t:
        answer.append(ans)

if len(answer) == 0:
    print('UNRESTORABLE')
else:
    answer.sort()
    print(answer[0])

Submission status: Accepted

Solution code:
S = input()
T = input()
ls = len(S)
lt = len(T)
flag = False
pos = None
ans = ''

for i in range(ls-lt+1):
  flag = True
  for j in range(lt):
    if S[i+j] != T[j] and S[i+j] != '?':
      flag = False
      break
  if flag:
    pos = i

if pos == None:
  print('UNRESTORABLE')
  exit()

ans = S[:pos] + T + S[pos+lt:]

print(ans.replace('?', 'a'))

Submission status: Accepted

Solution code:
S = input()
T = input()
ls = len(S)
lt = len(T)
if ls < lt:
    print('UNRESTORABLE')
    exit()

index = -1
for i in range(ls-lt+1):
    cnt = 0
    for j in range(lt):
        s = S[i+j]
        if s == '?':
            cnt +=1
        if s == T[j]:
            cnt +=1
    if cnt == lt:
        index = i
if index == -1:
    print('UNRESTORABLE')
    exit()
S = S[:index] + T + S[index+lt:]
S = S.replace('?', 'a')
print(S)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
""" AtCoder """

S = list(input())
T = list(input())

s = len(S)
t = len(T)
p = []

check = True
for i in range(s - t + 1):
    for j in range(t):
        if S[i + j] != T[j] and S[i + j] != '?':
            check = False
            break
    if check:
        p.append(i)
    check = True

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

ans = S[:p[0]] + T + S[p[0] + t:]
for j in range(s):
    if ans[j] == '?':
        ans[j] = 'a'

for i in range(len(p)):
    tmp = S[:p[i]] + T + S[p[i] + t:]
    for j in range(s):
        if tmp[j] == '?':
            tmp[j] = 'a'
    if tmp < ans:
        ans = tmp

print("".join(ans))

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]!='?'and s[i+j]!=t[j]:
            break
    else:
        print((s[:i]+t+s[i+len(t):]).replace('?','a'))
        break
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
import re
S=input()
T=input()
position=-100
ans=''
for i in range(len(S)-len(T)+1):
	#SをTの長さだけスライス。後ろから順に試す
	if i==0:
		regexp=r'%s' % S[-(len(T)):].replace('?','\w')
	else:
		regexp=r'%s' % S[-(i+len(T)):-i].replace('?','\w')
	if len(re.compile(regexp).findall(T))==1:
		position=i
		break
if position==-100:
	ans='UNRESTORABLE'
elif position==0:
	ans = S[:-(len(T))].replace('?','a') + T
else:
	ans=S[:-(position+len(T))].replace('?','a') + T + S[-(position):].replace('?','a')
print(ans)

Submission status: Accepted

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

lst = []
for x in range(len(S) - len_T + 1):
    flg = True
    s = S[x:len_T+x]    
    for idx in range(len_T):
        if s[idx] != '?' and s[idx] != T[idx]:
            flg = False
            break
    if flg:
        tmp = S[:x] + T + S[x + len_T:]
        tmp = tmp.replace('?', 'a')
        lst.append(tmp)


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

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
if len(S) < len(T):
	print("UNRESTORABLE")
else:
	S = S[::-1]
	T = T[::-1]
	for i in range(len(S)-len(T)+1):
		if all (T[j] == S[i+j] or S[i+j] == '?' for j in range(len(T))):
			S[i:i+len(T)] = T
			S = S[::-1]
			print("".join(S).replace('?','a'))
			exit()
	print("UNRESTORABLE")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
def equal_or_wildcard(s: str, t: str)->bool:
    for cs, ct in zip(s, t):
        if cs != '?' and cs != ct:
            return False
    return True


def dubious_document2(S: str, T: str)->str:
    ns, nt = len(S), len(T)
    for i in range(ns - nt, -1, -1):
        if equal_or_wildcard(S[i:i+nt], T):
            return (S[:i] + T + S[i+nt:]).replace('?', 'a')
    return 'UNRESTORABLE'


if __name__ == "__main__":
    S = input()
    T = input()
    ans = dubious_document2(S, T)
    print(ans)

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(1000000)
from operator import itemgetter

S1 = input()
T = input()

idx = 100

for i in range(len(S1)-len(T)+1):
    for j in range(len(T)):
        if S1[i+j] == T[j] or S1[i+j] == '?':
            if j == len(T)-1:
                idx = i
            continue
        else:
            break

if idx == 100:
    print("UNRESTORABLE")
    exit()
    
S1 = S1[:idx] + T + S1[idx+len(T):]
S1 = S1.replace('?', 'a')
print(S1)

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)


def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(Sd, T):
    L = len(T)
    for i in range(len(Sd)-L, -1, -1):
        for j in range(L):
            if Sd[i+j] != '?' and Sd[i+j] != T[j]:
                break
        else:
            k = i
            break
    else:
        return 'UNRESTORABLE'

    S = [c for c in Sd]

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

    for i in range(L):
        S[k+i] = T[i]
    
    return ''.join(S)

def main():
    Sd = read_str()
    T = read_str()
    print(slv(Sd, T))


if __name__ == '__main__':
    main()

Submission status: Accepted

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


def main():
    if len(S) < len(T):
        print("UNRESTORABLE")
        return

    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]:
                break
        else:
            print(S[:i].replace("?", "a") + T +
                  S[i + len(T):].replace("?", "a"))
            break
    else:
        print("UNRESTORABLE")

    return


main()

Submission status: Accepted

Solution code:
S = str(input())
T = str(input())
numS=len(S)
numT=len(T)
S+=" "
ref=""
cand=""
judge=True
ans=-1
result=""
for i in range(0,numS-numT+1):
    cand=""
    ref=S[i:i+numT]
    judge=True
    #refについてTと一致させられるか検討
    for j in range(0,numT):
        if(ref[j]!=T[j] and ref[j]!="?"):
            judge=False
    if(judge):
        cand=S[:i]+T+S[i+numT:]
        tmp=""
        for i in range(0,numS):
            if(cand[i]=="?"):
                tmp+="a"
            else:
                tmp+=cand[i]
        if(result==""):
            result=tmp
        else:
            if(result>tmp):
                result=tmp
    #結果が現在のものと比べて優秀かどうかを比較
if(result==""):
    print("UNRESTORABLE")
else:
    print(result)

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S, T = [str(input()) for _ in range(2)]
ans_list = []
for i in range(len(S)):
    if not i+len(T) <= len(S):
        break
    else:
        tmp = S
        # S[i:i+len(T)]のチェック
        flag = True
        for j in range(i, i+len(T)):
            if S[j] == '?':
                # tmp[j] = T[j-i]
                tmp = tmp[:j] + T[j-i] + tmp[j+1:]
            elif S[j] == T[j-i]:
                continue
            else:
                flag = False
                break
        if flag:
            ans_list.append(tmp.replace('?', 'a'))
if ans_list:
    print(sorted(ans_list)[0])
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
import sys

def main():
    input = sys.stdin.readline
    S = [str(c) for c in input().strip()]
    T = [str(c) for c in input().strip()]

    n = len(S) - len(T) + 1
    candidate = []
    for i in range(n):
        check = [False] * len(T)
        for j in range(len(T)):
            if T[j] == S[j+i] or S[j+i] == '?':
                check[j] = True

        if all(check):
            can = ''
            B = S[:i] + T + S[i+len(T):]
            for a in B:
                if a == '?':
                    can += 'a'
                else:
                    can += a

            candidate.append(can)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def f():
    l = []
    for i in range(len(S)):
        if i + len(T) > len(S):
            break
        flag = True
        for j in range(len(T)):
            if S[i + j] not in [T[j], "?"] :
                flag = False
                break
        if flag:
            s = S
            s = s[:i] + T + s[i+len(T):]
            s = s.replace("?", "a")
            l.append(s)
    l.sort()
    if len(l):
        return l[0]
    else:
        return "UNRESTORABLE"

print(f())

Submission status: Accepted

Solution code:
S = input()
T = input()
a = []
for i in range(len(S)):
    ok = True
    for j in range(len(T)):
        if i+j >= len(S):
            ok = False
            break
        if S[i+j] == '?':
            continue
        if S[i+j] != T[j]:
            ok = False
            break
    if not ok:
        continue
    U = list(S)
    for j in range(len(T)):
        U[i+j] = T[j]
    for i in range(len(U)):
        if U[i] == '?':
            U[i] = 'a'
    a.append("".join(U))
if a:
    print(sorted(a)[0])
else:
    print("UNRESTORABLE")

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(len(s)-len(t)+1):
    flg = True
    for j in range(len(t)):
        if not (s[-len(t)-i+j] == "?" or s[-len(t)-i+j] == t[j]):
            flg = False
            break
    
    if flg:
        for j in range(len(t)):
            s_list[-len(t)-i+j] = t[j]
        
        s = "".join(s_list)
        s = s.replace("?", "a")

if s.count("?") > 0:
    print("UNRESTORABLE")
else:
    print(s)

Submission status: Accepted

Solution code:
S = input()
T = input()
flag = False
for i in range(len(S)):
    k = len(S) - i - len(T)
    for j in range(len(T)):
        if k >= 0 and (S[k] == T[j] or S[k] == '?'):
            k += 1
            if j == len(T) - 1:
                flag = True
                st = len(S) - len(T) - i
        else:
            break
    if flag:
        break
ret = ""
if flag:
    for i in range(st):
        if S[i] == '?':
            ret += 'a'
        else:
            ret += S[i]
    ret += T
    for i in range(st + len(T), len(S)):
        if S[i] == '?':
            ret += 'a'
        else:
            ret += S[i]
else:
    ret = "UNRESTORABLE"
print(ret)