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

if len(T)>len(S):
    ans = "UNRESTORABLE"
else:
    Slr = list(S[::-1])
    Tlr = list(T[::-1])
    
    for i in range(len(S)-len(T)+1):
        flag = True
        for j in range(len(T)):
            if Slr[i+j]==Tlr[j] or Slr[i+j]=="?":
                pass
            else:
                flag = False
                break
        if flag:
            for j in range(len(T)):
                Slr[i+j] = Tlr[j]
            for j in range(len(S)):
                if Slr[i+j]=="?":
                    Slr[i+j] = "a"
            ans = ("".join(Slr[::-1]))
            break
        else:
            if i==len(S)-len(T):
                ans = "UNRESTORABLE"
print(ans)

Submission status: Runtime Error

Solution code:

S = input()
T = input()

Slr = list(S[::-1])
Tlr = list(T[::-1])

for i in range(len(S)-len(T)+1):
    flag = True
    for j in range(len(T)):
        if Slr[i+j]==Tlr[j] or Slr[i+j]=="?":
            pass
        else:
            flag = False
            break
    if flag:
        for j in range(len(T)):
            Slr[i+j] = Tlr[j]
        for j in range(len(S)):
            if Slr[i+j]=="?":
                Slr[i+j] = "a"
        ans = ("".join(Slr[::-1]))
        break
    else:
        if i==len(S)-len(T):
            ans = "UNRESTORABLE"
print(ans)

Submission status: Runtime Error

Solution code:
Sprime = input() # S'の入力
T = input() # Tの入力
S = [] # Sの候補をlistで管理
if len(Sprime) < len(T): # S'の文字列長がTの文字列長よりも短い場合はそもそもSが存在しえない
    print("UNRESTORABLE")
    exit()
for i in range(len(Sprime) - len(T) + 1): # 左からTを入れられるか見ていく
    flag = 0 # 文字が一致しえないことのflagを初期化
    if Sprime[i] == T[0] or Sprime[i] == "?":
        for j in range(len(T)):
            if Sprime[i + j] != T[j] and Sprime[i + j] != "?": # 一致しえない場合
                flag += 1
                break
        if flag != 1:
            S.append(Sprime[0 : i].replace("?", "a") + T + Sprime[i + len(T) :].replace("?", "a")) # 辞書順最小を求めるので?は全てaにする
S.sort() # Sの候補をさらに辞書順に並べる
if S == []: # Sの候補が無い場合 "UNRESTORABLE" を出力
    print("UNRESTORABLE")
else: # Sの候補のうち辞書順最小のものを出力
    print(S[0])
print(S[0]) # Sの候補のうち辞書順最小のものを出力

Submission status: Runtime Error

Solution code:
# coding: utf-8
Sprime = input() # S'の入力
T = input() # Tの入力
S = [] # Sの候補をlistで管理
if len(Sprime) < len(T): # S'の文字列長がTの文字列長よりも短い場合はそもそもSが存在しえない
    print("UNRESTORABLE")
    exit()
for i in range(len(Sprime) - len(T) + 1): # 左からTを入れられるか見ていく
    flag = 0 # 文字が一致しえないことのflagを初期化
    if Sprime[i] == T[0] or Sprime[i] == "?":
        for j in range(len(T)):
            if Sprime[i + j] != T[j] and Sprime[i + j] != "?": # 一致しえない場合
                flag += 1
                break
        if flag != 1:
            S.append(Sprime[0 : i].replace("?", "a") + T + Sprime[i + len(T) :].replace("?", "a")) # 辞書順最小を求めるので?は全てaにする
S.sort() # Sの候補をさらに辞書順に並べる
print(S[0]) # Sの候補のうち辞書順最小のものを出力

Submission status: Runtime Error

Solution code:
s=list(input())
t=list(input())
n=len(s)
m=len(t)
if m>n:
    print('UNRESTORABLE')
    exit()
af=0
for i in range(n-m+1):
    k=s[n-m-i:n-i]
    f=0
    for j in range(m):
        if k[i]=='?' or k[i]==t[i]:
            f+=1
    if f==m:
        af+=1
        s[n-m-i:n-i]=t
        break
