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

Solution code:
hint = input()
t = input()
s = []
for x in hint:
    s.append(x)
found = False

for i in t:
    if hint.rfind(i) > -1:
        for j in range(len(t) - t.index(i)):
            if hint[hint.rfind(i) + j] == t[t.index(i) + j] or "?" == hint[hint.rfind(i) + j]:
                found = True
            else:
                found = False

        if found:
            for k in range(t.index(i)):
                s[hint.rfind(i) - t.index(i) + k] = t[t.index(i) + k]
            for k in range(t.index(i), len(t)):
                s[hint.rfind(i) + k] = t[k]
            break

    elif hint.rfind('?' * len(t)) > -1:
            for x in t:
                s[hint.rfind('?' * len(t)) + t.index(x)] = x
            found = True

ans = ''.join(s)
if ans != hint:
    print(ans.replace("?", "a"))

else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
hint = input()
t = input()
s = []
for x in hint:
    s.append(x)
found = False

for i in t:
    if hint.rfind(i) > -1:
        for j in range(len(t) - t.index(i)):
            if hint[hint.rfind(i) + j] == t[t.index(i) + j] or "?" == hint[hint.rfind(i) + j]:
                found = True
            else:
                found = False

        if found:
            for k in range(t.index(i)):
                s[hint.rfind(i) - t.index(i) + k] = t[t.index(i) + k]
            for k in range(t.index(i), len(t)):
                s[hint.rfind(i) + k] = t[k]
            break

    elif hint.rfind('?' * len(t)) > -1:
            for x in t:
                s[hint.rfind('?' * len(t)) + t.index(x)] = x
            found = True

if found:
    ans = ''.join(s)
    print(ans.replace("?", "a"))

else:
    print('UNRESTORABLE')

'''

def found_all(index):
    global s

    for i in range(len(t)):
        if (t[i] != hint[index + i]) and (hint[index + i] != '?'):
            return False

    s = []
    for x in hint:
        s.append(x)
    
    for j in range(len(t)):
        s[index + j] = t[j]

    return True


# finding a substring in hint
for j in t:
    if found_all(hint.find(j)):
        found = True


'''

Submission status: Runtime Error

Solution code:
hint = input()
t = input()
s = []
for x in hint:
    s.append(x)
found = False

for i in t:
    if hint.rfind(i) > -1:
        for j in range(len(t) - t.index(i)):
            if hint[hint.rfind(i) + j] == t[t.index(i) + j] or "?" == hint[hint.rfind(i) + j]:
                found = True
            else:
                found = False

        if found:
            for k in range(t.index(i)):
                s[hint.rfind(i) - t.index(i) + k] = t[t.index(i) + k]
            for k in range(t.index(i), len(t)):
                s[hint.rfind(i) + k] = t[k]
            break

    elif hint.rfind('?' * len(t)) > -1:
            for x in t:
                # print(t.index(x))
                # print(hint.rfind('?' * len(t)) )
                # print(s[0])
                s[hint.rfind('?' * len(t)) + t.index(x)] = x
            found = True

print(found)
if found:
    ans = ''.join(s)
    print(ans.replace("?", "a"))

else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
hint = input()
t = input()
s = [0 for i in range(len(hint))]
found = False


def check(index):
    for i in range(len(t)):
        if (t[i] == hint[index + i]) or (hint[index + i] == '?'):
            s[index+i] = t[i]


# matching hint and t
for j in t:
    if hint.find(j) > -1:
        check(int(hint.find(j)))
        found = True

for k in range(len(hint)):
    if hint[k] != "?":
        s[k] = hint[k]
    elif s[k] == 0:
        s[k] = "a"

if found:
    # question_to_a = 'a' * (len(hint) - len(s))
    # s += question_to_a
    for st in s:
        print(st, end="")
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
hint = input()
t = input()
s = [0 for i in range(len(hint))]
found = False


