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


if len(T) > N:
    S = list('UNRESTORABLE')
else:
    flag = False
    for i in range(N):
        if i + len(T) > N:
            break
        if S2[i] == T[0] and check(S2[i:i + len(T)], T):
            S = list(S2)
            S[i:i + len(T)] = list(T)
            flag = True
    if flag:
        for i in range(N):
            if S[i] == '?':
                S[i] = 'a'
    else:
        S = list('UNRESTORABLE')
print(''.join(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


if len(T) > N:
    S = list('UNRESTORABLE')
else:
    flag = False
    for i in range(N):
        if i + len(T) > N:
            break
        if S2[i] == T[0] and check(S2[i:i + len(T)], T):
            S = list(S2)
            S[i:i + len(T)] = list(T)
            print(S)
            flag = True
    if flag:
        for i in range(N):
            if S[i] == '?':
                S[i] = 'a'
    else:
        S = list('UNRESTORABLE')
print(''.join(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 not len(T) == 1:
        l = list(reversed(S[:-len(T) + 1]))
    else:
        l = T
    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)

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):
    for i, s in enumerate(reversed(S[:-len(T) + 1])):
        index = len(S[:-len(T) + 1]) - (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)

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):
    for i, s in enumerate(S[:-len(T) + 1]):
        if s == T[0] or s == "?":
            if compare_string(T, S[i:i+len(T)]):
                S[i: i+len(T)] = T
                print("".join(find_string(S)))
                return
    print("UNRESTORABLE")

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

Submission status: Wrong Answer

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

a=len(s)
b=len(t)
f=0
for i in range(-1,-a+b,-1):
    f=0
    for j in range(-1,-b-1,-1):
        if (s[i+j+1]!="?"and t[j]!=s[i+j+1]):
            f=1
            break
    if f==1: continue
    for k in range(-1,-b-1,-1):
        s[i+k+1]=t[k]
    for p in range(a):
        if s[p]=="?":
            s[p]="a"
    print("".join(s))
    exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

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

a=len(s)
b=len(t)

for i in range(-1,-a+b,-1):
    for j in range(-1,-b-1,-1):
        if (s[i+j+1]!="?"and t[j]!=s[i+j+1]):
            continue
        for k in range(-1,-b-1,-1):
            s[i+k+1]=t[k]
        for p in range(a):
            if s[p]=="?":
                s[p]="a"
        print("".join(s))
        exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys
s = raw_input()
t = raw_input()

ls = len(s)
lt = len(t)
if ls < lt :
	print 'UNRESTORABLE'
	sys.exit()

for i in range(ls-lt,-1,-1):
	count = 0
	for j in range(lt):
		if s[i+j] == '?' or s[i+j] == t[j]:
			count += 1
		else :
			break
	if count == lt:
		print s[:i].replace('?','a')+t+s[i+lt:]
		sys.exit()

print 'UNRESTORABLE'

Submission status: Wrong Answer

Solution code:
import sys
s = raw_input()
t = raw_input()

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

for i in range(ls-lt,-1,-1):
	count = 0
	for j in range(lt):
		if s[i+j] == '?' or s[i+j] == t[j]:
			count += 1
		else :
			break
	if count == lt:
		print s[:i].replace('?','a')+t+s[i+lt:]
		sys.exit()

print 'UNRESTORABLE'

Submission status: Wrong Answer

Solution code:
import sys
s = raw_input()
t = raw_input()

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

for i in range(ls-lt+1):
	count = 0
	for j in range(lt):
		if s[i+j] == '?' or s[i+j] == t[j]:
			count += 1
		else :
			break
	if count == lt:
		print s[:i].replace('?','a')+t+s[i+lt:]
		sys.exit()

print 'UNRESTORABLE'

Submission status: Wrong Answer

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

insert_index = -1
while True:

    flag = True

    if left + len(t) - 1 == len(s):
        break

    for a, b in zip(s[left:left+len(t)], t):
        if a != b and a != "?":
            flag = False
            break
    if flag:
        insert_index = max(insert_index, left)
    left += 1


if insert_index == -1:
    print("UNRESTORABLE")
else:
    next_word = s.replace(s[insert_index:insert_index+len(t)], t)

    ans = next_word.replace("?", "a")
    print(ans)

Submission status: Wrong Answer

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

insert_index = -1
while True:

    flag = True

    if left + len(t) - 1 == len(s):
        break

    for a, b in zip(s[left:left+len(t)], t):
        if a != b and a != "?":
            flag = False
            break

    left += 1

    if flag:
        insert_index = max(insert_index, left)

if insert_index == -1:
    print("UNRESTORABLE")
else:
    next_word = s.replace(s[insert_index-1:insert_index+len(t)], t)
    ans = next_word.replace("?", "a")
    print(ans)

Submission status: Wrong Answer

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

insert_index = -1
while True:

    flag = True

    if left + len(t) - 1 == len(s):
        break

    for a, b in zip(s[left:left+len(t)], t):
        if a != b and a != "?":
            flag = False
            break

    left += 1

    if flag:
        insert_index = max(insert_index, left)

if insert_index == -1:
    print("UNRESTORABLE")
else:
    next_word = s.replace(s[insert_index:insert_index+len(t)], t)
    ans = next_word.replace("?", "a")
    print(ans)

Submission status: Wrong Answer

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

insert_index = -1
while True:

    flag = True

    if left + len(t) - 1 == len(s):
        break
    print(s[left:left+len(t)], t)

    for a, b in zip(s[left:left+len(t)], t):
        if a != b and a != "?":
            flag = False
            break

    left += 1

    if flag:
        insert_index = max(insert_index, left)

if insert_index == -1:
    print("UNRESTORABLE")
else:
    next_word = s[:insert_index] + t + s[len(t)+insert_index:]
    ans = next_word.replace("?", "a")
    print(ans)

Submission status: Wrong Answer

Solution code:

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

Len_S = len(S)
Len_T = len(T)

num = -1

for i in range(Len_S-Len_T+1):
    count = 0
    if S[i] == T[0]:
        flag = 1
        for j in range(Len_T):
            if S[i+j] != "?" and S[i+j] != T[j]:
                flag = -1
        if flag > 0:
            num = i

count = 0

for i in range(Len_S):
    if S[i]=="?":
        count+=1
    else:
        if count>Len_T:
            num = i-Len_T
        count=0

if count>0:
    if count>Len_T:
        num = Len_S-Len_T

if num < 0:
    print("UNRESTORABLE")
else:
    for i in range(Len_T):
        S[num+i] = T[i]
    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())

