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

s = len(S)
t = len(T)
if s < t:
  flag = False
else:
  for i in range(s-t+1):
    num = s-t-i
    tmp = S[num:num+t]
    flag = True
    for j in range(t):
      if (tmp[j]!='?') and (T[j]!=tmp[j]):
        flag = False
        break
    if flag:
      if 0 < num < s-t:
        ans = S[:num] + T + S[num+t:]
      elif num == 0:
        ans = T + S[num+t:]
      else:
        ans = S[:num] + T
      break
    
if flag:
  ans = ans.replace('?', 'a')
  print(ans)
else:
  print('UNRESTORABLE')

Submission status: Accepted

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

s_num = len(s)
t_num = len(t)

ans_list = []
ind_list = []

if s_num<t_num:
    ans_list.append('UNRESTORABLE')
else:
    for i in range(s_num -t_num + 1):
        flg = True
        for j in range(t_num):
            if s[i+j] == '?':
                pass
            elif s[i+j]==t[j]:
                pass
            else:
                flg=False
                break
        if flg:
            ind_list.append(i)
if len(ind_list) ==0:
    ans_list.append('UNRESTORABLE')
else:
    for i in ind_list:
        ans = ''
        j=0
        while j <s_num:
            if j==i:
               ans = ans+t
               j = j + t_num
            elif s[j] == '?':
                ans = ans + 'a'
                j = j + 1
            else:
                ans = ans + s[j]
                j = j + 1
        ans_list.append(ans)

print(min(ans_list))

Submission status: Accepted

Solution code:
s = '.'+input()+'.'
t = input()
def onazi(a):
  for i in range(len(t)):
    if a[i] == '?':
      continue
    if a[i] != t[i]:
      return 0
  return 1
cnt=0
for i in range(len(s)-len(t),0,-1):
  if onazi(s[i:i+len(t)])==1:
    cnt+=1
    s = s[:i]+t+s[i+len(t):]
    break
if cnt==0:
  print('UNRESTORABLE')
  exit(0)
g = ''
for i in s[1:-1]:
  if i == '?':
    g+='a'
  else:
    g+=i
print(g)

Submission status: Accepted

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

LS=len(S)
LT=len(T)

ans=[]
for i in range(LS-LT+1):
    F=True
    for t in range(LT):
        if T[t]==S[i+t] or S[i+t]=="?":continue
        else:
            F=False
            break
    if F:
        temp=""
        for j in range(LS):
            if j<i and S[j]=="?":
                temp+="a"
            elif i<=j<i+LT:
                temp+=T[j-i]
            elif j>=i+LT and S[j]=="?":
                temp+="a"
            else:
                temp+=S[j]
        ans.append(temp)

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

Submission status: Accepted

Solution code:
s = input()
t = input()
if len(s) < len(t):
  print("UNRESTORABLE")
  exit()

start = -1
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:
    start = i

if start == -1:
  print("UNRESTORABLE")
else:
  ans_list = list(s)
  for i in range(len(ans_list)):
    if start <= i < start+len(t):
      ans_list[i] = t[i-start]
    elif ans_list[i] == "?":
      ans_list[i] = "a"
  print("".join(ans_list))

Submission status: Accepted

Solution code:
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

S = list(input())[::-1]
slen = len(S)
T = list(input())[::-1]
tlen = len(T)

for i in range(slen):
    for j in range(tlen):
        if i+j>=slen:
            break
        if not (S[i+j]=='?' or S[i+j]==T[j]):
            break
    else:
        for j in range(tlen):
            S[i+j] = T[j]
        S = [s if not s=='?' else 'a' for s in S[::-1]]
        print(''.join(S))
        break
else:
    print('UNRESTORABLE')

Submission status: Accepted

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

l1, l2 = len(s), len(t)

res = ['z'] * l1
flag2 = False
for i in range(l1-l2+1):
    tmp_s = s.copy()
    flag1 = True
    for j in range(l1):
        if j < i or i + l2 <= j:
            if tmp_s[j] == '?':
                tmp_s[j] = 'a'
        else:
            if tmp_s[j] == t[j-i]:
                continue
            elif tmp_s[j] == '?':
                tmp_s[j] = t[j-i]
            else:
                flag1 = False

    if flag1:
        flag2 = True
        res = min(res, tmp_s)

if flag2:
    print(''.join(res))
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
S = input()
T = input()
if len(S)<len(T):
    print("UNRESTORABLE")
