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:
def match(s,t):
  for i in range(m):
    if s[i]==t[i] or s[i]=='?':
      continue
    return False
  return True
s = list(input())
t = list(input())
n = len(s)
m = len(t)
i = n-m
found = False
while i >= 0:
  if match(s[i:i+m],t):
    found = True
    for j in range(i,i+m):
      s[j] = t[j-i]
    break
  i-=1
if found:
  for i in s:
    if i=='?':
      print('a',end='')
    else:
      print(i,end='')
  print()
else:
  print("UNRESTORABLE")

Submission status: Accepted

Solution code:
from copy import deepcopy
def main():
    s = list(input())
    t = list(input())
    tlen = len(t)
    kohos = []
    for i1 in range(len(s) - tlen + 1):
        s_range = s[i1:i1 + tlen]
        flag = 1
        for i2 in range(tlen):
            if s_range[i2] != '?' and s_range[i2] != t[i2]:
                flag = 0
        if flag:
            s_koho = deepcopy(s)
            s_koho[i1:i1 + tlen] = t
            kohos.append(s_koho)
    if kohos:
        kohos.sort()
        koho0 = deepcopy(kohos[0])
        koho0 = ['a' if c == '?' else c for c in koho0]
        r = "".join(koho0)
        print(r)
    else:
        print('UNRESTORABLE')

if __name__ == '__main__':
    main()

Submission status: Accepted

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



if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import sys
S = list(input())
T = list(input())
s = len(S)
t = len(T)
if s < t:
    print('UNRESTORABLE')
    sys.exit()
OK = False
P = 0
for i in range(s - t + 1):
    if S[i] != T[0] and S[i] != '?':
        continue
    for j in range(1, t + 1):
        if j == t:
            OK = True
            P = i
            break
        if S[i + j] != T[j] and S[i + j] != '?':
            break
for k in range(t):
    S[P + k] = T[k]
for i in range(s):
    if S[i] == '?':
        S[i] = 'a'
if OK:
    [print(S[i], end='') for i in range(s)]
    print('')
else:
    print('UNRESTORABLE')

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def solve():
    S = input()
    T = input()
    
    l = []
    flag = False
    for i in range(len(S)-len(T)+1):
        for s, t in zip(S[i:i+len(T)], T):
            if s != '?' and s != t:
                flag = True
                break
        if flag:
            flag = False
            continue
        
        l.append(S[:i].replace('?', 'a')+T+S[i+len(T):].replace('?', 'a'))
    
    if len(l) == 0:
        return 'UNRESTORABLE'
    else:
        l.sort()
        return l[0]

print(solve())

Submission status: Accepted

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

Submission status: Accepted

Solution code:
X = open(0).readlines()
S = X[0].strip()
T = X[1].strip()
m, n = len(T), len(S)
if m > n:
    print('UNRESTORABLE')
else:
    for i in range(n-m, -1, -1):
        U = S[i:i+m]
        if all(u == t or u == '?' for u, t in zip(U, T)):
            V = list(S.replace('?', 'a'))
            for j in range(m):
                V[i+j] = T[j]
            print(''.join(V))
            break
    else:
        print('UNRESTORABLE')

Submission status: Accepted

Solution code:
s=list(input())
t=input()
k=[]
for i in range(len(s)-len(t)+1):
  m=i
  for j in t:
    if s[m]==j or s[m]=='?':
      m+=1
    else:break
  else:
    l=s[:i]+list(t)+s[i+len(t):]
    for i in l:
      if i=='?':
        l[l.index(i)]='a'
    k.append(''.join(l))
if len(k)==0:
  k.append('UNRESTORABLE')
print(min(k))

Submission status: Accepted

Solution code:
s = input()
t = input()
n_s = len(s)
n_t = len(t)

ans_li = []
for i in range(n_s-n_t+1):
    u = s[i:i+n_t]
    flag = True
    for j in range(len(u)):
        if (u[j]!='?' and u[j]==t[j]) or u[j]=='?':
            continue
        flag = False
    if flag:
        ans_li.append(s[:i].replace('?','a')+t+s[i+n_t:].replace('?','a'))
if ans_li==[]:
    print('UNRESTORABLE');exit()
ans_li.sort()
print(ans_li[0])

Submission status: Accepted

Solution code:
s = input()
t = input()
les = len(s)
let = len(t)
hoge = 0
if les < let:
  print('UNRESTORABLE')
  exit()
