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=list(input())
t=list(input())
ans=[0 for _ in range(len(s))]
for i in range(len(s)-len(t)+1):
    cnt=0
    for j in range(len(t)):
        if s[i+j]=='?' or s[i+j]==t[j]:
            cnt+=1
    if cnt==len(t):
        ans[i]=i
mark=ans.index(max(ans))
if sum(ans)!=0:
    for j in range(len(s)):
        if mark<=j and j<=mark+len(t):
            s[j]=t[j-mark]
        elif s[j]=='?':
            s[j]='a'
    print(''.join(s))
else:print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
s = list(input())
s_ = "".join(s)
t = list(input())

begin = t[0]
len_t = len(t) - 1
ok = 0
for i in range(len(s)):
    ok = 0
    if s[i] == begin:
        for j in range(1, len_t):
            if s[i+j] == "?":
                ok += 1
            else:
                break

        if ok == len_t - 1:
            for j in range(1, len_t+1):
                s[i+j] = t[j]

if list(s_) != s:
    S = ""
    for i in s:
        if i == "?":
            S += "a"
        else:
            S += i
    print(S)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

import sys

DEBUG = False


def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().rstrip().split(sep)]

def read_int():
    return int(sys.stdin.readline())

def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return

def solve(s, t):
    if len(t) > len(s):
        return None
    ans = None
    for i in range(0, len(s) - len(t) + 1):
        dprint(f"i: {i}")
        can_insert = True
        for j in range(0, len(t)):
            pos = i + j
            dprint(f"pos: {pos}, j: {j}")
            if s[pos] != '?' and s[pos] != t[j]:
                dprint(f"cannot insert")
                can_insert = False
                break
        if not can_insert:
            continue
        inserted = s[0:i] + t + s[i + len(t) + 1:]
        dprint(f"inserted: {inserted}")
        inserted = inserted.replace("?", "a")
        if ans is None or inserted < ans:
            ans = inserted
    if ans is None:
        return "UNRESTORABLE"
    return ans


def main():
    s = sys.stdin.readline().rstrip()
    t = sys.stdin.readline().rstrip()
    print(solve(s, t))
    



if __name__ == "__main__":
    main()

Submission status: Runtime Error

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

ans1 = "z"*len(S)
pos = ""
num = 0
for i in range(len(S)-len(T)+1):
    sl = ""
    sl = S[i:(i+len(T))]
    for j in range(len(T)):
        pos = ""
        if(sl[j] == T[j]):
            if(sl.count("?") >= len(T)-1):
                pos += S[:i]+T+S[(i+len(T)):]
                Flg = True
                if(pos < ans1):
                    ans1 = pos
if(Flg == True):
    ans1 = ans1.replace("?", "a")   
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

for i in range(len(s) - len(t), -1, -1):
	if re.fullmatch(s[i:i + len(t)].replace("?", "."), t):
		print((s[:i] + t + s[i+len(t)]).replace("?","a"))
		break
else:
	print("UNRESTORABLE")

Submission status: Runtime Error

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

if len()

def match(i):
  for j in range(len(t)):
    if not s[i+j] == '?' and s[i+j] != t[j]:
      return False
  return True

for i in range(len(s) - len(t), -1, -1):
  if not match(i):
    continue

  for j in range(i):
    print('a' if s[j] == '?' else s[j], end='')
  print(t, end='')
  for j in range(i+len(t), len(s)):
    print('a' if s[j] == '?' else s[j], end='')
  print()
  exit()
    
print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
import sys
from itertools import permutations
import math
from operator import itemgetter

s=input()
t=input()

flag2=True
for i in reversed(range(len(s))):
    if s[i]==t[0]:
        flag=True
        for j in range(1,len(t)):
            if (s[i+j]!=t[j]) & (s[i+j]!='?'):
                flag=False
        if flag:
            s=s[:i]+t+s[i+len(t):] 
            s=s.replace('?','a')
            print(s)
            flag2=False
            sys.exit()

if flag2:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

ls = len(sp)
lt = len(t)
ok = 1
s = list(sp)
print(s)
for i in range(ls):
    ok = 1
    for j in range(lt):
        if (sp[i+j] == t[j]) or (sp[i+j] == '?'):
            continue
        ok = 0
        break
    if ok == 1:
        for si in range(i, i+lt):
            s[si] = t[si - i]
            print(s[si], sep="")
        break

if ok == 1:
    for i in range(ls):
        if s[i] == '?':
            s[i] = 'a'
    print(str(s))
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

