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()
if len(s) < len(t):
  print('UNRESTORABLE')
elif s.count('?') == 0:
  if s.count(t) > 0:
    print(s)
  else:
    print('UNRESTORABLE')  
else:
  work = list(s[::1])
  result = ''
  for i in range(len(t)):
    if t[i] in s:
      x  = s.index(t[i])
    else:
      continue
    flg = True
    if i <= x and (len(t) - i)<= (len(s) -x):
      for j in range(1,i):
        if s[x-j] != '?':
          flg = False
          break
      if flg:
        for k in range(1,len(t)-i):
          if s[x+k] != t[i+k] and s[x+k] !='?':
            flg = False
            break
      if flg:
        counter = 0
        for z in range(x-i,x+len(t)-i):
          work[z] = t[counter]
          counter += 1
        result = ''.join(work)
        result = result.replace('?','a')        
        break
  if result != '':
    print(result)
  else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
def is_replaceable(s, t):
    if len(s) < len(t):
        return 'UNRESTORABLE'

    for i in range(len(s) - len(t) + 1):

        replaceable = True
        for x,y in zip(s[i:], t):
            if x != y and x != '?':
                replaceable = False

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

    return 'UNRESTORABLE'


s, t = input(), input()
print(is_replaceable(s, t))

Submission status: Wrong Answer

Solution code:
def is_replaceable(s, t):
    if len(s) < len(t):
        return 'UNRESTORABLE'

    for i in range(len(s) - len(t) + 1):

        replaceable = True
        for x,y in zip(s[i:i+len(t)], t):
            if x != y and x != '?':
                replaceable = False

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

    return 'UNRESTORABLE'


s, t = input(), input()
print(is_replaceable(s, t))

Submission status: Wrong Answer

Solution code:
s = input()
sd = "".join(reversed(list(s)))
t = input()
td = "".join(reversed(list(t)))
index = sd.find("?" * (len(td) - 1) + td[-1])
if index == -1:
    print("UNRESTORABLE")
    exit()
s = s.replace("?", "a")
print(s[:len(s) - index - len(t)] + t + s[:index - len(s)])

Submission status: Wrong Answer

Solution code:
def check(S, T):
    for i in range(len(S)-len(T)+1):
        found=True
        for j in range(len(T)):
            if S[i+j] != "?" and T[j] != S[i+j]:
                found=False
                break
        if found: 
            return S[:i].replace("?", "a")+T+S[i+len(T):].replace("?","a")

    return None


S=input()
T=input()

ans=check(S, T)
if ans == None:
    print("UNRESTORABLE")
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
def checkOne(S, T, start, Tstart):
  i=0
  while i+start<len(S) and Tstart+i<len(T):
      if S[i+start] != "?" and T[Tstart+i] != S[i+start]:
          return False
      i+=1
  return True

def check(S, T):
  i=0
  ret=-1
  QCount=0
  while i<len(S):
      if S[i] != "?":
          p=T.find(S[i])
          if p >= 0 and p <= QCount and checkOne(S, T, i, p):
              ret=i
          QCount=0
      else:
          QCount+=1
      i+=1
  return ret


S=input()
T=input()

start=check(S, T)
QS="?"*len(T)
start2=S.rfind(QS)
start=max(start, start2)

if -1 == start:
  print("UNRESTORABLE")
else:
  print(S[:start].replace("?", "a")+T+S[start+len(T):].replace("?","a"))

Submission status: Wrong Answer

Solution code:
def checkOne(S, T, start):
  i=0
  while i+start<len(S) and i<len(T):
      if S[i+start] != "?" and T[i] != S[i+start]:
          return False
      i+=1
  return True

def check(S, T):
  i=0
  ret=-1
  while i<len(S):
      if S[i] != "?" and S[i] == T[0]:
          if checkOne(S, T, i):
              ret=i
      i+=1
  return ret
def stisfiedS(S, length):
    prev=S[-1]
    start=len(S)-1
    if prev == "?":
        count=1
    else:
        count=0

    i=len(S)-2

    while i >=0:
        if S[i] == "?":
            if prev=="?":
                count+=1
                if count == length:
                    return i
            else:
                prev="?"
                count=1
        else:
            count=0
            prev=S[i]
        i-=1

    return -1

S=input()
T=input()

start=check(S, T)
start2=stisfiedS(S, len(T))
start=max(start, start2)

if -1 == start:
  print("UNRESTORABLE")
