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: Accepted

Solution code:
s,t = input(), input()
len_s = len(s)
len_t = len(t)

match = []
for i in range(len_s - len_t + 1):
    if s[i] == "?" or s[i] == t[0]:
        for s_j, t_j in zip(s[i:i+len_t], t):
            if s_j != t_j and s_j != "?":
                break
        else:
            temp = s[:i] + t + s[i + len_t:]
            match += [temp.replace("?", "a")]

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

Submission status: Accepted

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

S = S.replace('?', '.')
t_len = len(T)
for i in reversed(range(len(S) - t_len + 1)):
    if re.match(S[i:i + t_len], T) is not None:
        S = S[:i] + T + S[i + t_len:]
        print(S.replace('.', 'a'))
        break
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
import re
  
# 正解法   S=?b?? T=ab -> ans:abaa
def solve(s, t):
    s = s.replace('?', '.')
    ls, lt = len(s), len(t)
    if ls < lt:
        return 'UNRESTORABLE'
    ans = []
    for i in range(ls - lt + 1):
        m = re.match(s[i:i + lt], t)
        if m is None:
            continue
        ans.append((s[:i] + t + s[i + lt:]).replace('.', 'a'))
    if not ans:
        return 'UNRESTORABLE'
    return min(ans)
  
  
s = input().strip()
t = input().strip()
  
print(solve(s, t))

Submission status: Accepted

Solution code:
import re
S = input().replace("?", ".")[::-1]
T = input()[::-1]

for i in range(len(S)-len(T)+1):
  if re.match(S[i:i+len(T)], T):
    S = S.replace(".", "a")
    ans = S[:i]+T+S[i+len(T):]
    print(ans[::-1])
    exit()    
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s = input()
t = input()
flag = False
tlen = len(t)
slen = len(s)

def same(a,b):
    for aa, bb in zip(a,b):
        if not(aa =="?" or aa == bb):
            return False
    return True

if tlen <= slen:
    for i in range(slen-tlen,-1,-1):
        if same(s[i:i+tlen],t):
            flag = True
            s = s[:i]+t+s[i+tlen:]
            break
ans = ""
if flag:
    for ss in s:
        if ss == "?":
            ans += "a"
        else:
            ans += ss
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Accepted

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



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    S = input().replace('?', '.')
    T = input()

    import re
    import sys

    for i in range(len(S)-len(T),-1,-1):
        if(re.match(S[i:i+len(T)],T)):
            S = S.replace('.', 'a')
            print(S[:i]+T+S[i+len(T):])
            exit()
    else:
        print("UNRESTORABLE")
    
if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
import itertools
import math



def do():
    S = input()
    T = input()
    s = len(S)
    t = len(T)
    flag = False
    for i in range(s-t,-1,-1):
        if S[i] == "?" or S[i] ==T[0]:
            flag = True
            for j in range(t):
                if T[j] == S[i+j] or S[i+j] == "?":
                    pass
                else:
                    flag = False
        if flag:
            break
    if flag:
        ans = list(S)
        for k in range(i,i+t):
            ans[k] = T[k-i]
        for i,temp in enumerate(ans):
            if temp == "?":
                ans[i] = "a"
        print("".join(ans))
    else:
        print("UNRESTORABLE")





if __name__ == "__main__":
    do()

Submission status: Accepted

Solution code:
s=list(input())[::-1]
t=list(input())[::-1]
if len(s)<len(t):print('UNRESTORABLE')
else:
	for i in range(len(s)-len(t)+1):
		for j in range(len(t)):
			if s[i+j] not in ['?',t[j]]:break
		else:
			s[i:i+len(t)]=t
			break
	else:
		print('UNRESTORABLE')
		exit()
	print(''.join(s[::-1]).replace('?','a'))

Submission status: Accepted

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

ans = "UNRESTORABLE"

for i in range(len(S)-len(T)+1) :
    for j in range(len(T)) :
        if S[i+j] not in ["?", T[j]] : 
            break
    else :
        ans = (S[:i]+ T + S[i+len(T):])[::-1].replace("?", "a")
        break

