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:
# -*- 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_t = S_t[0:i] + 'a' + S_t[i+1:len(S_t)]
    return S_t



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

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

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:
# -*- coding: utf-8 -*-
# 整数の入力
ind = 0
sd = input()
t = input()

sdlen = len(sd)
res = 0
while ind < sdlen:
  if sd[ind] == t[0]:

    slist = list(sd)
    slist[ind] = t[0]
    sd = "".join(slist)

    ind += 1
    ind_t = 1
    while ind_t < len(t):
      if sd[ind] == t[ind_t] or sd[ind] == '?':
        res = 1
        slist = list(sd)
        slist[ind] = t[ind_t]
        sd = "".join(slist)
        ind += 1
        ind_t += 1
        continue
      else:
        res = -1
        break
    if res < 0:
      print ( 'UNRESTORABLE')
      break
    elif res > 0:
      # 残りの？を a に変換
      print (sd.replace('?', 'a'))
      break
  ind += 1
if res <= 0:
  print ( 'UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys

s_d = input()
t = input()

s = ''
for i in range(len(s_d)):
    find_num = t.find(s_d[i])
    if not find_num == -1:
        if len(s_d[:i]) >= len(t[:find_num]) or len(s_d[i:]) >= len(t[find_num:]):
            s_d = s_d[:i-find_num] + t + s_d[i+len(t)-find_num:]
            break
    elif i == len(s_d)-1:
        print('UNRESTORABLE');
        sys.exit()
        
for i in range(len(s_d)):
    if s_d[i] == '?':
        s = s + 'a'
    else:
        s = s + s_d[i]
          
print(s)

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import re

s=input()
s_t=input()
sl=[]
sl.extend(s)
#print(sl)
hl=re.compile(r'\?+').findall(s)
cl=re.compile(r'\w+').findall(s)
#print(hl)
#print(cl)
hf = False
f = True
tl=[]

if sl[0] == '?':
    for i in range(len(hl)-1):
        tl.append(hl[i])
        tl.append(cl[i])
    if len(hl) != len(cl):
        tl.append(hl[len(cl)])
else:
    for i in range(len(cl)-1):
        tl.append(cl[i])
        tl.append(hl[i])
    if len(hl) != len(cl):
        tl.append(cl[len(hl)])
        
        
#print(tl)

#まず上から
for t in tl:
    if t.find(s_t) != -1:
        s = s.replace('?','a')
        print(s)
        exit()

def fin(s,i):
    t=0
    for c in s:
        if c == i[t] or c == '?':
            t+=1
            continue
        
        else:
            #print (':'+c+':'+i[t]+':')
            return False
    
    return True
    
for w in range(len(s)-len(s_t)):
    #print(s[len(s)-w-len(s_t):len(s)-w]+':',end='')
    #print(s_t,end='')
    if fin(s[len(s)-w-len(s_t):len(s)-w],s_t):
        s = s[0:len(s)-w-len(s_t)] + s_t +s[len(s)-w:len(s)]
        s = s.replace('?','a')
        
        print(s)
        exit()


for t in tl:
    if t[0]!='?':
        continue
    if len(s_t)<= len(t):
        ind=tl.index(t)
        tl[ind]=(len(t)-len(s_t))*'?'+s_t
        ans=''
        for t in tl:
            ans=ans+t
        
        ans = ans.replace('?','a')
        print(ans)
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
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 len(T) > len(S_prime):
                print("UNRESTORABLE")
                raise EndLoop
            elif S_prime.count("?") == 0:
                if T in "".join(S_prime):
                    print("".join(S_prime))
                    raise EndLoop
                else:
                    print("UNRESTORABLE")
                    raise EndLoop
            elif S_prime.count("?") == len(S_prime):
                S = "".join(["a" for _ in range(len(S_prime) - len(T))]) + T
                print(S)
                raise EndLoop

            possible = []
            for i in range(len(S_prime) - len(T) + 1):
                tmp_str = list(S_prime[i:len(T) + i])
                if checker(tmp_str, T):
                    possible.append(i)

            for i in range(len(S_prime) - len(T) + 1):
                tmp_str = list(S_prime[i:len(T) + i])
                if i == possible[-1]:
                    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]) + 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:
if __name__ == "__main__":
    s = input()
    t = input()

    t_size=len(t)

    result=list(s)
    w_cnt=0
    for i, w in enumerate(list(s)):
        if w=='?':
            w_cnt=w_cnt+1
        if w_cnt==t_size:
            result[i-t_size+1:i+1]=list(t)

    if t in ''.join(result):
        result = ['a' if w=='?' else w for w in result]
        print(''.join(result))
    else:
        print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys

