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:
NO = "UNRESTORABLE"
S = input()
N = len(S)
T = input()
M = len(T)

candidates = []
for i in range(N - M + 1):
    if all(S[i + j] == "?" or S[i + j] == T[j] for j in range(M)):
        candidates.append((S[:i] + T + S[i + M :]).replace("?", "a"))
if candidates:
    candidates.sort()
    print(candidates[0])
else:
    print(NO)

Submission status: Accepted

Solution code:

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

for k in range(len(S)-len(T),-1,-1):
    f = 1
    for i in range(len(T)):
        if S[k+i] != "?":
            if S[k+i] != T[i]:
                f = 0
                break
    if f == 1:
        ans = ""
        for i in range(k):
            if S[i] == "?":
                ans += "a"
            else:
                ans += S[i]
        ans += T
        for i in range(k+len(T),len(S)):
            if S[i] == "?":
                ans += "a"
            else:
                ans += S[i]
        print(ans)
        exit(0)
print("UNRESTORABLE")

Submission status: Accepted

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


def main():
    s_dash = input()
    t = input()
    s_count = len(s_dash)
    t_count = len(t)
    ans = list()

    for i in range(s_count - t_count + 1):
        si = s_dash[i:i + t_count]

        count = 0

        for sj, tj in zip(si, t):
            if sj == '?':
                count += 1
            elif sj == tj:
                count += 1

        if count == t_count:
            s = s_dash[:i] + t + s_dash[i + count:]
            s = s.replace('?', 'a')
            ans.append(s)

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


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def main():
    S = list(input())
    T = input()
    judge = False
    lastidx = -1
    for i in range(len(S)-len(T)+1):
        judgetmp = True
        for j in range(len(T)):
            if S[i+j] != T[j] and S[i+j] != "?":
                judgetmp = False
                break
        if judgetmp:
            judge = True
            lastidx = i
    if not judge: return "UNRESTORABLE"
    for i in range(len(T)):
        S[lastidx+i] = T[i]
    return "".join(S).replace("?", "a")

print(main())

Submission status: Accepted

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


def read():
    S = list(input().strip())
    T = list(input().strip())
    return S, T


def solve(S, T):
    k = -1
    for i in range(len(S) - len(T), -1, -1):
        count = 0
        for j in range(len(T)):
            if S[i+j] in [T[j], "?"]:
                count += 1
        if count == len(T):
            k = i
            break
    if k == -1:
        return "UNRESTORABLE"
    for i in range(len(T)):
        S[k+i] = T[i]
    for i in range(len(S)):
        if S[i] == "?":
            S[i] = "a"
    return "".join(S)


if __name__ == '__main__':
    inputs = read()
    print(solve(*inputs))

Submission status: Accepted

Solution code:
def solve(s, t):
    n = len(s)
    m = len(t)
    if n < m:
        return 'UNRESTORABLE'
    for i in range(n-m+1)[::-1]:
        if all([s[i+j] == '?' or s[i+j] == t[j] for j in range(m)]):
            return s[:i].replace('?', 'a') + t + s[i+m:].replace('?', 'a')
    return 'UNRESTORABLE'


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


if __name__ == "__main__":
    main()

Submission status: Accepted

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

listS = list(S)
f = False
for i in range(len(S) - len(T), -1, -1):
    for ji, j in enumerate(range(i, i + len(T))):
        if S[j] == T[ji] or S[j] == "?":
            continue
        else:
            break
    else:
        for ji, j in enumerate(range(i, i + len(T))):
            listS[j] = T[ji]
        f = True
        break

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

    print("".join(listS))
else:
    print("UNRESTORABLE")

Submission status: Accepted

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

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

ans = 'z'*51
for i in range(len(S)-len(T)+1):
    s = S[i:i+len(T)]
    for a,b in zip(s,T):
        if a==b or a=='?': continue
        break
    else:
        cand = S[:i] + T + S[i+len(T):]
        ans = min(ans, cand.replace('?','a'))

print('UNRESTORABLE' if ans=='z'*51 else ans)

Submission status: Accepted

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

# input = stdin.readline

