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()

offset = len(S) - len(T)

ans = []
for d in range(offset + 1):
    A = ''
    Td = '?' * d + T
    for i in range(len(S)):
        if i < len(Td) and S[i] != Td[i] and '?' not in [S[i], Td[i]]:
            break
        else:
            c = Td[i] if i < len(Td) and Td[i] != '?' else S[i]
            A += c
    else:
        ans.append(A.replace('?', 'a'))

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

Submission status: Accepted

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

offset = len(Sx) - len(T)

ans = 'UNRESTORABLE'
if len(Sx) >= len(T):
    for d in range(offset, -1, -1):
        for j in range(len(T)):
            if Sx[d + j] not in ['?', T[j]]:
                break
        else:
            break
    else:
        print('UNRESTORABLE')
        exit()

    ans = ''
    for i in range(len(Sx)):
        if i < d or d + (len(T) - 1) < i:
            c = Sx[i]
        else:
            c = T[i - d]
        c = 'a' if c == '?' else c

        ans += c

print(ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
X = sorted((S[:i] + T + S[i + len(T):]).replace('?', 'a')
           for i in range(len(S) - len(T) + 1)
           if all(s == '?' or s == t for s, t in zip(S[i:i + len(T)], T)))
print(X[0] if len(X) > 0 else 'UNRESTORABLE')

Submission status: Accepted

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

if len(s) < len(t):
    print('UNRESTORABLE')
    exit()
ansl = []


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')
        ansl.append(ans)

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

Submission status: Accepted

Solution code:
s=input()
t=input()
n=len(s)
m=len(t)
ind=-1
for i in range(n-m+1):
  f=0
  for j in range(m):
    c=s[n-i-1-j]
    if t[m-1-j]!=c and c!='?':
      break
    else:
      f+=1
  if f==m:
    ind=i
    break

if ind==-1:
  print("UNRESTORABLE")
else:
  s=s[:n-ind-m]+t+s[n-ind:]
  s=s.replace('?','a')
  print(s)

Submission status: Accepted

Solution code:
# coding: utf-8

# https://atcoder.jp/contests/abc076/tasks/abc076_c
# 20:47-


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

    len_S = len(S)
    len_T = len(T)

    if len_T > len_S:
        return "UNRESTORABLE"
    
    condicates = []
    
    for i in range(len_S - len_T + 1):
        next_i = False
        part = S[i:i+len_T]
        
        for t, p in zip(T, part):
            if p != "?" and t != p:
                next_i = True
                break
        
        if next_i:
            continue
        
        # T == partの場合
        condicates.append((S[:i] + T + S[i+len_T:]).replace("?", "a"))
    
    return sorted(condicates)[0] if len(condicates) > 0 else "UNRESTORABLE"


print(main())

Submission status: Accepted

Solution code:

s = list(input())
t = list(input())
sn = len(s)
tn = len(t)
bag = []

for i in range(sn-tn+1):
  flag = True
  for j in range(tn):
    if s[i+j] == '?' or s[i+j] == t[j]:
      pass 
    else:
      flag = False 

  if flag:
    bag += [i]


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


def fill(ss, idx):
  for i in range(tn):
    ss[idx+i] = t[i]
  for i in range(sn):
    if ss[i] == '?':
      ss[i] = 'a'

  return ''.join(ss)

s_list = []
for idx in bag:
  ss = s[:]
  s_list += [str(fill(ss, idx))]

s_list.sort()
print(s_list[0])

Submission status: Accepted

Solution code:
Sp = input()
T = input()
len_Sp = len(Sp)
len_T = len(T)
ans = 'UNRESTORABLE'

i = len_Sp - len_T
while(i >= 0):
    isAns = True
    for j in range(len_T):
        if Sp[i + j] != T[j] and Sp[i + j] != '?':
            isAns = False
            break
    if isAns:
        ans = Sp[:i] + T + Sp[i + len_T:]
        ans = ans.replace('?', 'a')
        break
    i -= 1
print(ans)

Submission status: Accepted

Solution code:
Sp = input()
T = input()
len_Sp = len(Sp)
len_T = len(T)
ans = ''
cnt = 0

i = len_Sp-len_T
while(i >= 0):
    j = len_T-1
    while(j >= 0):
        if Sp[i + j] == T[j] or Sp[i + j] == '?':
            cnt += 1
        else:
            cnt = 0
            break
        j -= 1
    if cnt == len_T:
        Sp_list = list(Sp)
        for k in range(len_T):
            Sp_list[i + k] = T[k]
        ans = ''.join(Sp_list)
        ans = ans.replace('?', 'a')
        print(ans)
        break
    i -= 1
if cnt != len_T:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
Sp = input()
T = input()
len_Sp = len(Sp)
len_T = len(T)
ans = ''
cnt = 0

i = len_Sp-len_T
while(i >= 0):
    j = len_T-1
    while(j >= 0):
        if Sp[i + j] == T[j] or Sp[i + j] == '?':
            cnt += 1
        else:
            cnt = 0
            break;
        j -= 1
    if cnt == len_T:
        Sp_list = list(Sp)
        for k in range(len_T):
            Sp_list[i + k] = T[k]
        ans = ''.join(Sp_list)
        ans = ans.replace('?', 'a')
        print(ans)
        break;
    i -= 1
if cnt != len_T:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
S_ = input()
T = input()
len_s, len_t = len(S_), len(T)
i = len_s - len_t
ans = "UNRESTORABLE"
while i != -1:
    isAns = True
    for j in range(len_t):
        if S_[i + j] != '?' and S_[i + j] != T[j]:
            isAns = False
            break
    if isAns:
        ans = S_[:i] + T + S_[i + len_t:]
        ans = ''.join([c if c != '?' else 'a' for c in ans])
        break
    i -= 1
print(ans)

Submission status: Accepted

Solution code:
s=input()
t=input()
n=len(s)
m=len(t)
for i in range(n-1,-1,-1):
    if i+m-1>=n:
        continue
    j=0
    flag=True
    #print(i,end=' i cur\n')
    while j<m:
        if s[j+i]=='?':
            j+=1
        elif s[j+i]==t[j]:
            j+=1
        else:
            flag=False
            break
    if flag:
     #   print(i,end=' i\n')
        for k in range(i):
            if s[k]=='?':
                print('a',end='')
            else:
                print(s[k],end='')
        print(t,end='')
        for k in range(i+m,n):
            if s[k]=='?':
                print('a',end='')
            else:
                print(s[k],end='')
        print()
        import sys
        sys.exit()
print('UNRESTORABLE')

Submission status: Accepted

Solution code:
s=input()
t=input()
strs=[]
S=len(s)
T=len(t)
for i in range(S-T+1):
  flag=0
  for j in range(T):
    if s[i+j]=="?":
      continue
    if s[i+j]!=t[j]:
      flag=1;break
  if flag==0:
    posstr=s[:i]+t+s[i+T:]
    strs.append(posstr.replace("?","a",50))
strs.sort()
if strs==[]:print("UNRESTORABLE")
else:print(strs[0])

Submission status: Accepted

Solution code:
import sys

def main():
  S = input()
  T = input()
  lenS = len(S)
  lenT = len(T)
  for i in range(lenS-lenT,-1,-1):
    sub = S[i:i+lenT]
    for j in range(lenT):
      if sub[j]!=T[j] and sub[j]!="?":
        break
    else:
      S = S[:i]+T+S[i+lenT:]
      S=S.replace("?","a")
      print(S)
      sys.exit()
      break
    continue
  print("UNRESTORABLE")

main()

Submission status: Accepted

Solution code:
import numpy as np
import sys

def main():
  S = input()
  T = input()
  lenS = len(S)
  lenT = len(T)
  for i in range(lenS-lenT,-1,-1):
    sub = S[i:i+lenT]
    for j in range(lenT):
      if sub[j]!=T[j] and sub[j]!="?":
        break
    else:
      S = S[:i]+T+S[i+lenT:]
      S=S.replace("?","a")
      print(S)
      sys.exit()
      break
    continue
  print("UNRESTORABLE")

main()

Submission status: Accepted

Solution code:
S=list(input())
s=len(S)
T=list(input())
t=len(T)
for i in range(s-t+1):
  a=0
  for j in range(t):
    if S[-1-i-j]=="?":
      continue
    if S[-1-i-j]!=T[-1-j]:
      a=1
  if a==0:
    for j in range(s):
      if S[j]=="?":
        S[j]="a"
    S[s-t-i:s-i]=T
    for j in range(s):
      print(S[j],end="")
    print()
    exit()
print("UNRESTORABLE")

Submission status: Accepted

Solution code:

s = input()
t = input()
sl = len(s)
tl = len(t)
res = list(s)

def check(s1, s2):
    for i in range(len(s1)):
        if s1[i] == '?':
            continue
        if s1[i] != s2[i]:
            return False
    return True

for i in range(sl-tl, -1, -1):
    if check(s[i: i+tl], t):
        res[i: i+tl] = t
        res = ['a' if s == '?' else s for s in res]
        break
else:
    res = list('UNRESTORABLE')

print(''.join(res))

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re


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

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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

yn=""
for i in range(len(sd)-len(t)+1):
    ii=len(sd)-len(t)-i
    yn=""
    for j in range(len(t)):
        if sd[ii+j]!=t[j] and sd[ii+j]!="?":
            yn="NG"
            break
    if yn=="NG":
        continue
    else:
        yn="yes"
        break
    
if yn=="NG" or yn=="": 
    print("UNRESTORABLE")
else:
    for j in range(len(t)):
        sd[ii+j]=t[j]
    for j in range(len(sd)):
        if sd[j]=="?":
           sd[j]="a"
    strt="".join(sd)
    print(strt)

Submission status: Accepted

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

ls, lt = len(s), len(t)
ans_i, ans_j = -1, -1
for i in range(ls-lt+1):
    for j in range(lt):
        if s[i+j] == '?' or s[i+j] == t[j]:
            pass
        else:
            break
        if j == lt-1:
            ans_i = i
            ans_j = j

if ans_i > -1 and ans_j > -1:
    idx = 0
    for i in range(ans_i, ans_i+lt):
        if s[i] == '?':
            s[i] = t[idx]
        idx += 1
    for i in enumerate(s):
        if i[1] == '?':
            s[i[0]] = 'a'
    for i in s:
        print(i, end='')
    print()
else:
    print('UNRESTORABLE')

Submission status: Accepted

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

def check(s1, s2):
    for i in range(len(s1)):
        if s1[i] == '?':
            continue
        if s1[i] != s2[i]:
            return False
    return True

for i in range(sl-tl, -1, -1):
    if check(S[i: i+tl], T):
        res[i: i+tl] = T
        res = ['a' if s == '?' else s for s in res]
        break
else:
    res = list('UNRESTORABLE')

print(''.join(res))

Submission status: Accepted

Solution code:
import re
S=input().replace("?", ".")
T=input()
for i in range(len(S)-len(T), -1, -1):
    if re.match(S[i:i+len(T)], T):
        S = S.replace(".", "a")
        print(S[:i]+T+S[i+len(T):])
        break
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import sys

s = input()
t = input()
lenS = len(s)
lenT = len(t)
for i in range(lenS-lenT,-1,-1):
  sub = s[i:i+lenT]
  for j in range(lenT):
    if sub[j]!="?" and sub[j]!=t[j]:
      break
  else:
    s=s.replace("?","a")
    print(s[:i]+t+s[i+lenT:])
    sys.exit()
  continue
  
print('UNRESTORABLE')

Submission status: Accepted

Solution code:
def compare(sub, t):
    for i in range(len(t)):
        if sub[i] == t[i] or sub[i] == '?':
            continue
        else:
            return False
    return True

clear = False
s = input()
t = input()
if len(s) == len(t):
    clear = compare(s, t)
    s = t
for i in range(len(s)-len(t), 0, -1):
    if compare(s[i:i+len(t)], t):
        clear = True
        s = s[:i] + t + s[i+len(t):]
        break
if clear:
    print(s.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
S = input()
T = input()
ls, lt = len(S), len(T)    

ans = 'UNRESTORABLE'
for i in range(ls-lt+1):
    for j in range(lt):
      if S[i+j] not in (T[j], '?'):
        break       
    else:
      ans = (S[:i]+T+S[i+lt:]).replace('?','a')
   
print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

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

for i in range(len(s)-len(t)+1):
    p = s[i:(i+len(t))]
    flag = True
    for j in range(len(t)):
        if p[j] != "?" and p[j] != t[j]:
            flag = False
            break
    if flag:
        memo.append((s[0:i]+t+s[(i+len(t)):len(s)]).replace("?","a"))

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

Submission status: Accepted

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

ans = []
for i in range(len(s)-(len(t)-1)):
    f = True
    for j in range(len(t)):
        if s[j+i] != t[j] and s[j+i] != '?':
            f = False
    if f == True:
        s2 = s[:i] + t + s[i+len(t):]
        s2 = s2.replace('?','a')
        ans.append(s2)



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

Submission status: Accepted

Solution code:
S=input()
T=input()
for i in range(len(S)-len(T),-1,-1):
  a=0
  for j in range(len(T)):
    if S[i+j]=="?":
      continue
    if S[i+j]!=T[j]:
      a=1
      break
  if a==0:
    for j in range(i):
      if S[j]=="?":
        print("a",end="")
      else:
        print(S[j],end="")
    print(T,end="")
    for j in range(i+len(T),len(S)):
      if S[j]=="?":
        print("a",end="")
      else:
        print(S[j],end="")
    exit()
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import sys

s = input()
t = input()

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

Submission status: Accepted

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


def main():
    # Failed to predict input format
    sp = input()
    t = input()
    ans = "~" * len(sp)
    for i in range(len(sp) - len(t) + 1):
        is_ok = True
        for k in range(len(t)):
            if sp[i + k] != "?" and t[k] != sp[i + k]:
                is_ok = False
                break
        if not is_ok:
            continue
        s = list(sp)
        s[i:i + len(t)] = list(t)
        ans = min(ans, "".join(sc if sc != "?" else "a" for sc in s))
    if ans[0] == "~":
        print("UNRESTORABLE")
    else:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Accepted

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

def match(s,t):
    flag=True
    for i in range(len(s)):
        if s[i]!=t[i] and s[i]!='?':
            flag=False
            break
    return flag
    
cand = []
for i in range(len(S_)-len(T)+1):
    if match(S_[i:i+len(T)], T):
        s = S_[:i]+T+S_[i+len(T):]
        s = s.replace('?','a')
        cand.append(s)

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

Submission status: Accepted

Solution code:
S_ = input()
T = input()
S__len = len(S_)
T_len = len(T)

for i in range(S__len - T_len, -1, -1):
    t_kamo = S_[i : i + T_len]
    #print(t_kamo)
    for j in range(T_len + 1):
        if j == T_len:
            print((S_[: i] + T + S_[i + T_len :]).replace('?', 'a'))
            quit()
        if t_kamo[j] == '?':
            continue
        elif t_kamo[j] != T[j]:
            break
print('UNRESTORABLE')

Submission status: Accepted

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

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

for i in range(n - m, -1, -1):
    t_kamo = sd[i : i + m]
    for j in range(m + 1):
        if j == m:
            print((sd[: i] + t + sd[i + len(t):]).replace('?', 'a'))
            quit()
        if t_kamo[j] == '?':
            continue
        elif t_kamo[j] != t[j]:
            break
print('UNRESTORABLE')

Submission status: Accepted

Solution code:
s=input()
l=len(s)
t=input()
k=len(t)
cand=[]
for i in range(l-k+1):
    new=""
    for j in range(l):
        if i<=j<i+k:
            if s[j]=="?":
                new+=t[j-i]
            else:
                if s[j]==t[j-i]:
                    new+=t[j-i]
                else:
                    break
        else:
            if s[j]=="?":
                new+="a"
            else:
                new+=s[j]
    if len(new)==l:
        cand.append(new)
cand.sort()
if len(cand)==0:
    print("UNRESTORABLE")
else:
    print(cand[0])

Submission status: Accepted

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

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import re
s = input()
s = s.replace("?", ".")
t = input()
if len(t) > len(s):
  print("UNRESTORABLE")
else:
  r = []
  for i in range(len(s)-len(t)+1):
    m = re.match(s[i:i+len(t)], t)
    if m is None:
      continue
    r.append((s[:i]+t+s[i+len(t):]).replace(".","a"))
  if not r:
    print('UNRESTORABLE')
    quit()
      
  print(min(r))

Submission status: Accepted

Solution code:
import re
  
  
def solve(s, t):
    s = s.replace('?', '.')
    ls, lt = len(s), len(t)
    if ls < lt:
        return 'UNRESTORABLE'
    ans = []
    for i in range(ls - lt + 1):
        m = re.match(s[i:i + lt], t)
        if m is None:
            continue
        ans.append((s[:i] + t + s[i + lt:]).replace('.', 'a'))
    if not ans:
        return 'UNRESTORABLE'
    return min(ans)
  
  
s = input().strip()
t = input().strip()
  
print(solve(s, t))

Submission status: Accepted

Solution code:
s,y=(input() for i in range(2))
ans="{"*len(s);pa=ans
for i in range(len(s)-len(y)+1):
  for j in range(len(y)):
    if s[i+j]!='?' and s[i+j]!=y[j]:break
  else:ans=min(ans,s[:i].replace("?","a")+y+s[i+len(y):].replace("?","a"))
if pa==ans:print("UNRESTORABLE")
  
else:print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
s2 = s.replace('?', 'a')

ans = 'z' * 99
for i in range(len(s) - len(t)+1):
    u = s2[0:i] + t + s2[i + len(t):]

    ok = True
    for x, y in zip(s, u):
        if x != '?' and x != y:
            ok = False
            break
    if ok:
        ans = min(ans, u)

if ans == 'z' * 99:
    ans = 'UNRESTORABLE'

print(ans)

Submission status: Accepted

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

n_s = len(s)
n_t = len(t)
last_num = -1

base = [i for i,x in enumerate(s) if x == str(t[0]) or "?"]

if n_s >= n_t:
  for i in base:
    if n_s - i >= n_t:
      sign = 0
      for j in range(i,i+n_t):
        if not ((s[j] == t[j-i]) or (s[j] == "?")):
          sign = 1
        
      if sign == 0:
        last_num = i

  if last_num != -1:
    for i in range(last_num,last_num + n_t):
      if s[i] == "?":
        s[i] = t[i-last_num]
    
    if s[0] == "?":
      ans = "a"
    else:
      ans = str(s[0])
                  
    for j in range(1,n_s):
      if s[j] == "?":
        s[j] = "a"
      ans = ans + s[j]
    
  elif last_num == -1:
    ans = "UNRESTORABLE"

else:
  ans = "UNRESTORABLE"

print(ans)

Submission status: Accepted

Solution code:
S = list(input())
T = input()
ls = []
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != "?":
            break
    else:
        ls.append(i)

if ls:
    for j in range(len(T)):
        S[ls[-1]+j] = T[j]
    print("".join(S).replace("?", "a"))
else:
    print("UNRESTORABLE")

Submission status: Accepted

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

res = 'UNRESTORABLE'
for i in range(len(s)-len(t)+1):
    for ss, tt in zip(s[i:i+len(t)], t):
        if ss == '?' or ss == tt:
            continue
        break
    else:
        res = ((s[:i] + t + s[i+len(t):])[::-1]).replace('?', 'a')
        break

print(res)

Submission status: Accepted

Solution code:
s=input()
t=input()
u=[]
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:
    u.append(s[:i].replace('?','a')+t+s[i+len(t):].replace('?','a'))
if len(u)==0:
  print('UNRESTORABLE')
  exit()
u.sort()
print(u[0])

Submission status: Accepted

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

S = input().strip()
T = input().strip()
#-----
S=S[::-1]
T=T[::-1]

i=0
ans=""
flag = False
while i < len(S):

    if ( S[i] == T[0] or S[i] == "?" )  and  (len(S) - i) >= len(T):
        for j,word_t in enumerate(T):
            if word_t == S[i+j] or S[i+j] == "?":
                continue
            else:
                ans += S[i]
                i += 1 
                break
        
        else:
            ans += T + S[i+j+1:]
            flag = True
            break
            #i += (j+1)
            i = len(S)
    
    else:
        ans += S[i]
        i += 1
    
ans=ans[::-1]

if flag:
    ans = ans.replace('?','a')
    print(ans)

else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
ans = [-1, -1]
if len(t) <= len(s):
    for i in range(len(s) - len(t) + 1):
        c = 1
        for j in range(len(t)):
            if s[i + j] != "?" and t[j] != s[i + j]:
                c = 0
                break
        if c == 1:
            ans = [i, i + len(t)]

if ans != [-1, -1]:
    k = []
    for i in range(len(s)):
        if ans[0] <= i < ans[1]:
            k.append(t[i - ans[0]])
        else:
            if s[i] == "?":
                k.append("a")
            else:
                k.append(s[i])
    print("".join(k))
else:
    print("UNRESTORABLE")

Submission status: Accepted

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

n=len(s)
k=len(t)
if k>n:
    print('UNRESTORABLE')
    exit()
mozi=[]
for i in range(n-k+1):
    ok=True
    for j in range(k):
        if s[i+j]==t[j] or s[i+j]=='?':
            pass
        else:
            ok=False
    if ok:
        # print('==s==')
        # print(i)
        # print(s[:i])
        # print(s[i+k:])
        # print('==e==')
        # print(s[:i]+t+s[i+k:])
        mozi.append(s[:i]+t+s[i+k:])

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

for i in range(len(mozi)):
    mozi[i]=mozi[i].replace('?','a')
mozi.sort()
print(mozi[0])

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s = input()
t = input()
flag1 = 0
tmp = ""
for i in range(len(s) - len(t) + 1):
    u = s[i:i + len(t)]
    flag2 = 1
    for j in range(len(t)):
        if u[j] != t[j] and u[j] != "?":
            flag2 = 0
            break
    if flag2 == 1:
        flag1 = 1
        tmp = s[:i] + t + s[i + len(t):]

print(tmp.replace("?", "a")) if flag1 else print("UNRESTORABLE")

Submission status: Accepted

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

import fnmatch

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

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

Submission status: Accepted

Solution code:
def main():
    S = input()
    T = input()
    N = len(S)
    M = len(T)
    for i in range(N-M+1)[::-1]:
        if all(s == t or s == "?" for s, t in zip(S[i:i+M], T)):
            return print(S[:i].replace("?", "a") + T + S[i+M:].replace("?", "a"))
    print("UNRESTORABLE")


if __name__ == '__main__':
    main()

Submission status: Accepted

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

flag = False
def dfs(x, y):
    if y >= len(T):
        global flag
        flag = True
        return
    elif not S[x] in (T[y], '?'):
        return
    
    dfs(x+1, y+1)


ans = "UNRESTORABLE"
for i in range(len(S) - len(T) + 1)[::-1]:
    if S[i] in (T[0], '?'):
        dfs(i, 0)
        if flag:
            ans = S[:i] + T + S[i+len(T):]
            ans = ans.replace('?', 'a')
            break

print(ans)

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
pre_S = S
T = input()
s = len(S)
t = len(T)
key = []
for i in range(len(S)-len(T)+1):
    # print(S[i:i+t])
    same = 0
    for j, y in enumerate(S[i:i+t]):
        if y == "?":
            same += 1
            continue
        else:
            if y == T[j]:
                same += 1
    if same == t:
        # print(S[i:i+t])
        key.append(i)
    # print(y)
# l = list(S)
if key:
    ans = "z" * 60
    for i in key:
        S_ = S[:i] + T + S[i+t:]
        tmp = ""
        for i in range(len(S_)):
            if S_[i] == "?":
                tmp += "a"
            else:
                tmp += S_[i]
        ans = min(ans, tmp)
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
t = STR()
ans = list(deepcopy(s))
i = len(s) - len(t)
while i >= 0:
    flag = True
    for j in range(len(t)):
        if s[i + j] != '?' and s[i + j] != t[j]:
            flag = False
    if flag:
        ans[i:i + len(t)] = list(t)
        break
    i -= 1
if ''.join(ans) == s and '?' in s:
    print('UNRESTORABLE')
    exit()
for i in range(len(ans)):
    if ans[i] == '?':
        ans[i] = 'a'
print(''.join(ans))

Submission status: Accepted

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

L = [set() for _ in range(len(t))]
for i in range(len(t)):
    for j in range(len(s)):
        if s[j] == t[i] or s[j] == '?':
            L[i].add(j)
#print(L)

temp = set(range(len(s)))
for i in reversed(range(len(t))):
    temp = temp & L[i]
    if i != 0:
        temp = list(temp)
        temp = [p-1 for p in temp]
        temp = set(temp)
#print(temp)

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

temp = list(temp)
temp.sort()
id = temp[-1]
s_ = list(s)
t_ = list(t)
s_[id:id+len(t)] = t_
ans = ''
for c in s_:
    if c == '?':
        ans += 'a'
    else:
        ans += c
print(ans)

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
res = -1
for i in range(ls-lt, -1, -1):
    flag = True
    for j in range(lt):
        if s[i+j] == "?":
            pass
        elif s[i+j] == t[j]:
            pass
        elif s[i+j] != t[j]:
            flag = False
    if flag:
        res = i
        break
if res == -1:
    print("UNRESTORABLE")
else:
    s[res:res+lt] = t
    for i in range(ls):
        if s[i] == "?":
            s[i] = "a"
    print("".join(s))

Submission status: Accepted

Solution code:
# zentansaku
S = input()
T = input()
Ns = len(S)
Nt = len(T)

cand = []

N = max(0, Ns - Nt + 1)
for i in range(N):
    for j in range(Nt):
        s = S[i + j]
        t = T[j]
        if s == t or s == "?":
            continue
        else:
            break
    else:
        pre = S[:i].replace("?", "a")
        suf = S[i+j+1:].replace("?", "a")
        cand.append(pre + T + suf)

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

Submission status: Accepted

Solution code:
S = input()
T = input()
if len(S) < len(T):
    print("UNRESTORABLE")
    exit(0)

def compare(s,t):
    if len(s) != len(t):
        return False
    else:
        for k in range(len(s)):
            if s[k] == "?" or t[k] == "?":
                pass
            else:
                if s[k] != t[k]:
                    return False
    return True
ans = []
for k in range(len(S)-len(T)+1):
    if compare(S[k:k+len(T)],T) == True:
        ans.append(S[:k].replace("?","a")+T+S[k+len(T):].replace("?","a"))

if len(ans) > 0:
    print(sorted(ans)[0])
else:
    print("UNRESTORABLE")