if af>0:
    ans=''
    for i in range(n):
        if s[i]=='?':
            ans+='a'
        else:
            ans+=s[i]
    print(ans)
else:
    print('UNSTORABLE')

Submission status: Runtime Error

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

t_len = len(T)
found = False
for i in range(len(S)-len(T), -1,-1):
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != '?':
            break
    else:
        if i + t_len == len(S):
            S = S[:i] + T
        else:
            S = S[:i] + T + S[i+tlen:]
        found = True
    if found:
        print(S.replace('?','a'))
        break
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
sd = input()
t = input()
n = len(sd)
m = len(t)
ss = []
for i in range(n - m + 1):
    flag = True
    s = ""
    for j in range(m):
        if sd[i + j] == "?" or sd[i + j] == t[j]:
            continue
        else:
            flag = False
    if flag:
        k = 0
        for j in range(n):
            if j < i or j > i + m:
                if sd[j] == "?":
                    s += "a"
                else:
                    s += sd[j]
            else:
                if sd[j] == "?":
                    s += t[k]
                else:
                    s += sd[j]
                k += 1
        ss.append(s)
if ss:
    print(sorted(ss)[0])
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import os

def qcount(s,t,count):
    if s=="?" or s==t:
        count += 1
        return count
    else:
        return 0

S = list(input())
T = list(input())
count = 0
i = 0
result =False

if len(S)>=len(T):
    while len(S)-i:
        count = qcount(S[i],T[count],count)
        if count == len(T):
            i = len(S)-1
            result = True
            for j in range(len(T)):
                S[i-count+j+1] = T[j]
            for k in range(len(S)):
                if S[k]=="?":
                    S[k] = "a"
    i += 1
if result:
    print("".join(S))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import os

def qcount(s,t,count):
    if s=="?" or s==t:
        count += 1
        return count
    else:
        return 0

S = list(input())
T = list(input())
count = 0
i = 0
result =False
if len(S)>=len(T):
    while len(S)-i:
        count = qcount(S[i],T[count],count)
        if count == len(T):
            i = len(S)-1
            result = True
            for j in range(len(T)):
                S[i-count+j+1] = T[j]
                for k in range(len(S)):
                    if S[k]=="?":
                        S[k] = "a"
    i += 1
if result:
    print("".join(S))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
s=input()
t=input()
strs=[]
S=len(s)
T=len(t)
for i in range(S-T+1):
  flag=0
  for j in range(T):
    if S[i+j]=="?":
      continue
    if S[i+j]!=T[j]:
      flag=1;break
  if flag==0:
    posstr=s[:i]+t+s[i+T:]
    posstr.replace("?","a")
    strs.append(posstr)
if strs==[]:print("UNRESTORABLE")
else:print(strs[0])

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:
S = input()
T = input()
lenS=len(S)
lenT=len(T)
ans=["a"]*lenS
for i in range (lenS):
    if(S[i]!="?"):
        ans[i]=S[i]

for j in range(lenS-lenT):
    flag=1
    for i in range (lenS):
        if(S[i]=="?"):
            ans[i]="a"

    for i in range(1,lenT+1):
        if((S[lenS-i-j]!="?")&(S[lenS-i-j]!=T[lenT-i])):
            flag=0
            break
        else:
            ans[lenS-i-j]=T[lenT-i]
    
    if(flag==1):
        break

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

Submission status: Runtime Error

Solution code:
s = input()
S = input()
flag = False
for i in range(len(s)-len(S)+1):
    if s[i] == S[0] or s[i] == "?":
        a = s[i:i+len(S)]
        for j in range(len(S)):
            if a[j] == S[j] or a[j] == "?":
                continue
            break
        else:
            flag = True
            s = s[0:i]+S+s[i+len(S):-1]
print(s.replace("?","a") if flag == True else "UNRESTORABLE")

Submission status: Runtime Error

Solution code:
s = input()
t = input()
def check(a, b):
  if a == '?':
    return True
  else:
    return a == b
  
