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:
sd = raw_input()
t = raw_input()
lnsd = len(sd)
lnt = len(t)
sa = 0
tru = None
for i in range(lnsd - lnt + 1):
    for i2 in range(lnt -1):
        a = sd[(0+sa):(lnt+sa)]
        if a[i2] != t[i2] and a[i2] != "?":
            break
        if i2 == lnsd -lnt + 1:
            tru= i
    sa = sa+1
if tru == None:
    print("UNRESTORABLE")
    exit()
sd = list(sd)
for i in range(lnt):
    sd[tru+i]=t[i]
strn ="".join(sd)
print(strn.replace("?", "a"))

Submission status: Wrong Answer

Solution code:
sd = raw_input()
t = raw_input()
lnsd = len(sd)
lnt = len(t)
sa = 0
tru = None
for i in range(lnsd - lnt + 1):
    for i2 in range(lnt -1):
        a = sd[(0+sa):(lnt+sa)]
        if a[i2] != t[i2] and a[i2] != "?":
            break
        if i2 == lnsd -lnt:
            tru= i
    sa = sa+1
if tru == None:
    print("UNRESTORABLE")
    exit()
sd = list(sd)
for i in range(lnt):
    sd[tru+i]=t[i]
strn ="".join(sd)
print(strn.replace("?", "a"))

Submission status: Wrong Answer

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

flag = False
t_len = len(t)
start = 0
num = 0

for i in range(len(s)):
  num = i  
  if flag == True: break
  j = 0
  cnt = 0
  while j < t_len and i < len(s):
    if s[i] == t[j] or s[i] == '?':
      cnt += 1
      i += 1
      j += 1
    else:
      break

    if(t_len == cnt):
      start = num
      flag = True
      #print(num)
      break


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

s[num -1 :num + len(t) -1] = t

st = ''
for s_l in s:
  st += s_l


if flag == False:
  print('UNRESTORABLE')
else:
  print(st)

Submission status: Wrong Answer

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

flag = 0
count = 0
new = ''
l = []
for i in range(len(s)):
    if s[i] == '?' or s[i] in t:
        if count == 0:
            start = i
        count += 1
    else:
        if count >= len(t):
            print(count - len(t) + 1)
            for j in range(count - len(t) + 1):
                check = 0
                for k in range(len(t)):
                    if s[start + j + k] != t[k] and s[start + j + k] != '?':
                        check = 1
                        break
                if check == 0:
                    new = s[:start + j] + t + s[start + len(t) + j:]
                    l.append(new)
                    flag = 1
                    break
        count = 0

if count >= len(t):
    for j in range(count-len(t)+1):
        check = 0
        for k in range(len(t)):
            if s[start+j+k] != t[k] and s[start+j+k] != '?':
                check = 1
                break
        if check == 0:
            new = s[:start+j] + t + s[start+len(t)+j:]
            l.append(new)
            flag = 1

if flag == 0:
    print('UNRESTORABLE')
else:
    ans = []
    for n in l:
        for i in range(len(n)):
            if n[i] == '?':
                n = n[:i] + 'a' + n[i+1:]
        ans.append(n)
    print(sorted(ans)[0])

Submission status: Wrong Answer

Solution code:
#!/usr/bin/python
# -*- coding: utf-8 -*-


def checker(L1, L2):
    N = len(L1)
    for i in range(N):
        if L1[i] == L2[i] or L1[i] == "?":
            pass
        else:
            return False

    return True


def solve():
    while 1:
        try:
            S_prime = list(input())
            T = input()
            if S_prime.count("?") == 0:
                print("".join(S_prime))
                raise EndLoop

            for i in range(len(S_prime) - len(T) + 1):
                tmp_str = list(S_prime[i:len(T) + i])
                if checker(tmp_str, T):
                    if i + len(T) == len(S_prime):
                        S = "".join(S_prime[:i]) + "".join(T)
                        print(S.replace("?", "a"))
                        raise EndLoop
                    else:
                        S = "".join(S_prime[:i]) + "".join(T) + "".join(S_prime[i + len(T):])
                        print(S.replace("?", "a"))
                        raise EndLoop

            print("UNRESTORABLE")
            break
        except:
            break


solve()

Submission status: Wrong Answer

Solution code:
S_raw = input()
T_raw = input()

S = list(S_raw)
T = list(T_raw)

i = 0
j = 0