else:
  print(S[:start].replace("?", "a")+T+S[start+len(T):].replace("?","a"))

Submission status: Wrong Answer

Solution code:
def checkOne(S, T, start):
  i=0
  while i+start<len(S) and i<len(T):
      if S[i+start] != "?" and T[i] != S[i+start]:
          return False
      i+=1
  return True

def check(S, T):
  i=0
  while i<len(S):
      if S[i] != "?" and S[i] == T[0]:
          if checkOne(S, T, i):
              return i
      i+=1
  return -1

S=input()
T=input()

start=check(S, T)
if -1 == start:
  print("UNRESTORABLE")
else:
  print(S[:start].replace("?", "a")+T+S[start+len(T):].replace("?","a"))

Submission status: Wrong Answer

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

    f(s, t)

def f(s, t):
    l_t =len(t)
    for i in reversed(range(len(s)-l_t+1)):
        b = s[i:i+l_t]
        c = sum(c1 == c2 or c2 == "?" for c1, c2 in zip(t, b))

        if c == len(t):
            print(s[:i], t, s[i+l_t:])
            ans = s[:i].replace("?", "a") + t + s[i+l_t:].replace("?", "a")
            print(ans)
            return

    print("UNRESTORABLE")


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ns = len(s)
nt = len(t)
ss = []

for i in range(ns-nt+1):
    for j,k in zip(s[i:i+nt],t):
        if j == '?':
           continue
        if j != k:
           break
        else:
            s2 = s[:i] + t + s[i+nt:]
            s3 = s2.replace('?','a')
            ss.append(s3)
        
if len(ss) == 0:
    print('UNRESTORABLE')
else:
    print(list(sorted(ss))[0])

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ns = len(s)
nt = len(t)
ss = []
if ns < nt:
    print('UNRESTORABLE')
else:
    for i in range(ns-nt+1):
        for j,k in zip(s[i:i+nt],t):
            if j == '?':
                continue
            if j != k:
                break
        else:
            s2 = s[:i] + t + s[i+nt:]
            s3 = s2.replace('?','a')
            ss.append(s3)
        
if len(ss) == 0:
    print('UNRESTORABLE')
else:
    print(list(sorted(ss))[0])

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ns = len(s)
nt = len(t)
ss = []
if ns < nt:
    print('UNRESTORABLE')
else:
    for i in range(ns-nt+1):
        for j,k in zip(list(s)[i:i+nt],list(t)):
            if j == k or j == '?':
                continue
            else:
                break
        else:
            s2 = s[:i] + t + s[i+nt:]
            s3 = s2.replace('?','a')
            ss.append(s3)
        
try:
    print(min(ss))
except ValueError:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ns = len(s)
nt = len(t)
ss = []
if ns < nt:
    print('UNRESTORABLE')
else:
    for i in range(ns-nt+1):
        for j,k in zip(list(s)[i:i+nt],list(t)):
            if j == k or j == '?':
                continue
            else:
                break
        else:
            s2 =s.replace(s[i:i+nt],t)
            s3 = s2.replace('?','a')
            ss.append(s3)
        
try:
    print(min(ss))
except ValueError:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
le = len(t)
ma = 0
def equ(a, b):
    for i in range(len(a)):
        if a[i] != b[i] and a[i] != '?':
            return False
    else:
        return True
for i in range(len(s) - len(t)+1):
    if equ(s[i:i+le], t):
        ma = i
if ma == 0:
    print("UNRESTORABLE")
    exit()
ans = []
for i in range(ma):
    if s[i] == '?':
        ans.append('a')
    else:
        ans.append(s[i])
ans += t
ans += s[ma+le:]
print("".join(ans))

Submission status: Wrong Answer

Solution code:
S = list(input())
T = input()
flag = True
tmp_ind = len(T)-1

for i in range(len(S)-1, -1, -1):
    if(S[i]=='?' or S[i]==T[tmp_ind]) and flag:
        if tmp_ind==0:
            s_ind = i
            flag = False
            break
        tmp_ind -= 1
    else:
        tmp_ind = len(T)-1

if flag:
    print('UNRESTORABLE')
else:
    j = 0
    for i in range(s_ind, s_ind+len(T)):
        S[i] = T[j]
        j += 1
    for i in range(len(S)):
        if S[i]=='?':
            S[i] = 'a'
    print("".join(S))

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
flag = True
tmp_ind = len(T)-1
new_S = [S[i] for i in range(len(S))]