def check(index):
    for i in range(len(t)):
        if (t[i] == hint[index + i]) or (hint[index + i] == '?'):
            s[index+i] = t[i]


# matching hint and t
for j in t:
    if hint.find(j) > 0:
        check(int(hint.find(j)))
        found = True

for k in range(len(hint)):
    if hint[k] != "?":
        s[k] = hint[k]
    elif s[k] == 0:
        s[k] = "a"

if found:
    # question_to_a = 'a' * (len(hint) - len(s))
    # s += question_to_a
    for st in s:
        print(st, end="")
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
import sys
s = input()
T=input()
p = 0
for i in range(len(s)-len(T)+1,0,-1):
  for j in range(len(T)):
    if T[j]!=s[i-1+j] and "?"!= s[i-1+j] :
      p = 1
      break
if p == 0:
  s=s[:i-1]+T+s[i+len(T)-1:]
  s = s.replace('?', 'a')
  print(s)
sys.exit()
if p == 1:
  print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
def is_substring(s,t,start_index):
	ok=True
	j=0
	for i in range(start_index, start_index + len(s) - len(t) + 1):
		if s[i] == t[j] or s[i] == '?':
			j+=1
		else:
			ok = False
			break
	return ok


def replace(s, index, changed_char):
	s_list = list(s)
	s_list[index] = changed_char
	t = "".join(s_list)
	return t

def main():
	s=str(input())
	t=str(input())
	
	ok=False
	if len(s) >= len(t):
		for i in range(len(s) - len(t) + 1):
			j=0
			if s[i] == t[j] or s[i] == '?':
				if is_substring(s,t,i) == True:
					k=i
					for j in range(len(t)):
						s = replace(s, k, t[j])
						k+=1
					ok=True
					break

		if ok == True:
			for i in range(len(s)):
				if (s[i] == '?'):
					s = replace(s, i, 'a')

	print(s if ok == True else "UNRESTORABLE")

if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
def is_substring(s,t,start_index):
	ok=True
	j=0
	for i in range(start_index, start_index + max(len(s) - len(t) + 1,0)):
		if s[i] == t[j] or s[i] == '?':
			j+=1
		else:
			ok = False
			break
	return ok


def replace(s_list, index, changed_char):
	s_list[index] = changed_char
	t = "".join(s_list)
	return t

def main():
	s=str(input())
	t=str(input())
	s_list = list(s)

	ok=False

	if len(s) >= len(t):
		for i in range(max(len(s) - len(t) + 1,0)):
			j=0
			if s[i] == t[j] or s[i] == '?':
				if is_substring(s,t,i) == True:
					k=i
					for j in range(len(t)):
						s = replace(s_list, k, t[j])
						k+=1
					ok=True
					break

		if ok == True:
			s_list = list(s)
			for i in range(len(s)):
				if (s[i] == '?'):
					s = replace(s_list, i, 'a')

	print(s if ok == True else "UNRESTORABLE")

if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
def is_substring(s,t,start_index):
	ok=True
	j=0
	for i in range(start_index, start_index + max(len(s) - len(t) + 1,0)):
		if s[i] == t[j] or s[i] == '?':
			j+=1
		else:
			ok = False
			break
	return ok


def replace(s_list, index, changed_char):
	s_list[index] = changed_char
	t = "".join(s_list)
	return t

def main():
	s=str(input())
	t=str(input())
	s_list = list(s)

	ok=False
	for i in range(max(len(s) - len(t) + 1,0)):
		j=0
		if s[i] == t[j] or s[i] == '?':
			if is_substring(s,t,i) == True:
				k=i
				for j in range(len(t)):
					s = replace(s_list, k, t[j])
#				s[k] = t[j]
					k+=1
				ok=True
				break

	if ok == True:
		for i in range(len(s)):
			if (s[i] == '?'):
				s = replace(s_list, i, 'a')

	print(s if ok == True else "UNRESTORABLE")

