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 = input()
T = input()
res = ''
end = -1
for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        if S[i+j] == T[j]:
            end = i + j
            flag = 1
        elif S[i+j] == '?':
            end = i + j
            flag = 1
        else:
            flag = 0
            pass
            break
    if flag == 1:
        break
            
if end == -1:
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
res = ''
end = -1
for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        
        if S[i+j] == T[j]:
            end = i + j
            flag = 1
        elif S[i+j] == '?':
            end = i + j
            flag = 0
        else:
            flag = 0
            pass
            break
    if flag == 1:
        break
            
if end == -1:
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
res = ''
start = -1
for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        end = i + j
        if S[i+j] == T[j]:
            flag = 1
        elif S[i+j] == '?':
            flag = 0
        else:
            flag = -1
            break
    if flag == 1:
        break
            
if start == -1:
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
match = False
start = -1
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] == T[j] or S[i+j] == "?":
            match = True
    if match:
        start = i
    
    
if start == -1:
    print('UNRESTORABLE')
else:
    result = S[:start] + T + S[start+len(T):]
    print(result.replace("?", "a"))

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
tmp = ''
start = 0
result_list = []
for i, s in enumerate(S):
    if s == '?':
        start = i
        tmp += s
    elif s == T[len(tmp)]:
        start = i
        tmp += s
    else:
        tmp = ''
    if len(tmp) == len(T):
        # while start + 1 < len(S) and S[start + 1] == '?':
        #     start += 1
        start = start - len(T) -1 
        result = S[:start] + T + S[start + len(T):]
        result_list.append(result.replace('?', 'a'))
        tmp = ''
if len(result_list) == 0:
    print('UNRESTORABLE')
else:
    print(result_list[-1])

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
tmp = ''
start = 0
result_list = []
for i, s in enumerate(S):
    if s == '?':
        start = i
        tmp += s
    elif s == T[len(tmp)]:
        start = i
        tmp += s
    else:
        tmp = ''
    if len(tmp) == len(T):
        # while start + 1 < len(S) and S[start + 1] == '?':
        #     start += 1
        result = S[:start] + T + S[start + len(T):]
        result_list.append(result.replace('?', 'a'))
        tmp = ''
if len(result_list) == 0:
    print('UNRESTORABLE')
else:
    print(result_list[-1])

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
tmp = ''
start = 0
result_list = []
for i, s in enumerate(S):
    if s == '?':
        start = i
        tmp += s
    elif s == T[len(tmp)]:
        start = i
        tmp += s
    else:
        tmp = ''
    if len(tmp) == len(T):
        # while start + 1 < len(S) and S[start + 1] == '?':
        #     start += 1
        result = S[:start - len(T) + 1] + T + S[start + 1:]
        result_list.append(result.replace('?', 'a'))
        tmp = ''
if len(result_list) == 0:
    print('UNRESTORABLE')
else:
    print(result_list[-1])

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
tmp = ''
start = 0
result_list = []
for i, s in enumerate(S):
    if s == '?':
        start = i
        tmp += s
    elif s == T[len(tmp)]:
        start = i
        tmp += s
    else:
        tmp = ''
    if len(tmp) == len(T):
        while start + 1 < len(S) and S[start + 1] == '?':
            start += 1
        result = S[:start - len(T) + 1] + T + S[start + 1:]
        result_list.append(result.replace('?', 'a'))
        tmp = ''
if len(result_list) == 0:
    print('UNRESTORABLE')
else:
    print(result_list[-1])

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
result = ""
tmp = ''
start = 0
result_list = []
for i, s in enumerate(S):
    if s == '?':
        start = i
        tmp += s
        result += s
    elif s == T[len(tmp)]:
        start = i
        tmp += s
    else:
        tmp = ''
        result += s
    if len(tmp) == len(T):
        while start + 1 < len(S) and S[start + 1] == '?':
            start += 1
        result = S[:start - len(T) + 1] + T + S[start + 1:]
        result_list.append(result.replace('?', 'a'))
        result = ""
        tmp = ''
if len(result_list) == 0:
    print('UNRESTORABLE')
else:
    print(result_list[-1])

Submission status: Wrong Answer

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

t_length = len(T)