for i in range(les,let-1,-1):
  sa = s[i-let:i]
  for j in range(len(sa)):
    if sa[j] != t[j] and sa[j] != '?':
      break
    if j == len(sa)-1:
      hoge += 1
  if hoge == 1:
    sb = s[:i-let] + t + s[i:]
    ans = ''
    for v in sb:
      if v == '?':
        ans += 'a'
      else:
        ans += v
    print(ans)
    exit()
print('UNRESTORABLE')

Submission status: Accepted

Solution code:
def main():
    s = input()
    t = input()
    # ansはtを含む
    # tをいれられる場所を探す
    ans = []
    for i in range(len(s)-len(t)+1):
        tmp = s[:i]
        flag = False
        for j in range(i,i+len(t)):
            if s[j]==t[j-i]:
                tmp += t[j-i]
                pass
            elif s[j]=='?':
                tmp += t[j-i]
                pass
            else:
                flag = True
                break
        if not flag:
            tmp += s[i+len(t):]
            tmp = tmp.replace('?','a')
            ans.append(tmp)
    if ans:
        ans.sort()
        print(ans[0])
    else:
        print('UNRESTORABLE')

main()

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[:i] + t + s[i+len(t):]
        s = s.replace('.', 'a')
        print(s)
        exit(0)
print('UNRESTORABLE')

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

Submission status: Accepted

Solution code:
S=input()
T=input()
tmp=[]
for i in range(len(S)):
    flag=True
    for j in range(min(len(T),len(S)-i)):
        if S[i+j]==T[j] or S[i+j]=="?" or T[j]=="?":
            continue
        else:
            flag=False
    if flag:
        rec=S[:i]+T+S[i+len(T):]
        if len(rec)==len(S):
            rec=rec.replace("?","a")
            tmp.append(rec)
if tmp==[]:
    print("UNRESTORABLE")
    exit()
tmp.sort()
print(tmp[0])

Submission status: Accepted

Solution code:
sd = input()
t = input()
n = len(sd)
m = len(t)
s = []
for i in range(n-m, -1, -1):
  ans = sd[i:i+m]
  for j in range(m + 1):
    if j == m :
      print((sd[:i] + t + sd[i + len(t):]).replace('?','a'))
      exit()
    if ans[j] == '?':
      continue
    elif ans[j] != t[j]:
      break
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
from math import floor
from decimal import Decimal

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

isSuccess = False

for i in reversed(range(len(S) - len(T) + 1)):
    T_str = S[i: i + len(T)]
    for j in range(len(T)):
        if T_str[j] != T[j] and T_str[j] != "?":
        	break
    else:
        isSuccess = True
        S[i:i + len(T)] = T
        break
if isSuccess == False:
    print("UNRESTORABLE")
else:
    string = ",".join(S)
    string = string.replace('?', 'a')
    S = string.split(',')
    print("".join(map(str,S)))

Submission status: Accepted

Solution code:
from re import match
s, t = input().replace('?', '.'), input()

for i in range(len(s) - len(t) + 1)[::-1]:
    if match(s[i:i + len(t)], t):
        key = (s[:i] + t + s[i + len(t):]).replace('.', 'a')
        print(key)
        break
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
from re import match
s, t = input().replace('?', '.'), input()

for i in range(len(s) - len(t) + 1)[::-1]:
    if match(s[i:i + len(t)], t):
        key = s.replace(s[i:i + len(t)], t).replace('.', 'a')
        s = s.replace('.', 'a')
        print(s[:i] + t + s[i + len(t):])
        #print(key)
        break
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
chr1 = input().rstrip()
chr2 = input().rstrip()

result = []
for i in range(len(chr1)):
    if (chr1[i] == chr2[0] or chr1[i] == "?")and i + len(chr2) <= len(chr1):
        index = 0
        for j in range(len(chr2)):
            if chr1[i+j] == chr2[j] or chr1[i+j] == "?":
                index += 1
            else:
                break
        if index == len(chr2):
            temp = chr1[0:i]+chr2+chr1[i+len(chr2):]
            temp = temp.replace("?", "a")
            result.append(temp)
if len(result) >= 1:
    result.sort()
    print(result[0])
else:
    print("UNRESTORABLE")

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 = str(input())
t = str(input())

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

if ans_ind == -1:
    print('UNRESTORABLE')
else:
    ans = ''
    for i in range(len(s)):
        if ans_ind <= i < ans_ind + len(t):
            ans += t[i-ans_ind]
        else:
            if s[i] == '?': ans += 'a'
            else: ans += s[i]
    print(ans)

Submission status: Accepted