print(ans)

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()
  t=S()

  for i in range(len(s)-len(t)+1)[::-1]:
    x=s[i:i+len(t)]
    f=True
    for j in range(len(t)):
      if t[j]!=x[j] and x[j]!='?':
        f=False

    if f:
      return s[:i].replace('?','a')+t+s[i+len(t):].replace('?','a')

  return 'UNRESTORABLE'

print(main())

Submission status: Accepted

Solution code:
S = input()
T = input()
lenS = len(S)
lenT = len(T)
flag = False
ans = list(S)

for i in range(lenS-lenT, -1, -1):
    for j in range(lenT):
        if S[i+j] != T[j] and S[i+j] != '?':
            break
    else:
        flag = True
        break

if flag:
    for k in range(lenT):
        ans[i+k] = T[k]
    
    for k in range(lenS):
        if ans[k] == '?':
            ans[k] = 'a'
    print("".join(ans))
            
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
S = input()
T = input()
n = len(S)
t = len(T)
ans = ''
if t > n:
    flag = False
for i in range(t, n+1):
    flag = True
    for j in range(t):
        if S[-i+j] != '?' and S[-i+j] != T[j]:
            flag = False
            break
    if flag:
        break
if flag:
    for s in S[:-i]:
        if s == '?':
            ans += 'a'
        else:
            ans += s
    ans += T
    if i != t:
        for s in S[-i+t:]:
            if s == '?':
                ans += 'a'
            else:
                ans += s
    print(ans)
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
from itertools import product
s=input()
t=input()
t_point=-1
for i in range(len(s)-len(t)+1):
     for j in range(len(t)):
          if s[i+j]=='?':
               continue
          elif s[i+j]!=t[j]:
               break
     else:
          t_point=i
if t_point<0:
     print('UNRESTORABLE')
else:
     s=[x for x in s]
     for j in range(len(t)):
          s[t_point+j]=t[j]
     for i in range(len(s)):
          if s[i]=='?':
               s[i]='a'
     print(''.join(s))

Submission status: Accepted

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

Submission status: Accepted

Solution code:
S = input()
T = input()
c = 0
idx = 0
ans = []
for i, s in enumerate(S):
    if s == T[0] or s == '?':
        tmp = S[i:min(i+len(T), len(S))]
        flg = True
        if len(T) != len(tmp):
            continue
        for j, c in enumerate(tmp):
            if c != T[j] and c != '?':
                flg = False
                break
        if flg:
            ans.append((S[:i] + T + S[i+len(T):]).replace('?', 'a'))
if len(ans) == 0:
    print('UNRESTORABLE')
else:
    ans.sort()
    print(ans[0])

Submission status: Accepted

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

s = s.replace("?", ".")[::-1]
t = t[::-1]

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

Submission status: Accepted

Solution code:
hoge=input()
key=input()
ans=[]
for i in range(len(hoge)-len(key)+1):
  flag=0
  for j in range(len(key)):
    if(hoge[i+j]==key[j] or hoge[i+j]=="?"):
      flag+=1
  if(flag==len(key)):
    kari=hoge[:i]+key+hoge[i+len(key):]
    ans.append(kari.replace("?","a"))
    
if(len(ans)>0):
  ans.sort()
  print(ans[0])
else:
  print("UNRESTORABLE")

Submission status: Accepted

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

import re


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    S = input()
    T = input()

    S = S.replace("?",".")

    pos = []
    for i in range(0,len(S)-len(T)+1):
        s =  S[i:i+len(T)]
        m = re.match(s,T)
        if m: 
            pos.append(i)

    if len(pos) == 0:
        print("UNRESTORABLE")
        return

    S = S.replace(".","a")
    si = max(pos)

    print(S[0:si] + T + S[si+len(T):])




    pass

if __name__ == '__main__':
    main()

Submission status: Accepted

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

for n in range(0, len(S) - len(T) + 1):
	for i, t in enumerate(T):
		if "?" == S[n + i]:
			continue
		if t != S[n + i]:
			break
	else:
		S[n:n + len(T)] = T
		print("".join(S[::-1]).replace("?", "a"))
		break
else:
	print("UNRESTORABLE")

Submission status: Accepted

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

for i in range(len(S) - len(T) + 1):
    if i == 0:
        seq = S[-len(T)-i:]
    else:
        seq = S[-len(T)-i:-i]
    for j in range(len(T)):
        if seq[j] == "?":
            seq = seq[:j]+T[j]+seq[j+1:]

    if seq == T:
        if i == 0:
            print((S[:-len(T)-i]+T).replace("?", "a"))
        else:
            print((S[:-len(T)-i]+T+S[-i:]).replace("?", "a"))
        exit()

