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:
s=input()
t=input()
ls=len(s)
lt=len(t)
S=''
for i in range(ls-lt+1):
    cnt=0
    for j in range(lt):
#        print(s[i+j])
        if s[i+j]==t[j]:
            cnt+=1
        elif s[i+j]=='?':
            cnt+=1
        else:
            break
    if cnt==lt:
        S=s[:i]+t+s[i+lt:]
if S=='':
    print('UNRESORTABLE')
else:
    S=list(S)
    for i in range(ls):
        if S[i]=='?':
            S[i]='a'
    print(''.join(S))

Submission status: Wrong Answer

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

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

if str(check2).isdecimal:
    ans = s[0:check2] + t + s[check2+len(t):len(s)]
    print(ans.replace('?', 'a'))

else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

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

if check2 == False:
    print('UNRESTORABLE')
else:
    ans = s[0:check2] + t + s[check2+len(t):len(s)]
    print(ans.replace('?', 'a'))

Submission status: Wrong Answer

Solution code:
# 2019/07/02
# かんにんぐあり

s=input()
t=input()

len_s=len(s)
len_t=len(t)

ans=[]

for i in range(len_s-len_t+1):
    flag=True
   # if s[i]==t[0]:
    for j in range(len_t):
        if s[i+j]==t[j] or s[i+j]=='?':continue
        else:
            flag=False
            break
    if flag:
        ans.append((s[:i]+t[:]+s[len_t+i:]).replace('?','a'))

ans.sort
if len(ans)==0:print('UNRESTORABLE') 
else:print(ans[0])

Submission status: Wrong Answer

Solution code:
# 2019/07/02
# かんにんぐあり

s=input()
t=input()

len_s=len(s)
len_t=len(t)

ans=[]

for i in range(len_s-len_t+1):
    flag=True
    if s[i]==t[0]:
        for j in range(len_t):
            if s[i+j]==t[j] or s[i+j]=='?':continue
            else:
                flag=False
                break
        if flag:
            ans.append((s[:i]+t[:]+s[len_t+i:]).replace('?','a'))

ans.sort
if len(ans)==0:print('UNRESTORABLE') 
else:print(ans[0])

Submission status: Wrong Answer

Solution code:
# 2019/07/02
# かんにんぐあり

s=input()
t=input()

len_s=len(s)
len_t=len(t)

ans='UNRESTORABLE'

for i in range(len_s-len_t+1):
    flag=True
    if s[i]==t[0]:
        for j in range(len_t):
            if s[i+j]==t[j] or s[i+j]=='?':continue
            else:
                flag=False
                break
        if flag:
            ans=s[:i]+t[:]+s[len_t+i:]
            ans=''.join(ans.replace('?','a'))
print(ans)

Submission status: Wrong Answer

Solution code:
# 2019/07/02
# かんにんぐあり

s=input()
t=input()

len_s=len(s)
len_t=len(t)

ans='UNRESTORABLE'

for i in range(len_s-len_t+1):
    flag=True
    if s[i]==t[0]:
        for j in range(len_t):
            if s[i+j]==t[j] or s[i+j]=='?':continue
            else:
                flag=False
                break
        if flag:
            ans=s[:i]+t[:]
            ans=''.join(ans.replace('?','a'))
print(ans)

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
s.reverse()
t.reverse()
c=0
if len(s)<len(t):
    print("UNRESTORABLE")
    exit()
for i in range(len(s)-len(t)+1):
    ss=s[i:i+len(t)]
    f=True
    for j in range(len(t)):
        if ss[j]!=t[j] and ss[j]!="?":
            f=False
    if f:
        s[i:i+len(t)]=t
        c+=1
for i in range(len(s)):
    if s[i]=="?":
        s[i]="a"
if c:
    s.reverse()
    print("".join(s))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
s.reverse()
t.reverse()
c=0
for i in range(len(s)-len(t)+1):
    ss=s[i:i+len(t)]
    f=True
    for j in range(len(t)):
        if ss[j]!=t[j] and ss[j]!="?":
            f=False
    if f:
        s[i:i+len(t)]=t
        c+=1