Solution code:
import re

# ?があるとエラーが起きるので
# "."は、メタ文字（特別な意味を持つ文字）
# https://qiita.com/hiroyuki_mrp/items/29e87bf5fe46de62983c
s = input().replace('?', '.')
t = input()
#print("s,t:", s, t)

for i in range(len(s) - len(t), -1, -1):
    # re.match : 文字列の先頭がマッチするかチェック、抽出
    if re.match(s[i:i + len(t)], t):
        #print(s[i:i + len(t)], t)
        s = s.replace('.', 'a')
        print(s[:i] + t + s[i + len(t):])
        exit()

print('UNRESTORABLE')

Submission status: Accepted

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

def match(k):
    flag = True
    for i in range(len(t)):
        if s[i + k] != t[i] and s[i + k] != "?":
            flag = False
            break
    return flag

flag = False
for k in reversed(range(len(s) - len(t) + 1)):
    if match(k):
        s = s[:k] + t + s[k + len(t):]
        flag = True
        break

if flag:
    print(s.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
Sp = input()
T = input()
NSp = len(Sp)
NT = len(T)

for i in range(NSp-NT+1):
  Snow = Sp[NSp-NT-i:NSp-i]
  for j in range(NT):
    if (Snow[j]=='?') or (Snow[j]==T[j]):
      continue
    else:
      break
  else:
    ans = ''
    for k in range(NSp):
      if (NSp-NT-i<=k) and (k<=NSp-i-1):
        ans += T[k-NSp+NT+i]
      else:
        if Sp[k] == '?':
          ans += 'a'
        else:
          ans += Sp[k]
    print(ans)
    break
else:
  print('UNRESTORABLE')

Submission status: Accepted

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

for i in range(len(s)-len(t)+1):
    ok = 1
    memo = "".join(s[0:i])
    #print(memo)
    for j in range(len(t)):
        if s[i+j] != t[j] and s[i+j] != "?":
            #print(t[j])
            ok = 0
            break
        memo += t[j]

    if ok == 1:
        memo += "".join(s[i+j+1:])
        if ans == "":
            ans = memo
        if ans > memo:
            ans = memo


#s.replace(' ', '-')

if ans =="":
    print("UNRESTORABLE")
else:
    print(ans.replace("?","a"))

Submission status: Accepted

Solution code:
s=input()
t=input()
for i in range(len(t)-1,len(s))[::-1]:
    if s[i]==t[-1] or s[i]=="?":
        if all(s[i-j]==t[-1-j] or s[i-j]=="?" for j in range(len(t))):
            s=s.replace("?","a")
            print(s[:i-len(t)+1]+t+s[i+1:])
            exit()
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
Sprime = input()
T = input()
Slist = list(Sprime)
Tlist = list(T)
s = len(Sprime)
indexis = []
possibilities = set()
for i in range(s):
  if(Slist[i] != "?"):
    indexis.append(i)
    
for i in range(s- len(T)+ 1):
  key = []
  for p in range(i):
    key.append("?")
  key.extend(Tlist)
  for q in range(s- i- len(T)):
    key.append("?")
  flag = 0
  for j in indexis:
    if(Sprime[j] != key[j] and key[j] != "?"):
      flag = 1
      break
  if(flag == 0):
    for k in indexis:
      if(key[k] == "?"):
        key[k] = Sprime[k]
    for l in range(s):
      if(key[l] == "?"):
        key[l] = "a"
    ans = ""
    for r in range(s):
      ans+= key[r]
    possibilities.add(ans)
    
if(possibilities == set()):
  print("UNRESTORABLE")
else:
  
  print(min(possibilities))

Submission status: Accepted

Solution code:
s = input()
t = input()
s = s[::-1]
t = t[::-1]
s_size, t_size = len(s), len(t)
result = "UNRESTORABLE"

for i in range(s_size - t_size + 1):
    for j in range(t_size):
        if s[i + j] != t[j] and s[i + j] != '?':
            break
    else:
        break
else:
    print(result)
    exit()
s = (s[:i] + t + s[i + t_size :]).replace('?', 'a')
result = s[::-1]
print(result)

Submission status: Accepted

Solution code:
s=input()
t=input()
for i in range(len(t)-1,len(s))[::-1]:
    if s[i]==t[-1] or s[i]=="?":
        if all(s[i-j]==t[-1-j] or s[i-j]=="?" for j in range(len(t))):
            s=s.replace("?","a")
            print(s[:i-len(t)+1]+t+s[i+1:])
            exit()
print("UNRESTORABLE")

Submission status: Accepted

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

sn = len(s)
tn = len(t)

l = r = -1
for i in range(sn, -1, -1):
    if i+tn > sn:
        continue

    if all(sc == tc or sc == "?" for sc, tc in zip(s[i:i+tn], t)):
        l, r = i, i+tn
        break

if l == -1:
    print("UNRESTORABLE")
    exit()

i = 0
while i < sn:
    if l <= i < r:
        print(t[i-l], end="")
    else:
        if s[i] == "?":
            print("a", end="")
        else:
            print(s[i], end="")
    
    i += 1

print()

Submission status: Accepted

Solution code:
import sys
sys.setrecursionlimit(10**7) #再帰関数の上限,10**5以上の場合python
import math
from copy import copy, deepcopy
from operator import itemgetter
from bisect import bisect_left, bisect, bisect_right#2分探索
#bisect_left(l,x), bisect(l,x)#aはソート済みである必要あり。aの中からx未満の要素数を返す。rightだと以下
from collections import deque
#deque(l), pop(), append(x), popleft(), appendleft(x)
##listでqueの代用をするとO(N)の計算量がかかってしまうので注意
from collections import Counter#文字列を個数カウント辞書に、
#S=Counter(l),S.most_common(x),S.keys(),S.values(),S.items()
from itertools import accumulate#累積和
#list(accumulate(l))
from heapq import heapify,heappop,heappush
#heapify(q),heappush(q,a),heappop(q) #q=heapify(q)としないこと、返り値はNone
#import fractions#古いatcoderコンテストの場合GCDなどはここからimportする
from functools import lru_cache#pypyでもうごく
#@lru_cache(maxsize = None)#maxsizeは保存するデータ数の最大値、2**nが最も高効率

def input(): return sys.stdin.readline()[:-1]
def printl(li): print(*li, sep="\n")
def argsort(s, return_sorted=False): 
    inds=sorted(range(len(s)), key=lambda k: s[k])
    if return_sorted: return inds, [s[i] for i in inds]
    return inds
def alp2num(c,cap=False): return ord(c)-97 if not cap else ord(c)-65
def num2alp(i,cap=False): return chr(i+97) if not cap else chr(i+65)
def matmat(A,B):
    K,N,M=len(B),len(A),len(B[0])
    return [[sum([(A[i][k]*B[k][j]) for k in range(K)]) for j in range(M)] for i in range(N)]
def matvec(M,v):
    N,size=len(v),len(M)
    return [sum([M[i][j]*v[j] for j in range(N)]) for i in range(size)]
def T(M):
    n,m=len(M),len(M[0])
    return [[M[j][i] for j in range(n)] for i in range(m)]
def main():
    mod = 10**9+7
    #w.sort(key=itemgetter(1),reversed=True)  #二個目の要素で降順並び替え

    #N = int(input())
    #N, K = map(int, input().split())
    #A = tuple(map(int, input().split())) #1行ベクトル
    #L = tuple(int(input()) for i in range(N)) #改行ベクトル
    #S = tuple(tuple(map(int, input().split())) for i in range(N)) #改行行列
    s=input()
    t=input()
    lt,ls=len(t),len(s)
    if lt>ls:
        print('UNRESTORABLE')
        return
    for i in range(ls-lt,-1,-1):
        sc=s[i:i+lt]
        flag=True
        for tt,ss in zip(t,sc):
            if ss!='?' and tt!=ss:
                flag=False
                break
        if flag:
            break
    if not flag:
        print('UNRESTORABLE')
        return 
    ans=""
    for k in range(ls):
        if i<=k<i+lt:
            ans+=t[k-i]
        elif s[k]=='?':
            ans+="a"
        else:
            ans+=s[k]
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import re

# .にすることで正規表現で任意の文字列として扱う
S = input().replace('?', '.')
T = input()
ls = len(S)
lt = len(T)

for i in range(ls-lt,-1,-1):
    # Sの一部にTが含まれるかチェック
    if re.match(S[i:i+lt], T):
        S = S.replace('.', 'a')
        # i~i+lsとTの文字の部分に置き換えることで、Tを含む文字が作れる
        S = (S[:i]+T+S[i+lt:])
        print(S)
        exit(0)
print('UNRESTORABLE')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
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] != T[j] and s[i+j] != "?":
			break
	else:
		s[i:i+len(T)] = T
		for i in range(len(s)):
			if s[i] == "?":
				s[i] = "a"
		print(*s, sep = "")
		break