S = sys.stdin.readline().rstrip()
T = sys.stdin.readline().rstrip()

def checkValid(S, i, T):
    try:
        if S[i] == T[0]:
            for j in range(0, len(T)):
                if S[i+j] == T[j] or S[i+j] == '?':
                    pass
                else:
                    return False
        else:
            return False
        return True
    except Exception as e:
        return False

def checkValid2(S, i, T):
    try:
        for j in range(0, len(T)):
            if S[i+j] == T[j] or S[i+j] == '?':
                pass
            else:
                return False
            return False
        return True
    except Exception as e:
        return False

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:
    smallest = res_list[0]
    for i in range(0, len(res_list)):
        if smallest > res_list[i]:
            smallest = res_list[i]
    print(smallest)

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    s = input()
    t = input()

    t_size=len(t)

    result=list(s)
    w_cnt=0
    for i, w in enumerate(list(s)):
        if w=='?':
            w_cnt=w_cnt+1
        if w_cnt==t_size:
            result[i-t_size+1:i+1]=list(t)

    if t in ''.join(result):
        result = ['a' if w=='?' else w for w in result]
        print(result)
    else:
        print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import re

s=input()
s_t=input()
sl=[]
sl.extend(s)
#print(sl)
hl=re.compile(r'\?+').findall(s)
cl=re.compile(r'\w+').findall(s)
#print(hl)
#print(cl)
hf = False
f = True
tl=[]

if sl[0] == '?':
    for i in range(len(hl)-1):
        tl.append(hl[i])
        tl.append(cl[i])
    if len(hl) != len(cl):
        tl.append(hl[len(cl)])
else:
    for i in range(len(cl)-1):
        tl.append(cl[i])
        tl.append(hl[i])
    if len(hl) != len(cl):
        tl.append(cl[len(hl)])
        
        
#print(tl)

#まず上から
    
def fin(s,i):
    t=0
    for c in s:
        if c == i[t] or c == '?':
            t+=1
            continue
        
        else:
            #print (':'+c+':'+i[t]+':')
            return False
    
    return True
    
for w in range(len(s)-len(s_t)):
    #print(s[len(s)-w-len(s_t):len(s)-w]+':',end='')
    #print(s_t,end='')
    if fin(s[len(s)-w-len(s_t):len(s)-w],s_t):
        s = s[0:len(s)-w-len(s_t)] + s_t +s[len(s)-w:len(s)]
        s = s.replace('?','a')
        
        print(s)
        exit()


for t in tl:
    if t[0]!='?':
        continue
    if len(s_t)<= len(t):
        ind=tl.index(t)
        tl[ind]=(len(t)-len(s_t))*'?'+s_t
        ans=''
        for t in tl:
            ans=ans+t
        
        ans = ans.replace('?','a')
        print(ans)
        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 += 'X'
	        else:
	            ans += 'a'
	    else:
	        ans += _s[i]


        
	    if len(ans) == len(_s):
	        break

	        
	        
	a=''
	for i in range(len(ans)):
	    if ans[i] == "X":
	       _ans = ans
	       a = _ans.replace(_ans[i:i+len(t)], t)
	       a = a.replace('X', 'a')
	if a:
	    print(a)
	else:
	    print("UNRESTORABLE")
	       
	    
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
print "UNRESTORABLE"

Submission status: Wrong Answer

Solution code:
import sys

s_d = input()
t = input()

s = ''
for i in range(len(s_d)):
    find_num = t.find(s_d[i])
    if not find_num == -1:
        if len(s_d[:i]) >= len(t[:find_num]) or len(s_d[i:]) >= len(t[find_num:]):
            s_d = s_d[:i-find_num] + t + s_d[i+len(t)-1:]
            break
    elif i == len(s_d)-1:
        print('UNRESTORABLE');
        sys.exit()
        
for i in range(len(s_d)):
    if s_d[i] == '?':
        s = s + 'a'
    else:
        s = s + s_d[i]
          

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

    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()

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

import re

s=input()
s_t=input()
sl=[]
sl.extend(s)
#print(sl)
hl=re.compile(r'\?+').findall(s)
cl=re.compile(r'\w+').findall(s)
#print(hl)
#print(cl)
hf = False
f = True
tl=[]

if sl[0] == '?':
    for i in range(len(hl)-1):
        tl.append(hl[i])
        tl.append(cl[i])
    if len(hl) != len(cl):
        tl.append(hl[len(cl)])