Len_S = len(S)
Len_T = len(T)

num = -1

for i in range(Len_S-Len_T+1):
    count = 0
    if S[i] == T[0]:
        flag = 1
        for j in range(Len_T):
            if S[i+j] != "?" and S[i+j] != T[j]:
                flag = -1
                print(i)
        if flag > 0:
            num = i

count = 0

for i in range(Len_S):
    if S[i]=="?":
        count+=1
    else:
        if count>Len_T:
            num = i-Len_T
        count=0

if count>0:
    if count>Len_T:
        num = Len_S-Len_T

if num < 0:
    print("UNRESTORABLE")
else:
    for i in range(Len_T):
        S[num+i] = T[i]
    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())

Len_S = len(S)
Len_T = len(T)

num = -1

for i in range(Len_S-Len_T+1):
    count = 0
    if S[i] == T[0]:
        flag = 1
        for j in range(Len_T):
            if S[i+j] != "?" and S[i+j] != T[j]:
                flag = -1
                print(i)
        if flag > 0:
            num = i

if num < 0:
    print("UNRESTORABLE")
else:
    for i in range(Len_T):
        S[num+i] = T[i]
    for i in range(Len_S):
        if S[i] == "?":
            S[i] = "a"
    print("".join(S))

Submission status: Wrong Answer

