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


def main():

    # Get Args
    args = _input_args()  # get arguments as an array from console/script parameters.

    # Call main Logic
    result = _main(args)

    # Output a result in a correct way.
    _output_result(result)


def _main(args):
    """Write Main Logic here for the contest.

    :param args: arguments
    :type args: list
    :return: result
    :rtype: depends on your logic.
    """
    # Extract arguments.
    Sd = args[0]
    T = args[1]

    # Write main logic here.
    result = _fit_partial_strings(Sd, T)

    # Return something.
    return result


def _fit_partial_strings(Sd, T):

    for i in range(len(Sd)):
        for j in range(len(T)):
            if Sd[i] == T[j]:
                try:
                # if len(Sd) - i >= len(T) - j:  # enough space available?
                    offset = i - j
                    Sd_list = list(Sd)  # convert str to list for operation
                    for k in range(len(T)):
                        Sd_list[k + offset] = T[k]  # patch T to Sd
                    Sd = "".join(Sd_list)  # convert list to str
                    Sd = Sd.replace('?', 'a')
                    return Sd
                except IndexError:
                    return 'UNRESTORABLE'

    return 'UNRESTORABLE'


def _input_args():
    # Comment-out appropriate pattern depends on subject.

    # arguments = sys.argv[1:]  # ptn1: get args from script parameters.
    # arguments = _input().split()  # ptn2: get args from 1 line console prompt with space separated.

    # for multi-line console input, use this.
    arguments = _get_args_from_multiple_lines(end_of_lines_char=[''], limit=2)

    # Cast elements If you need.
    # arguments = list(map(int, arguments))  # cast elements to int for example.

    return arguments  # This will be array.


def _input():
    # If Subject requires interactive input, use this and patch mock in unittest.
    return input()  # Change if necessary.


def _get_args_from_multiple_lines(end_of_lines_char=[''], limit=2):
    """Get arguments from multiple lines standard input.

    :param end_of_lines_char: Strings that indicate the end of lines.
    :type end_of_lines_char: list of str
    :param limit: If a number of the input line are certain, you can use this param to close prompt immediately.
    :type limit: int
    :return: args
    :rtype list of str
    """
    args = []
    for i in range(limit):
        try:
            arg = _input()
            if arg in end_of_lines_char:
                break
            args.append(arg)
        except EOFError:  # Supports EOF Style. (Very Rare case)
            break
    return args


def _output_result(result):
    # Comment-out appropriate output pattern depends on subject.

    # sys.stdout.write(result)  # No Line Feed, and an result must be string (not useful). for single value output.
    # print(result)  # The result will cast to strings. Line feed will be appended to the end. for single value output.
    # print(result, end='')  # Same as above except Line Feed won't be appended. for single value output.
    # print(','.join(map(str, result)))  # Print array elements as comma separated strings. for multi-value.
    print('{}'.format(str(result)))  # Same as above, but more versatile.


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys


def main():

    # Get Args
    args = _input_args()  # get arguments as an array from console/script parameters.

    # Call main Logic
    result = _main(args)

    # Output a result in a correct way.
    _output_result(result)


def _main(args):
    """Write Main Logic here for the contest.

    :param args: arguments
    :type args: list
    :return: result
    :rtype: depends on your logic.
    """
    # Extract arguments.
    Sd = args[0]
    T = args[1]

    # Write main logic here.
    result = _fit_partial_strings(Sd, T)

    # Return something.
    return result


def _fit_partial_strings(Sd, T):

    for i in range(len(Sd)):
        for j in range(len(T)):
            if Sd[i] == T[j]:
                if len(Sd) - i >= len(T) - j:  # enough space available?
                    offset = i - j
                    Sd_list = list(Sd)  # convert str to list for operation
                    for k in range(len(T)):
                        Sd_list[k + offset] = T[k]  # patch T to Sd
                    Sd = "".join(Sd_list)  # convert list to str
                    Sd = Sd.replace('?', 'a')
                    return Sd
                else:
                    return 'UNRESTORABLE'

    return 'UNRESTORABLE'


def _input_args():
    # Comment-out appropriate pattern depends on subject.

    # arguments = sys.argv[1:]  # ptn1: get args from script parameters.
    # arguments = _input().split()  # ptn2: get args from 1 line console prompt with space separated.

    # for multi-line console input, use this.
    arguments = _get_args_from_multiple_lines(end_of_lines_char=[''], limit=2)

    # Cast elements If you need.
    # arguments = list(map(int, arguments))  # cast elements to int for example.

    return arguments  # This will be array.