else:
    lenS =len(S)
    lenT = len(T)
    for i in range(lenS-lenT+1):
        if S[lenS-1-i] == "?" or S[lenS-1-i] == T[lenT-1]:
            for j in range(lenT):
                if S[lenS-1-i-j] != T[lenT-1-j] and S[lenS-1-i-j] != "?":
                    flag = 0
                    break
                flag = 1
            if flag == 1:
                for j in range(lenT):
                    S = S[:(lenS-1-i-j)]+T[lenT-1-j]+S[(lenS-i-j):]
                    #S[lenS-1-i-j] = T[lenT-1-j]
                for k in range(lenS):
                    if S[k] == "?":
                        print("a",end="")
                    else:
                        print(S[k],end="")
                print("")
                break
    else:
        print("UNRESTORABLE")

Submission status: Accepted

Solution code:
# coding: utf-8
import sys
#from operator import itemgetter
sysread = sys.stdin.buffer.readline
read = sys.stdin.buffer.read
#from heapq import heappop, heappush
#from collections import defaultdict
sys.setrecursionlimit(10**7)
#import math
#from itertools import product, accumulate, combinations, product
#import bisect# lower_bound etc
#import numpy as np
#from copy import deepcopy
#from collections import deque



def run():
    S = input()
    T = input()
    ref = 'abcdefghijklmnopqrstuvwxyz'
    ans =[]
    for i in range(len(S)-len(T)+1):
        checked = True
        for j in range(len(T)):
            if S[i+j] == T[j] or S[i+j]=='?':
                continue
            else:
                checked = False
                break
        if checked:
            ret = S[:i].replace('?', 'a') + T + S[i+len(T):].replace('?', 'a')
            ans.append(ret)
    try:
        print(sorted(ans)[0])
    except:
        print('UNRESTORABLE')



if __name__ == "__main__":
    run()

Submission status: Accepted

Solution code:
S = input()
T = input()
s = len(S)
t = len(T)
f = True
ans = []
for i in range(s):
    tmp = list(S)
    if t+i>s:
        continue
    else:
        for j in range(t):
            tmp2 = list(T)
            if tmp[i+j]=='?':
                tmp[i+j] = tmp2[j]
            elif tmp[i+j]== tmp2[j]:
                continue
            else:
                f = False
        if f:
            ans.append(tmp)
    f = True
res = []
for a in ans:
    for i in range(len(a)):
        if a[i]=='?': a[i]='a'
    res.append(''.join(a))
print(min(res) if res else 'UNRESTORABLE')

Submission status: Accepted

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

if len(S) < len(A):
    print('UNRESTORABLE')
    exit(0)


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

Submission status: Accepted

Solution code:
import sys


def compare(s: str, t: str) -> bool:
    return all(x == y or x == "?" for x, y in zip(s, t))


if __name__ == "__main__":
    S = input()
    T = input()

    len_s = len(S)
    len_t = len(T)

    indexes = []
    for i in range(len_s):
        if i + len_t <= len_s:
            s = S[i : i + len_t]
            if compare(s, T):
                indexes.append(i)

    if len(indexes) == 0:
        print("UNRESTORABLE")
        sys.exit(0)

    decrypted = []
    for j in indexes:

        d = ""
        for i, s in enumerate(S):
            if i in range(j, j + len_t):

                d += T[i - j]
                continue
            if s == "?":
                d += "a"
                continue

            d += s

        decrypted.append(d)
    decrypted.sort()
    print(decrypted[0])

Submission status: Accepted

Solution code:
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


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

    SN = len(S)
    TN = len(T)

    ans = []
    for i in range(SN - TN + 1):
        for j in range(TN):
            if S[i + j] == '?' or S[i + j] == T[j]:
                continue
            else:
                break
        else:
            ts = list(S)
            for j in range(TN):
                ts[i + j] = T[j]
            ans.append(ts)

    if len(ans) == 0:
        print('UNRESTORABLE')
    else:
        for i in range(len(ans)):
            ans[i] = ''.join(ans[i]).replace('?', 'a')
        print(sorted(ans)[0])


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import re

sdash = input().replace('?', '.')
t = input()
len_t = len(t)
isNotUsed = True

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

Submission status: Accepted

Solution code:
import sys
S = input()
T = input()
match_list = []
for i in range(len(S)-len(T)+1):
    is_match = True
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != '?':
            is_match = False
            break
    if is_match:
        match_list.append(i)
if not match_list:
    print("UNRESTORABLE")
    sys.exit()