tmp = ''
result = ''
start = 0
result_list = []
for i, s in enumerate(S):
    if s == '?':
        start =i
        tmp += s
        result += s
    elif s == T[len(tmp)]:
        start = i
        tmp += s
    else:
        tmp = ''
        result += s
    if len(tmp) == len(T):
        while start+1 < len(S) and S[start+1] == '?':
            start += 1
        result = S[:start-len(T)+1] + T + S[start+1:]
        result_list.append(result.replace('?', 'a'))
        tmp = ''
if len(result_list) == 0:
    print('UNRESTORABLE')
else:
    print(result_list[-1])

Submission status: Wrong Answer

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

t_length = len(T)

tmp = ''
result = ''
start = 0
result_list = []
for i, s in enumerate(S):
    if s == '?':
        start =i
        tmp += s
        result += s
    elif s == T[len(tmp)]:
        start = i
        tmp += s
    else:
        tmp = ''
        result += s
    if len(tmp) == len(T):
        result = S[:start-len(T)+1] + T + S[start+1:]
        result_list.append(result.replace('?', 'a'))
        tmp = ''
if len(result_list) == 0:
    print('UNRESTORABLE')
else:
    print(result_list[-1])

Submission status: Wrong Answer

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

t_length = len(T)

tmp = ''
result = ''
start = 0
for i, s in enumerate(S):
    if s == '?':
        start =i
        tmp += s
        result += s
    elif s == T[len(tmp)]:
        start = i
        tmp += s
    else:
        tmp = ''
        result += s
    if len(tmp) == len(T):
        result = S[:start-len(T)+1] + T + S[start+1:]
        print(result.replace('?', 'a'))
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

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

t_length = len(T)

tmp = ''
result = ''
start = 0
for i, s in enumerate(S):
    if s == '?':
        start =i
        tmp += s
        result += s
    elif s == T[len(tmp)]:
        start = i
        tmp += s
    else:
        tmp = ''
        result += s
    if len(tmp) == len(T):
        result = S[:start-len(T)+1] + T + S[len(S[:start-len(T)+1])-1+start+len(T):]
        print(result.replace('?', 'a'))
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

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

t_length = len(T)

tmp = ''
result = ''
start = 0
for i, s in enumerate(S):
    if s == '?':
        start =i
        tmp += s
        result += s
    elif s == T[len(tmp)]:
        start = i
        tmp += s
    else:
        tmp = ''
        result += s
    if len(tmp) == len(T):
        result = S[:start-len(T)+1] + T + S[len(S[:start-len(T)+1])+start+len(T):]
        print(result.replace('?', 'a'))
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

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

t_length = len(T)

tmp = ''
result = ''
start = 0
for i, s in enumerate(S):
    if s == '?':
        start =i
        tmp += s
        result += s
    elif s == T[len(tmp)]:
        start = i
        tmp += s
    else:
        tmp = ''
        result += s
    if len(tmp) == len(T):
        result = S[:start-len(T)+1] + T + S[start+len(T):]
        print(result.replace('?', 'a'))
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

S = input()
T = input()

answer = ''
for i in range(len(S)-len(T)):
    found = True
    for j in range(len(T)):
        if S[i+j] != '?' and S[i+j] != T[j]:
            found = False
            break
    if found:
        tmp = deepcopy(S).replace('?', 'a')
        tmp = tmp[:i] + T + tmp[i+len(T):]
        if answer == '' or tmp < answer:
            answer = tmp

if answer == '':
    print('UNRESTORABLE')
else:
    print(answer)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

S = input()
T = input()

answer = ''
candidate = []

max_pos = len(S)
for i in range(1, len(T)+1):
    pos = 0
    finding = T[:i] + '?' * (len(T) - i)
    while pos < max_pos-len(finding):
        idx = S[pos:].find(finding)
        if idx == -1:
            break
        tmp = deepcopy(S).replace('?', 'a')
        tmp = tmp[:pos+idx] + T + tmp[pos+idx+len(finding):]
        candidate.append(tmp)
        pos = pos + idx + 1

if len(candidate) == 0:
    print('UNRESTORABLE')
else:
    print(sorted(candidate)[0])

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

S = input()
T = input()

answer = ''

