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()
judge = False
ans = ''
for i in range(len(s) - len(t) + 1):
    tmp = s[i:i + len(t)]
    for j in range(len(t)):
        if tmp[j] != t[j] and tmp[j] != '?':
            judge = False
            break
        else:
            judge = True
    if judge:
        ans = s[:i] + t + s[i + len(t):-1]
        break

if judge:
    print(''.join('a' if i == '?' else i for i in ans))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

S = input().strip()
T = input().strip()
#-----

i=0
ans=""
flag = False

while i < len(S):

    if ( S[i] == T[0] or S[i] == "?" )  and  (len(S) - i) >= len(T):
        for j,word_t in enumerate(T):
            if word_t == S[i+j] or S[i+j] == "?":
                continue
            else:
                ans += S[i]
                i += 1 
                break
        
        else:
            ans += T
            flag = True
            i += len(T)
    
    else:
        ans += S[i]
        i += 1


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

else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S1 = list(input())
T = list(input())
s = len(S1)
t = len(T)
kagi = -1
for i in range(s-t+1):
    for j in range(t):
        if T[j] != S1[-t-i+j] and T[j] != "?":
            continue
        kagi = i
        break
if kagi == -1:
    print("UNRESTORABLE")
else:
    for i in range(s-t-kagi):
        if S1[i] == "?":
            print("a", end = "")
        else:
            print(S1[i], end = "")
    print("".join(T))

Submission status: Wrong Answer

Solution code:
S1 = list(input())
T = list(input())
s = len(S1)
t = len(T)
kagi = -1
for i in range(s-t+1):
    for j in range(t):
        if T[j] != S1[-t-i+j] and T[j] != "?":
            continue
        kagi = i
if kagi == -1:
    print("UNRESTORABLE")
else:
    for i in range(s-t-kagi):
        if S1[i] == "?":
            print("a", end = "")
        else:
            print(S1[i], end = "")
    print("".join(T))

Submission status: Wrong Answer

Solution code:
S1 = list(input())
T = list(input())
s = len(S1)
t = len(T)
kagi = -1
for i in range(s-t+1):
    for j in range(t):
        if T[j] != S1[-t-i+j] and T[j] != "?":
            continue
        kagi = i
if kagi == -1:
    print("UNRESTORABLE")
    exit()
for i in range(s-t-kagi):
    if S1[i] == "?":
        print("a", end = "")
    else:
        print(S1[i], end = "")
print("".join(T))

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
if t in s:
    ans=s.replace("?","a")
    print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
s = s[::-1]
t = t[::-1]
s_size, t_size = len(s), len(t)
result = "UNRESTORABLE"

for i in range(s_size - t_size + 1):
    for j in range(t_size):
        if s[i + j] != t[j] and s[i + j] != '?':
            break
        if j == t_size - 1:
            s = (s[:i] + t + s[i + t_size :]).replace('?', 'a')
            if s.lower() < result.lower():
                s = s[::-1]
                result = s

print(result)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
s_size, t_size = len(s), len(t)
result = "UNRESTORABLE"

for i in range(s_size - t_size + 1):
    for j in range(t_size):
        if s[i + j] != t[j] and s[i + j] != '?':
            break
        if j == t_size - 1:
            s = (s[:i] + t + s[i + t_size :]).replace('?', 'a')
            if s.lower() < result.lower():
                result = s

print(result)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import re

# .にすることで正規表現で任意の文字列として扱う
S = input().replace('?', '.')
T = input()
ls = len(S)
lt = len(T)

for i in range(ls-lt,-1,-1):
    # Sの一部にTが含まれるかチェック
    if re.match(S[i:i+ls], T):
        S = S.replace('.', 'a')
        # i~i+lsとTの文字の部分に置き換えることで、Tを含む文字が作れる
        S = (S[:i]+T+S[i+lt:])
        print(S)
        exit(0)
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
s = input()
T = input()


for i in range(len(s)-len(T), -1, -1):
	for j in range(len(T)):
		if s[i+j] != T[j] and s[i+j] != "?":
			break
	else:
		p = s[:i] + T + s[i+len(s):]
		ans = ""
		for i in range(len(p)):
			if p[i] == "?":
				ans += "a"
			else:
				ans += p[i]
		print(ans)
		break
else:
	print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
s = input()
T = input()


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

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
s = input()
T = input()

