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 = list(input())
T = list(input())

ans = 'UNRESTORABLE'
len_s = len(S)
len_t = len(T)

is_matched = False

for i in range(len_s - len_t):
    s = S
    for j in range(len_t):
        sc = s[(-1) - i - j]
        tc = T[(-1) - j]
        if sc == tc or sc == '?':
            s[(-1) - i - j] = tc
            if len_t == (j + 1):
                is_matched = True
        else:
            break
    if  is_matched:
        ans = ''.join(s).replace('?', 'a')
        break
print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
found=False
st=0
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:
    found=True
    st=i
    break

if not found:
  print("UNRESTORABLE")
else:
  ans=s[:st]+t+s[st+len(t):]
  print(ans.replace("?","a"))

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
ans = "UNRESTORABLE"
len_s = len(s)
len_t = len(t)
for i in range(len_s-len_t+1):
  j = len_s-len_t-i
  for S,T in zip(s[j:j+5],t):
    if S != T and S != "?":
      break
  else:
    ans = ""
    for k,TT in enumerate(t):
      s[j+k] = TT
    break
if ans == "UNRESTORABLE":
  print(ans)
else:
  for i in s:
    if i == "?":
      ans += "a"
    else:
      ans += i
  print(ans)

Submission status: Wrong Answer

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

for i in range(len(s)-len(T)+1):
    F=0
    for j in range(len(T)):
        if s[len(s)-1-i-j]==T[len(T)-j-1] or s[len(s)-1-i-j]=="?":
            continue
        else:
            F=1
            break
    if F==0:
        for j in range(len(T)):
            if s[len(s)-1-i-j]=="?":
                s[len(s)-1-i-j]=T[len(T)-j-1]
        
        for j in range(len(s)):
            if s[i]=="?":
                s[i]="a"
        print("".join(s))
        exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import copy
import sys
S = input()
T = input()
if len(T) > len(S):
    print("UNRESTORABLE")
    sys.exit()
I = []
S1 = []
for k in range(len(S)):
    if S[k] == '?':
        S1.append("a")
    else:
        S1.append(S[k])
for i in range(len(S)-len(T) + 1):
    S_ = copy.deepcopy(S1)
    flag = 1
    for j in range(i, i + len(T)):
        if S[j] != T[j-i] and S[j] != "?":
            flag = 0
            break
        else:
            S_[j] = T[j-i]     
    if flag:
        temp = ''.join(S_)
        I.append(temp)
S_ = S_.sort()
if len(I) > 0:
    print(I[-1])
else:
    print("UNRESTORABLE")
print(I)

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
result = False
j=0

for i in range(len(S) - len(T) + 1):
    tmp_s=S
    if(S[i] == T[j] or S[i] == '?'):
        w=0
        for n in range(len(T)):
            if(S[i+n] == T[j+n] or S[i+n] == '?'):
                tmp_s = tmp_s[:i+n] + T[j+n] + tmp_s[i+n+1:]
                w+=1
            else:
                break
        if(w == len(T)):
            result = True
    if(result == True):
        break
    j=0
