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

Ns = len(S)
Nt = len(T)
flag = False
for i in range(Ns - Nt+1):
    for j in range(Nt):
        if not(S[i+j] == T[j] or S[i+j] == '?'):
            break
    else:
        flag = True
        break

if flag:
    
    ans = S
    for j in range(Nt):
        ans[i+j] = T[j]

    for k in range(Ns):
        if ans[k] == '?':
            ans[k] = 'a'
    ans = ''.join(ans)
else:
    ans = 'UNRESTORABLE'
    
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
ss=input()[::-1]
t=input()[::-1]

# ssの出来るだけ後ろに t を入れ、それ以外は "a" を入れる.
match_len=0

for i in range(len(ss)-len(t)):
    for j in range(len(t)):
        if ss[i+j]=="?" or ss[i+j]==t[j]:
            match_len+=1
        else:
            match_len=0
            break
            
        if match_len==len(t):
            ss=ss[:i]+t+ss[i+len(t):]
            ss=ss.replace("?","a")
            print(ss[::-1])
            exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
ss=input()[::-1]
t=input()[::-1]

# ssの出来るだけ後ろに t を入れ、それ以外は "a" を入れる.
match_len=0

for i in range(len(ss)-len(t)):
    for j in range(len(t)):
        if ss[i+j]=="?" or ss[i+j]==t[j]:
            match_len+=1
        else:
            match_len=0
            break
            
        if match_len==len(t):
            ss=ss[:i]+t+ss[i+len(t):]
            ss=ss.replace("?","a")
            print(ss[::-1])
            exit()
print("UNRESORABLE")

Submission status: Wrong Answer

Solution code:
ss=input()[::-1]
t=input()[::-1]

# ssの出来るだけ後ろに t を入れ、それ以外は "a" を入れる.
match_len=0

for i in range(len(ss)-len(t)):
    for j in range(len(t)):
        if ss[i+j]=="?" or ss[i+j]==t[j]:
            match_len+=1
            print("match")
        else:
            match_len=0
            break
            
        if match_len==len(t):
            ss=ss[:i]+t+ss[i+len(t):]
            ss=ss.replace("?","a")
            print(ss[::-1])
            exit()
print("UNRESORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
s = len(S)
t = len(T)
l = []
ans = []

if s < t:
    print('UNRESTORABLE')
    exit()

for i in range(s - t + 1):
    for j in range(t):
        if T[j] == S[i + j] or S[i + j] == '?':
            if j == t - 1:
                l.append(i)
            continue
        else:
            break

if l:
    for i in l:
        if i != 0 and i != s - 1:
            ans.append((S[:i] + T + S[i + t + 1:]).replace('?', 'a'))
        elif i == 0:
            ans.append((T + S[t:]).replace('?', 'a'))
        else:
            ans.append((S[:i] + T).replace('?', 'a'))
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
s = len(S)
t = len(T)
l = []
ans = []

if s < t:
    print('UNRESTORABLE')
    exit()

for i in range(s - t + 1):
    for j in range(t):
        if T[j] == S[i + j] or S[i + j] == '?':
            if j == t - 1:
                l.append(i)
            continue
        else:
            break

if l:
    for i in l:
        if i != 0 and i != s - 1:
            ans.append((S[:i] + T + S[i + t + 1:]).replace('?', 'a'))
        elif i == 0:
            ans.append((T + S[i + t + 1:]).replace('?', 'a'))
        else:
            ans.append((S[:i] + T).replace('?', 'a'))
    ans.sort()
    print(ans[0])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

switch=0
for i in range(-len(t),-len(s),-1):
    ss=s[i:]
    cnt=0
    for j in range(len(t)):
        if ss[j]==t[j] or ss[j]=='?':
            cnt+=1
    if cnt==len(t):
        switch=1
        s=s[:i]+t+ss[len(t):]
        break
for k in range(len(s)):
    if s[k]=='?':
        s[k]='a'
if switch==1:
    print(''.join(s))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

switch=0
for i in range(-len(t),-len(s),-1):
    ss=s[i:]
    cnt=0
    for j in range(len(t)):
        if ss[j]==t[j] or ss[j]=='?':
            cnt+=1
    if cnt==len(t):
        switch=1
        s=s[:i]+t
        break
for k in range(len(s)):
    if s[k]=='?':
        s[k]='a'
if switch==1:
    print(''.join(s))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
# ABC076c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

ss = list(input())[:-1]
t = list(input())[:-1]

pos = len(ss)-len(t)
while (pos > 0):
    #print(ss[pos:pos+len(t)], t, pos)
    for i in range(len(t)):
        if (ss[pos + i] != '?' and ss[pos + i] != t[i]):
            pos -= 1
            break
        if (i == len(t) - 1):
            for j in range(len(t)):
                ss[pos+j] = t[j]
            pos = -1
if (pos != -1):
    print('UNRESTORABLE')
    exit()
# print('hi')
# print(ss)

for i in range(len(ss)):
    if (ss[i] == '?'):
        ss[i] = 'a'
print(*ss, sep='')

Submission status: Wrong Answer

Solution code:
# ABC076c
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

ss = list(input())[:-1]
t = list(input())[:-1]

pos = 0
while (pos + len(t) <= len(ss)):
    #print(ss[pos:pos+len(t)], t, pos)
    for i in range(len(t)):
        if (ss[pos + i] != '?' and ss[pos + i] != t[i]):
            pos += 1
            break
        if (i == len(t) - 1):
            for j in range(len(t)):
                ss[pos+j] = t[j]
            pos = 9999
if (pos != 9999):
    print('UNRESTORABLE')
    exit()
# print('hi')
# print(ss)

for i in range(len(ss)):
    if (ss[i] == '?'):
        ss[i] = 'a'
print(*ss, sep='')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
if len(s)<len(t):
	print("UNRESTORABLE")
	exit()
d=[]
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):
		p=""
		for j in range(i):
			if s[j]=="?":
				p+="a"
			else:
				p+=s[j]
		for j in range(i,len(t)+i):
			p+=t[j-i]
		for j in range(len(t)+i,len(s)):
			if s[i]=="?":
				p+="a"
			else:
				p+=s[i]
		d.append(p)
