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: Accepted

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

ans = []
flag = False
for i in range(len(S)-len(T)+1)[::-1]:
    if flag == False:
        counter = 0
        sample = [c for c in S]
        for j in T:
            if sample[i+counter] != '?':
                if sample[i+counter] != j:
                    break
            else:
                sample[i+counter] = j
            counter += 1
            if counter == len(T):
                for k in range(len(sample)):
                    if sample[k] == '?':
                        sample[k] = 'a'
                sample = ''.join(sample)
                ans = sample
                flag = True

if flag:
    print ans
else:
    print 'UNRESTORABLE'

Submission status: Accepted

Solution code:
S = str(input())
T = str(input())
slist = list(S)
tlist = list(T)
Slen = len(slist)
Tlen = len(tlist)
ANSlist = []
Flag = 0
if Slen < Tlen:
    Flag = 0
else:
    for i in range(Slen-Tlen+1):
        flag = 0
        for j in range(Tlen):
            if slist[i+j] == "?" or slist[i+j] == tlist[j]:
                pass
            else:
                flag = 1
                break
        if flag == 0:
            Skari = ""
            k = 0
            for k in range(i):
                if slist[k] == "?":
                    Skari+="a"
                else:
                    Skari+=slist[k]
            l = 0
            for l in range(Tlen):
                Skari+=tlist[l]
            m = 0
            Skarilen = len(Skari)
            for m in range(Slen-Skarilen):
                M = m+Skarilen
                if slist[M] == "?":
                    Skari+="a"
                else:
                    Skari+=slist[M]
            ANSlist.append(Skari)
            Flag+=1
        else:
            pass
if Flag >= 1:
    print(min(ANSlist))
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s = input()
t = input()
s=s[::-1]
t=t[::-1]

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

for i in range(len_s-len_t+1):
  flag = True
  for j in range(len_t):
    if s[i+j]!=t[j] and s[i+j]!="?":
      flag = False
      break
  if flag:
    print((s[0:i]+t+s[i+len_t:len_s]).replace("?","a")[::-1])
    exit()
print("UNRESTORABLE")

Submission status: Accepted

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

l=[]
for i in range(len(S)-len(T)+1):
    f=True
    for j in range(len(T)):
        if S[i+j]!='?' and S[i+j]!=T[j]:
            f=False
            break
    if f:
        tmp=S[:i]+T+S[i+len(T):]
        l.append(tmp.replace('?','a'))
if len(l)>0:
    print(min(l))
else:
    print('UNRESTORABLE')

Submission status: Accepted

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

Submission status: Accepted

Solution code:
s0_r = list(input())[::-1]
t_r = list(input())[::-1]

for k in range(len(s0_r)-len(t_r)+1):
    for i in range(len(t_r)):
        if s0_r[k+i] != t_r[i] and s0_r[k+i] != "?":
            break
    else:
        for i in range(len(t_r)):
            s0_r[k+i] = t_r[i]
            s0 = s0_r[::-1]
        for k in range(len(s0)):
            if s0[k] == "?":
                s0[k] = "a"
        print(''.join(s0))
        break
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
# coding: utf-8

import re

def main():
    s = input()
    t = input()
    lt = len(t)
    for i in range(len(s) - lt, -1, -1):
        if re.match(s[i:i + lt].replace("?", "."), t):
            return s[:i].replace("?", "a") + t + s[i + lt:].replace("?", "a")
    return "UNRESTORABLE"


if __name__ == "__main__":
    print(main())

Submission status: Accepted

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

import re

def main():
    sp = input().replace("?", ".")
    t = input()
    ns = len(sp)
    nt = len(t)
    if ns < nt:
        return False
    se = set()
    for i in range(len(sp) - len(t) + 1):
        if re.match(sp[i:i + nt], t):
            res = sp[:i] + t + sp[i + nt:]
            assert len(res) == ns
            se.add(res.replace(".", "a"))
    if len(se) == 0:
        return False
    return sorted(list(se))[0]

res = main()
print(res if res else "UNRESTORABLE")

Submission status: Accepted

Solution code:
s=input()
t=input()
ans=[]
match=''
for i in range(len(s)-len(t)+1):
    flag=True
    for j in range(len(t)):
        if s[i+j]==t[j] or s[i+j]=='?':
            continue
        else:
            flag=False
    if flag:
        match=s[0:i]+t+s[i+len(t):]
        ans.append(match.replace('?','a'))