flag = True
s_len = len(s)
t_len = len(t)
max_ha = 0
l = []
max_save = 0
save = 0
count = 0

for i in range(s_len):
    if s[i] == '?':
        s[i] = 'a'
        count += 1
        max_ha += 1
        max_save = i
        if count == t_len and flag:
            save = i - count + 1
            flag = False
    elif count < t_len and s[i] == t[count]:
        l.append([max_ha, max_save])
        max_ha = 0
        count += 1
        if count == t_len and flag:
            save = i - count + 1
            flag = False
    else:
        l.append([max_ha, max_save])
        max_ha = 0
        count = 0

max_ha, max_save = max(l)        
        
if t_len < max_ha:
    for j in range(t_len):
        s[max_save-j] = t[t_len-j-1]
else:
    for j in range(t_len):
        s[j+save] = t[j]

if flag:
    print("UNRESTORABLE")
else:
    print(s)

Submission status: Runtime Error

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

flag = True
s_len = len(s)
t_len = len(t)
save = 0
count = 0

for i in range(s_len):
    if s[i] == '?':
        s[i] = 'a'
        count += 1
        if count == t_len and flag:
            save = i - count + 1
            flag = False
    elif count < t_len and s[i] == t[count]:
        count += 1
        if count == t_len and flag:
            save = i - count + 1
            flag = False
    else:
        count = 0
        
for j in range(t_len):
    s[j+save] = t[j]

if flag:
    print("UNRESTORABLE")
else:
    print(s)

Submission status: Runtime Error

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

flag = True
s_len = len(s)
t_len = len(t)
save = 0
count = 0

for i in range(s_len):
    if s[i] == '?':
        s[i] = 'a'
        count += 1
        if count == t_len and flag:
            save = i - count + 1
            flag = False
    elif s[i] == t[count]:
        count += 1
        if count == t_len and flag:
            save = i - count + 1
            flag = False
    else:
        count = 0
        
for j in range(t_len):
    s[j+save] = t[j]

if flag:
    print("UNRESTORABLE")
else:
    print(s)

Submission status: Runtime Error

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

L_S = len(SS)
L_T = len(T)

COND = 0
for i in range(L_S-L_T+1):
	cond = 1
	t = ('?' * i) + T + ('?' * (L_S-L_T-i))

	ans = ''
	for j in range(L_S):
		if SS[j] == '?' and t[j] == '?':
			ans += 'a'
			
		elif SS[j] == '?' and t[j] != '?':
			ans += t[j]
		elif SS[j] != '?' and t[j] == '?':
			ans += SS[j]
		else:
			if SS[j] != t[j]:
				cond = 0
				ans = ''
				break
			else:
				ans += t[j]

	if cond == 0:
		continue
	else:
		break

if ans == '':
	print('UNRESTORABLE')
else:
	print(ans)

Submission status: Runtime Error

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

L_S = len(SS)
L_T = len(T)

COND = 0
for i in range(L_S-L_T+1):
	cond = 1
	t = ('?' * i) + T + ('?' * (L_S-L_T-i))

	ans = ''
	for j in range(L_S):
		if SS[j] == '?' and t[j] == '?':
			ans += 'a'
			
		elif SS[j] == '?' and t[j] != '?':
			ans += t[j]
		elif SS[j] != '?' and t[j] == '?':
			ans += SS[j]
		else:
			if SS[j] != t[j]:
				cond = 0
				ans = ''
				break

	if cond == 0:
		continue
	else:
		break

if ans == '':
	print('UNRESTORABLE')
else:
	print(ans)

Submission status: Runtime Error

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

t = len(T)
ans = "UNRESTORABLE"

answers = []

for index, s in enumerate(S):
  if index + t > len(S):
    break

  if s != '?' and s != T[0]:
    continue

  for a in range(1, t):
    if S[index+a] != '?' and S[index+a] != T[a]:
      break

  else:
    ans = S[0:index] + T + S[index+t:-1]
    answers.append(ans.replace('?', 'a'))

answers.sort()  
print(answers[0])

Submission status: Runtime Error

Solution code:
import re
s=input().replace("?",".")
t=input()
for i in range(len(s)-lent(t)+1):
  if re.match(s[i:i+len(t)],t):
    s=s.replace(".","a")
    print(s[:i]+t+s[i+len(t):])
    exit()