if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
def is_substring(s,t,start_index):
	ok=True
	j=0
	for i in range(start_index, start_index + len(s) - len(t) + 1):
		if s[i] == t[j] or s[i] == '?':
			j+=1
		else:
			ok = False
			break
	return ok


def replace(s_list, index, changed_char):
	s_list[index] = changed_char
	t = "".join(s_list)
	return t

def main():
	s=str(input())
	t=str(input())
	s_list = list(s)

	ok=False
	for i in range(len(s) - len(t) + 1):
		j=0
		if s[i] == t[j] or s[i] == '?':
			if is_substring(s,t,i) == True:
				k=i
				for j in range(len(t)):
					s = replace(s_list, k, t[j])
#				s[k] = t[j]
					k+=1
				ok=True
				break

	if ok == True:
		for i in range(len(s)):
			if (s[i] == '?'):
				s = replace(s_list, i, 'a')

	print(s if ok == True else "UNRESTORABLE")

if __name__ == '__main__':
	main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python

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

    if len(Sdash) < len(T):
        print("UNRESTORABLE")

    S = ""
    for i in range(len(Sdash)):
        is_matched = True
        for j in range(len(T)):
            if i + j >= len(Sdash) or (Sdash[i + j] != '?' and Sdash[i + j] != T[j]):
                is_matched = False
                break
        if is_matched == True:
            S = Sdash[:i] + T + Sdash[i + len(T):]
            break

    if S == "":
        print("UNRESTORABLE")
    else:
        alphabets = [chr(i) for i in range(97, 97 + 26)]
        for i in range(len(S)):
            if S[i] == '?':
                S = S[:i] + alphabets.pop(0) + S[i + 1:]
        print(S)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
#!/usr/bin/env python

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

    S = ""
    for i in range(len(Sdash)):
        is_matched = True
        for j in range(len(T)):
            if i + j >= len(Sdash) or (Sdash[i + j] != '?' and Sdash[i + j] != T[j]):
                is_matched = False
                break
        if is_matched == True:
            S = Sdash[:i] + T + Sdash[i + len(T):]
            break

    if S == "":
        print("UNRESTORABLE")
    else:
        alphabets = [chr(i) for i in range(97, 97 + 26)]
        for i in range(len(S)):
            if S[i] == '?':
                S = S[:i] + alphabets.pop(0) + S[i + 1:]
        print(S)

if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
# -*- coding: utf-8 -*-
import unittest
from unittest import skip
from test.support import captured_stdout

from src.bin.main import main, _main
from unittest.mock import MagicMock, patch


class TestMain(unittest.TestCase):

    @staticmethod
    def mock_of_inputs():  # Use this mock if a contest requires interactive input.
        stdin_lines = MagicMock()
        stdin_lines.side_effect = ['?tc????',  # you can emulate standard input lines by using this list.
                                   'coder'
                                   ]
        return stdin_lines

    @staticmethod
    def get_last_stdout_line(stdout):  # This method sometimes useful when you print results to stdout.
        return stdout.getvalue().split('\n')[-2]

    def test_main(self):
        """Test Whole things, including standard Input/Output by using input mocking.
        Use this test if the contest requires input from stdin, and requires export result to stdout.
        """
        expected = 'atcoder'

        with patch(target='src.bin.main._input', new=self.mock_of_inputs()):  # emulate inputs by mock
            with captured_stdout() as stdout:
                main()
                result = self.get_last_stdout_line(stdout)

        self.assertEqual(expected, result)
        # if there are multiple output, stdout.getvalue returns combined one.

    @skip
    def test__main(self):
        """Test for Main Logic Only.
        Use This test if the contest only evaluates method level Input/Output and not interactive.
        """

        args = ['1', '2']
        expected = ['11', '22']

        result = _main(args)

        self.assertEqual(expected, result)

Submission status: Runtime Error

Solution code:
=str(input())
T=str(input())
SL=len(S)
TL=len(T)
a=[]
 