for i in range(len(S)-1, -1, -1):
    if (S[i]=='?' or S[i]==T[tmp_ind]) and flag:
        if tmp_ind==0:
            s_ind = i
            flag = False
            break
        tmp_ind -= 1
    else:
        tmp_ind = len(T)-1
if flag:
    print('UNRESTORABLE')
else:
    j = 0
    for i in range(s_ind, s_ind+len(T)):
        new_S[i] = T[j]
        j += 1
    for i in range(len(S)):
        if new_S[i]=='?':
            new_S[i] = 'a'
    print("".join(new_S))

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
flag = True
tmp_ind = len(T)-1
s_ind = [0, 0]
new_S = [S[i] for i in range(len(S))]

for i in range(len(S)-1, -1, -1):
    if (S[i]=='?' or S[i]==T[tmp_ind]) and flag:
        if tmp_ind==len(T)-1:
            s_ind[0] = i
        elif tmp_ind==0:
            s_ind[1] = i
            flag = False
            break
        tmp_ind -= 1
    else:
        tmp_ind = len(T)-1
if flag:
    print('UNRESTORABLE')
else:
    j = 0
    for i in range(s_ind[1], s_ind[0]+1):
        new_S[i] = T[j]
        j += 1
    for i in range(len(S)):
        if new_S[i]=='?':
            new_S[i] = 'a'
    print("".join(new_S))

Submission status: Wrong Answer

Solution code:
def CountE(x):
    cnt = 0
    ind = 0
    temp = 1
    for i in range(len(x)-1, 0, -1):
        if x[i] == "?" and x[i] == x[i-1]:
            temp += 1
            cnt = temp
            ind = i-1
        else: 
            temp = 1
    return cnt, ind

S = input()
T = input()
s = [i for i in S]
t = [i for i in T]

flg = 0
cnt = 0
ind = 0
if t[0] in s:
    if len(t) <= len(s)-s.index(t[0]):
        s[s.index(t[0]):s.index(t[0])+len(t)] = t
    else:
        flg = 1
else:
    if len(t) > s.count("?") or s.count("?") < 2:
        flg = 1
    else:
        cnt, ind = CountE(s)
        if cnt >= len(t):
            s[ind:ind+len(t)] = t
        else:
            flg = 1

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

Submission status: Wrong Answer

Solution code:
def CountE(x):
    cnt = 0
    ind = 0
    temp = 1
    for i in range(len(x)-1, 0, -1):
        if x[i] == "?" and x[i] == x[i-1]:
            temp += 1
            cnt = temp
            ind = i-1
        else: 
            temp = 1
    return cnt, ind

Sp = input()
T = input()

s = [i for i in Sp]
t = [i for i in T]

flg = 0
cnt = 0
ind = 0
if t[0] in s:
    if len(t) <= len(s)-s.index(t[0]):
        s[s.index(t[0]):s.index(t[0])+len(t)-1] = t
    else:
        flg = 1
else:
    if len(t) > s.count("?") or s.count("?") < 2:
        flg = 1
    else:
        cnt, ind = CountE(s)
        if cnt >= len(t):
            s[ind:ind+len(t)-1] = t
        else:
            flg = 1

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

Submission status: Wrong Answer

Solution code:
a = list(input())
b = list(input())

arr = []
length = len(b)

for i in range(len(a) - len(b) + 1):
  formable = True
  for j, bs in enumerate(b):
    if bs == a[i+j] or a[i+j] == "?":
      continue
    formable = False
  if formable == False:
    continue
  for k, bs in enumerate(b):
    a[i+k] = bs
  for l, sa in enumerate(a):
    if sa == "?":
      a[l] = "a"
  arr.append("".join(a))
nn = sorted(arr)
ans = "UNRESTORABLE" if len(arr) == 0 else nn[0]

print(ans)

Submission status: Wrong Answer

Solution code:
a = list(input())
b = list(input())

arr = []
length = len(b)

for i in range(len(a) - len(b) + 1):
  formable = True
  for j, bs in enumerate(b):
    if bs == a[i+j] or a[i+j] == "?":
      continue
    formable = False
  if formable == False:
    continue
  for k, bs in enumerate(b):
    a[i+k] = bs
  for l, sa in enumerate(a):
    if sa == "?":
      a[l] = "a"
  arr.append("".join(a))
  
ans = "UNRESTORABLE" if len(arr) == 0 else arr[0]