Solution code:
s = list(input())
slen = len(s)
t = list(input())
tlen = len(t)
box = []
phase = 0


def check(wh, phase=1):
    if wh + phase >= slen:
        return False
    
    if s[wh + phase] == "?" or s[wh + phase] == t[phase]:
        if phase + 1 == tlen:
            return True
        return check(wh, phase + 1)
    return False


def ume(arr):
    tmp = [e for e in arr]
    for i, e in enumerate(arr):
        if e == "?":
            tmp[i] = "a"
    return tmp



for i, e in enumerate(s):
    if e == t[0] or e == "?":
        if check(i):
            box.append(ume(s[:i] + t + s[i + tlen:]))

if not box:
    print("UNRESTORABLE")
else:
    box.sort
    print("".join(box[0]))

Submission status: Wrong Answer

Solution code:
s = list(input())
slen = len(s)
t = list(input())
tlen = len(t)
box = []
phase = 0


def check(wh, phase=1):
    if wh + phase >= slen:
        return False
    
    if s[wh + phase] == "?" or s[wh + phase] == t[phase]:
        if phase + 1 == tlen:
            return True
        return check(wh, phase + 1)
    return False


def ume(arr):
    tmp = [e for e in arr]
    for i, e in enumerate(arr):
        if e == "?":
            tmp[i] = "a"
    return tmp



for i, e in enumerate(s):
    if e == t[0]:
        print("ge")
        if check(i):
            box.append(ume(s[:i] + t + s[i + tlen:]))

if not box:
    print("UNRESTORABLE")
else:
    box.sort
    print("".join(box[0]))

Submission status: Wrong Answer

Solution code:
s = []
s += input()
t = []
t += input()
u = -1
for i in range(len(s) - len(t) + 1):
    if u == -1:
        no = 0
        if s[i] == t[0]:
            for k in range(len(t) - 1):
                if s[i + k + 1] != t[k + 1] and s[i + k + 1] != "?":
                    no = 1
                    break
            if no == 0:
                u = i
                break
    else:
        break
if u == -1:
    print("UNRESTORABLE")
else:
    for i in range(len(s)):
        if u <= i <= u + len(t) - 1:
            s[i] = t[i-u]
        elif s[i] == "?":
            s[i] = "a"
    print("".join(s))

Submission status: Wrong Answer

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

lp = len(s) - len(t) + 1


def check():
    for i in range(lp):
        for j in range(len(t)):
            if s[i+j] == t[j] or s[i+j] == '?':
                if j == (len(t) - 1):
                    return i
                else:
                    continue
            else:
                break

    return False


def main():
    res = check()
    if res is False:
        print('UNRESTORABLE')
        return
    else:
        s2 = list(s)

        for j in range(len(t)):
            s2[j+res] = t[j]

        for k in range(len(t)):
            if s2[k] == '?':
                s2[k] = 'a'

    print("".join(s2))
    return

main()

Submission status: Wrong Answer

Solution code:
import numpy
import re
import math
from collections import deque, defaultdict
import itertools

def main():
	"""
	テストコード実行
	:return:
	"""
	"""
	辞書順最小
	"""
	s = input().replace("?", ".")
	print(s)
	t = input()
	if len(s) < len(t):
		print("UNRESTORABLE")
		exit()
	ans = [] #答えのリスト
	# Sの先頭から順に確認していき、マッチする部分を見つけ、それ以外に部分を"a"に置き換える
	for i in range(len(s) - len(t) + 1):
		m = re.match(s[i:i + len(t)], t)
		if m is None:
			continue
		ans.append((s[:i] + t + s[i + len(t):]).replace(".", "a"))
	if len(ans) == 0:
		print("UNRESTORABLE")
		exit()
	print(min(ans)) #リスト内で辞書順最小の文字列を出力

if __name__ == '__main__':
	main()

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
res = ''
result = ''
if len(S) < len(T):
    print("UNRESTORABLE") 