ans = S[:max(match_list)] + T
if len(S) > len(ans):
    ans += S[len(ans):]
print(ans.replace('?', 'a'))

Submission status: Accepted

Solution code:
S = input()
T = input()
l = len(S)
lt = len(T)
ok = False
if l >= lt:
    for i in range(l - lt, -1, -1):
        SS = S[i:i+lt]
        can_replace = True
        for j, ss in enumerate(SS):
            can_replace *= (SS[j] == T[j] or SS[j] == '?')
        if can_replace:
            ok = True
            t_i = i
            break
if ok:
    S = S.replace('?', 'a')
    print(S[:t_i] + T + S[t_i + lt:])
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
S_p = input()
T = input()
S_len = len(S_p)
T_len = len(T)

if S_len < T_len:
    print("UNRESTORABLE")
    exit(0)

ans = []
for offset in range(S_len - T_len + 1):
    isRestorable = True
    for d in range(T_len):
        if S_p[offset+d] == "?":
            continue
        elif S_p[offset+d] != T[d]:
            isRestorable = False
            break
        else:
            pass
    if isRestorable:
        tmp = S_p[:offset] + T + S_p[offset+T_len:]
        ans.append(tmp.replace("?", "a"))
if len(ans) == 0:
    print("UNRESTORABLE")
else:
    ans.sort()
    print(ans[0])

Submission status: Accepted

Solution code:
s = input()
t = input()
ans = ""
for i in range(len(s)-len(t)+1):
    flag = 0
    for j in range(len(t)):
        if s[i+j]==t[j] or s[i+j]=="?":
            flag += 1
    if flag==len(t):
        tnp = ""
        for j in range(len(s)):
            if (s[j]!="?"):
                tnp += s[j]
            else:
                if (i<=j and j<i+len(t)):
                    tnp += t[j-i]
                else:
                    tnp += "a"
        ans = tnp
if (len(ans)>0):
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import sys
import heapq
import re
from itertools import permutations
from bisect import bisect_left, bisect_right
from collections import Counter, deque
from math import factorial, sqrt, ceil, gcd
from functools import lru_cache, reduce
from decimal import Decimal
from operator import mul

INF = 1 << 60
MOD = 1000000007
sys.setrecursionlimit(10 ** 7)


# UnionFind
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

# ダイクストラ
def dijkstra_heap(s, edge, n):
    #始点sから各頂点への最短距離
    d = [10**20] * n
    used = [True] * n #True:未確定
    d[s] = 0
    used[s] = False
    edgelist = []
    for a,b in edge[s]:
        heapq.heappush(edgelist,a*(10**6)+b)
    while len(edgelist):
        minedge = heapq.heappop(edgelist)
        #まだ使われてない頂点の中から最小の距離のものを探す
        if not used[minedge%(10**6)]:
            continue
        v = minedge%(10**6)
        d[v] = minedge//(10**6)
        used[v] = False
        for e in edge[v]:
            if used[e[1]]:
                heapq.heappush(edgelist,(e[0]+d[v])*(10**6)+e[1])
    return d

# 素因数分解
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr

# 組合せnCr
def combinations_count(n, r):
    if n < r:
        return 0
    r = min(r, n - r)
    numer = reduce(mul, range(n, n - r, -1), 1)
    denom = reduce(mul, range(1, r + 1), 1)
    return numer // denom

# 2数の最小公倍数
def lcm(x, y):
    return (x * y) // gcd(x, y)

# リストの要素の最小公倍数
def lcm_list(numbers):
    return reduce(lcm, numbers, 1)

# リストの要素の最大公約数
def gcd_list(numbers):
    return reduce(gcd, numbers)

# 素数判定
def is_prime(n):
    if n <= 1:
        return False
    p = 2
    while True:
        if p ** 2 > n:
            break
        if n % p == 0:
            return False
        p += 1
    return True


# limit以下の素数を列挙
def eratosthenes(limit):
    A = [i for i in range(2, limit+1)]
    P = []

    while True:
        prime = min(A)
        
        if prime > sqrt(limit):
            break
            
        P.append(prime)
            
        i = 0
        while i < len(A):
            if A[i] % prime == 0:
                A.pop(i)
                continue
            i += 1
            
    for a in A:
        P.append(a)
            
    return P

# 同じものを含む順列
def permutation_with_duplicates(L):

    if L == []:
        return [[]]

    else:
        ret = []

        # set（集合）型で重複を削除、ソート
        S = sorted(set(L))

        for i in S:

            data = L[:]
            data.remove(i)

            for j in permutation_with_duplicates(data):
                ret.append([i] + j)

        return ret

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]