else:
	print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
s = input()
T = input()


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

Submission status: Accepted

Solution code:
s = input()
s = list(s)
t = input()
ok_num = []
for i in range(len(s) - len(t) + 1):
  check = True
  s_part = s[i:i+len(t)]
  for j in range(len(t)):
    if s_part[j] != "?" and s_part[j] != t[j]:
      check = False
  if check == True:
    ok_num.append(i)  
if len(ok_num) == 0:
  print("UNRESTORABLE")
else:
  for i in range(len(t)):
    s[max(ok_num) + i] = t[i]
  for  j in range(len(s)):
    if s[j] == "?":
      s[j] = "a"
      
  print("".join(s))

Submission status: Accepted

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

Sdl = len(Sd)
Tl = len(T)

ans_str = ''

# inspect strings in reverse order
for i in reversed(range(Sdl - Tl + 1)):
  # if there is a character that hits, compare it with the string T.
  if Sd[i] == T[0] or Sd[i] == '?':
    is_match = True
    # loop for length of string T
    for j in range(Tl):
      # if string Sd doesn't match T and is not '?'
      if Sd[i + j] != T[j] and Sd[i + j] != '?':
        is_match = False
        break
    # if there is a T that meets the conditions, replace part of Sd
    if is_match:
      ans_str = Sd[:i] + T + Sd[i + Tl:]
      break