lt = len(T)
ls = len(S)

while True:
	if j == ls or i == lt:
		if not i == lt:
			print("UNRESTORABLE")
			exit(0)
		else:
			break

	if T[i] == S[j]:
		i += 1
		j += 1
	elif S[j] == '?':
		i += 1
		j += 1
	else:
		i = 0
		j += 1

for i,c in zip(range(j-lt,j),T):
	S[i] = c

for i in range(ls):
	if S[i] == '?':
		print("a",end="")
	else:
		print(S[i],end="")

print()

Submission status: Wrong Answer

Solution code:
#http://abc076.contest.atcoder.jp/
# -*- coding: utf-8 -*-
from collections import Counter
from os import sys

s = list(input())
t = input()

def error():
    print('UNRESTORABLE')
    sys.exit()


hatena_count = Counter(s)['?']
if hatena_count < len(t): error()

kouho = []
onlyA = []
t_in_s = False
for i,char in enumerate(s):
    if char == t[0] or char == '?':
        result = True
        hatena_nakami = []
        issho = []
        for j,t_char in enumerate(t):
            try:
                jouken = t_char == s[i+j] or s[i+j] == '?'
                if not jouken:
                    result = False
                    break
                if s[i+j] == '?' and t_char == 'a':
                    hatena_nakami.append(True)
                elif t_char == s[i+j]:
                    hatena_nakami.append(True)
                else:
                    hatena_nakami.append(False)
                if t_char == s[i+j]:
                    issho.append(True)
                else:
                    issho.append(False)
            except IndexError:
                result = False
                break

        if result == True:
            kouho.append(i)
            if all(hatena_nakami):
                onlyA.append(True)
            else:
                onlyA.append(False)
            if all(issho):
                t_in_s = True
                break

if t_in_s == True:
    for i,char in enumerate(s[:]):
        if char == '?':
            s[i] = 'a'

    result = ''
    for char in s:
        result += char

    print(result)
    sys.exit()



if len(kouho) == 0: error()

kouho2 = -1
for i,v in enumerate(onlyA):
    if v == True:
        kouho2 = i
if kouho2 == -1:
    kouho2 = max(kouho)

for i in range(len(t)):
    s[kouho2+i] = t[i]

for i,char in enumerate(s[:]):
    if char == '?':
        s[i] = 'a'

result = ''
for char in s:
    result += char

print(result)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
if __name__ == '__main__':
    SS = raw_input()
    T = raw_input()
    S = ""
    start_index = -1
    end_index = -1
    t_index = 0
    state = 0
    if len(T) > len(SS):
        S = 'UNRESTORABLE'
    else:
        for index in range(len(SS) - len(T), 0, -1):
            for current_index in range(index, index + len(T)):
                if SS[current_index] == '?' or SS[current_index] == T[t_index]:
                    t_index += 1
                    if t_index == len(T):
                        start_index = index
                        end_index = current_index
                        state = 1
                        break
                else:
                    t_index = 0
                    break
            if state == 1:
                break
        if start_index == -1:
            S = 'UNRESTORABLE'
        else:
            for index, s in enumerate(SS):
                if index >= start_index and index <= end_index:
                    S += T[index - start_index]
                elif s == '?':
                    S += 'a'
                else:
                    S += s
    print S

Submission status: Wrong Answer

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

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

for i in reversed(range(len(s) - len(t)+1)):
    if eq(s[i:i+len(t)], t[:]):
        s[i:i + len(t)] = t[:]
        ans = ''.join(s)
        print(ans.replace('?', 'b'))
        quit()
print('UNRESTORABLE')

Submission status: Wrong Answer

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

flag = False
t_len = len(t)
start = 0
num = 0

for i in range(len(s)):
  num = i  
  if flag == True: break
  j = 0
  cnt = 0
  while j < t_len and i < len(s):
    if s[i] == t[j] or s[i] == '?':
      cnt += 1
      i += 1
      j += 1
    else:
      break

    if(t_len == cnt):
      start = num
      flag = True
      #print(num)
      break


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

s[num -1 :num + len(t)] = t

st = ''
for s_l in s:
  st += s_l


if flag == False:
  print('UNRESTORABLE')
else:
  print(st)

Submission status: Wrong Answer

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()
    ans = S[:index] + T + S[index + len(S):]
    ans = ans.replace("?", "a")
    print(ans)

Submission status: Wrong Answer

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