def _input():
    # If Subject requires interactive input, use this and patch mock in unittest.
    return input()  # Change if necessary.


def _get_args_from_multiple_lines(end_of_lines_char=[''], limit=2):
    """Get arguments from multiple lines standard input.

    :param end_of_lines_char: Strings that indicate the end of lines.
    :type end_of_lines_char: list of str
    :param limit: If a number of the input line are certain, you can use this param to close prompt immediately.
    :type limit: int
    :return: args
    :rtype list of str
    """
    args = []
    for i in range(limit):
        try:
            arg = _input()
            if arg in end_of_lines_char:
                break
            args.append(arg)
        except EOFError:  # Supports EOF Style. (Very Rare case)
            break
    return args


def _output_result(result):
    # Comment-out appropriate output pattern depends on subject.

    # sys.stdout.write(result)  # No Line Feed, and an result must be string (not useful). for single value output.
    # print(result)  # The result will cast to strings. Line feed will be appended to the end. for single value output.
    # print(result, end='')  # Same as above except Line Feed won't be appended. for single value output.
    # print(','.join(map(str, result)))  # Print array elements as comma separated strings. for multi-value.
    print('{}'.format(str(result)))  # Same as above, but more versatile.


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys


def main():

    # Get Args
    args = _input_args()  # get arguments as an array from console/script parameters.

    # Call main Logic
    result = _main(args)

    # Output a result in a correct way.
    _output_result(result)


def _main(args):
    """Write Main Logic here for the contest.

    :param args: arguments
    :type args: list
    :return: result
    :rtype: depends on your logic.
    """
    # Extract arguments.
    Sd = args[0]
    T = args[1]

    # Write main logic here.
    result = _fit_partial_strings(Sd, T)

    # Return something.
    return result


def _fit_partial_strings(Sd, T):

    found = False
    for i in range(len(Sd)):
        for j in range(len(T)):
            if Sd[i] == T[j]:
                if len(Sd) - i >= len(T) - j:  # enough space available?
                    offset = i - j
                    Sd_list = list(Sd)  # convert str to list for operation
                    for k in range(len(T)):
                        Sd_list[k + offset] = T[k]  # patch T to Sd
                    Sd = "".join(Sd_list)  # convert list to str
                    found = True
                else:
                    return 'UNRESTORABLE'

    if found == True:
        Sd = Sd.replace('?', 'a')
        return Sd
    else:
        return 'UNRESTORABLE'


def _input_args():
    # Comment-out appropriate pattern depends on subject.

    # arguments = sys.argv[1:]  # ptn1: get args from script parameters.
    # arguments = _input().split()  # ptn2: get args from 1 line console prompt with space separated.

    # for multi-line console input, use this.
    arguments = _get_args_from_multiple_lines(end_of_lines_char=[''], limit=2)

    # Cast elements If you need.
    # arguments = list(map(int, arguments))  # cast elements to int for example.

    return arguments  # This will be array.


def _input():
    # If Subject requires interactive input, use this and patch mock in unittest.
    return input()  # Change if necessary.


def _get_args_from_multiple_lines(end_of_lines_char=[''], limit=2):
    """Get arguments from multiple lines standard input.

    :param end_of_lines_char: Strings that indicate the end of lines.
    :type end_of_lines_char: list of str
    :param limit: If a number of the input line are certain, you can use this param to close prompt immediately.
    :type limit: int
    :return: args
    :rtype list of str
    """
    args = []
    for i in range(limit):
        try:
            arg = _input()
            if arg in end_of_lines_char:
                break
            args.append(arg)
        except EOFError:  # Supports EOF Style. (Very Rare case)
            break
    return args


def _output_result(result):
    # Comment-out appropriate output pattern depends on subject.

    # sys.stdout.write(result)  # No Line Feed, and an result must be string (not useful). for single value output.
    # print(result)  # The result will cast to strings. Line feed will be appended to the end. for single value output.
    # print(result, end='')  # Same as above except Line Feed won't be appended. for single value output.
    # print(','.join(map(str, result)))  # Print array elements as comma separated strings. for multi-value.
    print('{}'.format(str(result)))  # Same as above, but more versatile.


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys


def main():

    # Get Args
    args = _input_args()  # get arguments as an array from console/script parameters.

    # Call main Logic
    result = _main(args)

    # Output a result in a correct way.
    _output_result(result)


def _main(args):
    """Write Main Logic here for the contest.

    :param args: arguments
    :type args: list
    :return: result
    :rtype: depends on your logic.
    """
    # Extract arguments.
    Sd = args[0]
    T = args[1]

    # Write main logic here.
    result = _fit_partial_strings(Sd, T)

    # Return something.
    return result


def _fit_partial_strings(Sd, T):

    for i in range(len(Sd)):
        for j in range(len(T)):
            if Sd[i] == T[j]:
                if len(Sd) - i >= len(T) - j: # enough space available?
                    offset = i - j
                    Sd_list = list(Sd)  # convert str to list for operation
                    for k in range(len(T)):
                        Sd_list[k + offset] = T[k]  # patch T to Sd
                    Sd = "".join(Sd_list)  # convert list to str
                else:
                    return 'UNRESTORABLE'


    Sd = Sd.replace('?', 'a')
    return Sd

    return 'UNRESTORABLE'


def _input_args():
    # Comment-out appropriate pattern depends on subject.

    # arguments = sys.argv[1:]  # ptn1: get args from script parameters.
    # arguments = _input().split()  # ptn2: get args from 1 line console prompt with space separated.

    # for multi-line console input, use this.
    arguments = _get_args_from_multiple_lines(end_of_lines_char=[''], limit=2)

    # Cast elements If you need.
    # arguments = list(map(int, arguments))  # cast elements to int for example.

    return arguments  # This will be array.


def _input():
    # If Subject requires interactive input, use this and patch mock in unittest.
    return input()  # Change if necessary.


def _get_args_from_multiple_lines(end_of_lines_char=[''], limit=2):
    """Get arguments from multiple lines standard input.

    :param end_of_lines_char: Strings that indicate the end of lines.
    :type end_of_lines_char: list of str
    :param limit: If a number of the input line are certain, you can use this param to close prompt immediately.
    :type limit: int
    :return: args
    :rtype list of str
    """
    args = []
    for i in range(limit):
        try:
            arg = _input()
            if arg in end_of_lines_char:
                break
            args.append(arg)
        except EOFError:  # Supports EOF Style. (Very Rare case)
            break
    return args


def _output_result(result):
    # Comment-out appropriate output pattern depends on subject.

    # sys.stdout.write(result)  # No Line Feed, and an result must be string (not useful). for single value output.
    # print(result)  # The result will cast to strings. Line feed will be appended to the end. for single value output.
    # print(result, end='')  # Same as above except Line Feed won't be appended. for single value output.
    # print(','.join(map(str, result)))  # Print array elements as comma separated strings. for multi-value.
    print('{}'.format(str(result)))  # Same as above, but more versatile.


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys


def main():

    # Get Args
    args = _input_args()  # get arguments as an array from console/script parameters.

    # Call main Logic
    result = _main(args)

    # Output a result in a correct way.
    _output_result(result)


def _main(args):
    """Write Main Logic here for the contest.

    :param args: arguments
    :type args: list
    :return: result
    :rtype: depends on your logic.
    """
    # Extract arguments.
    Sd = args[0]
    T = args[1]

    # Write main logic here.
    result = _fit_partial_strings(Sd, T)

    # Return something.
    return result


def _fit_partial_strings(Sd, T):

    for i in range(len(Sd)):
        for j in range(len(T)):
            if Sd[i] == T[j]:
                if len(Sd) - i >= len(T) - j: # enough space available?
                    offset = i - j
                    Sd_list = list(Sd)  # convert str to list for operation
                    for k in range(len(T)):
                        Sd_list[k + offset] = T[k]  # patch T to Sd
                    Sd = "".join(Sd_list) # convert list to str
                else:
                    return 'UNRESTORABLE'

    if Sd.count('?') == 1:
        Sd = Sd.replace('?', 'a')
        return Sd

    return 'UNRESTORABLE'


def _input_args():
    # Comment-out appropriate pattern depends on subject.

    # arguments = sys.argv[1:]  # ptn1: get args from script parameters.
    # arguments = _input().split()  # ptn2: get args from 1 line console prompt with space separated.

    # for multi-line console input, use this.
    arguments = _get_args_from_multiple_lines(end_of_lines_char=[''], limit=2)

    # Cast elements If you need.
    # arguments = list(map(int, arguments))  # cast elements to int for example.

    return arguments  # This will be array.


