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()
ans=[]
s2=''
for i in range(len(s)):
  store=s2
  if s[i]=='?' or s[i]==t[0]:
    s2+=t[0]
    for j in range(1,len(t)):
      if i+j>len(s)-1:
        break
      if s[i+j]!='?' and s[i+j]!=t[j]:
        break
      else:
        s2+=t[j]
      if j==len(t)-1:
        for k in range(len(s)-len(t)-i):
          if s[k]=='?':
            s2+='a'
          else:
            s2+=s[k]
        ans.append(s2)
  s2=store
  if s[i]=='?':
    s2+='a'
  else:
    s2+=s[i]
if len(ans)>0:
  ans=sorted(ans)
  print(ans[0])
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys

S = list(input())
T = list(input())

length = len(T)
position = len(S) - length

while position >= 0:
    text = S[position:position+length]
    print(text)
    for i in range(length):
        if text[i] == "?":
            text[i] = T[i]
    if text != T:
        position -= 1
    else:
        S[position:position+length] = T
        position = -10

if position != -10:
    print("UNRESTORABLE")
    sys.exit()

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

print("".join(S))

Submission status: Wrong Answer

Solution code:
import sys

S = list(input())
T = list(input())

length = len(T)

position = len(S) - length

while position > 0:
    text = S[position:position+length]
    for i in range(length):
        if text[i] == "?":
            text[i] = T[i]
    if text != T:
        position -= 1
    else:
        S[position:position+length] = T
        position = -1

if position != -1:
    print("UNRESTORABLE")
    sys.exit()

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

print("".join(S))

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
a = []
b = []
for i in range(len(s)):
    a.append(s[i])
for i in range(len(t)):
    b.append(t[i])
if len(t) <= len(s):
    for i in range(len(s)-(len(t)-1)):
        count = 0
        for j in range(len(t)):
            if s[i+j] == "?":
                count += 1
            elif s[i+j] == t[j]:
                count += 1
            else:
                break
        if count == len(t):
            for k in range(len(t)):
                a[i+k] = b[k]
            for i in range(len(s)):
                if a[i] == "?":
                    print("a",end="")
                else:
                    print(a[i],end="")
            print()
            exit()
    print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
a = []
b = []
for i in range(len(s)):
    a.append(s[i])
for i in range(len(t)):
    b.append(t[i])
if len(t) < len(s):
    for i in range(len(s)-(len(t)-1)):
        count = 0
        for j in range(len(t)):
            if s[i+j] == "?":
                count += 1
            elif s[i+j] == t[j]:
                count += 1
            else:
                count += 0
        if count == len(t):
            for k in range(len(t)):
                a[i+k] = b[k]
            for i in range(len(s)):
                if a[i] == "?":
                    print("a",end="")
                else:
                    print(a[i],end="")
            print()
            exit()
    print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
lt=len(t)
ls=len(s)

#例外処理
if lt>ls:
    print("UNRESTORABLE")
else:
    # 後ろから見ていってｔを入れれそうならflagを立てる
    # t入れれたら残りの?を全部aに変えてしまえばいい
    ans=[]
    for i in range(ls-1, ls-lt-2,-1):
        flag=True
        for j in range(lt):
            if s[i-j]!="?" and s[i-j]!=t[-j-1]:
                flag=False
                break                
        if flag: # countがtの長さになってたらtぶち込めるてこと
            tmp=s[:i-lt+1]+t+s[i+1:]
            tmp=tmp.replace("?", "a")
            ans.append(tmp)
            
      
    if ans:
        an=sorted(ans)
        print(an[0])
       
    else:
        print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
lt=len(t)
ls=len(s)

#例外処理
if lt>ls:
    print("UNRESTORABLE")
else:
    # 後ろから見ていってｔを入れれそうならflagを立てる
    # t入れれたら残りの?を全部aに変えてしまえばいい
    ans=[]
    for i in range(ls-1, ls-lt-2,-1):
        flag=True
        for j in range(lt):
            if s[i-j]!="?" and s[i-j]!=t[-j-1]:
                flag=False
                break                
        if flag: # countがtの長さになってたらtぶち込めるてこと
            tmp=s[:i-lt+1]+t+s[i+1:]
            tmp=tmp.replace("?", "a")
            ans.append(tmp)
            
      
    if ans==[]:
        print("UNRESTORABLE")
    else:
        an=sorted(ans)
        print(an[0])

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
lt=len(t)
ls=len(s)