else:
    for i in range(len(cl)-1):
        tl.append(cl[i])
        tl.append(hl[i])
    if len(hl) != len(cl):
        tl.append(cl[len(hl)])
        
        
#print(tl)

#まず上から

for t in tl:
    if t[0]!='?':
        continue
    if len(s_t)<= len(t):
        ind=tl.index(t)
        tl[ind]=(len(t)-len(s_t))*'?'+s_t
        ans=''
        for t in tl:
            ans=ans+t
        
        ans = ans.replace('?','a')
        print(ans)
        exit()
    
def fin(s,i):
    t=0
    for c in s:
        if c == i[t] or c == '?':
            t+=1
            continue
        
        else:
            #print (':'+c+':'+i[t]+':')
            return False
    
    return True
    
for w in range(len(s)-len(s_t)):
    #print(s[len(s)-w-len(s_t):len(s)-w]+':',end='')
    #print(s_t,end='')
    if fin(s[len(s)-w-len(s_t):len(s)-w],s_t):
        s = s[0:len(s)-w-len(s_t)] + s_t +s[len(s)-w:len(s)]
        s = s.replace('?','a')
        
        print(s)
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s_ = input()
t = input()
ls = len(s_)
lt = len(t)

for i in range(ls):
    nows = s_[ls-i-lt:ls-i]
    if len(nows) < lt:
        break
    isSame = True
    for j in range(lt):
        if nows[j] == "?" or nows[j] == t[j]:
            continue
        else:
            isSame = False
            break
    if isSame:
        res = s_[:ls-i-lt] + t + s_[ls-i:]
        res = res.replace("?", "a")
        print(res)
        break

print("UNRESTORABLE")

Submission status: Wrong Answer

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

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

i = 0
j = 0

j_list = []
S_list = []

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

while True:
	if j == ls or i == lt:
		if not i == lt:
			print("UNRESTORABLE")
			exit(0)
		elif j != ls:
			j_list.append(j)
			i = 0
			j = j - lt + 1
		else:
			j_list.append(j)
			break

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


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

	S_tmp = ''

	for i in range(ls):
		if S[i] == '?':
			S_tmp += 'a'
		else:
			S_tmp += str(S[i])

	S_list.append(S_tmp)

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

Submission status: Wrong Answer

Solution code:
import re

Sp = list(input())
T=list(input())
isOK=0
for n in range(len(Sp)-len(T)+1):
    count=0
    for m in range(len(T)):
        if Sp[n+m] == '?':
          count += 1
        elif Sp[n+m] == T[m]:
          count += 1

    if count == len(T):
        Sp[n:n+len(T)] = T
        isOK=1

Sp = "".join(Sp)
Sp = Sp.replace("?", "a")

if isOK == 1:
    print(Sp)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

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

i = 0
j = 0

j_list = []
S_list = []

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

while True:
	if j == ls or i == lt:
		if not i == lt:
			print("UNRESTORABLE")
			exit(0)
		elif j != ls:
			j_list.append(j)
			i = 0
			j = j - lt + 1
		else:
			j_list.append(j)
			break

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


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

	S_tmp = ''

	for i in range(ls):
		if S[i] == '?':
			S_tmp += 'a'
		else:
			S_tmp += str(S[i])

	S_list.append(S_tmp)

print(S_list[-1])

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[len(S)-1-i-len(T):len(S)-1-i]
        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
            else:
                pass
        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"

solve()

Submission status: Wrong Answer

Solution code:
if __name__ == "__main__":
    s = input()
    t = input()
    t_size=len(t)
    result=list(s)
    w_cnt=0
    for i, w in enumerate(list(s)):
        if w=='?':
            w_cnt=w_cnt+1
        if w_cnt==t_size:
            result[i-t_size+1:i+1]=list(t)
    result = ['a' if w=='?' else w for w in result]
    print(result)

Submission status: Wrong Answer

Solution code:
## -*- coding:utf-8
#import os
#import sys
import re
#import deque
 
SD=input().rstrip()
T=input().rstrip()
S=""
 
sdlen=len(SD)
tlen=len(T)
flag=False
for i in range(sdlen-tlen+1):
    s=SD[i:i+tlen]
    #print(s)
    flag=True
    for j,k in zip(s,T):
        if( j=="?" ):
            continue
        if( j==k ):
            continue
        else:
            flag=False
            break
    if(flag==True):
        # 部分文字列一致
        SD=(SD[0:i]+T+SD[i+tlen:])
        flag=True
        #S=SD.replace(s,T)
        #break
S=SD.replace('?','a')
print(("UNRESTORABLE" if flag==False else S),flush=True)