for i in range(len(s)):
    if s[i]=="?":
        s[i]="a"
if c:
    s.reverse()
    print("".join(s))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
c=0
if s==t:
    print("".join(s))
    exit()
for i in range(len(s)-len(t)+1):
    ss=s[i:i+len(t)]
    f=True
    for j in range(len(t)):
        if ss[j]!=t[j] and ss[j]!="?":
            f=False
    if f:
        s[i:i+len(t)]=t
        c+=1
for i in range(len(s)):
    if s[i]=="?":
        s[i]="a"
if c:
    print("".join(s))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
c=0
for i in range(len(s)-len(t)+1):
    ss=s[i:i+len(t)]
    f=True
    for j in range(len(t)):
        if ss[j]!=t[j] and ss[j]!="?":
            f=False
    if f:
        s[i:i+len(t)]=t
        c+=1
for i in range(len(s)):
    if s[i]=="?":
        s[i]="a"
if c:
    print("".join(s))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = list(input())
len_s = len(s)
t = list(input())
len_t = len(t)

if len_s<len_t:
    print("UNRESTORABLE")
    exit()

def fix(ls):
    for i in range(len(ls)):
        if ls[i]=="?":
            ls[i]="a"
    return ls

ans = []
for i in range(len_s-len_t+1):
    flg = True
    for j in range(len_t):
        if t[j]==s[i+j] or s[i+j]=="?":
            pass
        else:
            flg=False
            break
    if flg:
        can1 = fix(s[0:i-1])
        can2 = t
        can3 = fix(s[i+len_t:])
        ans.append("".join(can1+can2+can3))
ans.sort()
if len(ans)!=0:
    print(ans[0])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

kainashi="UNRESTORABLE"
ans1=[]
for i in range(len(s)-len(t)+1):
    tmp=s
    flag=1
    for j in range(len(t)):
        # print(s[len(s)-i-len(t)+j])
        # print(j)
        if s[len(s)-i-len(t)+j]==t[j] or s[len(s)-i-len(t)+j]=="?":
            tmp[len(s)-i-len(t)+j]=t[j]
            continue
        else:
            flag=0
            break
        
    if flag==1:
        ans=""
        for k in range(len(s)):
            if tmp[k]=="?":
                tmp[k]="a"
            ans+=tmp[k]
        ans1.append(ans)

if len(ans1)>0:
    ans1.sort()
    print(ans1[0])
else:
    print(kainashi)

Submission status: Wrong Answer

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

kainashi="UNRESTORABLE"
for i in range(len(s)-len(t)+1):
    tmp=s
    flag=1
    for j in range(len(t)):
        # print(s[len(s)-i-len(t)+j])
        # print(j)
        if s[len(s)-i-len(t)+j]==t[j] or s[len(s)-i-len(t)+j]=="?":
            tmp[len(s)-i-len(t)+j]=t[j]
            continue
        else:
            flag=0
            break
        
    if flag==1:
        ans=""
        for k in range(len(s)):
            if tmp[k]=="?":
                tmp[k]="a"
            ans+=tmp[k]
        print(ans)
        quit()

print(kainashi)

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

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

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

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

Submission status: Wrong Answer

Solution code:
def main():
    s = list(input())
    t = list(input())
    flag = False
    for i in range(len(s)-len(t)+1):
        st = s[i:i+len(t)]
        cnt = 0
        for j in range(len(t)):
            if st[j]==t[j]: cnt = 1
            elif t[j] != "?": break
        if cnt:
            flag = True
            for j in range(len(t)): s[i+j] = t[j]
    if flag: print("".join(s).replace("?","a"))
    else: print("UNRESTORABLE")

if __name__=="__main__": main()

Submission status: Wrong Answer

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



idx = None
for i in range(len(S) - len(T) + 1):
    w = S[i:i+len(T)]
    
    is_same = True
    for j in range(len(w)):
        if w[j] == '?':
            continue
        if w[j] == T[j]:
            continue
        else:
            is_same = False
            break

    if is_same:
        idx = i