for i in range(SL-TL+1):
 
    count=0
 
    for j in range(TL):
 
        if S[i+j] == '?' or S[i+j]==T[j]:
            count += 1
 
    if count==TL:
        ans = S[:i].replace('?','a')+T+S[i+TL:].replace('?','a')
        a.append(ans)
 
if len(a)==0:
    print('UNRESTORABLE')
else:
    a.sort()
    print(ans)

Submission status: Runtime Error

Solution code:
def main():
    s = list(input())
    t = list(input())
    #print(s)
    #print(t)
    #print(len(s)-len(t)+1)

    for i in range(len(s)-len(t)+1):
        flag = True
        for j in range(len(t)):
            if s[i+j] == '?':
                continue
            if s[i+j] == t[j]:
                continue
            flag = False
            break
            
        if flag:
            idx = i
            break

    if flag:
        s = ''.join(s[:i] + t + s[i+len(t):])
        print(s.replace('?', 'a'))
    else:
        print("UNRESTORABLE")
        

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

    for i in range(len(s)-len(t)+1):
        flag = True
        for j in range(len(t)):
            if s[-(i+j)] != t[-j] and s[-(i+j)] != '?':
                flag = False
                break
        if flag:
            s[len(s)-(len(t)+i):len(s)-i] = t
            break

    if flag:
        
        print(''.join(s).replace('?', 'a'))
    else:
        print("UNRESTORABLE")
        
        

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    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] != t[j] and s[i+j] != '?':
                flag = False
                break
        if flag:
            s = s[:i] + t + s[i+len(t):]
            #break

    if flag:
        print(s.replace('?', 'a'))
    else:
        print("UNRESTORABLE")
        

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    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] != t[j] and s[i+j] != '?':
                flag = False
                break
        if flag:
            s = s[:i] + t + s[i+len(t):]
            break

    if flag:
        print(s.replace('?', 'a'))
    else:
        print("UNRESTORABLE")
        

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    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] != t[j] and s[i+j] != '?':
                flag = False
        if flag:
            s = s[:i] + t + s[i+len(t):]
            break;

    if flag:
        print(s.replace('?', 'a'))
    else:
        print("UNRESTORABLE")
        

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def main():
    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] != t[j] and s[i+j] != '?':
                flag = False
        if flag:
            s = s.replace(s[i:i+len(t)], t)
            break;

    if flag:
        print(s.replace('?', 'a'))
    else:
        print("UNRESTORABLE")
        

if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

def is_restorable(a,b):
    ans = True
    for x,y in zip(a,b):
        if x == y or x == '?':
            pass
        else:
            ans = False
            break
    return ans

s = s[::-1]
t = t[::-1]
s_ = list(s)

can_restore = False
anchor = [0,0]

for i,x in enumerate(s):
    if not can_restore:
        if is_restorable(s[i:i+len(t)],t):
            can_restore = True
            s_[i:i+len(t)] = t
            s_ = s_[::-1]
            s_ = ''.join(s_)

ans = s_.replace('?','a')

print(ans)

Submission status: Runtime Error

Solution code:
S_prime = input()
T = input()
replaced = 'UNRESTORABLE'
matched = True

if len(S_prime) < len(T):
    cout << replaced << endl;

for i in range(len(S_prime) - len(T) + 1):
    for k in range(len(T)):
        if S_prime[i + k] != T[k] and S_prime[i + k] != '?':
            matched = False
            break
        matched = True
    if matched:
        print(S_prime[0:i])
        replaced = S_prime[0:i] + T + S_prime[i + len(T):]
        break

print(replaced.replace('?', 'a'))

Submission status: Runtime Error

Solution code:
X = 1
N = input()
K = input()
for i in range(N):
	if(X*2 < X+K):
	    X *= 2
	else:
            X += K
print(X)

Submission status: Runtime Error

Solution code:
import sys
S0=raw_input()
T=list(raw_input())

l=len(T)