# ここから書き始める
s = input()
t = input()
n = len(s)
m = len(t)
unrestorable = True
a = 0
for i in reversed(range(n)):
    if i-m+1 < 0:
        break
    t2 = s[i-m+1:i+1]
    ok = True
    for j in range(m):
        if t2[j] != "?" and t2[j] != t[j]:
            ok = False
            break
    if ok:
        # print("t2 =", t2)
        a = i-m+1
        unrestorable = False
        break
if unrestorable:
    print("UNRESTORABLE")
else:
    # print("a =", a)
    s2 = s[:a] + t + s[a+m:]
    # print(s2)
    ans = ""
    for i in s2:
        if i == "?":
            ans += "a"
        else:
            ans += i
    print(ans)

Submission status: Accepted

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

if not "?" in s:
    if ("".join(t) in "".join(s)):
        print("".join(s))
    else:
        print("UNRESTORABLE")
    exit()

ans=[]
switch=1
p=len(s)-len(t)
for i in range(p+1):
    for j in range(len(t)):
        if s[j+i]!=t[j] and s[j+i]!="?":
            switch=0
    if switch==1:
        c_s=s[:]
        for j in range(len(t)):
            c_s[j+i]=t[j]
        for j in range(len(c_s)):
            if c_s[j]=="?":
                c_s[j]="a"
        ans.append("".join(c_s))
    switch=1

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

Submission status: Accepted

Solution code:
def resolve():
    S = input()  # 問題文中のS'
    T = input()

    sl = len(S)
    tl = len(T)

    # Tと一致する文字がSに含まれるかをSの先頭から1つづつずらして判定する
    check = False
    for i in range(sl - tl, -1, -1):
        for j in range(tl):
            if S[i + j] == T[j] or S[i + j] == '?':
                check = True
            else:
                check = False
                break
        if check:
            print((S[:i] + T + S[i + tl:]).replace('?', 'a'))
            break
    if check is False:
        print('UNRESTORABLE')

        
resolve()

Submission status: Accepted

Solution code:
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

s = input()
t = input()

if len(s) < len(t):
    ans = "UNRESTORABLE"
else:
    reg = -1
    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:
            reg = i
            break
    if reg == -1:
        ans = "UNRESTORABLE"
    elif reg == len(s)-len(t):
        s = s[:i]+t
        ans = s.replace('?','a')
    else:
        s = s[:i]+t+s[i+len(t):]
        ans = s.replace('?','a')
print(ans)

Submission status: Accepted

Solution code:
def restore(s, t):
    orig_s = s
    for i in range(len(s) - len(t), -1, -1):
        s = list(orig_s)
        ok = True
        for j in range(len(t)):
            if s[i+j] != t[j] and s[i+j] != '?':
                ok = False
                break
            s[i+j] = t[j]
        if ok:
            for i in range(len(s)):
                if s[i] == '?':
                    s[i] = 'a'
            return "".join(s)
    return "UNRESTORABLE"


S = input()
T = input()

print(restore(S, T))

Submission status: Accepted

Solution code:
s = input()[::-1]
t = input()[::-1]
if len(s) < len(t):
    print("UNRESTORABLE")
    exit()
    
tmp = s.replace("?", "a")
if t in tmp:
    print(tmp[::-1])
    exit()
    
for i in range(len(s) - len(t) + 1):
    for j in range(len(t)):
        if s[i + j] == "?":
            continue
        elif s[i + j] == t[j]:
            continue
        break
    else:
        ans = ""
        for k in range(i):
            if s[k] == "?":
                ans += "a"
            else:
                ans += s[k]
        for tt in t:
            ans += tt
        for k in range(len(t) + i, len(s)):
            if s[k] == "?":
                ans += "a"
            else:
                ans += s[k]
        print(ans[::-1])
        exit()
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s = input()[::-1]
t = input()[::-1]
if len(s) < len(t):
    print("UNRESTORABLE")
    exit()
    
for i in range(len(s) - len(t) + 1):
    for j in range(len(t)):
        if s[i + j] == "?":
            continue
        elif s[i + j] == t[j]:
            continue
        break
    else:
        ans = ""
        for k in range(i):
            if s[k] == "?":
                ans += "a"
            else:
                ans += s[k]
        for tt in t:
            ans += tt
        for k in range(len(t) + i, len(s)):
            if s[k] == "?":
                ans += "a"
            else:
                ans += s[k]
        print(ans[::-1])
        exit()