if len(d)==0:
	print("UNRESTORABLE")
else:
	print(min(d))

Submission status: Wrong Answer

Solution code:
def get_t_strs(T):
  lenT = len(T)
  strs = []
  for i in range(0,lenT):
    strs.extend([T[:i] + '?'*(lenT-i), '?'*(i) + T[-i:]])
  return strs

S,T = input(), input()
if S.count('?') == 0:
  print(S)
  exit()

idx_options = []
t_strs = get_t_strs(T)
for t_str in t_strs:
  idx = S.rfind(t_str)
  if idx != -1: idx_options.append(idx+1)

if len(idx_options) == 0: print('UNRESTORABLE')
else:
  max_idx = max(idx_options)
  print((S[:max_idx-1] + T + S[max_idx+len(T)-1:]).replace('?','a'))

Submission status: Wrong Answer

Solution code:
def get_t_strs(T):
  lenT = len(T)
  strs = ['?'*lenT]
  for i in range(1,lenT):
    strs.extend([T[:i] + '?'*(lenT-i), '?'*(lenT-i) + T[-i:]])
  return strs

S,T = input(), input()
if S.count('?') == 0:
  print(S)
  exit()

idx_options = []
t_strs = get_t_strs(T)
for t_str in t_strs:
  idx = S.rfind(t_str)
  if idx != -1: idx_options.append(idx+1)

if len(idx_options) == 0: print('UNRESTORABLE')
else:
  max_idx = max(idx_options)
  print((S[:max_idx-1] + T + S[max_idx+len(T)-1:]).replace('?','a'))

Submission status: Wrong Answer

Solution code:
def get_t_strs(T):
  strs = []
  lenT = len(T)
  for i in range(1,lenT):
    strs.extend([T[:i] + '?'*(lenT-i), '?'*(lenT-i) + T[-i:]])
  return strs

S,T = input(), input()
idx_options = []
idx = S.rfind('?'*len(T))
if idx != -1: idx_options.append(idx+1)

t_strs = get_t_strs(T)
for t_str in t_strs:
  idx = S.rfind(t_str)
  if idx != -1: idx_options.append(idx+1)

if len(idx_options) == 0: print('UNRESTORABLE')
else:
  max_idx = max(idx_options)
  print((S[:max_idx-1] + T + S[max_idx+len(T)-1:]).replace('?','a'))

Submission status: Wrong Answer

Solution code:
def get_t_strs(T):
  strs = []
  lenT = len(T)
  for i in range(1,lenT):
    strs.extend([T[:i] + '?'*(lenT-i), '?'*(lenT-i) + T[-i:]])
  return strs

S,T = input(), input()
idx_options = []
idx = S.rfind('?'*len(T))
if idx != -1: idx_options.append(idx+1)

