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:
s_dash = input()
t = input()
match_index = []
candidate = []
for i in range(len(s_dash) - len(t) + 1):
    for j in range(len(t)):
        if not(t[j] == s_dash[i + j] or s_dash[i + j] == '?'):
            break
        if j == len(t) - 1:
            match_index.append(i)
for index in match_index:
    s = s_dash[:index] + t
    if index != len(s_dash) - len(t):
        s += s_dash[index + len(t)]
    s = list(s)
    for i in range(len(s)):
        if s[i] == '?':
            s[i] = 'a'
    s = "".join(s)
    candidate.append(s)
candidate.sort()
if len(candidate) == 0:
    print('UNRESTORABLE')
else:
    print(candidate[0])

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    s = str(readline().rstrip().decode('utf-8'))
    t = str(readline().rstrip().decode('utf-8'))
    lt = len(t)
    ans = []
    for i in range(len(s) - len(t), -1, -1):
        ts = s[i:i+lt]
        b = True
        for j in range(lt):
            if ts[j] != "?" and ts[j] != t[j]:
                b = False
                break
        if b:
            for j in range(len(s)):
                if i <= j < i + lt:
                    ans.append(t[j-i])
                else:
                    ans.append(s[j] if s[j] != "?" else "a")
            print("".join(ans))
            exit()


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

ans = "UNRESTORABLE"

ls = []

for i in range(len(t)):
    for j in range(i, len(s)-len(t)+i):
        if s[j] == t[i]:
            for k in range(len(t)):
                if t[k] != s[j+k-i] and s[j+k-i] != "?":
                    break
                if k == len(t)-1:
                    tmps = s[:j-i] + t + s[j-i+len(t):]
                    for p in range(len(s)):
                        if tmps[p] == "?":
                            tmps = tmps[:p] + "a" + tmps[p+1:]
                    ls.append(tmps)

ls.sort()
if len(ls) != 0:
    ans = ls[0]

print(ans)

Submission status: Wrong Answer

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

ans = "UNRESTORABLE"

ls = []

for i in range(len(t)):
    for j in range(i, len(s)-len(t)+i+1):
        if s[j] == t[i]:
            for k in range(len(t)):
                if t[k] != s[j+k-i] and s[j+k-i] != "?":
                    break
                if k == len(t)-1:
                    tmps = s[:j-i] + t + s[j-i+len(t):]
                    for p in range(len(s)):
                        if tmps[p] == "?":
                            tmps = tmps[:p] + "a" + tmps[p+1:]
                    ls.append(tmps)

ls.sort()
if len(ls) != 0:
    ans = ls[0]

print(ans)

Submission status: Wrong Answer

Solution code:
import re

s = str(input())
t = str(input())


#Sの?を正規表現　英文字1つに変換する
#tがsのどこに含まれるかどうかを、開始位置を一文字ずつずらしながら調査
#最初に見つかった場所を対象にtを代入
#残りの文字は'a'に変換
#リストに格納
#sortして最初に来たものがanswer
#リストがからの場合は UNRESTORABLE

NS = []

for i in range(len(s)):
    #対象外のものは?をaに変換
    s_res = s[:i]
    s_res = s_res.replace('?', 'a')
    
    #対象外のものは?を.に変換
    #探索範囲は探る文字列tと同じ長さ
    s_obj = s[i:i+len(t)]
    s_obj = s_obj.replace('?', '.')
    s_comp = re.compile(s_obj)

    s_res_f = s[i+len(t):]
 
    matchobj = s_comp.search(t)

    if matchobj:
        start = matchobj.start()
        new_s = s_res + t + s_res_f
        new_s = new_s.replace('?', 'a')
        NS.append(new_s)

if len(NS) == 0:
    ans = 'UNRESTORABLE'
else:
    ans = sorted(NS)[0]

print(ans)

Submission status: Wrong Answer

Solution code:
import re

s = str(input())
t = str(input())

# tがsのどこかに入らなければならない
# 入ったら辞書順最小 -> 残りの？にaを代入 を出力
# ?を正規表現に置き換えて確認できそう

NS = []

