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: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[22]:


Sdash = input()
T = input()


# In[23]:


length_S = len(Sdash)
length_T = len(T)
if length_S >= length_T:
    for i in range(length_S-length_T+1):
        for j in range(length_T):
            if Sdash[j+length_S-length_T-i] != T[j] and Sdash[j+length_S-length_T-i] != "?":
                break
        else:
            ans = Sdash[:length_S-length_T-i]+T+Sdash[length_S-i+length_T:]
            ans = [x if x != "?" else "a" for x in ans]
            print("".join(ans))
            break
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")


# In[ ]:

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python
# coding: utf-8

# In[8]:


Sdash = input()
T = input()


# In[9]:


if len(Sdash) >= len(T):
    for i in range(len(Sdash)-len(T)+1):
        for j in range(len(T)):
            if Sdash[j+i] != T[j] and Sdash[j+i] != "?":
                break
        else:
            ans = Sdash[:i]+T+Sdash[i+len(T):]
            ans = [x if x != "?" else "a" for x in ans]
            print("".join(ans))
            break
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

s = len(S)
t = len(T)

import re

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

pos = -1
wani = 0

for i in range (0, s-t+1):
	wani = 0
	for j in range (0,t):
		if	S[i+j] != T[j] and S[i+j] !='?':
			wani = 1
	if wani == 0 and pos == -1:
		pos = i        
        
if pos == -1:
	print("UNRESTORABLE")
	exit()

A = []
for i in range (0, s):
	A.append(S[i])

for i in range (0, t):
	A[pos+i] = T[i]

for i in range (0, s):
	if A[i] == '?':
		A[i] = 'a'

print(*A, sep='')

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
s = len(S)
t = len(T)
X = False
for i in range(s - t + 1):
    OK = True
    for j in range(t):
        if S[i + j] != '?' and S[i + j] != T[j]:
            OK = False
            break
    if OK:
        for j in range(t):
            S[i + j] = T[j]
        X = True
        break
if not X:
    print('UNRESTORABLE')
else:
    for i in range(s):
        if S[i] == '?':
            S[i] = 'a'
        print(S[i], end='')
    print('')

Submission status: Wrong Answer

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):]
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: Wrong Answer

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

INF = 10**18
idx = INF
word = ''
for i in range(len(A)):
    key = A[:len(A)-i] + '?'*i
    tmp_idx = S.rfind(key)
    if tmp_idx != -1:
        if tmp_idx < idx:
            idx = tmp_idx
            word = key

if idx == INF:
    print('UNRESTORABLE')
    exit(0)

ans = S[:idx] + A + S[idx+len(A):]
ans = ans.replace('?', 'a')
print(ans)

Submission status: Wrong Answer

Solution code:
sdash = input()
n = len(sdash)
t = input()
s = ['*'] * n
isNotUsed = True

for i in range(len(t), n+1):
    if sdash[-i] == t[0] and isNotUsed:
        for j in range(len(t)):
            s[-i+j] = t[j]
        isNotUsed = False
    elif sdash[-i] == '?':
        s[-i] = 'a'
    else:
        s[-i] = sdash[-i]
if isNotUsed:
    print('UNRESTORABLE')
else:
    s = ''.join(s)
    s.replace('*', 'a')
    print(s)

Submission status: Wrong Answer

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:
        a = i-m+1
        unrestorable = False
if unrestorable:
    print("UNRESTORABLE")
else:
    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: Wrong Answer

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):
        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: Wrong Answer

Solution code:
def restore(s, t):
    orig_s = s
    for i in range(len(s) - len(t) + 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: Wrong Answer

Solution code:
s = input()[::-1]
t = input()[::-1]
if len(s) < len(t):
    
    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: Wrong Answer

Solution code:
s = input()[::-1]
t = input()[::-1]
if len(s) < len(t):
    
    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 tt in t:
            ans += tt
        for i in range(len(t), len(s)):
            if s[i] == "?":
                ans += "a"
            else:
                ans += s[i]
        print(ans[::-1])
        exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

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]=='?':
            pass
        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: Wrong Answer

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

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

print(min(ans) if len(ans)>0 else "UNRESTORABLE")

Submission status: Wrong Answer

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

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

print(S[::-1] if S!=_S else "UNRESTORABLE")

Submission status: Wrong Answer

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

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

print(S[::-1] if S!=_S else "UNRESTORABLE")

Submission status: Wrong Answer

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

flag = False
T_l = len(T)
S_l = len(S)
u = 0

if T in S:
    flag = True