ans=""
for i in range(len(S0)-l+1):
	S1=list(S0)
	for j in range(l):
		#print i+j,j,S1[i+j],T[j]
		if S1[i+j]!=T[j] and S1[i+j]!="?":
			#print "break"
			break
	else:
		#print "else"
		for j in range(l):
			S1[i+j]=T[j]
		S_tmp=(''.join(S1)).replace('?','a')
		#print ans
		#print S_tmp
		if ans=="":
			ans=S_tmp
		if S_tmp < ans:
			ans=S_tmp
			
	
if S0==''.join(S1) and S0.find("?")!=-1:
	print "UNRESTORABLE"
	sys.exit()
	

print ans

Submission status: Runtime Error

Solution code:
import sys
S0=raw_input()
T=list(raw_input())

l=len(T)


ans=""
for i in range(len(S0)-l+1):
	S1=list(S0)
	for j in range(l):
		#print i+j,j,S1[i+j],T[j]
		if S1[i+j]!=T[j] and S1[i+j]!="?":
			#print "break"
			break
	else:
		#print "else"
		for j in range(l):
			S1[i+j]=T[j]
		S_tmp=(''.join(S1)).replace('?','a')
		#print ans
		#print S_tmp
		if ans=="":
			ans=S_tmp
		if S_tmp < ans:
			ans=S_tmp
			
	
if S0==''.join(S1):
	print "UNRESTORABLE"
	sys.exit()
	

print ans

Submission status: Runtime Error

Solution code:
import sys
S0=raw_input()
S1=list(S0)
T=list(raw_input())
#print S1
#print T

l=len(T)

S=[]

for i in range(3):
	for j in range(l):
		#print i+j,j,S1[i+j],T[j]
		if S1[i+j]!=T[j] and S1[i+j]!="?":
			#print "break"
			break
	else:
		#print "else"
		for j in range(l):
			S1[i+j]=T[j]
	
if S0==''.join(S1):
	print "UNRESTORABLE"
	sys.exit()
	

S2=''.join(S1)
print S2.replace('?','a')

Submission status: Runtime Error

Solution code:

a = list(input())
b = list(input())
a_l = len(a)
b_l = len(b)
 
for i in range(1,a_l-b_l+2):
    if a_l < b_l:
        f=False
        break
    f = True
    for j in range(1,b_l+1):
        if not(b[b_l-j] == a[a_l-i-j+1] or a[a_l-i-j+1] == "?"):
            f = False
            break
    if f:
        for j in range(1,b_l+1):
            a[a_l-i-j+1] = b[b_l-j]
        break
 
if f:
    print("".join(a).replace("?", "a"))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:

a = list(input())
b = list(input())
a_l = len(a)
b_l = len(b)
 
for i in range(1,a_l-b_l+2):
    f = True
    for j in range(1,b_l+1):
        if not(b[b_l-j] == a[a_l-i-j+1] or a[a_l-i-j+1] == "?"):
            f = False
            break
    if f:
        for j in range(1,b_l+1):
            a[a_l-i-j+1] = b[b_l-j]
        break
 
if f:
    print("".join(a).replace("?", "a"))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
a = list(input())
b = list(input())
a_l = len(a)
b_l = len(b)

for i in range(1,a_l-b_l+2):
    f = True
    for j in range(1,b_l+1):
        if not(b[b_l-j] == a[a_l-i-j+1] or a[a_l-i-j+1] == "?"):
            f = False
            break
    if f:
        for j in range(1,b_l+1):
            a[a_l-i-j+1] = b[b_l-j]
        break

if f:
    print("".join(a).replace("?", "a"))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
a = raw_input()
b = raw_input()
a = list(a)
b = list(b)
n = len(a)
m = len(b)
z = ''
for i in range(n - m + 1):
	flag = True
	for j in range(m):
		if a[i + j] != b[j] and a[i + j] != '?':
			flag = False
	if not flag:
		continue
	c = a
	for j in range(m):
		c[i + j] = b[j]
	for i in range(n):
		if c[i] == '?':
			c[i] = 'a'
	if z == '':
		z = c
	else:
		z = min(z, c)
