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:
import sys
from copy import deepcopy
def main():
    s = list(map(str, input()))
    t = list(map(str, input()))
    for i1 in range(len(s)):
        if s[i1] == t[0] or s[i1] == '?':
            s_tmp = deepcopy(s)
            s_tmp[i1] = t[0]
            for i2 in range(1, len(t)):
                if len(s) - i1 < len(t):
                    break
                elif s[i1+i2] == t[i2] or s[i1+i2] == '?':
                    s_tmp[i1+i2] = t[i2]
                else:
                    break
            else:
                s_tmp = ['a' if c == '?' else c for c in s_tmp]
                print("".join(s_tmp))
                sys.exit()
    print('UNRESTORABLE')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

if n >= m:
    for i in range(n - m + 1):
        bubun = s[i:i + m]
        flag = True
        for j in range(m):
            x = bubun[j]
            y = t[j]
            if x == y:
                continue
            elif x == '?':
                continue
            else:
                flag = False
                break

        if flag:
            ans = s[:i] + t + s[i + m:]
            break

    print(ans.replace('?', 'a')) if flag else print('UNRESTORABLE')
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

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

if n >= m:
    for i in range(n - m + 1):
        bubun = s[i:i + m]
        flag = True
        for j in range(m):
            x = bubun[j]
            y = t[j]
            if x == y:
                pass
            elif x == '?':
                pass
            else:
                flag = False
                break

        if flag:
            ans = s[:i].replace('?', 'a') + t + s[i + m:].replace('?', 'a')
            break

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

Submission status: Wrong Answer

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

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

if n > m:
    for i in range(n - m + 1):
        bubun = s[i:i + m]
        flag = True
        for j in range(m):
            x = bubun[j]
            y = t[j]
            if x == y:
                pass
            elif x == '?':
                pass
            else:
                flag = False

        if flag:
            ans = s[:i].replace('?', 'a') + t + s[i + m:].replace('?', 'a')
            break

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

Submission status: Wrong Answer

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

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

if n >= m:
    for i in range(n - m + 1):
        bubun = s[i:i + m]
        flag = True
        for j in range(m):
            x = bubun[j]
            y = t[j]
            if x == y:
                pass
            elif x == '?':
                pass
            else:
                flag = False

        if flag:
            ans = s[:i].replace('?', 'a') + t + s[i + m:].replace('?', 'a')
            break

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

Submission status: Wrong Answer

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

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

if n >= m:
    for i in range(n - m + 1):
        bubun = s[i:i + m]
        flag = True
        for j in range(m):
            x = bubun[j]
            y = t[j]
            if x == y:
                pass
            elif x == '?':
                pass
            else:
                flag = False

        if flag:
            ans = s[:i].replace('?', 'a') + t + s[i + m:].replace('?', 'a')
            break

    print(ans) if flag else print('UNRESTORABLE')
else:
    print(t) if n == m else print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = "???"
T = "abc"

S_length = len(S)
T_length = len(T)

if S_length < T_length:
    print("UNRESTORABLE")
    
elif S_length == T_length:
    for i in range(T_length):
        if S[i] != "?" and S[i] != T[j]:
            break
    else:
        print(T)
    
else:
    flag = 0
    for i in range(S_length - T_length):
        for j in range(T_length):
            if S[S_length - T_length - i + j] != "?" and S[S_length - T_length - i + j] != T[j]:
                break
        else:
            flag = 1
            S = S[:S_length - T_length - i] + T + S[S_length - i:]
            break
            
    if flag == 1:
        ans = S.replace("?", "a")
        print(ans)
        
    elif flag == 0:
        print("UNRESTORABLE")

Submission status: Wrong Answer

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

S_length = len(S)
T_length = len(T)

if S_length < T_length:
    print("UNRESTORABLE")
    
else:
    flag = 0
    for i in range(S_length - T_length):
        for j in range(T_length):
            if S[S_length - T_length - i + j] != "?" and S[S_length - T_length - i + j] != T[j]:
                break
        else:
            flag = 1
            S = S[:S_length - T_length - i] + T + S[S_length - i:]
            break
            
    if flag == 1:
        ans = S.replace("?", "a")
        print(ans)
        
    elif flag == 0:
        print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