Submission status: Wrong Answer

Solution code:
import re

Sp = list(input())
T=list(input())
isOK=0
for n in range(len(Sp)-len(T)+1):
    count=0
    for m in range(len(T)):
        if Sp[n+m] == '?':
          count += 1
        elif Sp[n+m] == T[m]:
          count += 1

    if count == len(T):
        Sp[n:n+len(T)] = T
        isOK=1
        break
Sp = "".join(Sp)
Sp = Sp.replace("?", "a")

if isOK == 1:
    print(Sp)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
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 len(T) > len(S_prime):
                print("UNRESTORABLE")
                raise EndLoop
            elif S_prime.count("?") == 0:
                if T in "".join(S_prime):
                    print("".join(S_prime))
                    raise EndLoop
                else:
                    print("UNRESTORABLE")
                    raise EndLoop
            elif S_prime.count("?") == len(S_prime):
                S = "".join(["a" for _ in range(len(S_prime) - len(T))]) + T
                print(S)
                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]) + 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

j_list = []
S_list = []

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

while True:
	if j == ls or i == lt:
		if not i == lt:
			print("UNRESTORABLE")
			exit(0)
		elif j != ls:
			j_list.append(j)
			i = 0
			j = j - lt + 1

		else:
			j_list.append(j)
			break

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


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

	S_tmp = ''

	for i in range(ls):
		if S[i] == '?':
			S_tmp += 'a'
		else:
			S_tmp += str(S[i])


	S_list.append(S_tmp)


S_list.sort()

print(S_list[0])

Submission status: Wrong Answer

Solution code:
import sys

S = sys.stdin.readline()
T = sys.stdin.readline()


def checkValid(S, i, T):
    if S[i] == T[0]:
        for j in range(0, len(T)):
            if S[i+j] == T[j] or S[i+j] == '?':
                pass
            else:
                return False
    else:
        return False
    return True

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 = False
for i in range(0, len(S)):
    if S[i] != '?':
        if checkValid(S, i, T) == True:
            print(getResult(S, i, T))
            res = True

if res == False:
    print("UNRESTORABLE")

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):
            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:
s = input()
t = input()

flag = False
t_len = len(t)
start = 0
num = 0
flag1 = False
if t in s:
  flag1 = True
  #print("aaaaaaaaas")

#print(flag1)

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

for i in range(len(s) - len(t) + 1):
  num = i  
  j = 0
  cnt = 0
  while j < len(t) 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'


if flag == False:
  print('UNRESTORABLE')
elif flag1 == True:
  st = ''
  for s_l in s:
    st += s_l

  print(st)
else:
  s[num :num + len(t)] = t

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


  print(st)

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

            return 0

    print "UNRESTORABLE"

solve()

Submission status: Wrong Answer

Solution code:
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 len(T) > len(S_prime):
                print("UNRESTORABLE")
                raise EndLoop
            if S_prime.count("?") == 0:
                print("".join(S_prime))
                raise EndLoop
            elif S_prime.count("?") == len(S_prime):
                S = "".join(["a" for _ in range(len(S_prime) - len(T))]) + T
                print(S)
                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]) + 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:
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 len(T) > len(S):
                print("UNRESTORABLE")
                raise EndLoop
            if S_prime.count("?") == 0:
                print("".join(S_prime))
                raise EndLoop
            elif S_prime.count("?") == len(S_prime):
                S = "".join(["a" for _ in range(len(S_prime) - len(T))]) + T
                print(S)
                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]) + 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

j_list = []
S_list = []

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

while True:
	if j == ls or i == lt:
		if not i == lt:
			print("UNRESTORABLE")
			exit(0)
		elif j != ls:
			j_list.append(j)
			i = 0
			j = j - lt + 1

		else:
			j_list.append(j)
			break


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

j = j_list[-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:
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
            elif S_prime.count("?") == len(S_prime):
                S = "".join(["a" for _ in range(len(S_prime) - len(T))]) + T
                print(S)
                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]) + 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 = input()
t = input()
s = s[::-1]
t = t[::-1]
import re
s2 = s.replace("?","9")
temp = ""
for i in t:
    temp += "("+i+"|9)"

M = re.match(temp,s2)
temp = []
if M:
    c = 0
    while(c<len(s)):
        print(temp,c)
        if M.start()<=c and c < M.start() + len(t):
            temp.append(t[c])
            c+=1
            continue
        temp.append(s[c])
        c += 1
    print(M.start())
    print("".join(temp).replace("?","a")[::-1])
else:
    print("UNRESTORABLE")