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:
#文字列Tを突っ込むのはできるだけ最後の方が良い(残りは全てaにしないと辞書順で負けうる。)
#if 文字列が入らない→UNRESTORABLE
#if 文字列が入ったら全部aを入れられる。(ん？これってここまでやったら絶対に一番最初のやつになるのでは?)
#※すでに文字が入っていたら、文字列を入れずに全てaを突っ込む
#文字列をどうやって探すか。
#Tの長さと同じだけ?が連続している場所があるならいける
#というか一文字ずつみて(その文字or?ならオーケー)失敗したらindexを戻していけばいいので

#フラグは一箇所ずつ新しいのを設定しないと混乱する
def strProduct(S,T):
    Tindex = 0#Tのindex失敗するたびに0に戻る
    lt = len(T) #Tの文字列の長さ
    ls = len(S) #Sの文字列の長さ
    flag = []#Tの材料に ?がなければFalse
    reasonable = False#文字を作れるかどうか
    notchange  = False#変更がいるかどうか
    f = False
    translateIndex = [] #SがTの文字列になる場所の初めの位置のque
    S.reverse()
    T.reverse()
    for si in range(len(S)):
        s = S[si]
        #print(s,T[Tindex])
        if s == T[Tindex] or s == "?":
            if Tindex == 0:#初めての一致
                if si <= ls - lt : #一致する可能性があれば
                    translateIndex.append(si)
            if s == "?":#?をつかって文字列をつくる時と作らない時で異なるし、?を使わないのがあればそれを優先するべき
                flag = True
                if len(translateIndex) > 1:#すでに一つ完成している時はそっちを優先する
                    translateIndex.pop()#translateIndexには残らない
            Tindex += 1
            if Tindex == lt:#全てmatchingした時
                reasonable = True#文字列ができる
                if not flag:#?を使わないなら優先的にそれを使う
                    notchange = True#?を使わないでもできる
                    break
                #初期化して次のを探す
                Tindex = 0
                flag = False
        else: #一回でも失敗すれば初期化だが、Tindexが進んでいるとミスした時に次の段階を始められないので
            if Tindex > 0:
                f = True
            Tindex = 0
            flag = False
            if f:
                if s == T[Tindex] or s == "?":
                    if Tindex == 0:#初めての一致
                        if si <= ls - lt : #一致する可能性があれば
                            translateIndex.append(si)
                    if s == "?":#?をつかって文字列をつくる時と作らない時で異なるし、?を使わないのがあればそれを優先するべき
                        flag = True
                        if len(translateIndex) > 1:#すでに一つ完成している時はそっちを優先する
                            translateIndex.pop()#translateIndexには残らない
                    Tindex += 1
                    if Tindex == lt:#全てmatchingした時
                        reasonable = True#文字列ができる
                        if not flag:#?を使わないなら優先的にそれを使う
                            notchange = True#?を使わないでもできる
                            break
                        #初期化して次のを探す
                        Tindex = 0
                        flag = False
        #print("Tindex={} translateIndex={} flag={} reasonable={} notchange={}".format(Tindex,translateIndex,flag,reasonable,notchange))
    if (not notchange) and reasonable:#?を使わないとできないなら変更します。
        for j in range(translateIndex[len(translateIndex)-1],translateIndex[len(translateIndex)-1]+lt):
            S[j] = T[j-translateIndex[len(translateIndex)-1]]
    S.reverse()
    #T.reverse()
    if not reasonable:
        return "UNRESTORABLE"
    else:
        for si in range(len(S)):
            if S[si] == "?":
                S[si] = "a"
        modifiedS = ''.join(S)
        return modifiedS

S = list(input())
T = list(input())
#print(S)
#print(T)
print(strProduct(S,T))

Submission status: Wrong Answer

Solution code:
#文字列Tを突っ込むのはできるだけ最後の方が良い(残りは全てaにしないと辞書順で負けうる。)
#if 文字列が入らない→UNRESTORABLE
#if 文字列が入ったら全部aを入れられる。(ん？これってここまでやったら絶対に一番最初のやつになるのでは?)
#※すでに文字が入っていたら、文字列を入れずに全てaを突っ込む
#文字列をどうやって探すか。
#Tの長さと同じだけ?が連続している場所があるならいける
#というか一文字ずつみて(その文字or?ならオーケー)失敗したらindexを戻していけばいいので

