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: Runtime Error

Solution code:
s=input()
t=input()
ls=len(s)
lt=len(t)
if ls<lt:
  print("UNRESTORABLE")
  exit()
for i in range(ls-lt,-1,-1):
  for j in range(i,i+lt):
    if s[j]==t[j] or s[j]=="?":
      continue
    else:
      break
  else:
    for k in range(i,i+lt):
      s[k]=t[k]
    for l in range(ls):
      if s[l]=="?":
        s[l]="a"
    print(s)
    exit()
else:
  print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
def getLastMatch(s,t):
    for i in range(len(s)-len(t), -1, -1):
        if s[i] == '?' or s[i] == t[0]:
            match = True
            for j in range(len(t)):
                if s[i+j] == '?': continue
                if s[i+j] != t[j]:
                    match = False
                    break
            if match: return i
    return -1

s,t = input(), input()
lastMatch = getLastMatch(s,t)
if lastMatch == -1:
    print('UNRESTORABLE')
else:
    for i in range(len(s)):
        if i >= lastMatch:
            print(t[i-lastMatch],end='')
            continue
        
        if s[i] == '?': print('a',end='')
        else: print(s[i],end='')
    print()

Submission status: Runtime Error

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

ans = "UNRESTORABLE"

ls = []

for i in range(len(t)):
    for j in range(i, len(s)-len(t)+i+1):
        if s[j] == t[i]:
            for k in range(len(t)):
                if t[i+k] != s[j+k] and s[j+k] != "?":
                    break
                if k == len(t)-1:
                    tmps = s[:j-i] + t + s[j-i+len(t):]
                    for p in range(len(s)):
                        if tmps[p] == "?":
                            tmps = tmps[:p] + "a" + tmps[p+1:]
                    ls.append(tmps)

ls.sort()
if len(ls) != 0:
    ans = ls[0]

print(ans)

Submission status: Runtime Error

Solution code:
import sys
import os
f = open('/Users/murakiyusuke/coding/atcoder/input.txt','r')
sys.stdin = f

S=input()
T=input()

def match(S,T):
    for i in range(len(T)):
        if S[i]==T[i] or S[i]=='?':
            continue
        else:
            return False
    return True

if len(T)>len(S):
    print('UNRESTORABLE')
    exit()

S=S[::-1]
T=T[::-1]   
p=len(S)-len(T)+1
for i in range(p):
    sub = S[i:i+len(T)]
    if match(sub,T):
        S1=S.replace(sub,T,1).replace('?','a')
        print(S1[::-1])
        exit()
print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
ss, t = input(), input()
lt = len(t)
lss = len(ss)

for i in range(0, lss - lt + 1):
  tss = ss[i : i + lt]
  tb = True
  for a, b in zip(tss, t):
    if a == '?':
      continue
    elif a != b:
      tb = False
      break
  if tb:
    ss = ss[: i] + t + ss[i + lt:]
    break
if tb:
  print(ss.replace('?', 'a'))
else:
  print('UNRESTORABLE')

Submission status: Runtime Error

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

import sys

j = 0
flag = 0
check = 0

while j < len(S):
    flag = S.find(T[0],j)
    if flag != -1:
        for i in range(len(T)-1):
            if S[flag+1+i] == '?' or S[flag+1+i] == T[i+1]:
                check += 1
        if check == len(T)-1:
            Snew = S[:flag] + T + S[flag+len(T):]
            break
        else:
            check = 0
            j = flag + len(T)
    else:
        print('UNRESTORABLE')
        sys.exit()
            
for i in range(len(S)):
    if Snew[i] == '?':
        print('a', end="")
    else:
        print(Snew[i], end="")

Submission status: Runtime Error