ls=len(S)
lt=len(T)

ans='UNRESTORABLE'

if ls<lt:
    print(ans)
    exit()
for i in range(ls-lt,-1,-1):
    c=0
    for j in range(lt):
        if T[j]==S[i+j] or S[i+j]=='?':
            continue
        else:
            c=1
            break
    if c==0:
        ans=S.replace('?','a')
        ans=ans[:i] + T + ans[i+lt+1:]
        break
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
ls=len(S)
lt=len(T)

ans='UNRESTORABLE'

if ls<lt:
    print(ans)
    exit()
for i in range(ls-lt,0,-1):
    c=0
    for j in range(lt):
        if T[j]==S[i+j] or S[i+j]=='?':
            continue
        else:
            c=1
            break
    if c==0:
        ans=S.replace('?','a')
        ans=ans[:i] + T + ans[i+lt+1:]
        break
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
ls=len(S)
lt=len(T)

ans='UNRESTORABLE'

if ls<lt:
    print(ans)
    exit()
for i in range(ls-lt,-1,-1):
    c=0
    for j in range(lt):
        if T[j]==S[i+j] or S[i+j]=='?':
            continue
        else:
            c=1
            break
    if c==0:
        ans=S.replace('?','a')
        ans=ans[:i] + T + ans[i+lt:]
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
ls=len(S)
lt=len(T)

ans='UNRESTORABLE'

if ls<lt:
    print(ans)
    exit()
for i in range(ls-lt,0,-1):
    c=0
    for j in range(lt):
        if T[j]==S[i+j] or S[i+j]=='?':
            continue
        else:
            c=1
            break
    if c==0:
        ans=S.replace('?','a')
        ans=ans[:i] + T + ans[i+lt:]
print(ans)

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
print(ls, lt)
if ls < lt:
    print("UNRESTORABLE")
else:
    res = []
    for i in range(ls-lt+1):
        res.append(s[i:i+lt])
    tmp = []
    for i in range(len(res)):
        flag = True
        for j in range(lt):
            if res[i][j] == t[j] or res[i][j] == '?':
                pass
            else:
                flag = False
                break
        if flag:
            tmp.append(i)
    ans = []
    for i in tmp:
        q = []
        for j in range(0, i):
            q.append(s[j])
        for j in range(0, lt):
            q.append(t[j])
        for j in range(i+lt, ls):
            q.append(s[j])
        for j in range(ls):
            if q[j] == '?':
                q[j] = 'a'
        ans.append(''.join(q))
    if ans:
        print(min(ans))
    else:
        print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
sp = list(input())
t = list(input())
boo = False
if len(sp)-len(t)>=0:
    for i in range(len(sp)-len(t)+1):
        for j in range(len(t)):
            if t[j] != sp[i+j] and sp[i+j] != "?":
                break
        else:
            for j in range(len(t)):
                sp[i+j] = t[j]
            
            boo = True
            break
        continue
    if boo:
        for i in range(len(sp)):
            if sp[i] =="?":
                sp[i] = "a"
    
        print("".join(map(str, sp)))
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
sp = list(input())
t = list(input())
boo = False
if len(sp)-len(t)>=0:
    for i in range(len(sp)-len(t)+1):
        for j in range(len(t)):
            if t[j] != sp[i+j] and sp[i+j] != "?":
                break
        else:
            for j in range(len(t)):
                sp[i+j] = t[j]
            print(sp)
            boo = True
            break
        continue
    if boo:
        for i in range(len(sp)):
            if sp[i] =="?":
                sp[i] = "a"
    
        print("".join(map(str, sp)))
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
sp = list(input())
t = list(input())
if len(sp)-len(t)>=0:
    for i in range(len(sp)-len(t)+1):
        for j in range(len(t)):
            if t[j] != sp[i+j] and sp[i+j] != "?":
                break
        else:
            for j in range(len(t)):
                sp[i+j] = t[j]

            
        continue
    for i in range(len(sp)):
        if sp[i] =="?":
            sp[i] = "a"
    print("".join(map(str, sp)))