print(ans)

Submission status: Wrong Answer

Solution code:

import re

def foo(s, t):
    pat = "".join(map(lambda x: "({0}|[?])".format(x), list(t)))
    m = re.search(pat, s)
    if m is None:
        return "UNRESTORABLE"
    start, end = m.span()
    r = s[:start] + t + s[end:]
    return r.replace("?", "a")


if __name__ =="__main__":
    s = input()
    t = input()
    print(foo(s, t))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

Sd = input()
T = input()

def match(L):
    for l, t in zip(L, T):
        if l == "?":
            continue
        else:
            if l != t:
                return False
            else:
                pass
    return True

res = []

for i in range(len(Sd)-len(T)+1)[::-1]:
    print(Sd[i:i+len(T)])
    if match(Sd[i:i+len(T)]):
        print(i)
        res.append((Sd[:i] + T + Sd[i+len(T):]).replace("?", "a"))

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

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
def inpl(): return list(map(int, input().split()))

Sd = input()
T = input()

def match(L):
    for l, t in zip(L, T):
        if l == "?":
            continue
        else:
            if l != t:
                return False
            else:
                pass
    return True

res = []

for i in range(len(Sd)-len(T)+1)[::-1]:
    if match(Sd[i:i+len(T)]):
        res.append((Sd[:i] + T + Sd[i+len(T)+1:]).replace("?", "a"))

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

Submission status: Wrong Answer

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

import sys

S=input()
T=input()

# S'の開始位置
for p in range(len(S)):

    def findStr(k):
        # 文字の照合
        for q in range(len(T)):
            # print("Finding", p, q)
            try:
                # 文字が等しくなく かつ ?でない
                if(S[k+q]!=T[q] and S[k+q]!="?"):
                    # print(S[k+q], "!=", T[q])
                    return False
            except IndexError:
                return False

        # 一致した場合
        # print("p=",p,"q=",q)
        return p
    
    result=findStr(p)
    if(result!=False):
        # 一致した文字列を切り出し
        text=S[p:p+len(T)]
        # 置き換え
        newTxt=S.replace(text, T)
        # 残った?をaに置き換え
        fixTxt=newTxt.replace("?", "a")
        print(fixTxt)
        sys.exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = raw_input()
T = raw_input()
m = len(S)
n = len(T)
ans = "UNRESTORABLE"
for i in range(m-n+1):
    ok = True
    for j in range(n):
        if not ((S[i+j] == T[j]) or (S[i+j] == '?')):
            ok = False
            break
    if ok:
        s = ""
        for j in range(m):
            if i <= j < i+n:
                s += T[j-i]
            elif S[j] == '?':
                s += 'a'
            else:
                s += S[j]
        ans = min(ans, s)
print ans

Submission status: Wrong Answer

Solution code:
S = raw_input()
T = raw_input()
m = len(S)
n = len(T)
ans = "UNRESTORABLE"
for i in range(m-n+1):
    ok = True
    for j in range(n):
        if not ((S[i+j] == T[j]) or (S[i+j] == '?')):
            ok = False
            break
    if ok:
        s = ""
        for j in range(m):
            if i <= j < i+n:
                s += T[j-i]
            elif S[j] == '?':
                s += 'a'
            else:
                s += S[j]
        ans = s
        break
print ans

Submission status: Wrong Answer

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

def check(s, t):
    for i in range(len(s)):
        for j in range(min(len(t), len(s[i:]))):
            if s[i:][j] != '?' and s[i:][j] != t[j]:
                break
            if j == len(t)-1:
                return True, i
    return False, 0


c, i = check(s, t)
ans = ''
if c:
    ans = s[:i] + t + s[(i+len(t)):]
    ans = ans.replace('?', 'a')
    print(ans)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

def check(A, B):
    for a, b in zip(A, B):
        if a != '?' and a != b:
            return False
    return True

for i in range(len(Sd) - len(T) + 1)[::-1]:
    if check(Sd[i:i + len(T)], T):
        print((Sd[:i] + T + Sd[i + len(T):]).replace('?', 'a'))
        break
else:
    print('UNRESTORSBLE')

Submission status: Wrong Answer

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

def check(A, B):
    for a, b in zip(A, B):
        if a != '?' and a != b:
            return False
    return True

for i in range(len(Sd) - len(T) + 1):
    if check(Sd[i:i + len(T)], T):
        print((Sd[:i] + T + Sd[i + len(T):]).replace('?', 'a'))
        break