while u < S_l:
    cnt = 0
    name = S[u]

    if name == T[0] or name == "?":
        cnt += 1
        u += 1
        for j in range(u,S_l):
            if cnt == T_l:
                break
            if S[j] == "?" or S[j] == T[cnt]:
                cnt += 1
                u += 1
            else:
                break
        
        if cnt == T_l:
            if flag == False:
                ans = ans + list(T)
                flag = True
            else:
                for j in range(u-cnt, u):
                    if S[j] == "?":
                        ans.append("a")
                    else:
                        ans.append(S[j])

        else:
            for j in range(cnt):
                if S[j] == "?":
                    ans.append("a")
                else:
                    ans.append(S[j])

    else:
        ans.append(name)
        u += 1
        continue

if flag:
    ans = "".join(ans)
    ans = ans[::-1]
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

flag = False
T_l = len(T)
S_l = len(S)
u = 0

while u < S_l:
    cnt = 0
    name = S[u]

    if name == T[0] or name == "?":
        cnt += 1
        u += 1
        for j in range(u,S_l):
            if cnt == T_l:
                break
            if S[j] == "?" or S[j] == T[cnt]:
                cnt += 1
                u += 1
            else:
                break
        
        if cnt == T_l:
            if flag == False:
                ans = ans + list(T)
                flag = True
            else:
                for j in range(u-cnt, u):
                    if S[j] == "?":
                        ans.append("a")
                    else:
                        ans.append(S[j])

        else:
            for j in range(cnt):
                if S[j] == "?":
                    ans.append("a")
                else:
                    ans.append(S[j])

    else:
        ans.append(name)
        u += 1
        continue

if flag:
    ans = "".join(ans)
    ans = ans[::-1]
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

flag = False
T_l = len(T)
S_l = len(S)
u = 0

while u < S_l:
    cnt = 0
    name = S[u]

    if name == T[0] or name == "?":
        cnt += 1
        u += 1
        for j in range(u,S_l):
            if cnt == T_l:
                break
            if S[j] == "?" or S[j] == T[cnt]:
                cnt += 1
                u += 1
            else:
                break
        
        if cnt == T_l:
            if flag == False:
                ans = ans + list(T)
                flag = True
            else:
                for j in range(cnt):
                    if S[j] == "?":
                        ans.append("a")
                    else:
                        ans.append(S[j])

        else:
            for j in range(cnt):
                if S[j] == "?":
                    ans.append("a")
                else:
                    ans.append(S[j])

    else:
        ans.append(name)
        u += 1
        continue

if flag:
    ans = "".join(ans)
    ans = ans[::-1]
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

flag = False
T_l = len(T)
S_l = len(S)
u = 0

while u < S_l:
    cnt = 0
    name = S[u]

    if name == T[0] or name == "?":
        cnt += 1
        u += 1
        for j in range(u,S_l):
            if cnt == T_l:
                break
            if S[j] == "?" or S[j] == T[cnt]:
                cnt += 1
                u += 1
            else:
                break
        
        if cnt == T_l:
            ans = ans + list(T)
            flag = True
        else:
            for j in range(cnt):
                if S[j] == "?":
                    ans.append("a")
                else:
                    ans.append(S[j])

    else:
        ans.append(name)
        u += 1
        continue

if flag:
    ans = "".join(ans)
    print(*ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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)+1:]).replace(".", "a")
        ans.append(tmp)

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    t = input()
    ls = len(s)
    lt = len(t)
    ans = []
    for i in range(lt):
        for j in range(ls):
            if (t[i] == s[j]) and (j-i >= 0) and (j+lt-i <= ls):
                for k in range(lt):
                    if s[j-i+k] != "?" and s[j-i+k] != t[k]:
                        break
                    elif k == lt-1:
                        tmp = s[:j-i] + t + s[j+lt-i:]
                        tmp = tmp.replace("?", "a")
                        ans.append(tmp)

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

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
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")
        print(ans)
        exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
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 + 1:]
        ans = ans.replace("?", "a")
        print(ans)
        exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
l=[]
import sys
if len(t)>len(s) or (len(t)==len(s) and t!=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: Wrong Answer

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)):
        print(j, ns, nt)
        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: Wrong Answer

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

for i in range(len(s) - len(t) + 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: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
a=0
l=len(T)-1
for i in range(len(S)-1,-1,-1):
  if S[i]=='?'or S[i]==T[l]:
    l-=1
  else:
    l=len(T)-1
  if l==-1:
    a=i
    break
if l!=-1:
  print('UNRESTORABLE')
else:
  c=0
  p=''
  for j in range(len(S)):
    if a<=j<a+len(T):
      p=p+T[c]
      c+=1
    else:
      if S[j]=='?':
        p=p+'a'
      else:
        p=p+S[j]
  print(p)

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
a=0
l=0
for i in range(len(S)):
  if S[i]=='?'or S[i]==T[l]:
    l+=1
  else:
    l=0
  if l==len(T):
    a=i
    break
if l!=len(T):
  print('UNRESTORABLE')
else:
  c=0
  p=''
  for j in range(len(S)):
    if a-l<j<=a:
      p=p+T[c]
      c+=1
    else:
      if S[j]=='?':
        p=p+'a'
      else:
        p=p+S[j]
  print(p)

Submission status: Wrong Answer

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)):
    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[k] or s[k] == "?":
            k += 1
        else:
            break