if ans==[]:
    print('UNRESTORABLE')
else:
    print(min(ans))

Submission status: Accepted

Solution code:
S=input()
T=input()
ans='UNRESTORABLE'
for j in range(len(S)-len(T)+1):
    flag=1
    for i in range(len(T)):
        if S[j+i]==T[i] or S[j+i]=='?':
            continue
        else:
            flag=0
    if flag:
        ans =S[0:j]+T+S[j+len(T):]
        ans =ans.replace('?','a')

print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
ans = 'UNRESTORABLE'

for i in range(len(s) - len(t) + 1):
    match = True
    for tt, ss in zip(t, s[len(s) - len(t) - i: len(s) - i]):
        if ss not in ('?', tt):
            match = False
            break
    if match:
        ans = s[:len(s) - len(t) - i] + t + s[len(s) - i:]
        ans = ans.replace('?', 'a')
        break

print(ans)

Submission status: Accepted

Solution code:
import re

def resolve(patterns, text):
    res = "UNRESTORABLE"
    for i in reversed(range(len(patterns) - len(text) + 1)):
        if re.search(patterns[i:i+len(text)], text):
            res = patterns[:i] + text + patterns[i+len(T):]
            res = res.replace('.', 'a')
            return res
    return res

S_dash = raw_input().replace('?', '.')
T = raw_input()

print resolve(S_dash, T)

Submission status: Accepted

Solution code:
s = input()
t = input()
a = len(s)
b = len(t)
ans = []
#後ろから検索して残りをaで埋める
for i in range(1+a-b):
  query = s[a-b-i:a-i] 
  #print(query)
  ct= 0
  for j in range(b):
    if t[j] == query[j] or query[j] == '?':
      ct += 1
  if ct == b:
    ans.append(s[0:a-b-i]+t+s[a-i::])
if ans ==[] : print('UNRESTORABLE')
else:print(min(ans).replace('?','a'))

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
S = input()
T = input()
n, m = len(S), len(T)

def main(S, T, n, m):
    for i in range(n-m, -1, -1):
        flag = True
        for s, t in zip(S[i:i+m], T):
            if s == '?' or s == t:
                pass
            else:
                flag = False
                break
        if flag:
            S = S.replace('?', 'a')
            return S[:i] + T + S[i+m:]
    return 'UNRESTORABLE'

print(main(S, T, n, m))

Submission status: Accepted

Solution code:
S = input()
T = input()
 
ans = 'UNRESTORABLE'
for i in range(len(S) - len(T) + 1):
    s = S[i:i+len(T)+1]
    flag = 1
    for j in range(len(T)):
        if s[j] == T[j] or s[j] == '?':
            pass
        else:
            flag = 0
    if flag:
        ans = S[0:i] + T + S[i+len(T):]
        ans = ans.replace('?', 'a')
print(ans)

Submission status: Accepted

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

ans = 'UNRESTORABLE'
for i in range(len(S) - len(T) + 1):
    flag = 1
    for j in range(len(T)):
        if S[i+j] == T[j] or S[i+j] == '?':
            continue
        else:
            flag = 0
    if flag:
        ans = S[0:i] + T + S[i+len(T):]
        ans = ans.replace('?', 'a')
print(ans)

Submission status: Accepted

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

ans = 'UNRESTORABLE'
for i in range(len(S) - len(T) + 1):
    flag = 1
    for j in range(len(T)):
        if S[i+j] == T[j] or S[i+j] == '?':
            continue
        else:
            flag = 0
    if flag:
        ans = S[0:i] + T + S[i+len(T):]
        ans = ans.replace('?', 'a')
    