if idx != None:
    inserted = (S[:i] + T + S[i+len(T):])
    print(inserted.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

idx = None
for i in range(len(S) - len(T) + 1):
    w = S[i:i+len(T)]
    
    is_same = True
    for j in range(len(w)):
        if w[j] == '?':
            continue
        if w[j] == T[j]:
            continue
        else:
            is_same = False
            break

    if is_same:
        idx = i
    
if idx:
    inserted = (S[:i] + T + S[i+len(T):])
    print(inserted.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

idx = None
for i in range(len(S) - len(T) + 1):
    w = S[i:i+len(T)]
    
    is_same = True
    for j in range(len(w)):
        if w[j] == '?':
            continue
        if w[j] == T[j]:
            continue
        else:
            is_same = False
            break

    if is_same:
        idx = i
    
if idx:
    inserted = (S[:i] + T + S[i+len(T):])
    print(inserted.replace('?', 'a'))
else:
    print('UNRESTORABLE ')

Submission status: Wrong Answer

Solution code:
from sys import stdin

Sd=list(stdin.readline().rstrip())
T=list(stdin.readline().rstrip())

output="UNRESTORABLE"
if len(Sd)<len(T):
    print(output)
for s in range(len(Sd)-len(T)+1):
    counter=0
    for t in range(len(T)):
        if (Sd[s+t] != "?") & (Sd[s+t] != T[t]):
            break
        else:
            counter+=1
    if counter==len(T):
        t_position=s
        #Sd=["a" if x=="?" else x for x in Sd]
        output=Sd[:t_position]+T+Sd[t_position+len(T):]
        output="".join(output).replace("?","a")
        #break

print(output)

Submission status: Wrong Answer

Solution code:
from sys import stdin

Sd=list(stdin.readline().rstrip())
T=list(stdin.readline().rstrip())

output="UNRESTORABLE"
if len(Sd)<len(T):
    print(output)
for s in range(len(Sd)-len(T)+1):
    counter=0
    for t in range(len(T)):
        if (Sd[s+t] != "?") & (Sd[s+t] != T[t]):
            break
        else:
            counter+=1
    if counter==len(T):
        t_position=s
        Sd=["a" if x=="?" else x for x in Sd]
        output=Sd[:t_position]+T+Sd[t_position+len(T):]
        output="".join(output)
        break

print(output)

Submission status: Wrong Answer

Solution code:
from sys import stdin

Sd=list(stdin.readline().rstrip())
T=list(stdin.readline().rstrip())

output="UNRESTORABLE"
if len(Sd)<len(T):
    print(output)
for s in range(len(Sd)-len(T)+1):
    counter=0
    for t in range(len(T)):
        if (Sd[s+t] != "?") & (Sd[s+t] != T[t]):
            break
        else:
            counter+=1
    if counter==len(T):
        t_position=s
        Sd[Sd=="?"]="a"
        output=Sd[:t_position]+T+Sd[t_position+len(T):]
        output="".join(output)
        break

print(output)

Submission status: Wrong Answer

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

def last_match(s, t):
    l, r = -1, -1
    for i in range(len(s)):
        if s[i] == "?" or s[i] == t[0]:
            match = True
            print i, s[i]
            for j in range(len(t)):
                if i + j >= len(s) or (s[i+j] != '?' and s[i+j] != t[j]):
                    match = False
                    break
                print j, s[i+j], t[j]
            if match:
                l, r = i, i + j
    return l, r
l, r = last_match(s, t)
if l == -1 and r == -1:
    print "UNRESTORABLE"
    exit()
res = ""
for i in range(len(s)):
    if i == l:
        match = True
        j = i
        res += t[0]
    elif i >= l and i <= r:
        res += t[i-j]
    elif s[i] == "?":
        res += "a"
    else:
        res += s[i]
print res

Submission status: Wrong Answer

Solution code:
# ABC076
def main():
    s, t = [input().rstrip() for _ in range(2)]
    len_s, len_t = len(s), len(t)
    if len_s < len_t:
        print("UNRESTORABLE")
        return
    flg = False
    for i in range(len_s - len_t + 1):
        p = s[i : i + len_t]  # partial string (substring)
        if all(j in (i, "?") for i, j in zip(t, p)):
            ans = s[:i] + t + s[i + len_t:]
            print(ans.replace("?", "a"))
            flg = True
            break
    if not flg:
        print("UNRESTORABLE")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
# ABC076
def main():
    s, t = [input().rstrip() for _ in range(2)]
    len_s, len_t = len(s), len(t)
    flg = False
    for i in range(len_s - len_t + 1):
        p = s[i : i + len_t]  # partial string (substring)
        if all(j in (i, "?") for i, j in zip(t, p)):
            ans = s[:i] + t + s[i + len_t:]
            print(ans.replace("?", "a"))
            flg = True
            break
    if not flg:
        print("UNRESTORABLE")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ss = []
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j] not in ("?",t[j]):
            break
    else:
        s = s[:i]+t+s[i+len(t):]
        ss.append(s.replace("?","a"))
if ss:
    print(min(ss))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
ss = []
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j] not in ("?",t[j]):
            break
    else:
        s = s[:i]+t+s[i+len(t):]
        ss.append(s.replace("?","a"))