lis = []
for i in range(len(s)-len(T)+1):
	for j in range(len(T)):
		if not (s[i+j] == T[j] or s[i+j] == "?"):
			break
	else:
		p = s[:i] + T + s[i+len(s):]
		ans = ""
		for i in range(len(p)):
			if p[i] == "?":
				ans += "a"
			else:
				ans += p[i]
		lis.append(ans)

lis.sort()

if not lis:
	print("UNRESTORABLE")
else:
	print(lis[0])

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
s = input()
T = input()

lis = []
for i in range(len(s)-len(T)+1):
	for j in range(len(T)):
		if s[i+j] == T[j] or s[i+j] == "?":
			continue
		else:
			break
	else:
		p = s[:i] + T + s[i+len(s):]
		ans = ""
		for i in range(len(p)):
			if p[i] == "?":
				ans += "a"
			else:
				ans += p[i]
		lis.append(ans)

lis.sort()

if not lis:
	print("UNRESTORABLE")
else:
	print(lis[0])

Submission status: Wrong Answer

Solution code:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *
 
s = input()
T = input()

for i in range(len(s)-len(T)+1):
	if s[i:i+len(T)] == T[0]+"?"*(len(T)-1):
		s = s[:i] + T +s[i+len(T):]
		break
else:
	print("UNRESTORABLE")
	exit()

for x in s:
	if x == "?":
		print("a", end="")
	else:
		print(x, end="")
print()

Submission status: Wrong Answer

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

x = "UNRESTORABLE"

sl = len(s)
tl = len(t)


if sl < tl:
    print(x)
    exit()

flag =0

for i in range(sl-tl,-1,-1):
    temp = s[i:i+tl]
    print(temp)
    for j in range(tl):
        if temp[j] == t[j] or temp[j] =="?":
            if j == tl-1:
                x = s[:i] + t + s[i+tl:]
                flag = 1
                break            
        else:
            break

    if flag ==1:
        break

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

print(x)

Submission status: Wrong Answer

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

for i in reversed(range(len(s)-n+1)):
    x = s[i:i+n]
    y = 0
    for j in range(n):
        if x[j] == "?" or x[j] == t[j]:
            continue
        else:
            y = 1
            break
    if y == 0:
        print(s[:i].replace("?", "a") +t)
        exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def test(SS, T, ss_index, t_index, target, list):
    if t_index == len(T):
        ret = "".join(SS).replace(target, "".join(T)).replace("?", "a")
        list.append(ret)
        return
    if ss_index == len(SS):
        return

    if SS[ss_index] == "?" or SS[ss_index] == T[t_index]:
        target += SS[ss_index]
        test(SS, T, ss_index + 1, t_index + 1, target, list)

    test(SS, T, ss_index + 1, 0, "", list)


SS = list(input())
T = list(input())
list = []
test(SS, T, 0, 0, "", list)

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

Submission status: Wrong Answer

Solution code:
def test(SS, T, ss_index, t_index, target, list):
    if t_index == len(T):
        ret = "".join(SS).replace(target, "".join(T)).replace("?", "a")
        list.append(ret)
        return
    if ss_index == len(SS):
        return

    if SS[ss_index] == "?" or SS[ss_index] == T[t_index]:
        target += SS[ss_index]
        test(SS, T, ss_index + 1, t_index + 1, target, list)
    else:
        target = ""
        test(SS, T, ss_index - t_index + 1, 0, target, list)


SS = list(input())
T = list(input())
list = []
test(SS, T, 0, 0, "", list)

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

Submission status: Wrong Answer

Solution code:
def test(SS, T, ss_index, t_index, target, list):
    if t_index == len(T):
        ret = "".join(SS).replace(target, "".join(T)).replace("?", "a")
        list.append(ret)
        return
    if ss_index == len(SS):
        return

    if SS[ss_index] == "?" or SS[ss_index] == T[t_index]:
        target += SS[ss_index]
        test(SS, T, ss_index + 1, t_index + 1, target, list)
    else:
        target = ""
        test(SS, T, ss_index + 1, 0, target, list)


SS = list(input())
T = list(input())
list = []
test(SS, T, 0, 0, "", list)

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

Submission status: Wrong Answer

Solution code:
Sp = input()
Sp_list = list(Sp)
N = len(Sp)
T = input()
n = len(T)

def check(s, t):
  for si, ti in zip(s, t):
    if si == '?':
      continue
    if si != ti:
      return False
  return True