def _input():
    # If Subject requires interactive input, use this and patch mock in unittest.
    return input()  # Change if necessary.


def _get_args_from_multiple_lines(end_of_lines_char=[''], limit=2):
    """Get arguments from multiple lines standard input.

    :param end_of_lines_char: Strings that indicate the end of lines.
    :type end_of_lines_char: list of str
    :param limit: If a number of the input line are certain, you can use this param to close prompt immediately.
    :type limit: int
    :return: args
    :rtype list of str
    """
    args = []
    for i in range(limit):
        try:
            arg = _input()
            if arg in end_of_lines_char:
                break
            args.append(arg)
        except EOFError:  # Supports EOF Style. (Very Rare case)
            break
    return args


def _output_result(result):
    # Comment-out appropriate output pattern depends on subject.

    # sys.stdout.write(result)  # No Line Feed, and an result must be string (not useful). for single value output.
    # print(result)  # The result will cast to strings. Line feed will be appended to the end. for single value output.
    # print(result, end='')  # Same as above except Line Feed won't be appended. for single value output.
    # print(','.join(map(str, result)))  # Print array elements as comma separated strings. for multi-value.
    print('{}'.format(str(result)))  # Same as above, but more versatile.


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
s=input()
T=input()
a=[]
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] :
      break
  else:
    a.append(s[:i-1].replace('?', 'a')+T+s[i+len(T):].replace('?', 'a'))

if a==[]:
  print("UNRESTORABLE")
else:
  a.sort()
  print(a[0])

Submission status: Wrong Answer

Solution code:
import sys
s=input()
T=input()
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] :
      break
  else:
    s=s[:i-1]+T+s[i+len(T):]
    s = s.replace('?', 'a')
    print(s)
    sys.exit()
else: print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
#!/Library/Frameworks/Python.framework/Versions/3.5/bin/python3

sd = input()
t = input()

index = 0
done = 0
repmin = float('inf')
for i in range(len(sd) - len(t) + 1):
    ok = 1
    rep = 0
    for j in range(len(t)):
        if sd[i + j] != '?':
            if sd[i + j] != t[j]:
                ok = 0
                break
        else:
            rep += 1
    if ok == 1:
        done = 1
        if rep < repmin:
            index = i
            repmin = rep

if done == 1:
    s = sd.replace('?', 'a')
    print(s[0:index], end = '')
    print(t, end = '')
    print(s[index + len(t):len(s)])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S=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(a)

Submission status: Wrong Answer

Solution code:
S=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:
    print(a)

Submission status: Wrong Answer

Solution code:
a = list(raw_input())
b = list(raw_input())
sign = False
con = False
for a_bi in xrange(len(a) - len(b) + 1):
	#TRY TO RESTORE B AT EVERY BYTE OF A
	#a_bi = byte's index in a
	for b_bi in xrange(len(b)):
		if a[a_bi + b_bi] == '?':
			continue
		if a[a_bi + b_bi] != b[b_bi]:
			con = True
			break
	if con:
		con = False
		continue
	#MEANING THAT THIS IS RESTORABLE
	a[a_bi:a_bi + len(b)] = b
	a = ''.join(a)
	a = a.replace('?', 'a')
	sign = True
	print a
	break
if not sign:
	print 'UNRESTORABLE'

Submission status: Wrong Answer

Solution code:
# coding: utf-8
S=input()
T=input()
slen=len(S)
tlen=len(T)
flg=False
#リスト化
slist=list(S)
tlist=list(T)
for i in range(slen-tlen+1):
    cnt=0
    for j in range(tlen):
        if slist[i+j]==tlist[j] or slist[i+j]=='?':
            cnt=cnt+1
            if cnt==tlen:
                for k in range(tlen):
                    slist[i+k]=tlist[k]
                flg=True
        else:
            break
for i in range(slen):
    if slist[i]=='?':
        slist[i]='a'
if flg==True:
    #リストを文字列にもどす
    S="".join(slist)
    print(S)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
S=input()
T=input()
slen=len(S)
tlen=len(T)
flg=False
#リスト化
slist=list(S)
tlist=list(T)
for i in range(slen-tlen+1):
    cnt=0
    for j in range(tlen):
        if slist[i+j]==tlist[j] or slist[i+j]=='?':
            cnt=cnt+1
            if cnt==tlen:
                for k in range(tlen):
                    slist[i+k]=tlist[k]
                flg=True
        else:
            break