Solution code:
def ABC076C_DubiousDocument2():
    Sd = list(input().strip())
    T = list(input().strip())

    tlen = len(T)
    slen = len(Sd)

    ans = 'UNRESTORABLE'
    nowPos = 0
    for pos in range(slen - 1, -1, -1):
        if pos < (tlen - 1):
            break
        if(T[tlen - (slen - 1 - pos) - 1] == Sd[pos]) or (Sd[pos] == '?'):
            nowPos = pos
            match = True
            for chk in range(nowPos, nowPos - tlen, -1):
                if(T[tlen - (nowPos - chk) - 1] != Sd[chk]) and (Sd[chk] != '?'):
                    match = False
                    break

            if match:
                # 書き換え
                for chk in range(nowPos, nowPos - tlen, -1):
                    Sd[chk] = T[tlen - (nowPos - chk) - 1]
                for i in range(0, slen):
                    if Sd[i] == '?':
                        Sd[i] = 'a'
                # 答えはこれ
                ans = ''.join(Sd)

    print(ans)

def main():
    ABC076C_DubiousDocument2()

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
def ABC076C_DubiousDocument2():
    Sd = list(input().strip())
    T = list(input().strip())

    tlen = len(T)
    slen = len(Sd)

    ans = 'UNRESTORABLE'
    nowPos = 0
    for pos in range(slen - 1, -1, -1):
        if pos < tlen:
            break
        if(T[tlen - (slen - 1 - pos) - 1] == Sd[pos]) or (Sd[pos] == '?'):
            nowPos = pos
            match = True
            for chk in range(nowPos, nowPos - tlen, -1):
                if(T[tlen - (nowPos - chk) - 1] != Sd[chk]) and (Sd[chk] != '?'):
                    match = False
                    break

            if match:
                # 書き換え
                for chk in range(nowPos, nowPos - tlen, -1):
                    Sd[chk] = T[tlen - (nowPos - chk) - 1]
                for i in range(0, slen):
                    if Sd[i] == '?':
                        Sd[i] = 'a'
                # 答えはこれ
                ans = ''.join(Sd)

    print(ans)

def main():
    ABC076C_DubiousDocument2()

if __name__ == "__main__":
    main()

Submission status: Runtime Error

Solution code:
S = input()
T = input()
count = 0
flg = False
while True:
    flg = False
    for i in range(1,len(T)+1):
        if S[-i-count] != T[-i] and S[-i-count] != '?':
            count += 1
            flg = True
            break
    if count == len(S) - len(T) + 1:
        print('UNRESTORABLE')
        exit()
    if not flg:
        if count == 0:
            ans = S[0:len(S)-len(T)] + T
        elif count == len(S)-len(T):
            ans = T + S[len(T):]
        else:
            ans = S[0:len(S)-len(T)-count] + T + S[-count:]
        print(ans.replace('?','a'))
        exit()

Submission status: Runtime Error

Solution code:
S = input()
T = input()
count = 0
flg = False
while True:
    flg = False
    for i in range(1,len(T)+1):
        if S[-i-count] != T[-i] and S[-i-count] != '?':
            count += 1
            flg = True
            break
    if count == len(S) - len(T):
        print('UNRESTORABLE')
        exit()
    if not flg:
        if count == 0:
            ans = S[0:len(S)-len(T)] + T
        elif count == len(S)-len(T):
            ans = T + S[:-len(S)+len(T)]
        else:
            ans = S[0:len(S)-len(T)-count] + T + S[-count:]
        print(ans.replace('?','a'))
        exit()

Submission status: Runtime Error

Solution code:
S = input()
T = input()
count = 0
flg = False
while True:
    flg = False
    for i in range(1,len(T)+1):
        if S[-i-count] != T[-i] and S[-i-count] != '?':
            count += 1
            flg = True
            break
    if count == len(S) - len(T):
        print('UNRESTORABLE')
        exit()
    if not flg:
        if count == 0:
            ans = S[0:len(S)-len(T)] + T
        elif count == len(S)-len(T):
            ans = T + S[:-len(S)+len(T)]
        else:
            ans = S[0:len(S)-len(T)-1] + T + S[-count:]
        print(ans.replace('?','a'))
        exit()

Submission status: Runtime Error

