Problem:


Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.

He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.  

One more thing he found is a sheet of paper with the following facts written on it:  

Condition 1: The string S contains a string T as a contiguous substring.

Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.

Print the string S.

If such a string does not exist, print UNRESTORABLE.  

Constraints

1 \leq |S'|, |T| \leq 50

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

If such a string does not exist, print UNRESTORABLE instead.  

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

There are 26 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder.
Among them, the lexicographically smallest is atcoder, so we can say S = atcoder.

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

There is no string that satisfies Condition 1, so the string S does not exist.



Sample input:
?tc????
coder


Sample output:
atcoder

Submission status: Wrong Answer

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

if len(s) <= len(t):
    print('UNRESTORABLE')
    exit()
ansl = []

if t in s:
    print(s.replace('?', 'a'))
else:
    target = []
    for i, si in enumerate(s):
        if si == t[0]:
            target.append(i)
    for tar in target:
        flag = True
        for i in range(tar, tar+len(t)):
            if s[i] == t[i-tar] or s[i] == '?':
                continue
            else:
                flag = False
        if flag:
            ans = s[:tar]+t+s[tar+len(t):]
            ans = ans.replace('?', 'a')
            if len(ans) == len(s):
                ansl.append(ans)
if len(ansl) == 0:
    print('UNRESTORABLE')
else:
    ansl.sort()
    print(ansl[0])

Submission status: Wrong Answer

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

if len(s) <= len(t):
    print('UNRESTORABLE')
    exit()
ansl = []

if t in s:
    print(s.replace('?', 'a'))
else:
    target = []
    for i, si in enumerate(s):
        if si == t[0]:
            target.append(i)
    for tar in target:
        flag = True
        for i in range(tar, tar+len(t)):
            if s[i] == t[i-tar] or s[i] == '?':
                continue
            else:
                flag = False
        if flag:
            ans = s[:tar]+t+s[tar+len(t):]
            ans = ans.replace('?', 'a')
            ansl.append(ans)
if len(ansl) == 0:
    print('UNRESTORABLE')
else:
    ansl.sort()
    print(ansl[0])

Submission status: Wrong Answer

Solution code:

s = list(input())
t = list(input())
sn = len(s)
tn = len(t)

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

  if flag:
    for j in range(tn):
      s[i+j] = t[j] 
    break

  if i == sn - tn and flag == False:
    print('UNRESTORABLE')
    exit()

for i in range(sn):
  if s[i] == '?':
    s[i] = 'a'

print(''.join(s))

Submission status: Wrong Answer

Solution code:

s = list(input())
t = list(input())
sn = len(s)
tn = len(t)

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

  if flag:
    for j in range(tn):
      s[i+j] = t[j] 
    break

  if i == sn - tn and flag == False:
    print('UNRESTORABLE')
    exit()

print(s)
for i in range(sn):
  if s[i] == '?':
    s[i] = 'a'

print(''.join(s))

Submission status: Wrong Answer

Solution code:
Sp = input()
T = input()
len_Sp = len(Sp)
len_T = len(T)
ans = ''
cnt = 0

for i in range(len_Sp - len_T + 1):
    for j in range(len_T):
        if Sp[i + j] == T[j] or Sp[i + j] == '?':
            cnt += 1
        else:
            cnt = 0
            break;
    if cnt == len_T:
        Sp_list = list(Sp)
        for k in range(len_T):
            Sp_list[i + k] = T[k]
        ans = ''.join(Sp_list)
        ans = ans.replace('?', 'a')
        print(ans)
        break;