def A(S):
    for i in range(len(S)):
        #print(i)
        if len(T)+i>len(S):
            return 1000
        if check(i):
            return (i)
    return 1000

def check(i):
    j=i
    for A in T:
        if not(A==S[j] or S[j]=='?'):
            return False
        else: j+=1
    return True


i=A(S)

if i==1000:
    print('UNRESTORABLE')
    
else:
    for j in range (len(T)):
        S[i+j]=T[j]
    for k in range(len(S)):
        if S[k]=='?':
            S[k]='a'
    print(''.join(S))

Submission status: Wrong Answer

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

a = None
q = 0
qt = 0
j = 0
for i,s in enumerate(S_):
    if s == '?': 
        qt += 1
        if i == len(S_) - 1:
            if qt > q:
                q = qt
                j = i
        continue
    if qt > q:
        q = qt
        j = i
    qt = 0
    if T.find(s) != -1 and len(S_[i:]) >= len(T):
        b = set(S_[i:i+len(T)]) - set(['?']) 
        c = set(T)
        if len(b-c) == 0:
            a = i
if a == None and q < len(T):
    print('UNRESTORABLE')
else:
    if q >= len(T):
        a = j - q + 1
    S_ = S_[:a] + T + S_[i+len(T):]
    print(S_.replace('?','a'))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
if __name__ == '__main__':
    SS = raw_input()
    T = raw_input()
    S = ""
    start_index = -1
    end_index = -1
    t_index = 0
    state = 0
    for index in range(len(SS) - len(T), 0, -1):
        for current_index in range(index, index + len(T)):
            if SS[current_index] == '?' or SS[current_index] == T[t_index]:
                t_index += 1
                if t_index == len(T):
                    start_index = index
                    end_index = current_index
                    state = 1
                    break
            else:
                t_index = 0
                break
        if state == 1:
            break
    if start_index == -1:
        S ='UNRESTORABLE'
    else:
        for index, s in enumerate(SS):
            if index >= start_index and index <= end_index:
                S += T[index - start_index]
            elif s == '?':
                S += 'a'
            else:
                S += s
    print S

Submission status: Wrong Answer

Solution code:
Sd_ = input()
T_ = input()
Sd = []
T = []
S = []
for i in range(len(Sd_)):
    Sd.append(Sd_[i])
for i in range(len(T_)):
    T.append(T_[i])

def check(s,t,n):
    for i in range(len(t)):
        if s[n+i] is not t[i] and s[n+i] is not '?':
            return False
    return True

for m in range(len(Sd)-len(T),0,-1):
    if check(Sd[:],T[:],m):
        for j in range(len(T)):
            Sd[m+j] = T[j]
        for a in range(len(Sd)):
            if Sd[a] is '?':
                S.append('a')
            else:
                S.append(Sd[a])
        print(''.join(S))
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

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:
	            ans += t
	            f = True
	        else:
	            ans += 'a'
	    else:
	        ans += _s[i]
	    
	    if len(ans) == len(_s):
	        break
	    elif f:
	        d = len(_s)-len(ans)
	        for i in range(d):
	            ans += "a"
	        break
	        
	if f:
	    print(ans)
	else:
	    print("UNRESTORABLE")
	    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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)):
        # print S[i:len(T)+i]
        flag = True
        for j in range(len(T)):
            if T[j] == S[i:len(T)+i][j] or S[i:len(T)+i][j] == "?":
                pass
            else:
                flag = False
        if flag:
            S = S[0:i] + T + S[len(T)+i:len(S)]
            print S.replace("?", "a")
            # print S.replace(S[i:len(T)+i], T).replace("?", "a")
            return 0

    print "UNRESTORABLE"

solve()

Submission status: Wrong Answer

Solution code:
#http://abc076.contest.atcoder.jp/
# -*- coding: utf-8 -*-
from collections import Counter
from os import sys

s = list(input())
t = input()

def error():
    print('UNRESTORABLE')
    sys.exit()


hatena_count = Counter(s)['?']
if hatena_count < len(t): error()

kouho = []
onlyA = []
for i,char in enumerate(s):
    if char == t[0] or char == '?':
        result = True
        hatena_nakami = []
        for j,t_char in enumerate(t):
            try:
                jouken = t_char == s[i+j] or s[i+j] == '?'
                if not jouken:
                    result = False
                    break
                if s[i+j] == '?' and t_char == 'a':
                    hatena_nakami.append(True)
                elif t_char == s[i+j]:
                    hatena_nakami.append(True)
                else:
                    hatena_nakami.append(False)
            except IndexError:
                result = False
                break

        if result == True:
            kouho.append(i)
            if all(hatena_nakami):
                onlyA.append(True)
            else:
                onlyA.append(False)