Solution code:
S = input()
T = input()
count = 0
flg = False
while True:
    flg = False
    for i in range(1,len(T)+1):
        if S[-i-count] != T[-i] and S[-i-count] != '?':
            count += 1
            flg = True
            break
    if count == len(S) - len(T):
        print('UNRESTORABLE')
        exit()
    if not flg:
        if count == 0:
            ans = S[0:len(S)-len(T)] + T
        elif count == len(S)-len(T):
            ans = T + S[:-len(S)+len(T)]
        else:
            ans = S[0:len(S)-len(T)-1] + T + S[-count:]
        print(ans)
        exit()

Submission status: Runtime Error

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

n=len(sd)
m=len(t)
s=[]

for i in range(n-m,-1,-1):
    t_kamo=sd[i:i+m]
    for j in range(m+1):
        if j==m:
            print((sd[:i]+t+sd[i+m:]).replace("?","a"))
        if t_kamo[j]=="?":
            continue
        elif t_kamo[j]!=t[j]:
            break
print("UNRESTORABLE")

Submission status: Runtime Error

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

n=len(sd)
m=len(t)
s=[]

for i in range(n-m,-1,-1):
    t_kamo=sd[i:i+m]
    for j in range(m+1):
        if j==m:
            print((sd[:i]+t+sd[i+m:]).replace("?","a"))
        if k_kamo[j]=="?":
            continue
        elif k_kamo[j]!=t[j]:
            break
print("UNRESTORABLE")

Submission status: Runtime Error

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

for i in range(len(S) - len(T) + 1):
    if S[i] == "?" or S[i] == T[0]:
        k = 1
        flag = True
        while k < len(T):
            if S[i+k] == "?":
                k += 1
            else:
                if S[i + k] == T[k]:
                    k += 1
                else:
                    flag = False
                    break
        if k == len(T) and flag == True:
            check = i

if check != -1:
    S = list(S)
    for i in range(len(T)):
        S[check + i] = T[i]
    S = "".join(S)
    ans = S.replace("?", "a")
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
# ABC076C
S = input()
T = input()
check = -1
flag = True
for i in range(len(S)):
    flag = True
    if S[i] != T[0]:
        continue
    k = 1
    while k < len(T):
        if S[i+k] == "?":
            k += 1
        else:
            if S[i+k] == T[k]:
                k += 1
            else:
                flag = False
                break        
    if k == len(T) and flag == True:
        check = i

if check != -1:
    S = list(S)
    for i in range(len(T)):
        S[check + i] = T[i]
    S = "".join(S)
    ans = S.replace("?", "a")
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

ans = 0
if m >= n:
    for i in range(m+1-n):
        for j in range(n):
            if S[i+j] != T[j] and S[i+j] != "?":
                break
        else:
            S = S[0:i] + T + S[i+n+1:]
            ans = 1

if ans == 1:
    print(S.replace("?", "a"))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

sl = list(S)
tl = list(T)
n = len(tl)
w = "?" * n

ans = 0
if len(S) >= n:
    if w in S:
        ans = 1
        S.replace(w, T)
        sl = list(S)
    for i in range(n):
        if tl[i] in sl:
            j = sl.index(tl[i])
            #print(j, tl[i])
            sl2 = sl[j-i:j]
            sl2.extend(sl[j+1:j+n-i])
            #print(sl2)
            tl2 = tl[0:i]
            tl2.extend(tl[i+1:])
            #print(tl2)
            #print(sl2)
            # #print(tl)
            for k in range(len(tl2)):
                if  sl2[k] != tl2[k] and sl2[k] != "?":
                    break
                ans = 1
                sl[j-i:j] = tl2[0:i]
                sl[j+1:j+n-i] = tl[i+1:] 
#print(ans)
S = "".join(sl)
#print(S)

if ans == 1:
    A = S.replace("?", "a")
    print(A)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

sl = list(S)
tl = list(T)
n = len(tl)
w = "?" * n

ans = 0

if w in S:
  ans = 1
  S.replace(w, T)
  sl = list(S)