print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
def solve(sequence, term):
    count = 0
    for t in term:
        count = 0
        for i, s in enumerate(sequence):
            if t == s or s == "?":
                count += 1
            else:
                count = 0
            if count == len(term):
                newSeq = sequence[:i - count+1] + term + sequence[i +1:]
                res = solve(newSeq, term)
                if (res == "UNRESTORABLE"):
                    return newSeq.replace("?", "a")
                else:
                    return res.replace("?", "a")
            
    return "UNRESTORABLE"

S = input()
T = input()
print(solve(S, T))

Submission status: Runtime Error

Solution code:
def solve(sequence, term):
    count = 0
    for t in term:
        count = 0
        for i, s in enumerate(sequence):
            if t == s or s == "?":
                count += 1
            else:
                count = 0
            if count == len(term):
                newSeq = sequence[:i - count+1] + term + sequence[i +1:]
                res = solve(newSeq, term)
                if (res == "UNRESTORABLE"):
                    return newSeq
                else:
                    return res
            
    return "UNRESTORABLE"

S = input()
T = input()
print(solve(S, T))

Submission status: Runtime Error

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

s_len = len(s)
t_len = len(t)

result = ''
for i in range(s_len - t_len, -1, -1):
    match = False
    s_part = s[i:i + t_len]
    for j in range(t_len + 1):
        if j == t_len:
            result = (s[0:i] + t + s[i + t_len:]).replace('?', 'a')
            match = True
            break
        if s_part[j] == '?':
            continue
        if s_part[j] != t[j]:
            match = False
            break
    if match:
        break

print(result if match else 'UNRESTORABLE')

Submission status: Runtime Error

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

s_len = len(s)
t_len = len(t)

result = ''
for i in range(s_len - t_len, -1, -1):
    match = False
    s_part = s[i:i + t_len]
    for j in range(t_len + 1):
        if j == t_len:
            result = (s[0:i] + t + s[i + 5:]).replace('?', 'a')
            match = True
            break
        if s_part[j] == '?':
            continue
        if s_part[j] != t[j]:
            match = False
            break
    if match:
        break

print(result if match else 'UNRESTORABLE')

Submission status: Runtime Error

Solution code:
fS, T = input(), input()

j = 0
k = 0
for i, c in enumerate(S):
  if j == len(T):
    break
  if c in (T[j], '?'):
    j += 1
  else:
    j = 0
    k = i + 1
if k < len(S):
  S = S[:k].replace('?', 'a') + T + S[k+len(T):].replace('?', 'a')
else:
  S = 'UNRESTORABLE'
print(S)

Submission status: Runtime Error

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

if len(S) < len(T):
    print('UNRESTORABLE')
else:
    raise Exception()
    # pos = []
    # # Sのi文字目をスタートとしたときにマッチするか
    # for i in range(len(S)-len(T)+1):
    #     # print('S[i]', S[i])
    #     match = True
    #     for j in range(len(T)):
    #         # print('-', T[j], S[i+j])
    #         if T[j] == S[i+j] or S[i+j] == '?':
    #             pass
    #         else:
    #             match = False
    #     if match:
    #         pos.append(i)

    # # print(pos)
    # if len(pos) == 0:
    #     print('UNRESTORABLE')
    # else:
    #     ans = 'z' * 51
    #     for pi in pos:
    #         r = ''
    #         for j in range(pi):
    #             if S[j] == '?':
    #                 r += 'a'
    #             else:
    #                 r += S[j]
    #         r += T
    #         for j in range(pi+len(T), len(S)):
    #             if S[j] == '?':
    #                 r += 'a'
    #             else:
    #                 r += S[j]
    #         ans = min(ans, r)
    #     print(ans)

Submission status: Runtime Error

Solution code:
# coding: utf-8
# Your code here!
# coding: utf-8
S=list(input())
T=list(input())
m=len(S)
n=len(T)
S.reverse()
T.reverse()
A=[]

for i in range(max(0,m-n+1)):
    flg=True
    #ans=copy.deepcopy(S)
    for j in range(n):
        if S[i+j]!='?':
            if S[i+j]!=T[j]:
                flg=False
    if flg:
        for j in range(n):
            if S[i+j]=='?':
                S[i+j]=T[j]
                
for i in range(m):
    if S[i]=='?':
        S[i]='a'
S.reverse()
if flg:
    print(S)
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

Solution code:
# coding: utf-8
S=list(input())
T=list(input())

S.reverse()
T.reverse()