if cnt != len_T:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
n=len(s)
m=len(t)
for i in range(n):
    if i+m-1>=n:
        continue
    j=0
    flag=True
    #print(i,end=' i cur\n')
    while j<m:
        if s[j+i]=='?':
            j+=1
        elif s[j+i]==t[j]:
            j+=1
        else:
            flag=False
            break
    if flag:
     #   print(i,end=' i\n')
        for k in range(i):
            if s[k]=='?':
                print('a',end='')
            else:
                print(s[k],end='')
        print(t,end='')
        for k in range(i+m,n):
            if s[k]=='?':
                print('a',end='')
            else:
                print(s[k],end='')
        print()
        import sys
        sys.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, -1, -1):
    if re.match(S[i:i+len(T)], T):
        S = S.replace(".", "a")
        print(S[:i]+T+S[i+len(T):])
        break
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.replace(".", "a")
        print(S[:i]+T+S[i+len(T):])
        break
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)], S):
        S.replace(".", "a")
        print(S[:i]+T+S[i+len(T):])
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def compare(sub, t):
    for i in range(len(t)):
        if sub[i] == t[i] or sub[i] == '?':
            continue
        else:
            return False
    return True

clear = False
s = input()
t = input()
for i in range(len(s)-len(t), 0, -1):
    if compare(s[i:i+len(t)], t):
        clear = True
        s = s[:i] + t + s[i+len(t):]
        break