for i in range(len(s)):
    s_res = s[:i]
    s_obj = s[i:]
    
    if len(t) > len(s_obj):
        break

    #対象外は辞書順最小に変換
    s_res.replace('?', 'a')

    s_w = s_obj.replace('?', '.') 
    s_re = re.compile(s_w)

    matchobj = s_re.fullmatch(t)
    if matchobj:
        start = matchobj.start()
        end = matchobj.end()
        new_s = s_res + s_obj[:start] + t + s_obj[end:]
        new_s = new_s.replace('?', 'a')
        NS.append(new_s)

if len(NS) >= 1:
    NS = sorted(NS)
    ans = NS[0]
else:
    ans = 'UNRESTORABLE'

print(ans)

Submission status: Wrong Answer

Solution code:
import re

s = str(input())
t = str(input())

# tがsのどこかに入らなければならない
# 入ったら辞書順最小 -> 残りの？にaを代入 を出力
# ?を正規表現に置き換えて確認できそう

NS = []

for i in range(len(s)):
    s_res = s[:i]
    s_obj = s[i:]
    
    #対象外は辞書順最小に変換
    s_res.replace('?', 'a')

    s_w = s_obj.replace('?', '.') 
    s_re = re.compile(s_w)

    matchobj = s_re.fullmatch(t)
    if matchobj:
        start = matchobj.start()
        end = matchobj.end()
        new_s = s_res + s_obj[:start] + t + s_obj[end:]
        new_s = new_s.replace('?', 'a')
        NS.append(new_s)

if len(NS) >= 1:
    NS = sorted(NS)
    ans = NS[0]
else:
    ans = 'UNRESTORABLE'

print(ans)

Submission status: Wrong Answer

Solution code:
import re

s = str(input())
t = str(input())

# tがsのどこかに入らなければならない
# 入ったら辞書順最小 -> 残りの？にaを代入 を出力
# ?を正規表現に置き換えて確認できそう

NS = []

for i in range(len(s)):
    s_res = s[:i]
    s_obj = s[i:]
    
    #対象外は辞書順最小に変換
    s_res.replace('?', 'a')

    s_w = s_obj.replace('?', '.') 
    s_re = re.compile(s_w)

    matchobj = s_re.fullmatch(t)
    if matchobj:
        start = matchobj.start()
        end = matchobj.end()
        print('-' * 30)
        print('i' + str(i))
        print(start)
        print(end)
        print('-' * 30)
        
        new_s = s_res + s_obj[:start] + t + s_obj[end:]
        new_s = new_s.replace('?', 'a')
        NS.append(new_s)

if len(NS) >= 1:
    NS = sorted(NS)
    ans = NS[0]
else:
    ans = 'UNRESTORABLE'

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
S = len(s)
T = len(t)

for i in range(S):
    if S - i >= T:
        ans = list(s)
        cnt = 0
        for j in range(T):
            if s[i + j] == t[j] or s[i + j] == "?":
                cnt += 1
                ans[i + j] = t[j]
            if cnt == T:
                print("".join(ans).replace("?", "a"))
                exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
S = len(s)
T = len(t)

for i in range(S):
    if s[i] == t[0] and S - i >= T:
        ans = list(s)
        cnt = 0
        for j in range(T):
            if s[i + j] == t[j] or s[i + j] == "?":
                cnt += 1
                ans[i + j] = t[j]
            if cnt == T:
                print("".join(ans).replace("?", "a"))
                exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

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

ANS=[]
for i in range(n-m+1):
    for j in range(m):
        #print(s[i+j],t[j])
        if s[i+j] != "?" and s[i+j] != t[j]:
            break
    else:
        ans = s[:i] + t
        ans = ans.replace('?','a')
        ANS.append(ans)
if len(ANS) == 0:
    print("UNRESTORABLE")
else:
    ANS.sort()
    print(ANS[0])

Submission status: Wrong Answer

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

start_t = t[0]

def t_check(t_str, t_e):
  r = True
  for i, ts in enumerate(list(t_e)):
    if ts == '?':
      continue
    if ts != t_str[i]:
      r = False
  return r

a = s
is_t_correct = False
for i, si in enumerate(list(s)):
  if si != '?' and si == start_t:
    if len(s) - i >= len(t):
      expected_t = a[i:i+len(t)]
      if t_check(t, expected_t):
        a = a[0:i] + t + a[i+len(t):]
        is_t_correct = True

if is_t_correct is False:
  print('UNRESTORABLE')
  exit(0)
      
print(a.replace('?', 'a'))

Submission status: Wrong Answer

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