print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s = list(input())
t = input()
ls, lt = len(s), len(t)

def seq(inlist):
	global t
	dismatch = 0
	for i in range(len(t)):
		if t[i] != inlist[i] and inlist[i] != "?":
			dismatch = 1
			break
	return dismatch


ans = "UNRESTORABLE"
if ls >= lt:

	d = -1
	for i in range(ls-lt+1):
		if seq(s[i:i+lt]) == 0:
			d = i
	if d != -1:

		for i in range(lt):
			s[d+i] = t[i]
		for i in range(ls):
			if s[i] == "?":
				s[i] = "a"

		ans = "".join(s)

print(ans)

Submission status: Accepted

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

candi = []

for i in range(len(s)-len(t)+1):
    c = 0
    k = s[:]
    for j in range(len(t)):
        if s[i+j] == t[j] or s[i+j] == '?':
            k[i+j] = t[j]
            c += 1
    
    
    if c == len(t):
        candi.append(k)

if len(candi) == 0:
    print('UNRESTORABLE')
    
else:
    for i in range(len(candi)):
        for j in range(len(s)):
            if candi[i][j] == '?':
                candi[i][j] = 'a'

    candi = sorted(candi)

    print(''.join(candi[0]))

Submission status: Accepted

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

def check(s):
    for t in range(len(T)):
        if S[s+t] != "?" and S[s+t] != T[t]:
            return False
    return True

p = -1
for s in range(len(S)-len(T)+1):
    c = check(s)
    if c:
        p = s

S = S.replace("?", "a")

if p == -1:
    print "UNRESTORABLE"
else:
    print S[:p] + T + S[(p + len(T)):]

Submission status: Accepted

Solution code:
def m():
    Sdash = input()
    T = input()

    diff = len(Sdash) - len(T)

    if diff < 0:
        print('UNRESTORABLE')
        return

    index = -1
    for i in range(diff+1):
        Sp = Sdash[i:i+len(T)]
        for j in range(len(T)):
            if T[j] == Sp[j] or Sp[j] == '?':
                pass
            else:
                break
        else:
            index = i
    if index < 0:
        print('UNRESTORABLE')
        return

    res = Sdash.replace('?', 'a')
    res = res[0:index] + T + res[index+len(T):]
    print(res)


if __name__ == '__main__':
    m()

Submission status: Accepted

Solution code:
# 写経
S = input()
T = input()


found = []
for i in range(len(S) - len(T) + 1):
    for cs, ct in zip(S[i:], T):
        if cs != "?" and cs != ct:
            break
    else:
        found.append(i)


if not found:
    ans = "UNRESTORABLE"
else:
    ans = "z" * 51
    for i in found:
        tmp = S[:i] + T + S[i+len(T):]
        ans = min(ans, tmp.replace("?", "a"))
print(ans)

Submission status: Accepted

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

cnd = []
for i in range(len(s) - len(t) + 1):
    if all(s[i + j] == t[j] or s[i + j] == '?' for j in range(len(t))):
        cnd.append(i)

if cnd:
    x = [s[:k] + t + s[k + len(t):] for k in cnd]
    x = [v.replace('?', 'a') for v in x]
    print(sorted(x)[0])
else:
  	print('UNRESTORABLE')

Submission status: Accepted

Solution code:
import re
Srd = "".join(reversed(input()))
T = input()
Tr = "".join(reversed(T))
Trd = "".join(["[{}?]".format(x) for x in Tr])

S = "".join(reversed(re.sub(Trd, Tr, Srd, 1))).replace("?", "a")
if S.count(T):
  print(S)
else:
  print("UNRESTORABLE")

Submission status: Accepted

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

for i in range(len(s)-len(t),-1,-1):
    tmp = s[i:i+len(t)]
    ans = ''
    for j in range(len(t)):
        if tmp[j] != t[j] and tmp[j] != '?':
            break
        ans += t[j]
        if j == len(t)-1:
            ans = s[:i]+ans+s[len(t)+i:]
            print(ans.replace('?','a'))
            exit()