ans = []
for i in range(N-n+1):
  if check(Sp[i:i+n], T):
    Sp_list[i:i+n] = list(T)
    ans.append(''.join(Sp_list).replace('?', 'a'))

if ans:
  ans.sort()
  print(ans[0])
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Sun May 31 14:28:43 2020

@author: NEC-PCuser
"""

S = input()
T = input()

start = 0

i = -1
for i in range(0, len(S) - len(T) + 1):
    k = 0
    for b in T:
        if S[i + k] != b and S[i + k] != '?':
            break
        k += 1
    else:
        start = i

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

Submission status: Wrong Answer

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

def match(k):
    flag = True
    for i in range(len(T)):
        if S[i+k] != T[i] and S[i+k]!="?":
            flag = False
            break
    return flag

flag = False
for k in reversed(range(len(S)-len(T)+1)):
    # print(k)
    if match(k):
        S = S[:k] + T + S[k+len(T):]
        flag = True
    
if flag:
    ans = S.replace("?","a")

if not flag:
    ans = "UNRESTORABLE"

print(ans)

Submission status: Wrong Answer

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

def match(k):
    flag = True
    for i in range(len(T)):
        if S[i+k] != T[i] and S[i+k]!="?":
            flag = False
            break
    return flag

flag = False
for k in range(len(S)-len(T)+1):
    # print(k)
    if match(k):
        S = S[:k] + T + S[k+len(T):]
        flag = True
    
if flag:
    ans = S.replace("?","a")

if not flag:
    ans = "UNRESTORABLE"

print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
s = s[::-1]
t = t[::-1]
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:
    break
else:
  print('UNSTORERABLE')
  exit(0)
s = s[:i] + t + s[i+len(t):]
s = s.replace('?','a')
s = s[::-1]
print(s)

Submission status: Wrong Answer

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

flag = 0
if t in s:
  s = s.replace('?', 'a')
  print(s)
  flag = 1
if '?' * len(t) in s:
  s = s[::-1]
  s = s.replace('?' * len(t), t[::-1], 1)
  s = s.replace('?', 'a')
  print(s[::-1])
  flag = 1          

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

Submission status: Wrong Answer

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

flag = 0
if t in s:
  s = s.replace('?', 'a')
  print(s)
  flag = 1
if '?' * len(t) in s:
  s = s[::-1]
  s = s.replace('?' * len(t), t[::-1], 1)
  s = s.replace('?', 'a')
  print(s[::-1])
  flag = 1          

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

Submission status: Wrong Answer

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

flag = 0
if t in s:
  s = s.replace('?', 'a')
  print(s)
  flag = 1
if '?' * len(t) in s:
  s = s[::-1]
  s = s.replace('?' * len(t), t[::-1], 1)
  s = s.replace('?', 'a')
  print(s[::-1])
  flag = 1          

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

Submission status: Wrong Answer

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

flag = 0
if t in s:
  s = s.replace('?', 'a')
  print(s)
  flag = 1

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

Submission status: Wrong Answer

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

flag = 0
if t in s:
  s = s.replace('?', 'a')
  print(s)
  flag = 1

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

Submission status: Wrong Answer

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

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

if flag == 0:
	print('UNRESTORABLE')

Submission status: Wrong Answer

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

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

if flag == 0:
	print('UNRESTORABLE')

Submission status: Wrong Answer

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

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

if flag == 0:
	print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
s=str(input()).replace("?", "@")
t=str(input())
cnt=0
ans=""
for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if cnt==1:
      break;
      
    elif s[i+j]==t[j] and len(s)-i-j+1>len(t)-j:
      ans=s[:i]+t+s[i+len(t):]
      cnt+=1
if cnt>0:
  ans2=ans.replace("@", "a")
  print(ans2)
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
s=str(input()).replace("?", "@")
t=str(input())
cnt=0
ans=""
for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if s[i+j]==t[j] and len(s)-i-j+1>len(t)-j:
      ans=s[:i]+t+s[i+len(t):]
      cnt+=1
      break;
if cnt>0:
  ans2=ans.replace("@", "a")
  print(ans2)
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
s=str(input()).replace("?", "@")
t=str(input())
cnt=0
ans=""
for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if s[i+j]==t[j] and len(s)-i+1>len(t):
      ans=s[:i]+t+s[i+len(t):]
      cnt+=1
      break;

      
if cnt>0:
  ans2=ans.replace("@", "a")
  print(ans2)
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
s=str(input()).replace("?", "@")
t=str(input())
cnt=0
ans=""
for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if s[i+j]==t[j]:
      ans=s[:i]+t+s[i+len(t):]
      cnt+=1
      break;

      
if cnt>0:
  ans2=ans.replace("@", "a")
  print(ans2)
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def main():
    UNRESTORABLE = 'UNRESTORABLE'
    INIT = 'z' * 51

    S = input()
    N = len(S)

    T = input()
    M = len(T)

    ans = INIT
    for i in range(N):
        if (N - i) < M: break
        *B, = S
        for j in range(i):
            if B[j] == '?': B[j] = 'a'

        for j in range(M):
            if (B[i + j] != '?') and (B[i + j] != T[j]): break
            B[i + j] = T[j]
        else:
            ans = min(ans, ''.join(B))

    if ans == INIT:
        print(UNRESTORABLE)
    else:
        print(ans)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

"""まず最初にTをどこに埋め込むかを考える　必ずTが埋め込めるやつをリストにして　そこから最小のやつをとる
埋め込む場所として考えられるのは高々S-T +1 個しかない
注意：文字列はイミュータブルだから変更できない"""

result = []
longt = len(T)
longs = len(S)
if longt <= longs:
    for k in range(longs - longt+1):
        st = list(S[k:k+longt+1])
        f = True
        for ii,s in enumerate(zip(st,T)):
            if s[0] == '?' :
                st[ii] = s[1]
            elif s[0] != s[1]:
                f = False

        if f:
            bS = list(S[:k])
            aS = list(S[k+longt+1:])
            bs = ['a' if i == '?' else i for i in bS]
            aa = ['a' if i == '?' else i for i in aS]
            bs = ''.join(bs)
            aa = ''.join(aa)
            sst = ''.join(st)
            result.append(bs+ sst + aa)

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

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import string

def main():
    S_ = input()
    T = input()
    S = ''
    i = 0
    if len(S_) < len(T):
        print('UNRESTORABLE')
        return
    while len(S) < len(S_):
        print(S)
        if S_[i] == T[0] and i <= len(S_)-len(T):
            accept = True
            for j,t in enumerate(T):
                if S_[i+j] == t or S_[i+j] == '?':
                    continue
                accept = False
            if accept:
                S += T
                i += len(T)
                continue
        S += S_[i]
        i += 1

    if len(S) != len(S_):
        print('UNRESTORABLE')
    else:
        print(S.replace('?','a'))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
from collections import defaultdict
import string

def main():
    S_ = input()
    T = input()
    S = ''
    accept = False
    for i in range(len(S_)-len(T)+1):
        accept = True
        for j,s in enumerate(S_[i:i+len(T)]):
            # print(s,T[j])
            if s == '?' or s == T[j]:
                continue
            accept = False
        if accept:
            break
    if accept:
        for j,s in enumerate(S_):
            if i <= j and j < i+len(T):
                S += T[j-i]
            else:
                S += s
        print(S.replace('?','a'))
    else:
        print('UNRESTORABLE')

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import copy

sd = str(input())
t = str(input())
s = copy.deepcopy(sd)

flg = False
pin = -1
for i in reversed(range(len(sd)-len(t)+1)):
    for j in range(len(t)):
        if sd[i+j] != t[j] and sd[i+j] != '?':
            break
        elif j == len(t)-1:
            flg = True
            pin = i
            break
    if flg:
        break
if flg:
    s = s.replace(s[pin:],t[:])
    s = s.replace('?', 'a')
    print(s)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=[x for x in input()]
t=[x for x in input()]
ans=[]
for i in range(len(s)):
  cnt=0
  nowi=i
  fi=i
  for j in range(len(t)):
    if s[nowi]==t[j] or s[nowi]=="?":
      cnt+=1
    else:
      break
    if cnt==len(t):
      ans.append((s[:fi]+t+s[nowi+1:]))
    if nowi+1<=len(s)-1:
      nowi+=1
    else:
      break

A=[]
if len(ans)==0:
  print("UNRESTORABLE")
else:   
  for i in ans:
    moji=""
    for m in i:
      if m=="?":
        moji+="a"
      else:
        moji+=m
    A.append(moji)
  print(A)
  A.sort()
  print(A[0])

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
T = input()
M = len(T)

ans = []

def changehatena(S):
    S = "".join(S)
    S = S.replace("?", "a")
    return S

hatena_num = 0
for i in range(N):
    if S[i] == "?":
        hatena_num += 1
        if hatena_num == M-2:
            #odeのパターン
            tmp = S[:]
            tmp[i-M+3:i+1] = list(T)[1:-1]#TOCHECK
            tmp = changehatena(tmp)
            # print(hatena_num, tmp)#TEST
            if T in tmp:
                ans.append(tmp)
        elif hatena_num == M-1:
            #codeのパターン
            tmp = S[:]
            tmp[i-M+2:i+1] = list(T)[:-1]#TOCHECK
            tmp = changehatena(tmp)
            # print(hatena_num, tmp)#TEST
            if T in tmp:
                ans.append(tmp)
            #oderのパターン
            tmp = S[:]
            tmp[i-M+2:i+1] = list(T)[1:]#TOCHECK
            tmp = changehatena(tmp)
            # print(hatena_num, tmp)#TEST
            if T in tmp:
                ans.append(tmp)
        elif hatena_num == M:
            #coderのパターン
            tmp = S[:]
            tmp[i-M+1:i+1] = list(T)[:]#TOCHECK
            tmp = changehatena(tmp)
            # print(hatena_num, tmp)#TEST
            if T in tmp:
                ans.append(tmp)
            hatena_num -= 1
    else:
        hatena_num = 0

if ans:
    ans.sort()
    print(ans[0])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
T = input()
M = len(T)

ans = []

def changehatena(S):
    S = "".join(S)
    S = S.replace("?", "a")
    return S

hatena_num = 0
for i in range(N):
    if S[i] == "?":
        hatena_num += 1
        if hatena_num == M-2:
            #odeのパターン
            tmp = S[:]
            tmp[i-M+3:i+1] = list(T)[1:-1]#TOCHECK
            tmp = changehatena(tmp)
            # print(hatena_num, tmp)#TEST
            if T in tmp:
                ans.append(tmp)
        elif hatena_num == M-1:
            #codeのパターン
            tmp = S[:]
            tmp[i-M+2:i+1] = list(T)[:-1]#TOCHECK
            tmp = changehatena(tmp)
            # print(hatena_num, tmp)#TEST
            if T in tmp:
                ans.append(tmp)
            #oderのパターン
            tmp = S[:]
            tmp[i-M+2:i+1] = list(T)[1:]#TOCHECK
            tmp = changehatena(tmp)
            # print(hatena_num, tmp)#TEST
            if T in tmp:
                ans.append(tmp)
        elif hatena_num == M:
            #coderのパターン
            tmp = S[:]
            tmp[i-M+1:i+1] = list(T)[:]#TOCHECK
            tmp = changehatena(tmp)
            # print(hatena_num, tmp)#TEST
            if T in tmp:
                ans.append(tmp)
            hatena_num = 0
    else:
        hatena_num = 0

if ans:
    ans.sort()
    print(ans[0])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys
s=[x for x in input()]
t=[x for x in input()]

def hantei():

  for i in range(len(s)):
    nowi=i
    fi=i
    cnt=0
    for j in range(len(t)):
      if s[nowi]==t[j] or s[nowi]=="?":
        cnt+=1
        # print(i,nowi,j,cnt)
        if cnt==len(t):
          return True,fi,nowi

        if nowi+1<=len(s)-1:
          nowi+=1
        else:
          cnt=0
          break
      else:
        cnt=0
  return False,fi,nowi

a,b,c=hantei()
ans=""
if a==False:
  print("UNRESTORABLE")
else:
  moji=""
  ans=s[0:b]+t+s[c+1:]
  for i in ans:
    if i=="?":
      moji+="a"
    else:
      moji+=i
  print(moji)

Submission status: Wrong Answer

Solution code:
import sys
s=[x for x in input()]
t=[x for x in input()]

def hantei():

  for i in range(len(s)):
    nowi=i
    fi=i
    cnt=0
    for j in range(len(t)):
      if s[nowi]==t[j] or s[nowi]=="?":
        cnt+=1
        # print(i,nowi,j,cnt)
        if cnt==len(t):
          return True,fi

        if nowi+1<=len(s)-1:
          nowi+=1
        else:
          cnt=0
          break
      else:
        cnt=0
  return False,float('inf')

a,b=hantei()
ans=""
if a==False:
  print("UNRESTORABLE")
else:
  moji=""
  ans=s[0:b]+t
  for i in ans:
    if i=="?":
      moji+="a"
    else:
      moji+=i
  print(moji)