Problem:


Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.

He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.  

One more thing he found is a sheet of paper with the following facts written on it:  

Condition 1: The string S contains a string T as a contiguous substring.

Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.

Print the string S.

If such a string does not exist, print UNRESTORABLE.  

Constraints

1 \leq |S'|, |T| \leq 50

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

If such a string does not exist, print UNRESTORABLE instead.  

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

There are 26 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder.
Among them, the lexicographically smallest is atcoder, so we can say S = atcoder.

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

There is no string that satisfies Condition 1, so the string S does not exist.



Sample input:
?tc????
coder


Sample output:
atcoder

Submission status: Wrong Answer

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

LEN_S = len(S)
LEN_T = len(T)

if LEN_S < LEN_T:
  print('UNRESTORABLE')
  exit()

def isEquals(s):
  for i in range(LEN_T):
    if T[i] == s[i] or s[i] == '?':
      pass
    else:
      return False
  return True

answers = []
for i in range(LEN_S - LEN_T+1):
  if isEquals(S[i:i+LEN_T]):
    text = S[:i] + T + S[i+LEN_T+1:]
    answers.append(text.replace('?', 'a'))
  else:
    pass

if 0 < len(answers):
  answers.sort()
  print(answers[0])
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=1
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def is_ok(sd, st, t):
	if len(sd) < st+len(t):
		return False
	for i, c in enumerate(sd[st:st+len(t)]):
		if c != '?' and t[i] != c:
			return False
	return True
	
def to_aaa(a_str):
	rr=list(a_str)
	for i, c in enumerate(rr):
		rr[i] = 'a' if c == '?' else c
	ret = ''.join(rr)
	return ret

def mk_s(a_s_dash, i, t):
	front = to_aaa(a_s_dash[:i])
	back = to_aaa(a_s_dash[i+len(t):])
	ret = front+t+back
	pa((i,t,front,t,back,ret))
	return ret
			
def main():
	s_dash = input()
	t=input()
	dd='UNRESTORABLE'
	qq='?'
	
	aa=[]
	for i, _ in enumerate(s_dash[:len(t)+1]):
		if is_ok(s_dash,i,t):
			aa.append(mk_s(s_dash, i, t))
			#pa(aa)
			
	if len(aa)>0:
		aa.sort()
		ret = aa[0]
		print(ret)
		return
	print(dd)
	return
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def is_ok(sd, st, t):
	if len(sd) < st+len(t):
		return False
	for i, c in enumerate(sd[st:st+len(t)]):
		if c != '?' and t[i] != c:
			return False
	return True
	
def to_aaa(a_str):
	rr=list(a_str)
	for i, c in enumerate(rr):
		rr[i] = 'a' if c == '?' else c
	ret = ''.join(rr)
	return ret

def mk_s(a_s_dash, i, t):
	front = to_aaa(a_s_dash[:i])
	back = to_aaa(a_s_dash[i+len(t):])
	ret = front+t+back
	pa((i,t,front,t,back))
	return ret
			
def main():
	s_dash = input()
	t=input()
	dd='UNRESTORABLE'
	qq='?'
	
	aa=[]
	for i, _ in enumerate(s_dash[:len(t)]):
		#print(i)
		if is_ok(s_dash,i,t):
			aa.append(mk_s(s_dash, i, t))
			pa(aa[-1])
			pa(aa)
			
	if len(aa)>0:
		aa.sort()
		ret = aa[0]
		return ret
	return dd
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Submission status: Wrong Answer

Solution code:
def check(a, b):
    for i, j in zip(a, b):
        if i == "?" or i == j:
            pass
        else:
            return False
    return True


def make(a):
    x = ""
    for i in a:
        if i == "?":
            x += "a"
        else:
            x += i
    return x


s = list(input())
t = list(input())
n = len(t)
ans = []
for i in range(len(s)-n+1):
    if check(s[i:n+i], t):
        w = s[:i] + t + s[n+i:]
        ans.append(make(w))

if len(ans) == 0:
    print("UNRETSORABLE")
else:
    print(min(ans))

Submission status: Wrong Answer

Solution code:
# むずかしい

Submission status: Wrong Answer