max_pos = len(S)-1
for i in range(1, len(T)+1):
    pos = 0
    finding = T[:i] + '?' * (len(T) - i)
    while pos < max_pos-len(finding):
        idx = S[pos:].find(finding)
        if idx == -1:
            break
        tmp = deepcopy(S).replace('?', 'a')
        tmp = tmp[:pos+idx] + T + tmp[pos+idx+len(finding):]
        if answer == '' or tmp < answer:
            answer = tmp
        pos = pos + idx + 1

if answer == '':
    print('UNRESTORABLE')
else:
    print(answer)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

S = input()
T = input()

answer = ''

max_pos = len(S)-1
for i in range(1, len(T)+1):
    pos = 0
    finding = T[:i] + '?' * (len(T) - i)
    print(finding)
    while pos < max_pos-len(finding):
        idx = S[pos:].find(finding)
        if idx == -1:
            break
        tmp = deepcopy(S).replace('?', 'a')
        tmp = tmp[:pos+idx] + T + tmp[pos+idx+len(finding):]
        if answer == '' or tmp < answer:
            answer = tmp
        pos = pos + idx + 1
        print(pos)

if answer == '':
    print('UNRESTORABLE')
else:
    print(answer)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

S = input()
T = input()

answer = ''

max_pos = len(S)-1
for i in range(1, len(T)+1):
    finding = T[:i] + '?' * (len(T) - i)
    idx = S.find(finding)
    if idx == -1:
        continue

    tmp = deepcopy(S).replace('?', 'a')
    tmp = tmp[:idx] + T + tmp[idx+len(finding):]
    if answer == '' or tmp < answer:
        answer = tmp

if answer == '':
    print('UNRESTORABLE')
else:
    print(answer)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

S = input()
T = input()

answer = ''

max_pos = len(S)-1
for i in range(1, len(T)+1):
    pos = 0
    finding = T[:i] + '?' * (len(T) - i)
    idx = S[pos:].find(finding)
    if idx == -1:
        continue

    tmp = deepcopy(S).replace('?', 'a')
    tmp = tmp[:idx] + T + tmp[idx+len(finding):]
    if answer == '' or tmp < answer:
        answer = tmp
    pos = idx + 1

if answer == '':
    print('UNRESTORABLE')
else:
    print(answer)

Submission status: Wrong Answer

Solution code:
from copy import deepcopy

S = input()
T = input()

answer = ''

max_pos = len(S)-1
for i in range(1, len(T)+1):
    pos = 0 
    finding = T[:i] + '?' * (len(T) - i)
    while pos < max_pos:
        idx = S[pos:].find(finding)
        if idx == -1: 
            break
        tmp = deepcopy(S).replace('?', 'a')
        tmp = tmp[:idx] + T + tmp[idx+len(finding):]
        if answer == '' or tmp < answer:
            answer = tmp 
        pos = idx + 1 

if answer == '': 
    print('UNRESTORABLE')
else:
    print(answer)

Submission status: Wrong Answer

Solution code:
S=list(input())
T=list(input())
A=[]
for i in range(len(S)-len(T)+1):
    is_ok=1
    for j in range(i, i+len(T)):
        if S[j]!=T[j-i] and S[j]!='?':
            is_ok=0
    if is_ok:
        tmp=S[:]
        is_con=1
        for j in range(i, i+len(T)):
            tmp[j]=T[j-i]
        A.append(tmp)
print(A)
if len(A)==0:
    print("UNRESTORABLE")
    exit(0)
B=[]
for a in A:
    for i in range(len(a)):
        if a[i]=='?':
            a[i]='a'
    B.append(''.join(a))
B.sort()
print(B[0])

Submission status: Wrong Answer

Solution code:
S=list(input())
T=list(input())
is_con=0
if len(T)>len(S):
    print("UNRESTORABLE")
    exit(0)
for i in range(len(S)-len(T)+1):
    is_ok=1
    for j in range(i, i+len(T)):
        if S[j]!=T[j-i] and S[j]!='?':
            is_ok=0
    if is_ok:
        is_con=1
        for j in range(i, i+len(T)):
            S[j]=T[j-i]
        break
if is_con==0:
    print("UNRESTORABLE")
    exit(0)
for i in range(len(S)):
    if S[i]=='?':
        S[i]='a'
print(''.join(S))

Submission status: Wrong Answer