print('UNRESTORABLE')

Submission status: Accepted

Solution code:
import math
import fractions
import copy
#以下てんぷら
def j(q):
    if q==1: print("YES")
    elif q == 0:print("NO")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def printrow(a):
    for i in range(len(a)):
        print(a[i])
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)


#n = ip()                                     #入力整数1つ
#n,k= (int(i) for i in input().split())       #入力整数横2つ以上
#a = [int(i) for i in input().split()]        #入力整数配列
a = input()                                  #入力文字列
#a = input().split()                          #入力文字配列
#n = ip()                      #入力セット(整数改行あり)(1/2)
#a=[ip() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#a=[input() for i in range(n)]    #入力セット(整数改行あり)(2/2)
#jの変数はしようできないので注意
#全足しに4 3sum変数使用はsum関数使用できないので注意
b = input()
matchplace = []
diff = len(a)-len(b)
for i in range(len(a)-len(b)+1):
    cut = a[i:i+(len(b))]
    for k in range(len(cut)):
        if not(cut[k] == b[k] or cut[k] == '?'):
            break
        else:
            if k == len(b)-1:
                matchplace.append(i)
wordlist = []
for i in matchplace:
    cword = [ a[:i],b,a[(i+len(b)):] ]
    cword = ''.join(cword)
    cword = cword.replace('?','a')
    wordlist.append(cword)
if len(matchplace) == 0:
    print("UNRESTORABLE")
else:
    wordlist.sort()
    print(wordlist[0])

Submission status: Accepted

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

ans = []
for i in range(len(S) - len(T) + 1):
    c = ""
    for j in range(len(T)):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break
        c += T[j]
    if len(c) == len(T):
        ans.append((S[:i] + c + S[i+len(T):]).replace("?", "a"))
print(min(ans) if ans else "UNRESTORABLE")

Submission status: Accepted

Solution code:
from copy import deepcopy

S = str(input())
T = str(input())

if len(S) < len(T):  ## ヒントの文字列が長すぎる場合
  print('UNRESTORABLE')
  exit()

solve = []
for i in range(len(S)-len(T)+1):
  bool_match = True
  for j in range(len(T)):
    if S[i+j] != '?' and S[i+j] != T[j]:
      bool_match = False
      break
  if bool_match == True:
    if len(S) == len(T):
      S_tmp = T
    elif i == 0:
      S_tmp = T + S[len(T):]
    elif i+len(T) == len(S):
      S_tmp = S[:-len(T)] + T
    else:
      S_tmp = S[:i] + T + S[i+len(T):]
    solve.append(S_tmp.replace('?', 'a'))

if len(solve) == 0:
  print('UNRESTORABLE')
else:
  print(sorted(solve)[0])

Submission status: Accepted

Solution code:
# coding: utf-8
# Your code here!

words= list(input())
target = list(input())
i=len(words)-len(target)
flag=False
while(0<=i):
    flag = True
    for j in range(len(target)):
        if not(words[i+j] == target[j] or words[i+j] == '?'):
            flag = False
            break
    if flag is True:
        words[i:i+len(target)] = target
        for k,word in enumerate(words):
            if word == '?':
                words[k]='a'
        break
    i-=1

if flag is True:
    print(''.join(words))
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
S = input()
T = input()
s = len(S)
t = len(T)
q = []
for i in range(s+1-t):
  f = True
  for j in range(t):
    if S[i+j] == '?' or S[i+j] == T[j]:
      continue
    f = False
  if f:
    #print(S[i+t:])
    tmp = S[:i] + T + S[i+t:]
    #print(tmp)
    q.append(tmp.replace('?','a'))
    q.sort()
if len(q) == 0:
  print('UNRESTORABLE')
else:
  print(q[0])

Submission status: Accepted

Solution code:
S=list(input())
T=list(input())
L=[]
if len(S)-len(T)<0:
    print('UNRESTORABLE')
    exit()
for i in range(len(S)-len(T)+1):
    if all(S[i:i+len(T)+1][j]==T[j] or S[i:i+len(T)+1][j]=='?' for j in range(len(T))):
        L.append(''.join((S[0:i]+T+S[i+len(T):])).replace('?','a'))
if L==[]:
    print('UNRESTORABLE')
    exit()