for i in range(slen):
    if slist[i]=="?":
        slist[i]="a"
if flg==True:
    #リストを文字列にもどす
    S="".join(slist)
    print(S)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
# coding: utf-8

S=input()
T=input()

#リスト化
slist=list(S)
tlist=list(T)

slen=len(S)
tlen=len(T)

flg=False

for i in range(slen-tlen+1):
    cnt=0
    for j in range(tlen):
        if slist[i+j]==tlist[j] or slist[i+j]=='?':
            cnt=cnt+1
            if cnt==tlen:
                for k in range(tlen):
                    slist[i+k]=tlist[k]
                flg=True
        else:
            break
for i in range(slen):
    if slist[i]=="?":
        slist[i]="a"

#ひょうじ
if flg==True:
    #リストを文字列にもどす
    S="".join(slist)
    print(S)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def calc(val, val2):
    ret = 0
    val_back = list(val)
    val2_back = list(val2)
    for i in reversed(range(0, len(val))):
        if len(val2) == 0:
            ret = 0
            break
        elif i < len(val2):
            ret = -1
            break
        else:
            for j in reversed(range(0, len(val2))):
                if val[i] == "?" or val[i] == val2[j]:
                    val[i] = val2[j]
                    i -= 1
                    val2.pop()
                else:
                    val = list(val_back)
                    val2 = list(val2_back)
                    break
    return (ret, val)


val = list(input())
val2 = list(input())

ret = calc(val, val2)

if ret[0] == -1:
    print("UNRESTORABLE")
else:
    val = "".join(ret[1])
    print(val.replace("?", "a"))

Submission status: Wrong Answer

Solution code:
if __name__ == '__main__':
    S = list(input())
    T = list(input())

    num = -1
    for i in range(len(S) - len(T)):
        flg = True
        for j in range(1, len(T) + 1):
            if S[-(i + j)] == "?":
                continue
            if S[-(i + j)] == T[-j]:
                continue
            flg = False
            break

        if flg:
            num = i
            break

    if num == -1:
        print("UNRESTORABLE")
    else:
        start = len(S) - (len(T) + num)
        end = len(S) - num
        S[start:end] = T
        mojiretu = "".join(S)
        ans = mojiretu.replace("?", "a")
        print(ans)

Submission status: Wrong Answer

Solution code:
import re

S = input()
T = input()
lenT = len(T)
can = []
for it in re.finditer(T[0], S):
    a = it.span()[0]
    tmp = S[a+1: a+lenT]
    if len(tmp) == len(T) - 1 and all("?" == h for h in list(tmp)):
        tmp = S[:a] + T + S[a+lenT:]
        can.append(tmp.replace("?", "a"))
print("UNRESTORABLE" if len(can) == 0 else can[-1])

Submission status: Wrong Answer

Solution code:
import re

S = input()
T = input()
lenT = len(T)
can = []
for it in re.finditer(T[0], S):
    a = it.span()[0]
    tmp = S[a+1: a+lenT]
    if all("?" == h for h in list(tmp)):
        tmp = S[:a] + T + S[a+lenT:]
        can.append(tmp.replace("?", "a"))
print("UNRESTORABLE" if len(can) == 0 else can[-1])

Submission status: Wrong Answer

Solution code:
import re

S = input()
T = input()
lenT = len(T)
for it in re.finditer(T[0], S):
    a = it.span()[0]
    tmp = S[a+1: a+lenT]
    if all("?" == h for h in list(tmp)):
        tmp = S[:a] + T + S[a+lenT:]
        print(tmp.replace("?", "a"))
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
sd, t = input(), input()
# for i in range(len(t)-len(sd)+1)において,
# :sd[i]==t[i] or sd=='?' ならばそのsdの箇所を実際にtで書き換え、かつ残りの?をaに書き換えたものを結果として残す。結果は昇順なので比較しながら一つだけ残す
# :それ以外ならばとくになにもしない
# 結果が空白ならばUNRESTORABLEとする
# オーダーがよくわからんけど余裕だろう
ans = ''
for i in  range(len(sd) - len(t)+1):
    target = sd[i:i+len(t)]
    print("target= {}".format(target))
    count = 0
    for j in range(len(t)):
        if t[j]==target[j] or target[j]=='?':
            count+=1
        else:
            break
    if count==len(t):
        # 候補として追加。残りの?をaに変える
        tmp = sd[:i]+t+sd[len(t)+i:]
        print("tmp= {}".format(tmp))
        if ans=='':
            ans = ''.join(['a' if i=='?' else i for i in tmp])
        else:
            ans = min(ans, ''.join(['a' if i=='?' else i for i in tmp]))