Solution code:
S=list(input())
T=list(input())
is_con=0
for i in range(len(S)-len(T)+1):
    is_ok=1
    for j in range(i, i+len(T)):
        if S[j]!=T[j-i] and S[j]!='?':
            is_ok=0
    if is_ok:
        is_con=1
        for j in range(i, i+len(T)):
            S[j]=T[j-i]
        break
if is_con==0:
    print("UNRESTORABLE")
    exit(0)
for i in range(len(S)):
    if S[i]=='?':
        S[i]='a'
print(''.join(S))

Submission status: Wrong Answer

Solution code:
S=list(input())
T=list(input())
is_con=0
for i in range(len(S)-len(T)+1):
    is_ok=1
    for j in range(i, i+len(T)):
        if S[j]!=T[j-i] and S[j]!='?':
            is_ok=0
    if is_ok:
        is_con=1
        for j in range(i, i+len(T)):
            S[j]=T[j-i]
        break
if is_con==0:
    print("UNRESTORABLE")
    exit(0)
# print(S)
for i in range(len(S)):
    if S[i]=='?':
        S[i]='a'
print(S)

Submission status: Wrong Answer

Solution code:
S0=input()
S1=list(S0)
T=list(input())
T1=['0']*len(T)
is_break=0
for i in range(1 << len(T)):
    if is_break:
        break
    for j in range(len(T)):
        T1[j]='?' if i&(1<<j) else T[j]
    T2=''.join(T1)
    if S0.find(T2)+1:
        # print(S0, T2)
        j=0
        for i in range(S0.find(T2),S0.find(T2)+len(T)):
            S1[i]=T[j]
            j+=1
        is_break=1
        break
if is_break==0:
    print("UNRESTORABLE")
    exit(0)
# print(S1)
for i in range(len(S1)):
    if S1[i]=='?':
        S1[i]='a'
S2=''.join(S1)
print(S2)

Submission status: Wrong Answer

Solution code:
S0=input()
S1=list(S0)
T=list(input())
T1=['0']*len(T)
is_break=0
for i in range(1 << len(T)):
    if is_break:
        break
    for j in range(len(T)):
        T1[j]='?' if i&(1<<j) else T[j]
    T2=''.join(T1)
    if S0.find(T2)+1:
        print(S0, T2)
        j=0
        for i in range(S0.find(T2),S0.find(T2)+len(T)):
            S1[i]=T[j]
            j+=1
        is_break=1
        break
if is_break==0:
    print("UNRESTORABLE")
    exit(0)
print(S1)
for i in range(len(S1)):
    if S1[i]=='?':
        S1[i]='a'
S2=''.join(S1)
print(S2)

Submission status: Wrong Answer

Solution code:
Sd=input().strip()
T=input().strip()
S=""
for i in range(len(Sd)-len(T)+1):
    sub=Sd[i:i+len(T)]
    for t,s in zip(T,sub):
        if s!="?" and s!=t:
            break
    else:
        S=Sd[:i]+T+Sd[i+len(T):]
        break
if S !="":
    print(S.replace("?", "a"))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

def NE(str1,str2):
    c=1
    for j in range(len(str1)):
        if str1[j]!="?" and str1[j]!=str2[j]:
            c=0
    return c

if len(S)<len(T):
    f=0
else:
    for i in range(len(S)-len(T)+1):
        f=NE(S[i:i+len(T)],T)
        if f:
            ans=S[0:i]+T+S[i+len(T):]
            ans=list(ans)
            break

if f:
    for i in range(len(ans)):
        if ans[i]=="?":
            ans[i]="a"
    print("".join(ans))
    
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
que = 0
for i in range(len(S)):
    if S[i] =='?':
        que += 1
if que == 0:
    print(S)
else:
    for i in range(len(S)-len(T)+1):
        count = 0
        for j in range(len(T)):
            if S[i+j] == T[j] or S[i+j] == '?':
                count += 1
        if count == len(T):
            S = S[:i] + T + S[i+j+1:]
            S_list = list(S)
            for k in range(len(S)):
                if S[k] == '?':
                    S_list[k] = 'a'
            print("".join(S_list))
            break
    else:
        print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