else:
    print("UNRESORABLE")

Submission status: Wrong Answer

Solution code:
sp = list(input())
t = list(input())
if len(sp)-len(t)>=0:
    for i in range(len(sp)-len(t)+1):
        for j in range(len(t)):
            if t[j] != sp[i+j] and sp[i+j] != "?":
                break
        else:
            for j in range(len(t)):
                sp[i+j] = t[j]
            print(sp)
            
        continue
    for i in range(len(sp)):
        if sp[i] =="?":
            sp[i] = "a"
    print("".join(map(str, sp)))
else:
    print("UNRESORABLE")

Submission status: Wrong Answer

Solution code:
def resolve():
	s = list(input())
	t = list(input())
	candidates = []
	for i in range(len(s) - len(t) + 1):
		ok = True
		for j in range(len(t)):
			if s[i+j] != t[j] and s[i+j] != '?':
				ok = False
				break
		if ok:
			for j in range(len(t)):
				s[i + j] = t[j]
			for j in range(len(s)):
				if s[j] == '?':
					s[j] = 'a'
			candidates.append("".join(s))
	if len(candidates):
		print(min(candidates))
	else:
		print('UNRESTORABLE')
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
	s = list(input())
	t = list(input())
	for i in range(len(s) - len(t) + 1):
		ok = True
		for j in range(len(t)):
			if s[i+j] != t[j] and s[i+j] != '?':
				ok = False
				break
		if ok:
			for j in range(len(t)):
				s[i + j] = t[j]
			for j in range(len(s)):
				if s[j] == '?':
					s[j] = 'a'
			print("".join(s))
			return
	print('UNRESTORABLE')
resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
	s = list(input())
	t = list(input())
	ok = False
	for i in range(len(s)):
		if s[i] == t[0] and (i+len(t)-1) < len(s):
			l = 0
			for j in range(len(t)):
				g = s[i+j]
				if g == t[j]:
					l += 1
				elif s[i+j] == '?':
					l += 1
			if len(t) == l:
				ok = True
			if ok:
				for k in range(len(t)):
					s[i+k] = t[k]
				break
	if ok:
		for i in range(len(s)):
			if s[i] == '?':
				s[i] = 'a'
		print("".join(s))
	else:
		print('UNRESTORABLE')
resolve()

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
t = input()[::-1]

def check(c,t):
    if len(c) < len(t):
        return False
    for i in range(len(t)):
        if c[i] != "?" and c[i] != t[i]:
            return False

    return True
        

i = 0 
Has = False
ans = ""
while i < len(s):
    if s[i] == "?" or s[i] == t[0] and not Has:
        if check(s[i:],t):
            Has = True
            ans += t
            i += len(t)
        else:
            if s[i] == "?":
                ans += "a"
            else:
                ans += s[i]
            i += 1

    elif s[i] == "?":
        i += 1
        ans += "a"
    else:
        ans += s[i]
        i += 1

if Has:
    print(ans[::-1])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

ans_list = []
if t in s:
    print(s.replace('?', 'a'))
else:
    for i in range(0 , len(s) - len(t)+1)[::-1]:
        flag = True
        for j in range(len(t)):
            if s[i+j] == t[j] or s[j] == '?':
                continue
            else:
                flag = False
                break
        if flag ==  True:
            tmp = s
            tmp = tmp.replace(tmp[i : i+len(t)] , t)
            ans_list.append(tmp.replace('?', 'a'))
    if len(ans_list) == 0:
        print('UNRESTORABLE')
    else:
        ans_list.sort()
        print(ans_list[0])

Submission status: Wrong Answer

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

ans_list = []
if t in s:
    print(s.replace('?', 'a'))
else:
    for i in range(0 , len(s) - len(t)+1)[::-1]:
        flag = True
        for j in range(i , i + len(t)):
            if s[j] == t[j - i] or s[j] == '?':
                continue
            else:
                flag = False
                break
        if flag ==  True:
            tmp = s
            tmp = tmp.replace(tmp[i : i+len(t)] , t)
            ans_list.append(tmp.replace('?', 'a'))
    if len(ans_list) == 0:
        print('UNRESTORABLE')
    else:
        ans_list.sort()
        print(ans_list[0])