cand = []
for i in range(len(s)-len(t)+1):
  flag = True
  c = list(s)
  for j in range(len(t)):
    if not check(s[i+j], t[j]):
      flag = False
      break
    c[i+j] = t[j]
  if flag:
    cs = ''.join(c)
    cand(cs.replace('?', 'a'))
if len(cand):
  cand.sort()
  print(cand[0])
else:
  print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
s = input()
t = input()
def check(a, b):
  if a == '?':
    return True
  else:
    return a == b
  
cand = []
for i in range(len(s)-len(t)+1):
  flag = True
  c = list(s)
  for j in range(len(t)):
    if not check(s[i+j], t[j]):
      flag = False
      break
    c[i+j] = t[j]
  if flag:
    s = ''.join(c)
    cand(s.replace('?', 'a'))
if len(cand):
  cand.sort()
  print(cand[0])
else:
  print("UNRESTORABLE")

Submission status: Runtime Error

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

for i in range(len(s) - len(t) + 1):
    tmps = s[i:i + len(t)]
    ok = True
    for j in range(len(tmps)):
        if t[j] == tmps[j] or tmps[j] == '?':
            pass
        else:
            ok = False
            break
    if ok == True:
        for k in range(len(t)):
            s[k+i] = t[k]
        break

if ok == False:
    print("UNRESTORABLE")
else:
    for c in s:
        if c == '?':
            print('a', end="")
        else:
            print(c, end="")
    print()

Submission status: Runtime Error

Solution code:
S = list(input())
T = list(input())
#S = list('??p??d??')
#T = list('abc')

Ns = len(S)
Nt = len(T)
flag = True
for i in range(Ns - Nt+1):
    for j in range(Nt):
        if not(S[i+j] == T[j] or S[i+j] == '?'):
            break
    else:
        flag = True
        break

if flag:
    
    ans = S
    for j in range(Nt):
        ans[i+j] = T[j]

    for k in range(Ns):
        if ans[k] == '?':
            ans[k] = 'a'
    ans = ''.join(ans)
else:
    ans = 'UNRESTORABLE'
    
print(ans)

Submission status: Runtime Error

Solution code:
S = list(input())
T = list(input())
Ns = len(S)
Nt = len(T)
ans = S
flag = True
for i in range(Ns - Nt+1):
    for j in range(Nt):
        if not(S[i+j] == T[i+j] or S[i+j] == '?'):
            break
    else:
        flag = True
        break

if flag:
    for j in range(Nt):
        ans[i+j] = T[j]

    for k in range(Ns):
        if ans[k] == '?':
            ans[k] = 'a'
    ans = ''.join(ans)
else:
    ans = 'UNRESTORABLE'
    
print(ans)

Submission status: Runtime Error

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

N, M = len(S), len(T)

# N>=Mのとき
for i in range(max(0,N-M), -1, -1):
    # 今着目しているSの部分
    now = S[i:i+M]

    # nowにTを入れられるかチェック
    for j in range(M):
        if now[j] == '?' or now[j] == T[j]:
            continue
        else:
            break
    else:
        # 入れられるならその部分をTに置換
        S = S[0:i] + T + S[i+M:N]
        # 残った?をaに置換
        S = S.replace('?', 'a')
        print(S)
        break
else:
    # どこにもTを入れられなかったら
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
s=input()
t=input()
f=0
e=5
flg=0
while e<=len(s):
  tmp=s[f:e]
  for i in range(len(t)):
    if tmp[i]!=t[i] and tmp[i]!='?':
      break
    if i==len(t)-1:
      ans=s[:f]+t+s[e:]
      flg=1
  f+=1
  e+=1
if flg==0:
  print('UNRESTORABLE')
else:
  print(ans.replace('?','a'))

Submission status: Runtime Error

Solution code:
s=input()
t=input()
f=0
e=5
flg=0
while e<=len(s):
  tmp=s[f:e]
  for i in range(len(t)):
    if tmp[i]!=t[i] and tmp[i]!='?':
      break
    if i==len(t)-1:
      s=s[:f]+t+s[e:]
      flg=1
      print(s.replace('?','a'))
  f+=1
  e+=1