elif len(S) == len(T):
    print(T)
    
else:
    for i in range(len(S)):
        for j in range(len(T)):
            if len(res) == len(S):   
                break
                
            if (S[i+j] == '?') or (S[i+j] == T[j]):
                res += T[j]
                t = 0
            elif (S[i+j] != T[j]):
                res = S[:i+j+1]
                t = 1
                break
           
    for i in range(len(S)):
        if res[i] == '?':
            result += 'a'
        else:   
            result += res[i]
   
    if t == 1:
         print("UNRESTORABLE") 
    else:
        print(result)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
res = ''
result = ''
if len(S) < len(T):
    print("UNRESTORABLE") 

elif len(S) == len(T):
    print(T)
    
else:
    for i in range(len(S)):
        for j in range(len(T)):
            if len(res) == len(S):   
                break
                
            if (S[i+j] == '?') or (S[i+j] == T[j]):
                res += T[j]
            elif (S[i+j] != T[j]):
                res = S[:i+j+1]
                break
            
    for i in range(len(S)):
        if res[i] == '?':
            result += 'a'
        else:   
            result += res[i]
            
    if len(res) != len(S):
         print("UNRESTORABLE") 
    
    else:
        print(result)

Submission status: Wrong Answer

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

s = input()
t = input()

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

# 先頭から探索、一か所でも当てはまる場所があればよい
for i in range(len(s) - len(t) + 1):
    s_split = s[i:i + len(t)]
    flag_loop = True

    for j in range(len(t)):
        # j文字目が一致またはs側が?であれば大丈夫
        if s_split[j] == t[j] or s_split[j] == '?':
            continue
        else:
            flag_loop = False
            break

    if flag_loop:
        if i == 0:
            if len(s) == len(t):
                print(t)
                exit()
            else:
                print(t + s[len(t):].replace('?', 'a'))
                exit()
        elif i == len(s) - len(t):
            print(s[:(len(s) - len(t))].replace('?', 'a') + t)
            exit()
        else:
            print(s[:i] + t + s[(i + len(s) - len(t)):])
            exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

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

s = len(S)
t = len(T)
ans = s + 1

if len(T) > len(S):
    print('UNRESTORABLE')
else:
    for i in range(s - t + 1): # iから|T|文字を見る
        tmp = 0
        for j in range(t):
            if S[i + j] == T[j] or S[i + j] == '?':
                tmp += 1
            else:
                break
        if tmp == t:
            ans = i

S_lst = list(S)

if ans < s + 1:
    for i in range(t):
        if S_lst[ans + i] == '?':
            S_lst[ans + i] = T[i]
    for i in range(s):
        if S_lst[i] == '?':
            S_lst[i] = 'a'
    print(''.join(S_lst))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
candidates = []
if len(S) < len(T):
    print("UNRESTORABLE")
else:
    for i in range(len(S) - len(T) + 1):
        s = S[i:len(T) + i]
        for j in range(len(s)):
            if s[j] != "?" and s[j] != T[j]:
                break
            if j == len(s) - 1:
                c = S[:i] + T + S[len(T) + i:]
                m = c.replace("?", "a")
                candidates.append(m)

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

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
candidates = []
if len(S) < len(T):
    print("UNRESTORABLE")
else:
    for i in range(len(S) - len(T) + 1):
        s = S[i:len(T) + i]
        assert len(T) == len(s)
        for j in range(len(s)):
            if s[j] != "?" and s[j] != T[j]:
                break
            if j == len(s) - 1:
                c = S[:i] + T + S[len(T) + i:]
                candidates.append(c.replace("?", "a"))

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

Submission status: Wrong Answer

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

s = len(S)
t = len(T)
ans = s + 1

if len(T) > len(S):
    print('UNRESTORABLE')