Solution code:
def dubious(s, t):

    ans = ""
    count = -2

    for i in range(len(s) - len(t) + 1):
        for w in range(len(t)):
            if str(s[i + w]) != "?" and s[i + w] != t[w]:
                break
            elif w == len(t) - 1:
                count = i

    if count == -2:
        ans = "UNRESTORABLE"
    else:
        for i in range(len(s)):
            if i < count or count + len(t) < i:
                ans += s[i]
            elif i == count:
                ans += t
        ans = ans.replace("?" , "a")

    return ans

def main():
    s = str(input())
    t = str(input())
    print(dubious(s , t))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def dubious(s, t):

    ans = ""
    count = -2

    for i in range(len(s) - len(t), -1 , -1):
        for w in range(len(t) - 1, -1, -1):
            if str(s[i + w]) != "?" and s[i + w] != t[w]:
                break
            elif w == 0:
                count = i
        if count != -2:
            break

    if count == -2:
        ans = "UNRESTORABLE"
    else:
        for i in range(len(s)):
            if i < count or count+len(t) < i:
                ans += s[i]
            elif i == count:
                ans += t
        ans = ans.replace("?" , "a")

    return ans

def main():
    s = str(input())
    t = str(input())
    print(dubious(s , t))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def dubious(s, t):

    ans = ""
    count = -2

    for i in range(len(s) - len(t), -1 , -1):
        for w in range(len(t) - 1, -1, -1):
            if str(s[i + w]) != "?" and s[i + w] != t[w]:
                break
            elif w == 0:
                count = i

    if count == -2:
        ans = "UNRESTORABLE"
    else:
        for i in range(len(s)):
            if i < count or count+len(t) < i:
                ans += s[i]
            elif i == count:
                ans += t
        ans = ans.replace("?" , "a")

    return ans

def main():
    s = str(input())
    t = str(input())
    print(dubious(s , t))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def dubious(s, t):

    ans = ""
    count = -1

    for i in range(len(s) - len(t), -1 , -1):
        for w in range(len(t) - 1, -1, -1):
            if str(s[i + w]) != "?" and s[i + w] != t[w]:
                break
            elif w == 0:
                count = i

    if count == -1:
        ans = "UNRESTORABLE"
    else:
        for i in range(len(s)):
            if i < count or count+len(t) < i:
                ans += s[i]
            elif i == count:
                ans += t
        ans = ans.replace("?" , "a")

    return ans

def main():
    s = str(input())
    t = str(input())
    print(dubious(s , t))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ls = len(s)
lt = len(t)
match = -1

for i in range(ls-lt+1):
    for j in range(lt):
        if s[i+j] == t[j] or s[i+j] == '?':
            pass
            #continueはここで処理が終わってしまう
        else:
            break
            
        if j == lt - 1:
            match = i
        
for i in range(ls):
    if s[i] == '?':
        s[i] = 'a'
        
for i in range(lt):
    s[match+i] = t[i]
        
if match < 0:
    print("UNRESTORABLE")
else:
    print(s)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
s_len=len(s)
t_len=len(t)
ans="UNRESTORABLE"
if s_len>=t_len:
    for i in range(s_len-t_len+1):
        count=0
        for j in range(t_len):
            if s[i+j]=="?" or s[i+j]==t[j]:
                count+=1
            else:
                break
        if count==t_len:
            s=s[:i]+t[:]+s[i+t_len:]
            s=s.replace("?", "a")
            ans=s
            break
print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    input_string = input()
    part_string = input()

    s = []

    for i in range(len(input_string) - len(part_string), -1, -1):
        possible_part_string = input_string[i:i+len(part_string)]
        for j in range(len(part_string) + 1):  # 1つ多くループしているのは最後の処理のため
            if j == len(part_string):
                result = input_string[:i] + part_string + part_string[i + len(part_string):]
                result = result.replace("?", "a")
                print(result)
                return
            if possible_part_string[j] == "?":
                continue
            elif possible_part_string[j] != part_string[j]:
                break

    print("UNRESTORABLE")

solve()

Submission status: Wrong Answer

Solution code:

def solve():
    input_string = input()
    part_string = input()

    s = []

    for i in range(len(input_string) - len(part_string), -1, -1):
        possible_part_string = input_string[i:i+len(part_string)]
        for j in range(len(part_string) + 1):  # 1つ多くループしているのは最後の処理のため
            if j == len(part_string):
                result = input_string[:i] + part_string + part_string[i + len(part_string):]
                result.replace("?", "a")
                print(result)
                return
            if possible_part_string[j] == "?":
                continue
            elif possible_part_string[j] != part_string[j]:
                break

    print("UNRESTORABLE")