if ss:
    print(min(ss))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
ans = []
flagss=False
if len(s)<len(t):
    print("UNRESTORABLE")
    exit()
for i in range(len(s)-len(t)+1):
    flag=True
    for j in range(len(t)):
        if s[j+i]!=t[j] and s[j+i]!="?":
            flag = False
    if flag:
        ss = s[:i]+t+s[i+j+1:]
        flagss=True
    else:
        ss=""
    if len(ss)==len(s):
        u = ""
        for j in range(len(s)):
            if ss[j]=="?":
               u+="a"
            else:
                u+=ss[j]
        ans.append(u)
if flag:
    print(min(ans))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
l=len(t)
a=[]
for i in range(l-1,len(s)):
    x=s[len(s)-1-i:len(s)-1-i+l]
    cnt=0
    for j in range(l):
        if x[j]=="?" or x[j]==t[j]:
            cnt+=1
        else:
            break
    if cnt==l:
        u=s[:len(s)-1-i].replace("?","a")
        v=s[len(s)-1-i+l:].replace("?","a")
        key=u+t+v
        a.append(key)
if len(a)==0:
    print("UNRESTORABLE")
    exit()
a=sorted(a)
print(a)

Submission status: Wrong Answer

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

s_n = len(s)
t_n = len(t)

# 辞書順最小にするために末尾の部分文字列からチェック
for i in range(s_n - t_n, -1,-1):
    # 部分文字列
    match = s[i: i + t_n]
    
    isMatch=True
    for m_in,m_c in enumerate(match):
        if m_c == "?":
            continue
        
        if m_c != t[m_in]:
            isMatch = False
            break
    
    # 一致していなければ次を検索
    if not isMatch:
        continue

    # 一致している場合は、部分文字列を置き換える
    password=""
    if i > 0:
        password = s[:i]
    password += t
    if s_n > i + t_n:
        password+=s[i+t_n]

    password = password.replace('?', 'a')  # 辞書順最小にするために、残りの?をaに置き換えておく
    print(password)
    exit()
    
print("UNRESTORABLE")

Submission status: Wrong Answer

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

s_n = len(s)
t_n = len(t)

# 辞書順最小にするために末尾の部分文字列からチェック
for i in range(s_n - t_n, -1,-1):
    # 部分文字列
    match = s[i: i + t_n]
    
    isMatch=True
    for m_in,m_c in enumerate(match):
        if m_c == "?":
            continue
        
        if m_c != t[m_in]:
            isMatch = False
            break
    
    # 一致していなければ次を検索
    if not isMatch:
        continue

    # 一致している場合は、部分文字列を置き換える
    s = s.replace(match, t)    
    s = s.replace('?', 'a')  # 辞書順最小にするために、残りの?をaに置き換えておく
    print(s)
    exit()
    
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
Sd = input()
T = input()