else:
    for i in range(s - t + 1):
        tmp = 0
        for j in range(t):
            if S[i + j] == T[j] or S[i + j] == '?':
                tmp += 1
            else:
                break
        if tmp == t:
            ans = i

S_lst = list(S)

if ans < s + 1:
    for i in range(t):
        if S_lst[ans + i] == '?':
            S_lst[ans + i] = T[i]
    for i in range(s):
        if S_lst[i] == '?':
            S_lst[i] = 'a'
    print(''.join(S_lst))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys

S_dash = input()
T = input()

for i in range(len(S_dash) - len(T) + 1):
    for idx, s in enumerate(T):
        if S_dash[i + idx] != s and S_dash[i + idx] != '?':
            break
    else:
        S = S_dash[:i] + T + S_dash[i + len(T):]
        S = S.replace('?', 'a')
        print(S)
        sys.exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys

S_dash = input()
T = input()

for i in range(len(T)):
    for idx, s in enumerate(T):
        if i + idx >= len(S_dash):
            break
        if S_dash[i + idx] != s and S_dash[i + idx] != '?':
            break
    else:
        S = S_dash[:i] + T + S_dash[i + len(T):]
        S = S.replace('?', 'a')
        print(S)
        sys.exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
words_list = []


def make_s(T):
    for i in range(1, len(T) + 1):
        q_n = '?' * i
        for j in range(len(T)):
            w = T[:j] + q_n + T[j + i:]
            if len(w) == len(T):
                words_list.append(w)
            else:
                break


S = input()
T = input()
make_s(T)

for w in words_list:
    if w in S:
        S = S.replace(w, T)
        S = S.replace('?', 'a')
        print(S)
        break
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

final_counter = 0
if len(S_list) >= len(T_list):
    for i, t in enumerate(T_list):
        if final_counter != 0:
            for j, s in enumerate(S_list):
                if s == t:
                    counter = 0
                    for k, l in zip(T_list, S_list[(j-i):]):
                        if l == "?" or k == l:
                            counter += 1

                    if counter == len(T_list):
                        print(S.replace("?", "a")[:(j-i)] +
                              T + 
                              S.replace("?", "a")[(j - i + len(T_list)):])
                        final_counter += 1
                    else:
                        pass
            
else:
    print("UNRESTORABLE")
    
if final_counter ==0:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

final_counter = 0
if len(S_list) >= len(T_list):
    if final_counter != 0:
        for i, t in enumerate(T_list):
            for j, s in enumerate(S_list):
                if s == t:
                    counter = 0
                    for k, l in zip(T_list, S_list[(j-i):]):
                        if l == "?" or k == l:
                            counter += 1

                    if counter == len(T_list):
                        print(S.replace("?", "a")[:(j-i)] +
                              T + 
                              S.replace("?", "a")[(j - i + len(T_list)):])
                        final_counter += 1
                    else:
                        pass
            
else:
    print("UNRESTORABLE")
    
if final_counter ==0:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

final_counter = 0
if len(S_list) >= len(T_list):
    
    for i, t in enumerate(T_list):
        for j, s in enumerate(S_list):
            if s == t:
                counter = 0
                for k, l in zip(T_list, S_list[(j-i):]):
                    if l == "?" or k == l:
                        counter += 1

                if counter == len(T_list):
                    print(S.replace("?", "a")[:(j-i)] +
                          T + 
                          S.replace("?", "a")[(j - i + len(T_list)):])
                    final_counter += 1
                else:
                    pass
            
else:
    print("UNRESTORABLE")
    
if final_counter ==0:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

ans = 'UNRESTORABLE'
memo = -1

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
        else:
            break
        if cnt == len(T):
            ans = T
            memo = i

if ans == 'UNRESTORABLE':
    print(ans)
else:
    ans = ''
    for s in S:
        if s == '?':
            ans += 'a'
        else:
            ans += s
    print(ans[:i]+T+ans[i+len(T):])

Submission status: Wrong Answer

Solution code:
ss = "abcdefghijklmn"
tt = "abc"
count = 0