if len(kouho) == 0: error()

kouho2 = -1
for i,v in enumerate(onlyA):
    if v == True:
        kouho2 = i
if kouho2 == -1:
    kouho2 = max(kouho)

for i in range(len(t)):
    s[kouho2+i] = t[i]

for i,char in enumerate(s[:]):
    if char == '?':
        s[i] = 'a'

result = ''
for char in s:
    result += char

print(result)

Submission status: Wrong Answer

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

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

for i in range(len(s) - len(t)+1):
    if eq(s[i:i+len(t)], t[:]):
        s[i:i + len(t)] = t[:]
        ans = ''.join(s)
        print(ans.replace('?', 'a'))
        quit()
print('UNRESTORABLE')

Submission status: Wrong Answer

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

    for i in range(len(S) - len(T)):
        # print S[i:len(T)+i]
        flag = True
        for j in range(len(T)):
            if T[j] == S[i:len(T)+i][j] or S[i:len(T)+i][j] == "?":
                pass
            else:
                flag = False
        if flag:
            S = S[0:i] + T + S[len(T)+i:len(S)]
            print S.replace("?", "a")
            # print S.replace(S[i:len(T)+i], T).replace("?", "a")
            return 0

    print "UNRESTORABLE"

solve()

Submission status: Wrong Answer

Solution code:
import sys

s = raw_input()
key = raw_input()

for i in range(len(key)):
    index = s.find(key[i])
    if index < 0 and i == len(s) - 1:
        print "UNRESTORABLE"
        sys.exit()
    else:
        if index - i < 0 or index - i + len(key) > len(s):
            print "UNRESTORABLE"
            sys.exit()
        else:
            tmp = s[:index - i] + key + s[index - i + len(key):]
            for i in range(len(s)):
                if s[i] != '?' and s[i] != tmp[i]:
                    print "UNRESTORABLE"
                    sys.exit()

            break

ans = ""
for i in tmp:
    if i == '?':
        ans = ans + 'a'
    else:
        ans = ans + i

print ans

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

flag = 0
count = 0
for i in range(len(s)):
    if s[i] == '?' or s[i] in t:
        if count == 0:
            start = i
        count += 1
    else:
        if count >= len(t):
            print(count - len(t) + 1)
            for j in range(count - len(t) + 1):
                check = 0
                for k in range(len(t)):
                    if s[start + j + k] != t[k] and s[start + j + k] != '?':
                        check = 1
                        break
                if check == 0:
                    s = s[:start + j] + t + s[start + len(t) + j:]
                    flag = 1
                    break
        count = 0

if count >= len(t):
    for j in range(count-len(t)+1):
        check = 0
        for k in range(len(t)):
            if s[start+j+k] != t[k] and s[start+j+k] != '?':
                check = 1
                break
        if check == 0:
            s = s[:start+j] + t + s[start+len(t)+j:]
            flag = 1
            break

if flag == 0:
    print('UNRESTORABLE')
else:
    for i in range(len(s)):
        if s[i] == '?':
            s = s[:i] + 'a' + s[i+1:]
    print(s)

Submission status: Wrong Answer

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

    for i in range(len(S) - len(T)):
        # print S[i:len(T)+i]
        flag = True
        for j in range(len(T)):
            if T[j] == S[i:len(T)+i][j] or S[i:len(T)+i][j] == "?":
                pass
            else:
                flag = False
        if flag:
            print S.replace(S[i:len(T)+i], T).replace("?", "a")
            return 0

    print "UNRESTORABLE"

solve()

Submission status: Wrong Answer

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

    indexes = [i for i, x in enumerate(Sd) if x == T[0]][::-1]
    s = list(Sd)
    for i in indexes:
        for j in range(len(T)):
            if i + len(T) <= len(Sd):
                if s[i+j] == T[j] or s[i+j] == '?':
                    s[i+j] = T[j]
                    continue
            s = list(Sd)
            break
        else:
            ans = ''.join(s)
            ans = ans.replace('?', 'a')
            print(ans)
            exit()

    print('UNRESTORABLE')