start_t = t[0]

a = s
is_t_correct = False
for i, si in enumerate(list(s)):
  if si != '?' and si == start_t:
    if len(s) - i >= len(t):
      a = a[0:i] + t + a[i+len(t):]
      is_t_correct = True

if is_t_correct is False:
  print('UNRESTORABLE')
  exit(0)
      
print(a.replace('?', 'a'))

Submission status: Wrong Answer

Solution code:
S = list(input())
lenS = len(S)
T = list(input())
lenT = len(T)
Flag = False
for i in range(lenS - lenT + 1):
    for j in range(lenT):
        if S[i + j] != "?" and T[j] != S[i + j]:
            break
    else:
        Flag = True
        for j in range(lenT):
            S[i + j] = T[j]
        break
if Flag:
    for i in range(lenS):
        if S[i] == "?":
            S[i] = "a"
    print("".join(S))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

    rs = S.replace("?","a")

    candidates = set()

    for i in range(len(S)-len(T)+1):
        ts = S[i:i+len(T)]
        #print("checking:",ts)
        is_mismatched = False
        for ii in range(len(T)):
            if ts[ii] != "?" and ts[ii] != T[ii]:
                is_mismatched = True
                break
        if not is_mismatched:
            candidates.add(rs[:i] + T + rs[i+len(T):(len(S)-(i+len(T)))])
           
    return min(candidates) if candidates else "UNRESTORABLE"

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

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

    rs = S.replace("?","a")

    candidate = None

    for i in range(len(S)-len(T)+1):
        ts = S[i:i+len(T)]
        #print("checking:",ts)
        is_mismatched = False
        for ii in range(len(T)):
            if ts[ii] != "?" and ts[ii] != T[ii]:
                is_mismatched = True
                break
        if not is_mismatched:
            candidate = rs[:i] + T + rs[i+len(T):(len(S)-(i+len(T)))]
           
    return candidate if candidate else "UNRESTORABLE"

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

Solution code:

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

    if len(S) < len(T):
        return "UNRESTORABLE"

    rs = S.replace("?","a")

    candidate = None

    for i in range(len(S)-len(T)+1):
        ts = S[i:i+len(T)]
        #print("checking:",ts)
        is_mismatched = False
        for ii in range(len(T)):
            if not (ts[ii] == "?" or ts[ii] == T[ii]):
                is_mismatched = True
                break
        if not is_mismatched:
            candidate = rs[:i] + T + rs[i+len(T):(len(S)-(i+len(T)))]
           
    return candidate if candidate else "UNRESTORABLE"

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

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

    rs = S.replace("?","a")

    candidate = None

    for i in range(len(S)-len(T)+1):
        ts = S[i:i+len(T)]
        #print("checking:",ts)
        is_mismatched = False
        for ii in range(len(T)):
            if not (ts[ii] == "?" or ts[ii] == T[ii]):
                is_mismatched = True
                break
        if not is_mismatched:
            candidate = rs[:i] + T + rs[i+len(T):(len(S)-(i+len(T)))]
           
    return candidate if candidate else "UNRESTORABLE"

if __name__ == '__main__':
    print(main())

Submission status: Wrong Answer

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


for i in range(len(S)-len(T)+1):
    cnt = 0
    for j in range(len(T)):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break

        if cnt == len(T):
            # Sのi~i+jまでがTと一致させられる
            ans = S[:i] + T + S[i+len(T):]

            ans = ans.replace("?", "a")
            print(ans)
            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 j in range(len(T)):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break

        if cnt == len(T):
            # Sのi~i+jまでがTと一致させられる
            ans = S[:i] + T + S[i+j+1:]

            ans = ans.replace("?", "a")
            print(ans)
            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 j in range(len(T)):
        if S[i+j] != "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break

        if cnt == len(T):
            # Sのi~i+jまでがTと一致させられる
            ans = S[:i] + T + S[i+j+1:]

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

Submission status: Wrong Answer

Solution code:

S = input()
T = input()


for i in range(len(S)-len(T)+1):
    idx = 0
    for j in range(len(T)):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break

        if j == len(T)-1:
            # Sのi~i+jまでがTと一致させられる
            ans = S[:i] + T + S[i+j+1:]
            #print(type(ans))
            ans = ans.replace("?", "a")
            print(ans)
            exit()
        
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:

S = input()
T = input()


for i in range(len(S)-len(T)+1):
    idx = 0
    for j in range(len(T)):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break

        if j == len(T)-1:
            # Sのi~i+jまでがTと一致させられる
            ans = S[:i] + T + S[i+j+1:]
            print(type(ans))
            ans = ans.replace("?", "a")
            print(ans)
            exit()
        
print("UNRESTORABLE")

Submission status: Wrong Answer

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

ANS = False
for i in range(len(S) - len(T) + 1):
    count = 0
    left = i
    right = i + len(T)

    for sv, tv in zip(S[left:right], T):
        if sv != tv and sv != '?':
            break
        count += 1

    if count == len(T):
        S[left:right] = T
        ANS = True
        break

if ANS:
    for w in S:
        if w == '?':
            print('a', end='')
        else: 
            print(w, end='')
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

ANS = False
for i in range(len(S) - len(T) + 1):
    count = 0
    left = i
    right = i + len(T)

    for sv, tv in zip(S[left:right], T):
        if sv != tv and sv != '?':
            break
        count += 1

    if count == len(T):
        S[left:right] = T
        ANS = True

if ANS:
    for w in S:
        if w == '?':
            print('a', end='')
        else: 
            print(w, end='')
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

j = 0
idx = 0
flag = 1
for i,s in enumerate(S):
    if s == T[j-1] or s == "?":
        j = min(j+1,len(T))
    elif s == T[0] or s == "?":
        j = 1
    else:
        j = 0
    if j >= len(T):
        flag = 0
        # print(i,j,len(T))
        idx = i+1-len(T)

if flag:
    print('UNRESTORABLE')
    exit()

S = S[:idx]+T+S[idx+len(T):]
for i in range(len(S)):
    if S[i] == "?":
        S[i] = "a"

print("".join(S))

Submission status: Wrong Answer

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

for i in range(len(s)) :

  counter = 0
  
  for j in range(len(t)) :
    if len(s) == i+j  :
      print("UNRESTORABLE")
      exit()
    si = s[i+j]
    tj = t[j]

    if si == "?" or si == tj :

      counter+=1
      if counter == len(t) :
        s = s.replace(s[i:i+j+1],t)
        s = s.replace("?","a")
        print(s)
        exit()
      continue
    else :

      break

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
m = len(S)
n = len(T)

Sa = []

if m >= n:
    for i in range(m+1-n):
        for j in range(n):
            if S[i+j] != T[j] and S[i+j] != "?":
                break
        else:
            S = S[:i] + T + S[i+n:]
            Sa.append(S.replace("?", "a"))
            

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

Submission status: Wrong Answer

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

s_len =len(S)
t_len =len(T)

flg=False

if s_len >= t_len:
    for head in range(len(S)-t_len,0,-1):
        flg=True
        for s,t in zip(S[head:head+t_len],T):
            if not(s==t or "?"==s):
                flg=False
        if flg:
            break


if flg:
    S=list(S)
    S[head:head+t_len] = T
    S="".join(S)
    S=S.replace("?","a")
    print(S)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
def MAP(): return [int(s) for s in input().split()]

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

S = input().rstrip()
T = input().rstrip()

ans = [s for s in S]
end = len(S)

for x in range(len(T)-1, -1, -1):
	while S.rfind(T[x],0,end) != -1:
		for i in range(len(T)-1, -1, -1):
			if S.rfind(T[i],0,end) != -1 and S.rfind(T[i],0,end)+len(T)-i<=len(S):
				j = S.rfind(T[i],0,end)
				flag = True
				for k in range(len(T)):
					#print(S[j+k-i], T[k])
					if S[j+k-i] == T[k] or S[j+k-i] == '?':
						continue
					else:
						flag = False
						break
				else:
					if flag:
						for k in range(len(T)): ans[j+k-i] = T[k]
						print(''.join(ans).replace('?','a'))
						sys.exit()
		end -= 1

if S.rfind('?'*len(T)) != -1:
	j = S.rfind('?'*len(T))
	for i in range(len(T)):
		ans[i+j] = T[i]
	
	print(''.join(ans).replace('?','a'))
else:
	print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
def MAP(): return [int(s) for s in input().split()]

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

S = input().rstrip()
T = input().rstrip()

ans = [s for s in S]
end = len(S)