def checker(original,checked):
    o = list(original)
    c = list(checked)
    flag = 1
    for i in range(len(o)):
        if o[i] == c [i]:
            continue
        elif o[i] == '?':
            continue
        else:
            flag = 0
    if flag == 1:
        return checked
    else:
        return -1

if len(ss) >=len(tt):
    while count <= len(ss):
        if count == 0:
            print(ss[(len(ss)-len(tt)):len(ss)])
        else:
            if len(ss[-count-len(tt):-count]) == len(tt):
                print(ss[-count-len(tt):-count])
        count += 1
    

    
print(checker('?i?','jkl'))

Submission status: Wrong Answer

Solution code:
from itertools import zip_longest

S = input()
T = input()

N = len(S)
Tn = len(T)
for i in range(N):
    K = S[i:i+Tn]
    for k, t in zip_longest(K, T, fillvalue=""):
        if k == "?":
            continue
        elif k != t:
            break
    else:
        ans = S[:i] + T + S[i+Tn:]
        print(ans.replace("?", "a"))
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
from itertools import zip_longest

S = input()
T = input()

N = len(S)
Tn = len(T)
for i in range(N):
    K = S[i:i+Tn]
    for k, t in zip_longest(K, T):
        if k == "?":
            continue
        elif k != t:
            break
    else:
        ans = S[:i] + T + S[i+Tn:]
        print(ans.replace("?", "a"))
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import sys
S_ = input()
T = input()

for i in range(0, len(S_) - len(T) + 1):
    tmp = S_[:]
    tmp = tmp[:i] + T + tmp[i + len(T):]

    double = [_ if _ == S_[i] else '?' for i, _ in enumerate(tmp)]
    if ''.join(double) == S_:
        S = tmp
        S = ''.join(['a' if _ == '?' else _ for _ in S])
        print(S)
        sys.exit()

else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
answer='UNRESTORABLE'

for i in range(len(S)-len(T),0,-1):
    tmpS=S[i:i+len(T)]
    flag=True
    for j in range(len(T)):
        if T[j]==tmpS[j] or tmpS[j]=='?':
            continue
        else:
            flag=False
    if flag:
        ans=S[0:i]+T+S[i+len(T):len(S)]
        answer = ans.replace("?","a")
        break

print(answer)

Submission status: Wrong Answer

Solution code:
s, t = input(), input()
sl, tl = len(s), len(t)
p, dict = 0, {}
for i in range(26):
    dict[chr(ord('a')+i)] = tl
for i in range(tl-1):
    dict[t[i]] = tl - i - 1
while(p + tl < sl):
    check = True
    for i in range(tl):
        if(s[p+tl-i] != '?' and s[p+tl-i] != t[-i-1]):
            p += max(dict[s[p+tl-i]] - i, 1)
            check = False
            break
    if(check):
        s = s[:p+1] + t + s[p+tl+1:]
        s = s.replace('?', 'a')
        print(s)
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ans = []
for i in range(len(s)-len(t)+1):
    if s[i] == '?' or s[i] == t[0]:
        ok = True
        j = 1
        while j < len(t) and ok:
            if s[i+j] == '?' or s[i+j] == t[j]:
                j += 1
                continue
            else:
                ok = False
        if ok:
            f = [x for x in s]
            print(f, t)
            for j in range(len(t)):
                f[i+j] = t[j]
            f = "".join(f)
            f.replace('?', 'a')
            ans.append(f)
        if s[i] == '?':
            s[i] = 'a'
if ans:
    print(sorted(ans)[0])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = str(input())
T = str(input())
a = len(S)
b = len(T)
if (a < b):
    B = "UNRESTORABLE"
else:
    m = a-b
    B = "UNRESTORABLE"
    i = m
    #for i in range(m+1):
    while 0<=i:
        for j in range(b):
            if S[i+j] == T[j]:
                S =S.replace(S[i:i+b], T)
                S = S.replace('?', 'a')
                B = S
                break
        if B != "UNRESTORABLE":
            break
        i -= 1
        