solve()

Submission status: Wrong Answer

Solution code:
s=str(input())
t=str(input())
s=list(s)
t=list(t)
count2=0
count=0
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        #print(s[i+j])
        if s[i+j]!='?' and  s[i+j]!=t[j]:
            count=0
            break
        else:
            count+=1
        #print(count)
    
    if count==len(t):
        for z in range(len(s)):
            if z<i or i+len(t)-1<z:
                if s[z]=='?':
                    print("a",end="")
                else:
                    print(s[z],end="")
            else:
                #print(count2)
                print(t[count2],end="")
                count2+=1
        exit()
    count=0
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def solve():
    input_string = input()
    part_of_string = input()  # 含まれる可能性のある、部分文字列
    key_string = ""  # 回答の鍵文字列

    # (?????, AA)の場合 -> 3,2,1,0
    for search_i in range(len(input_string) - len(part_of_string), -1, -1):
        result_string = ""
        string_for_search = input_string[search_i: search_i + len(part_of_string)]  # part_of_stringに置き換わる可能性のある文字列

        has_key_string = True
        for search_j in range(len(string_for_search)):
            if string_for_search[search_j] == "?" or string_for_search[search_j] == part_of_string[search_j]:
                result_string = result_string + part_of_string[search_j]
            else:
                has_key_string = False
        if has_key_string:
            result_string = input_string[:search_i] + result_string + input_string[search_i + len(part_of_string):]
            result_string.replace("?", "a")
            print(result_string)
            return  # 1つ見つかったら終了する
    print("UNRESTORABLE")
    
solve()

Submission status: Wrong Answer

Solution code:
def main():
  import copy
  
  s=list(map(str,list(input())))
  t=list(map(str,list(input())))
  h=len(s)
  w=len(t)
  
  ans=[]
  
  for i in range(h):
    u=copy.deepcopy(s)
    if i+w>h:
      continue
    
    if u[i+1:i+w]==["?"]*(w-1):
      
      u[i:i+w]=t
      
      for i in range(h):
        if u[i]=="?":
          u[i]="a"
          
      ans.append("".join(u))
  
  if len(ans)==0:
    print("UNRESTORABLE")
  
  else:
    ans.sort()
    print(ans[0])
   
if __name__=="__main__":
  main()

Submission status: Wrong Answer

Solution code:
def main():
  import copy
  
  s=list(map(str,list(input())))
  t=list(map(str,list(input())))
  h=len(s)
  w=len(t)
  
  ans=[]
  
  for i in range(h):
    u=copy.deepcopy(s)
    if i+w>h:
      continue
    
    if u[i+1:i+w]==["?"]*(w-1):
      
      u[i:i+w]=t
      
      for i in range(h):
        if u[i]=="?":
          u[i]="a"
          
      ans.append("".join(u))
  
  if len(ans)==0:
    print("UNRESTORABLE")
  
  else:
    ans=sorted(ans)
    print(ans[0])
   
if __name__=="__main__":
  main()

Submission status: Wrong Answer

Solution code:
def main():
  s=list(map(str,list(input())))
  t=list(map(str,list(input())))
  h=len(s)
  w=len(t)
  ans=[]
  for i in range(h):
    if i+w>h:
      continue
    if s[i+1:i+w]==["?"]*(w-1):
      s[i:i+w]=t
      for i in range(len(s)):
        if s[i]=="?":
          s[i]="a"
        ans.append("".join(s))
  if len(ans)==0:
    print("UNRESTORABLE")
  else:
    ans=sorted(ans)
    print(ans[0])
    
if __name__=="__main__":
  main()

Submission status: Wrong Answer

Solution code:
def main():
  s=list(map(str,list(input())))
  t=list(map(str,list(input())))
  w=len(t)

  if t[0] in s:
    i=s.index(t[0])
    if i+w<=len(s) and s[i+1:i+w+1]==["?"]*(w-1):
      s[i:i+w+1]=t
      for i in range(len(s)):
        if s[i]=="?":
          s[i]="a"
      print("".join(s))
  else:
    print("UNRESTORABLE")
  
if __name__=="__main__":
  main()

Submission status: Wrong Answer

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