for i in range(len(S)-len(T)):
    flg=True
    for j in range(len(T)):
        if not(S[i+j]=="?"):
            if S[i+j]!=T[j]:
                flg=False
    if flg:
        for k in range(len(T)):
            S[i+k]=T[k]
        break    
        

S.reverse()

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

Submission status: Runtime Error

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

moji = []

for i in range(len(S)):
    j = 0
    cnt = 0
    

    while j < len(T) and i+len(T)-1 < len(S):
        if S[i+j] == T[j] or S[i+j] == '?':
            cnt += 1

        else:
            break
        j += 1
    
    if cnt == len(T):
        moji0 = ''
        if i == 0: moji0 = T+S[i+len(T):len(S)]
        elif i+len(T) > len(S)-1: 
            moji0 = S[0:i]+T
        else:
            moji0 = S[0:i]+T+S[i+len(T):len(S)]

        
        moji1 = moji0.replace('?', 'a')
\
        moji.append(moji1)

    
print(min(moji) if moji != [] else "UNRESTORABLE")

Submission status: Runtime Error

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

moji = []

for i in range(len(S)):
    j = 0
    cnt = 0
    

    while j < len(T) and i+len(T)-1 < len(S):
        if S[i+j] == T[j] or S[i+j] == '?':
            cnt += 1

        else:
            break
        j += 1
    
    if cnt == len(T):
        moji0 = ''
        if i == 0: moji0 = T+S[i+len(T):len(S)]
        elif i+len(T) > len(S)-1: 
            moji0 = S[0:i]+T
        else:
            moji0 = S[0:i]+T+S[i+len(T):len(S)]

        
        moji1 = moji0.replace('?', 'a')
\
        moji.append(moji1)

    
print(min(moji))

Submission status: Runtime Error

Solution code:
s=input()
t=input()
a=-1
n=len(s)
k=len(t)
if k>n:
  print('UNRESTORABLE')
else:
  ans=str()
  for i in range(n):
    ok=True
    if n-i>=k:
      for j in range(k):
        if t[j]!=s[i+j] and s[i+j]!='?':
          ok=False
      if ok:
        a=i
  if a==-1:
    print('UNRESTORABLE')
  else:
    for i in range(n):
      if a<=i<=a+k-1:
        ans+=t[i-a]
      else:
        if s[i]=='?':
          ans+='a'
        else:
          ans+=s[i]
print(ans)

Submission status: Runtime Error

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

for i in range(len(S)):
    j = 0
    cnt = 0
    moji = []

    while j < len(T) and i+len(T)-1 < len(S):
        if S[i+j] == T[j] or S[i+j] == '?':
            cnt += 1
    if cnt == len(T):
        moji0 = S[0:i]+T+S[i+len(T)]
        moji1 = moji0.replace('?', 'a')
        moji.append(moji1)

    
print(min(moji))

Submission status: Runtime Error

Solution code:
S = list(input())
T = list(input())
for n in range(len(S)):
    if S[n] == T[0]:
        noOfnext = 0
        for m in range(n+1, len(S)):
            if S[m] == "?":
                noOfnext += 1
            else:
                break
        if noOfnext < len(T)-1:
            continue
        else:
            for m in range(noOfnext):
                S[n+1+m] = T[m+1]
            for k in range(len(S)):
                if S[k] == "?":
                    S[k] = "a"
if "?" in S:
    print("UNRESTORABLE")
else:
    print("".join(S))

Submission status: Runtime Error

Solution code:
s_d=input()
t=input()
for i in range(len(s_d)-len(t),-1,-1):
    flag = True
    for j,k in zip(s_d[i:i+len(t)],t):
        if j != "?" and j != k:
            flag=False
            break
    if flag:
        s_d = s_d[:i]+t+s_d[i+len(t)+1:]
        break
if not flag:
    print("UNRESTORABLE")
else:
    for i in s_d:
        if i == "?":
            print("a",end="")
        else:
            print(i,end="")

Submission status: Runtime Error

Solution code:
s = input()
t = input()
flag = False
tq = '?'*len(t)
start = []
for i in range(len(s)-len(t)+1):
    if s[i] == t[0]:
        start.append(i)
        for j in range(len(t)):
            if s[i+j] == t[j] or s[i+j] == '?':
                continue
            else:
                start.pop(-1)
    if s[i:i+len(t)] == tq:
        start.append(i)
stal = []
if start:
    for i in start:
        stal.append(s[:i].replace('?','a') + t + s[i+len(t):].replace('?','a'))
    stal.sort()
    print(stal[0])
else:
    print('UNRESTORABLE')