for i in range(n):
    if tl[i] in sl:
        j = sl.index(tl[i])
        try:
            sl2 = sl[j-i:j+n-i]
        except:
            continue
        #print(sl2)
        # #print(tl)
        for k in range(n):
            if  sl2[k] != tl[k] and sl2[k] != "?":
                break
            ans = 1
            sl[j-i:j+n-i] = T

S = "".join(sl)
#print(S)

if ans == 1:
    A = S.replace("?", "a")
    print(A)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

sl = list(S)
tl = list(T)
n = len(tl)
w = "?" * n

ans = 0

if w in S:
  ans = 1
  S.replace(w, T)
  sl = list(S)
for i in range(n):
  if tl[i] in sl:
    j = sl.index(tl[i])
    sl2 = sl[j-i:j+n-i]
    #print(sl2)
    #print(tl)
    for k in range(n):
      if  sl2[k] != tl[k] and sl2[k] != "?":
        break
      ans = 1
      sl[j-i:j+n-i] = T

S = "".join(sl)
#print(S)

if ans == 1:
    A = S.replace("?", "a")
    print(A)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

s_len =len(S)
t_len =len(T)

for head in range(len(S)-t_len,0,-1):
    flg=True
    for s,t in zip(S[head:head+t_len],T):
        if not(s==t or "?"==s):
            flg=False
    if flg:
        break


if flg:
    S=list(S)
    S[head:head+t_len] = T
    S="".join(S)
    S=S.replace("?","a")
    print(S)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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)-1,-1):
  key = 0
  for j in range(len(T)):
    if S_d[i+j]=="?" or S_d[i+j]==T[j]:
      key+=1
    else:
      break
  if key == len(T):
    st=len(S_d)+i
    break
  else:
    st=-1

if st==-1:
  print(UNRESTORABLE)
else:
  for i in range(len(S_d)):
    if st <= i and i < st+len(T):
      print(T[i-st],end="")
    elif S_d[i]=="?":
      print("a",end="")
    else:
      print(S_d[i],end="")

Submission status: Runtime Error

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)-1,-1):
  key = 0
  for j in range(len(T)):
    if S_d[i+j]=="?" or S_d[i+j]==T[j]:
      key+=1
  if key == len(T):
    st=len(S_d)+i
    break
  else:
    st=-1

if st==-1:
  print(UNRESTORABLE)
else:
  for i in range(len(S_d)):
    if st <= i and i < st+len(T):
      print(T[i-st],end="")
    elif S_d[i]=="?":
      print("a",end="")
    else:
      print(S_d[i],end="")

Submission status: Runtime Error

Solution code:
ss = list(input())
t = list(input())
s = ""
for c in ss:
    cnt = len(t)
    if c == "?" or c == t[0]:
        d = ss.index(c)
        copy = ss.copy()
        for i in range(d, d + len(t)):
            if ss[i] == t[i - d] or ss[i] == "?":
                copy[i] = t[i - d]
                cnt -= 1
            else:
                break
    if cnt == 0:
            break
for i in range(len(copy)):
    if copy[i] == "?":
        copy[i] = "a"
    s += copy[i]
if cnt == 0:
    print(s)
elif cnt != 0 or len(ss) < len(t):
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
ss = list(input())
t = list(input())
s = ""
for c in ss:
    cnt = len(t)
    if c == "?" or c == t[0]:
        d = ss.index(c)
        copy = ss.copy()
        for i in range(d, d + len(t)):
            if ss[i] == t[i - d] or ss[i] == "?":
                copy[i] = t[i - d]
                cnt -= 1
            else:
                break
    if cnt == 0:
            break
for i in range(len(copy)):
    if copy[i] == "?":
        copy[i] = "a"
    s += copy[i]
if cnt == 0:
    print(s)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S_dash = list(map(str, input()))
T = list(map(str, input()))


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

Submission status: Runtime Error

Solution code:
S_dash = list(map(str, input()))
T = list(map(str, input()))


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