main()

Submission status: Wrong Answer

Solution code:


SD = input()
K = input()

ans_list = []

for i in range(len(SD) - len(K) + 1):
    flag = True
    for j in range(len(K)):
        if SD[i] != K[j] and SD[i] != '?':
            flag = False
            break
    if flag:
        tmp = SD[:i] + K + SD[len(K) + 1:]
        ans_list.append(tmp.replace('?', 'a'))

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

Submission status: Wrong Answer

Solution code:
import sys

s = raw_input()
key = raw_input()

for i in range(len(key)):
    index = s.find(key[i])
    if index < 0 and i == len(s) - 1:
        print "UNRESTORABLE"
        sys.exit()
    else:
        if index - i < 0 or index - i + len(key) > len(s):
            print "UNRESTORABLE"
            sys.exit()
        else:
            tmp = s[:index - i] + key + s[index - i + len(key):]
            break

ans = ""
for i in tmp:
    if i == '?':
        ans = ans + 'a'
    else:
        ans = ans + i

print ans

Submission status: Wrong Answer

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

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:
import sys
S = input()
T = input()
ans = []
o = []
def check(S, T):
    for i in range(len(S)):
        if (T[i] == S[i]) or (S[i] == "?"):
            pass
        else:
            return False
    else:
        return True
    
hint_len = len(T)
UnCheck = True
for i in range(len(S)-(hint_len+1) , -1 , -1):
    if check(S[i+1:i+hint_len+1], T):
        Z = list(S)
        Z[i:i+hint_len+1] = list(T)
        ans.append(Z)
        UnCheck = False

if UnCheck:
    print("UNRESTORABLE")
    sys.exit()
else:
    for a in ans:
        x = ("".join(a)).replace("?", "a")
        o.append(x)

o.sort()
print(o[0])

Submission status: Wrong Answer

Solution code:
def solve():
    S = raw_input()
    T = raw_input()

    if len(S) == len(T):
        print T
        return 0

    for i in range(len(S) - len(T)):
        # print S[i:len(T)+i]
        flag = True
        for j in range(len(T)):
            if T[j] == S[i:len(T)+i][j] or S[i:len(T)+i][j] == "?":
                pass
            else:
                flag = False
        if flag:
            print S.replace(S[i:len(T)+i], T).replace("?", "a")
            return 0

    print "UNRESTORABLE"

solve()

Submission status: Wrong Answer

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

def comp(a, b, n):
	for i in range(n):
		if a[i] != '?' and a[i] != b[i]:
			return False
	return True 

def change(a):
	b = ""
	for i in range(len(a)):
		c = a[i]
		if a[i] == '?':
			c = 'a'
		b += c
	return b

t_len = len(t)
bad = "UNRESTORABLE"

n = len(t)
if len(t) > len(s):
	print(bad)
else:
	found = 0
	for i in range(n, len(s)):
		if comp(s[-i:-(i-n+1)]+s[-(i-n+1)], t, t_len):
			s = change(s)
			if i > n:
				print(s[:-i]+t+s[-(i-n):])
			else:
				print(s[:-i]+t)
			found = 1
			break
	if found == 0:
		print(bad)

Submission status: Wrong Answer

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

s_l, t_l = len(S), len(T)
not_find = False
start_i = 0

for i in range(s_l - t_l + 1):
    start_i = s_l - i - t_l
    here = True
    for j in range(t_l):
        if S[start_i+j] == T[j] or (S[start_i+j] == '?' and j != 0):
            here = True
        else:
            here = False
            break
    if here:
        break
    if start_i == 0:
        not_find = True

if not_find:
    print("UNRESTORABLE")
else:
    for s in range(len(S[:start_i])):
        if S[s] == '?':
            S[s] = 'a'

    S[start_i:start_i+t_l] = T

    for s in range(len(S[start_i+t_l:])):
        if S[start_i+t_l+s] == '?':
            S[start_i+t_l+s] = 'a'
    SS = ''
    for i in range(len(S)):
        SS += S[i]
    print(SS)

Submission status: Wrong Answer

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

for i, x in enumerate(t):
    if x in s:
        idx = s.index(x)
        res = "".join(s[:idx-i] + list(t) + s[idx+len(t):])
        res = res.replace("?", "a")
        if len(res) != len(s):
            print("UNRESTORABLE")
            break
        flag = False
        for a in range(len(s)):
            if s[a]=="?" or s[a]==res[a]:
                pass
            else:
                flag=True
                break
        if flag:
            print("UNRESTORABLE")
            break
        print(res)
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re