t_strs = get_t_strs(T)
for t_str in t_strs:
  idx = S.rfind(t_str)
  if idx != -1: idx_options.append(idx+1)

if len(idx_options) == 0: print('UNRESTORABLE')
else:
  max_idx = max(idx_options)
  print((S[:max_idx-1] + T + S[max_idx+len(T):]).replace('?','a'))

Submission status: Wrong Answer

Solution code:
from itertools import groupby

def get_max_len_q(S):
  max_len_q = -1
  for key, gp in groupby(S):
    if key == '?': max_len_q = max(max_len_q, len(list(gp)))
  return max_len_q

def get_t_strs(T):
  strs = []
  lenT = len(T)
  for i in range(1,lenT):
    strs.extend([T[:i] + '?'*(lenT-i), '?'*(lenT-i) + T[-i:]])
  return strs

def print_ans(S,T,idx,max_len_q):
  print((S[:idx-1] + T + S[idx+max_len_q:]).replace('?','a'))
  exit()

S,T = input(), input()
max_len_q = get_max_len_q(S)

if max_len_q >= len(T):
  idx = S.rfind('?'*max_len_q)
  print_ans(S,T,idx,max_len_q)
else:
  t_strs = get_t_strs(T)
  for t_str in t_strs:
    idx = S.rfind(t_str)
    if idx != -1: print_ans(S,T,idx+1,t_str.count('?'))
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
from itertools import groupby

def get_max_len_q(S):
  max_len_q = -1
  for key, gp in groupby(S):
    if key == '?': max_len_q = max(max_len_q, len(list(gp)))
  return max_len_q

def get_t_strs(T):
  strs = []
  lenT = len(T)
  for i in range(1,lenT):
    strs.extend([T[:i] + '?'*(lenT-i), '?'*(lenT-i) + T[-i:]])
  return strs

def print_ans(S,T,idx,max_len_q):
  print((S[:idx-1] + T + S[idx+max_len_q:]).replace('?','a'))
  exit()

S,T = input(), input()
max_len_q = get_max_len_q(S)

if max_len_q >= len(T):
  idx = S.rfind('?'*max_len_q)
  print_ans(S,T,idx,max_len_q)
else:
  t_strs = get_t_strs(T)
  for t_str in t_strs:
    idx = S.find(t_str)
    if idx != -1: print_ans(S,T,idx+1,t_str.count('?'))
  print('UNRESTORABLE')

Submission status: Wrong Answer

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

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

l = len(t)

ans = []

for i in range(len(s)-l+1):
    temp = s[i:i+l]
    flag = True
    for j in range(l):
        if not (t[j] == temp[j] or temp[j] == "?"):
            flag = False
            
    if flag:
        s = s[:i] + t + s[i+l:]

        x = []
        for k in s:
            if k == "?":
                x.append("a")
            else:
                x.append(k)

        ans.append("".join(x))

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


print(sorted(ans)[0])

Submission status: Wrong Answer

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


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

    A = []
    for i in range(len(S)-len(T)+1):
        flg = True
        for j in range(len(T)):
            if S[i+j:i+j+1] not in [T[j:j+1], '?']:
                flg = False
        
        if flg:
            K = S[:i] + T + S[i+len(T):]
            A.append(K.replace('?', 'a'))
    
    if len(A)==0 or len(S)<len(T):
        print('UNRESTORABLE')
        return
    print(min(A))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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

    if T in S:
        print(S.replace('?', 'a'))
        return

    unrestorable = True
    for i in reversed(range(len(S)-len(T)+1)):
        flg = True
        for j in range(len(T)):
            if S[i+j:i+j+1] not in [T[j:j+1], '?']:
                flg = False
        
        if flg:
            S = S[:i] + T + S[i+len(T):]
            unrestorable = False
            break
    
    if unrestorable:
        print('UNRESTORABLE')
        return
    print(S.replace('?', 'a'))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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

    if T in S:
        print(S.replace('?', 'a'))

    unrestorable = True
    for i in reversed(range(len(S)-len(T)+1)):
        flg = True
        for j in range(len(T)):
            if S[i+j:i+j+1] not in [T[j:j+1], '?']:
                flg = False
        
        if flg:
            S = S[:i] + T + S[i+len(T):]
            unrestorable = False
            break
    
    if unrestorable:
        print('UNRESTORABLE')
        return
    print(S.replace('?', 'a'))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


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

    unrestorable = True
    for i in reversed(range(len(S)-len(T)+1)):
        flg = True
        for j in range(len(T)):
            if S[i+j:i+j+1] not in [T[j:j+1], '?']:
                flg = False
        
        if flg:
            S = S[:i] + T + S[i+len(T):]
            unrestorable = False
            break
    
    if unrestorable:
        print('UNRESTORABLE')
        return

    S = S.replace('?', 'a')
    print(S)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

