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()
ls = len(S)
lt = len(T)
cnt = 0
pos = -1
ans = ''

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

for i in range(ls-lt+1):
  cnt = 0
  for j in range(lt):
    if S[i+j] == T[j] or S[i+j] == '?':
      cnt += 1
  if cnt == lt:
    pos = i

if pos == -1:
  print('UNRESTORABLE')
  exit()

ans = S[:i] + T + S[i+lt:]

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

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
ls = len(S)
lt = len(T)
cnt = 0
pos = None
ans = ''

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

for i in range(ls-lt+1):
  cnt = 0
  for j in range(lt):
    if S[i+j] == T[j] or S[i+j] == '?':
      cnt += 1
  if cnt == lt:
    pos = i

if pos == None:
  print('UNRESTORABLE')
  exit()

ans = S[:i] + T + S[i+lt:]

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

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
ls = len(S)
lt = len(T)
flag = False
pos = None
ans = ''

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

for i in range(ls-lt+1):
  flag = True
  for j in range(lt):
    if S[i+j] != T[j] and S[i+j] != '?':
      flag = False
      break
  if flag:
    pos = i

if pos == None:
  print('UNRESTORABLE')
  exit()

ans = S[:i] + T + S[i+lt:]

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

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
ls = len(S)
lt = len(T)
flag = False
pos = None
ans = []

for i in range(ls-lt+1):
  flag = True
  for j in range(lt):
    if S[i+j] != T[j] and S[i+j] != '?':
      flag = False
      break
  if flag:
    pos = i

if pos == None:
  print('UNRESTORABLE')
  exit()

ans = S[:i] + T + S[i+lt:]

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

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
ls = len(S)
lt = len(T)
flag = False
pos = None
ans = []

for i in range(ls-lt+1):
  flag = True
  for j in range(lt):
    if S[i+j] != T[j] and S[i+j] != '?':
      flag = False
      break
  if flag:
    pos = i

if pos == None:
  print('UNRESTORABLE')
  exit()

for k in S[:i]:
  if k == '?':
    ans.append('a')
  else:
    ans.append(k)
ans.append(T)
print(''.join(ans))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

lst = []
for x in range(len(S) - len_T + 1):
    flg = True
    s = S[x:len_T+x]    
    for idx in range(len_T):
        if s[idx] != '?' and s[idx] != T[idx]:
            flg = False
            break
    if flg:
        tmp = S[:x] + T + S[x + len_T:]
        print(tmp)
        tmp = tmp.replace('?', 'a')
        lst.append(tmp)


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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

for i in range(len(s)-len(t)+1):
  flag=True
  for j in range(len(t)):
    if s[i+j]==t[j] and s[i+j]=="?":
      continue
    else:
      flag=False
  if flag:
    s=s[:i]+t+s[i+len(t):]
    s=s.replace("?","a")
    print(s)
    exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

if len(t)>len(s):
  print("UNRESTORABLE")
  exit()

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
flag=False
for i in range(len(s)):
  if s[i] in t:
    s=s[:i]+t+s[i+len(t):]
    flag=True
    break

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

Submission status: Wrong Answer

Solution code:
def equal_or_wildcard(s: str, t: str)->bool:
    for cs, ct in zip(s, t):
        if cs != '?' and cs != ct:
            return False
    return True


def dubious_document2(S: str, T: str)->str:
    ns, nt = len(S), len(T)
    for i in range(ns - nt + 1):
        if equal_or_wildcard(S[i:i+nt], T):
            return (S[:i] + T + S[i+nt:]).replace('?', 'a')
    return 'UNRESTORABLE'


if __name__ == "__main__":
    S = input()
    T = input()
    ans = dubious_document2(S, T)
    print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