if z == '':
	print UNRESTORABLE
else:
	print ''.join(z)

Submission status: Runtime Error

Solution code:
from collections import defaultdict

Ss = input()
T =  input()

Tdic = defaultdict(lambda: len(T))

for idx,i in  enumerate(T):
    Tdic[i] = len(T) -(idx+1)
    
Tdic[T[-1]] = len(T)
Tdic["?"] = 1
    
Flag = False
mutchdic = dict()
mutch = 0
head = len(T)-1
          
while(1):
    for i in range(len(T)):
        if T[-(i+1)] == Ss[head-i]:
            mutch += 1
            if i+1 == len(T):
                mutchdic[head] = mutch
                head += len(T)
                mutch = 0
                Flag = True
        elif Ss[head-i] == "?":
            if i+1 == len(T):
                mutchdic[head] = mutch
                head += 1
                mutch = 0
                Flag = True
        else:
            mutchdic[head] = mutch
            head += Tdic[Ss[head]]
            break
    if head > len(Ss)-1:
        break

if Flag:
    SsL = list(Ss)
    max_head = max(mutchdic.items(), key=lambda x:x[1])[0]
    for i in range(len(T)):
        SsL[max_head-i] = T[-(i+1)]
        SsLstr = "".join(SsL)
        SsLstr=SsLstr.replace("?","a")
        ans = SsLstr
else:
    ans = "UNRESTORABLE"

print(ans)

Submission status: Runtime Error

Solution code:
def getResult(S, i, T):
    res = ""
    for k in range(0, len(S)):
        if k < i:
            res = res + S[k]
        elif k >= i and k < i+len(T):
            res = res + T[k-i]
        else:
            res = res + S[k]
    S = res.replace('?', 'a')
    return S

res_list = []

res = False
for i in range(0, len(S)):
    if S[i] != '?':
        if checkValid(S, i, T) == True:
            res_list.append(getResult(S, i, T))
            res = True
    else:
        if checkValid2(S, i, T) == True:
            res_list.append(getResult(S, i, T))
            res = True

if res == False:
    print("UNRESTORABLE")
else:
    print (len(res_list))
    smallest = res_list[0]
    for i in range(0, len(res_list)):
        if smallest > res_list[i]:
            smallest = res_list[i]
def getResult(S, i, T):
    res = ""
    for k in range(0, len(S)):
        if k < i:
            res = res + S[k]
        elif k >= i and k < i+len(T):
            res = res + T[k-i]
        else:
            res = res + S[k]
    S = res.replace('?', 'a')
    return S

res_list = []

res = False
for i in range(0, len(S)):
    if S[i] != '?':
        if checkValid(S, i, T) == True:
            res_list.append(getResult(S, i, T))
            res = True
    else:
        if checkValid2(S, i, T) == True:
            res_list.append(getResult(S, i, T))
            res = True

if res == False:
    print("UNRESTORABLE")
else:
    print (len(res_list))
    smallest = res_list[0]
    for i in range(0, len(res_list)):
        if smallest > res_list[i]:
            smallest = res_list[i]

Submission status: Runtime Error

Solution code:
from sys import stdin, stdout
from collections import defaultdict
def readLine_int_list():return list(map(int, stdin.readline().split()))
def readLine_int_list_reverse(): return list(map(int, stdin.readline().split())).reverse()
def readAll_int(): return list(map(int, stdin))
def readLine_str_list():return list(map(str, stdin.readline().split()))
def readAll_str(): return list(map(str, stdin))

import re