#例外処理
if lt>ls:
    print("UNRESTORABLE")
else:
    # 後ろから見ていってｔを入れれそうならflagを立てる
    # t入れれたら残りの?を全部aに変えてしまえばいい
    ans=[]
    for i in range(ls-1, ls-lt-2,-1):
        count=0
        for j in range(lt):
            if s[i-j]!="?" and s[i-j]!=t[-j-1]:
                break
            else:
                count+=1 # クリアしたらカウントする
                
        if count==lt: # countがtの長さになってたらtぶち込めるてこと
            tmp=s[:i-lt+1]+t+s[i+1:]
            tmp=tmp.replace("?", "a")
            ans.append(tmp)
            
      
    if ans==[]:
        print("UNRESTORABLE")
    else:
        an=sorted(ans)
        print(an[0])

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
lt=len(t)
ls=len(s)

#例外処理
if lt>ls:
    print("UNRESTORABLE")
else:
    # 後ろから見ていってｔを入れれそうならflagを立てる
    # t入れれたら残りの?を全部aに変えてしまえばいい
    ans=[]
    for i in range(ls-1, ls-lt-2,-1):
        count=0
        for j in range(lt):
            if s[i-j]!="?" and s[i-j]!=t[-j-1]:
                break
            else:
                count+=1 # クリアしたらカウントする
                
        if count==lt: # countがtの長さになってたらtぶち込めるてこと
            tmp=s[:i-lt+1]+t+s[i+1:]
            tmp=tmp.replace("?", "a")
            ans.append(tmp)
            
      
    if ans==[]:
        print("UNRESTORABLE")
    else:
        ans.sort()
        print(ans[0])

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
lt=len(t)
ls=len(s)

#例外処理
if lt>ls:
    print("UNRESTORABLE")
else:
    # 後ろから見ていってｔを入れれそうならflagを立てる
    # t入れれたら残りの?を全部aに変えてしまえばいい
    flag=0
    for i in range(ls-1, ls-lt-2,-1):
        count=0
        for j in range(lt):
            if s[i-j]!="?" and s[i-j]!=t[-j-1]:
                break
            else:
                count+=1 # クリアしたらカウントする
                
        if count==lt: # countがtの長さになってたらtぶち込めるてこと
            flag=1
            matubi=i # どこにtを挿入するかの目印
            break
      
    if flag==0:
        print("UNRESTORABLE")
    else:
        S=s[:matubi-lt+1]+t+s[matubi+1:]
        S=S.replace("?", "a")
        print(S)

Submission status: Wrong Answer

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

ans = [""] * len(S)
start= -1
flag = True

for i in range(len(S) - len(T) + 1):
    flag = True
    for i2 in range(len(T)):
        if S[i + i2] != T[i2] and S[i + i2] != "?":
            flag = False
            break
    if flag:
        start = i
        break
if start != -1:
    for i in range(len(T)):
        ans[i + start] = T[i]
    for i in range(len(S)):
        if ans[i] == "":
            if S[i] == "?":
                ans[i] = "a"
            else:
                ans[i] = S[i]
    print("".join(ans))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
lt=len(t)
ls=len(s)

#例外処理
if lt>ls:
    print("UNRESTORABLE")
else:
    # 後ろから見ていってｔを入れれそうならflagを立てる
    # t入れれたら残りの?を全部aに変えてしまえばいい
    flag=0
    for i in range(ls-1, ls-lt-2,-1):
        count=0
        for j in range(lt):
            if s[i-j]!="?" and s[i-j]!=t[-j-1]:
                print(i,j,s[i-j],t[-j-1])
                break
            else:
                count+=1 # クリアしたらカウントする
                
        if count==lt: # countがtの長さになってたらtぶち込めるてこと
            flag=1
            matubi=i # どこにtを挿入するかの目印
            break
      
    if flag==0:
        print("UNRESTORABLE")
    else:
        S=s[:matubi-lt+1]+t+s[matubi+1:]
        S=S.replace("?", "a")
        print(S)

Submission status: Wrong Answer

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

ans = [""] * len(S)
start= 10000
flag = True