print(B)

Submission status: Wrong Answer

Solution code:
S = str(input())
T = str(input())
a = len(S)
b = len(T)
if (a < b):
    B = "UNRESTORABLE"
else:
    m = a-b
    B = "UNRESTORABLE"
    for i in range(m+1):
        for j in range(b):
            if S[i+j] == T[j]:
                S =S.replace(S[i:i+b+1], T)
                S = S.replace('?', 'a')
                B = S
                break
        if B != "UNRESTORABLE":
            break
        
print(B)

Submission status: Wrong Answer

Solution code:
S = str(input())
T = str(input())
a = len(S)
b = len(T)
if (a < b):
    print("UNRESTORABLE")
    exit()
    
m = a-b
B = "UNRESTORABLE"
for i in range(m+1):
    for j in range(b):
        if S[i+j] == T[j]:
            S =S.replace(S[i:i+b+1], T)
            S = S.replace('?', 'a')
            print(S)
            exit()
print(B)

Submission status: Wrong Answer

Solution code:
import sys
S = str(input())
T = str(input())
a = len(S)
b = len(T)
if (a < b):
    print("UNRESTORABLE")
    sys.exit()
m = a-b
for i in range(m+1):
    for j in range(b):
        if S[i+j] == T[j]:
            S =S.replace(S[i:i+b+1], T)
            S = S.replace('?', 'a')
            print(S)
            sys.exit()
            
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = str(input())
T = str(input())
a = len(S)
b = len(T)
if (a < b):
    print("UNRESTORABLE")
    exit(0)
m = a-b
for i in range(m+1):
    for j in range(b):
        if S[i+j] == T[j]:
            S =S.replace(S[i:i+b+1], T)
            S = S.replace('?', 'a')
            print(S)
            exit(0)
            
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S_d = input()
T = input()
l = len(S_d)
result = S_d

def check(sig, clue):
    if len(sig) != len(clue): return None
    count = 0
    for i in range(len(sig)):
        if sig[i] == clue[i] or sig[i] == '?':
            count += 1
    if count == len(sig):
        return True
    else: return False

for i, c in enumerate(S_d[::-1]):
    if c == T[0] and i >= len(T) - 1:
        if check(S_d[l-i-1:], T):
            result = S_d[:l-i-1] + T + S_d[l-i-1+len(T):]
            result = result.replace('?', 'a')
if S_d == result:
    print('UNRESTORABLE')
else:
    print(result)

Submission status: Wrong Answer

Solution code:
S_d = input()
T = input()
l = len(S_d)
result = S_d

def check(sig, clue):
    if len(sig) != len(clue): return None
    count = 0
    for i in range(len(sig)):
        if sig[i] == clue[i] or sig[i] == '?':
            count += 1
    if count == len(sig):
        return True
    else: return False

for i, c in enumerate(S_d[::-1]):
    if c == T[0] and i >= len(T) - 1:
        if check(S_d[l-i-1:], T):
            result = S_d[:l-i-1] + T + S_d[l-i-1+len(T):]
            result = S_d.replace('?', 'a')
if S_d == result:
    print('UNRESTORABLE')
else:
    print(result)

Submission status: Wrong Answer

Solution code:
S_d = input()
T = input()
l = len(S_d)
result = S_d

def check(sig, clue):
    if len(sig) != len(clue): return None
    count = 0
    for i in range(len(sig)):
        if sig[i] == clue[i] or sig[i] == '?':
            count += 1
    if count == len(sig):
        return True
    else: return False

for i, c in enumerate(S_d[::-1]):
    if c == T[0] and i >= len(T) - 1:
        if check(S_d[l-i-1:], T):
            S_d = S_d[:l-i-1] + T + S_d[l-i-1+len(T):]
            S_d = S_d.replace('?', 'a')
print(S_d)