else:
    print(sorted(L)[0])

Submission status: Accepted

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

Submission status: Accepted

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

flg = 0
y = s[::-1]
z = t[::-1]
result = []
for j,x in enumerate(range(0,len(y))):
    result = []
    for i,k in enumerate(y[x:x+len(t)]):
        if (k == z[i])|(k=="?"):
            result.append(True)
    if all(result)&(len(result)==len(t)):
        flg = 1
        break
if flg == 1:
    print((s[:len(s)-j-len(t)]+t+s[len(s)-j:]).replace("?","a"))
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
from sys import exit, stdin
S = stdin.readline().rstrip()
T = stdin.readline().rstrip()
LOS, LOT = len(S), len(T)
for i in range(LOS)[::-1]:
    p = S[i:i+LOT]
    LOP = len(p)
    if LOP != LOT:
        continue

    ok = True
    for j in range(LOP):
        if p[j] == '?':
            continue
        if p[j] != T[j]:
            ok = False

    if ok:
        print(S[:i].replace('?', 'a')+T+S[i+LOT:].replace('?', 'a'))
        exit()
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
s_sub= input()
t = input()
ans = []
for i in range(len(s_sub) - len(t) + 1):
    for j, c in enumerate(t):
        if s_sub[i + j] != c and s_sub[i + j] != '?':
            break
    else:
        s = s_sub[:i] + t + s_sub[i + len(t):]
        sample = ''
        for c in s:
            if c == '?':
                sample += 'a'
            else:
                sample += c
        ans.append(sample)
if len(ans) == 0:
    print('UNRESTORABLE')
else:
    print(min(ans))

Submission status: Accepted

Solution code:
S = input()
T = input()
s = len(S)
t = len(T)

if t > s:
	print("UNRESTORABLE")
else:
	ans = []
	for i in range(s - t + 1):
		ju = "YES"
		for j in range(t):
			if S[i + j] != "?" and S[i + j] != T[j]:
				ju = "NO"
				break
		if ju == "YES":
			x = S[:i] + T + S[i + t:]
			ans.append(x.replace("?", "a"))
	if ans == []:
		print("UNRESTORABLE")
	else:
		ans = sorted(ans)
		print(ans[0])

Submission status: Accepted

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

def main():
  s=S()
  t=S()

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

    if f:
      # 後ろから合致する場所は置き換え
      # 残りの '?' 部は 'a' に置き換え
      print(str(s[:i]+t+s[i+len(t):]).replace('?','a'))
      exit()

  print('UNRESTORABLE')

main()
# print(main())

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc076/tasks/abc076_c
import re
def solve(s,t):
    sc = s.replace("?",".")
    if lt > ls:
        return "UNRESTORABLE"
    ans = []
    s = s.replace("?","a")    
    for i in range(ls-lt+1):
        if re.match(sc[i:i+lt], t) is None:
            continue
        ans.append(s[:i]+ t + s[i+lt:])
    if not ans:
        return "UNRESTORABLE"
    return min(ans) 

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

print(solve(S,T))

Submission status: Accepted

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

is_ok = False
li = []
ans = '{'
for i in range(len(S)-len(T)+1):
    flag = True
    for ind,j in enumerate(T):
        if(S[i+ind]=='?' or S[i+ind]==j):
            pass
        else:
            flag = False
    if(flag):
        is_ok=True
        li.append(i)

if(is_ok):
    for i in li:
        s = S[:i]+T+S[i+len(T):]
        ans = min(ans,s.replace('?','a'))

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

Submission status: Accepted

Solution code:
# https://abc076.contest.atcoder.jp/tasks/abc076_c
#

S = input()
T = input()

candidates = []
for i in range(len(S) - len(T) + 1):
    yn = all(S[i + k] == "?" or S[i + k] == T[k] for k in range(len(T)))
    if yn:
        s = S[:i] + T + S[i + len(T) :]
        candidates.append(s)

if candidates:
    candidates = ["".join("a" if c == "?" else c for c in s) for s in candidates]
    print(min(candidates))
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
S, T = input(), input()
if len(T) > len(S):
    print('UNRESTORABLE')
    exit()

able_list = []