if clear:
    print(s.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

if T in S:
    print(S.replace('?', 'a'))
    exit()

A = ''
cnt = 0
while len(S) > len(A):
    A += S[cnt]
    if S[cnt] == T[0]:
        tmp = 1
        while len(T) > tmp:
            A += T[tmp]
            tmp += 1
        cnt = tmp     
    cnt +=1
           
if A == S:
  print('UNRESTORABLE')
  exit()
  
print(A.replace('?', 'a'))

Submission status: Wrong Answer

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

A = ''
cnt = 0
while len(S) > len(A):
    A += S[cnt]
    if S[cnt] == T[0]:
        tmp = 1
        while len(T) > tmp:
            A += T[tmp]
            tmp += 1
        cnt = tmp
    cnt +=1
           
if A == S:
  print('UNRESTORABLE')
  exit()
  
ans =''  
for a in A:
  if a == '?':
    a = 'a'
  ans += a
    
print(ans)

Submission status: Wrong Answer

Solution code:

S = input()
T = input()


A = ''
cnt = 0
while len(S) > len(A):
    A += S[cnt]
    if S[cnt] == T[0]:
        tmp = 0
        while len(T) > tmp:
            A += T[tmp]
            tmp += 1
        cnt = tmp                         
    cnt +=1
           
if A == S:
  print('UNRESTORABLE')
  exit()
  
ans =''  
for a in A:
  if a == '?':
    a = 'a'
  ans += a
    
print(ans)

Submission status: Wrong Answer

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

A = ''
cnt = 0
while len(S) > len(A):
    A += S[cnt]
    if S[cnt] == T[0]:
        tmp = 0
        while len(T) > tmp:
            A += T[tmp]
            tmp += 1
    cnt +=1
           
if A == S:
  print('UNRESTORABLE')
  exit()
  
ans =''  
for a in A:
  if a == '?':
    a = 'a'
  ans += a
    
print(ans)

Submission status: Wrong Answer

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

A = ''
for i in range(len(S)):
    if S[i] == T[0]:
        A += T
        break
    A += S[i]
if A == S:
  print('UNRESTORABLE')
  exit()

ans =''  
for a in A:
  if a == '?':
    a = 'a'
  ans += a
    
print(ans)

Submission status: Wrong Answer

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

cands = []
S_cand = None
for i in range(len(S_d) - len(T) + 1):
    flag = True
    for j, t in enumerate(T):
        if S_d[i + j] == '?':
            continue
        elif S_d[i + j] != t:
            flag = False
            break

    if flag: # found substring
        S = S_d.replace('?', 'a')
        S_cand = S[:i] + T + S[i + len(S_d):]
        cands.append(S_cand)

if len(cands) > 0:
    print(min(cands))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

S_cand = None
for i in range(len(S_d) - len(T) + 1):
    flag = True
    for j, t in enumerate(T):
        if S_d[i + j] == '?':
            continue
        elif S_d[i + j] != t:
            flag = False
            break

    if flag: # found substring
        S = S_d.replace('?', 'a')
        S = S[:i] + T + S[i + len(S_d):]
        S_cand = S

if S_cand:
    print(S_cand)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
memo = []

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

Submission status: Wrong Answer

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

for i in range(len(s)-len(t)+1):
    p = s[i:(i+len(t))]
    flag = True
    for j in range(len(t)):
        if p[j] != "?" and p[j] != t[j]:
            flag = False
            break
    if flag:
        memo = s[0:i]+t+s[(i+len(t)):len(s)]
        break

if len(memo) == 0:
    print("UNRESTORABLE")
else:
    print(memo.replace("?","a"))

Submission status: Wrong Answer

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

ans = []
for i in range(len(s)-(len(t)-1)):
    f = True
    for j in range(len(t)):
        if s[j+i] != t[j] and s[j+i] != '?':
            f = False
    if f == True:
        s = s[:i] + t + s[i+len(t):]
        s = s.replace('?','a')
        ans.append(s)



if len(ans) > 0:
    print(min(ans))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

ans = []
for i in range(len(s)-(len(t)-1)):
    f = True
    for j in range(len(t)):
        if s[j+i] != t[j] and s[j+i] != '?':
            f = False
    if f == True:
        s = s[:i] + t + s[i+len(t):]
        s = s.replace('?','a')
        ans.append(s)



if len(ans) > 0:
    print(sorted(ans)[0])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

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

if f == False:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
for i in range(len(S)-len(T),-1,-1):
  a=0
  for j in range(len(T)):
    if S[i+j]=="?":
      continue
    if S[i+j]!=T[j]:
      a=1
      break
  if a==0:
    for j in range(i):
      if S[j]=="?":
        print("a",end="")
      else:
        print(S[j],end="")
    print(T,end="")
    for j in range(i+len(T)+1,len(S)):
      if S[j]=="?":
        print("a",end="")
      else:
        print(S[j],end="")
    exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys

s = input()
t = input()

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

Submission status: Wrong Answer

Solution code:
import sys

s = input()
t = input()

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

Submission status: Wrong Answer

Solution code:
import re
import sys

s = input().replace('?','.')
t = input()

sLen=len(s)
tLen=len(t)

for i in range(sLen-tLen+1):
  sub = s[sLen-tLen-i:sLen-i]
  #macthするかテスト
  pattern = re.compile(r"%s"%sub)
  if pattern.search(t):
    s=s[:sLen-tLen-i]+t+s[sLen-i:]
    s=s.replace('.','a')
    print(s)
    sys.exit()
print('UNRESTORERABLE')

Submission status: Wrong Answer

Solution code:
s,y=(input() for i in range(2))
ans="{"*len(s);pa=ans
for i in range(len(s)-len(y)):
  for j in range(len(y)):
    if s[i+j]!='?' and s[i+j]!=y[j]:break
  else:ans=min(ans,s[:i].replace("?","a")+y+s[i+len(y):].replace("?","a"))
if pa==ans:print("UNRESTORABLE")
  
else:print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
s2 = s.replace('?', 'a')

ans = 'z' * 99
for i in range(len(s) - len(t)+1):
    u = s2[0:i] + t + s2[i + len(t):]

    ok = True
    for x, y in zip(s2, t):
        if x != y:
            ok = False
            break
    if ok:
        ans = min(ans, u)

if ans == 'z' * 99:
    ans = 'UNRESTORABLE'

print(ans)

Submission status: Wrong Answer

Solution code:
import re
import sys

s = input()
t = input()

tLen = len(t)

"""
sの中の?を.に置換する
"""
s = s.replace("?",".")
sLen = len(s)
for i in range(tLen,sLen+1):
  #[-i:(-i+tLen)]の区間の文字列が、tにマッチするかを調べる。マッチするなら置換する。
  test = s[sLen-i:sLen-i+tLen] 
  pattern = re.compile(r"%s" % test)
  if pattern.search(t):
    s = s[:sLen-i]+t+s[sLen-i+tLen+1:]
    s = s.replace(".","a")
    print(s)
    sys.exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

S = input().strip()
T = input().strip()
#-----
S=S[::-1]
T=T[::-1]

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 += (j+1)
    
    else:
        ans += S[i]
        i += 1
    
ans=ans[::-1]

if flag:
    ans = ans.replace('?','a')
    print(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 += (j+1)
    
    else:
        ans += S[i]
        i += 1
    

if flag:
    ans = ans.replace('?','a')
    print(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] 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 += (j+1)
    
    else:
        ans += S[i]
        i += 1
    

if flag:
    ans = ans.replace('?','a')
    print(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] 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:
                break
        
        else:
            ans += T
            flag = True
            i += (j+1)
    
    else:
        ans += S[i]
        i += 1
    

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

else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
flag1 = 0
tmp = ""
for i in range(len(s) - len(t) + 1):
    u = s[i:i + len(t)]
    flag2 = 1
    for j in range(len(t)):
        if u[j] != t[j] and u[j] != "?":
            flag2 = 0
            break
    if flag2 == 1:
        flag1 = 1
        tmp = s[:i] + t
        break

print(tmp.replace("?", "a")) if flag1 else print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
SA = S.replace("?", "a")
T = input()


def test(i):
  S_sub = S[i: i + len(T)]
  for s, t in zip(S_sub, T):
    if s == "?":
      continue
    if s != t:
      return False
    return True

pw = []
for i in range(len(S) - len(T) + 1):
  if test(i):
    x = SA[:i] + T + SA[i + len(T) :]
    pw.append(x)

if pw:
  ans = sorted(pw)[0]
else:
  ans = "UNRESTORABLE"
print(ans)

Submission status: Wrong Answer

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

import fnmatch

if set(s) == {'?'} and set(t) =={'?'}:
    print('UNRESTORABLE')
else:
    for  i in range(len(s) - len(t)+1):
        if fnmatch.fnmatch(t, s[i:i+len(t)]):
            x = s[0:i] + t + s[i+len(t):]
            print(x.replace('?', 'a'))
            break
    else:
        print('UNRESTORABLE')

Submission status: Wrong Answer

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

import fnmatch

if set(s) == {'?'}:
    print('UNRESTORABLE')
else:
    for  i in range(len(s) - len(t)+1):
        if fnmatch.fnmatch(t, s[i:i+len(t)]):
            x = s[0:i] + t + s[i+len(t):]
            print(x.replace('?', 'a'))
            break
    else:
        print('UNRESTORABLE')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

import fnmatch
for  i in range(len(s) - len(t)+1):
    if fnmatch.fnmatch(t, s[i:i+len(t)]):
        x = s[0:i] + t + s[i+len(t):]
        x = x.replace('?', 'a')
        print(x.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
pre_S = S
T = input()
s = len(S)
t = len(T)
key = []
for i in range(len(S)-len(T)+1):
    # print(S[i:i+t])
    same = 0
    for j, y in enumerate(S[i:i+t]):
        if y == "?":
            same += 1
            continue
        else:
            if y == T[j]:
                same += 1
    if same == t:
        # print(S[i:i+t])
        key.append(i)
    # print(y)
# l = list(S)
if key:
    ans = "z" * 60
    for i in key:
        S = S[:i] + T + S[i+t:]
        tmp = ""
        for i in range(len(S)):
            if S[i] == "?":
                tmp += "a"
            else:
                tmp += S[i]
        ans = min(ans, tmp)
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
pre_S = S
T = input()
s = len(S)
t = len(T)
key = []
for i in range(len(S)-len(T)+1):
    # print(S[i:i+t])
    same = 0
    for j, y in enumerate(S[i:i+t]):
        if y == "?":
            same += 1
            continue
        else:
            if y == T[j]:
                same += 1
    if same == t:
        # print(S[i:i+t])
        key.append(i)
    # print(y)
# l = list(S)
for i in key:
    S = S[:i] + T + S[i+t:]
if S != pre_S:
    ans = ""
    for i in range(len(S)):
        if S[i] == "?":
            ans += "a"
        else:
            ans += S[i]
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
t = STR()
ans = []
i = len(s) - len(t)
flag2 = True
while i >= 0:
    if flag2:
        ans.append(list(deepcopy(s)))
    flag2 = False
    flag = True
    for j in range(len(t)):
        if s[i + j] != '?' and s[i + j] != t[j]:
            flag = False
    if flag:
        ans[len(ans) - 1][i:i + len(t)] = list(t)
        flag2 =True
    i -= 1
i = 0
while i < len(ans):
    if ''.join(ans[i]) == s:
        del ans[i]
    else:
        i += 1
if len(ans) == 0:
    print('UNRESTORABLE')
    exit()
for i in range(len(ans)):
    for j in range(len(ans[i])):
        if ans[i][j] == '?':
            ans[i][j] = 'a'
ans.sort()
print(''.join(ans[0]))

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
pre_S = S
T = input()
s = len(S)
t = len(T)
key = []
for i in range(len(S)-len(T)+1):
    # print(S[i:i+t])
    same = 0
    for j, y in enumerate(S[i:i+t]):
        if y == "?":
            same += 1
            continue
        else:
            if y == T[j]:
                same += 1
    if same == t:
        # print(S[i:i+t])
        key.append(i)
    # print(y)
# l = list(S)
for i in key:
    S = S[:i] + T + S[i+t:]
if S != pre_S:
    print(S)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
# zentansaku
S = input()
T = input()
Ns = len(S)
Nt = len(T)

cand = []

N = max(0, Ns - Nt + 1)
for i in range(N):
    for j in range(Nt):
        s = S[i + j]
        t = T[j]
        if s == t or s == "?":
            continue
        else:
            break
    else:
        pre = S[:i].replace("?", "a")
        cand.append(pre + T)

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

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
t = STR()
ans = list(deepcopy(s))
i = len(s) - len(t)
while i >= 0:
    flag = True
    for j in range(len(t)):
        if s[i + j] != '?' and s[i + j] != t[j]:
            flag = False
    if flag:
        ans[i:i + len(t)] = list(t)
        break
    i -= 1

if ''.join(ans) == s:
    print('UNRESTORABLE')
    exit()
for i in range(len(ans)):
    if ans[i] == '?':
        ans[i] = 'a'
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
t = STR()
ans = list(deepcopy(s))
i = len(s) - len(t)
if i < 0:
    print('UNRESTORABLE')
    exit()
while i > 0:
    flag = True
    for j in range(len(t)):
        if s[i + j] != '?' and s[i + j] != t[j]:
            flag = False
    if flag:
        ans[i:i + len(t)] = list(t)
        break
    i -= 1

if ''.join(ans) == s:
    print('UNRESTORABLE')
    exit()
for i in range(len(ans)):
    if ans[i] == '?':
        ans[i] = 'a'
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
t = STR()
ans = list(deepcopy(s))
i = len(s) - len(t)
while i > 0:
    flag = True
    for j in range(len(t)):
        if s[i + j] == '?' or s[i + j] == t[j]:
            continue
        else:
            flag = False
    if flag:
        ans[i:i + len(t)] = list(t)
        break
    else:
        i -= 1

if ''.join(ans) == s:
    print('UNRESTORABLE')
    exit()
for i in range(len(ans)):
    if ans[i] == '?':
        ans[i] = 'a'
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
t = STR()
ans = list(deepcopy(s))
i = len(s) - len(t)
while i > 0:
    flag = True
    for j in range(len(t)):
        if s[i + j] == '?' or s[i + j] == t[j]:
            continue
        else:
            flag = False
    if flag:
        ans[i:i + len(t)] = list(t)
        i -= len(t)
    else:
        i -= 1

if ''.join(ans) == s:
    print('UNRESTORABLE')
    exit()
for i in range(len(ans)):
    if ans[i] == '?':
        ans[i] = 'a'
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7

s = STR()
t = STR()
ans = list(deepcopy(s))
for i in range(len(s) - len(t) + 1):
    flag = True
    for j in range(len(t)):
        if s[i + j] == '?' or s[i + j] == t[j]:
            continue
        else:
            flag = False
    if flag:
        ans[i:i + len(t)] = list(t)
if ''.join(ans) == s:
    print('UNRESTORABLE')
    exit()
for i in range(len(ans)):
    if ans[i] == '?':
        ans[i] = 'a'
print(''.join(ans))