print("UNRESTORABLE")

Submission status: Wrong Answer

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

s = s[::-1]
t = t[::-1]
n_s = len(s)
n_t = len(t)
i = 0
cnt = 0
flg = True
while i < n_s:
    if s[i] == '?':
        cnt += 1
        i += 1
    else:
        if s[i] == t[len(t)-1]: # tの先頭文字と同じ
            if n_t-1 < cnt:
                while n_t-1 != cnt:
                    res += 'a'
                    cnt -= 1
            if n_t-1 == cnt and flg:
                for j in range(n_t-1):
                    res += t[j]
                flg = False
            else:
                for j in range(cnt):
                    res += 'a'
        else:
            if n_t < cnt:
                for j in range(n_t):
                    res += t[j]
            else:
                for j in range(cnt):
                    res += 'a'
        res+= s[i]
        cnt = 0
        i += 1
if 0 < cnt:
    for i in range(cnt):
        res+='a'
res = res[::-1]
t = t[::-1]
if t in res:
    print(res)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

res = ""

s = s[::-1]
t = t[::-1]
n_s = len(s)
n_t = len(t)
i = 0
cnt = 0
flg = True
while i < n_s:
    if s[i] == '?':
        cnt += 1
        i += 1
    else:
        if s[i] == t[len(t)-1]: # tの先頭文字と同じ
            if n_t-1 < cnt:
                while n_t-1 != cnt:
                    res += 'a'
                    cnt -= 1
            if n_t-1 == cnt and flg:
                for j in range(n_t-1):
                    res += t[j]
                flg = False
            else:
                for j in range(cnt):
                    res += 'a'
        else:
            if n_t < cnt:
                for j in range(n_t):
                    res += t[j]
            else:
                for j in range(cnt):
                    res += 'a'
        res+= s[i]
        cnt = 0
        i += 1
if 0 < cnt:
    for i in range(cnt):
        res+='a'
res = res[::-1]
t = t[::-1]
if t in res:
    print(res)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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):
        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: Wrong Answer

Solution code:
S = list(input())
T = list(input())
import copy
ans = []
if len(S) < len(T):
    print("UNRESTRABLE")
else:
    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")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import copy
S=input()
N=len(S)
SS=[]
for i in range(N):
    SS.append(S[i])

T=input()
M=len(T)
TT=[]

for i in range(M):
    TT.append(T[i])

if N<M:
    print("UNRESTORABLE")
else:
    for i in range(N-M):
        flag=True
        tmp=copy.deepcopy(SS)
        for j in range(M):
            #print(SS[N-1-i-j],TT[M-1-j])
            if SS[N-1-i-j]==TT[M-1-j] or SS[N-1-i-j]=="?":
                tmp[N-1-i-j]=TT[M-1-j]
            else:
                flag=False
                break
        
        if flag==True:
            Z=[str(a) for a in tmp]
            Z="".join(Z)
            #print(Z)

            ans=Z.replace("?","a")
            print(ans)
            exit()
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import copy
S=input()
N=len(S)
SS=[]
for i in range(N):
    SS.append(S[i])

T=input()
M=len(T)
TT=[]

for i in range(M):
    TT.append(T[i])

if N<M:
    print("UNRESTORABLE")
else:
    for i in range(N-M):
        flag=True
        tmp=copy.deepcopy(SS)
        for j in range(M):
            #print(SS[N-1-i-j],TT[M-1-j])
            if SS[N-1-i-j]==TT[M-1-j] or SS[N-1-i-j]=="?":
                tmp[N-1-i-j]=T[M-1-j]
            else:
                flag=False
                break
        
        if flag==True:
            Z=[str(a) for a in tmp]
            Z="".join(Z)
            #print(Z)

            ans=Z.replace("?","a")
            print(ans)
            exit()
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import re
Sp = input().replace('?','.')
T = input()
flag = 0
for i in range(len(Sp)-len(T)+1):
    if re.findall(Sp[i:i+len(T)],T):
        Sp = Sp[:i]+T+Sp[i+len(T)+1:]
        flag = 1
        break
if flag == 1:
    print(Sp.replace('.','a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import re
Sp = input().replace('?','.')
T = input()
flag = 0
for i in range(len(Sp)-len(T)+1):
    if re.search(Sp[i:i+len(T)],T):
        Sp = Sp[:i]+T+Sp[i+len(T)+1:]
        flag = 1
        break
if flag == 1:
    print(Sp.replace('.','a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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