def strProduct(S,T):
    Tindex = 0#Tのindex失敗するたびに0に戻る
    lt = len(T) #Tの文字列の長さ
    ls = len(S) #Sの文字列の長さ
    flag = []#Tの材料に ?がなければFalse
    reasonable = False#文字を作れるかどうか
    notchange  = False#変更がいるかどうか
    translateIndex = [] #SがTの文字列になる場所の初めの位置
    S.reverse()
    T.reverse()
    for si in range(len(S)):
        s = S[si]
        if s == T[Tindex] or s == "?":
            if Tindex == 0:#初めての一致
                if si <= ls - lt : #一致する可能性があれば
                    translateIndex.append(si)
            if s == "?":#?をつかって文字列をつくる時と作らない時で異なるし、?を使わないのがあればそれを優先するべき
                flag = True
                if len(translateIndex) > 1:#すでに一つ完成している時はそっちを優先する
                    translateIndex.pop()#translateIndexには残らない
            Tindex += 1
            if Tindex == lt:#全てmatchingした時
                reasonable = True#文字列ができる
                if not flag:#?を使わないなら優先的にそれを使う
                    notchange = True#?を使わないでもできる
                    break
                #初期化して次のを探す
                Tindex = 0
                flag = False
        else: #一回でも失敗すれば初期化
            Tindex = 0
            flag = False
            #translateIndexはあまり関係ない
        #print("Tindex={} translateIndex={} flag={} reasonable={}".format(Tindex,translateIndex,flag,reasonable))
    if (not notchange) and reasonable:#?を使わないとできないなら変更します。
        for j in range(translateIndex[len(translateIndex)-1],translateIndex[len(translateIndex)-1]+lt):
            S[j] = T[j-translateIndex[len(translateIndex)-1]]
    S.reverse()
    #T.reverse()
    if not reasonable:
        return "UNRESTORABLE"
    else:
        for si in range(len(S)):
            if S[si] == "?":
                S[si] = "a"
        modifiedS = ''.join(S)
        return modifiedS

S = list(input())
T = list(input())
#print(S)
#print(T)
print(strProduct(S,T))

Submission status: Wrong Answer

Solution code:
#文字列Tを突っ込むのはできるだけ最後の方が良い(残りは全てaにしないと辞書順で負けうる。)
#if 文字列が入らない→UNRESTORABLE
#if 文字列が入ったら全部aを入れられる。(ん？これってここまでやったら絶対に一番最初のやつになるのでは?)
#※すでに文字が入っていたら、文字列を入れずに全てaを突っ込む
#文字列をどうやって探すか。
#Tの長さと同じだけ?が連続している場所があるならいける
#というか一文字ずつみて(その文字or?ならオーケー)失敗したらindexを戻していけばいいので

def strProduct(S,T):
    Tindex = 0#Tのindex失敗するたびに0に戻る
    lt = len(T) #Tの文字列の長さ
    flag = False#Tの材料に ?がなければFalse
    reasonable = False#文字を作れるかどうか
    translateIndex = 0 #SがTの文字列になる場所の初めの位置
    S.reverse()
    T.reverse()
    for si in range(len(S)):
        s = S[si]
        if s == T[Tindex] or s == "?":
            if Tindex == 0:#初めての一致
                translateIndex = si
            if s == "?":#?をつかって文字列をつくる時と作らない時で異なる
                flag = True
            Tindex += 1
            if Tindex == lt:#全てmatchingした時
                if flag:
                    for j in range(translateIndex,translateIndex+lt):
                        S[j] = T[j-translateIndex]
                #else:何もなければ触らない
                reasonable = True
                break
        else: #一回でも失敗すれば初期化
            Tindex = 0
            flag = False
            #translateIndexはあまり関係ない
    S.reverse()
    #T.reverse()
    if not reasonable:
        return "UNRESTORABLE"
    else:
        for si in range(len(S)):
            if S[si] == "?":
                S[si] = "a"
        modifiedS = ''.join(S)
        return modifiedS

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

print(strProduct(S,T))

Submission status: Wrong Answer

Solution code:
sp = input()
t = input()
len_t = len(t)
len_s = len(sp)
cand = []

for i in range(len_s - len_t + 1):
    num = 0
    for j in range(len_t):
        if (sp[i + j] == '?' or sp[i + j] == t[j]):
            num += 1
    
    if (num == len_t):
        sp2 = sp
        sp2 = sp2.replace(sp2[i:i+len_t], t)
        cand.append(sp2)