if flg==0:
  print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
import sys
from pprint import pprint

s = sys.stdin.readline().strip()
t = sys.stdin.readline().strip()

len_s = len(s)
len_t = len(t)
# print(len_s, len_t)

for i in range(0, len_s - len_t + 1):
    flag = True
    for j in range(len_t):
        if flag == False:
            continue
        # print(s[i+j], t[j])
        if s[i+j] == "?" or s[i+j] == t[j]:
            continue
        flag = False
        break
    if flag:
        ans = ""
        for k, s_k in enumerate(s):
            if i < k <= i + len_t:
                ans += t[k-i]
            else:
                if s_k == "?":
                    ans += "a"
                else:
                    ans += s_k
        print(ans)        
        sys.exit()

print("UNRESTORABLE")

Submission status: Runtime Error

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

li=[]
for i in range(len(s)-len(t)+1):
    if s[i]==t[0] or s[i]=='?':
        check=1
        tid=1
        while True:
            if s[i+1] ==t[tid] or s[i+1]=='?':

                check+=1
                i+=1
                tid+=1

                if check==len(t):
                    li.append(s[:i-len(t)+1]+t+s[i+1:])
                    break
            else:
                break

li2=[]      

for i in li:

    li2.append(i.replace('?','a'))
    

li2.sort()


print(li2[0] if li2 else 'UNRESTORABLE')

Submission status: Runtime Error

Solution code:

s=input()
t=input()

li=[]
for i in range(len(s)-len(t)+1):
    if s[i]==t[0] or s[i]=='?':
        check=1
        tid=1
        while True:
            if s[i+1] ==t[tid] or s[i+1]=='?':

                check+=1
                i+=1
                tid+=1

                if check==len(t):
                    li.append(s[:i-len(t)+1]+t+s[i+1:])
                    break
            else:
                break

li2=[]      
print(li)
for i in li:

    li2.append(i.replace('?','a'))
    

li2.sort()


print(li2[0] if li2 else 'UNRESTORABLE')

Submission status: Runtime Error

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

li=[]
for i in range(len(s)-len(t)+1):
    if s[i]==t[0] or s[i]=='?':
        check=1
        tid=1
        while True:
            if s[i+1] ==t[tid] or s[i+1]=='?':

                check+=1
                i+=1
                tid+=1

                if check==len(t):
                    li.append(s[:i-len(t)]+t+s[i+len(t):])
                    break
            else:
                break

li2=[]                
for i in li:

    li2.append(i.replace('?','a'))
li2.sort    

print(li2[0] if li2 else 'UNRESTORABLE')

Submission status: Runtime Error

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

li=[]
for i in range(len(s)-len(t)+1):
    if s[i]==t[0] or s[i]=='?':
        check=1
        tid=1
        while True:
            if s[i+1] ==t[tid] or s[i+1]=='?':

                check+=1
                i+=1
                tid+=1
                print(check)
                if check==len(t):
                    li.append(s[:i-len(t)]+t+s[i+len(t):])
                    break
            else:
                break

li2=[]                
for i in li:

    li2.append(i.replace('?','a'))
li2.sort    

print(li2[0] if li2 else 'UNRESTORABLE')

Submission status: Runtime Error

Solution code:
S_ = input()
T = input()
ans = list(S_)
for i in range(len(T)):
    if T[i] in S_:
        prev = len(S_)
        while(1):
            id = S_.rfind(T[i], 0, prev-1)
            if id < 0:
                break
            prev = id
            flag = True
            for j in range(i+1, len(T)):
                if S_[id + j - i] == T[i] or S_[id + j - i] == "?":
                    continue
                else:
                    flag = False
                    break
                for j in reversed(range(i)):
                    if S_[id - j - 1] == T[i - j - 1] or S_[id - j - 1] == "?":
                        continue
                    else:
                        flag = False
                        break
            if flag:
                ans[id - i:id - i + len(T)] = T
                for i in range(len(ans)):
                    if ans[i] == "?":
                        ans[i] = "a"
                print("".join(ans))
                exit(0)