else:
    print('UNRESTORSBLE')

Submission status: Wrong Answer

Solution code:
import re

def solve(s, t):
    s = s.replace('?', '.')
    ls, lt = len(s), len(t)
    if ls < lt:
        return 'UNRESTORSBLE'
    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()
T = input()

print(solve(S, T))

Submission status: Wrong Answer

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


def f(begin, txt, query):
    for i in range(len(query)):
        if (txt[begin+i] == '?') or (txt[begin+i] == query[i]):
            pass
        else:
            return False
    return True


def g(begin, txt, query):
    tmp = list(txt)
    for i in range(len(tmp)):
        if tmp[i] == '?':
            tmp[i] = 'a'
    for i in range(len(query)):
        tmp[begin+i] = query[i]
    return ''.join(tmp)


flag = False

for i in range(len(S) - len(T)):
    if f(len(S) - i - len(T), S, T):
        S = g(len(S) - i - len(T), S, T)
        flag = True
        break

if flag is False:
    print('UNRESTORABLE')
else:
    print(S)

Submission status: Wrong Answer

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


def f(begin, txt, query):
    for i in range(len(query)):
        if (txt[begin+i] == '?') or (txt[begin+i] == query[i]):
            pass
        else:
            return False
    return True


def g(begin, txt, query):
    tmp = list(txt)
    for i in range(len(tmp)):
        if tmp[i] == '?':
            tmp[i] = 'a'
    for i in range(len(query)):
        tmp[begin+i] = query[i]
    return ''.join(tmp)


flag = False

for i in range(len(S) - len(T)):
    if f(len(S) - i - len(T), S, T):
        S = g(len(S) - i - len(T), S, T)
        flag = True
        break

if flag is False:
    print('UNRESTORED')
else:
    print(S)

Submission status: Wrong Answer

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

Slen=len(S)
Tlen=len(T)
flag=0
def check(S,T,i):
	k=0
	Slen=len(S)
	Tlen=len(T)
	for _ in range(Tlen):
		if S[_+i]==T[_] or S[_+i]=="?":
			k+=1
	if k==Tlen:
		return True
	else:
		return False
	
for j in range(Slen-Tlen,0,-1):
	if check(S,T,j):
		S[j:j+Tlen]=T[::]
		for _ in range(Slen):
			if S[_] == "?":
				S[_]="a"
		ans="".join(S)
		flag=1
		print(ans)
	break

if flag !=1:
	print("UNRESTORABLE")

Submission status: Wrong Answer

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

Slen=len(S)
Tlen=len(T)
flag=0
def check(S,T,i):
	k=0
	Slen=len(S)
	Tlen=len(T)
	for _ in range(Tlen):
		if S[_+i]==T[_] or S[_+i]=="?":
			k+=1
	if k==Tlen:
		return True
	else:
		return False
	
for j in range(Slen-Tlen,-1,-1):
	if check(S,T,j):
		S[j:j+Tlen]=T[::]
		for _ in range(Slen):
			if S[_] == "?":
				S[_]="a"
		ans="".join(S)
		flag=1
		print(ans)
	break

if flag !=1:
	print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
hint = input()
t = input()
s = []
for x in hint:
    s.append(x)
found = False

for i in range(len(t)):
    if hint.rfind(t[i]) > -1 and len(t) - i <= len(hint) - hint.rfind(t[i]):
        for j in range(len(t)):
            if hint[hint.rfind(t[i]) - i + j] == t[j] or "?" == hint[hint.rfind(t[i]) - i + j]:
                found = True
            else:

                found = False

        if found:
            # initialize s and counter
            s = []
            for x in hint:
                s.append(x)
            c = 0

            for k in range(i):
                s[hint.rfind(t[i]) - i + k] = t[k]

            for k in range(i, len(t)):
                s[hint.rfind(t[i]) + c] = t[k]
                c += 1

ans = ''.join(s)

if ans != hint or found:
    print(str.replace(ans, "?", "a"))

elif hint.rfind('?'*len(t)) > -1:
    for x in t:
        s[hint.rfind('?' * len(t)) + t.index(x)] = x
    ans = ''.join(s)
    print(str.replace(ans, "?", "a"))