for i in range(len(S)-len(T)+1):
    count = 0
    for j in range(len(T)):
        if S[i+j] == T[j] or S[i+j] == '?':
            count += 1
    if count == len(T):
        S = S[:i] + T + S[i+j+1:]
        S_list = list(S)
        for k in range(len(S)):
            if S[k] == '?':
                S_list[k] = 'a'
        print("".join(S_list))
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

def coincide(s, t):
    res = True
    for i in range(0, len(s)):
        if s[i] != t[i] and s[i] != '?':
            res = False
    return res

ss = []
for i in range(0, len(sd) - len(t) + 1):
    if coincide(sd[i:i+len(t)], t):
        ss.append((sd[0:i]+t+sd[i+len(t):]).replace('?', 'a'))
        break
    else:
        continue

if len(ss) != 0:
    print(sorted(ss)[0])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

q = 0
ans = []

for i in range(len(S)-1, -1, -1):
    if S[i] == '?' or S[i] == T[-q-1]:
        q += 1
        if q >= len(T):
            ans.append((S[:i] + T + S[i+len(T):]).replace('?', 'a'))
            q -= 1
    else:
        q = 0

print(min(ans) if ans else 'UNRESTORABLE')

Submission status: Wrong Answer

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

q = 0

for i in range(len(S)-1, -1, -1):
    if S[i] == '?' or S[i] == T[-q-1]:
        q += 1
        if q == len(T):
            S = S[:i] + T + S[i+len(T):]
            print(S.replace('?', 'a'))
            exit()
    else:
        q = 0

print('UNRESTORABLE')

Submission status: Wrong Answer

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

q = 0

for i in range(len(S)-1, -1, -1):
    if S[i] == '?' or S[i] == T[:-q]:
        q += 1
        if q == len(T):
            S = S[:i] + T + S[i+len(T):]
            print(S.replace('?', 'a'))
            exit()
    else:
        q = 0

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
# enumerate の 番号が降順 のもの. 最後が0になる
def reverse_enumerate(l):
	for i, l_i in zip(range(len(l)-1, -1, -1), l):
		yield i, l_i
# n-gram(調べて)
def n_gram(s, n):
	return [s[i:i+n] for i in range(len(s)-n+1)]
# 二つの文字列が等しいかを調べる. 全ての文字と等しくなる文字を設定可能(all_match)
def is_equal_match(s1, s2, all_match=[]):
	for i in range(len(s1)):
		if not (s1[i] == s2[i] or s1[i] in all_match):
			return False
	return True
# 指定した index に 文字列を埋め込む
def fill_in_str(text, s, n):
	return text[:n] + s + text[n+len(s):]

s_ = input()
t = input()

for i, s_i in reverse_enumerate(n_gram(s_, len(t))):
	if is_equal_match(s_i, t, all_match="?"):
		print(fill_in_str(s_, t, i).replace("?", "a"))
		exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
# enumerate の 番号が降順 のもの. 最後が0になる
def reverse_enumerate(l):
	for i, l_i in zip(range(len(l)-1, -1, -1), l):
		yield i, l_i
# n-gram(調べて)
def n_gram(s, n):
	return [s[i:i+n] for i in range(len(s)-n+1)]
# 二つの文字列が等しいかを調べる. 全ての文字と等しくなる文字を設定可能(all_match)
def is_equal_match(s1, s2, all_match=[]):
	for i in range(len(s1)):
		if not (s1[i] == s2[i] or s1[i] in all_match):
			return False
	return True
# 指定した index に 文字列を埋め込む
def fill_in_str(text, s, n):
	return text[:n] + s + text[n+len(s):]

s_ = input()
t = input()

for i, s_i in reverse_enumerate(n_gram(s_, len(t))):
	if is_equal_match(s_i, t, all_match="?"):
		print(fill_in_str(s_, t, i))
		exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
#-*-coding:utf-8-*-