Submission status: Runtime Error

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

Submission status: Runtime Error

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

Submission status: Runtime Error

Solution code:

def main():
  S_=input()
  T=input()
  U=[]
  if len(S_)<len(T):
    print('UNRESTORABLE')
    return
  for i in range(len(S_)-len(T)+1):
    flag=True
    for j in range(len(T)):
      if S_[i+j]!='?' and S_[i+j]!=T[j]:
        flag=False
        break
    if flag:
      S=['a']*len(S_)
      for k in range(i):
        if S_[k]!='?':
          S[k]=S_[k]
      for k in range(i,i+len(T)):
        S[k]=T[k-i]
      for k in range(i+len(T),len(S_)):
        if S_[k]!='?':
          S[k]=S_[k]
      if ans=='':
        ans=''.join(S)
      elif ans>''.join(S):
        ans=''.join(S)
  if ans=='':
    print('UNRESTORABLE')
  else:
    print(ans)
  return

main()

Submission status: Runtime Error

Solution code:

def main():
  S_=input()
  T=input()
  U=[]
  if len(S_)<len(T):
    print('UNRESTORABLE')
    return
  for i in range(len(S_)-len(T)+1):
    flag=True
    for j in range(len(T)):
      if S_[i+j]!='?' and S_[i+j]!=T[j]:
        flag=False
        break
    if flag:
      S=['a']*len(S_)
      for k in range(i):
        if S_[k]!='?':
          S[k]=S_[k]
      for k in range(i,i+len(T)):
        S[k]=T[k-i]
      for k in range(i+len(T),len(S_)):
        if S[k]_!='?':
          S[k]=S_[k]
      if ans=='':
        ans=''.join(S)
      elif ans>''.join(S):
        ans=''.join(S)
  if ans=='':
    print('UNRESTORABLE')
  else:
    print(ans)
  return

main()

Submission status: Runtime Error

Solution code:
s = str(input())
t = str(input())
s_l =[]
for i in range(len(s)):
    s_l.append(s[i])

a = len(s) - len(t)

while a >= 0:
    insert = False
    string = True
    i = 0
    while i < len(t):
        if s[a + i] != "?" and s[a + i] != t[i]:
            string = False
            break
        i += 1
        
    if string == True:
        for i in range(len(t)):
                s_l[a+i] = t[i]
        insert = True
        break
    a -= 1

f = ""
if insert == True:
    for i in range(len(s)):
        if s_l[i] == "?":
            f += "a"
        else:
            f += s_l[i]
    print(f)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

Solution code:
s = str(input())
t = str(input())
s_l =[]
for i in range(len(s)):
    s_l.append(s[i])

a = len(s) - len(t)

while a >= 0:
    insert = False
    count = 0
    for i in range(0, len(t)):
        if s[a + i] == "?" or s[a + i] == t[i]:
            count += 1
    if count == len(t):
        for i in range(len(t)):
                s_l[a+i] = t[i]
        insert = True
        break
    i -= 1

f = ""

if insert:
    for i in range(len(s)):
        if s[i] == "?":
            f += "a"
        else:
            f += s_l[i]
    print(f)
else:
    print("UNRESTORABLE")

Submission status: Runtime Error

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
t = input()
n = len(s)
m = len(t)
for i in range(m-1,n)[::-1]:
    if s[i] == t[-1] or s[i] == '?':
        cnt = 0
        flg = False
        while cnt < m:
            if s[i-cnt] == t[-(cnt+1)] or s[i-cnt] == '?':
                cnt += 1
                if cnt == m:
                    flg = True
            else:
                break

        if flg:
            break
if not flg:
    print('UNRESTORABLE')
    quit()
ans = ''
cnt2 = 0
for k in range(n):
    if i-cnt < k <= i:
        ans += t[cnt2]
        cnt2 += 1
    else:
        if s[k] == '?':
            ans += 'a'
        else:
            ans += s[k]
print(ans)

Submission status: Runtime Error

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
t = input()
n = len(s)
m = len(t)

if m > n:
    print('UNRESTORABLE')
    quit()
i = n-1
while i-m >= 0:
    if (s[i] == t[-1]) or (s[i] == '?'):
        cnt = 0
        flg = False
        while cnt < m:
            if (s[i-cnt] == t[-cnt-1]) or (s[i-cnt] == '?'):
                cnt += 1
                if cnt == m:
                    flg = True
            else:
                break
        if flg:
            break
    i -= 1
if not flg:
    print('UNRESTORABLE')
    quit()