else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
lisS = list(input())
lisT = list(input())
for i in range(len(lisS)-len(lisT)+1):
  for num,item in enumerate(lisT):
    if item != lisS[i+num] and lisS[i+num] != "?":
      break
  else:
    for j in range(len(lisT)):
      lisS[i+j] = lisT[j]
    while "?" in lisS:
      lisS[lisS.index("?")] = "a"
    print ("".join(lisS))
    break
else:
  print ("UNRESTORABLE")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys
s = list(raw_input()[::-1])
t = list(raw_input()[::-1])
for i in xrange(0, len(s)-len(t)):
    for j in xrange(len(t)):
        if ("?" == s[i+j]) or (t[j] == s[i+j]):
            continue
        break
    else:
        for j in xrange(len(t)):
            s[i+j] = t[j]
        break
else:
    print "UNRESTORABLE"
    sys.exit()
print "".join([(lambda x: "a" if x == "?" else x)(s[i]) for i in xrange(len(s))])[::-1]

Submission status: Wrong Answer

Solution code:
hint = input()
t = input()
s = []
for x in hint:
    s.append(x)
found = False


def found_all(index):
    global s

    for i in range(len(t)):
        if (t[i] != hint[index + i]) and (hint[index + i] != '?'):
            return False

    s = []
    for x in hint:
        s.append(x)

    for j in range(len(t)):
        s[index + j] = t[j]

    return True


# finding a substring in hint
for j in t:
    if found_all(hint.find(j)):
        found = True

if found:
    ans = ''.join(s)
    print(ans.replace("?", "a"))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
hint = input()
t = input()
s = []
for x in hint:
    s.append(x)
found = False


def found_all(index):
    global s

    for i in range(len(t)):
        if (t[i] != hint[index + i]) and (hint[index + i] != '?'):
            return False

    for j in range(len(t)):
        s[index + j] = t[j]

    return True


# finding a substring in hint
for j in t:
    if found_all(hint.find(j)):
        found = True

if found:
    ans = ''.join(s)
    print(ans.replace("?", "a"))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

judge = False

for i in range(len(val)-len(code)+1):
    slice_val = val[i:i+len(code)]
    res = val[i+len(code):]
    for j in range(0, len(code)):
        if slice_val[j] == code[j] or slice_val[j] == "?":
            slice_val[j] = code[j]
        else:
            break
    if slice_val == code:
        slice_val += res
        judge = True
        break