slen = len(s)
Tlen = len(T)
ans = "UNRESTORABLE"
if slen >= Tlen:
    for i in range(slen - Tlen + 1)[::-1]:
        for j in range(Tlen):
            if not s[i+j] in ("?", T[j]):
                break
        else:
            ans = s
            ans = ans[:i] + T + ans[i+Tlen:]
            ans = ans.replace("?", "a")
            print(ans)
            break

print(ans)

Submission status: Wrong Answer

Solution code:
def solve():
    S = input()
    T = input()
    ls = len(S)
    lt = len(T)
    lst = []
    w_lst = []
    if ls < lt:
        return 'UNRESTORABLE'
    if ls == lt:
        for i in range(ls):
            if not S[i] == T[i]:
                return 'UNRESTORABLE'
        return S
    for d in range(ls - lt + 1):
        eq = True
        for i in range(lt):
            if S[i + d] == '?':
                continue
            if not S[i + d] == T[i]:
                eq = False
                break
        if eq:
            lst.append(d)
    if len(lst) == 0:
        return 'UNRESTORABLE'
    for d in lst:
        w = S[0:d] + T + S[d + lt:]
        for i in range(ls):
            if w[i] == '?':
                w = w[0:i] + 'a' + w[i + 1:]
        w_lst.append(w)
    return min(w_lst)
if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

Solution code:
def solve():
    S = input()
    T = input()
    ls = len(S)
    lt = len(T)
    lst = []
    w_lst = []
    if ls < lt:
        return 'UNRESTORABLE'
    if ls == lt:
        for i in range(ls):
            if not S[i] == T[i]:
                return 'UNRESTORABLE'
        return S
    for d in range(ls - lt + 1):
        eq = True
        for i in range(d, ls):
            if S[i] == '?':
                continue
            if 0 <= i - d < lt and not S[i] == T[i - d]:
                eq = False
                break
        if eq:
            lst.append(d)
    if len(lst) == 0:
        return 'UNRESTORABLE'
    for d in lst:
        w = S[0:d] + T + S[d + lt:]
        for i in range(ls):
            if w[i] == '?':
                w = w[0:i] + 'a' + w[i + 1:]
        w_lst.append(w)
    return min(w_lst)
if __name__ == '__main__':
    print(solve())

Submission status: Wrong Answer

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

ans = ""
match = 0

for i in range(len(s)):
    if i < len(t):
        continue
    for j in reversed(range(len(t))):
        if s[-i+j] == "?" or s[-i+j] == t[j]:
            if j == 0:
                match = i
                break
            continue
        else:
            break

if match != 0:
    s_rev = s[::-1]
    t_rev = t[::-1]
    ans = s_rev[i-1+len(t)::] + t_rev + s_rev[i-1+len(t)::] + s_rev[i-1::]
    print(ans.replace("?","a")[::-1])
    exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys

S = input()
T = input()

t = len(T)
answers = []

if len(T) > len(S):
  print("UNRESTORABLE")
  sys.exit()

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'))
    
if len(answers) == 0:
  print("UNRESTORABLE")
else:
  answers.sort()  
  print(answers[0])

Submission status: Wrong Answer