for i in range(len(S) - len(T) + 1):
    S_part = S[i:len(T) + i]
    for j in range(len(T)):
        if S_part[j] == T[j] or S_part[j] == '?':
            if j == len(T) - 1:
                able_list.append(S[0:i] + T + S[len(T) + i:])
            continue
        else:
            break

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

for i in range(len(able_list)):
    able_list[i] = able_list[i].replace('?', 'a')

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

Submission status: Accepted

Solution code:
S = input()
T = input()
s = len(S)
t = len(T)

def hantei(a):
    for i in range(t):
        if S[a + i] != "?" and S[a + i] != T[i]:
            return(False)
    return(True)

def solve():
    p = s - t
    while p >= 0:
        if hantei(p):
            ans = ""
            for i in range(s):
                if i >= p and i < p + t:
                    ans += T[i - p]
                else:
                    if S[i] == "?":
                        ans += "a"
                    else:
                        ans += S[i]
            return(ans)
        else:
            p -= 1
    return("UNRESTORABLE")
print(solve())

Submission status: Accepted

Solution code:
# /usr/bin/python
# -*- coding: utf-8 -*-
import math
import sys


def main():
  Sn = list(str(input()))
  Tn = list(str(input()))
  ls = len(Sn)
  lt = len(Tn)

  if ls < lt:
    return 'UNRESTORABLE'

  ret = []
  for i in range(ls-lt+1):
    chk = True
    for j in range(lt):
      if Sn[i+j]!=Tn[j] and Sn[i+j]!='?':
        chk = False
    if chk:
      ret.append(''.join(Sn[:i]+Tn+Sn[i+lt:]).replace('?','a'))
  if len(ret)==0:
    return 'UNRESTORABLE'
  else:
    return min(ret)


if __name__ == "__main__":
  print(main())

Submission status: Accepted

Solution code:
# 2019/05/13
# AtCoder Beginner Contest 076 - C

# Input
s = input()
t = input()
aidx = -1

# Search t
for i in range(len(s)-1, len(t)-2, -1):
    if s[i] == "?" or s[i] == t[len(t)-1]:
        aflg = True
        for j in range(len(t)-2, -1, -1):
            if s[i-(len(t)-j)+1] == "?":
                continue
            elif s[i-(len(t)-j)+1] == t[j]:
                continue
            else:
                aflg = False
                break
        if aflg == True:
            aidx = i
            break

if aidx == -1:
    ans = "UNRESTORABLE"
else:
    # Make answer
    ans = ""
    i = len(s)-1
    while(i >= 0):
        if i != aidx:
            if s[i] == "?":
                ans = "a" + ans
            else:
                ans = s[i] + ans
            i -= 1
        else:
            ans = t + ans
            i -= len(t)
# Output
print(ans)

Submission status: Accepted

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

ans = "UNRESTORABLE"
for i in range(len(ss) - len(t), -1, -1):
  flag = True
  for j in range(i, i + len(t)):
    if ss[j] != t[j-i] and ss[j] != "?":
      flag = False
      break
  if flag:
    ss[i:i+len(t)] = t
    ans = "".join(ss).replace("?", "a")
    break
    
print(ans)

Submission status: Accepted

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

S_all = []
for i in range(len(S2) - len(T) + 1):
    tmp = S2[i: i+len(T)]

    flag = True
    for j in range(len(tmp)):
        if tmp[j] != '?' and tmp[j] != T[j]:
            flag = False
            break

    if flag:
        S_tmp = S2[:i] + T + S2[i+len(T):]
        S = ''

        for k in range(len(S_tmp)):
            if S_tmp[k] == '?':
                S += 'a'
            else:
                S += S_tmp[k]

        S_all.append(S)

if len(S_all) == 0:
    print('UNRESTORABLE')
else:
    S_all.sort()
    print(S_all[0])

Submission status: Accepted

Solution code:
s=[x for x in input()]
t=[x for x in input()]
ls=len(s)
lt=len(t)
ret=False
for i in range(ls-lt,-1,-1):
  flag=True
  for j in range(lt):
    if s[i+j]!='?' and s[i+j]!=t[j]:
      flag=False
  if flag==True:
    for j in range(lt):
      s[i+j]=t[j]
    ret=True
    break
for i in range(ls):
  if s[i]=='?':
    s[i]='a'
if ret==True:
  print(''.join(map(str,s)))