Submission status: Runtime Error

Solution code:
S_dash = list(map(str, input()))
T = list(map(str, input()))


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

Submission status: Runtime Error

Solution code:
import copy
S = input()
T = input()
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")

Submission status: Runtime Error

Solution code:
import copy
S = input()
T = input()
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[0])
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
ef 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: Runtime Error

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

a = len(s)
b = len(t)
#最小の文字列となるためには前にaを固めたほうが良いため後ろから入れる
for i in range(a-b,-1,-1):
    t_kamo = s[i:i+b]
    count = 0
    for j in range(b):
        if t_kamo[j] == t[j] or t_kamo[j] == "?":
            count += 1
    if count == b:
        #replaceメソット(リストには使えない,strに直接使う？)
        #条件分で記述
        ans = "".join(s[:i]+t+s[i+b:])
        print(ans.replace("?","a"))
        sys.exit()
        #ans = []"a" if "?" for i in ans]
        #print("join.(ans)")でもいけるはず
        
print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S=list(str(input()))
T=list(str(input()))
len_T=len(T)
len_S=len(S)
ST=len_S-len_T
for i in range(ST+1):
    judge=True
    S_strip=S[ST-i:len_S-i]
    for j,k in zip(T,S_strip):
        if j==k or k=='?':
            pass
        else:
            judge=False
            break
    if judge:
        S[ST-i:len_S-i]=T
        S_join="".join(S)
        S_join=S_join.replace("?","a")
        break
if judge:print(S_join)
else:print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S=list(str(input()))
T=list(str(input()))
len_T=len(T)
len_S=len(S)
ST=len_S-len_T
for i in range(ST+1):
    judge=True
    S_strip=S[ST-i:len_S-i]
    for j,k in zip(T,S_strip):
        if j==k or k=='?':
            continue
        else:
            judge=False
            break
    if judge:
        S[ST-i:len_S-i]=T
        S_join="".join(S)
        S_join=S_join.replace("?","a")
        break
if judge:print(S_join)
else:print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S=list(str(input()))
T=list(str(input()))
len_T=len(T)
len_S=len(S)
for i in range(len_S-len_T+1):
    judge=True
    S_strip=S[i:i+len_T]
    for j,k in zip(T,S_strip):
        if j==k or k=='?':
            continue
        else:
            judge=False
            break
    if judge:
        S_letter="".join(S_strip)
        S_join="".join(S)
        T_join="".join(T)
        S_join=S_join.replace(S_letter,T_join)
        S_join=S_join.replace("?","a")
        break
if judge:print(S_join)
else:print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
s=input()
t=input()
score = 0
L = []
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):]
    L.append(s.replace("?","a"))
  score = 0
if L = []:
  print("UNRESTORABLE")
else:
  L = sorted(L)
  print(L[0])

Submission status: Runtime Error

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

for i in reversed(range(len(S) - len(T) + 1)):
    if checker(S[i:(i + len(T))], T):
        S = S.replace('?', 'a')
        print(S[:i] + T + S[i + len(T):])
        exit()
print('UNRESTORABLE')
exit()
def checker(s, t):
	for i in range(len(s)):
		if s[i] != "?" and s[i] != t[i]:
			return False
	return True

Submission status: Runtime Error

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

for i in reversed(range(len(S) - len(T) + 1)):
    if checker(S[i:(i + len(T)), T]):
        S = S.replace('?', 'a')
        print(S[:i] + T + S[i + len(T):])
        exit()
print('UNRESTORABLE')
exit()
def checker(s, t):
	for i in range(len(s)):
		if s[i] != "?" and s[i] != t[i]:
			return False
	return True

Submission status: Runtime Error

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

for i in reversed(range(len(S) - len(T) + 1)):
    if checker(S[i:(i + len(T)), T]):
        S = S.replace('?', 'a')
        print(S[:i] + T + S[i + len(T):])
        return
    print('UNRESTORABLE')