ans = ''
print(cnt)
cnt2 = 0
for k in range(n):
    if (k <= i-cnt) or (k > i):
        if s[k] == '?':
            ans += 'a'
        else:
            ans += s[k]
    else:
        ans += t[cnt2]
        cnt2 += 1
print(ans)

Submission status: Runtime Error

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
t = input()
n = len(s)
m = len(t)

i = 0
while i < n-m:
    if (s[i] == t[0]) or (s[i] == '?'):
        j = i
        flg = True
        while j-i < m:
            if (s[j] == t[j-i]) or (s[j] == '?'):
                j += 1
            else:
                flg = False
                break
        if flg:
            j -= 1
            break
    i += 1
if not flg:
    print('UNRESTORABLE')
    quit()
ans = ''
cnt = 0
for k in range(n):
    if k < i:
        if s[k] == '?':
            ans += 'a'
        else:
            ans += s[k]
    elif i <= k <= j:
        ans += t[cnt]
        cnt += 1
    else:
        if s[k] == '?':
            ans += 'a'
        else:
            ans += s[k]
print(ans)

Submission status: Runtime Error

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

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

s = input()
t = input()
n = len(s)
m = len(t)

i = 0
while i < n-m+1:
    if (s[i] == t[0]) or (s[i] == '?'):
        j = i
        flg = True
        while j-i < m:
            if (s[j] == t[j-i]) or (s[j] == '?'):
                j += 1
            else:
                flg = False
                break
        if flg:
            j -= 1
            break
    i += 1
if not flg:
    print('UNRESTORABLE')
    quit()
ans = ''
cnt = 0
for k in range(n):
    if k < i:
        if s[k] == '?':
            ans += 'a'
        else:
            ans += s[k]
    elif i <= k <= j:
        ans += t[cnt]
        cnt += 1
    else:
        if s[k] == '?':
            ans += 'a'
        else:
            ans += s[k]
print(ans)

Submission status: Runtime Error

Solution code:
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,ceil,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    S=ST()
    T=ST()
    N=len(S)
    M=len(T)
    ans = []
    for i in range(N-M+1)[::-1]:
        can = True
        for s,t in zip(S[i:],T):
            if s!=t and s!="?":
                can = False
        if can:
            for j,s in enumerate(S):
                if j<i:
                    if s=="?":
                        ans.append("a")
                    else:
                        ans.append(s)
                else:
                    ans.append(T[j-i])
            break
    if ans:
        print(*ans,sep="")
    else:
        print("UNRESTORABLE")
if __name__ == '__main__':
    main()

Submission status: Runtime Error

Solution code:
S = input()
T = input()
ind = 0
w = ""
for i in range(len(S)):
  if S[i] == "?" or S[i] == T[ind]:
    ind += 1
    if ind == len(T):
      w += T
      for j in range(i+1,len(S)):
        w += S[j]
      break
  else:
    for k in range(ind, 0 , -1):
      w += S[i-k]
    ind = 0
    w += S[i]
if ind < len(T):
  print("UNRESTORABLE")
else:
  for i in range(len(w)):
    if w[i] == "?":
      ans = w.replace("?", "a")
  print(ans)

Submission status: Runtime Error

Solution code:
S = input()
T = input()
ind = 0
w = ""
for i in range(len(S)):
  if S[i] == "?" or S[i] == T[ind]:
    ind += 1
    if ind == len(T):
      w += T
      for j in range(i+1,len(S)):
        w += S[j]
      break
  else:
    for k in range(ind, 0 , -1):
      w += S[i-k]
    ind = 0
    w += S[i]
if ind < len(T):
  print("UNRESTORABLE")
else:
  print(w)
  for i in range(len(w)):
    if w[i] == "?":
      ans = w.replace("?", "a")
  print(ans)

Submission status: Runtime Error

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

ans = "UNRESTORABLE"

i = 0

while i < len(s)-len(t)+2:
    flag = False
    if s[i] == t[0] or s[i] == "?":
        for j in range(1,len(t)):
            if s[i+j] == "?" or s[i+j] == t[j]:
                flag = True
            else:
                flag = False
                break
        if flag:
            tmps = ""
            k = 0
            while k < len(s):
                if k < i or k >= i+len(t):
                    if s[k] == "?":
                        tmps += "a"
                        k += 1
                    else:
                        tmps += s[k]
                        k += 1
                else:
                    tmps += t
                    k += len(t)
            ans = tmps
    i += 1

print(ans)