if cand:
    # 部分文字列は最後にあったほうがいい?はaで最小化できる可能性があり、文字列の先頭に近い部分にそれらがあったほうがよい
    ans = cand[-1].replace('?', 'a')
    print(ans)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
sp = input()
t = input()
len_t = len(t)
len_s = len(sp)
cand = []

for i in range(len_s - len_t + 1):
    num = 0
    for j in range(len_t):
        if (sp[i + j] == '?' or sp[i + j] == t[j]):
            num += 1
    
    if (num == len_t):
        sp2 = sp
        sp2 = sp2.replace(sp2[i:i+len_t], t)
        cand.append(sp2)
    
if cand:
    # min = float('inf')
    # ans = ''
    # for c in cand:
    #     for i in range(len(c)):
    #         if (c[i] == 'a' or c[i] == '?'):
    #             if (min > i):
    #                 min = i
    #                 ans = c
    #             break
    for i in range(len(cand)):
        cand[i] = cand[i].replace('?', 'a')
    cand.sort()
    print(cand)

else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
sp = input()
t = input()
len_t = len(t)
len_s = len(sp)
cand = []

for i in range(len_s - len_t + 1):
    num = 0
    for j in range(len_t):
        if (sp[i + j] == '?' or sp[i + j] == t[j]):
            num += 1
    
    if (num == len_t):
        sp2 = sp
        sp2 = sp2.replace(sp2[i:i+len_t], t)
        cand.append(sp2)
    
if cand:
    min = float('inf')
    ans = ''
    for c in cand:
        for i in range(len(c)):
            if (c[i] == 'a' or c[i] == '?'):
                if (min > i):
                    min = i
                    ans = c
                break
    ans = ans.replace('?', 'a')
    print(ans)

else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import copy
S=list(input())
S1 = "".join(S)
T=list(input())
T1 = "".join(T)
F = ["?"]*len(T)
F1 = "".join(F)
l =[]
M =[]
index =[]
B = copy.deepcopy(S)
while -1<S1.find(F1):
    a = S1.find(F1)
    index.append(a)
    B[a] ="a"
    S1="".join(B)
S1 ="".join(S)
for i in range(len(S)-len(T)+1):
    if S[i]==T[0]:
        l.append(i)
if 0<len(l):
    for i in l:
        c = S[i:len(T)+i]
        while "?" in c:
            c[c.index("?")] = T[c.index("?")]
        if c==T:
            A = copy.deepcopy(S)
            A[i:len(T)+i] = c
            while "?"in A:
                A[A.index("?")]="a"
            M.append(A)
if 0<len(index):
    for i in index:
        A = copy.deepcopy(S)
        A[i:len(T)+i] = T
        while "?"in A:
            A[A.index("?")]="a"
        M.append(A)
if 0<len(M):
    M.sort()
    print("".join(M[0]))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
flag=False
for i in range(len(S)-len(T)+1):
    dif=0
    same=0
    s=S[i:i+len(T)]#len(T)
    for i in range(len(T)):
        if s[i]!='?':#sが言葉の時
            if s[i]!=T[i]:
                #print("st",s[i],T[i])
                dif+=1
            else:
                same+=1
#                flag=True

        #else:#?のとき
    if dif==0:
        dst=S.replace(s,T)
        flag=True
if flag==False:
    print("UNRESTORABLE")
else:
    dst=dst.replace('?','a')
    print(dst)

Submission status: Wrong Answer

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

len_Sp = len(Sp)
len_T = len(T)
restorable = False
max_i = 0
if len_Sp >= len_T:
    for i in range(len_Sp - len_T, -1, -1):
        for j in range(len_T):
            if Sp[i + j] != '?' and Sp[i + j] != T[j]:
                break
        else:
            #Sp[i : i + len_T] = T
            max_i = i
            restorable = True
if restorable:
    Sp[max_i : max_i + len_T] = T
    print(''.join(Sp).replace('?', 'a'))
else:
    print('UNRESTORABLE')
#print(''.join(Sp).replace('?', 'a') if restorable else 'UNRESTORABLE')

Submission status: Wrong Answer

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

len_Sp = len(Sp)
len_T = len(T)
restorable = False
if len_Sp >= len_T:
    for i in range(len_Sp - len_T, -1, -1):
        for j in range(len_T):
            if Sp[i + j] != '?' and Sp[i + j] != T[j]:
                break
        else:
        	Sp[i : i + len_T] = T
        	restorable = True