if ans_str:
  print(ans_str.replace('?', 'a'))
else:
  print('UNRESTORABLE')

Submission status: Accepted

Solution code:
s = input()
t = input()
ans = 'UNRESTORABLE'
r = []

for i in range(len(s)):
    cnt = 0
    idx = i
    for j in range(len(t)):
        if s[idx] == t[j] or s[idx] == "?":
            cnt += 1
        else:
            break
        if cnt == len(t):
            r.append((s[:i]+t+s[idx+1:]).replace('?','a'))
        if idx+1 <= len(s)-1:
            idx += 1
        else:
            break

if len(r) == 0:
    print(ans)
else:
    print(sorted(r)[0])

Submission status: Accepted

Solution code:
ret = 'UNRESTORABLE'
sd = input()
t = input()
idxs = []
for i in range(len(sd)-len(t)+1):
    ext_s = sd[i:len(t)+i]
    mach_flag = True
    for j in range(len(t)):
        if( ext_s[j] != t[j] and  ext_s[j] != '?' ):
            mach_flag = False
            break
    if mach_flag :
        idxs.append(i)

            
if len(idxs) == 0:
    print('UNRESTORABLE')
else:
    sList = []
    for idx in idxs:
        s = sd[:idx] + t + sd[idx+len(t):]
        s = s.replace('?', 'a')
        sList.append(s)
    sList.sort()
    print(sList[0])

Submission status: Accepted

Solution code:
SS = list(input())
T = list(input())
list = []

for i in range(len(SS)):
    target = SS[:]
    flg = False
    for j in range(len(T)):
        if i + j == len(SS):
            break
        if i + j == len(SS) or (
            target[i + j] != "?" and target[i + j] != T[j]
        ):
            break
        target[i + j] = T[j]
        if j == len(T) - 1:
            flg = True
    if flg is True:
        list.append("".join(target).replace("?", "a"))

if len(list) == 0:
    print("UNRESTORABLE")
else:
    print(sorted(list)[0])

Submission status: Accepted

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

x = "UNRESTORABLE"

sl = len(s)
tl = len(t)


if sl < tl:
    print(x)
    exit()

flag =0

for i in range(sl-tl,-1,-1):
    temp = s[i:i+tl]
    for j in range(tl):
        if temp[j] == t[j] or temp[j] =="?":
            if j == tl-1:
                x = s[:i] + t + s[i+tl:]
                flag = 1
                break            
        else:
            break

    if flag ==1:
        break

x = x.replace("?","a")

print(x)

Submission status: Accepted

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

for i in reversed(range(len(s)-n+1)): #後ろから一致する部分が無いか見ていく
    x = s[i:i+n]
    y = 0
    for j in range(n):
        if x[j] == "?" or x[j] == t[j]:
            continue
        else:
            y = 1
            break
    if y == 0:
        print(s[:i].replace("?", "a") +t + s[i+n:].replace("?", "a"))
        exit()

print("UNRESTORABLE")

Submission status: Accepted

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

Submission status: Accepted

Solution code:
Sp = input()
Sp_list = list(Sp)
N = len(Sp)
T = input()
n = len(T)