def solve(s,t):
  s_len = len(s)
  t_len = len(t)
  k = 0
  l = []
  while k + t_len <= s_len:
    flag = True
    for i in range(t_len):
      if s[k+i] == t[i] or s[k+i] == "?":
        pass
      else:
        flag = False
    cand = "".join((s[:k],t,s[k+t_len:])).replace("?","a")
    if flag:
      l.append(cand)
    k += 1
  if len(l) == 0:
    return "UNRESTORABLE"
  else:
    return list(sorted(l))[0]


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

if __name__ == '__main__':
  main()

Submission status: Accepted

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

ls = len(s)
lt = len(t)

if ls < lt:
    print('UNRESTORABLE')
    exit()
anslist = []
for i in range(ls-lt+1):
    flag = True
    for j in range(lt):
        if s[i+j] != '?' and s[i+j] != t[j]:
            flag = False
    if flag:
        anslist.append(i)
if anslist:
    i = max(anslist)
    x = s[:i] + t + s[i+lt:]
    print(x.replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
def resolve():
  S_base = list(input())
  T = list(input())

  if len(T) > len(S_base):
    print("UNRESTORABLE")
    return True

  for i in reversed(range(len(S_base) - len(T) + 1)):
    isMatched = True
    for t in range(len(T)):
      if not (S_base[i + t] == T[t] or S_base[i + t] == "?"):
        isMatched = False
        break
    if isMatched:
      result = "".join(S_base[:i])+"".join(T)+"".join(S_base[i+len(T):])
      print(result.replace("?", "a"))
      return True

  print("UNRESTORABLE")

if __name__ == "__main__":
  resolve()

Submission status: Accepted

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

Submission status: Accepted

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

a=len(s)
b=len(t)

ans=[]
ans1=[]

if b>a:
  print('UNRESTORABLE')
  

else:
  for i in range(a-b+1):
    ch=0
    for j in range(b):
      if s[i+j]==t[j] or s[i+j]=='?':
        ch+=1
        
    if ch==b:
      ans.append(i)
      
  if len(ans)==0:
    print('UNRESTORABLE')
    
  else:
    for k in ans:
      r=[]
      for h in range(a):
        if s[h]=='?':
          r.append('a')
        else:
          r.append(s[h])
       
      f=0
      for l in range(k,k+b):
        r[l]=t[f]
        f+=1
        
      ans1.append(r)
    ans2=[]
    for w in ans1:
      u=''.join(w)
      ans2.append(u)
    
    ans2.sort()
    print(ans2[0])

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
for i in range((len(s))-(len(t)),-1,-1):
    for j in range(len(t)):
        if s[i+j] == "?":
            continue
        if s[i+j] != t[j]:
            break
    else:
        for k in range(len(t)):
            s[i+k] = t[k]
        for l in range(len(s)):
            if s[l] == "?":
                s[l] = "a"
        print("".join(s))
        break
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s = input()
T = input()
n_s = len(s)
n_t = len(T)
S = ""
for i in range(n_s-n_t+1):
    s_i = s[i:n_t+i]
    flag = True
    for j in range(n_t):
        if s_i[j] != "?":
            if s_i[j] != T[j]:
                break
    else:
        S = s[:i] + T + s[n_t+i:]
#print(S)
if S == "":
    print("UNRESTORABLE")
    exit()
    
S = list(S)
for i in range(n_s):
    if S[i] == "?":
        S[i] = "a"
print("".join(S))

Submission status: Accepted

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

p = 0
e = len(T)
ans = ''
while 1:
    s = S[p:e]

    if len(s) != len(T):
        print('UNRESTORABLE')
        break
    tmp = ''
    for i in range(len(T)):
        if s[i] == T[i] or s[i] == '?':
            tmp += T[i]
        else:
            ans += s[0]
            break
    else:
        ans += tmp
        ans += S[e::]
        print(ans.replace('?','a')[::-1])
        exit()
    p += 1
    e += 1

Submission status: Accepted

Solution code:
def main():
  S = list(input())
  T = list(input())
  
  if len(S) < len(T):
    print("UNRESTORABLE")
    return 0

  restorable = False
  LT = len(T)
  LS = len(S)
  for i in range(LS - LT + 1):
    if check_char(S[LS - LT - i : LS - i], T):
      restorable = True
      for j in range(LT):
        S[LS - LT - i + j] = T[j]
      break
  print("".join(["a" if s == "?" else s for s in S])) if restorable else print("UNRESTORABLE")

def check_char(A, B): # same length
  for i in range(len(B)):
    if A[i] not in [B[i], "?"]:
      return False
  return True

main()

Submission status: Accepted

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

partial_s = []
for i in range(len(S)-len(T)+1):
    partial_s.append(S[i:i+len(T)])
to_replace_idxs = []

for idx, sub_s in enumerate(partial_s):
    for i in range(len(sub_s)):
        flag = 1
        if sub_s[i] != T[i]:
            if sub_s[i] != "?":
                flag = 0
                break
    if flag:
        to_replace_idxs.append(idx)

tmp_ans = []
if not to_replace_idxs:
    print("UNRESTORABLE")
else:
    for to_replace_idx in to_replace_idxs:
        tmp_string = S
        tmp_string = list(tmp_string)
        for i in range(to_replace_idx, to_replace_idx+len(T)):
            tmp_string[i] = T[i-to_replace_idx]
            
        tmp_string = "".join(tmp_string)
        tmp_string = tmp_string.replace("?", "a")
        tmp_ans.append(tmp_string)
    print(min(tmp_ans))

Submission status: Accepted

Solution code:
S_dash  =   list(input())
len_s   =   len(S_dash)
T       =   list(input())
len_t   =   len(T)

if len_s < len_t:
    print('UNRESTORABLE')
else:
    flag_i = 0
    # if flag_i = 1, it means restorable. if not, unrestorable
    for i in range( len_s - len_t + 1 ):
        flag_j = 0
        # if flag_j = 1 , it means unrestorable
        check_s = S_dash[ len_s - len_t - i : len_s - i ]
        for j in range( len_t ):
            if ( check_s[j] != '?' and check_s[j] != T[j] ):
                flag_j = 1
                break
        if flag_j == 0:
            flag_i = 1
            break
    if flag_i == 0:
        print('UNRESTORABLE')
    else:
        S_dash[ len_s - len_t - i : len_s - i ] = T
        for i in range( len_s ):
            if S_dash[i] == '?':
                S_dash[i] = 'a'
        print( ''.join(S_dash) )

Submission status: Accepted

Solution code:
s = str(input())
t = str(input())
n = len(s)
m = len(t)
mi = -1
if m > n:
  print("UNRESTORABLE")
  exit()
for i in range(n-m,-1,-1):
  flag = True
  for j in range(0,m):
    if t[j] != s[i+j] and s[i+j] != "?":
      flag = False
      break
  if flag:
    mi = i
    break
if mi == -1:
  print("UNRESTORABLE")
  exit()
ans = ""
i = 0
while i < n:
  if i == mi:
    ans += t
    i += m
  else:
    if s[i] == "?":
      ans += "a"
    else:
      ans += s[i]
    i += 1
print(ans)

Submission status: Accepted

Solution code:
a = list(input())
b = list(input())
c = len(a)
d = len(b)
if d > c:
    print("UNRESTORABLE")
    exit()
ans = []
   
for i in range(c-d+1):
    #print(a[i:i+d])
    flag = False
    for j in range(d):
        if a[i:i+d][j] == b[j] or a[i:i+d][j] == "?":
            flag = True
        else:
            flag = False
            break
    li = [] 
    if flag:
        #print(a[i:i+d])
        li = a[:i] + b + a[i+d:]
        for k in range(len(li)):
            if li[k] == "?":
                li[k] = "a"
        ans.append("".join(li))
if ans:
    ans.sort()
    print(ans[0])
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import copy
S_dash = input()
T = input()

len_S = len(S_dash)
len_T = len(T)

candidate0 = list(S_dash)


ans = "z"*51

if len_S >= len_T:
  for s in range(len_S):
    cha_S = S_dash[s]
    if cha_S != "?" and cha_S in list(T):
      for t in range(len_T):
        cha_T = T[t]
        if cha_S == cha_T and 0<= s-t < len_S and  0< s-t+len_T <= len_S:
          S_cut = S_dash[s-t:s-t+len_T]
          candidate1 = copy.deepcopy(candidate0)
          for x in range(len_T):
            if S_cut[x] == "?":
              candidate1[s-t+x] = T[x]
            elif  S_cut[x] != T[x]:
              break
          else:
            if "".join(candidate1[s-t:s-t+len_T]) == T:
              if ans > "".join(candidate1).replace('?', 'a'):
                ans = "".join(candidate1).replace('?', 'a')
  
  
  
  for u in range(len_S-len_T+1):
    cut_S = S_dash[u:u+len_T]
    if cut_S.count("?") == len_T:
      candidate1 = copy.deepcopy(candidate0)
      for t in range(len_T):
        candidate1[u+t] = T[t]
      if ans > "".join(candidate1).replace('?', 'a'):
        ans = "".join(candidate1).replace('?', 'a')
                
if ans == "z"*51:
  ans = "UNRESTORABLE"
print(ans)

Submission status: Accepted

Solution code:
from copy import deepcopy
S = input()
T = input()
s_num = len(S)
t_num = len(T)
ans = []
if s_num < t_num:
  print('UNRESTORABLE')
else:
  for i in range(s_num-t_num+1):
    s_key = S[i:i+t_num]
    judge = 0
    for s, t in zip(s_key, T):
      if s=='?':
        judge += 1
      elif s == t:
        judge += 1
    if judge == t_num:
      tmp = S[:i] + T + S[i+t_num:]
      tmp = tmp.replace('?', 'a')
      ans.append(tmp)
  if ans:
    print(sorted(ans)[0])
  else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
s = str(input())
t = str(input())
ns = len(s)
nt = len(t)
start = -1
for j in range(ns):
    if t[0] == s[j] or s[j] == '?':
        j_temp = j
        i_temp = 0
        is_ok = True
        while i_temp < nt - 1:
            i_temp += 1
            j_temp += 1
            if j_temp >= ns:
                is_ok = False
                break
            if s[j_temp] == '?' or s[j_temp] == t[i_temp]:
                if i_temp == nt - 1:
                    break
                continue
            if s[j_temp] != t[i_temp]:
                is_ok = False
                break
        if is_ok:
            start = max(j, start)
ans = ""
if start == -1:
    print("UNRESTORABLE")
    exit()
for i in range(ns):
    if start <= i < start + nt:
        ans += t[i - start]
    elif s[i] == "?":
        ans += "a"
    else:
        ans += s[i]
print(ans)

Submission status: Accepted

Solution code:
import copy
SD = list(input())
T = list(input())

Possible = []
for TSD in range(0,len(SD)-len(T)+1):
    SDCopy = copy.deepcopy(SD)
    String = SDCopy[TSD:TSD+len(T)]
    Flag = True
    for TST in range(0,len(T)):
        if String[TST]!='?' and String[TST]!=T[TST]:
            Flag = False
            break
    if Flag:
        SDCopy[TSD:TSD+len(T)] = T
        Possible.append(''.join(['a' if TSC=='?' else TSC for TSC in SDCopy]))
if Possible:
    print(sorted(Possible)[0])
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
s = input()
t = input()
sn = len(s)
tn = len(t)

if sn < tn:
    print("UNRESTORABLE")
    quit()
    
for i in range(sn-tn, -1, -1):
    matched = True
    for j in range(tn):
        if s[i+j] != t[j] and s[i+j] != '?':
            matched = False
            break
    if matched:
        break
        
if not matched:
    print("UNRESTORABLE")
    quit()

ans = ['a'] * sn
for j in range(0, i):
    if s[j] != '?':
        ans[j] = s[j]
for j in range(tn):
    ans[i + j] = t[j]
for j in range(i + tn, sn):
    if s[j] != '?':
        ans[j] = s[j]

print("".join(ans))

Submission status: Accepted

Solution code:
s = str(input())
t = str(input())
l = []
for i in range(len(s)-len(t)+1):
    num = 0
    for h in range(len(t)):
        if s[i+h] == t[h] or s[i+h] == '?':
            num += 1
        elif s[i+h] != t[h]:
            break
    if num == len(t):
        w2 = s[:i] + t + s[i + len(t):]
        w = ""
        for j in range(len(w2)):
            if w2[j] == "?":
                w += "a"
            else:
                w += w2[j]
        l.append(w)
l.sort()
if 0 < len(l):
    print(l[0])
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import re

s = "".join("." if i == "?" else i for i in input())
t = input()

lent = len(t)
mstart = -1
for start in range(len(s) - lent + 1):
    m = re.match(re.compile(s[start:start+lent]), t)    
    if m:
        mstart = start
else:
    if mstart == -1:
        print("UNRESTORABLE")
    else:
        s = s[:mstart] + t + s[mstart+lent:]
        print(s.replace(".", "a"))

Submission status: Accepted

Solution code:
import re

s = "".join("." if i == "?" else i for i in input())
t = input()

lent = len(t)
mgroup = ""
mstart = 0
for start in range(len(s) - lent + 1):
    m = re.match(re.compile(s[start:start+lent]), t)    
    if m:
        mgroup, mstart = m.group(), start
else:
    if mgroup:
        s = s[:mstart] + t + s[mstart+lent:]
        print(s.replace(".", "a"))
    else:
        print("UNRESTORABLE")

Submission status: Accepted

Solution code:
S = input()
T = input()
t = len(T)
if len(S) < t :
    print('UNRESTORABLE')
    exit()
ans = []
for i in range(len(S)-t+1) :
    s = S[i:i+t]
    if all (s[j] == '?' or s[j] == T[j] for j in range(t)) :
        x = (S[:i]+ T + S[i+t:]).replace('?','a')
        ans.append(x)

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

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
ans_list = []
for i in range(len(S)):
  flag = True
  if S[i] == "?" or S[i] == T[0]:
    tmp = S[i:i+len(T)]
    if len(tmp) != len(T):
      continue
    for j in range(len(T)):
      if tmp[j] != '?' and T[j] != tmp[j]:
        flag = False
        break
    if flag:
      ans = S[:i] + T + S[i+len(T):]
      for i in range(len(ans)):
        if ans[i] == '?':
          ans[i] = 'a'
      ans_list += [ans]

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

Submission status: Accepted

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

if len(Sp) < len(T):
    print('UNRESTORABLE')
    exit(0)

candidates = []
for i in range(len(Sp) - len(T) + 1):
    x = Sp[i:i + len(T)]

    if all((x[idx] == '?' or x[idx] == T[idx] for idx in range(len(T)))):
        candidate = (Sp[:i] + T + Sp[i + len(T):]).replace('?', 'a')
        candidates.append(candidate)

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

Submission status: Accepted

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

A=len(S)
B=len(T)

if A<B:
    print("UNRESTORABLE")
    exit()

X=[]
for i in range(A-B+1):
    U=S[i:i+B]

    F=True
    for k in range(B):
        F&=(U[k]=="?" or U[k]==T[k])

    if F:
        Y=S[:i]+T+S[i+B:]
        Y=Y.replace("?","a")
        X.append(Y)

if X:
    print(min(X))
else:
    print("UNRESTORABLE")

Submission status: Accepted

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

n = len(S)
m = len(t)

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

Submission status: Accepted

Solution code:
import sys
s = input()
t = input()
num0, num1 = len(s), len(t)

if num0 < num1:
    print('UNRESTORABLE')
elif num0 == num1:
    for i, j in zip(s, t):
        if i != j and i != '?':
            print('UNRESTORABLE')
            sys.exit()
    print(t)
else:
    for i in range(num0-num1, 0, -1):
        for j in range(num1):
            if s[i+j] != t[j] and s[i+j] != '?':
                break
            elif j == num1-1:
                ans = s[:i]+t+s[i+num1:]
                ans = ans.replace('?', 'a')
                print(ans)
                sys.exit()
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
pos = []
for i in range(len(S)-len(T)+1):
    if S[i] == T[0] or S[i] == '?':
        flag = 1
        for j in range(len(T)):
            if not T[j] == S[i+j] and not S[i+j] == '?':
                flag = 0
                break
        if flag:
            pos.append(i)

if not pos:
    print('UNRESTORABLE')
    exit()

words = []
for p in pos:
    word = S[0:p] + T + S[p+len(T):]
    for i in range(len(word)):
        if word[i] == '?':
            word[i] = 'a'
    words.append(word)
words.sort()
print("".join(words[0]))

Submission status: Accepted

Solution code:
import re
S=input().replace("?", ".")
T=input()
ans=[]
moji = len(T)
for i in range(len(S)-len(T)+1):
  m = re.search(S[i:moji+i], T)
  if m is not None:
    ans.append((S[0:i] + T + S[i+moji:]).replace(".", "a"))

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

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
ans = ["UNRESTORABLE"]

if "?" not in set(s):
    print("".join(s))
    exit()

for i in range(ls-lt+1):
    f = True
    for j in range(lt):
        f &= (s[i + j] == "?" or s[i + j] == t[j])

    if f:
        ans = s.copy()
        for j in range(lt):
            ans[i+j] = t[j]


print("".join(ans).replace("?", "a"))

Submission status: Accepted

Solution code:
no="UNRESTORABLE"

s=input()
t=input()
ans=list(s[:])
hatena=[ s[i]=="?" for i in range(len(s))]

left=0 ; right=len(s)
while right>=len(t):
    for i in range(right-len(t), right):
        if s[i]!="?" and s[i]!=t[i-right+len(t)]:
            break
    else:
        # hatena[right-len(t):right]=[i*2 for i in hatena[right-len(t):right]]
        ans[right-len(t):right]=list(t) 
        print( ("".join(ans)).replace("?","a") )
        exit()
    right-=1



# for i in range(len(hatena)):
#     if i==0:
#         s+=s[i]
#     elif i==1:
#         s+="a"
print(no)

Submission status: Accepted

Solution code:
S = input().strip()
T = input().strip()
ans = "UNRESTORABLE"
for i in range(len(S)-len(T), -1, -1):
    ok = True
    for j in range(len(T)):
        if not (S[i+j] == '?' or S[i+j] == T[j]):
            ok = False

    if ok:
        ans = S[:i]+T+S[i+len(T):]
        ans = ans.replace("?", "a")
        break
print(ans)

Submission status: Accepted

Solution code:
S = input().strip()
T = input().strip()
ans = "UNRESTORABLE"
for i in range(len(S)-len(T), -1, -1):
    ok = True
    for j in range(len(T)):
        if not (S[i+j] == '?' or S[i+j] == T[j]):
            ok = False

    if ok:
        a = S[:i]+T+S[i+len(T):]
        a = a.replace("?", "a")
        if ans == "UNRESTORABLE" or a < ans:
            ans = a
print(ans)

Submission status: Accepted

Solution code:
S_hatena = input()
T_hint = input()

N = len(S_hatena)
ans_list = []

for i in range(N):
    index_init = i
    index_end = i + len(T_hint) - 1
    
    s = S_hatena[index_init:index_end + 1]
    FLAG = True
    
    if (index_end < N):
        for j in range(len(T_hint)):
            if (s[j] != T_hint[j] and s[j] != '?'):
                FLAG = False
                break
    else:
        FLAG = False
    
    if (FLAG):
        tmp_ans = S_hatena[:index_init] + T_hint + S_hatena[index_init + len(T_hint):]
        tmp_ans = tmp_ans.replace('?', 'a')
        ans_list.append(tmp_ans)

ans_list.sort()

if (len(ans_list) > 0):
    print(ans_list[0])

else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:


def main():
        
    S_part = list(input())
    T_hint = list(input())

    N = len(S_part)
    ans = []

    for i in range(N):
        index_init = i
        
        if (index_init + len(T_hint) <= N):
            s = S_part[index_init:index_init + len(T_hint)]

            if (s == T_hint):
                ans_right = ''.join(S_part[:index_init]).replace('?', 'a')
                ans_middle = ''.join(s)
                tmp_ans = ans_right + ans_middle
                
                if (index_init + len(T_hint) < N):
                    ans_left = ''.join(S_part[index_init + len(T_hint):]).replace('?', 'a')
                    tmp_ans += ans_left
                
                ans.append(tmp_ans)
            

            elif ('?' in s):
                FLAG = True
                
                for j in range(len(s)):
                    if (T_hint[j] != s[j] and s[j] == '?'):
                        s[j] = T_hint[j]
                    
                    elif (T_hint[j] != s[j] and s[j] != '?'):
                        FLAG = False
                        break
                
                
                if (FLAG):
                    ans_left = ''.join(S_part[:index_init])
                    ans_right = ''.join(s)
                    
                    tmp_ans = ans_left + ans_right
                    tmp_ans = tmp_ans.replace('?', 'a')

                    if (index_init + len(T_hint) < N):
                        module = S_part[index_init + len(T_hint):]
                        module = ''.join(module)
                        module = module.replace('?', 'a')
                        
                        tmp_ans += module


                    ans.append(tmp_ans)

    ans.sort()

    if (S_part.count('?') == 0 and T_hint in S_part):
        print(''.join(S_part))
    
    elif (len(ans) > 0):
        print(ans[0])
    
    else:
        print('UNRESTORABLE')


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
def cmpStr(S1, S2):
    for i in range(len(S2)):
        if S1[i] == S2[i] or S1[i] == '?':
            yield S2[i]
        else:
            break

Sp = input()
T = input()
res = []
for i in range(len(Sp)-len(T), -1, -1):
    if Sp[i] == '?' or Sp[i] == T[0]:
        substr = ''.join(list(cmpStr(Sp[i:i+len(T)], T)))

        if len(substr) == len(T):
            res.append(Sp[:i]+T+Sp[i+len(T):])
            res[-1] = res[-1].replace('?', 'a')
            break
if res:
    res.sort()
    print(res[0])
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    S2 = list(input())
    T = list(input())
    N = len(S2)
    unable = "UNRESTORABLE"


    window_size = len(T)
    X = [] # 合致したwindow
    for i in range(N):
        window = S2[i:i+window_size]
        f = True

        if len(window) != window_size: continue
        for j in range(window_size):
            if not (window[j] == T[j] or window[j] == "?"):
                f = False
                break
        
        if f:
            X.append((i,i+window_size))
    
    if len(X) == 0:
        print(unable)
        exit()
    

    i,j = X[-1]
    S2[i:j] = T

    S = []
    for s in S2:
        if s == "?":
            S.append("a")
        else:
            S.append(s)
    
    print("".join(S))



if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s=input()
t=input()
ans=[]
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:
    a=''
    for k in s[0:i]+t+s[i+len(t):]:
      if k=='?':a+='a'
      else:a+=k
    ans+=[a]
ans=sorted(ans)
if ans:print(ans[0])
else:print('UNRESTORABLE')

Submission status: Accepted

Solution code:
s, t = raw_input(), raw_input()
def check(a,b):
	if len(a) != len(b): return False

	for u,v in zip(a,b):
		if u != v and u != '?':
			return False
	return True
cand = -1
for i in range(len(s)):
	if check(s[i:i + len(t)],t): cand = i

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

Submission status: Accepted

Solution code:
s, t = raw_input(), raw_input()
def f(a,b):
	if len(a) != len(b): return False

	for u,v in zip(a,b):
		if u != v and u != '?':
			return False
	return True
cand = -1
for i in range(len(s)):
	if f(s[i:i + len(t)],t):
		cand = i

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

Submission status: Accepted

Solution code:
S=input()
T=input()
t=len(T)
s=len(S)
if s<t:
  print("UNRESTORABLE")
  exit()
L=list()
for i in range(s-t+1):
  "S[i]からs[i+t-1]までの文字列"
  for j in range(t):
    if S[i+j]!="?" and S[i+j]!=T[j]:
      break
    if j==t-1:
      k=S[:i]+T+S[i+t:]
      k=k.replace("?","a")
      L.append(k)
if len(L)==0:
  print("UNRESTORABLE")
else:
  L=sorted(L)
  print(L[0])

Submission status: Accepted

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

n = len(S)
m = len(T)

res = []

for i in range(n-m+1):
    for j in range(m):
        if S[i+j] != "?":
            if S[i+j] != T[j]:
                break
    else:
        text = ""
        for x in S[:i]+T+S[i+m:]:
            if x == "?":
                text += "a"
            else:
                text += x
        res.append(text)

if res:
    print(min(res))
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import sys

S_ = input()
T = input()

ans = 'UNRESTORABLE'
if len(S_) < len(T):
    print(ans)
    sys.exit()

S = []
for i in range(len(S_) - len(T) + 1):
    for j in range(len(T)):
        if S_[i + j] == '?' or S_[i + j] == T[j]:
            continue
        else: break
    else:
        tmp = S_[0:i] + T + S_[i + len(T):len(S_)]
        S.append(tmp.replace('?', 'a'))

if len(S) > 0:
    sort = sorted(S)
    ans = sort[0]

print(ans)