for x in range(len(T)-1, -1, -1):
	while S.rfind(T[x],0,end) != -1:
		for i in range(len(T)-1, -1, -1):
			if S.rfind(T[i],0,end) != -1 and S.rfind(T[i],0,end)+len(T)<=len(S):
				j = S.rfind(T[i],0,end)
				flag = True
				for k in range(len(T)):
					#print(S[j+k-i], T[k])
					if S[j+k-i] == T[k] or S[j+k-i] == '?':
						continue
					else:
						flag = False
						break
				else:
					if flag:
						for k in range(len(T)): ans[j+k-i] = T[k]
						print(''.join(ans).replace('?','a'))
						sys.exit()
		end -= 1

if S.rfind('?'*len(T)) != -1:
	j = S.rfind('?'*len(T))
	for i in range(len(T)):
		ans[i+j] = T[i]
	
	print(''.join(ans).replace('?','a'))
else:
	print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
def MAP(): return [int(s) for s in input().split()]

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

S = input().rstrip()
T = input().rstrip()

ans = [s for s in S]
for i in range(len(T)-1, -1, -1):
	if S.rfind(T[i]) != -1:
		j = S.rfind(T[i])
		for k in range(len(T)):
			#print(S[j+k-i], T[k])
			if S[j+k-i] == T[k] or S[j+k-i] == '?':
				ans[j+k-i] = T[k]
			else:
				break
		else:
			print(''.join(ans).replace('?','a'))
			sys.exit()

if S.rfind('?'*len(T)) != -1:
	j = S.rfind('?'*len(T))
	for i in range(len(T)):
		ans[i+j] = T[i]
	
	print(''.join(ans).replace('?','a'))
else:
	print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
def MAP(): return [int(s) for s in input().split()]

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

S = input().rstrip()
T = input().rstrip()

ans = [s for s in S]
for i in range(len(T)):
	if S.find(T[i]) != -1:
		j = S.find(T[i])
		for k in range(len(T)):
			#print(S[j+k-i], T[k])
			if S[j+k-i] == T[k] or S[j+k-i] == '?':
				ans[j+k-i] = T[k]
			else:
				break
		else:
			print(''.join(ans).replace('?','a'))
			sys.exit()

if S.rfind('?'*len(T)) != -1:
	j = S.rfind('?'*len(T))
	for i in range(len(T)):
		ans[i+j] = T[i]
	
	print(''.join(ans).replace('?','a'))
else:
	print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
sys.setrecursionlimit(10**6)
def MAP(): return [int(s) for s in input().split()]

if sys.platform =='ios':
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline

S = input().rstrip()
T = input().rstrip()

for i in range(len(T)):
	if S.find(T[i]) != -1:
		j = S.find(T[i])
		ans = [s for s in S]
		for k in range(len(T)):
			#print(S[j+k-i], T[k])
			if S[j+k-i] == T[k] or S[j+k-i] == '?':
				ans[j+k-i] = T[k]
			else:
				break
		else:
			print(''.join(ans).replace('?','a'))
			sys.exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

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

tmp_i=0
tmp_j=0
if len(s)<len(t):
    ans='UNRESTORABLE'
else:
    for i in range(len(s)-len(t)+1):
        cnt=0
        for j in range(len(t)):
            if s[i+j]==t[j] or s[i+j]=='?':
                cnt+=1
            if cnt==len(t):
                tmp_i=i
                tmp_j=j
    if tmp_i!=0 or tmp_j!=0:
        ans_s=s[:tmp_i]+t+s[tmp_i+len(t):]
        ans=(ans_s).replace('?','a')
    else:
        ans='UNRESTORABLE'
print(ans)

Submission status: Wrong Answer

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

tmp_i=0
tmp_j=0
ans='UNRESTORABLE'
if len(s)<len(t):
    print(ans)
    exit()
else:
    for i in range(len(s)-len(t)+1):
        cnt=0
        for j in range(len(t)):
            if s[i+j]==t[j] or s[i+j]=='?':
                cnt+=1
            if cnt==len(t):
                tmp_i=i
                tmp_j=j
    if tmp_i!=0 and tmp_j!=0:
        ans_s=s[:tmp_i]+t+s[tmp_i+len(t):]
        ans=(ans_s).replace('?','a')
print(ans)

Submission status: Wrong Answer

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