Solution code:
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(input()) #整数読み込み
def ifn(): return float(input()) #浮動小数点読み込み
def isn(): return input().split() #文字列読み込み
def imn(): return map(int, input().split()) #整数map取得
def fmn(): return map(float, input().split()) #浮動小数点map取得
def iln(): return list(map(int, input().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, input().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD

S = input()
T = input()

ans = ''

index = -1
matched = 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:
        matched = True
        S = S[0:i] + T + S[i+len(T):len(S)]
if not matched:
    print('UNRESTORABLE')
else:
    for i in range(len(S)):
        if S[i] == '?':
            ans += 'a'
        else:
            ans += S[i]
    print(ans)

Submission status: Wrong Answer

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

t = len(T)
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'))
    
if len(answers) == 0:
  print("UNRESTORABLE")
else:
  answers.sort()  
  print(answers[0])

Submission status: Wrong Answer

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

t = len(T)
ans = "UNRESTORABLE"

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]

print(ans.replace('?', 'a'))

Submission status: Wrong Answer

Solution code:
S=list(input())
T=list(input())
p=-1; i=0; e=0
for i in range(len(S)-len(T)+1):
  for j in range(len(T)):
    if S[j+i]==T[j] or S[j+i]=="?":
      e=e+1
      #print(i,p,e)
    else:
      e=0
      break
    if e==len(T):
      p=i
      e=0
    #print(i,p,e)
if p==-1:
  print("UNRESTORABLE")
else:
  S[p:p+len(T)]=T
  for i in range(len(S)):
    if S[i]=="?":
      S[i]="a"
  print(S)

Submission status: Wrong Answer

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

num_t=len(t)
if len(s)<num_t:
    print('UNRESTORABLE')
    exit()
num=-1
for i in range(len(s)-num_t+1):
    temp_s=s[i:i+num_t]
    trial=True
    for x,y in zip(temp_s,t):
        if x!='?' and x!=y:
            trial=False
            break

    if trial:
        num=i
        break
        
if num==-1:
    print('UNRESTORABLE')
    exit()

ans=''
for i in range(len(s)):
    if num==i:
        ans+=t

    elif i<num or num+num_t<=i:
        if s[i]=='?':
            ans+='a'
        else:
            ans+=s[i]
print(ans)

Submission status: Wrong Answer

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

num_t=len(t)
num=-1
for i in range(len(s)-num_t+1):
    temp_s=s[i:i+num_t]
    trial=True
    for x,y in zip(temp_s,t):
        if x!='?' and x!=y:
            trial=False
            break

    if trial:
        num=i
        break
ans=''
for i in range(len(s)):
    if num==i:
        ans+=t

    elif i<num or num+num_t<=i:
        if s[i]=='?':
            ans+='a'
        else:
            ans+=s[i]
print(ans if num!=-1 else 'UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys

s = list(input())
t = list(input())

for i in range(len(s) - len(t) + 1):
    ok = True
    for j in range(len(t)):
        if s[i + j] != '?' and s[i + j] != t[j]:
            ok = False
            break
    if ok:
        s[i : i + len(t)] = t
        for i in range(len(s)):
            if s[i] == '?':
                s[i] = 'a'
        print(''.join(s))
        sys.exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=list(input())
t=input()
n,m=len(s),len(t)
def match(a,b):
    for i in range(len(a)):
        if a[i]!=b[i] and a[i]!="?":
            return False
    return True
flag=True
for i in range(n-m,-1,-1):
    if match(s[i:i+m],t):
        for j in range(m):
            s[j+i]=t[j]
        flag=False
if flag:
    print("UNRESTORABLE")
    exit()
for i in range(n):
    if s[i]=="?":
        s[i]="a"
print(*s,sep="")

Submission status: Wrong Answer

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

ls = len(S)
lt = len(T)

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

diff = ls - lt

candidates = []
for i in range(diff+1):
    string = S[i:i+lt]

    for j in range(lt):
        if string[j] == T[j] or string[j] == '?':
            continue
        else:
            break

    else:
        candidate = S[:i] + T
        candidate = candidate.replace('?', 'a')
        candidates.append(candidate)

if not candidates:
    print('UNRESTORABLE')
    exit()

ans = min(candidates)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
sl = len(s)
tl = len(t)

if sl < tl:
  print("UNRESTORABLE")
  exit()
  
possible = []
for i in range(sl - tl + 1):
  temp = s[i:i+tl]
  flag = True
  for a, b in zip(t, temp):
    if b != "?" and a != b:
      flag = False
  if flag:
    s = s[:i] + t + s[i+tl:]
    possible.append(s.replace("?", "a"))
if len(possible) == 0:
  print("UNRESTORABLE")
  exit()
print(sorted(possible)[0])

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
sl = len(s)
tl = len(t)

if sl < tl:
  print("UNRESTORABLE")
  exit()
  
possible = []
for i in range(sl - tl + 1):
  temp = s[i:i+tl]
  flag = True
  for a, b in zip(t, temp):
    if b != "?" and a != b:
      flag = False
  if flag:
    w = s[:i] + t + s[i+tl:]
    possible.append(w.replace("?", "a"))
if len(possible) == 0:
  print("UNRESTORABLE")
  exit()
print(possible[0])

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ls = len(s)
lt = len(t)
cands = []

for i in range(ls-lt):
  cand = list(s)
  for j in range(lt):
    if s[i+j] != '?' and s[i+j] != t[j]:
      cand = []
      break
    else:
      cand[i+j] = t[j]
  if cand:
    cands.append(''.join(cand).replace('?', 'a'))
if cands:
  cands.sort()
  print(cands[0])
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

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

start_t = t[0]

def t_check(t_str, t_e):
  r = True
  for i, ts in enumerate(list(t_e)):
    if ts == '?':
      continue
    if ts != t_str[i]:
      r = False
  return r

a = s
is_t_correct = False
for i, si in enumerate(list(s)):
  if si != '?' and si == start_t:
    if len(s) - i >= len(t):
      expected_t = a[i:i+len(t)]
      if t_check(t, expected_t):
        a = a[0:i] + t + a[i+len(t):]
        is_t_correct = True
  if si == '?' and i+len(t) <= len(a) and a[i:i+len(t)] == '?'*len(t):
    a = a[0:i] + t + a[i+len(t):]
    is_t_correct = True

if is_t_correct is False:
  print('UNRESTORABLE')
  exit(0)
      
print(a.replace('?', 'a'))

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(1000000)

def solve(sequence, term):
    res = []
    for index in range(len(sequence) - len(term) + 1):
        count = 0
        for i, s in enumerate(sequence[index : index + len(term)]):
            if s == term[i] or s == "?":
                count += 1
            else:
                break
            if count == len(term):
                res.append((sequence[:index] + term + sequence[index +count+1:]).replace("?", "a"))

    if len(res) == 0:
        return "UNRESTORABLE"
    else:
        return sorted(res)[0]

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

Submission status: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(1000000)

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:
                break
            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: Wrong Answer

Solution code:
import sys

sys.setrecursionlimit(1000000)

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: Wrong Answer

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):
                return (sequence[:i - count+1] + term + sequence[i +1:]).replace("?", "a")
            
    return "UNRESTORABLE"

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

Submission status: Wrong Answer

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):
                return (sequence[:i - count+1] + term + sequence[i +2:]).replace("?", "a")
            
    return "UNRESTORABLE"

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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]!=t[j] and s[i+j]!="?":
            flag = False
            break
    if flag:
        ans = ""
        for k in range(i):
            if s[k]!="?":
                ans+=s[k]
               
            else:
                ans += "a"
        ans+=t
        for k in range(i+len(t),len(s)):
            if s[i]!="?":
                ans+=s[i]
            else:
                ans += "a"
        print(ans)
        exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

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