print(ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
ans_list = []
for i in range(len(S)):
    for j in range(i+1,len(S)+1):
        part = S[i:j]
        if len(part) != len(T):
            continue
        for k in range(len(part)):
            if part[k] != T[k] and part[k] != "?":
                break
            elif k == len(part)-1:
                ans_str = S[:i] + T + S[j:]
                ans_str = ans_str.replace("?","a")
                ans_list.append(ans_str)
ans_list.sort()
if ans_list == []:
    print("UNRESTORABLE")
else:
    print(ans_list[0])

Submission status: Accepted

Solution code:
S = input()
T = input()
ans_list = []
for i in range(len(S)):
    for j in range(i+1,len(S)+1):
        part = S[i:j]
        if len(part) != len(T):
            continue
        for k in range(len(part)):
            if part[k] != T[k] and part[k] != "?":
                break
            elif k == len(part)-1:
                ans_str = S[:i] + T + S[j:]
                ans_list.append(ans_str)
ans_list = sorted([s.replace("?","a") for s in ans_list])
if ans_list == []:
    print("UNRESTORABLE")
else:
    print(ans_list[0])

Submission status: Accepted

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


def search(s, t):
    l_s = len(s)
    l_t = len(t)
    for i in range(l_s):
        if s[i] == t[0] or s[i] == '?':
            for j in range(l_t):
                if i+j < l_s:
                    if s[i+j] == t[j] or s[i+j] == '?':
                        if j == l_t-1:
                            return i
                        continue
                    else:
                        break
    return -1


s = s[::-1]
t = t[::-1]
ret = search(s, t)
if ret == -1:
    ans = 'UNRESTORABLE'
    print(ans)
else:
    ans = []
    for k in range(len(s)):
        if ret <= k <= ret+len(t)-1:
            ans.append(t[k-ret])
        else:
            if s[k] == '?':
                ans.append('a')
            else:
                ans.append(s[k])
    print(''.join(map(str, ans[::-1])))

Submission status: Accepted

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

flag=0
if len(t) > len(s):
    print("UNRESTORABLE")
else:
    index = len(s)-len(t)
    while index > -1:
        index2=0
        while index2 < len(t):
            if s[index+index2] == t[index2] or s[index+index2] == "?":
                index2+=1
            else:
                break
        if index2!=len(t):
            index-=1
        else:
            flag=1
            index2=0
            while index2 < len(t):
                if s[index+index2] == "?":
                    s[index+index2] = t[index2]
                index2+=1
            index3=0
            while index3 < len(s):
                if s[index3] == "?":
                    s[index3] = "a"
                index3+=1
            break
    if index == -1 and flag==0:
        print("UNRESTORABLE")
    else:
        print("".join(s))

Submission status: Accepted

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


def check1(s):
    ret = True
    for i in range(len(T)):
        if s[i] != '?' and s[i] != T[i]:
            ret = False
            break
    return ret


candidate = []
for i in range(len(S)-len(T)+1):
    if check1(S[i:i+len(T)]):
        candidate.append(i)

if not candidate:
    print('UNRESTORABLE')
else:
    S = S[:candidate[-1]] + T + S[candidate[-1]+len(T):]
    for i in range(len(S)):
        if S[i] == '?':
            S = S[:i] + 'a' + S[i+1:]
    print(S)

Submission status: Accepted

Solution code:
import copy
s = list(input())
t = list(input())
ans_list = []

if len(t)>len(s):
    print('UNRESTORABLE')
    exit()
else:

    for i in range(len(s)-len(t)+1): #sのi番目から部分列を取り出す
        sublist = copy.copy(s)
        for j in range(len(t)):
            if sublist[i+j] == '?':
                sublist[i+j] = t[j]
            elif sublist[i+j] != t[j]:
                break
        else:
            str_ans = ''.join(sublist)
            str_ans = str_ans.replace('?','a')
            ans_list.append(str_ans)

if ans_list:
    ans_list.sort()
    print(ans_list[0])
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
S = input()
T = input()
S = S[::-1]
T = T[::-1]

ans = "UNRESTORABLE"[::-1]
if len(S) >= len(T) :
    if T in S :
        ans = S
    else :
        for i in range(len(S)-len(T)+1) :
            S_ = S[i:i+len(T)]
            #print(S_)
            for j in range(len(T)) :
                if S_[j] == "?" :
                    continue
                if S_[j] != T[j] :
                    break
            else :
                ans = S[:i] + T + S[i+len(T):]
                break
ans = ans.replace("?","a")
ans = ans[::-1]
print(ans)

Submission status: Accepted

Solution code:
S_ = list(input())
T = list(input())
ans = []
for i in range(len(S_)-len(T)+1):
    for j in range(len(T)):
        if (T[j] == S_[i+j]) or (S_[i+j] == '?'):
            continue
        else:
            break
    else:
        S = S_[:i] + T + S_[i+len(T):]
        ans.append((''.join(S)).replace('?','a'))

if len(ans)!=0:
    print((sorted(ans))[0])
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
SS = input()
T = input()
S = ""
for i in range(len(SS) - len(T) + 1):
    flg = True
    for j in range(len(T)):
        if SS[i+j] == "?":
            continue
        elif SS[i+j] == T[j]:
            continue
        else:
            flg = False
            break
    if flg == True:
        S = SS[0:i] + T + SS[i+len(T):]

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

Submission status: Accepted

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


def ok(i):
    for j in range(len(t)):
        if s[i + j] == '?':
            continue
        elif s[i + j] != t[j]:
            return False
    return True


for i in range(len(s) - len(t), -1, -1):
    if ok(i):
        s = s[:i] + t + s[i + len(t) :]
        s = s.replace('?', 'a')
        print(s)
        import sys
        sys.exit()
print('UNRESTORABLE')

Submission status: Accepted

Solution code:
Sd = input()
T = input()
flag = False
t = len(T)
answers = set()
if len(Sd) < t: pass
else:
    for i in range(0, len(Sd)+1-t):
        for j in range(0,t):
            if Sd[i+j] in (T[j], '?'):
                if j == t-1: flag = True
            else: break
        if flag:
            answers.add(Sd[:i].replace('?','a')+T+Sd[i+t:].replace('?','a'))
        flag = False

if answers:
    print(min(answers))
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
s = str(input())
t = str(input())
ans = []
for i in range(len(s)-len(t)+1):
    s_part = s[i:i+len(t)]
    check = True
    for j in range(len(t)):
        if (s_part[j] != "?"): 
            if (s_part[j] != t[j]):
                check = False
    if check:
        a = s[0:i]+t+s[i+len(t):len(s)]
        ans.append(a.replace("?","a"))
if ans == []:
    print("UNRESTORABLE")
else:
    print(sorted(ans)[0])

Submission status: Accepted

Solution code:
s = str(input())
t = str(input())
index = []
n = len(s)
m = len(t)
if n>=m:
    for i in range(n-m+1):
        isFittable = True
        for j in range(m):
            if not (s[i+j]==t[j] or s[i+j]=="?"):
                isFittable = False
                break
        if isFittable:
            index.append(i)
ans = ""
if len(index)>0:
    i = index[-1]
    for j in range(n):
        if j<i or j>=i+m:
            if s[j]=="?":
                ans += "a"
            else:
                ans += s[j]
        else:
            ans += t[j-i]
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Accepted

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

def hantei(S,T):
    ans=True
    if(len(S)!=len(T)):
        return False
    for i in range(0,len(T)):
        if(S[i]==T[i] or S[i]=='?'):
            pass
        else:
            ans=False
            break
    return ans

ans=list()
for i in range(0,len(S)):
    if(hantei(S[i:i+len(T)],T)):
        ans.append(S[0:i]+T+S[i+len(T):100])
if(len(ans)>0):
    ans=list(ans[-1])
    for i in range(0,len(ans)):
        if(ans[i]=='?'):
            ans[i]="a"
            
    ans="".join(ans)
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s = [x for x in input()]
t = [x for x in input()]
s_num = len(s);t_num = len(t)
ans = [x for x in 'z'*51]
chinpo = [x for x in 'z'*51]
for i in range(s_num-t_num+1):
    anco = list(s)
    for j in range(t_num):
        check = 0
        if s[i+j] == '?' or s[i+j] == t[j]:
            pass
        else:
            check = 1
            break
    if check == 0:
        for k in range(0,i):
            if anco[k] == '?':anco[k] = 'a'
        c = 0
        for k in range(i,i+t_num):
            anco[k] = t[c]
            c += 1
        for k in range(i+t_num,s_num):
            if anco[k] == '?':anco[k] = 'a'
        ans = min(ans,anco)
if ans == chinpo:print('UNRESTORABLE')
else:print(''.join(ans))

Submission status: Accepted

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

#当てはまるかのフラグ
f=False

#順に当てはまるか見ていけばいい
#当てはまったら当てはまった場所をTで置き換え、それ以外の?をaで置き換える？

ns = len(S)
nt = len(T)
correspond=-1
index=ns-nt
answer=-1

while(1):
    correspond=1
    if index<0:break


    
    if nt > ns : break
    if (ns-index) < nt:break

    for i in range(index,nt+index):
        if S[i]=='?':
            continue
        elif S[i]!=T[i-index]:
            correspond=-1
            break

    if correspond==1 :    
        f=True
        answer=index
        # print(answer)
        break

    index-=1
    


if f==False:
    print('UNRESTORABLE')

if f==True:
    if ns==nt:
        answer_word=T
    else:
        if answer==0:
            answer_word=T+S[nt:]
        elif ns-answer==nt:
            answer_word=S[:answer]+T
        else:
            answer_word=S[:answer]+T+S[(nt+answer):]

    while(answer_word.count('?')>=1):
        answer_word=answer_word.replace('?','a')
        # break

    print(answer_word)

Submission status: Accepted

Solution code:
S = list(input())
T = list(input())
ans = []
for i in range(len(S) - len(T) + 1):
    tmp = S[:]
    count = 0
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != '?':
            break
        elif S[i+j] == T[j]:
            tmp[i+j] = T[j]
            count += 1
        elif S[i+j] == '?':
            tmp[i+j] = T[j]
            count += 1

    if len(T) == count:
        ans.append(tmp)

if ans:

    ans1 = []
    for i in ans:
        word = ''.join(i)
        word = word.replace('?', 'a')
        ans1.append(word)

    ans1.sort()
    print(ans1[0])
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
def check(i):
    for j in range(len(T)):
        if T[j] == S[i+j] or S[i+j] == "?":
            continue
        return False
    return True


def okikae(i):
    for j in range(len(T)):
        S[i+j] = T[j]
    return

S = list(input())
T = list(input())

for i in reversed(range(len(S)-len(T)+1)):
    if check(i) is True:
        last = i
        break
else:
    print("UNRESTORABLE")
    exit()

okikae(last)

for i in range(len(S)):
    if S[i] == "?":
        S[i] = "a"
print("".join(S))

Submission status: Accepted

Solution code:
s = input()
t = input()
S = len(s)
T = len(t)
ans= ''
for i in range(S-T+1):
    c = 1
    for j in range(T):
        if s[i+j] == t[j] or s[i+j] == '?':
            continue
        else:
            c = 0
    if c :
        ans = s[0:i] + t + s[i+T:]
if ans:
    ans = ans.replace('?','a')
    print(ans)
else:
    print('UNRESTORABLE')

Submission status: Accepted

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

ans = ''

for i in range(0, len(SD) - len(T)+1):
    flg = True
    for j in range(len(T)):
        if SD[i+j] == '?' or SD[i+j] == T[j]:
            continue
        else:
            flg = False
    if flg == True:
        ans = SD[0:i] + T + SD[i+len(T):]
            
if ans:
    ans = ans.replace('?', 'a')
else:
    ans = 'UNRESTORABLE'
    
print(ans)

Submission status: Accepted

Solution code:
S = input()
T = input()
r_S = S[::-1]
r_T = T[::-1]
if len(S) < len(T):
    print('UNRESTORABLE')
    exit()
if T in S:
    q_ans = r_S
else:
    for i in range(len(r_S)-len(T)+1):
        flag = True
        for j in range(len(T)):
            if r_S[i+j] == '?':
                pass
            elif r_S[i+j] == r_T[j]:
                pass
            elif r_S[i+j] != r_T[j]:
                flag = False
                break
        if flag:
            q_ans = r_S[:i] + r_T + r_S[i+len(T):]
            break
    if not flag:
        print('UNRESTORABLE')
        exit()

q_ans = q_ans[::-1]
ans = ''
for i in q_ans:
    if i == '?':
        ans += 'a'
    else:
        ans += i
print(ans)

Submission status: Accepted

Solution code:
#Dubious Document 2
SD = input()
T = input()
wordList = []
for i in range(len(SD)-len(T)+1):
    #print('i %s' % i) #
    found = True
    for j in range(len(T)):
        #print('j %s' % j) #
        if T[j]==SD[i+j] or SD[i+j]=='?': continue
        else:
            found = False
            break
    if found: 
        s = SD[:i]
        for j in range(len(T)): s +=  T[j]
        s += SD[i+len(T):]
        wordList.append(s)
wordList.sort()
#print(wordList) #
if wordList==[]:
    S = 'UNRESTORABLE'
else:
    S = ''
    for c in wordList[0]:
        if c=='?': S += 'a'
        else:    S += c
print(S)

Submission status: Accepted

Solution code:
def judge(s,t):
    j = True
    if len(s) != len(t):
        return False
    for i in range(len(s)):
        if s[i] != '':
            if(s[i] == t[i] or s[i] == '?') :
                continue
            else:
                j  = False
        else:
            j = False
    return j
            
s = input()
t = input()
ans = 'z'*50
ok = False

for i in range(len(s)):
    if judge(s[i:(len(t)+i)],t):
        ok = True
        s1 = s[0:i]
        s1 += t
        s1 += s[len(t)+i:len(s)]
        if ans > s1:
            ans = s1
if ok :
    print(ans.replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Accepted

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


def Find(S, T):
    ans = ''
    for i in range(0, len(S)-len(T)+1):
        s = S[i:i+len(T)]
        boolen = 1
        for j in range(len(s)):
            if not(s[j] == '?' or T[j] == s[j]):
                boolen *= 0
        if boolen == 1:
            ans = S[:i] + T + S[i+len(T):]
    return ans


ans = Find(S, T)

if ans:
    ans = list(ans)
    for i, v in enumerate(ans):
        if v == '?':
            ans[i] = 'a'
    ans = ''.join(ans)
    print(ans)
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
Sdash = str(input())
T = str(input())

reslis = []

if len(Sdash) >= len(T):
    for i in range(len(Sdash) - len(T) + 1):
        res = Sdash
        temp = Sdash[i:i+len(T)]
        for k in range(len(T)):
            if T[k] == temp[k] or temp[k] == "?":
                res = list(res)
                res[k+i] = T[k]
                res = "".join(res)
            else:
                break
        else:
            reslis.append(res) 

if reslis:
    reslis = [st.replace("?", "a") for st in reslis]
    print(min(reslis))
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
def may_eq(s, t):
    return all(c_s == '?' or c_s == c_t for c_s, c_t in zip(s, t))


def main():
    s = input()
    t = input()

    if not '?' in s:
        print(s)
        return

    if len(t) > len(s):
        print('UNRESTORABLE')
        return

    for i in reversed(range(0, len(s) - len(t) + 1)):
        if may_eq(s[i:i + len(t)], t):
            s = s[:i] + t + s[i + len(t):]
            s = s.replace('?', 'a')
            print(s)
            return

    print('UNRESTORABLE')


if __name__ == '__main__':
    main()

Submission status: Accepted

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

if len(t)>len(s):
  print("UNRESTORABLE")
  exit()

ans = []

for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if s[i+j] != t[j] and s[i+j]!='?':
      # print('Aの方')
      break
  else:
      #:iまでの文字はSを引き継ぎ、tを足し、残りは引き継ぎ、?部分はaに
      # print('Bの方')
    ans.append((s[:i]+t+s[i+len(t):]).replace('?','a'))
      # print('s[i+j]',s[i+j],"t[j]",t[j])
      # print('i',i,"j",j)
      # print(ans)

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

Submission status: Accepted

Solution code:
S = input()
T = input()
L = []

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 :
        l = S[:i]+T+S[i+len(T):]
        l = l.replace("?","a")
        L.append(l)
if L :
    print(min(L))
else :
    print("UNRESTORABLE")

Submission status: Accepted

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

cand = []
for i in range(len(S) - len(T) + 1):
    f = True
    for s, t in zip(S[i:i+len(T)], T):
        if s == '?':
            continue
        if s != t:
            f = False
            break
    if f:
        cand.append(S[:i] + T + S[i+len(T):])
if cand == []:
    print('UNRESTORABLE')
    exit()
print(cand[-1].replace('?', 'a'))

Submission status: Accepted

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

ans = []
for i in range(len(S)-len(T)+1):
    ss = list(S)
    for j in range(len(T)):
        if S[i+j]=="?":
            ss[i+j] = T[j]
            continue
        elif S[i+j]!=T[j]:
            break
    else:
        ans.append("".join(ss))

# print(ans)
if ans:
    for i in range(len(ans)):
        ans[i] = ans[i].replace("?", "a")
    print(min(ans))
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
n = len(s)
m = len(t)

i = 0
check = False
start = 0
while i+m <= n:
    temp = True
    k = 0
    while k < m and temp:
        if s[i+k] == t[k] or s[i+k] == "?":
            k += 1
        else:
            temp = False
    if temp:
        check = True
        start = i
        i += 1
    else:
        i += 1
if check:
    for k in range(start,start+m):
        s[k] = t[k-start]

if check:
    for i in range(n):
        if s[i] == "?":
            s[i] = "a"
    for i in range(n):
        if i != n-1:
            print(s[i],end = "")
        else:
            print(s[i])
else:
    print("UNRESTORABLE")

Submission status: Accepted

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

ls=len(s)
lt=len(t)

def f(a,b):
    r=""
    for i in range(lt):
        if a[i]==b[i] or a[i]=="?":
            r+=b[i]
        else:
            return False
    return True
        
ans=[]

for i in range(ls-lt+1):
    c=""
    if f(s[i:i+lt],t):
        c+=s[0:i]
        c+=t
        c+=s[i+lt:ls]
        c=c.replace("?","a")
        ans.append(c)

if ans==[]:
    print("UNRESTORABLE")
else:
    print(min(ans))

Submission status: Accepted

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


for i in range(len(S)-len(T)+1):
    cnt=0
    for j in range(len(T)):
        if S[len(S)-len(T)-i+j]=="?":
            cnt+=1
        else:
            if S[len(S)-len(T)-i+j]==T[j]:
                cnt+=1
    if len(T)==cnt:
        ANS=S[:len(S)-len(T)-i]+T+S[len(S)-i:]
        ANS=ANS.replace("?","a")
        print(ANS)
        exit()
    
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
S1=input()
T1=input()
S=""
T=""
A=""
for i in range(1,len(S1)+1):
    S+=S1[-i]
for i in range(1,len(T1)+1):
    T+=T1[-i]
j=0
i=0
flag = False
while i<=len(S)+1-len(T):
    while j<=len(T)+1:
        if i==len(S)-len(T)+1:
            A="UNRESTORABLE"
            flag=True
            break
        elif j==len(T):
            P=S.replace(S[i:i+len(T)],T,1)
            Q=P.replace("?","a")
            for i in range(1,len(Q)+1):
                A+=Q[-i]
            flag=True
            break
        elif S[i+j]==T[j] or S[i+j]=="?":
            j+=1
        else:
            j=0
            i+=1
    if flag:
        break
print(A)

Submission status: Accepted

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

p = ""
for i in range(len(t)):
    p += "[" + t[i] + "?]"

ans = []
for i in range(len(s)-len(t)+1):
    a = re.match(p, s[i:])
    if a is None:
        continue
    tmp = s[:i] + t + s[i+len(t):]
    ans.append(tmp.replace("?", "a"))

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

Submission status: Accepted

Solution code:
s=list(input())
t=list(input())
f=0
for i in range(len(s)-len(t),-1,-1):
  l=[]
  for j in range(len(t)):
    if s[i+j]=='?':l.append(t[j])
    else:l.append(s[i+j])
  if ''.join(t)==''.join(l):
    if f==0:
      for m in range(len(t)):
        s[i+m]=t[m]
    f=1
if f==0:print('UNRESTORABLE')
else:
  for k in range(len(s)):
    if s[k]=='?':s[k]='a'
  print(''.join(s))

Submission status: Accepted

Solution code:
def find_match(S, T):
    for i in range(len(S) - len(T) + 1):
        match = True
        for j in range(len(T)):
            if S[i+j] != "?" and S[i+j] != T[j]:
                match = False
                break
        if match:
            return i
    return -1


def main():
    S = input()[::-1]
    T = input()[::-1]
    idx = find_match(S, T)
    if idx != -1:
        S = S[:idx] + T + S[idx+len(T):]
        S = S[::-1].replace("?", "a")
    else:
        S = "UNRESTORABLE"
    print(S)


if __name__ == "__main__":
    main()

Submission status: Accepted

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