def main():
	_s = input()
	t = input()
	pattern=""
	for i in t:
	    pattern += "[?{}]".format(i)

	ans = ""
	f = False
	for i in range(len(_s)):
	    if _s[i] == '?' or _s[i] == t[0]:
	        tmp = _s[i:i+len(t)]
	        match = re.match(pattern , tmp)
	        if match:
	            f = True
	            ans += 'X'
	        else:
	            ans += 'a'
	    else:
	        ans += _s[i]
	
	
	for i in range(len(ans)):
	    if ans[i] == "X":
	       _ans = [_ for _ in ans]
	       _ans[i:i+len(t)] = t
	       for i in range(len(_ans)):
	           if _ans[i] == "X":
	               _ans[i] = 'a'
	       
	ans = ''.join(_ans)
	if f:
	    print(ans)
	else:
	    print("UNRESTORABLE")
	    
if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def compair(x,y):
    if len(x)!=len(y):
        return False

    for i in range(len(x)):
        if x[i]!=y[i] and x[i]!='?':
            return False

    return True

ss=input()

T=input()

flg=False
for i in reversed(range(len(ss)-1)):
    if compair(ss[i:(i+len(T) )],T):
        flg=True
        break


ss=list(ss)
for j in range(i):
    if ss[j]=='?':
        ss[j]='a'

for k in range(len(T)):
    ss[i+k]=T[k]


if flg:
    print("".join(ss))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
def compair(x,y):
    if len(x)!=len(y):
        return False

    for i in range(len(x)):
        if x[i]!=y[i] and x[i]!='?':
            return False

    return True

ss=input()

T=input()

flg=False
for i in reversed(range(len(ss)-1)):
    if compair(ss[i:(i+len(T) )],T):
        flg=True
        break


ss=list(ss)
for j in range(i):
    if ss[j]=='?':
        ss[j]='a'

if flg:
    print("".join(ss))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
def compair(x,y):
    print("comp",x,y)
    if len(x)!=len(y):
        return False

    for i in range(len(x)):
        if x[i]!=y[i] and x[i]!='?':
            return False

    return True

ss=input()

T=input()

flg=False
for i in reversed(range(len(ss)-1)):
    if compair(ss[i:(i+len(T) )],T):
        flg=True
        break


ss=list(ss)
for j in range(i):
    if ss[j]=='?':
        ss[j]='a'

Submission status: Runtime Error

Solution code:
def solve():
    S = raw_input()
    T = raw_input()
 
    if len(S) == len(T):
        for j in range(len(T)):
            if T[j] != S[j] and S[j] != "?":
                print "UNRESTORABLE"
                return 0
            else:
                pass
        print T
        return 0
 
    if len(S) < len(T):
        print "UNRESTORABLE"
        return 0
 
    for i in range(len(S) - len(T)):
        flag = True
        for j in range(len(T)):
            if T[j] != S[len(S)-1-i-len(T):len(S)-1-i][j] and S[len(S)-1-i-len(T):len(S)-1-i][j] != "?":
                flag = False
 
        if flag:
            S = S[0:len(S)-1-i-len(T)] + T + S[len(S)-1-i:len(S)+1]
            print S.replace("?", "a")
            return 0
 
    print "UNRESTORABLE"
    return 0
solve()
def solve():
    S = raw_input()
    T = raw_input()

    if len(S) == len(T):
        for j in range(len(T)):
            if T[j] != S[j] and S[j] != "?":
                print "UNRESTORABLE"
                return 0
            else:
                pass
        print T
        return 0

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

    for i in range(len(S) - len(T) + 1):
        flag = True
        for j in range(len(T)):
            if T[j] != S[len(S)-1-i-len(T):len(S)-1-i][j] and S[len(S)-1-i-len(T):len(S)-1-i][j] != "?":
                flag = False

        if flag:
            S = S[0:len(S)-1-i-len(T)] + T + S[len(S)-1-i:len(S)+1]
            print S.replace("?", "a")
            return 0

    print "UNRESTORABLE"
    return 0
solve()

Submission status: Runtime Error

Solution code:
import sys
 
S = sys.stdin.readline().strip()
T = sys.stdin.readline().strip()
 
if S.find(T) > -1:
    ans = S.replace("?", "a")
    print(ans)