Sdr = Sd[::-1].replace('?', '.')
Tr = T[::-1]

for i in range(len(Sdr)-len(Tr)+1):
    pattern = Sdr[i:i+len(Tr)]
    if re.match(pattern, Tr):
        print(Sdr.replace(pattern, Tr).replace('.', 'a')[::-1])
        break
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    key = inputs[0]
    hint = inputs[1]
    len_hint = len(hint)
    hint_start_i = -1
    for i, c in enumerate(key):
        if c == hint[0] or c == "?":
            for j, ch in enumerate(key[i : i + len_hint]):
                if ch == hint[j] or ch == "?":
                    if j == len_hint - 1:
                        hint_start_i = i
                        break
                else:
                    break

            if hint_start_i != -1:
                break

    if hint_start_i == -1:
        return "UNRESTORABLE"

    resolved_key = ""
    for i, c in enumerate(key):
        if i == hint_start_i:
            resolved_key += hint
        elif i >= hint_start_i and i < hint_start_i + len_hint:
            continue
        elif c == "?":
            resolved_key += "a"
        else:
            resolved_key += c
    return resolved_key


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    key = inputs[0]
    hint = inputs[1]
    len_hint = len(hint)
    hint_start_i = {}
    for i, c in enumerate(key):
        if c == hint[0] or c == "?":
            for j, ch in enumerate(key[i : i + len_hint]):
                if ch == hint[j] or ch == "?":
                    if j == len_hint - 1:
                        hint_start_i[i] = True
                        break
                else:
                    break

    if len(hint_start_i) == 0:
        return "UNRESTORABLE"

    resolved_key = ""
    counter = -1
    for i, c in enumerate(key):
        if i in hint_start_i:
            resolved_key += hint
            counter = 0
        elif counter >= 0 and counter <= len_hint:
            counter += 1
            continue
        elif c == "?":
            resolved_key += "a"
            counter = -1
        else:
            resolved_key += c
            counter = -1
    return resolved_key


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    key = inputs[0]
    hint = inputs[1]
    len_hint = len(hint)
    hint_start_i = -1
    for i, c in enumerate(key):
        if c == hint[0] or c == "?":
            for j, ch in enumerate(key[i : i + len_hint]):
                if ch == hint[j] or ch == "?":
                    if j == len_hint - 1:
                        hint_start_i = i
                        break
                else:
                    break

            if hint_start_i != -1:
                break

    if hint_start_i == -1:
        return "UNRESTORABLE"

    resolved_key = ""
    for i, c in enumerate(key):
        if i == hint_start_i:
            resolved_key += hint
        elif i >= hint_start_i and i <= hint_start_i + len_hint:
            continue
        elif c == "?":
            resolved_key += "a"
        else:
            resolved_key += c
    return resolved_key


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def solve(inputs):
    key = inputs[0]
    hint = inputs[1]
    len_hint = len(hint)
    possibility = []  # matched_index
    hint_start_i = -1
    for i, c in enumerate(key):
        if c == hint[0] or c == "?":
            possibility.append(0)

        new_possibility = []
        for matched_hint_index in possibility:
            if c == hint[matched_hint_index] or c == "?":
                new_possibility.append(matched_hint_index + 1)

                if matched_hint_index + 1 == len_hint:
                    hint_start_i = i - len_hint + 1
                    break

        possibility = new_possibility

        if hint_start_i != -1:
            break

    if hint_start_i == -1:
        return "UNRESTORABLE"

    resolved_key = ""
    for i, c in enumerate(key):
        if i == hint_start_i:
            resolved_key += hint
        elif i >= hint_start_i and i <= hint_start_i + len_hint:
            continue
        elif c == "?":
            resolved_key += "a"
        else:
            resolved_key += c
    return resolved_key