ans=1
table=str.maketrans({'?':'a'})
for i in range(len(s)-len(t),-1,-1):
    x=list(s[i:i+len(t)])
    if set(x)=={'?'}:
        s=s.translate(table)
        ans=2
        break
    else:
        cnt=0
        for j in range(len(t)):
            if x[j]=='?' or x[j]==t[j]:
                cnt+=1
        
        if cnt==len(t):
            ans=2
            s=s.translate(table)
            s=s[:i]+t+s[i+len(t):]
            
            break
        else:
            ans=1

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

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
ans=1
table=str.maketrans({'?':'a'})
for i in range(len(s),len(t),-1):
    x=list(s[i-len(t):i])
    if set(x)=={'?'}:
        s=s.translate(table)
        ans=2
        break
    else:
        cnt=0
        for j in range(len(t)):
            if x[j]=='?' or x[j]==t[j]:
                cnt+=1
        
        if cnt==len(t):
            ans=2
            y=list(t)
            for k in range(len(t)):
                x[k]=y[k]
            s=s[:i-len(t)]+"".join(x)+s[i:]
            s=s.translate(table)
            break
        else:
            ans=1

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

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
ans=1
table=str.maketrans({'?':'a'})
for i in range(len(s),len(t),-1):
    x=list(s[i-len(t):i])
    if set(x)=={'?'}:
        s=s.translate(table)
        ans=2
        break
    else:
        cnt=0
        for j in range(len(t)):
            if x[j]=='?' or x[j]==t[j]:
                cnt+=1
        
        if cnt==len(t):
            ans=2
            y=list(t)
            for k in range(len(t)):
                x[k]=y[k]
            s=s[:i-len(t)]+"".join(x)+s[i:]
            s=s.translate(table)
            break
        else:
            ans=1
            break

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

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
ans=1
table=str.maketrans({'?':'a'})
for i in range(len(s),len(t),-1):
    x=list(s[i-len(t):i])
    if set(x)=={'?'}:
        s=s.translate(table)
        ans=2
        break
    else:
        cnt=0
        for j in range(len(t)):
            if x[j]=='?' or x[j]==t[j]:
                cnt+=1
        
        if cnt==len(t):
            ans=2
            s.replace(s[i-len(t):i],t)
            print(s[i-len(t):i])
            print(s)
            s=s.translate(table)
            break
        else:
            ans=1
            break

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

Submission status: Wrong Answer

Solution code:
import copy
def solve():
    S = list(input())
    T = list(input())
    
    tests = []
    for i in range(len(S)):
        if (is_ok(S, T, i)):
            temp = copy.copy(S)
            for j in range(len(T)):
                temp[i + j] = T[j]
            tests.append(afill(temp))
    if (len(tests) == 0):
        print('UNRESTORABLE\n'); return None
    max_temp = ''.join(tests[0])
    for e in tests:
        max_temp = max(max_temp, ''.join(e))
    print(max_temp + '\n')

def afill(string):
    for i in range(len(string)):
        if (string[i] == '?'):
            string[i] = 'a'
    return string

def is_ok(string, target, idx):
    for i in range(len(target)):
        try:
            if (string[idx + i] != '?' and string[idx + i] != target[i]):
                return False
        except:
            return False
    return True

solve()

Submission status: Wrong Answer

Solution code:
def solve():
    S = list(input())
    T = list(input())
    
    tests = []
    for i in range(len(S)):
        if (is_ok(S, T, i)):
            temp = S
            for j in range(len(T)):
                temp[i + j] = T[j]
            tests.append(afill(temp))
    if (len(tests) == 0):
        print('UNRESTORABLE\n'); return None
    max_temp = ''.join(tests[0])
    for e in tests:
        max_temp = max(max_temp, ''.join(e))
    print(max_temp + '\n')

def afill(string):
    for i in range(len(string)):
        if (string[i] == '?'):
            string[i] = 'a'
    return string

def is_ok(string, target, idx):
    for i in range(len(target)):
        try:
            if (string[idx + i] != '?' and string[idx + i] != target[i]):
                return False
        except:
            return False
    return True

solve()

Submission status: Wrong Answer

Solution code:
import re
 
S = input().replace('?', '.')
T = input()
 
ans = []
 
for i in range(len(S)-len(T), -1, -1):
    print(i)
    if re.match(S[i:i+len(T)], T):
        ans.append((S[:i] + T + S[i+len(T):]).replace('.', 'a'))