def all_same(lists, s):
    if list(set(lists))[0] == s and len(set(lists)) == 1:
        return True
    else:
        return False

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

    for i in range(len(s_hint) - len(t) + 1):
        arry = s_hint[i+1:i+len(t)]
        if s_hint[i] == t[0] and all_same(arry, '?'):
            start = i
            for j in range(start, start + len(t)):
                s_hint[j] = t[j - start]
            print(''.join(s_hint).replace('?', 'a'))
            exit()
    print('UNRESTORABLE')
                
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#-*-coding:utf-8-*-

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

    if len(t) > len(s_hint):
        print('UNRESTORABLE')
        exit()

    for i in range(len(s_hint)):
        if s_hint[i] == t[0] and len(s_hint) - i <= len(s_hint):
            arry = s_hint[i+1:i + len(t)]
            if len(set(arry)) == 1:
                start = i
                for j in range(start, start + len(t)):
                    s_hint[j] = t[j - start]
                for k in range(len(s_hint)):
                    if s_hint[k] == '?':
                        s_hint[k] = 'a'
                print(''.join(s_hint))
                break
                exit()
    print('UNRESTORABLE')
                
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#-*-coding:utf-8-*-

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

    for i in range(len(s_hint)):
        if s_hint[i] == t[0] and len(s_hint) - i <= len(s_hint):
            arry = s_hint[i+1:i + len(t)]
            if len(set(arry)) == 1:
                start = i
                for j in range(start, start + len(t)):
                    s_hint[j] = t[j - start]
                for k in range(len(s_hint)):
                    if s_hint[k] == '?':
                        s_hint[k] = 'a'
                print(''.join(s_hint))
                break
                exit()
    print('UNRESTORABLE')
                
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def chk(a,b):
    for (i,j) in zip(a,b):
        if i!=j and i!="?":
            return False
    return True

s=input()
t=input()
n=len(t)
l=[]
for i in range(len(s)-n,0,-1):
    if chk(s[i:i+n],t):
        l.extend([s[:i]+t+s[i+n:]])
if not l:
    print("UNRESTORABLE")
else:
    l=sorted(l)
    print(l[0].replace("?","a"))

Submission status: Wrong Answer

Solution code:
def chk(a,b):
    for (i,j) in zip(a,b):
        if i!=j and i!="?":
            return False
    return True

s=input()
t=input()
n=len(t)
o=""
for i in range(len(s)-n,0,-1):
    if chk(s[i:i+n],t):
        o=s[:i]+t+s[i+n:]
        break
if not o:
    print("UNRESTORABLE")
else:
    print(o.replace("?","a"))

Submission status: Wrong Answer

Solution code:
def chk(a,b):
    for (i,j) in zip(a,b):
        if i!=j and i!="?":
            return False
    return True

s=input()
t=input()
n=len(t)
o=""
for i in range(len(s)-n+1):
    if chk(s[i:i+n],t):
        o=s[:i]+t+s[i+n:]
        break
if not o:
    print("UNRESTORABLE")
else:
    print(o.replace("?","a"))

Submission status: Wrong Answer

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

ls = len(s)
lt = len(t)

ans = 'UNRESTORABLE'
for i in range((ls - lt + 1)):
    ds = s[i:i+lt]
    flg = True
    for j in range(lt):
#        if not((ds[j] == t[j]) or (ds[j] == '?')):
        if (ds[j] != t[j]) and (ds[j] != '?'):
            flg = False
            break
    if flg:
        ans = s[:i] + t + s[i+lt:]
        ans = ans.replace('?', 'a')
        break
print(ans)

Submission status: Wrong Answer

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

search_str = ["?" for x in range(len(T))]

last_occ = -1

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

        if ok_cnt == len(T) :
            print("HOGE")
            last_occ = i
            
if last_occ != -1 :
    str_tmp = S[0:last_occ] + T + S[last_occ + len(T):]
    print(str_tmp.replace("?", "a"))
else :
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

s2.reverse() 
t.reverse() 

ans = 'UNRESTORABLE'

if (len(t) > len(s2)):
    print(ans)
    exit()

for i in range(len(s2) - len(t) + 1):
    for j in range(len(t)):
        if t[j] == s2[i + j] or s2[i + j] == '?':
            if j == len(t) - 1:
                s2[i:i+j + 1] = t
                s2.reverse()
                ans = ''.join(s2)
                ans = ans.replace('?', 'a')
                break
            else:
                continue
        else:
            break


print(ans)

Submission status: Wrong Answer

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

s2.reverse() 
t.reverse() 

ans = 'UNRESTORABLE'

for i in range(len(s2) - len(t) + 1):
    for j in range(len(t)):
        if t[j] == s2[i + j] or s2[i + j] == '?':
            if j == len(t) - 1:
                s2[i:i+j + 1] = t
                s2.reverse()
                ans = ''.join(s2).replace('?', 'a')
                break
            else:
                continue
        else:
            break