print(''.join(Sp).replace('?', 'a') if restorable else 'UNRESTORABLE')

Submission status: Wrong Answer

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

len_Sp = len(Sp)
len_T = len(T)
restorable = False
if len_Sp >= len_T:
    for i in range(len_Sp - len_T + 1):
        for j in range(len_T):
            if Sp[i + j] != '?' and Sp[i + j] != T[j]:
                break
        else:
        	Sp[i : i + len_T] = T
        	restorable = True

print(''.join(Sp).replace('?', 'a') if restorable else 'UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
a=input()
b=input()
la=len(a)
lb=len(b)
ans="UNRESTORABLE"
for i in range(la-lb+1):
  k=1
  for j in range(lb):
    if a[i+j]=="?":
      continue
    if a[i+j]!=b[j]:
      k=0
  if k==1:
    ans=i
if ans=="UNRESTORABLE":
  print(ans)
else:
  print(a[:i].replace("?","a")+b)

Submission status: Wrong Answer

Solution code:
sd = input()
t = input()
lsd = len(sd)
lt = len(t)
for i in range(lsd-lt,-1,-1):
  for j in range(lt):
    if sd[i+j] != "?" and sd[i+j] != t[j]:
      break
  else:
      print((sd[:i]+t+sd[i+lt:]).replace("?","a"))
      break
else:
  print("UNRESTOREBLE")

Submission status: Wrong Answer

Solution code:
sd=input()
t=input()
lsd=len(sd)
lt=len(t)
ans='UNRESTORABLE'
for i in range(lsd-lt,-1,-1):
    for j in range(lt):
        if sd[i+j]!='?' and sd[i+j]!=t[j]:
            break
        else:
            ans=(sd[:i]+t+sd[i+lt:]).replace('?','a')
            break
print(ans)

Submission status: Wrong Answer

Solution code:
sd=input()
t=input()
lsd=len(sd)
lt=len(t)
for i in range(lsd-lt,-1,-1):
    for j in range(lt):
        if sd[i+j]!='?' and sd[i+j]!=t[j]:
            break
    else:
            print((sd[:i]+t+sd[i+lt:]).replace('?','a'))
            break
else:
    print('UNRESTRABLE')

Submission status: Wrong Answer

Solution code:
sd=input()
t=input()
lsd=len(sd)
lt=len(t)
for i in range(lsd-lt,-1,-1):
    for j in range(lt):
        if sd[i+j]!='?' and sd[i+j]!=t[j]:
            break
    else:
            ans=(sd[:i]+t+sd[i+lt:]).replace('?','a')
            break
else:
    print('UNRESTRABLE')

Submission status: Wrong Answer

Solution code:
sd=input()
t=input()
lsd=len(sd)
lt=len(t)
ans='UNRESTRABLE'
for i in range(lsd-lt,-1,-1):
    for j in range(lt):
        if sd[i+j]!='?' and sd[i+j]!=t[j]:
            break
    else:
            ans=(sd[:i]+t+sd[i+lt:]).replace('?','a')
            break
print(ans)

Submission status: Wrong Answer

Solution code:
sd=input()
t=input()
lsd=len(sd)
lt=len(t)
ans='UNRESTRABLE'
for i in range(lsd-lt,-1,-1):
    for j in range(lt):
        if sd[i+j]!='?' and sd[i+j]!=t[j]:
            break
        else:
            ans=(sd[:i]+t+sd[i+lt:]).replace('?','a')
        break
print(ans)

Submission status: Wrong Answer

Solution code:
sd=input()
t=input()
lsd=len(sd)
lt=len(t)
ans='UNRESTRABLE'
for i in range(lsd-lt):
    for j in range(lt):
        if sd[i+j]!='?' and sd[i+j]!=t[j]:
            break
        else:
            ans=(sd[:i]+t+sd[i+lt:]).replace('?','a')
        break
print(ans)

Submission status: Wrong Answer

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

ans = 'UNRESTORABLE'
found = False

for i in range(len(S)-len(T)+1):
    found = True
    for l in range(len(T)):
        if S[i+l] not in ['?', T[l]]:
            found = False
    if found:
        S[i:i+len(S)] = T
        break
if found:
    ans = ''
    
    for s in S:
        if s == '?':
            ans += 'a'
        else:
            ans += s

print(ans)

Submission status: Wrong Answer

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

ans = 'UNRESTORABLE'
found = False

for i in range(len(S)-len(T)):
    found = True
    for l in range(len(T)):
        if S[i+l] not in ['?', T[l]]:
            found = False
    if found:
        S[i:i+len(S)] = T
        break
if found:
    ans = ''
    
    for s in S:
        if s == '?':
            ans += 'a'
        else:
            ans += s

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
# s = 'c?????a'
# t = 'coder'
errorword = 'UNRESTORABLE'

ls=len(s)
lt=len(t)
if ls < lt:
    print(errorword)
else:
    for i in range(ls-lt,-1,-1):
        is_matched = True
        s_slice = slice(i, i+lt)
        print(s[s_slice])
        
#         # すべて？の場合はスキップ
#         if s[s_slice].count('?') == lt:
#             continue

        for s_char, t_char in zip(s[s_slice], t):
            # 文字が不一致かつ？以外の場合は文字列不一致のためbreak
            if (s_char != t_char) and s_char != '?':
                is_matched = False
                break
                
        # ここまでbreakせずに来たら文字列一致のため文字列Sを出力
        if is_matched:
            temp_sl1 = slice(0, i)
            temp_sl2 = slice(i+lt, ls+1)
            out_str = '{}{}{}'.format(s[temp_sl1], t, s[temp_sl2])
            print(out_str.replace('?', 'a'))
            break
    
    if not is_matched:
        print(errorword)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
# s = 'c?????a'
# t = 'coder'
errorword = 'UNRESTORABLE'

ls=len(s)
lt=len(t)
if ls < lt:
    print(errorword)
else:
    for i in range(ls-lt,-1,-1):
        is_matched = True
        s_slice = slice(i, i+lt)
        
        # すべて？の場合はスキップ
        if s[s_slice].count('?') == lt:
            continue

        for s_char, t_char in zip(s[s_slice], t):
            # 文字が不一致かつ？以外の場合は文字列不一致のためbreak
            if (s_char != t_char) and s_char != '?':
                is_matched = False
                break
                
        # ここまでbreakせずに来たら文字列一致のため文字列Sを出力
        if is_matched:
            temp_sl1 = slice(0, i)
            temp_sl2 = slice(i+lt, ls+1)
            out_str = '{}{}{}'.format(s[temp_sl1], t, s[temp_sl2])
            print(out_str.replace('?', 'a'))
            break
    
    if not is_matched:
        print(errorword)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
# s = 'c?????'
# t = 'coder'
errorword = 'UNRESTORABLE'

ls=len(s)
lt=len(t)
if ls < lt:
    print(errorword)
else:
    for i in range(ls-lt,-1,-1):
        is_matched = True
        s_slice = slice(i, lt+2)

        for s_char, t_char in zip(s[s_slice], t):
            # 文字が不一致かつ？以外の場合は文字列不一致のためbreak
            if (s_char != t_char) and s_char != '?':
                is_matched = False
                break
                
        # ここまでbreakせずに来たら文字列一致のため文字列Sを出力
        if is_matched:
            temp_sl1 = slice(0, i)
            temp_sl2 = slice(i+lt, ls+1)
            out_str = '{}{}{}'.format(s[temp_sl1], t, s[temp_sl2])
            print(out_str.replace('?', 'a'))
            break
    
    if not is_matched:
        print(errorword)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
#print(s,t)

if len(s) < len(t):
    print('UNRESTORABLE') 
elif len(s) == len(t):
  for i in range(len(s)):
    if s[i] == t[i] or s[i] == '?':
      continue
    else:
      print('UNRESTORABLE') 
else:
  flag1=0
  for j in range(len(s)-len(t)+1):
    cnt=0
    for i in range(len(t)):
      if s[i+j]==t[i]:
        cnt+=1
      elif s[i+j]=='?':
        cnt+=1
    if cnt==len(t):
      flag1=1
      if j==0:
        s=t+s[len(t):]
      if 0 < j < len(s)-len(t)+1:
        s=s[0:j]+t+s[j+len(t):]
      if j == len(s)-len(t)+1:
        s=s[0:j]+t      
      s=s.replace('?','a')
      print(s)
    
  if flag1==0:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
#print(s,t)

if len(s) < len(t):
    print('UNRESTORABLE') 
elif len(s) == len(t):
  cnt=0
  for i in range(len(s)):
    if s[i] == t[i]:
      cnt+=1
    elif s[i] == '?':
      cnt+=1
  if len(t)==cnt:
    print(t)
  else:
    print('UNRESTORABLE') 
else:
  flag1=0
  for j in range(len(s)-len(t)+1):
    cnt=0
    for i in range(len(t)):
      if s[i+j]==t[i]:
        cnt+=1
      elif s[i+j]=='?':
        cnt+=1
    if cnt==len(t):
      flag1=1
      if j==0:
        s=t+s[len(t):]
      if 0 < j < len(s)-len(t)+1:
        s=s[0:j]+t+s[j+len(t):]
      if j == len(s)-len(t)+1:
        s=s[0:j]+t      
      s=s.replace('?','a')
      print(s)
    
  if flag1==0:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
#print(s,t)

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

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
#print(s,t)

if len(s) < len(t):
    print('UNRESTORABLE') 
elif len(s) == len(t):
  cnt=0
  for i in range(len(s)):
    if s[i] == t[i]:
      cnt+=1
    elif s[i] =='?':
      cnt+=1
  if len(t)==cnt:
    print(t)
  else:
    print('UNRESTORABLE') 
else:
  flag1=0
  for j in range(len(s)-len(t)+1):
    flag=0
    for i in range(len(t)):
      if s[i+j]=='?' or s[i+j]==t[i]:
        flag+=1
    if flag==len(t):
      flag1=1
      s=s[0:j]+t+s[j+len(t):]
      s=s.replace('?','a')
      print(s)
    
  if flag1==0:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
#print(s,t)

if len(s) < len(t):
    print('UNRESTORABLE') 
elif len(s) == len(t):
  for i in range(len(s)):
    if s[i] !='?' and s[i] != t[i]:
      print('UNRESTORABLE')
    else:
      print(t)      
else:
  flag1=0
  for j in range(len(s)-len(t)+1):
    flag=0
    for i in range(len(t)):
      if s[i+j]=='?' or s[i+j]==t[i]:
        flag+=1
    if flag==len(t):
      flag1=1
      s=s[0:j]+t+s[j+len(t):]
      s=s.replace('?','a')
      print(s)
    
  if flag1==0:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
#print(s,t)

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

Submission status: Wrong Answer

Solution code:
#import re

s=input()
t=input()
#print(s,t)

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

Submission status: Wrong Answer

Solution code:
#import re

s=input()
t=input()
#print(s,t)

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

Submission status: Wrong Answer

Solution code:
#import re

s=input()
t=input()
#print(s,t)

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

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
s = len(S)
t = len(T)
list = []
for i in range(s-t+1):
    if S[i] == T[0] or S[i] == "?":
        for j in range(1,t):
            if (S[i+j] == T[j] or S[i+j] =="?") and (j<=t-2):
                continue
            if (j==t-1) and (S[i+j] == T[j] or S[i+j] == "?"):
                a = S
                for l in range(i,i+t):
                    a[l] = T[l-i]
                for k in range(s):
                    if a[k] == "?":
                        a[k] = "a"
                list.append(a)
            if (S[i+j] != "?") and (S[i+j] != T[j]):

                break
        continue
if list == []:
    print("UNRESTORABLE")
else:
 list.sort()
 ans =''
 for x in list[0]:
    ans += x
 print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
change_index = -1

for i in range(len(S)-len(T)+1):
    step = 0
    for j in T:
        if S[i+step] != j and S[i+step] != '?':
            break
        step += 1
        if step == len(T):
            change_index = i

if change_index >= 0 or len(T) == 0:
    Sa_list = list(S.replace('?', 'a'))
    step = 0
    for j in T:
        Sa_list[i+step] = j
        step += 1
    Sa = ''.join(Sa_list)
    print(Sa)
    
else :
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
ans=[]
for i in range(1,len(s)-len(t)+1):
  m=[]
  flag=True
  for p in range(i):
    if s[p]=='?':
      m.append('a')
    else:
      m.append(s[p])
  for q in range(i,len(t)+i):
    if s[q]=='?' or s[q]==t[q-i]:
      m.append(t[q-i])
    else:
      flag=False
      break
  for r in range(len(t)+i,len(s)):
    if flag==False:
      break
    if s[r]=='?':
      m.append('a')
    else:
      m.append(s[r])
  if flag:
    ans.append("".join(m))
ans.sort()
if len(ans)>0:
  print(ans[0])
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
ans=[]
for i in range(1,len(s)-len(t)):
  m=[]
  flag=True
  for p in range(i):
    if s[p]=='?':
      m.append('a')
    else:
      m.append(s[p])
  for q in range(i,len(t)+i):
    if s[q]=='?' or s[q]==t[q-i]:
      m.append(t[q-i])
    else:
      flag=False
      break
  for r in range(len(t)+i,len(s)):
    if flag==False:
      break
    if s[r]=='?':
      m.append('a')
    else:
      m.append(s[r])
  if flag:
    ans.append("".join(m))
ans.sort()
if len(ans)>0:
  print(ans[0])
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

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

for i in range(len(S)-len(T)+1):
    step = 0
    for j in T:
#        if i + step >= len(S):
#            break
        if S[i+step] != j and S[i+step] != '?':
            break
        step += 1
        if step == len(T):
            change_index.append(i)

if len(change_index) or len(T) == 0:
    Sa_list = list(S.replace('?', 'a'))
    for i in change_index:
        step = 0
        for j in T:
            Sa_list[i+step] = j
            step += 1
    Sa = ''.join(Sa_list)
    print(Sa)
else :
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

for i in range(len(S)):
    step = 0
    for j in T:
        if i + step >= len(S):
            break
        if S[i+step] != j and S[i+step] != '?':
            break
        step += 1
        if step == len(T):
            change_index.append(i)

if len(change_index) or len(T) == 0:
    Sa_list = list(S.replace('?', 'a'))
    for i in change_index:
        step = 0
        for j in T:
            Sa_list[i+step] = j
            step += 1
    Sa = ''.join(Sa_list)
    print(Sa)
else :
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

s = list(input())
t = list(input())
a = []

for i in range(len(t)-1,len(s)):
    lock = True
    for j in range(len(t)):
        if s[i-len(t)+j+1] == "?":
            pass
        elif s[i-len(t)+j+1] != t[j]:
            lock = False
    if lock:
        a.append(s[:i-len(t)+1] + t[:])

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

Submission status: Wrong Answer

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

for i in range(len(S)):
    step = 0
    for j in T:
        if i + step >= len(S):
            break
        if S[i+step] != j and S[i+step] != '?':
            break
        step += 1
        if step == len(T):
            change_index.append(i)

if change_index == []:
    print('UNRESTORABLE')
else:
    Sa_list = list(S.replace('?', 'a'))
    for i in change_index:
        step = 0
        for j in T:
            Sa_list[i+step] = j
            step += 1
    Sa = ''.join(Sa_list)
    print(Sa)

Submission status: Wrong Answer

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

for i in range(len(S)):
    step = 0
    for j in T:
        if i + step >= len(S):
            break
        if S[i+step] != j and S[i+step] != '?':
            break
        step += 1
        if step == len(T):
            change_index.append(i)

if change_index is None:
    print('UNRESTORABLE')
else:
    Sa_list = list(S.replace('?', 'a'))
    for i in change_index:
        step = 0
        for j in T:
            Sa_list[i+step] = j
            step += 1
    Sa = ''.join(Sa_list)
    print(Sa)

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
LS = len(S)
LT = len(T)
a = ""
for i in range(LS - LT + 1):
    for j in range(LT):
        if S[i + j] != T[j] and S[i + j] != "?":
            break
        if j == LT - 1:
            for k in range(LT):
                S[i + k] = T[k]
            #print("".join(S))
            s = str("".join(S)).replace("?", "a")
            print(s)
            exit()
# S = S.replace("?", "a")
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
LS = len(S)
LT = len(T)
for i in range(LS - LT + 1):
    for j in range(LT):
        if S[i + j] != T[j] and S[i + j] != "?":
            break
        if j == LT - 1:
            for k in range(LT):
                S[i + k] = T[k]
            s = str(S).replace("?", "a")
            print(S)
            exit()
# S = S.replace("?", "a")
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
ls = len(S)
lt = len(T)
cnt = 0
pos = -1
ans = ''

if ls < lt:
  print('UNRESTORABLE')
  exit()

for i in range(ls-lt+1):
  cnt = 0
  for j in range(lt):
    if S[i+j] == T[j] or S[i+j] == '?':
      cnt += 1
  if cnt == lt:
    pos = i

if pos == -1:
  print('UNRESTORABLE')
  exit()

ans = S[:i] + T + S[i+lt:]
ans = ans.replace('?','a')
print(ans)