l = len(t)

ans = []

for i in range(len(s)-l+1):
    temp = s[i:i+l]
    flag = True
    for j in range(l):
        if not (t[j] == temp[j] or temp[j] == "?"):
            flag = False
            
    if flag:
        s = s[:i] + t + s[i+l:]

        x = []
        for k in s:
            if k == "?":
                x.append("a")
            else:
                x.append(k)

        ans.append("".join(x))

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


print(sorted(ans)[0])

Submission status: Wrong Answer

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

if len(S)>=len(T):
    emptylists=[]
    flag=True
    for x in range(len(S)+1-len(T)):
        judgement=1 if all(  S[-(x+j)]=="?" or S[-(x+j)]==T[-j] for j in range(1,len(T)+1)) else 0
        if judgement==1:
            flag=False
            if x==0:
                words=str(S[:-len(T)]+T)
                changed=words.replace("?","a")
                print(changed)
                emptylists.append(changed)
                
                
            else:
                words=S[:-len(T)-x]+T+S[-x:]
                changed=words.replace("?","a")
                emptylists.append(changed)
        else:
            continue
        ans=sorted(emptylists)

    if flag:
        print("UNRESTORABLE")
    else:
        print(ans[0])
        
if len(S)<len(T):
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S=str(input())
T=str(input())
if len(S)>=len(T):
    emptylists=[]
    flag=True
    for x in range(len(S)+1-len(T)):
        judgement=1 if all(  S[-(x+j)]=="?" or S[-(x+j)]==T[-j] for j in range(1,len(T)+1)) else 0
        if judgement==1:
            flag=False
            if x==0:
                words=str(S[:-len(T)]+T)
                changed=words.replace("?","a")
                emptylists.append(changed)
            else:
                words=S[:-len(T)]+T+S[-x:]
                changed=words.replace("?","a")
                emptylists.append(changed)
        else:
            continue
        ans=sorted(emptylists)

    if flag:
        print("UNRESTORABLE")
    else:
        print(ans[0])
if len(S)<len(T):
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S=str(input())
T=str(input())
emptylists=[]
flag=True
for x in range(len(S)+1-len(T)):
    judgement=1 if all(  S[-(x+j)]=="?" or S[-(x+j)]==T[-j] for j in range(1,len(T)+1)) else 0
    if judgement==1:
        flag=False
        if x==0:
            words=str(S[:-len(T)]+T)
            changed=words.replace("?","a")
            emptylists.append(changed)
        else:
            words=S[:-len(T)]+T+S[-x:]
            changed=words.replace("?","a")
            emptylists.append(changed)
    else:
        continue
    ans=sorted(emptylists)

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

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    s = list(str(input().rstrip('\n')))
    t = str(input().rstrip('\n'))
    for i in range(len(s) - len(t), -1, -1):
        ts = s[i:i + len(t)]
        b = True
        for j in range(len(t)):
            if ts[j] != "?" and ts[j] != t[j]:
                b = False
                break
        if b:
            for j in range(len(t)):
                s[i + j] = t[j]
            for j in range(len(s)):
                if s[j] == "?":
                    s[j] = "a"
            print("".join(s))
            exit()
        else:
            if s[i] == "?":
                s[i] = "a"
    print("UNRESTORABLE")


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

Solution code:
def slove():
    import sys
    input = sys.stdin.readline
    s = list(str(input().rstrip('\n')))
    t = str(input().rstrip('\n'))
    for i in range(len(s) - len(t) + 1):
        ts = s[i:i + len(t)]
        b = True
        for j in range(len(t)):
            if ts[j] != "?" and ts[j] != t[j]:
                b = False
                break
        if b:
            for j in range(len(t)):
                s[i + j] = t[j]
            print("".join(s))
            exit()
        else:
            if s[i] == "?":
                s[i] = "a"
    print("UNRESTORABLE")


if __name__ == '__main__':
    slove()

Submission status: Wrong Answer

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