# tの当てはまり判定
start_ind = "#"
for i in range(len(s)-len(t)+1):
    temp = s[i:i+len(t)]
    flag = False
    for j, x in enumerate(temp):
        if (t[j] == x or t[j] == "?"):
            flag = True
    if flag:
        start_ind = i

if start_ind == "#":
    print("UNRESTORABLE")
    exit()

x = s[:start_ind] + t + s[start_ind+len(t):]

ans = ""
for c in x:
    if c == "?":
        ans += "a"
    else:
        ans += c

print(ans)

Submission status: Wrong Answer

Solution code:
SS=list(map(str,input()))
T=list(map(str,input()))
T1=len(T)
f=0
p=-1
j=0

#print(SS)
#print(T)
for i in range(len(SS)-T1+1):
  if SS[i]==T[min(j,(len(T)-1))] or SS[i]=="?" :
    p=i
    f=f+1
    #print(p,SS[i],T[j],i,j,f)
    j=j+1
    if f==T1 and p!=-1 and SS[min(i,len(SS))]!="?":
      break
  else:
    p=-1
    f=0
    j=0
  
#print(p,j,f,T1,len(SS),i)
for i in range(p,p+T1):
  SS[i]=T[i-p]
for i in range(len(SS)):
  if SS[i]=="?":
    SS[i]="a"

if p==-1:
  print("UNRESTORABLE")
else:
  print("".join(map(str,SS)))

Submission status: Wrong Answer

Solution code:
SS=list(map(str,input()))
T=list(map(str,input()))
T1=len(T)
f=0
p=-1
j=0

#print(SS)
#print(T)
for i in range(len(SS)-T1+1):
  if SS[i]==T[j] or SS[i]=="?" :
    p=i
    f=f+1
    #print(p,SS[i],T[j],i,j,f)
    j=j+1
    if f==T1 and p!=-1:
      p=p-(T1-1)
      break
  else:
    p=-1
    f=0
    j=0
  
#print(p,j,f,T1,len(SS),i)
for i in range(p,p+T1):
  SS[i]=T[i-p]
for i in range(len(SS)):
  if SS[i]=="?":
    SS[i]="a"

if p==-1:
  print("UNRESTORABLE")
else:
  print("".join(map(str,SS)))