print("UNRESTORABLE")

Submission status: Accepted

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

lt = len(T)
for i in range(len(S)-lt+1):
    s = S[i:i+lt]
    for t in range(lt):
        if s[t]=='?':
            if t != lt-1:
                pass
            else:
                ans.append((S[:i]+T+S[i+lt:]).replace('?', 'a'))
        else:
            if s[t]!=T[t]:
                break
            elif t==lt-1:
                ans.append((S[:i]+T+S[i+lt:]).replace('?', 'a'))
                break

print(min(ans) if len(ans)>0 else "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"))
            exit()
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break

print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s=input()
t=input()
a=[]
ans=[]
for i in range(len(s)-len(t)+1):
  flg=0
  for j in range(len(t)):
    if s[i+j]!=t[j] and s[i+j]!='?':
      flg=1
  if flg==0:
    a.append(i)
for i in a:
  tmp=s[:i]+t+s[i+len(t):]
  for j in range(len(tmp)):
    if tmp[j]=='?':
      tmp=tmp[:j]+'a'+tmp[j+1:]
  ans.append(tmp)
ans.sort()
if ans==[]:
  print('UNRESTORABLE')
else:
  print(ans[0])

Submission status: Accepted

Solution code:
import re

def main():
    s = input().replace("?", ".")
    t = input()
    ans = []

    for i in range(len(s)-len(t)+1):
        if not re.match(s[i:i+len(t)], t):
            continue
        tmp = (s[:i] + t + s[i+len(t):]).replace(".", "a")
        ans.append(tmp)

    if not ans:
        print("UNRESTORABLE")
    else:
        print(min(ans))

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import re
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


sd = S()
sd = sd.replace('?', '.')  # 正規表現を使うため、「任意の一文字」を表す「.」に変換しておく
t = S()

# s' の先頭から len(t) 文字を見て、 ? を 置き換えることで t にできる場合、
# t のために 使った s の ? 以外の ? を全て a に変えた文字列を候補の一つとする
ans = []
for i in range(len(sd) - len(t) + 1):
    if not re.match(sd[i:i + len(t)], t):
        continue
    kouho = (sd[:i] + t + sd[i + len(t):]).replace('.', 'a')
    ans.append(kouho)

if not ans:
    print('UNRESTORABLE')
    sys.exit()

print(min(ans))  # 文字列 の min は 辞書順の最小になる

Submission status: Accepted

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

for i in range(len(s)):
    l.clear()
    cnt = 0
    pre = i
    while cnt < len(t) :
        if pre + cnt >= len(s):
            break
        if s[i] == t[cnt] or s[i] == "?":
            l.append(t[cnt])
            i += 1
            cnt += 1
        else:
            break
    else:
        ans = s[:pre] + "".join(l) + s[i:]
        ans = ans.replace("?", "a")
        ans = ans[::-1]
        print(ans)
        exit()
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s = input()
t = input()
ans = "UNRESTORABLE"
for begin in range(len(s)):#塗り替えるとこの始点
    if begin+len(t) > len(s):
        break
    tmp = list(s)
    ti = 0
    for i in range(begin,begin+len(t)):
        tmp[i] = t[ti]
        ti += 1
    for i in range(len(s)):
        if s[i] != '?':
            if s[i] != tmp[i]:
                break
    else:
        for i in range(len(s)):
            if tmp[i] == "?":
                tmp[i] = 'a'
        ans = "".join(tmp)
print(ans)

Submission status: Accepted

Solution code:
s=input()
t=input()
l=[]
import sys
if len(t)>len(s):
  import sys
  print("UNRESTORABLE")
  exit()
  
for i in range(len(s)-len(t)+1):
  z=s[:i]
  for j in range(i,i+len(t)):
    if s[j]!=t[j-i] and s[j]!="?":
      break
    else:
      z+=t[j-i]
  else:
    z+=s[i+len(t):]
    l.append(z.replace("?","a"))
l.sort()
print(l[0] if len(l) else "UNRESTORABLE")

Submission status: Accepted

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

for i in range(len(s) - len(t) + 1)[::-1]:
    for j, (ns, nt) in enumerate(zip(s[i:i+len(t)], t)):
        if ns != nt and ns != '?':
            break
        if j == len(t) -1:
            ans = s[:i] + t + s[i+len(t):]
            print(ans.replace('?', 'a'))
            exit()
print('UNRESTORABLE')

Submission status: Accepted

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