def checker(s, t):
	for i in range(len(s)):
		if s[i] != "?" and s[i] != t[i]:
			return False
	return True

Submission status: Runtime Error

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

for i in range(len(Sz)-len(T),-1,-1):
    Flag=1
    for s in range(len(T)):

        if not (Sz[i+s]=="?" or Sz[i+s]==T[s]):
            Flag=0
            break
    if Flag:
        for s in range(len(T)):
             Sz[i+s]=T[s]
        break
for i in range(len(Sz)):
    if Sz[i]=="?":Sz[i]="a"

if Flag:print("".join(Sz))
else:print("UNRESTORABLE ")

Submission status: Runtime Error

Solution code:
a = list(input())
b = list(input())
c = len(a)
d = len(b)

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: Runtime Error

Solution code:
s = input()
t = input()
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:
        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])
    print("".join(res))

else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S = input()
T = input()
i = 0
j = 0
flg1 = True
flg2 = False
while i < len(S):
    while j < len(T):
        if S[i] == T[j] or S[i] == "?":
            if flg1:
                tmp = i
                flg1 = False
            j += 1
        else:
            flg1 = True
            i = tmp
            j = 0
        if j == len(T)-1:
            startId = i-j+1
            flg2 = True
            break
        i += 1
if flg2:
    for k in range(len(S)):
        if S[k] != "?":
            print(S[k],end="")
        elif startId <= k and k <= startId+len(T):
            print(T[k],end="")
        else:
            print("a",end="")
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S = input()
T = input()
i = 0
j = 0
flg1 = True
print(i)
while i < len(S):
    print(i)
    while j < len(T):
        if S[i] == T[j] or S[i] == "?":
            if flg1:
                tmp = i
                flg1 = False
            j += 1
        else:
            flg1 = True
            i = tmp
            j = 0
        if j == len(T)-1:
            startId = i-j+1
            flg2 = True
            break
        i += 1
if flg2:
    for k in range(len(S)):
        if S[k] != "?":
            print(S[k],end="")
        elif startId <= k and k <= startId+len(T):
            print(T[k],end="")
        else:
            print("a",end="")
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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 = []
count = 0
for i in range(len(s)):
    if s[i] == '?':
        continue
    for j in range(len(t)):
        if s[i] == t[j]:
            x.append(check_context(i, j))
            if x[count]:
                for k in range(len(x[count])):
                    if x[count][k] == '?':
                        x[count][k] = 'a'
                count += 1


if x:
    x.sort()
    while x[0] == []:
        x.pop(0)
    for i in x[0]:
        print(i, end='')
elif x == []:
    print('UNRESTORABLE')

Submission status: Runtime Error

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



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='')
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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



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:
    print(x, sep='')
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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):]).raplace("?","a")
        ans.append(tmp)

ans.sort()

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

Submission status: Runtime Error

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):]).raplace("?","a")
        ans.append(tmp)
ans.sort()

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

Submission status: Runtime Error

Solution code:
s = input()
t = 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 -=m
        i+=1
if len(point)==0:
    print("UNRESTORABLE")
    exit()
i = 0
ans = 0
for l in range(len(point)):
    a = (s[:point[l]-1]+t+s[point[l]+m-1:]).replace("?","a")
    ans.append(a)
ans.sort()
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
t = 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 -=m
        i+=1
if len(point)==0:
    print("UNRESTORABLE")
    exit()
i = 0
ans = 0
for l in range(len(point)):
    a = (s[:point[l]]+t+s[point[l]+m:]).replace("?","a")
    ans.append(a)
ans.sort()
print(ans)

Submission status: Runtime Error

Solution code:
s = input()
t = 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 -=m
        i+=1
if len(point)==0:
    print("UNRESTORABLE")
    exit()
i = 0
ans = 0
for l in range(len(point)):
    a = (s[:point[l]]+t+s[point[l]+m:]).replace("?","a")
    ans.append(a)
ans.sort()
print(ans)
print("".join(ans[0]))

Submission status: Runtime Error

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