Submission status: Wrong Answer

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

ans_list = []
if t in s:
    print(s.replace('?', 'a'))
else:
    for i in range(0 , len(s) - len(t)+1):
        flag = True
        for j in range(i , i + len(t)):
            if s[j] == t[j - i] or s[j] == '?':
                continue
            else:
                flag = False
                break
        if flag ==  True:
            tmp = s
            tmp = tmp.replace(tmp[i : i+len(t)] , t)
            ans_list.append(tmp.replace('?', 'a'))
    if len(ans_list) == 0:
        print('UNRESTORABLE')
    else:
        ans_list.sort()
        print(ans_list[0])

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
s_long = len(s)
t_long = len(t)
ok = []
for i in range(s_long - t_long+1):
  part_s = s[i:i+t_long]
  check = True
  for j in range(t_long):
    if part_s[j] != "?" and part_s[j] != t[j]:
      check = False
  if check == True:
    ok.append(i)
  
if len(ok) == 0 or t_long > s_long:
  print("UNRESTORABLE")
else:
  a = max(ok)
  s = s[:a] + t + s[a + t_long + 1:]
  s = list(s)
  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()
s_long = len(s)
t_long = len(t)
ok = []
for i in range(s_long - t_long+1):
  part_s = s[i:i+t_long]
  check = True
  for j in range(t_long):
    if part_s[j] != "?" and part_s[j] != t[j]:
      check = False
  if check == True:
    ok.append(i)
  
if len(ok) == 0:
  print("UNRESTORABLE")
else:
  a = max(ok)
  s = s[:a] + t + s[a + t_long + 1:]
  s = list(s)
  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()
res = []

ok = -1
for i in range(len(S) - len(T) + 1):
    if S[i] == T[0] or S[i] == "?":
        for j in range(len(T)):
            if S[i + j] not in ("?", T[j]):
                break
        else:
            s = S[:i] + T + S[i + len(T):]
            res.append(s.replace("?", "a"))

if res:
    print(*res)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
res = []

ok = -1
for i in range(len(S) - len(T) + 1):
    if S[i] == T[0] or S[i] == "?":
        for j in range(len(T)):
            if S[i + j] not in ("?", T[j]):
                break
        else:
            s = S[:i] + T + S[i + len(T):]
            res.append(s.replace("?", "a"))

if res:
    print(res)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

ok = -1
for i in range(len(S) - len(T) + 1):
    if S[i] == T[0] or S[i] == "?":
        for j in range(len(T)):
            if S[i + j] != T[j] and S[i + j] != "?":
                break
        else:
            ok = i
            break

if ok > -1:
    for i in range(len(S)):
        if S[i] == "?":
            S[i] = "a"
    res = S[:ok] + T + S[ok + len(T):]
    print("".join(res))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

ok = -1
for i in range(len(S) - len(T) + 1):
    if S[i] == T[0] or S[i] == "?":
        for j in range(len(T)):
            if S[i + j] != T[j] and S[i + j] != "?":
                break
        else:
            ok = i
            break

if ok > -1:
    for i in range(len(S)):
        if S[i] == "?":
            S[i] = "a"
    res = S[:ok] + T + S[i + len(T):]
    print("".join(res))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
res = "UNRESTORABLE"

for i in range(len(S)-1, len(T)-1, -1):

  s = list(S[::])
  j = i
  flag = True
  for k in range(len(T)-1, -1, -1):
    if s[j] == "?":
      s[j] = T[k]
      j -= 1
    elif s[j] == T[k]:
      j -= 1
      continue
    elif s[j] != T[k]:
      flag = False
      break

  if flag:
    for j in range(len(s)):
      if s[j] == "?": s[j] = "a"
    res = "".join(s)
    break

print(res)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
res = "UNRESTORABLE"