print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S_ = input()
T = input()
ans = list(S_)
for i in range(len(T)):
    if T[i] in S_:
        prev = len(S_)
        while(1):
            id = S_.rfind(T[i], 0, prev-1)
            if id < 0:
                break
			prev = id
            flag = True
            for j in range(i+1, len(T)):
                if S_[id + j - i] == T[i] or S_[id + j - i] == "?":
                    continue
                else:
                    flag = False
                    break
                for j in reversed(range(i)):
                    if S_[id - j - 1] == T[i - j - 1] or S_[id - j - 1] == "?":
                        continue
                    else:
                        flag = False
                        break
            if flag:
                ans[id - i:id - i + len(T)] = T
                for i in range(len(ans)):
                    if ans[i] == "?":
                        ans[i] = "a"
                print("".join(ans))
                exit(0)


print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S_ = input()
T = input()
ans = list(S_)
for i in range(len(T)):
    if T[i] in S_:
        prev = len(S_)
        while(1):
            id = S_.rfind(T[i], 0, prev-1)
            if id < 0:
                break

            flag = True
            for j in range(i+1, len(T)):
                if S_[id + j - i] == T[i] or S_[id + j - i] == "?":
                    continue
                else:
                    flag = False
                    break
                for j in reversed(range(i)):
                    if S_[id - j - 1] == T[i - j - 1] or S_[id - j - 1] == "?":
                        continue
                    else:
                        flag = False
                        break
            if flag:
                ans[id - i:id - i + len(T)] = T
                for i in range(len(ans)):
                    if ans[i] == "?":
                        ans[i] = "a"
                print("".join(ans))
                exit(0)


print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S_ = input()
T = input()
ans = list(S_)
for i in range(len(T)):
    if T[i] in S_:
        id = S_.rfind(T[i])
        if id < 0:
            continue
        flag = True
        for j in range(i+1, len(T)):
            if S_[id + j - i] == T[i] or S_[id + j - i] == "?":
                continue
            else:
                flag = False
                break
            for j in reversed(range(i)):
                if S_[id - j - 1] == T[i - j - 1] or S_[id - j - 1] == "?":
                    continue
                else:
                    flag = False
                    break
        if flag:
            ans[id - i:id - i + len(T)] = T
            for i in range(len(ans)):
                if ans[i] == "?":
                    ans[i] = "a"
            print("".join(ans))
            exit(0)


print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
S_ = input()
T = input()
ans = list(S_)
for i in range(len(T)):
    if T[i] in S_:
        id = S_.rfind(T[i])
        flag = True
        for j in range(i+1, len(T)):
            if S_[id + j - i] == T[i] or S_[id + j - i] == "?":
                continue
            else:
                flag = False
                break
            for j in reversed(range(i)):
                if S_[id - j - 1] == T[i - j - 1] or S_[id - j - 1] == "?":
                    continue
                else:
                    flag = False
                    break
        if flag:
            ans[id - i:id - i + len(T)] = T
            for i in range(len(ans)):
                if ans[i] == "?":
                    ans[i] = "a"
            print("".join(ans))
            exit(0)


print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
import copy
S = list(input())
T = list(input())
for i in range(len(S) - len(T) + 1):
    c = 0
    A=copy.copy(S)
    check = False
    for j in range(len(T)):
        if A[i + j] == T[j]:
            c += 1
        elif A[i + j] == "?":
            A[i + j] = T[j]
            c += 1
        else:
            break
        if c == len(T):
            check = True
    if check:
        break
print("".join(A).replace("?","a") if check else "UNRESTORABLE")

Submission status: Runtime Error

Solution code:
def main(S_,T):

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

if __name__ == '__main__':
    S_ = list(input())
    T = list(input())
    main(S_,T)

Submission status: Runtime Error

Solution code:
#入力
S_prime = str(input())
T = str(input())
ans = []

if len(S_prime) >= len(T):
    times = len(S_prime) - len(T) + 1
    for i in range(times):
        count = 0
        for j in range(len(T)):
            if S_prime[i+j] == '?':
                count = count + 1
            elif S_prime[i+j] != T[j]:
                continue
            else:
                count = count + 1
            
        if count == len(T):
            S_prime = S_prime[:i] + T + S_prime[(i+len(T)+1):]
            S = S_prime.replace('?', 'a')
            ans.append(S)