for i in range(len(s) - len(t) + 1)[::-1]:
    cnt = 0
    for ns, nt in zip(s[i:i+len(t)], t):
        cnt += 1
        if ns != nt and ns != '?':
            break
        if cnt == len(t):
            ans = s[:i] + t + s[i+len(t):]
            print(ans.replace('?', 'a'))
            exit()
print('UNRESTORABLE')

Submission status: Accepted

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

ans = 'UNRESTORABLE'
def test(i):
    for ns, nt in zip(s[i:i+len(t)], t):
        if ns == '?':
            continue
        if ns != nt:
            return False
    return True

for i in range(len(s) - len(t) + 1):
    if test(i):
        re_s = s.replace('?', 'a')
        ans = re_s[:i] + t + re_s[i+len(t):]

print(ans)

Submission status: Accepted

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

len_t = len(T)
for i in reversed(range(len(S)-len_t + 1)):
    for j, s in enumerate(S[i:i+len_t]):
        if s != T[j] and s != "?":
            break
        if j == len_t - 1:
            res = S[:i] + T + S[i + len_t:]
            res = res.replace("?", "a")
            print(res)
            exit()

print("UNRESTORABLE")

Submission status: Accepted

Solution code:
S=input()
T=input()
for i in range(len(S)-1,len(T)-2,-1):
  a=''
  for j in range(len(T)):
    if S[i+1-len(T)+j]=='?':
      a=a+T[j]
    else:
      a=a+S[i+1-len(T)+j]
  if a==T:
    U=S[:i+1-len(T)]+a+S[i+1-len(T)+len(T):]
    c=''
    for k in range(len(U)):
      if U[k]=='?':
        c=c+'a'
      else:
        c=c+U[k]
    print(c)
    exit()
print('UNRESTORABLE')

Submission status: Accepted

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

if len(t) > len(s):
    print("UNRESTORABLE")
    exit()

s = s[::-1]
t = t[::-1]
for i in range(len(s)-len(t)+1):
    k = 0
    while True:
        if k == len(t):
            ans = s[:i] + t + s[i+len(t):]
            print(ans[::-1].replace("?","a",len(ans)))
            exit()
        if t[k] == s[i+k] or s[i+k] == "?":
            k += 1
        else:
            break
print("UNRESTORABLE")

Submission status: Accepted

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

s= s.replace('?','.')

n_s = len(s)
n_t = len(t)

res = []

for i in range(n_s-n_t+1):
    m = re.match(s[i:i+n_t],t)
    if not m:continue
    res.append((s[:i]+t+s[i+n_t:]).replace('.','a'))
if not res:
    print('UNRESTORABLE')
else:
    print(min(res))

Submission status: Accepted

Solution code:
def readinput():
    s=input()
    t=input()
    return s,t

def main(s,t):
    found=False
    it=0
    for i in range(len(s)-len(t),-1,-1):
        for j in range(len(t)):
            #print(s[i+j],t[j])
            if s[i+j]=='?':
                continue
            if s[i+j]!=t[j]:
                break
        else:
            found=True
            it=i
            break
    if found==False:
        return 'UNRESTORABLE'

    ans=s[:it]+t+s[it+len(t):]
    ans=ans.replace('?','a')

    return ans

if __name__=='__main__':
    s,t=readinput()
    ans=main(s,t)
    print(ans)

Submission status: Accepted

Solution code:
s=input()
t=input()
l=[]
check=0
for i in range(len(s)-len(t)+1):
    c=0
    for j in range(len(t)):
        if s[i+j]!=t[j] and s[i+j]!="?":
            break
        else:
            c+=1
    if c==len(t):
        check+=1
        l.append(s[:i]+t+s[i+j+1:])
    #print(c)
#print(l)
if check==0:
    print("UNRESTORABLE")
else:
    L=[]
    for i in range(len(l)):
        x=""
        for j in range(len(s)):
            if l[i][j]=="?":
                x+="a"
            else:
                x+=l[i][j]
        L.append(x)
    L.sort()
    print(L[0])

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
import copy
ans = []
for i in reversed(range((len(S)-len(T))+1)):
    R = copy.deepcopy(S)
    for j in range(len(T)):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break
    else:
        for j in range(len(T)):
            R[i+j] = T[j]
        for j in range(len(S)):
            R[j] = "a" if R[j] == "?" else R[j]
        ans.append("".join(R))
if ans:
    ans.sort()
    print(ans[0])
else:
    print("UNRESTORABLE")