t = float('inf')
for i in range(len(S2)-len(T), -1, -1):
    flag = True
    for j in range(len(T)):
        if S2[i+j] == '?':
            continue
        if S2[i+j] != T[j]:
            flag = False
            break
    if flag:
        t = i
if t == float('inf'):
    print('UNRESTORABLE')
    exit()
else:
    S2 = S2.replace('?', 'a')
    answer = S2[:t] + T + S2[t+len(T):]
    print(answer)

Submission status: Wrong Answer

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

t = float('inf')
for i in range(len(S2)-len(T), -1, -1):
    flag = True
    for j in range(len(T)):
        if S2[i+j] != T[j] and S2[i+j] != '?':
            
            flag = False
            break
    if flag:
        t = i
if t == float('inf'):
    print('UNRESTORABLE')
    exit()
else:
    S2 = S2.replace('?', 'a')
    answer = S2[:t] + T + S2[t+len(T):]
    print(answer)

Submission status: Wrong Answer

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

d_len = len(D)
t_len = len(T)

flag = 0
p = -1

#後ろの?から入れられるかを試す
#入れられた最短の後ろに入れる
#それ以外の文字は?とする
#入れられる場所がなければUNRESTORABLEを表示

for i in range(d_len - t_len, -1, -1):
    if D[i] == '?' or D[i] == T[0]:
        #部分列Tが入るかどうかを検討

        for j in range(1,t_len):
            if D[i+j] == '?' or D[i+j] == T[j]:
                if j == t_len - 1:
                    flag = 1
                    p = i
            else:
                break             
    
if flag == 1:
    #他の?を全て置換して表示
    c = 0

    while True:
        if c == p:
            print("".join(T),end="")
            c += t_len
        elif c >= d_len:
            break
        elif D[c] == '?':
            print("a",end="")
            c += 1
        else:
            print(D[c],end="")
            c += 1
    
    print()

else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

l = []

for i in range(len(s) - len(t) + 1):
    for j in range(len(t)):
        if s[i+j] != t[j] and s[i+j] != "?":
            break
    else: l.append(s[:i] + t + s[i+len(t):])
        
ans, mc = "", 0

for li in l:
    cnt = 0
    for lj in li:
        if lj != "?" and lj != "a": break
        cnt += 1
    if cnt > mc:
        ans = li
        mc = cnt

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

Submission status: Wrong Answer

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

for i in range(-1,len(T)-len(S)-1,-1):
  f=1
  for j in range(-1,-1*len(T)-1,-1):
    if S[i+j+1]==T[j] or S[i+j+1]=="?":pass
    else:f=0
  if f==1:
    S=list(S)
    for j in range(-1,-1*len(T)-1,-1):
      S[i+j+1]=T[j]
    for k in range(len(S)):
      if S[k]=="?":S[k]="a"
    print("".join(S))
    exit(0)
print("UNRESTORABLE")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
A=input()
a=list(A)
tmp=list(A)
t=list(input())
flg,i,j=0,0,0
while i<len(a) and j<len(t):
  if a[i]==t[j] or a[i]=='?':
    a[i]=t[j]
    if j==len(t)-1:
      flg=1
      break
    i+=1
    j+=1
  else:
    i+=1
    j=0
    a=tmp
if flg==1:
  ans=''
  for i in a:
    ans+=i
  print(ans.replace('?','a'))
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
from pprint import pprint

s = sys.stdin.readline().strip()
t = sys.stdin.readline().strip()

len_s = len(s)
len_t = len(t)
# print(len_s, len_t)

for i in range(0, len_s - len_t + 1):
    a = list(s)
    flag = True
    for j in range(len_t):
        # print(s[i+j], t[j])
        if s[i+j] == "?":
            a[i+j] = t[j]
        elif s[i+j] != t[j]:
            flag = False
            break
    if flag:
        print("".join(a).replace("?", "a"))
        sys.exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys
from pprint import pprint

s = sys.stdin.readline().strip()
t = sys.stdin.readline().strip()

len_s = len(s)
len_t = len(t)
# print(len_s, len_t)

for i in range(0, len_s - len_t + 1):
    a = list(s)
    flag = True
    for j in range(len_t):
        # print(s[i+j], t[j])
        if s[i+j] == "?":
            a[i+j] = t[j]
        elif s[i+j] == t[j]:
            continue
        else:
            flag = False
            break
    if flag:
        print("".join(a).replace("?", "a"))
        sys.exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys
from pprint import pprint

s = sys.stdin.readline().strip()
t = sys.stdin.readline().strip()