if len(ans) != 0:
    print(min(ans))
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
s_d = input()
t = input()
s = "a"
for i in range(len(s_d) - len(t), -1, -1):
    possible = True
    for j in range(len(t)):
        if s_d[i + j] == t[j] or s_d[i + j] == "?":
            continue
        else:
            possible = False
            break
    if possible == False:
        continue
    else:
        s = s_d[:i] + t + s_d[i+len(t):]
        for k in range(len(s)):
            if s[k] == "?":
                s = s[:k] + "a" + s[k+1:]
        break
if possible == True:
    print(s)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
s_d = input()
t = input()
possible = True
for i in range(len(s_d) - len(t), -1, -1):
    for j in range(len(t)):
        if s_d[i + j] == t[j] or s_d[i + j] == "?":
            continue
        else:
            possible = False
            break
    if possible == False:
        continue
    else:
        s = s_d[:i] + t + s_d[i+len(t):]
        for k in range(len(s)):
            if s[k] == "?":
                s = s[:k] + "a" + s[k+1:]
        break
if possible == True:
    print(s)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
s_d = input()
t = input()
for i in range(len(s_d) - len(t), -1, -1):
    possible = True
    for j in range(len(t)):
        if s_d[i + j] == t[j] or s_d[i + j] == "?":
            continue
        else:
            possible = False
            break
    if possible == False:
        continue
    else:
        s = s_d[:i] + t + s_d[i+len(t):]
        for k in range(len(s)):
            if s[k] == "?":
                s = s[:k] + "a" + s[k+1:]
        break
if possible == True:
    print(s)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
ss = input()
t = insput()

def search(ss,t):
    ans = []
    if len(ss) < len(t):
        return ans
    for i in range(len(ss) - len(t), -1, -1):
        ss_cut = ss[i:len(t)+i]
        flag = True
        for j in range(len(t)):
            if ss_cut[j] != '?' and ss_cut[j] != t[j]:
                flag = False
        if flag:
            ss_ans = ss.replace(ss[i:len(t)+i], t)
            while '?' in ss_ans:
                ss_ans = ss_ans.replace('?', 'a')
            ans.append(ss_ans)
    return ans

if len(search(ss, t)) == 0:
    print('UNRESTORABLE')
else:
    ans_list = sorted(search(ss, t))
    print(ans_list)
    s = ans_list[0]
    print(s)

Submission status: Runtime Error

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

for i in range(len(S) - len(T), -1, -1):
  flag = True
  for j in range(len(T)):
    if S[i+j] != '?' and S[i+j] != T[j]:
      flag = False
      break
  if flag:
    break
if flag:
  U = S[:i] + T + S[i+len(T):]
  U = U.replace('?', 'a')
  print(U)
else:
  print('UNRESTORABLE')

Submission status: Runtime Error

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

N = len(S)
M = len(T)

i_a = 0
for i in reversed(range(N-M+1)):
    ans = 0
    for j in range(M):
        if T[j] == S[i+j] or S[i+j] == '?':
            ans += 1
        else:
            break
    if ans == M:
        for k in range(N):
            if k == i:
                print(T,end='')
            elif k < i or i + M - 1 < k:
                if S[k] == '?':
                    print('a',end='')
                else:
                    print(S[k],end='')
        exit()
    if i == 0:
        print('UNRESTORABLE')
        eixt()

Submission status: Runtime Error

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

N = len(S)
M = len(T)

i_a = 0
for i in reversed(range(N-M+1)):
    ans = 0
    for j in range(M):
        if T[j] == S[i+j] or S[i+j] == '?':
            ans += 1
        else:
            break
    if ans == M:
        for k in range(N):
            if k == i:
                print(T,end='')
            elif k < i or i + M - 1 < k:
                if S[k] == '?':
                    print('a',end='')
                else:
                    print(S[k],end='')
            exit()
    if i == 0:
        print('UNRESTORABLE')
        eixt()