print("".join(reversed(slice_val)).replace("?", "a") if judge else "UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
T = input()
p = 0
for i in range(len(s)-len(T)+1,0,-1):
    for j in range(len(T)):
        if T[j]!=s[i-1+j] and "?"!= s[i-1+j] :
            p = 1
            break
    if p == 0:
        s=s[:i-1]+T+s[i+len(T)-1:]
        s = s.replace('?', 'a')
        print(s)
        break
    elif p == 1:
        print("UNRESTORABLE")
        break

Submission status: Wrong Answer

Solution code:
s = input()
T=input()
p = 0
for i in range(len(s)-len(T)+1,0,-1):
  for j in range(len(T)):
    if T[j]!=s[i-1+j] and "?"!= s[i-1+j] :
      p = 1
      break
  else:
    s=s[:i-1]+T+s[i+len(T)-1:]
    s = s.replace('?', 'a')
    print(s)
if p == 1:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys
s = input()
T=input()
p = 0
for i in range(len(s)-len(T)+1,0,-1):
  for j in range(len(T)):
    if T[j]!=s[i-1+j] and "?"!= s[i-1+j] :
      p = 1
      break
  else:
    s=s[:i-1]+T+s[i+len(T)-1:]
    s = s.replace('?', 'a')
    print(s)
    sys.exit()
if p == 1:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys
s = input()
T=input()
p = 0
for i in range(len(s)-len(T)+1,0,-1):
  for j in range(len(T)):
    if T[j]!=s[i-1+j] and "?"!= s[i-1+j] :
      break
      p = 1
  else:
    s=s[:i-1]+T+s[i+len(T)-1:]
    s = s.replace('?', 'a')
    print(s)
    sys.exit()
if p == 1:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
ok=False
ans=[]

for i in range(max(len(S)-len(T) + 1,0)):
	tmpS = list(S)
	for j in range(len(T)):
		if i + j < len(S) and tmpS[i+j] == "?":
			tmpS[i+j] = T[j]

	if "".join(tmpS[i:i+len(T)]) == T:
		ans = tmpS
		ok = True
		break

ans = "".join(ans)
if ok == False:
	print("UNRESTORABLE")
else:
	print(ans.replace("?","a"))

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
flg = 0
ans = []

for i in range(len(S)-len(T), 0, -1):
    tmpS = list(S)
    for j in range(len(T)):
        if tmpS[i+j] == "?":
            tmpS[i+j] = T[j]
    
    if "".join(tmpS[i:i+len(T)]) == T:
        ans = tmpS
        flg = 1
        break

ans = "".join(ans)
if flg == 0:
    print("UNRESTORABLE")
else:
    print(ans.replace("?", "a"))

Submission status: Wrong Answer

Solution code:

def solve():
	S = input()
	T = input()

	cnt = 0
	for start in range(len(S) - len(T)+1):
		for i,t in enumerate(T):
			if S[start+i] == t or S[start+i] == '?':
				if i == len(T)-1:
					ans = S[:start].replace('?', 'a') + T + S[start+i+1:].replace('?', 'a')
					print(ans)
					return True
			else:
				break
if not solve():
	print('UNRESTORABLE')

Submission status: Wrong Answer

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


# 後ろから見ていって、はまったらa埋めする
def check_embed(s, t, ind):
    use_s = s[ind:ind+len(t)]
    for i in range(len(t)):
        if use_s[i] != "?" and use_s[i] != t[i]:
            return False
    return True

def check_a(s, t, ind):
    use_s = s[ind:ind+len(t)]
    for i in range(len(t)):
        if not ((use_s[i] == "?" and t[i] == "a") or use_s[i] == t[i]):
            return False
    return True

flag = 0
for i in range(len(s) - len(t) + 1):
    if check_a(s, t, i):
        print(i)
        flag = 1
        s = (s[:i] + t + s[i + len(t):]).replace("?", "a")
        break
if flag:
    print(s)
else:
    flag = 0
    for i in range(len(s) - len(t) + 1):
        if check_embed(s, t, len(s) - len(t) - i):
            flag = 1
            s = (s[:len(s) - len(t) - i] + t + s[len(s) - i:]).replace("?", "a")
            break
    if flag:
        print(s)
    else:
        print("UNRESTORABLE")

Submission status: Wrong Answer

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


# 後ろから見ていって、はまったらa埋めする
def check_embed(s, t, ind):
    use_s = s[ind:ind+len(t)]
    for i in range(len(t)):
        if use_s[i] != "?" and use_s[i] != t[i]:
            return False
    return True

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

Submission status: Wrong Answer

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

indices = []
for i in range(len(sPrime) - len(t) + 1):
	if sPrime[i] != t[0] and sPrime[i] != "?":
		continue
	possible = True
	for j in range(i+1, i+len(t)):
		diff = i - j
		tLetter = t[diff]
		if sPrime[j] != "?" and sPrime[j] != tLetter:
			possible = False
			break
	if possible:
		indices.append(i)

possibilities = []
for i in indices:
	new = ""
	for l in range(len(sPrime)):
		letter = sPrime[l]
		if l < i or l >= i + len(t):
			new = new + letter
		else:
			new = new + t[l - i]
	possibilities.append(new)

for i in range(len(possibilities)):
	possibilities[i] = possibilities[i].replace("?", "a")
possibilities.sort()
if len(possibilities) == 0:
	print("UNRESTORABLE")
else:
	print(possibilities[0])

Submission status: Wrong Answer

Solution code:
def matches(pattern, text):
    for i in range(len(text)-len(pattern), -1, -1):
        good = True
        for j in range(len(pattern)):
            if not text[i+j] in ['?', pattern[j]]:
                good = False
        if good:
            return i
    return False

Sprime = input()
T = input()

match = matches(T, Sprime)
if match:
    print((Sprime[:match]+T+Sprime[match+len(T):]).replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

S_r = Sd[::-1]
T_r = T[::-1]

lenS = len(Sd)
lenT = len(T)

Flag2 = True

if lenS < lenT:
    pass
else:
    for i in range(lenS - lenT + 1):
        for j in range(lenT):
            Flag1 = True
            if S_r[i+j] == "?" or T_r[j]:
                pass
            else:
                Flag1 =False
                break
        if Flag1:
            Flag2 = False
            S_r = S_r.replace(S_r[i:i+lenT],T_r,1)
            S_r = S_r.replace("?","a")
            ans = S_r[::-1]
            break

if Flag2:
    ans = "UNRESTORABLE"
print(ans)