len_s = len(s)
len_t = len(t)
# print(len_s, len_t)

for i in range(0, len_s - len_t + 1):
    flag = True
    for j in range(len_t):
        if flag == False:
            continue
        # print(s[i+j], t[j])
        if s[i+j] == "?" or s[i+j] == t[j]:
            continue
        flag = False
        break
    if flag:
        ans = ""
        for s_i in s[0:i]:
            if s_i == "?":
                ans += "a"
            else:
                ans += s_i
        print(ans + t)
        sys.exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i in range(len(S)-len(T),-1,-1):
  flag = True
  for j in range(len(T)):
    if S[i+j] != '?' and S[i+j] != T[j]:
      flag = False
  if flag:
    print(S[i:i+len(T)])
    S = S[:i]+T+S[i+len(T):]
    S = S.replace('?','a')
    print(S)
    exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

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

for i in range(len(S)-len(T)+1):
  flag = True
  for j in range(len(T)):
    if S[i+j] != '?' and S[i+j] != T[j]:
      flag = False
  if flag:
    S = S.replace(S[i:i+len(T)],T).replace('?','a')
    print(S)
    exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

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

for i in range(len(S)-len(T)+1):
  flag = True
  for j in range(len(T)):
    if S[i+j] != '?' and S[i+j] != T[j]:
      flag = False
  if flag:
    S = S.replace(S[i:i+len(T)],T).replace('?','a')
    print(S)
    exit()

if '?' in S:
  print('UNRESTORABLE')

Submission status: Wrong Answer

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

    if T in S:
        if "?" in S:
            print(S.replace("?", "a"))
            exit()
        else:
            print(S)
            exit()

    top = -1
    for head in range(len(S) - len(T)+1):
        for i in range(len(T)):
            if T[i] == S[head + i] or S[head + i] == "?":
                continue
            else:
                break
        else:
            top = head
            break
    if top == -1:
        print("UNRESTORABLE")
    else:
        password = S[:top] + T + S[top + len(T):]
        password = password.replace("?", "a")
        print(password)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    top = -1
    for head in range(len(S) - len(T)+1):
        for i in range(len(T)):
            if T[i] == S[head + i] or S[head + i] == "?":
                continue
            else:
                break
        else:
            top = head
            break
    if top == -1:
        print("UNRESTORABLE")
    else:
        password = S[:top] + T + S[top + len(T):]
        password = password.replace("?", "a")
        print(password)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    if len(T) > len(S):
        print("UNRESTORABLE")
        quit()

    top = -1
    for head in range(len(S) - len(T)+1):
        for i in range(len(T)):
            if T[i] == S[head + i] or S[head + i] == "?":
                continue
            else:
                break
        else:
            top = head
            break
    if top == -1:
        print("UNRESTORABLE")
    else:
        password = S[:head] + T + S[head + len(T):]
        password = password.replace("?", "a")
        print(password)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

    top = -1
    for head in range(len(S) - len(T)+1):
        for i in range(len(T)):
            if T[i] == S[head + i] or S[head + i] == "?":
                continue
            else:
                break
        else:
            top = head
            break
    if top == -1:
        print("UNRESTORABLE")
    else:
        password = S[:head] + T + S[head + len(T):]
        password = password.replace("?", "a")
        print(password)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

S = list(sys.stdin.readline().rstrip())
T = sys.stdin.readline().rstrip()
SL = len(S)
TL = len(T)

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

for i in range(0, SL - TL + 1):
    PSR = SR[i:TL + i:]
    equal = True
    for s, t in zip(PSR, TR):
        if s == t or s == '?':
            pass
        else:
            equal = False
            break
    if equal:
        for j, t in zip(range(i, TL + i), TR):
            SR[j] = t
        break

if SR == O_SR:
    print("UNRESTORABLE")
else:
    print(''.join(SR[::-1]).replace('?','a'))

Submission status: Wrong Answer

Solution code:
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

S = list(sys.stdin.readline().rstrip())
T = sys.stdin.readline().rstrip()
SL = len(S)
TL = len(T)

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

for i in range(0, SL - TL + 1):
    PSR = SR[i:TL + i:]
    equal = True
    for s, t in zip(PSR, TR):
        if s == t or s == '?':
            pass
        else:
            equal = False
            break
    if equal:
        for j, t in zip(range(i, TL + i), TR):
            SR[j] = t

if SR == O_SR:
    print("UNRESTORABLE")
else:
    print(''.join(SR[::-1]).replace('?','a'))