for i in range(len(S) - len(T) + 1):
    flag = True
    for i2 in range(len(T)):
        if S[i + i2] != T[i2] and S[i + i2] != "?":
            flag = False
            break
    if flag:
        start = i
        break
if start != 10000:
    for i in range(len(T)):
        ans[i + start] = T[i]
    for i in range(len(S)):
        if ans[i] == "":
            if S[i] == "?":
                ans[i] = "a"
            else:
                ans[i] = S[i]
    print("".join(ans))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s_dash_rev = input()[::-1]
t_rev = input()[::-1]
s_length = len(s_dash_rev)
t_length = len(t_rev)
if t_length > s_length:
    print('UNRESTORABLE')
    exit(0)
matched = False
for begin_index in range(s_length - t_length):
    end_index = begin_index + t_length
    part_s_dash_rev = s_dash_rev[begin_index:end_index]
    part_matched = True
    for i in range(t_length):
        if part_s_dash_rev[i] != '?' and part_s_dash_rev[i] != t_rev[i]:
            part_matched = False
            break
    if part_matched:
        # replace by `T`
        matched = True
        s_rev = s_dash_rev[:begin_index] + t_rev + s_dash_rev[end_index:]
        break
if not matched:
    print('UNRESTORABLE')
else:
    s = s_rev[::-1]
    print(s.replace('?', 'a'))

Submission status: Wrong Answer

Solution code:
# matching T from end, and fill `a` in the rest `?`
s_dash_rev = input()[::-1]
t_rev = input()[::-1]
s_length = len(s_dash_rev)
t_length = len(t_rev)
matched = False
for begin_index in range(s_length - t_length):
    end_index = begin_index + t_length
    part_s_dash_rev = s_dash_rev[begin_index:end_index]
    part_matched = True
    for i in range(t_length):
        if part_s_dash_rev[i] != '?' and part_s_dash_rev[i] != t_rev[i]:
            part_matched = False
            break
    if part_matched:
        # replace by `T`
        matched = True
        s_rev = s_dash_rev[:begin_index] + t_rev + s_dash_rev[end_index:]
        break
if not matched:
    print('UNRESTORABLE')
else:
    s = s_rev[::-1]
    print(s.replace('?', 'a'))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
ns=len(s)
nt=len(t)
ans=''
for i in range(ns-nt,0,-1):
      flg=True
      for j in range(nt):
            if s[i+j]!='?' and s[i+j]!=t[j]:
                  flg=False
      if flg:
            ans=s[:i]+t+s[i+nt:]
            ans=ans.replace('?','a')
            break