else:
  print('UNRESTORABLE')

Submission status: Accepted

Solution code:

S = list(input())
T = list(input())

def solve():
    global S, T
    if len(S) < len(T):
        print("UNRESTORABLE")
        return

    inds = []
    for i in reversed(range(len(S) - len(T) + 1)):
        s = S[i:i+len(T)]
#         print(i, S[i], S[i:i+len(T)])

        yes = True
        for j in range(len(s)):
#             print(T[j], s[j])
            if s[j] == '?' or s[j] == T[j]:
                continue
            else:
                yes = False
                break
        if yes:
            inds.append(i)
#     print(inds)
    if len(inds) == 0:
        print("UNRESTORABLE")
        return
    
    ans = []
    for ind in inds:
        ss = S[:]
        for i in range(len(S)):
            if ind<= i < ind+len(T):
                ss[i] = T[i-ind]
            elif  ss[i] == '?':
                ss[i] = 'a'
        ans.append(ss)
#     print(ans)
    ans = list(map(lambda x: ''.join(x), ans))
    print(min(ans))
        
solve()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd
readInt = lambda: int(sys.stdin.readline())
readIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]



def solve(S, T):
    res = []
    for i in range(len(S) - len(T) + 1):
        cc = S[:i] + T + S[i+len(T):]
        q = set([s for s,c in zip(S, cc) if s != c])
        if q == set(['?']) or q == set():
            res.append(cc.replace('?', 'a'))

    res.sort()
    if 0 < len(res):
        return res[0]

    return 'UNRESTORABLE'


def main():
    S = input()
    T = input()
    result = solve(S, T)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Accepted

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

t_pattern = []

for i in range(len(S)+1 - len(T)):
    tmp = ""
    for j in range(i):
        tmp += " "
    tmp += T
    tmp_len = len(tmp)
    for j in range(len(S) - tmp_len):
        tmp += " "
    t_pattern.append(tmp)

candidate = []

for i in t_pattern:
    count = 0
    for j in range(len(S)):
        if i[j] == " ":
            continue
        elif i[j] == S[j] or S[j] == "?":
            count += 1
            if count == len(T):
                candidate.append(i)
            continue
        else:
            break

if not candidate:
    print("UNRESTORABLE")
    exit()

ans = ""
for i in range(len(S)):
    if S[i] == "?" and candidate[-1][i] == " ":
        ans += "a"
    elif S[i] != "?":
        ans += S[i]
    else:
        ans += candidate[-1][i]


print(ans)

Submission status: Accepted

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

S = list(input().strip())
T = list(input().strip())
s = set()

for i in range(len(S) - len(T) + 1):
    p = S[i:i+len(T)]
    f = True
    for j in range(len(T)):
        if p[j] != T[j] and p[j] != "?":
            f = False
        
    if f:
        s.add("".join(S[0:i] + T + S[i+len(T):]))

    if p == ["?"] * len(T):
        s.add("".join(S[0:i] + T + S[i+len(T):]))
        
if len(s) == 0:
    print("UNRESTORABLE")
else:
    l = list(s)
    for i in range(len(s)):
        l[i] = l[i].replace("?", "a")
        
    l.sort()
    print(l[0])

Submission status: Accepted

Solution code:
S,T=[list(input()) for _ in range(2)]
k = -1
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:
		k = i
if k == -1:
	print("UNRESTORABLE")
else:
	for i in range(len(T)):
		S[i+k] = T[i]
	print("".join(S).replace("?", "a"))

Submission status: Accepted

Solution code:
# 問題 https://abc076.contest.atcoder.jp/tasks/abc076_c
S = input()
T = input()
Tlen = len(T)
Slen = len(S)
# Tの入りうる箇所の探索
# Tは入りうる箇所の一番うしろに入れて
# 前の?をすべてaで埋め尽くせばよい

for i in range(Slen-Tlen, -1, -1):
    # print(i)
    for s, t in zip(S[i:i + Tlen], T):
        flg = True
        if s != t and s != '?':
            flg = False
            break
    if flg:
        insertidx = i
        break
else:
    print('UNRESTORABLE')
    # import sys
    exit()

ans = S[:insertidx] + T + S[insertidx + Tlen:]
ans = ans.replace('?', 'a')
print(ans)