tmp_i=0
tmp_j=0
if len(s)<len(t):
    ans='UNRESTORABLE'
else:
    for i in range(len(s)-len(t)+1):
        cnt=0
        for j in range(len(t)):
            if s[i+j]==t[j] or s[i+j]=='?':
                cnt+=1
            if cnt==len(t):
                tmp_i=i
                tmp_j=j
    if tmp_i!=0:
        ans_s=s[:tmp_i]+t+s[tmp_i+len(t):]
        ans=(ans_s).replace('?','a')
    else:
        ans='UNRESTORABLE'
print(ans)

Submission status: Wrong Answer

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

tmp_i=0
tmp_j=0
ans='UNRESTORABLE'
if len(s)<len(t):
    ans='UNRESTORABLE'
else:
    for i in range(len(s)-len(t)+1):
        cnt=0
        for j in range(len(t)):
            if s[i+j]==t[j] or s[i+j]=='?':
                cnt+=1
            tmp_i=i
            tmp_j=j
    if tmp_i!=0:
        ans_s=s[:tmp_i]+t+s[tmp_i+len(t):]
        ans=(ans_s).replace('?','a')
print(ans)

Submission status: Wrong Answer

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

ans='UNRESTORABLE'
cnt=0
if len(s)<len(t):
    ans='UNRESTORABLE'
else:
    for i in range(len(s)-len(t)+1):
        cnt=0
        for j in range(len(t)):
            if s[i+j]==t[j] or s[i+j]=='?':
                cnt+=1
        if cnt==len(t):
            ans_s=s[:i]+t+s[i+len(t):]
            ans=(ans_s).replace('?','a')
            break
print(ans)

Submission status: Wrong Answer

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

    SR = S[::-1]
    TR = T[::-1]

    s_len = len(S)
    i = 0
    last_i = None
    ans = False
    for ind, si in enumerate(SR):
        if si == '?':
            i += 1
        elif si == TR[i]:
            i += 1
        else:
            i = 0
        # print(si, i)
        if i == len(T):
            ans = True
            last_i = i
            break

    if ans:
        # print(ans)
        # print(ind)
        r = S[:len(S)-last_i] + T
        # print(r)
        r = r.replace('?', 'a')
        print(r)
    else:
        print('UNRESTORABLE')




if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = list(str(input()))
rs = "".join(s)
lenS = len(s)
t = list(str(input()))
lenT = len(t)
if lenT > lenS:
    ans = "UNRESTORABLE"
    print(ans)
    exit()
for i in range(lenS,lenS-lenT,-1):
    tmps = s[i-lenT:i+1]
    #print(tmps)
    Flag = True
    for j in range(lenT):
        #print(j)
        if tmps[j] == "?" or tmps[j] == t[j]:
            continue
        else:
            Flag = False
            break
    if Flag:
        for j in range(lenT):
            s[i-lenT+j] = t[j]
        break
if "".join(s) == rs:
    ans = "UNRESTORABLE"
else:
    ans = "".join(s).replace('?', 'a')
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(str(input()))
rs = "".join(s)
lenS = len(s)
t = list(str(input()))
lenT = len(t)
if lenT > lenS:
    ans = "UNRESTORABLE"
    print(ans)
    exit()
for i in range(lenS - lenT + 1):
    tmps = s[i:i+lenT]
    Flag = True
    for j in range(lenT):
        if tmps[j] == "?" or tmps[j] == t[j]:
            continue
        else:
            Flag = False
            break
    if Flag:
        for j in range(lenT):
            s[i+j] = t[j]
        break
if "".join(s) == rs:
    ans = "UNRESTORABLE"
else:
    ans = "".join(s).replace('?', 'a')
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(str(input()))
rs = "".join(s)
lenS = len(s)
t = list(str(input()))
lenT = len(t)
if lenT > lenS:
    ans = "UNRESTORABLE"
    print(ans)
    exit()
for i in range(lenS - lenT + 1):
    tmps = s[i:i+lenT]
    Flag = True
    for j in range(lenT):
        if tmps[j] == "?" or tmps[j] == t[j]:
            continue
        else:
            Flag = False
            break
    if Flag:
        for j in range(lenT):
            s[i+j] = t[j]
if "".join(s) == rs:
    ans = "UNRESTORABLE"
else:
    ans = "".join(s).replace('?', 'a')
print(ans)

Submission status: Wrong Answer

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