if(result == True):
    print(tmp_s.replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
def agree(s1, t1):
    for i in range(len(t1)):
        if not(s1[i] == t1[i] or s1[i] =='?'):
            return False
    return True

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

ss =[]
for i in range(ls - lt +1):
    #print(s[i:i+lt], t)
    if agree(s[i:i+lt], t):
        ss.append( (s[:i]+t).replace('?', 'a') )
#print(ss)

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

Submission status: Wrong Answer

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

counter = 0
len_T = len(T)

for index, char in enumerate(S, 1):
    if char == T[counter] or char == "?":
        counter += 1
    else:
        counter = 0
    if counter == len_T:
        ans = S[:index - len_T - 1] + T + S[len_T:]
        print("".join(ans[::-1]).replace("?", "a"))
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

counter = 0
len_T = len(T)

for index, char in enumerate(S, 1):
    if char == T[counter] or char == "?":
        counter += 1
    else:
        counter = 0
    if counter == len_T:
        ans = S[:index - len_T + 1] + T + S[len_T:]
        print("".join(ans[::-1]).replace("?", "a"))
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

counter = 0
len_T = len(T)

for index, char in enumerate(S, 1):
    if char == T[counter] or char == "?":
        counter += 1
    else:
        counter = 0
    if counter == len_T:
        ans = S[:index - len_T] + T + S[len_T:]
        print("".join(ans[::-1]).replace("?", "a"))
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s,t=list(input()),list(input())
length_s,length_t=len(s),len(t)
if length_t>length_s:print("UNRESTORABLE");exit()
flag=0
for i in reversed(range(length_s-length_t+1)):
    word=s[i:i+length_t]
    cnt=0
    for j in range(length_t):
        if word[j]==t[j] or word[j]=="?":
            cnt +=1
        if cnt==length_t:
            flag=1
            s[i:i+length_t]=t

s="".join(s).replace("?","a")
print(s if flag else "UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s,t=list(input()),list(input())
length_s,length_t=len(s),len(t)
flag=0
for i in reversed(range(length_s-length_t+1)):
    word=s[i:i+length_t]
    cnt=0
    for j in range(length_t):
        if word[j]==t[j] or word[j]=="?":
            cnt +=1
        if cnt==length_t:
            flag=1
            s[i:i+length_t]=t

s="".join(s).replace("?","a")
print(s if flag else "UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s,t=list(input()),list(input())
length_s,length_t=len(s),len(t)
if length_t>length_s:print("UNRESTORABLE");exit()
flag=0
add=50
for i in range(length_s-length_t+1):
    word=list(s[i:i+length_t])
    cnt=0
    for j in range(length_t):
        if word[j]==t[j] or word[j]=="?":cnt +=1
        if cnt==length_t:
            flag=1
            add=min(add,i)

s[add:add+length_t]=t
for i in range(length_s):
    if s[i]=="?":s[i]="a"

print("".join(s) if flag==1 else "UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s,t=list(input()),list(input())
length_s,length_t=len(s),len(t)
flag=0
add=50
for i in range(length_s-length_t+1):
    word=list(s[i:i+length_t])
    cnt=0
    for j in range(length_t):
        if word[j]==t[j] or word[j]=="?":cnt +=1
        if cnt==length_t:
            flag=1
            add=min(add,i)

s[add:add+length_t]=t
for i in range(length_s):
    if s[i]=="?":s[i]="a"

print("".join(s) if flag==1 else "UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s,t=list(input()),list(input())
length_s,length_t=len(s),len(t)
flag=0
for i in range(length_s-length_t+1):
    word=list(s[i:i+length_t])
    cnt=0
    for j in range(length_t):
        if word[j]==t[j] or word[j]=="?":cnt +=1
        if cnt==length_t:
            flag=1
            s[i:i+length_t]=t

for i in range(length_s):
    if s[i]=="?":s[i]="a"

print("".join(s) if flag==1 else "UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys


def main():
    S = list(input())[::-1]
    T = list(input())[::-1]
    d = len(S) - len(T)

    for i in range(d):
        cnt = 0
        for j in range(len(T)):
            if S[i+j] == T[j] or S[i+j] == '?':
                cnt += 1

        if cnt == len(T):
            for k in range(len(T)):
                S[i+k] = T[k]
            break

    else:
        print('UNRESTORABLE')
        sys.exit()

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

    print(''.join(S)[::-1])


main()

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
len_S = len(S)
len_T = len(T)
qc = 0
ans = ''
for i in range(len_S-1, -1, -1):
    si = S[i]
    if si == '?':
        qc += 1
    else:
        qc = 0
    if qc == len_T:
        ans = ans = S[:i] + T + S[i+len_T:]
        break
    if si == T[0] and len_S - i >= len_T:
        flag = True
        for ii in range(1, len_T):
            if T[ii] == S[i+ii] or S[i+ii] == '?':
                continue
            else:
                flag = False
                break
        if flag:
            ans = S[:i] + T + S[i+len_T:]
            break

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

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
len_S = len(S)
len_T = len(T)
qc = 0
ans = ''
for i in range(len_S-1, -1, -1):
    print(i, S[i])
    si = S[i]
    if si == '?':
        qc += 1
    else:
        qc = 0
    if qc == len_T:
        ans = ans = S[:i] + T + S[i+len_T:]
        break
    if si == T[0] and len_S - i >= len_T:
        print(T)
        flag = True
        for ii in range(1, len_T):
            print(ii, S[i+ii])
            if T[ii] == S[i+ii] or S[i+ii] == '?':
                continue
            else:
                flag = False
                break
        if flag:
            ans = S[:i] + T + S[i+len_T:]
            break

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

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
score = 0
for i in range(len(s)-len(t)+1):
  cut = s[-len(t)-i:len(s)-i]
  
  for j in range(len(t)):
    if cut[j] == t[j] or cut[j] =="?":
      score += 1
  if score == len(t):
    s = s[:-len(t)-i] + t + s[len(t)-i+2:]
    print(s.replace("?","a"))
    exit()
  score = 0
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
score = 0
for i in range(len(s)-len(t)+1):
  cut = s[i:i+len(t)]
  for j in range(len(t)):
    if cut[j] == t[j] or cut[j] =="?":
      score += 1
  if score == len(t):
    s = s[:i] + t + s[i+len(t):]
    print(s.replace("?","a"))
    exit()
  score = 0
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
a = list(input())
b = list(input())
c = len(a)
d = len(b)
if d > c:
    print("UNRESTORABLE")
    exit()
flag = False
for i in range(c-d+1):
    li = [0]*c
    for k in range(c):
        li[k] = a[k]
    for j in range(d):
        if b[j] == a[i+j] or a[i+j] == "?":
            flag = True
            li[i+j] = b[j]
        elif b[j] != a[i+j]:
            flag = False
            break
    else:
        continue
for i in range(c):
    if li[i] == "?":
        li[i] = "a"

if flag:
    print("".join(li))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

fin=[]

flag=0
for i in range(len(s)-len(t)+1):
    if(s[i]==t[0]):
        ind=0
        f=1
        for j in range(i,i+len(t)):
            if(s[j]!='?' and s[j]!=t[ind]):
                f=0
                break
            ind+=1
        ind=0
        temp = s[:]
        if(f==1):
            flag=1
            for j in range(i,i+len(t)):
                if(s[j]=='?'):
                    temp[j]=t[ind]
                ind+=1
            fin.append(temp)
if(flag==0):
    print('UNRESTORABLE')
else:
    for i in range(len(fin)):
        for j in range(len(fin[i])):
            if(fin[i][j]=='?'):
                fin[i][j]='a'
    fin.sort()
    print(''.join(fin[0]))

Submission status: Wrong Answer

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

flag=0
for i in range(len(s)-len(t)+1):
    if(s[i]==t[0]):
        ind=0
        f=1
        for j in range(i,i+len(t)):
            if(s[j]!='?' and s[j]!=t[ind]):
                f=0
                break
            ind+=1
        ind=0
        if(f==1):
            flag=1
            for j in range(i,i+len(t)):
                if(s[j]=='?'):
                    s[j]=t[ind]
                ind+=1
            break
if(flag==0):
    print('UNRESTORABLE')
else:
    for i in range(len(s)):
        if(s[i]=='?'):
            s[i]='a'
    print(''.join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
f = 0
for i in range(len(s)-len(t)+1):
  for j,k,l in zip(s[i:i+len(t)],t,range(len(t))):
    if j != k and j != '?':
      break
    if l == len(t) -1:
      f = i
if f:
  s[f:f+len(t)] = t
  for i in range(len(s)):
    if s[i] == '?':
      s[i] = 'a'
  print(*s,sep='')
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
def printAns(n):
    k = 0
    while k < len(S):
        if k < n or n+len(T)-1 < k:
            if S[k] != "?":
                print(S[k],end="")
            else:
                print("a",end="")
        else:
            print(T,end="")
            k = n+len(T)
            continue
        k += 1

S = input()
T = input()
listS = []
ans = ""
id = -1
for i in range(len(S)):
    if i+len(T) < len(S)+1:
        listS.append(S[i:i+len(T)])
for i in range(len(listS)):
    for j in range(len(T)):
        if listS[i][j] == T[j] or listS[i][j] == "?":
            if j == len(T)-1:
                id = max(id,i)
            continue
        else:
            break
if id > 0:
    printAns(id)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

n = len(s)
m = len(t)
if n < m:
  print("UNRESTORABLE")
x = -1
for i in range(n-m+1):
  for j in range(m):
    if s[n-j-i-1] == "?" or s[n-j-i-1] == t[m-j-1]:
      continue
      #print("{} {}".format(i,j))
    else:
      #print("break1")
      #print(j)
      #print(s[n-j-i])
      #print(t[m-j-1])
      break
  else:
    x = i
    #print("break2")
    break
#print(x)
if x == -1:
  print("UNRESTORABLE")
else:
  ans = s[:n-m-x]+t+s[n-x:]
  #print(ans)
  for i in range(n):
    if ans[i] == "?":
      ans = ans[:i] + "a" + ans[i+1:]
  print(ans)

Submission status: Wrong Answer

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

n = len(s)
m = len(t)
if n < m:
  print("UNRESTORABLE")
x = -1
for i in range(n-m):
  for j in range(m):
    if s[n-j-i-1] == "?" or s[n-j-i-1] == t[m-j-1]:
      continue
    else:
      #print("break1")
      #print(j)
      #print(s[n-j-i])
      #print(t[m-j-1])
      break
  else:
    x = i
    break
#print(x)
if x == -1:
  print("UNRESTORABLE")
else:
  ans = s[:n-m-x]+t+s[n-x:]
  #print(ans)
  for i in range(n):
    if ans[i] == "?":
      ans = ans[:i] + "a" + ans[i+1:]
  print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
t_len = len(T)
s_len = len(S)
output_list = [''] * len(S)

flag = True
#何も操作をせずにTが存在する場合
for i in reversed(range(len(S)-t_len-1)):
    if S[i:t_len] == T:
        flag = False
       
flag_2 = False
flag_3 = False
if flag:
    for i in reversed(range(s_len-t_len+1)):
        #print(i)
        text = S[i:i+t_len]
        for j in range(t_len):
            if not ( text[j] == T[j] or text[j] == '?' ):
                break 
            if j == t_len-1:
                flag_2 = True
                for s in range(t_len):
                    output_list[i+s] = T[s]
        if flag_2:
            break
        if i == 0:
            flag_3 = True

if flag_3:
    print('UNRESTORABLE')
else:
    for i in range(len(S)):
        if output_list[i] != '':
            continue
        elif  S[i] == '?':
            output_list[i] = 'a'
        else:
            output_list[i] = S[i]
    print(''.join(map(str,output_list)))

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
t_len = len(T)
s_len = len(S)
output_list = [''] * len(S)

flag = True
#何も操作をせずにTが存在する場合
for i in reversed(range(len(S)-t_len-1)):
    if S[i:t_len] == T:
        flag = False
       
flag_2 = False
flag_3 = False
if flag:
    for i in reversed(range(s_len-t_len+1)):
        text = S[i:i+t_len]
        for j in range(t_len):
            if not ( text[j] == T[j] or text[j] == '?' ):
                break 
            if j == t_len-1:
                flag_2 = True
                for s in range(t_len):
                    output_list[i+s] = T[s]
        if flag_2:
            break
        if i == s_len-t_len:
            flag_3 = True

if flag_3:
    print('UNRESTORABLE')
else:
    for i in range(len(S)):
        if output_list[i] != '':
            continue
        elif  S[i] == '?':
            output_list[i] = 'a'
        else:
            output_list[i] = S[i]
    print(''.join(map(str,output_list)))

Submission status: Wrong Answer

Solution code:
def is_matched(i, inputS, T):
  for s,t in zip(inputS, T):
    if s == '?': continue
    if s != t: return False
  return True

S, T = input(), input()
lenS, lenT = len(S), len(T)
matched_i = None
ans = []
for i in range(lenS-lenT+1):
  if is_matched(i, S[i:i+lenT], T):
    ans.append(''.join([s for s in S[:i].replace('?', 'a') + T + S[i+lenT+1:].replace('?', 'a')]))
  
if ans == []: print('UNRESTORABLE')
else: print(sorted(ans)[0])

Submission status: Wrong Answer

Solution code:
def printAns(n):
    k = 0
    while k < len(S):
        if k < n or n+len(T)-1 < k:
            if S[k] != "?":
                print(S[k],end="")
            else:
                print("a",end="")
        else:
            print(T,end="")
            k = n+len(T)
            continue
        k += 1

S = input()
T = input()
listS = []
ans = ""
for i in range(len(S)):
    if i+len(T) < len(S)+1:
        listS.append(S[i:i+len(T)])
listS = listS[::-1]
for s in listS:
    for j in range(len(T)):
        if s[j] == T[j] or s[j] == "?":
            if j == len(T)-1:
                id = listS.index(s)
                printAns(id)
                exit()
            continue
        else:
            break
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def printAns(n):
    k = 0
    while k < len(S):
        if k < n or n+len(T)-1 < k:
            if S[k] != "?":
                print(S[k],end="")
            else:
                print("a",end="")
        else:
            print(T,end="")
            k = n+len(T)
            continue
        k += 1

S = input()
T = input()
listS = []
ans = ""
for i in range(len(S)):
    if i+len(T) < len(S)+1:
        listS.append(S[i:i+len(T)])
for s in listS:
    for j in range(len(T)):
        if s[j] == T[j] or s[j] == "?":
            if j == len(T)-1:
                id = listS.index(s)
                printAns(id)
                exit()
            continue
        else:
            break
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
i = 0
j = 0
flg = False
while i < len(S) and j < len(T):
    if S[i] == T[j] or S[i] == "?":
            if j == len(T)-1:
                startId = i-j-1
                flg = True
                i = len(S)
                break
            j += 1
    else:
        j = 0
    i += 1

if flg:
    for k in range(len(S)):
        if S[k] != "?":
            print(S[k],end="")
        elif startId <= k and k <= startId+len(T):
            print(T[k-startId-1],end="")
        else:
            print("a",end="")
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def is_matched(i, inputS, T):
  for s,t in zip(inputS, T):
    if s == '?': continue
    if s != t: return False
  return True

S, T = input(), input()
lenS, lenT = len(S), len(T)
matched_i = None
for i in range(lenS-lenT+1):
  if is_matched(i, S[i:i+lenT], T):
    matched_i = i
  #print(i, is_matched(i, S[i:i+lenT], T))
if matched_i is None: print('UNRESTORABLE')
else: print(''.join([s for s in S[:matched_i].replace('?', 'a') + T + S[matched_i+lenT+1:].replace('?', 'a')]))

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
candidate = []
for i in range(len(s) - len(t) + 1):
    can = True
    for j in range(len(t)):
        if s[i + j] == "?" or s[i + j] == t[j]:
            continue
        else:
            can = False
            break
    if can:
        res = []
        for j in range(i):
            if s[j] == "?":
                res.append("a")
            else:
                res.append(s[j])
        for j in range(len(t)):
            res.append(t[j])
        for j in range(len(s) - len(t) - i):
            if s[j + len(t) + i] == "?":
                res.append("a")
            else:
                res.append(s[j + len(t) + i])
        candidate.append("".join(res))

if len(candidate) != 0:
    candidate.sort()
    print(candidate[-1])

else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
from sys import stdin

s, t = stdin.read().split()
s = list(s)

possible_indexes = []
for i in range(len(s) - len(t) + 1):
    substring = s[i: i+len(t)]
    for j in range(len(t)):
        if substring[j] == t[j] or substring[j] == '?': continue
        else: break
    else:
        possible_indexes.append(i)

if not possible_indexes: print('UNRESTORABLE'); exit()

ma = min(possible_indexes)
for j in range(len(t)):
    s[ma+j] = t[j]
    print(s)

s = ''.join(s)

s = s.replace('?', 'a')
print(s)

Submission status: Wrong Answer

Solution code:
from sys import stdin

s, t = stdin.read().split()
s = list(s)

possible_indexes = []
for i in range(len(s) - len(t) + 1):
    substring = s[i: i+len(t)]
    for j in range(len(t)):
        if substring[j] == t[j] or substring[j] == '?': continue
        else: break
    else:
        possible_indexes.append(i)

if not possible_indexes: print('UNRESTORABLE'); exit()

ma = max(possible_indexes)
for j in range(len(t)):
    s[ma+j] = t[j]
    print(s)

s = ''.join(s)

s = s.replace('?', 'a')
print(s)

Submission status: Wrong Answer

Solution code:
import sys
import re
input = sys.stdin.readline

Sd = input().strip()
T = input().strip()

def same(s, t):
    s = re.sub('\?', '.', s)
    return re.match(s, t)

flag = False
for i in range(len(T), len(Sd) + 1):
    if same(Sd[len(Sd) - i:len(Sd) - i + len(T) + 1], T):
        Sd = Sd[:len(Sd) - i] + T + Sd[len(Sd) - i + len(T) + 1:]
        flag = True
        break

if flag:
    Sd = re.sub('\?', 'a', Sd)
else:
    Sd = 'UNRESTORABLE'

print(Sd)

Submission status: Wrong Answer

Solution code:
S_d,T = list(input()),list(input())

if len(S_d) < len(T):
  print("UNRESTORABLE");exit()

flag = 1
for i in range(len(T),len(S_d)):
  for j in range(len(T)):
    if S_d[-i+j] != T[j] and S_d[-i+j] != "?":
      flag = 0
      break
  if flag == 1:
    for j in range(len(T)):
      S_d[-i+j] = T[j]
    break
      
if flag == 1:
  for a in S_d:
    if a == "?":
      print("a",end="")
    else:
      print(a,end="")
  print()
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S_d,T = list(input()),list(input())

flag = 1
for i in range(len(T),len(S_d)):
  for j in range(len(T)):
    if S_d[-i+j] != T[j] and S_d[-i+j] != "?":
      flag = 0
      break
  if flag == 1:
    for j in range(len(T)):
      S_d[-i+j] = T[j]
    break
      
if flag == 1:
  for a in S_d:
    if a == "?":
      print("a",end="")
    else:
      print(a,end="")
  print()
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def main():
    s=list(input())
    t=list(input())
    key=0
    index=0
    if len(s)<len(t):
        print("UNRESTORABLE")
        return
    key2=0
    for i in range(len(s)-len(t)+1):
        if s[i]==t[0]:
            for j in range(len(t)-1):
                if s[i+j+1]!="?" and s[i+j+1]!=t[1+j]:
                    key2=1
                    break
            if key2==0:
                index=i
                key=1
            key2=0
    if key==0:
        print("UNRESTORABLE")
        return
    for i in range(len(t)):
        s[index+i]=t[i]
    for i in range(len(s)):
        if s[i]=="?":
            s[i]="a"
    print(''.join(s))
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    s=list(input())
    t=list(input())
    key=0
    index=0
    if len(s)<len(t):
        print("UNRESTORABLE")
        return
    key2=0
    for i in range(len(s)-len(t)+1):
        if s[i]==t[0]:
            for j in range(len(t)-1):
                if s[i+j+1]!="?" and s[i+j+1]!=t[1+j]:
                    print("a")
                    key2=1
                    break
            if key2==0:
                index=i
                key=1
            key2=0
    if key==0:
        print("UNRESTORABLE")
        return
    for i in range(len(t)):
        s[index+i]=t[i]
    for i in range(len(s)):
        if s[i]=="?":
            s[i]="a"
    print(''.join(s))
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    s=list(input())
    t=list(input())
    key=0
    index=0
    if len(s)<len(t):
        print("UNRESTORABLE")
        return
    for i in range(len(s)-len(t)+1):
        if s[i]==t[0]:
            for j in range(len(t)-1):
                if s[i+j+1]!="?" and s[i+j+1]!=t[1+j]:
                    break
            index=i
            key=1
    if key==0:
        print("UNRESTORABLE")
        return
    for i in range(len(t)):
        s[index+i]=t[i]
    for i in range(len(s)):
        if s[i]=="?":
            s[i]="a"
    print(''.join(s))
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
def main():
    s=list(input())
    t=list(input())
    key=0
    index=0
    for i in range(len(s)-len(t)+1):
        if s[i]==t[0]:
            for j in range(len(t)-1):
                if s[i+j+1]!=t[1+j]:
                    break
            index=i
            key=1
    if key==0:
        print("UNRESTORABLE")
        return
    for i in range(len(t)):
        s[index+i]=t[i]
    for i in range(len(s)):
        if s[i]=="?":
            s[i]="a"
    print(''.join(s))
if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

def check_context(a, b):
    ss = s.copy()
    if a <= b:
        return []
    if len(s[a:]) < len(t[b:]):
        return []
    ss[a-b:a-b+len(t)] = t[:]
    return ss


x = []
for i in range(len(s)):
    for j in range(len(t)):
        if s[i] == t[j]:
            x = check_context(i, j)
            if x:
                for k in range(len(x)):
                    if x[k] == '?':
                        x[k] = 'a'

if x:
    for i in x:
        print(i, end='')
elif x == []:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
n = len(s)
m = len(t)
ans = []
for i in range(n-m+1):
    flag = True
    for j in range(m):
        if s[i+j]!="?" and s[i+j]!=t[j]:
            flag = False
            break
    if flag:
        tmp = (s[:i] + t + s[(i+m):])
        print(tmp)
        a = []
        for j in range(n):
            if tmp[j]=="?":
                a.append("a")
            else:
                a.append(tmp[j])
        tmp = "".join(a)
        ans.append(tmp)

ans.sort()

if len(ans)>0:
    print(ans[0])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
n = len(s)
m = len(t)
i = 0
j = 0
point = []
if n<m:
    print("UNRESTORABLE")
    exit()
while i<n:
    if s[i]==t[j] or s[i]=="?":
        j+=1
        i+=1
    else:
        j=0
        i+=1

    if j==m:
        point.append(i-m)
        j = 0
        i = i-m+1
if len(point)==0:
    print("UNRESTORABLE")
    exit()
i = 0
ans = []
for l in range(len(point)):
    x = "".join(s)
    ans.append(list(x))
    while i<n:
        if ans[l][i]=="?" and i!=point[l]:
            ans[l][i]="a"
            i +=1
        elif i==point[l]:
            for k in range(m):
                ans[l][i+k]=t[k]
            i = i+m
        else:
            i+=1
ans.sort()
print("".join(ans[0]))

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
n = len(s)
m = len(t)
i = 0
j = 0
point = []
if n<m:
    print("UNRESTORABLE")
    exit()
while i<n:
    if s[i]==t[j] or s[i]=="?":
        j+=1
        i+=1
    else:
        j=0
        i+=1

    if j==m:
        point.append(i-m)
        j = 0
if len(point)==0:
    print("UNRESTORABLE")
    exit()
i = 0
ans = []
for l in range(len(point)):
    x = "".join(s)
    ans.append(list(x))
    while i<n:
        if ans[l][i]=="?" and i!=point[l]:
            ans[l][i]="a"
            i +=1
        elif i==point[l]:
            for k in range(m):
                ans[l][i+k]=t[k]
            i = i+m
        else:
            i+=1
ans.sort()
print("".join(ans[0]))

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
n = len(s)
m = len(t)
i = 0
j = 0
point = []
if n<m:
    print("UNRESTORABLE")
    exit()
while i<n:
    if s[i]==t[j] or s[i]=="?":
        j+=1
        i+=1
    else:
        j=0
        i+=1

    if j==m:
        point.append(i-m)
        j = 0
if len(point)==0:
    print("UNRESTORABLE")
    exit()
i = 0
x = "".join(s)
x = list(x)
ans = [x]*len(point)
for l in range(len(point)):
    while i<n:
        if ans[l][i]=="?" and i!=point[l]:
            ans[l][i]="a"
            i +=1
        elif i==point[l]:
            for k in range(m):
                ans[l][i+k]=t[k]
            i = i+m
        else:
            i+=1
ans.sort()
print("".join(ans[0]))

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
n = len(s)
m = len(t)
i = 0
j = 0
point = 60
if n<m:
    print("UNRESTORABLE")
    exit()
while i<n:
    if s[i]==t[j] or s[i]=="?":
        j+=1
        i+=1
    else:
        j=0
        i+=1

    if j==m:
        point = i-m
        break
if point==60:
    print("UNRESTORABLE")
    exit()
i = 0
while i<n:
    if s[i]=="?" and i!=point:
        s[i]="a"
        i +=1
    elif i==point:
        for k in range(m):
            s[i+k]=t[k]
        i = i+m
    else:
        i+=1
print("".join(s))

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
n = len(s)
m = len(t)
i = 0
j = 0
point = 60
while i<n:
    if s[i]==t[j] or s[i]=="?":
        j+=1
        i+=1
    else:
        j=0
        i+=1

    if j==m:
        point = i-m
        break
if point==60:
    print("UNRESTORABLE")
    exit()
i = 0
while i<n:
    if s[i]=="?" and i!=point:
        s[i]="a"
        i +=1
    elif i==point:
        for k in range(m):
            s[i+k]=t[k]
        i = i+m
    else:
        i+=1
print("".join(s))