def check(s, t):
  for si, ti in zip(s, t):
    if si == '?':
      continue
    if si != ti:
      return False
  return True

ans = []
for i in range(N-n+1):
  if check(Sp[i:i+n], T):
    ans.append(''.join(Sp_list[:i] + list(T) + Sp_list[i+n:]).replace('?', 'a'))
    
if ans:
  ans.sort()
  print(ans[0])
else:
  print('UNRESTORABLE')

Submission status: Accepted

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


def check_match(a, b):
  m = len(a)
  for i in range(m):
    if not (a[i] == '?' or a[i] == b[i]):
      return False
  return True


def calc_possible_s(s, t):
  """
  Args:
    s, t (str)
  Returns:
    list[str]
  """
  buf = []
  n, m = len(s), len(t)
  assert n >= m
  for i in range(n-m+1):
    # compare s[i:i+m] and t. 
    if check_match(s[i:i+m], t):
      buf.append(s[:i].replace('?', 'a') + t + s[i+m:].replace('?', 'a'))
  return buf


if len(t) > len(s):
  print('UNRESTORABLE')
else:
  possible_s = calc_possible_s(s, t)
  if possible_s:
    print(min(possible_s))
  else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
from copy import deepcopy

S = input()
T = input()

candidate = []
ln = len(S) - len(T) + 1
for i in range(ln):
    if S[i] == T[0] or S[i] == '?':
        for s, t in zip(S[i:i+len(T)], T):
            if not(s == t or s == '?'):
                break
        else:
            candidate.append(i)

if candidate == []:
    print('UNRESTORABLE')
    exit()

ans = []
for i in candidate:
    tmp_s = list(deepcopy(S))
    tmp_s[i:i+len(T)] = list(T)
    tmp_s = ['a' if c == '?' else c for c in tmp_s]
    ans.append(''.join(tmp_s))

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

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 31 14:28:43 2020

@author: NEC-PCuser
"""

S = input()
T = input()

start = -1

i = 0
for i in range(0, len(S) - len(T) + 1):
    k = 0
    for b in T:
        if S[i + k] != b and S[i + k] != '?':
            break
        k += 1
    else:
        start = i

if start == -1:
    print("UNRESTORABLE")
else:
    s = list(S)
    s[start:start + len(T)] = T
    S = "".join(s)
    
    print(S.replace('?', 'a'))

Submission status: Accepted

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

def match(k):
    flag = True
    for i in range(len(T)):
        if S[i+k] != T[i] and S[i+k]!="?":
            flag = False
            break
    return flag

flag = False
for k in reversed(range(len(S)-len(T)+1)):
    # print(k)
    if match(k):
        S = S[:k] + T + S[k+len(T):]
        flag = True
        break
    
if flag:
    ans = S.replace("?","a")

if not flag:
    ans = "UNRESTORABLE"

print(ans)

Submission status: Accepted

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

Submission status: Accepted

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

#print(N,M)
ans = ""

for i in range(N-M+1):
    jdg = True
    for k in range(M):
        if not (T[k] == S1[i+k] or S1[i+k] == "?"):
            jdg = False
    if jdg:
        ans = S1[:i] + T + S1[i+M:]
        #print(S1[:i],T,S1[i+M:])
if ans == "":
    print("UNRESTORABLE")
else:
    print(ans.translate(str.maketrans({'?': 'a'})))

Submission status: Accepted

Solution code:
import sys

# import re
import math
import collections
# import decimal
import bisect
import itertools
import fractions
# import functools
import copy
import heapq
import decimal
# import statistics
import queue

sys.setrecursionlimit(10000001)
INF = 10 ** 16
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===


def main():
    s = list(input())
    t = list(input())

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

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

    if flg:
        print(*s, sep="")
    else:
        print("UNRESTORABLE")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
Sp = str(input())
T = str(input())
n = len(T)
a = [] # Spの何文字目から始まる文字列ならTと一致できるか。
b = [] # 候補のリスト
for i in range(len(Sp)-n+1):
  X = Sp[i:i+n]
  cnt = 0
  for j in range(n):
    if X[j] != '?':
      if X[j] != T[j]:
        break
      else:
        cnt += 1
    else:
      cnt += 1
  if cnt == n:
    a.append(i)
if a == []:
  print('UNRESTORABLE')
  exit()
for i in a:
  S1 = Sp[:i]
  S2 = Sp[i+n:]
  S3 = S1.replace('?', 'a')
  S4 = S2.replace('?', 'a')
  b.append(S3 + T + S4)
b.sort()
print(b[0])