for i in range(len(S)-len(T)+1):
    if S[i] == '?' or S[i] == T[0]:
        for j in range(1, len(T)):
            if S[i+j] == '?' or S[i+j] == T[j]:
                pass
            else:
                break
            if j == len(T)-1:
                ans.append(i)

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

can = []
for idx in ans:
    c = ''
    for i in range(idx):
        if S[i] == '?':
            c += 'a'
        else:
            c += S[i]
    c += T
    for i in range(idx+len(T),len(S)):
        if S[i] == '?':
            c += 'a'
        else:
            c += S[i]
    can.append(c)
d = can[0]
for e in can:
    if d > e:
        d = e
print(d)

Submission status: Wrong Answer

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

for i in range(len(S)-len(T)+1):
    if S[i] == '?' or S[i] == T[0]:
        for j in range(1, len(T)):
            if S[i+j] == '?' or S[i+j] == T[j]:
                pass
            else:
                break
            if j == len(T)-1:
                ans.append(i)

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

can = []
for idx in ans:
    c = ''
    for i in range(idx):
        if S[i] == '?':
            c += 'a'
        else:
            c += S[i]
    c += T
    for i in range(idx+len(T),len(S)):
        if S[i] == '?':
            c += 'a'
        else:
            c += S[i]
    can.append(c)
sorted(can)
print(can[0])

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
idx = -1

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

if idx == -1:
    print('UNRESTORABLE')
    exit()

for i in range(idx):
    if S[i] == '?':
        print('a', end='')
    else:
        print(S[i], end='')
print(T)
for i in range(idx+len(T),-1):
    if S[i] == '?':
        print('a', end='')
    else:
        print(S[i], end='')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
idx = -1

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

if idx == -1:
    print('UNRESTORABLE')
    exit()

for i in range(idx):
    if S[i] == '?':
        print('a', end='')
    else:
        print(S[i], end='')
print(T)
for i in range(idx+len(T),-1):
    print(S[i], end='')

Submission status: Wrong Answer

Solution code:
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    s = str(readline().rstrip().decode('utf-8'))
    t = str(readline().rstrip().decode('utf-8'))
    k = len(t)
    for i in range(len(s) - k, -1, -1):
        ts = s[i:i+k]
        b = True
        for j in range(k):
            if ts[j] != "?" and ts[j] != t[j]:
                b = False
                break
        if b:
            a = []
            for j in range(i):
                if s[j] == "?":
                    a.append("a")
                else:
                    a.append(s[j])
            print("".join(a + list(t)))
            exit()
    print("UNRESTORABLE")


if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
S_dash = list(map(str, input()))
T = list(map(str, input()))


for i in reversed(range(len(S_dash) - len(T) + 1)):
	flg = 1
	for j in range(len(T)):
		if S_dash[i + j] != "?" and S_dash[i + j] != T[j]:
			flg = 0
			break
	# if flg:
		# for j in range(len(T)):
			# S_dash[i + j] = T[j]
		# break
		
# if flg:
	# for i in range(len(S_dash)):
		# if S_dash[i] == "?":
			# print("a", end = "")
		# else:
			# print(S_dash[i], end = "")
# else:
	# print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S_dash = list(map(str, input()))
T = list(map(str, input()))


for i in reversed(range(len(S_dash) - len(T) + 1)):
	pass
	# flg = 1
	# for j in range(len(T)):
		# if S_dash[i + j] != "?" and S_dash[i + j] != T[j]:
			# flg = 0
			# break
	# if flg:
		# for j in range(len(T)):
			# S_dash[i + j] = T[j]
		# break
		
# if flg:
	# for i in range(len(S_dash)):
		# if S_dash[i] == "?":
			# print("a", end = "")
		# else:
			# print(S_dash[i], end = "")
# else:
	# print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import copy

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

ans = 'UNRESTORABLE'
len_s = len(S)
len_t = len(T)

is_matched = False

for i in range(len_s - len_t):
    s = copy.deepcopy(S)
    for j in range(len_t):
        sc = s[(-1) - i - j]
        tc = T[(-1) - j]
        if sc == tc or sc == '?':
            s[(-1) - i - j] = tc
            if len_t == (j + 1):
                is_matched = True
        else:
            break
    if  is_matched:
        ans = ''.join(s).replace('?', 'a')
        break
print(ans)