Submission status: Runtime Error

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

N = len(S)
M = len(T)

i_a = 0
for i in reversed(range(N-M+1)):
    ans = 0
    for j in range(M):
        if T[j] == S[i+j] or S[i+j] == '?':
            ans += 1
        else:
            break
    if ans == M:
        for k in range(N):
            if k == i:
                print(T,end='')
            elif k < i or i + M - 1 < k:
                if S[k] == '?':
                    print('a',end='')
                else:
                    print(S[k],end='')
        break
    if i == 0:
        print('UNRESTORABLE'

Submission status: Runtime Error

Solution code:
s = input()
t = input()
cnt = 0
for i in range(len(s) - len(t), -1, -1):
    cnt = 0
    for j in range(len(t)):
        if s[j + i] == "?" or s[j + i] == t[j]:
            cnt += 1
        else:
            break
    if cnt == len(t):
        for j in range(len(s)):
            if i <= j < j + len(t):
                print(t[j - i], end = "")
            elif s[j] == "?":
                print("a", end = "")
            else:
                print(s[j], end = "")
        print()
        break
if cnt != len(t):
    print("UNRESTORABLE")

Submission status: Runtime Error

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

len_S = len(S_dash)
len_T = len(T)

answer = "UNRESTORABLE"
candidate = []

# まず T と一致させられる位置があるかを調べる
for i in range(len_S - len_T + 1):
  # print(S_dash[i:i+len_T])
  tmp = S_dash[i:i+len_T]
  
  count = 0
  for s, t in zip(tmp, T):
    if s == t or s == '?':
      count += 1
  if count == len_T:
    candidate.append(S_dash[:i] + T + S_dash[i+len_T:])
    
replaced_candidate = [item.replace("?", "a") for item in candidate]
replaced_candidate.sort()
print(replaced_candidate[0])

Submission status: Runtime Error

Solution code:
import copy
Sd = list(input())
T = list(input())
S = copy.deepcopy(Sd)
flag = 0
for i in range(len(Sd)-len(T)+1):
    if flag == 1:
        break
    for j in range(len(T)):
        if Sd[i+j] != '?' and Sd[i+j] != T[j]:
            Sd = S
            flag = 0
            break
        elif Sd[i+j] == '?':
            Sd[i+j] = T[j]
        if j == len(T)-1:
            flag = 1
if flag == 1:
    l = ['a' if i =='?' else i for i in Sd]
    print(''.join(l))
else:
    print('UNRESTORABLE')
import copy
Sd = list(input())
T = list(input())
S = copy.deepcopy(Sd)
flag = 0
for i in range(len(Sd)-len(T)+1):
    if flag == 1:
        break
    for j in range(len(T)):
        if Sd[i+j] != '?' and Sd[i+j] != T[j]:
            Sd = S
            flag = 0
            break
        elif Sd[i+j] == '?':
            Sd[i+j] = T[j]
        if j == len(T)-1:
            flag = 1
if flag == 1:
    l = ['a' if i =='?' else i for i in Sd]
    print(''.join(l))
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

S=s[::-1]
T=t[::-1]

for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        
        if T[j]==S[i+j]:
            pass    
        elif S[i+j]=="?":
            pass
        else:
            break
        
        if j==(len(T)-1):
            #for item in T:
            S[i:i+5]=T
                                                                  
ans="".join(S[::-1])
if ans=="".join(s):
    print("UNRESTORABLE")
else:                                                                      
    print(ans.replace("?","a"))

Submission status: Runtime Error

Solution code:
s2 = str(input())
l2 = len(s2)
t = str(input())
l = len(t)
count = 0

for i in range(0,l2-l+1):
    string = s2[i:i+l]
    for j in range(0,l):
        if string[j] in [t[j],"?"]:
            count += 1
            if count==l:
                s2[i:i+1] = t
                change_count += 1
        else:
            break
for i in range(0,l2):
    if s2[i]=="?":
        s2[i] = "a"

if change_count >=1:
    print(s2)
else:
    print("UNRESTORABLE")