print('UNRESTORABLE' if ans=='' else ans)

Submission status: Wrong Answer

Solution code:
def calc(val, val2):
    ret = 0
    val_back = list(val)
    val2_back = list(val2)
    for i in reversed(range(0, len(val))):
        if len(val2) == 0:
            ret = 0
            break
        elif i < len(val2):
            ret = -1
            break
        else:
            for j in reversed(range(0, len(val2))):
                if val[i] == "?" or val[i] == val2[j]:
                    val[i] = val2[j]
                    i -= 1
                    val2.pop()
                else:
                    val = list(val_back)
                    val2 = list(val2_back)
                    break
    return ret


val = list(input())
val2 = list(input())

ret = calc(val, val2)

if ret == -1:
    print("UNRESTORABLE")
else:
    ret = "".join(val)
    print(ret.replace("?", "a"))

Submission status: Wrong Answer

Solution code:
S_prime = input()
T = input()
ans = 'z'
matched = False

if len(S_prime) < len(T):
    print('UNRESTORABLE')

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] != '?':
            break

    if k == len(T) - 1 and (S_prime[i + k] == T[k] or S_prime[i + k] == '?'):
        tmp = (S_prime[0:i] + T + S_prime[i + len(T):]).replace('?', 'a')
        if ans > tmp:
            ans = tmp
        matched = True

if matched:
    print(ans)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S_prime = input()
T = input()
ans = 'z'
matched = False

if len(S_prime) < len(T):
    print(ans)

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] != '?':
            break

    if k == len(T) - 1 and (S_prime[i + k] == T[k] or S_prime[i + k] == '?'):
        tmp = (S_prime[0:i] + T + S_prime[i + len(T):]).replace('?', 'a')
        if ans > tmp:
            ans = tmp
        matched = True

if matched:
    print(ans)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S_prime = input()
T = input()
ans = 'zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz'
matched = False

if len(S_prime) < len(T):
    print(ans)

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] != '?':
            break

    if k == len(T) - 1 and (S_prime[i + k] == T[k] or S_prime[i + k] == '?'):
        if ans > S_prime[0:i] + T + S_prime[i + len(T):]:
            ans = S_prime[0:i] + T + S_prime[i + len(T):]
        matched = True

if matched:
    print(ans.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

if len(S_prime) < len(T):
    print(replaced)

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] != '?':
            break

    if k == len(T) - 1 and (S_prime[i + k] == T[k] or S_prime[i + k] == '?'):
        replaced = S_prime[0:i] + T + S_prime[i + len(T):]
        break

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

Submission status: Wrong Answer

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

if len(S_prime) < len(T):
    print(replaced)

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

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

contain = False
for i in range(len(S)-len(T)+1):
	#check it out
	contain = True
	for j in range(len(T)):
		if(S[i+j] != T[j] and S[i+j] != '?'):
			contain = False
			break
	if contain :
		ans = S[0:i] + T + S[i+len(T):]
		print(ans.replace('?','a'))
		break
		
if not contain: print("UNRESTORABLE")

Submission status: Wrong Answer

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

contain = False
for i in range(len(S)-len(T)+1):
	#check it out
	contain = True
	for j in range(len(T)):
		if(S[i+j] != T[j] and S[j+i] != '?'):
			contain = False
			break
	if contain :
		ans = S[0:i] + T + S[i+len(T):]
		ans = ans.replace("?", "a")
		print(ans)
		break
		
if not contain: print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = raw_input()
t = raw_input()
sl = len(s)
tl = len(t)
p = -1
for i in range(0, sl-tl+1):
    for j in range(0, tl):
        if s[i+j] != '?' and s[i+j] != t[j]:
            break
    else:
        p = i
        break
if p == -1:
    print 'UNRESTORABLE'
else:
    u = s[0:p] + t + s[p+tl:]
    print u.replace('?', 'a')

Submission status: Wrong Answer

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

j=len(t)-1

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