print(ans)

Submission status: Wrong Answer

Solution code:
# time complexity: O(|S - T|*|T|)
# space complexity: O(|S - T|)

S_d = input()
T = input()
len_T = len(T)


def replacable(string, T):
    for char_s, char_t in zip(string, T):
        if char_s == char_t or char_s == '?':
            continue
        else:
            return False
    else:
        return True


# see if S_d can contain T
t_start_index_list = []
# O(|S - T|)
for start_idx in range(len(S_d) - len_T + 1):
    string = S_d[start_idx:start_idx + len_T]
    # O(|T|)
    if replacable(string, T):
        t_start_index_list.append(start_idx)

if len(t_start_index_list) == 0:
    print("UNRESTORABLE")
else:
    S_candidate_list = []
    for t_start_index in t_start_index_list:
        print(t_start_index)
        S = S_d[:t_start_index] + T + S_d[t_start_index + len_T:]
        S = S.replace('?', 'a')
        S_candidate_list.append(S)
    S_candidate_list.sort()
    print(S_candidate_list[0])

Submission status: Wrong Answer

Solution code:
s=list(input())
a=list(input())
c=0
for i in range(len(s)-len(a)+1):
    x=s[i:i+len(a)]
    for j in range(len(x)):
        if x[j]=="?" or x[j]==a[j]:continue
        else:break
    else:
        for k in range(len(a)):
            s[i+k]=a[k]
        c+=1
if c==0:print("UNRESTORABLE")
else:   
    for i in s:
        if i=="?": print("a",end="")
        else:print(i,end="")

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!
Sprime = input()
T = input()

def index(s, t):
    i = len(t) - 1
    j = len(s) - 1
    while j >= 0:
        if s[j] == t[i] or s[j] == "?":
            if i == 0:
                return j
                break
            else:
                i -= 1
        else:
            i = len(t) - 1
        if j == 0:
            return -1
            break
        else:
            j -= 1

def password(s = Sprime, t = T):
    i = index(s, t)
    if i == -1:
        print("UNRESTORABLE")
    else:
        new_s = []
        for j in range(len(s)):
            if j - i in range(len(t)):
                new_s.append(t[j-i])
            elif s[j] == "?":
                new_s.append("a")
            else:
                new_s.append(s[j])
        print("".join(new_s))
        
password()

Submission status: Wrong Answer

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

N = len(S2)


def check(S, T):
    for i in range(len(S)):
        if S[i] != '?' and S[i] != T[i]:
            return False
    return True


S = 'UNRESTORABLE'
if len(T) <= N:
    C = []
    for i in range(N - len(T) + 1):
        j = i + len(T)
        if S2[i] == T[0] and check(S2[i:j], T):
            S = list(S2)
            S[i:j] = list(T)
            S = ''.join(S).replace('?', 'a')
            C.append(S)
    if len(C) > 0:
        S = sorted(C)[0]
print(S)

Submission status: Wrong Answer

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

N = len(S2)


def check(S, T):
    for i in range(len(S)):
        if S[i] != '?' and S[i] != T[i]:
            return False
    return True


S = 'UNRESTORABLE'
if len(T) <= N:
    for i in range(N - len(T) + 1):
        j = i + len(T)
        if S2[i] == T[0] and check(S2[i:j], T):
            S = list(S2)
            S[i:j] = list(T)
            S = ''.join(S).replace('?', 'a')
print(S)

Submission status: Wrong Answer

Solution code:
def compare_string(left, right):
    for a, b in zip(left, right):
        if not (a == b or b == "?"):
            return False
    return True

def find_string(string):
    for i, s in enumerate(string):
        if s == "?":
            string[i] = "a"
    return string

def dubious(T, S):
    if len(T) == 1:
        l = list(reversed(S[:-1]))        
    else:
        l = list(reversed(S[:-len(T) + 1]))
    for i, s in enumerate(l):
        index = len(l) - (i + 1)
        if s == T[0] or s == "?":
            if compare_string(T, S[index:index+len(T)]):
                S[index: index+len(T)] = T
                print("".join(find_string(S)))
                return
    print("UNRESTORABLE")

S = list(input())
T = list(input())
dubious(T, S)