for i in range(len(S)-1, len(T)-1, -1)[::-1]:
  
  s = list(S[::])
  j = i
  flag = True
  for k in range(len(T)-1, -1, -1):
    if s[j] == "?":
      s[j] = T[k]
    elif s[j] == T[k]:
      continue
    elif s[j] != T[k]:
      flag = False
      break
    j -= 1

  if flag:
    for j in range(len(s)):
      if s[j] == "?": s[j] = "a"
    res = s
    break

print("".join(res))

Submission status: Wrong Answer

Solution code:
ss = input()
t = input()
sl = len(ss)
tl = len(t)
f = False
min = ""

for i in range(sl-tl+1):
    for j, tj in enumerate(t):
        if not(ss[i+j] == tj or ss[i+j] == "?"):
            break
        if tj == t[-1]:
            s = ""
            for k, sk in enumerate(ss):
                if i <= k and k < i+tl:
                    s += t[k-i]
                elif sk == "?":
                    s += "a"
                else:
                    s += sk
            if not f:
                f = True
                min = s
            elif min > s:
                min = s

if not f:
    print("UNRESTORABLE")
else:
    print(min)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = readline().rstrip().decode()
t = read().rstrip().decode()
ans = []
for i in range(len(s) - len(t) + 1):
    for j, (ss, tt) in enumerate(zip(s[i:], t)):
        if ss not in ('?', tt):
            break
    else:
        memo = s[:i] + t + s[i + len(t):]
        ans.append(memo.replace('?', 'a'))
print(min(ans) if ans else 'UNRESTRABLE')

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = readline().rstrip().decode()[::-1]
t = read().rstrip().decode()[::-1]
if t in s:
    print(''.join('{}'.format('a' if ss == '?' else ss) for ss in s[::-1]))
    exit()
for i in range(len(s) - len(t)):
    for ss, tt in zip(s[i:i + len(t)], t):
        if ss != tt and ss != '?':
            break
    else:
        ans = ''
        for i, ss in enumerate(s):
            if ss == '?':
                ans = ('a' if i >= len(t) else t[i]) + ans
            else:
                ans = ss + ans
        print(ans)
        exit()
print('UNRESTRABLE')

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = readline().rstrip().decode()[::-1]
t = read().rstrip().decode()[::-1]
for i in range(len(s) - len(t)):
    for ss, tt in zip(s[i:i + len(t)], t):
        if ss != tt and ss != '?':
            break
    else:
        ans = ''
        for i, ss in enumerate(s):
            if ss == '?':
                ans = ('a' if i >= len(t) else t[i]) + ans
            else:
                ans = ss + ans
        print(ans)
        exit()