print(ans if ans!='' else 'UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s1 = input()
t = input()
n = len(s1)
m = len(t)

def check(i):
    for j in range(m):
        if not (s1[i+j] == t[j] or s1[i+j] == "?"):
            return False
    return True
            
def run():
    ans = 0
    i = 0
    for s in range(n-m):
        if s1[s] == t[0] or s1[s] == '?':
            if check(i):
                ans = max(ans,i)
                return ans
        i += 1
    return -1
i = run()
if i == -1:
    print("UNRESTORABLE");exit()
li = []
for j in range(n):
    if i==j:
        li += t
    elif i<=j<(i+m):
        continue
    elif s1[j] == "?":
        li.append("a")
    else:
        li.append(s1[j])

print("".join(li))

Submission status: Wrong Answer

Solution code:
s1 = input()
t = input()
n = len(s1)
m = len(t)

def check(i):
    for j in range(m):
        if not (s1[i+j] == t[j] or s1[i+j] == "?"):
            return False
    return True
            
def run():
    i = 0
    for s in range(n-m):
        if s1[s] == t[0] or s1[s] == '?':
            if check(i):
                return i
        i += 1
    return -1
i = run()
if i == -1:
    print("UNRESTORABLE");exit()
li = []
for j in range(n):
    if i==j:
        li += t
    elif i<=j<(i+m):
        continue
    elif s1[j] == "?":
        li.append("a")
    else:
        li.append(s1[j])

print("".join(li))

Submission status: Wrong Answer

Solution code:
A = list(input())
C = list(input())
ans = 0
D = A
for i in range(len(A)):
    if A[i] in C:
        C_index = C.index(A[i])
        # if C_index == 0:
        #     if len(C) - 1 <= len(A) - 1 - i:
        #         # print(A[i+1:i+len(C)])
        #         if len(set(A[i+1:i+len(C)])) == 1 and A[0] == "?":
        #             ans = 1
        #             for j in range(len(C)):
        #                 D[i + j] = C[j]
        # else:
        # print(A[i-C_index:i-C_index+len(C)])
        ok = 0
        for j, k in zip(A[i-C_index:i-C_index+len(C)], C):
            if j == "?" or j == k:
                continue
            else:
                ok = 1
                break
        if ok == 0:
            ans = 1
            start = 0
            for j, k in zip(A[i-C_index:i-C_index+len(C)], C):
                D[i-C_index + start] = k
                start += 1
            # print(D)


if ans == 0:
    print("UNRESTORABLE")
else:
    E = []
    for i in D:
        if i == "?":
            E.append("a")
        else:
            E.append(i)
    print("".join(E))

Submission status: Wrong Answer

Solution code:
A = list(input())
C = list(input())
ans = 0
D = A
for i in range(len(A)):
    if A[i] in C:
        C_index = C.index(A[i])
        if C_index == 0:
            if len(C) - 1 <= len(A) - 1 - i:
                # print(A[i+1:i+len(C)])
                if len(set(A[i+1:i+len(C)])) == 1 and A[0] == "?":
                    ans = 1
                    for j in range(len(C)):
                        D[i + j] = C[j]


if ans == 0:
    print("UNRESTORABLE")
else:
    E = []
    for i in D:
        if i == "?":
            E.append("a")
        else:
            E.append(i)
    print("".join(E))

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
t_len = len(t)
s_len = len(s)
ans = []
for i in range(s_len-t_len+1):
    count = 0
    for j in range(t_len):
        if s[i+j]=='?' or s[i+j]==t[j]:
            count += 1
            if count == t_len:
                for k in range(i):
                    if s[k] == '?':
                        ans.append('a')
                    else:
                        ans.append(s[k])
                for k in range(s_len-(t_len+i)):
                    if s[i+t_len+k] =='?':
                        ans.append('a')
                    else:
                        ans.append(s[i+t_len+k])
                for k in range(t_len):
                    ans.append(t[k])
                print(*ans, sep='')
                exit(0)
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
t_len = len(t)
s_len = len(s)
ans = []
for i in range(s_len-t_len+1):
    count = 0
    for j in range(t_len):
        if s[i+j]=='?' or s[i+j]==t[j]:
            count += 1
            if count == t_len:
                for k in range(i):
                    if s[k] == '?':
                        ans.append('a')
                    else:
                        ans.append(s[k])
                for k in range(t_len):
                    ans.append(t[k])
                for k in range(s_len-(t_len+i)):
                    if s[i+t_len+k] =='?':
                        ans.append('a')
                    else:
                        ans.append(s[i+t_len+k])
                print(*ans, sep='')
                exit(0)
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
t_len = len(t)
s_len = len(s)
ans = []
for i in range(s_len-t_len+1):
    count = 0
    for j in range(t_len):
        if s[i+j]=='?' or s[i+j]==t[j]:
            count += 1
            print(count, i, j)
            if count == t_len:
                for k in range(i):
                    if s[k] == '?':
                        ans.append('a')
                    else:
                        ans.append(s[k])
                for k in range(t_len):
                    ans.append(t[k])
                for k in range(s_len-(t_len+i)):
                    if s[i+t_len+k] =='?':
                        ans.append('a')
                    else:
                        ans.append(s[i+t_len+k])
                print(*ans, sep='')
                exit(0)
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
tlen = len(t)
anslist = []
n = len(s)
'''
当てはまる文字列を全列挙してソート
'''
def mojiretu(a):
    global anslist
    a = list(a)
    for i in range(len(a)):
        if a[i] == '?':
            a[i] = 'a'
    anslist.append(''.join(a))

def hantei(ss):
    for i in range(len(ss)):
        if ss[i] != t[i] and ss[i] != '?':
            return False
    else:return True

for i in range(n+1-tlen):
    if s[i] == t[0] or s[i] == '?':
        if hantei(s[i:i+tlen]):
            mojiretu(s[:i] + t + s[i+tlen:])
if anslist:
    print(anslist[0])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
def resolve():
    ss = input()
    t = input()

    ans = 'UNRESTORABLE'
    for i in range(len(ss) - len(t) + 1):
        flg = True
        for j in range(len(t)):
            if ss[i + j] != t[j] and ss[i + j] != '?':
                flg = False
                break

        if flg:
            ans = ss[:i] + t + ss[i + len(t):]
            ans = ans.replace('?', 'a')
            break

    print(ans)

resolve()

Submission status: Wrong Answer

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

startpoint=51
for i in range(len(sd)-len(t)+1):
	okflag = True
	for j in range(len(t)):
		if sd[i+j] == "?" or sd[i+j] == t[j]:
			continue
		else:
			okflag = False
		
	if okflag:
		startpoint=i

if startpoint == 51:
	print("UNRESTORABLE")
else:
    sd=sd.replace("?","a")
    s=sd[:i-1] + t + sd[i-1+len(t):]
    print(s)

Submission status: Wrong Answer

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

startpoint=51
for i in range(len(sd)-len(t)+1):
	okflag = True
	for j in range(len(t)):
		if sd[i+j] == "?" or sd[i+j] == t[j]:
			continue
		else:
			okflag = False
		
	if okflag:
		startpoint=i

if startpoint == 51:
	print("UNRESTORABLE")
else:
	sd=sd.replace("?","a")
	s=sd[:i] + t + sd[i+len(t):]
	print(s)

Submission status: Wrong Answer

Solution code:
import re

S_ = input().replace('?', '.')
T = input()
flag = True
for i in range(len(S_)-len(T), -1, -1):
    angou = re.compile(S_[i:i+len(T)])
    mo = angou.search(T)
    if mo != None:
        S_ = S_[:i] + mo.group() + S_[i+len(T) + 1:]
        flag = False
        break
S = S_.replace('.', 'a')

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

Submission status: Wrong Answer

Solution code:
import re

S_ = input().replace('?', '.')
T = input()
flag = True
for i in range(len(S_)-len(T), 0, -1):
    angou = re.compile(S_[i:i+len(T)])
    mo = angou.search(T)
    if mo != None:
        S_ = S_[:i] + mo.group() + S_[i+len(T) + 1:]
        flag = False
        break
S = S_.replace('.', 'a')

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

Submission status: Wrong Answer

Solution code:
import re

S_ = input().replace('?', '.')
T = input()
flag = True
for i in range(len(S_)-len(T), 0, -1):
    angou = re.compile(S_[i:i+len(T)])
    mo = angou.search(T)
    if mo != None:
        S_ = S_[:i] + mo.group() + S_[i+len(T) + 1:]
        flag = False
S = S_.replace('.', 'a')

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

Submission status: Wrong Answer

Solution code:
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

S = input()
T = input()
sl = len(S)
tl = len(T)

def f(idx):
    if idx + tl > sl:
        return False
    for i in range(tl):
        if S[idx + i] != '?' and S[idx + i] != T[i]:
            return False

    ret = []
    for s in S[0:idx]:
        ret.append(s if s != '?' else 'a')

    return "".join(ret) + T

def solve():
    for i in range(sl, -1, -1):
        if f(i):
            print(f(i))
            return

    print("UNRESTORABLE")

solve()

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc076/tasks/abc076_c
import numpy as np


S_ = np.array(list(input()))
T  = np.array(list(input()))
ans = np.empty(0)


# 文字列Sが存在するかを確かめる
for i in range(len(S_) - len(T)+1):
    for j in range(len(T)):
        if S_[i+j] == '?' or S_[i+j] == T[j]:
            if j == len(T)-1:
                # 文字列Sが存在することが確定
                S = np.concatenate([S_[:i],T],0) # Tと結合させる
                S = ''.join(map(str,S))
                ans = np.append(ans,S.replace('?','a'))
            else:
                # S_の次の文字もTと一致しているかを調べる
                continue
        else:
            break

if len(ans) == 0:
    # 文字列Sが存在しない
    print('UNRESTORABLE')
else:
    # ans.sort()
    print(ans[-1])

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc076/tasks/abc076_c
import numpy as np
import sys

S_ = np.array(list(input()))
T  = np.array(list(input()))
ans = np.empty(0)

if len(S_) < len(T):
    print('UNRESTORABLE')
    sys.exit()

# 文字列Sが存在するかを確かめる
for i in range(len(S_) - len(T)+1):
    for j in range(len(T)):
        if S_[i+j] == '?' or S_[i+j] == T[j]:
            if j == len(T)-1:
                # 文字列Sが存在することが確定
                S = np.concatenate([S_[:i],T],0) # Tと結合させる
                S = ''.join(map(str,S))
                ans = np.append(ans,S.replace('?','a'))
            else:
                # S_の次の文字もTと一致しているかを調べる
                continue
        else:
            break

if len(ans) == 0:
    # 文字列Sが存在しない
    print('UNRESTORABLE')
else:
    ans.sort()
    print(ans[0])

Submission status: Wrong Answer

Solution code:
import re
word = input()
substring = input()
word = word.replace('?','.')
N = len(word) - len(substring)
found = False
for i in range(N+1):
    regexp = re.compile(word[i:i+len(substring)])
    if regexp.search(substring):
        found = True
        res = word[0:i] + substring + word[len(substring)+1:-1]
        print(res.replace('.','a'))
        break

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

Submission status: Wrong Answer

Solution code:
import re
word = input()
substring = input()
word = word.replace('?','.')
N = len(word) - len(substring)
found = False
for i in range(N+1):
    regexp = re.compile(word[i:i+len(substring)])
    if regexp.search(substring):
        found = True
        res = word[0:i] + substring
        print(res.replace('.','a'))

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

Submission status: Wrong Answer

Solution code:
import re
word = '?tc????'.replace('?','.')
substring = 'coder'
N = len(word) - len(substring)
found = False
for i in range(N+1):
    regexp = re.compile(word[i:i+len(substring)])
    if regexp.search(substring):
        found = True
        res = word[0:i] + substring
        print(res.replace('.','a'))

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

Submission status: Wrong Answer

Solution code:
import re
word = '?tc????'.replace('?','.')
substring = 'coder'
N = len(word) - len(substring)
for i in range(N+1):
    regexp = re.compile(word[i:i+len(substring)])
    if regexp.search(substring):
        print('matched')
        res = word[0:i] + substring
        print(res.replace('.','a'))

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s_prime=list(input())
t=list(input())
ls=len(s_prime)
lt=len(t)
s_prime.reverse()
t.reverse()


if lt>ls:
    print('UNRESTORABLE')
else:
    def check(t,s):
        l=len(t)
        c=0
        for i in range(l):
            if s[i]!='?' and s[i]!=t[i]:
                c=1
        return True if c==0 else False
    c=0            
    for i in range(ls-lt+1):
        if check(t,s_prime)==1:
            t_in=s_prime[:i]+t+s_prime[i+lt:] 
            for k in range(ls):
                if t_in[k]=='?':
                    t_in[k]='a'
            t_in.reverse()   
            print(''.join(t_in))
            c=1
            break
    print('UNRESTORABLE') if c==0 else exit()

Submission status: Wrong Answer

Solution code:
s_prime=list(input())
t=list(input())
ls=len(s_prime)
lt=len(t)
s_prime.reverse()
t.reverse()


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

    
def check(t,s):
    l=len(t)
    c=0
    for i in range(l):
        if s[i]!='?' and s[i]!=t[i]:
            c=1
    return True if c==0 else False
c=0            
for i in range(ls-lt+1):
    if check(t,s_prime)==1:
        t_in=s_prime[:i]+t+s_prime[i+lt:] 
        for k in range(ls):
            if t_in[k]=='?':
                t_in[k]='a'
        t_in.reverse()   
        print(''.join(t_in))
        c=1
        break
print('UNRESTORABLE') if c==0 else exit()

Submission status: Wrong Answer

Solution code:
import sys, copy

s = input()
t = input()


def match(k):
    for i in range(len(t)):
        if t[i] != s[i + k] and s[i + k] != "?":
            return False
    return True


def construct(k):
    ans = copy.deepcopy(list(s))
    for i in range(len(t)):
        ans[k + i] = t[i]
    for i in range(len(s)):
        if ans[i] == "?":
            ans[i] = "a"
    return "".join(ans)


K = len(s) - len(t) + 1

for i in range(K):
    if match(i):
        print(construct(i))
        sys.exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys

s = input()
t = input()


def match(k):
    for i in range(len(t)):
        if t[i] != s[i + k] and s[i + k] != "?":
            return False
    return True


def construct(k):
    ans = list(s)[:]
    for i in range(len(t)):
        ans[k + i] = t[i]
    for i in range(len(s)):
        if ans[i] == "?":
            ans[i] = "a"
    return "".join(ans)


K = len(s) - len(t) + 1

for i in range(K):
    if match(i):
        print(construct(i))
        sys.exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys

s = input()
t = input()


def match(k):
    for i in range(len(t)):
        if t[i] != s[i + k] and s[i + k] != "?":
            return False
    return True


def construct(k):
    ans = list(s)
    for i in range(len(t)):
        ans[k + i] = t[i]
    for i in range(len(s)):
        if ans[i] == "?":
            ans[i] = "a"
    return "".join(ans)


K = len(s) - len(t) + 1

for i in range(K):
    if match(i):
        print(construct(i))
        sys.exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc076/tasks/abc076_c
import numpy as np

S_ = np.array(list(input()))
T  = np.array(list(input()))
ans = np.empty(0)
# 文字列Sが存在するかを確かめる
for i in range(len(S_) - len(T)+1):
    for j in range(len(T)):
        if S_[i+j] == '?' or S_[i+j] == T[j]:
            if j == len(T)-1:
                # 文字列Sが存在することが確定
                S = np.concatenate([S_[:i],T],0) # Tと結合させる
                S = ''.join(map(str,S))
                ans = np.append(ans,S.replace('?','a'))
            else:
                # S_の次の文字もTと一致しているかを調べる
                continue
        else:
            break

if len(ans) == 0:
    # 文字列Sが存在しない
    print('UNRESTORABLE')
else:
    ans.sort()
    print(ans[0])

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc076/tasks/abc076_c
import sys
import numpy as np

S_ = np.array(list(input()))
T  = np.array(list(input()))
ans = np.empty(0)
# 文字列Sが存在するかを確かめる
for i in reversed(range(len(S_) - len(T)+1)):
    for j in range(len(T)):
        if S_[i+j] == '?' or S_[i+j] == T[j]:
            if j == len(T)-1:
                # 文字列Sが存在することが確定
                S = np.concatenate([S_[:i],T],0) # Tと結合させる
                S = ''.join(map(str,S))
                ans = np.append(ans,S.replace('?','a'))
            else:
                # S_の次の文字もTと一致しているかを調べる
                continue
        else:
            break

if len(ans) == 0:
    # 文字列Sが存在しない
    print('UNRESTORABLE')
    sys.exit()
else:
    print(min(ans))

Submission status: Wrong Answer

Solution code:
# https://atcoder.jp/contests/abc076/tasks/abc076_c
import sys
import numpy as np

S_ = np.array(list(input()))
T  = np.array(list(input()))
ans = list()
# 文字列Sが存在するかを確かめる
for i in range(len(S_) - len(T)+1):
    for j in range(len(T)):
        if S_[i+j] == '?' or S_[i+j] == T[j]:
            if j == len(T)-1:
                # 文字列Sが存在することが確定
                S = np.concatenate([S_[:i],T],0) # Tと結合させる
                S = ''.join(map(str,S))
                # print(S.replace('?','a'))
                ans.append(S.replace('?','a'))
            else:
                # S_の次の文字もTと一致しているかを調べる
                continue
        else:
            break

if len(ans) == 0:
    # 文字列Sが存在しない
    print('UNRESTORABLE')
    sys.exit()
else:
    print(min(ans))

Submission status: Wrong Answer

Solution code:
import sys

S_ = list(input())
T  = list(input())

# 文字列Sが存在するかを確かめる
for i in range(len(S_) - len(T)+1):
    for j in range(len(T)):
        if S_[i+j] == '?' or S_[i+j] == T[j]:
            if j == len(T)-1:
                # 文字列Sが存在することが確定
                S = S_[:i] + T # Tと結合させる
                S = ''.join(map(str,S))
                print(S.replace('?','a'))
                sys.exit()
            else:
                # S_の次の文字もTと一致しているかを調べる
                continue
        else:
            break

# 文字列Sが存在しない
print('UNRESTORABLE')
sys.exit()