def string_to_int(string):
    return list(map(lambda x: int(x), string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Submission status: Wrong Answer

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

index = len(S)
ans = []
isMatch = True

# 後ろから判定
while index - len(T) >= 0:
  obj = S[index - len(T):index]
  # 切り出した文字列がTと一致し得るか判定
  for i in range(len(obj)):
    if not obj[i] == "?" and not obj[i] == T[i]:
      isMatch = False
  
  # T文字列で埋める
  if isMatch:
    ans.append(S[0:index-len(T)] + T + S[index:])

  isMatch = True
  index = index - 1

if ans == []:
  print("UNRESTORABLE")
else:
  ans = sorted(ans)[0]
  for i in range(len(ans)):
    if ans[i] == "?":
      ans[i] = "a"
      print("".join(ans))

Submission status: Wrong Answer

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

index = len(S)
ans = []
isMatch = True

# 後ろから判定
while index - len(T) >= 0:
  obj = S[index - len(T):index]
  # 切り出した文字列がTと一致し得るか判定
  for i in range(len(obj)):
    if not obj[i] == "?" and not obj[i] == T[i]:
      isMatch = False
      break
  
  # T文字列で埋める
  if isMatch:
    ans.append(S[0:index-len(T)] + T + S[index:])

  isMatch = True
  index = index - 1

if ans == []:
  print("UNRESTORABLE")
else:
  ans = sorted(ans)[0]
  for i in range(len(ans)):
    if ans[i] == "?":
      ans[i] = "a"
      print("".join(ans))

Submission status: Wrong Answer

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

index = len(S)
ans = ""
isMatch = True

# 後ろから判定
while index - len(T) >= 0:
  obj = S[index - len(T):index]
  # 切り出した文字列がTと一致し得るか判定
  for i in range(len(T)):
    if not obj[i] == "?" and not obj[i] == T[i]:
      isMatch = False
  
  # T文字列で埋める
  if isMatch:
    ans = S[0:index-len(T)] + T + S[index:]

  isMatch = True
  
  index = index - 1

if ans == "":
  print("UNRESTORABLE")
  exit()
else:
  for i in range(len(ans)):
    if ans[i] == "?":
      ans[i] = "a"

print("".join(ans))

Submission status: Wrong Answer

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

index = len(S)
ans = ""
isMatch = True

# 後ろから判定
while index - len(T) >= 0 and isMatch:
  obj = S[index - len(T):index]
  # 切り出した文字列がTと一致し得るか判定
  for i in range(len(T)):
    if not obj[i] == "?" and not obj[i] == T[i]:
      isMatch = False
  
  # T文字列で埋める
  if isMatch:
    ans = S[0:index-len(T)] + T + S[index:]
  
  index = index - 1

if ans == "":
  print("UNRESTORABLE")
else:
  for i in range(len(ans)):
    if ans[i] == "?":
      ans[i] = "a"

  print("".join(ans))

Submission status: Wrong Answer

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

index = len(S)
ans = ""
isMatch = True

# 後ろから判定
while index - len(T) >= 0 and isMatch:
  obj = S[index - len(T):index]
  # 切り出した文字列がTと一致し得るか判定
  for i in range(len(T)):
    if not obj[i] == "?" and not obj[i] == T[i]:
      isMatch = False
      break
  
  # T文字列で埋める
  if isMatch:
    ans = S[0:index-len(T)] + T + S[index:]
  
  index = index - 1

if ans == "":
  print("UNRESTORABLE")
else:
  for i in range(len(ans)):
    if ans[i] == "?":
      ans[i] = "a"

  print("".join(ans))

Submission status: Wrong Answer

Solution code:
l = input().split()
S = l[0]
l = input().split()
T = l[0]

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

# print(S, T, len(S), len(T))

found = False

def match(pos, max_pos, src, dst):
    if pos == max_pos:
        return True
    if src[pos] == '?' or src[pos] == dst[pos]:
        return match(pos + 1, max_pos, src, dst)
    return False

for i in range(ls - lt + 1):
    if match(0, lt, S[i:], T):
        S = S[:i] + T + S[i + lt:]
        found = True

if found:
    S = S.replace('?', 'a')
    print(S)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
l = input().split()
S = l[0]
l = input().split()
T = l[0]

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

# print(S, T, len(S), len(T))

found = False

def match(pos, max_pos, src, dst):
    if pos == max_pos:
        return True
    if src[pos] == '?' or src[pos] == dst[pos]:
        return match(pos + 1, max_pos, src, dst)
    return False

for i in range(ls - lt + 1):
    if match(0, lt, S[i:], T):
        S = S[:i] + T + S[i + lt:]
        found = True
        break

if found:
    S = S.replace('?', 'a')
    print(S)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
l = input().split()
S = l[0]
l = input().split()
T = l[0]

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

# print(S, T, len(S), len(T))

found = False

def match(pos, max_pos, src, dst):
    if pos == max_pos:
        return True
    if src[pos] == '?' or src[pos] == dst[pos]:
        return match(pos + 1, max_pos, src, dst)
    return False

for i in range(ls - lt + 1):
    if match(0, lt - 1, S[i:], T):
        S = S[:i] + T + S[i + lt:]
        found = True
        break

if found:
    S = S.replace('?', 'a')
    print(S)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    T = input()
    i = 0
    j = 0
    SL = list(S)
    AL = []
    while len(S) > i:
        if S[i] == '?' or S[i] == T[j]:
            SL[i] = T[j]
            if j == len(T) - 1:
                AL.append(''.join(SL).replace('?', 'a'))
                SL = list(S)
                if len(T) == 1:
                    i += 1
                j = 0
            else:
                i += 1
                j += 1
            continue
        SL = list(S)
        i += 1
        j = 0
    if len(AL) == 0:
        print('UNRESTORABLE')
    else:
        print(sorted(AL)[0])


main()

Submission status: Wrong Answer

Solution code:
# けつから順に当てはまるものを探していく
s = list(input())
h = list(input())

index = len(s)
ans = []
notFound = False
while index - len(h) >= 0 and not notFound:
    obj = s[index - len(h):index]
    #この文字列がhと生合成を持っているかを確認する
    for i in range(len(obj)):
        if not obj[i] == "?":
            if not obj[i] == h[i]:
                notFound = True
                break

    if not notFound:
        ans = s[0:index-len(h)] + h + s[index:]

    notFound = False
    index -= 1

    

if ans == []:
    print('UNRESTORABLE')
else:
    for i in range(len(ans)):
        if ans[i] == "?":
            ans[i] = "a"
    print("".join(ans))

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    T = input()
    i = 0
    j = 0
    SL = list(S)
    AL = []
    while len(S) > i and len(T) > j:
        if S[i] == '?' or S[i] == T[j]:
            SL[i] = T[j]
            i += 1
            j += 1
            if j == len(T):
                AL.append(''.join(SL).replace('?', 'a'))
                SL = list(S)
                j = 0
            continue
        SL = list(S)
        i += 1
        j = 0
    if len(AL) == 0:
        print('UNRESTORABLE')
    else:
        print(sorted(AL)[0])


main()

Submission status: Wrong Answer

Solution code:
def f(S, T):
    i = 0
    j = 0
    SL = list(S)
    while len(S) > i and len(T) > j:
        if S[i] == '?' or S[i] == T[j]:
            SL[i] = T[j]
            i += 1
            j += 1
            continue
        SL = list(S)
        i += 1
        j = 0
    if len(T) > j:
        return ''
    return ''.join(SL).replace('?', 'a')


def ff(S, T):
    i = len(S) - 1
    j = len(T) - 1
    SL = list(S)
    while i >= 0 and j >= 0:
        if S[i] == '?' or S[i] == T[j]:
            SL[i] = T[j]
            i -= 1
            j -= 1
            continue
        SL = list(S)
        i -= 1
        j = len(T) - 1
    if j > -1:
        return ''
    return ''.join(SL).replace('?', 'a')


def main():
    S = input()
    T = input()
    ans = sorted([f(S, T), ff(S, T)])[0]
    if not ans:
        print('UNRESTORABLE')
    else:
        print(ans)


main()