print(min(ans) if ans else 'UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import re
 
S = input().replace('?', '.')
T = input()
 
ans = []
 
for i in range(len(S)-len(T), -1, -1):
    print(i)
    if re.match(S[i:i+len(T)], T):
        ans.append((S[:i] + T + S[i+len(T):]).replace('.', 'a'))
print(ans)
print(min(ans) if ans else 'UNRESTORABLE')

Submission status: Wrong Answer

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

t_len = len(T)-1 if len(T)>1 else 0

if t_len!=0 and len(S_) != 1:
    if re.search("\?{%d}"%t_len, S_):
        text=re.sub("\?{%d}"%t_len,T[1:],S_)
        print(text.replace("?","a"))
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
flag = False
for i in range(len(S)):
    k = i
    for j in range(len(T)):
        if k < len(S) and (S[k] == T[j] or S[k] == '?'):
            k += 1
            if j == len(T) - 1:
                flag = True
                st = i
        else:
            break
    if flag:
        break
ret = ""
if flag:
    for i in range(st):
        if S[i] == '?':
            ret += 'a'
        else:
            ret += S[i]
    ret += T
    for i in range(st + len(T), len(S)):
        if S[i] == '?':
            ret += 'a'
        else:
            ret += S[i]
else:
    ret = "UNRESTORABLE"
print(ret)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
flag = False
for i in range(len(S)):
    k = i
    for j in range(len(T)):
        if k < len(S) and (S[k] == T[j] or S[k] == '?'):
            k += 1
        else:
            break
    if k == i + len(T):
        flag = True
        st = i
        break
ret = ""
if flag:
    for i in range(st):
        if S[i] == '?':
            ret += 'a'
        else:
            ret += S[i]
    ret += T
    for i in range(st + len(T), len(S)):
        if S[i] == '?':
            ret += 'a'
        else:
            ret += S[i]
else:
    ret = "UNRESTORABLE"
print(ret)

Submission status: Wrong Answer

Solution code:
#!usr/bin/env python3
from collections import defaultdict
from heapq import heappush, heappop
import sys
import math
import bisect
import itertools
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS(): return sys.stdin.readline().split()
def S(): return list(sys.stdin.readline())
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
mod = 1000000007

#A
"""
r = I()
g = I()
print(2*g-r)
"""

#B
"""
n = I()
k = I()
ans = 1
for i in range(n):
    ans = min(ans * 2, ans + k)
print(ans)
"""

#C
s = S()
t = S()
s = s[:-1]
t = t[:-1]
t = t[::-1]
ans = 0
anspri = ""
ansnum = float("INF")
flg = True
for num, i in enumerate(s[::-1]):
    if t[ans] == i or i == "?":
        ans += 1
        if ans == len(t):
            ansnum = num + 1
            break
    else:
        ans = 0
if ansnum == float("INF"):
    print("UNRESTORABLE")
else:
    t = t[::-1]
    for i in range(len(t)):
        s[i - ansnum] = t[i]
    for i in s:
        if i == "?":
            i = "a"
        anspri += i
    print(anspri)

Submission status: Wrong Answer

Solution code:
SS = list(input())
T = list(input())
nt = len(T)
un = 'UNRESTORABLE'
flag = False
for i in reversed(range(len(SS))):
    if i < nt-1:
        break

    for j in range(nt):
        if SS[i-j] == T[nt-1-j] or SS[i-j] == '?':
            pass
        else:
            break
    for k in range(nt):
        SS[i+1-nt+k] = T[k]
    flag = True
    break
if flag:
    for s in range(len(SS)):
        if SS[s] == '?':
            SS[s] = 'a'
    print(''.join(SS))
else:
    print(un)

Submission status: Wrong Answer

Solution code:
def main():
  s = list(input())
  ls = len(s)
  t = list(input())
  lt = len(t)
  flag = 0
  for i in range(ls-lt):
    if flag == 1:
      break
    for j in range(lt):
#      print(i, j)
      if s[ls-i-j-1] != '?' and s[ls-i-j-1] != t[lt-j-1]:
        break
      if j == lt - 1:
        flag = 1
        x = i
  if flag:
    for j in range(lt):
      s[ls-x-j-1] = t[lt-j-1]
    for k in range(ls):
      if s[k] == '?':
        s[k] = 'a'
    str = ''
    for c in s:
      str += c
    print(str)
  else:
    print('UNRESTORABLE')

main()

Submission status: Wrong Answer

Solution code:
import sys
write = sys.stdout.write

#BM法をやってみーましょ
Sdash = input()
Slen = len(Sdash)
T = input()

#ord('?') = 63
#ord('a') = 97

#ずらし表の生成
Tlen = len(T)
Pat = [Tlen for i in range(26)]
for i in range(Tlen):
    Pat[ord(T[i]) - 97] = Tlen - (i+1)

#末尾から照合
flg = 0 #探索結果
index = Tlen - 1 #照合開始位置
pos = Tlen - 1 #探索の現在地
while index <= Slen-1 and flg == 0:
    if pos == index - Tlen:
        flg = 1
        break
    if ord(Sdash[pos]) == 63 or Sdash[pos] == T[Tlen - (index - pos) - 1]:
        pos -= 1
        continue
    else:
        move = Pat[ord(Sdash[pos]) - 97]
        if pos + move <= index:
            index += 1
            pos = index
        else:
            index = pos + move
            pos = index
if flg == 1:
    #pos+1 - pos+TlenまではTを入れる
    #Sdashで'?'の部分にa, '?'以外の部分にSdashの文字を入れる
    for i in range(pos+1):
        if Sdash[i] == '?':
            write("a")
        else:
            write(Sdash[i])
    write(T)
    for i in range(pos+Tlen+1, Slen):
        if Sdash[i] == '?':
            write("a")
        else:
            write(Sdash[i])
    write("\n")
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

    print(solve(s, t))

def solve(s, t):
    n = len(t)
    for i in range(len(s) - n + 1):
        if match(s[i:i+n], t):
            return s[:i].replace('?', 'a') + t + s[i+n:].replace('?', 'a')
    
    return 'UNRESTORABLE'

def match(x, y):
    for i, j in zip(x, y):
        if i != '?' and i != j:
            return False
    return True

main()

Submission status: Wrong Answer

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

l = []

for i in range(len(s)-len(t) - 1):
    f = False
    for j in range(len(t)):
        if s[i+j] != '?' and s[i+j] != t[j]:
            f = False
            break
    if f:
        a = s[:i] + t + s[:i+len(t)]
        l.append(a.replace('?','a'))
if len(l)>0:
    print(min(l))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

l = []

for i in range(len(s)-len(t) - 1):
    f = False
    for j in range(len(t)):
        if s[i+j] != '?' and s[i+j] != t[j]:
            f = False
            break
    if f:
        a = s[:i] + t + s[i+len(t):]
        l.append(a.replace('?','a'))
if len(l)>0:
    print(min(l))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

for i in range(len(S)):
  for s, t in zip(S[i:], T):
    if(s == t):
      if(len(S[S.index(s):]) == len(T[T.index(t):])):
        S = S[:S.index(s)]+T[T.index(t):]
        print(S.replace("?","a"))
        exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i in range(len(S)):
  for s, t in zip(S[i:], T):
    if(s == t):
      if(len(S[S.index(s):]) == len(T[T.index(t):])):
        S = S[:S.index(s)]+T[T.index(t):]
        print(S.replace("?","a"))
        exit()
print("UNRESTOREABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
ls=len(s)
lt=len(t)
L=[]
y=0
for i in list(reversed(range(ls-lt+1))):
    for j in range(lt):
        L.append((s[i+j]==t[j] or s[i+j]=='?'))
    if all(L):
        s=list(s)
        s[i:i+lt]=list(t)
        s="".join(s)
        s=s.replace('?','a')
        print(s)
        y=1
        break
if y==0:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
X = "UNRESTORABLE"
ans = ""
x = 0
res = []
for inds, s in enumerate(S):
    if s == "?":
        s = "a"
    if (inds + len(T) > len(S)):
        break
    flag = 0
    for indt, t in enumerate(T):
        if S[inds + indt] == t or S[inds+indt] == "?":
            flag += 1
    if flag == len(T):
        res.append(ans+T + S[inds + len(T):len(S)])
    else:
        ans += s
if (len(res) > 0):
    ans = res[0]
    for i in res:
        ans = min(i, ans)
    print(ans)
else:
    print(X)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
T = T[::-1]
S = S[::-1]
X = "UNRESTORABLE"
ans = ""
x = 0
for ind, s in enumerate(S):
    if s == "?":
        s = "a"
    if x > 1:
        x -= 1
        continue
    if (s == "a" or s == T[0]):
        if ind + len(T) >= len(S):
            ans += s
            continue
        flag = 0
        for i in range(len(T)):
            if (S[i] == "?" or S[ind+i] == T[i]):
                flag += 1
        if flag == len(T) and x == 0:
            ans += T
            x = len(T)
        else:
            ans += s
    else:
        ans += s
if x:
    print(ans[::-1])
else:
    print(X)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

ls = len(s)
lt = len(t)
ANS = []

for i in range(ls) :
    for j in range(lt) :
        #print("{}{}{}{}".format(i,s[i],j,t[j]))
        if s[i] == t[j] :
            #print("B")
            co = 0
            for k in range(lt) :
                
                #print("{}{}{}".format(s[i-j+k],t[k],k))
                if 0 <= i-j+k < ls and (s[i-j+k] == t[k] or s[i-j+k] == "?") :
                    #print("C")
                    co += 1
                    #print(co)
            if co == lt :
                #print("A")
                ANS.append((s[:i-j]+t+s[i-j+lt:]).replace("?","a"))
#print(ANS)
ANS.sort()
if len(ANS) > 0 :
    print(ANS[0])
else :
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

def match(s_):
    if len(s_) < len(T):
        return False

    for i in range(len(s_)):
        if s_[i] != T[i] and s_[i] != '?':
            return False
    return True


for i in range(1, len(S)-len(T)+1):
    s_ = S[i:i+len(T)]
    if match(s_):
        S = S[:i] + T + S[i+len(T):]
        S = S.replace('?', 'a')
        print(S)
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
m = len(S)
n = len(T)

for i in range(m-n+1):
    cnt = 0
    for j in range(n):
        if T[j] == S[i+j] or S[i+j] == '?':
            cnt += 1
    if cnt == n:
        S = S[:i] + T + S[i+n:]
        S = S.replace("?", "a")
        print(S)
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
m = len(S)
n = len(T)

for i in range(m-n+1):
    cnt = 0
    for j in range(n):
        if T[j] == S[i+j] or S[i+j] == '?':
            cnt += 1
    if cnt == n:
        S = S[:i] + T + S[i+cnt+1:]
        S = S.replace("?", "a")
        print(S)
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
m = len(S)
n = len(T)

for i in range(m-n+1):
    cnt = 0
    for j in range(n):
        if T[j] == S[i+j] or S[i+j] == '?':
            cnt += 1
    if cnt == n:
        S = S[:i] + T + S[i+cnt:]
        S = S.replace("?", "a")
        print(S)
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
m = len(S)
n = len(T)

for i in range(m-n+1):
    cnt = 0
    for j in range(n):
        if T[j] == S[i+j] or S[i+j] == '?':
            cnt += 1
    if cnt == n:
        S = S[:i] + T
        S = S.replace("?", "a")
        print(S)
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i in range(len(S)):
    if T[0] != S[i]:
        continue
    for j, c in enumerate(T):
        try:
            if c == S[i+j] or S[i+j] == '?':
                continue
            else:
                break
        except IndexError:
            break
    else:
        S = S[:i] + T
        S = S.replace("?", "a")
        print(S)
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i in range(len(S)):
    if T[0] != S[i]:
        continue

    if len(T) > len(S):
        print("UNRESTORABLE")
        break

    for j in range(1, len(T)):
        if T[j] == S[i+j] or S[i+j] == '?':
            continue
        break
    else:
        S = S[:i] + T
        S = S.replace("?", "a")
        print(S)
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i in range(len(S)):
    if T[0] != S[i]:
        continue

    if i == len(S)-1:
        continue

    S_ = S[i+1:i+len(T)]
    if len(set(S_)) == 1 and '?' in S_ and len(S_) == len(T)-1:
        S = S[:i] + T
        S = S.replace("?", "a")
        print(S)
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i in range(len(S)):
    if T[0] != S[i]:
        continue
    j = i+1
    if j >= len(S):
        print("UNRESTORABLE")
        break
    cnt = 0
    while S[j] == '?':
        cnt += 1
        j += 1
        if j >= len(S):
            break
    if cnt == len(T[1:]):
        S = S[:i+1] + T[1:]
        print(S.replace("?", "a"))
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
SS="??p??d??"
T="abc"
can=False
for i in reversed(range(len(SS)-len(T)+1)):
    can1=True
    for j in range(len(T)):
        if SS[i+j]==T[j] or SS[i+j]=="?":
            continue
        can1=False
        break
    if can1:
        can=True
        break
if can:
    S=""
    for j in range(len(SS)):
        if i<=j<i+len(T):
            S+=T[j-i]
        elif SS[j]=="?":
            S+="a"
        else:
            S+=SS[j]
    print(S)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
n=len(s)
m=len(t)
ans=0
for i in range(n-m+1):
    sum=0
    for j in range(m):
        if s[i+j]==t[j] or s[i+j]=='?':
            sum+=1
    if sum==m:
        ans=i
if ans==0:
    print('UNRESTORABLE')
else:
    s=s[:ans]+t+s[ans+m:]
    b=s.replace('?','a')
    print(b)

Submission status: Wrong Answer

Solution code:
#ABC076C
S=input()
T=input()
for s in range(len(S)-len(T)+1)[::-1]:
	for t in range(len(T)):
		print(S[s+t])
		if S[s+t]!='?':
			if S[s+t]!=T[t]:
				break
	else:
		ans=''
		for ss in S[:s]:
			if ss=='?':
				ans+='a'
			else:
				ans+=ss
		ans+=T
		for ss in S[s+len(T):]:
			if ss=='?':
				ans+='a'
			else:
				ans+=ss
		print(ans)
		exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
#ABC076C
S=input()
T=input()
for s in range(len(S)-len(T)+1)[::-1]:
	for t in range(len(T)):
		if S[s+t]!='?':
			if S[s+t]!=T[t]:
				break
	else:
		ans=''
		for ss in S[:s]:
			if ss=='?':
				ans+='a'
			else:
				ans+=ss
		ans+=T
		for ss in S[s+len(T):]:
			ans+=ss
		print(ans)
		exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
sd = input()
t = input()
n = len(sd)
m = len(t)
s = []
for i in range(n - m, -1, -1):
    t_kamo = sd[i:i + m]
    for j in range(m + 1):
        if j == m:
            print((sd[:i] + t + sd[i + len(t):]).replace("?", "a"))
            exit()
        if t_kamo[j] != t[j]:
            break
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
sd = input()
t = input()
n = len(sd)
m = len(t)
s = []
for i in range(n - m + 1):
    for j in range(m):
        if not (sd[i + j] == t[j] or sd[i + j] == "?"):
            break
        if j == m - 1:
            s_hatena = sd[:i] + t + sd[i + m + 1:]
            s.append(s_hatena.replace("?", "a"))
if s:
    print(sorted(s)[0])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

ls = len(s)
lt = len(t)
for i in range(ls - lt + 1):
    ss = s[i:i+lt]
    lss = len(ss)
    cnt = 0
    for j in range(lss):
        if s[i + j] == '?' or t[j] == ss[j]:
            cnt += 1
        else:
            break
    else:
        if cnt == lss:
            ans = ''
            for j in range(i):
                if s[j] == '?':
                    ans += 'a'
                else:
                    ans += s[j]
            ans += t
            for j in range(i + lt, ls):
                if s[j] == '?':
                   ans += 'a'
                else:
                    ans += s[j]
            print(ans)
            exit()
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
n = len(S)
m = len(T)

ans = 'UNRESTORABLE'
for i in range(n - m + 1):
    for j in range(m):
        if S[i + j] != '?' and S[i + j] != T[j]:
            break
    else:
        S2 = S[: i] + T + S[i + m :]
        ans = S2.replace('?', 'a')
        break
        
print(ans)

Submission status: Wrong Answer

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

tmp1 = 0
tmp2 = 0
res = ''
flag = False
while True:
    if S[-tmp1 - 1] == t[-tmp2 - 1]  or S[-tmp1 - 1] == '?':
        res = t[-tmp2 - 1] + res
        tmp1 += 1
        tmp2 += 1
    else:
        tmp1 += 1
        tmp2 = 0
        res = ''
        
        
    if tmp2 == len(t):
        flag = True
        break
        
    if tmp1 == len(S):
        break
      
tmp3 = ''
k = 0
for i in range(len(S)):
    if len(S) - tmp1 <= i < len(S) - tmp1 + tmp2:
        tmp3 += t[k]
        k += 1
    elif S[i] == '?':
        tmp3 += 'a'
    else:
        tmp3 += S[i]
        
res = tmp3 
 
if flag:
    print(res)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

flag = False
for i in range(len(S)-len(T),0,-1):
    count = 0
    for j in range(len(T)):
        #print(T[j],S[i:i+len(T)][j])
        if T[j] == S[i+j] or S[i+j] == '?':
            count += 1
        else:
            break
    
    if count == len(T):
        flag = True
        for j in range(len(T)):
            S[i+j] = T[j]
        break

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

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

tmp1 = 0
tmp2 = 0
res = ''
flag = False
while True:
    if S[-tmp1 - 1] == t[-tmp2 - 1]  or S[-tmp1 - 1] == '?':
        res = t[-tmp2 - 1] + res
        tmp1 += 1
        tmp2 += 1
    else:
        tmp1 += 1
        tmp2 = 0
        res = ''
        
        
    if tmp2 == len(t):
        flag = True
        break
        
    if tmp1 == len(S):
        break
      
tmp3 = ''
for i in range(len(S) - len(t)):
    if S[i] == '?':
        tmp3 += 'a'
    else:
        tmp3 += S[i]
        
res = tmp3 + res
 
if flag:
    print(res)
else:
    print('UNRESTORABLE')