print('UNRESTRABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
s_rev = s[::-1]
t_rev = t[::-1]
cnt = 0
j = len(t)-1
ans = -1
for i in range(len(s)):
    if cnt == len(t):
        ans = s[:cnt-j] + t + s[cnt+len(t):]
    if s_rev[i]=='?':
        cnt += 1
    elif s_rev[i]==t_rev[j]:
        cnt += 1
        j -= 1
    else:
        cnt = 0
        j = len(t) - 1
if ans == -1:
    print('UNRESTORABLE')
else:
    print(ans.replace('?', 'a'))

Submission status: Wrong Answer

Solution code:
import re
S2=input().strip().replace("?",".")
T=input()
ans="UNRESTORABLE"
if len(S2)<len(T):
    pass
else:
    for i in range(len(S2)-len(T)):
        m=re.match(S2[len(S2)-len(T)-i:len(S2)-i],T)
        if m != None:
            ans=S2[:len(S2)-len(T)-i]+ T + S2[len(S2)-i:]
            ans=ans.replace(".","a")
            break

print(ans)

Submission status: Wrong Answer

Solution code:
import re
S2=input().strip().replace("?",".")
T=input()
ans="UNRESTORABLE"
if len(S2)<=len(T):
    pass
else:
    for i in range(len(S2)-len(T)):
        m=re.match(S2[len(S2)-len(T)-i:len(S2)-i],T)
        if m != None:
            ans=S2[:len(S2)-len(T)-i]+ T + S2[len(S2)-i:]
            ans=ans.replace(".","a")
            break

print(ans)

Submission status: Wrong Answer

Solution code:
a = list(input())
b = list(input())
c = len(a)
d = len(b)
if d > c:
    print("UNRESTORABLE")
    exit()
    
def comp1(s,t,l):
    for i in range(l):
        if s[i] == t[i] or s[i] == "?":
            flag = True
        else:
            flag = False
            break
    return flag

def comp2(s,l):
    for i in range(l):
        if s[i] == "?":
            flag = True
        else:
            flag = False
            break
    return flag

if comp2(a,c):
    e = a[:c-d] + b
    for i in range(c):
        if e[i] == "?":
            e[i] = "a"
    print("".join(e))
    exit()

if comp1(a[:d],b,d):
    e = b + ["a"*(c-d)]
    print("".join(e))
    exit()
    
flag = False
idx1,idx2 = 0,0 

for i in range(c-d+1):
    aa = a[c-d-i:c-i]
    idx1,idx2 = c-d-i,c-i
    #print(a[idx1:idx2])
    for j in range(d):
        #print(aa)
        if (aa[j] == b[j]):
            flag = True
            if a[idx1:idx2] == b:
                
                break
        elif (aa[j] == "?"):
            aa[j] = b[j]
            flag = True
            if aa == b:
                break
        else:
            flag = False
            #break
    else:
        continue
    break
if flag:
    a = a[:idx1] + b + a[idx2:]
    for i in range(c):
        if a[i] == "?":
            a[i] = "a"
    print("".join(a))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
a = list(input())
b = list(input())
c = len(a)
d = len(b)
if d > c:
    print("UNRESTORABLE")
    exit()

ok = 1
for i in range(len(a)):
    if a[i] == "?":
        ok = 1
    else:
        ok = 0
        break
if ok:
    e = a[:c-d] + b
    for i in range(c):
        if e[i] == "?":
            e[i] = "a"
    print("".join(e))
    exit()

flag = False
idx1,idx2 = 0,0 

for i in range(c-d+1):
    aa = a[c-d-i:c-i]
    idx1,idx2 = c-d-i,c-i
    #print(a[idx1:idx2])
    for j in range(d):
        #print(aa)
        if (aa[j] == b[j]):
            flag = True
            if a[idx1:idx2] == b:
                
                break
        elif (aa[j] == "?"):
            aa[j] = b[j]
            flag = True
            if aa == b:
                break
        else:
            flag = False
            #break
    else:
        continue
    break
if flag:
    a = a[:idx1] + b + a[idx2:]
    for i in range(c):
        if a[i] == "?":
            a[i] = "a"
    print("".join(a))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
a = list(input())
b = list(input())
c = len(a)
d = len(b)
if d > c:
    print("UNRESTORABLE")
    exit()
flag = False
idx1,idx2 = 0,0 

for i in range(c-d+1):
    aa = a[c-d-i:c-i]
    for j in range(d):
        if aa[j] == b[j]:
            flag = True
            idx1,idx2 = c-d+i,c-i
            break
        else:
            flag = False
            break
    else:
        continue
    break
#print(aa,idx1,idx2)
a = a[:idx1] + b + a[idx2:]

for i in range(c):
    if a[i] == "?":
        a[i] = "a"

if flag:
    print("".join(a))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
a = list(input())
b = list(input())
c = len(a)
d = len(b)
if d > c:
    print("UNRESTORABLE")
    exit()
flag = False
idx = 0
for i in range(c-d+1):
    li = [0]*c
    for k in range(c):
        li[k] = a[k]
        
    for j in range(d):
        if b[j] == a[i+j] or a[i+j] == "?":
            flag = True
            li[i+j] = b[j]
            if li[i:i+j+1] == b:
                idx = j+1
                break
        elif b[j] != a[i+j]:
            flag = False
        if li[i:i+j+1] != b:
            flag = False
    else:
        continue
    break

cnt = 0
if "?" in li[idx:]:
    for i in range(idx,len(li)):
        if li[i] == "?":
            li.remove(li[i])
            cnt +=1
            li = ["a"] + li

for i in range(c):
    if li[i] == "?":
        li[i] = "a"

if flag:
    print("".join(li))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
a = list(input())
b = list(input())
c = len(a)
d = len(b)
if d > c:
    print("UNRESTORABLE")
    exit()
flag = False
for i in range(c-d+1):
    li = [0]*c
    for k in range(c):
        li[k] = a[k]
        
    for j in range(d):
        if b[j] == a[i+j] or a[i+j] == "?":
            flag = True
            li[i+j] = b[j]
            #print(i,j,li,li[i:i+j+1])
            if li[i:i+j+1] == b:
                break
        elif b[j] != a[i+j]:
            flag = False
        if li[i:i+j+1] != b:
            flag = False
    else:
        continue
    break
#print(li)
for i in range(c):
    if li[i] == "?":
        li[i] = "a"

if flag:
    print("".join(li))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

N = len(S)
M = len(T)

if N < M:
    print('UNRESTORABLE')
    exit()

ans = 'UNRESTORABLE'
for i in range(N-M+1):
    anss = S[:i] + T + S[i+M:]
    print(anss)
    make = 1
    anss = list(anss)
    for j in range(N):
        if anss[j] == '?':
            if S[j] == '?':
                anss[j] = 'a'
            else:
                anss[j] = S[j]
        else:
            if anss[j] != S[j] and S[j] != '?':
                make = 0
                break
    if make:
        ans = ''.join(anss)
print(ans)

Submission status: Wrong Answer

Solution code:
def solve(s, t):

    length = len(t)
    ans = ""
    i = len(s)-1
    flg = False
    while i > 0:
        tmp = s[i-length+1:i+1]
        count = len([i for i, j in zip(tmp, t) if i == j or i == "?"])
        if length == count:
            ans = s[:i-length+1] + t
            flg = True
            break
        else:
             ans = s[:i-length] + ("a" if s[i] == "?" else s[i])
             i -= 1

    return ans.replace("?", "a") if flg else "UNRESTORABLE"

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

Submission status: Wrong Answer

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

def rplc(s, i, T):
  s[i:i+len(T)] = T
  return ''.join(s).replace('?', 'a')

ans = 'UNRESTORABLE'
for i in range(len(s)-len(T)+1):
  sbstr = s[i:i+len(T)]
  flg = True
  for j in range(len(T)):
    if sbstr[j] == '?':
      continue
    if sbstr[j] != T[j]:
      flg = False
      break
  if flg:
    ans = rplc(s, i , T) 

print(ans)

Submission status: Wrong Answer

Solution code:
def solve(s, t):

    length = len(t)
    ans = ""
    i = 0
    flg = False
    while i < len(s):
        tmp = s[i:i+length]
        count = len([i for i, j in zip(tmp, t) if i == j or i == "?"])
        if length == count:
            ans += t
            i += length
            flg = True
        else:
            ans += "a" if s[i] == "?" else s[i]
            i += 1

    return ans if flg else "UNRESTORABLE"

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

Submission status: Wrong Answer

Solution code:
def solve(s, t):

    length = len(t)
    ans = ""
    i = 0
    flg = False
    while i < len(s):
        tmp = s[i:i+length]
        print(tmp, t)
        count = len([i for i, j in zip(tmp, t) if i == j or i == "?"])
        if length == count:
            ans += t
            i += length
            flg = True
        else:
            ans += "a" if s[i] == "?" else s[i]
            i += 1

    return ans if flg else "UNRESTORABLE"

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

Submission status: Wrong Answer

Solution code:
#6 Dubious Document 2
s=input()
t=input()
ls=len(s)
lt=len(t)

cand=[]
for i in range(ls-lt+1):
    scut =s[i:i+lt]
#    for j,tt in enumerate(t):
    if all(tt==ss or ss=="?" for tt,ss in zip(t,scut) ):
        cand.append(i)
        
ans=[]
for c in cand:
    ans.append( (s[:i]+ t+ s[i+lt:]).replace("?","a") )

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

Submission status: Wrong Answer

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