else:
    index = -1
    for i in range(len(S)):
        b = True
        for j in range(len(T)):
            if (i + j > (len(S)-1)) or ((S[i + j] != "?") and (S[i + j] != T[j])):
                b = False
                break
        if b:
            index = i
    if index == -1:
        print("UNRESTORABLE")
        sys.exit()
    elif:
        ans = S[:index] + T + S[index + len(S):]
        ans = ans.replace("?", "a")
        print(ans)

Submission status: Runtime Error

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

S_p = input()
T = input()

def search_mask_text(S_p,T,T_p):
    for i in range(len(T_p)):
        if T_p[i] == '?':
            T_p_n = T_p[0:i] + T[i] + T_p[i+1:len(T_p)]
            if T_p_n != T:
                index_S = S_p.find(T_p_n)
                if index_S != -1:
                    return S_p[0:index_S] + T + S_p[index_S+len(T):len(S_p)]
                S_n = search_mask_text(S_p,T,T_p_n)
                if S_n != 'UNRESTORABLE':
                    return S_n
            #else:
            #    exit
    return 'UNRESTORABLE'


def search_ans_text(S_t,T):
    for i in range(len(S_t)):
        if S_t[i] == '?':
            S_n = S_t[0:i] + 'a' + S_t[i+1:len(S_t)]
    return S_n



T_p = '?' * len(T)
S_r = search_mask_text(S_p,T,T_p)
print(search_ans_text(S_r,T))

Submission status: Runtime Error

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

S_p = input()
T = input()

def search_mask_text(S_p,T,T_p):
    for i in range(len(T_p)):
        if T_p[i] == '?':
            T_p_n = T_p[0:i] + T[i] + T_p[i+1:len(T_p)]
            print(i)
            print(T_p_n)
            if T_p_n != T:
                index_S = S_p.find(T_p_n)
                if index_S != -1:
                    return S_p[0:index_S] + T + S_p[index_S+len(T):len(S_p)]
                S_n = search_mask_text(S_p,T,T_p_n)
                if S_n != 'UNRESTORABLE':
                    return S_n
            #else:
            #    exit
    return 'UNRESTORABLE'


def search_ans_text(S_t,T):
    for i in range(len(S_t)):
        if S_t[i] == '?':
            S_n = S_t[0:i] + 'a' + S_t[i+1:len(S_t)]
    return S_n



T_p = '?' * len(T)
S_r = search_mask_text(S_p,T,T_p)
print(S_r)
print(search_ans_text(S_r,T))

Submission status: Runtime Error

Solution code:
words = input()
key = input()
for i in range(len(words)):
    if words[i:i+len(key)] == key:
         words[i:i+len(key)] = key
         print(words.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
s_=input()
t=input()
ans=[]
n=len(s_)
m=len(t)
ind=0
dic={}
for i in range(n-m+1):
	con1=True
	for j in range(m):
		if s_[i+j] !=t[j] and s_[i+j]!='?':
			con1=False
			dic.clear()
			break
		else:
			dic[i+j]=t[j]
	
	if con1:
		lis=list(s_)
		if len(dic)!=0:
			for key in dic:
				lis[key]=dic[key]
			lis=''.join(lis)
		lis=lis.replace('?','a')
		ans.append(lis)
		dic.clear()
if con1:
	ans.sort()
	print(ans[0])
else:
	print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
def compair(x,y):
    print("comp",x,y)
    if len(x)!=len(y):
        return False

    for i in range(len(x)):
        if x[i]!=y[i] and x[i]!='?':
            return False

    return True

ss=input()

T=input()

flg=False
for i in reversed(range(len(ss)-1)):
    if compair(ss[i:(i+len(T) )],T):
        flg=True
        break


ss=list(ss)
for j in range(i):
    if ss[j]=='?':
        ss[j]='a'

if flg:
    print("".join(ss))
else:
    print("UNRESTORABLE")