S2 = input()
T = input()

S_list = []

for j in range(len(S2) - len(T) + 1):
    if S2[j:(j + len(T))] == T:
        S_list.append(re.sub("\?", "a", S2))
    else:
        flag = 1
        tmp_S = ""
        for k in range(len(T)):
            if(S2[j + k] == T[k] or S2[j + k] == "?"):
                pass
            else:
                flag = 0
        if flag == 1:
            tmp = S2[:j] + T + S2[j + len(T):]
            S_list.append(re.sub("\?", "a", tmp))

if S_list == []:
    print("UNRESTORABL")
else:
    print(sorted(S_list)[0])

Submission status: Wrong Answer

Solution code:
import sys,collections
sys.setrecursionlimit(10**7)
def Is(): return [int(x) for x in sys.stdin.readline().split()]
def Ss(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

Sp = S()
T = S()
S = ""
for i in range(len(Sp)-len(T),-1,-1):
    for j in range(len(T)):
        if Sp[i+j] != "?" and T[j] != Sp[i+j]:
            break
        elif j == len(T)-1:
            S = Sp[0:i] + T + Sp[i+j+1:len(Sp)]
if S == "":
    print("UNRESTORABLE")
else:
    print(S.replace("?", "a"))

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Here your code !
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import numpy as np
import copy as cp
S = input()
T = input()
s = len(S)
t = len(T)

rst = []
for i in range(t) : 
    #１文字ずつ検索していく
    #検索範囲は iから(t - i)まで
    flag = False
    for j in reversed(range(i , s + i - t + 1)): 
        if (T[i] != S[j]) & (S[j] != "?") : continue
        else:
            #マッチしたら他の部分もあうか考える
            flag = True
            for k in range(t) : 
                if (T[k] == S[j - i + k]) | (S[j - i + k] == "?"): continue
                else : 
                    flag = False
                    break
            if flag : 
                #これでoKなのでブレイクしてあとはaで埋めます
                x = cp.deepcopy(S)
                for k in range(t) : 
                    if (T[k] == S[j - i + k])  : x = x[ : (j-i+k-1)] + T[k] + x[(j -i +k) : ]
                x = x.replace("?" , "a")
                rst.append(x)

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

Submission status: Wrong Answer

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

if len(S1) < len(T):
    print("UNRESTORABLE")
else:    
    for i in range(len(S1)-len(T)+1):
        flag1 = True
        flag2 = True
        for s,t in zip(S1[i:i+len(T)],T):
            if s == "?" or s == t:
                pass
            else:
                flag1 = False 
                break
        if flag1:
            flag2 = False
            S1 = S1.replace(S1[i:i+len(T)],T)
            S = ["a" if s1 == "?" else s1 for s1 in S1]
            print("".join(S))
            break
    if flag2:
        print("UNRESTORABLE")

Submission status: Wrong Answer

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

    indexes = [i for i, x in enumerate(Sd) if x == T[0]]
    s = list(Sd)
    for i in indexes:
        for j in range(len(T)):
            if i + len(T) <= len(Sd):
                if s[i+j] == T[j] or s[i+j] == '?':
                    s[i+j] = T[j]
                    continue
            s = list(Sd)
            break
        else:
            ans = ''.join(s)
            ans = ans.replace('?', 'a')
            print(ans)
            exit()

    print('UNRESTORABLE')

main()

Submission status: Wrong Answer

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

S = list(S)
T = list(T)
s_l, t_l = len(S), len(T)
not_find = False
start_i = 0
for i in range(s_l - t_l + 1):
    start_i = s_l - i - t_l
    here = True
    for j in range(t_l):
        if S[start_i+j] == T[j] or S[start_i+j] == '?':
            here = True
        else:
            here = False
            break
    if here:
        break
    if start_i == 0:
        not_find = True

if not_find:
    print("UNRESTORABLE")
else:
    for s in range(len(S[:start_i])):
        if S[s] == '?':
            S[s] = 'a'

    S[start_i:start_i+t_l] = T

    for s in range(len(S[start_i+t_l:])):
        if S[s] == '?':
            S[s] = 'a'
    SS = ''
    for i in range(len(S)):
        SS += S[i]
    print(SS)