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:


def main():
        
    S_part = list(input())
    T_hint = list(input())
 
    N = len(S_part)
    ans = []

    for i in range(N):
        index_init = i
        
        if (index_init + len(T_hint) <= N):
            s = S_part[index_init:index_init + len(T_hint)]

            if ('?' in s):
                FLAG = True
                
                for j in range(len(s)):
                    if (T_hint[j] != s[j] and s[j] == '?'):
                        s[j] = T_hint[j]
                    
                    elif (T_hint[j] != s[j] and s[j] != '?'):
                        FLAG = False
                        break
                
                
                if (FLAG):
                    ans_left = ''.join(S_part[:index_init])
                    ans_right = ''.join(s)
                    
                    tmp_ans = ans_left + ans_right
                    tmp_ans = tmp_ans.replace('?', 'a')
                    

                    if (index_init + len(T_hint) < N):
                        module = S_part[index_init + len(T_hint):]
                        module = ''.join(module)
                        module = module.replace('?', 'a')
                        
                        tmp_ans += module


                    ans.append(tmp_ans)
 
    ans.sort()

    if (S_part.count('?') == 0):
        print(S_part)
    elif (len(ans) > 0):
        print(ans[0])
 
    else:
        print('UNRESTORABLE')
 
 
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

def main():
        
    S_part = list(input())
    T_hint = list(input())
 
    N = len(S_part)
    ans = []
 
    for i in range(N):
        index_init = i
            
        if (index_init + len(T_hint) <= N):
            s = S_part[index_init:index_init + len(T_hint)]
 
            if ('?' in s):
                FLAG = True
                
                for j in range(len(s)):
                    if (T_hint[j] != s[j] and s[j] == '?'):
                        s[j] = T_hint[j]
                    
                    elif (T_hint[j] != s[j] and s[j] != '?'):
                        FLAG = False
                        break
                
                
                if (FLAG):
                    ans_left = ''.join(S_part[:index_init])
                    ans_right = ''.join(s)
                    
                    tmp_ans = ans_left + ans_right
                    tmp_ans = tmp_ans.replace('?', 'a')
                    

                    if (index_init + len(T_hint) < N):
                        module = S_part[index_init + len(T_hint):]
                        module = ''.join(module)
                        tmp_ans += module


                    ans.append(tmp_ans)
 
    ans.sort()

    if (S_part.count('?') == 0):
        print(S_part)
    elif (len(ans) > 0):
        print(ans[0])
 
    else:
        print('UNRESTORABLE')
 
 
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:


def main():
        
    S_part = list(input())
    T_hint = list(input())
 
    N = len(S_part)
    ans = []
 
    for i in range(N):
        index_init = i
            
        if (index_init + len(T_hint) <= N):
            s = S_part[index_init:index_init + len(T_hint)]
 
            if ('?' in s):
                FLAG = True
                
                for j in range(len(s)):
                    if (T_hint[j] != s[j] and s[j] == '?'):
                        s[j] = T_hint[j]
                    
                    elif (T_hint[j] != s[j] and s[j] != '?'):
                        FLAG = False
                        break
                
                
                if (FLAG):
                    ans_left = ''.join(S_part[:index_init])
                    ans_right = ''.join(s)
                                        
                    tmp_ans = ans_left + ans_right
                    tmp_ans = tmp_ans.replace('?', 'a')
                    
                    ans.append(tmp_ans)
 
    ans.sort()

    if (S_part.count('?') == 0):
        print(S_part)
    elif (len(ans) > 0):
        print(ans[0])
 
    else:
        print('UNRESTORABLE')
 
 
 
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
        
    S_part = list(input())
    T_hint = list(input())

    N = len(S_part)
    ans = []

    for i in range(N):
        index_init = i
            
        if (index_init + len(T_hint) <= N):
            s = S_part[index_init:index_init + len(T_hint)]

            FLAG = True

            if ('?' not in s and s == T_hint):
                s = T_hint
            
            elif ('?' in s):
                
                for j in range(len(s)):
                    if (T_hint[j] != s[j] and s[j] == '?'):
                        s[j] = T_hint[j]
                    
                    elif (T_hint[j] != s[j] and s[j] != '?'):
                        FLAG = False
                        break
                
                
            if (FLAG):
                ans_left = ''.join(S_part[:index_init])
                ans_right = ''.join(s)
                                    
                tmp_ans = ans_left + ans_right
                tmp_ans = tmp_ans.replace('?', 'a')
                
                ans.append(tmp_ans)

    ans.sort()

    if (len(ans) > 0):
        print(ans[0])

    else:
        print('UNRESTORABLE')



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
        
    S_part = list(input())
    T_hint = list(input())

    N = len(S_part)
    ans = []

    for i in range(N):
        index_init = i
            
        if (index_init + len(T_hint) <= N):
            s = S_part[index_init:index_init + len(T_hint)]

            if ('?' in s):
                FLAG = True
                
                for j in range(len(s)):
                    if (T_hint[j] != s[j] and s[j] == '?'):
                        s[j] = T_hint[j]
                    
                    elif (T_hint[j] != s[j] and s[j] != '?'):
                        FLAG = False
                        break
                
                
                if (FLAG):
                    ans_left = ''.join(S_part[:index_init])
                    ans_right = ''.join(s)
                                        
                    tmp_ans = ans_left + ans_right
                    tmp_ans = tmp_ans.replace('?', 'a')
                    
                    ans.append(tmp_ans)

    ans.sort()

    if (len(ans) > 0):
        print(ans[0])

    else:
        print('UNRESTORABLE')



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
        
    S_part = list(input())
    T_hint = list(input())

    N = len(S_part)
    ans = []

    for i in range(N):
        index_init = i
            
        if (index_init + len(T_hint) <= N):
            s = S_part[index_init:index_init + len(T_hint)]

            if ('?' in s):
                FLAG = True
                
                for j in range(len(s)):
                    if (T_hint[j] != s[j] and s[j] == '?'):
                        s[j] = T_hint[j]
                    
                    elif (T_hint[j] != s[j] and s[j] != '?'):
                        FLAG = False
                        break
                
                
                if (FLAG):
                    tmp_ans = ''.join(s)
                    tmp_ans = tmp_ans.replace('?', 'a')
                    
                    ans.append(tmp_ans)

    ans.sort()

    if (len(ans) > 0):
        print(ans[0])

    else:
        print('UNRESTORABLE')



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

ok=0
idx=-1
for i in range(len(S)): 
  count=0
  if i>len(S)-len(T):
    break
  for j in range(len(T)):
    if S[i+j] == T[j] or S[i+j] == '?':
      count += 1
    else:
      break
  if count == len(T):
    ok=1
    idx=i
    break
      
if not ok:
  print('UNRESTORABLE')
  exit()
  
ans=[]
for i in range(len(S)):
  if i in range(idx,idx+count):
    ans.append(T[i-idx])
  else:
    if S[i]=='?':
      ans.append('a')
    else:
      ans.append(S[i])
      
print(''.join(ans))

Submission status: Wrong Answer

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

count=0
idx=0
ok=0
for i in range(len(S)):
  if S[i]==T[count] or S[i] == '?':
    count += 1
  else:
    count = 0
  if count == len(T):
    idx = i-count+1
    ok=1
    break
    
if not ok:
  print('UNRESTORABLE')
  exit()

ans=[]
for i in range(len(S)):
  if i in range(idx,idx+count):
    ans.append(T[i-idx])
  else:
    if S[i]=='?':
      ans.append('a')
    else:
      ans.append(S[i])
      
print(''.join(ans))

Submission status: Wrong Answer

Solution code:
s, t = raw_input(), raw_input()
def f(a,b):
	if len(a) != len(b): return False

	for u,v in zip(a,b):
		if u != v and u != '?':
			return False
	return True
cand = -1
for i in range(len(s)):
	if f(s[i:i + len(t)],t):
		cand = i

if cand == -1:
	print 'UNRESTORABLE'
else:
	print s[:cand].replace('?', 'a') + t + s[cand+len(t):]

Submission status: Wrong Answer

Solution code:
s, t = raw_input(), raw_input()
def f(a,b):
	if len(a) != len(b): return False

	for u,v in zip(a,b):
		if u != v and u != '?':
			return False
	return True
cand = -1
for i in range(len(s)):
	if f(s[i:i + len(t)],t):
		cand = i

if cand == -1:
	print 'UNRESTORABLE'
else:
	print s[:cand].replace('?', 'a') + t

Submission status: Wrong Answer

Solution code:
s, t = raw_input(), raw_input()
def f(a,b):
	if len(a) != len(b): return False

	for u,v in zip(a,b):
		if u != v and u != '?':
			return False
	return True
cand = -1
for i in range(len(s)):
	if f(s[i:i + len(t)],t):
		cand = i

if cand == -1:
	print 'UNRESTORABLE'
else:
	print s[:cand] + t

Submission status: Wrong Answer

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

n = len(s)
m = len(t)
ans = ""
for i in range(n-m+1):
  if s[i] == t[0] and s[i+1:i+m] == "?"*(m-1):
    ans = s[:i]+t+s[i+m:]

if ans == "":
  print("UNRESTORABLE")
  exit()
else: print(ans.replace("?","a"))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

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

flag = 0
for i in range(len(s)):
    if s[i] == t[0]:
        for j in range(i+1, i+len(t)-1):
            if s[j] == '?' or s[j] == t[j-i]:
                flag = 1
            else:
                flag = 0
                break
    
    if flag:
        s[i:i+len(t)+1] = t
        break

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

for k in range(len(s)):
    if s[k] == '?':
        s[k] = 'a'


print(''.join(s))

Submission status: Wrong Answer

Solution code:
S,T = input(),input()
N,M = len(S),len(T)
maximum = 0
maxstr = ""
for i in range(0,N-M+1):
    str = S[:i] + T + S[i+M:]

    n = 0
    for j in range(i,i+M):
        if (S[j] != str[j])&(S[j]!="?"):
            n = 1
            # print(S[j],str[j])
            break
    if n==1:continue

    match = 0
    for j in range(N):
        if S[j] == str[j]:match += 1
    if maximum<=match:
        maximum = match
        maxstr = str
    # print(str)
# print(maximum)
if maximum == 0:print("UNRESTORABLE")
else:print(maxstr.replace("?","a"))

Submission status: Wrong Answer

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

ins = -1#挿入場所(できるだけうしろにして前はAでつめる)
for i in range(0,len(S)-len(T)+1,1):
    
    isOk = True
    for j in range(i,i+len(T),1):
        print(T[j-i],S[j])
        if not(T[j-i]==S[j] or S[j]=="?"):
            isOk = False
            break
        
    if isOk:
        ins = i

if ins == -1:
    print("UNRESTORABLE")
    exit()

ans = list(S)
for i in range(len(T)):
    ans[ins+i]=T[i]

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

print("".join(ans))

Submission status: Wrong Answer

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

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

    if flag == False:
        continue
    for j in range(len(t)):
        s[i+j] = t[j]
    pos = True

if len(t) > len(s):
    pos = False

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

Submission status: Wrong Answer

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

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

    if flag == False:
        continue
    for j in range(len(t)):
        s[i+j] = t[j]
    pos = True

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

Submission status: Wrong Answer

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

Rs=list(S)[::-1]
Rt=list(T)[::-1]
N=len(S)
M=len(T)
i=0
while i+M<N:
    j=0
    while j<M:
        if Rs[i+j]=='?' or Rs[i+j]==Rt[j]:
            j+=1
        else:
            i+=1
            break
    if j==M:
        break

if i+M==N or M>N:
    ans='UNRESTORABLE'
else:
    for t in Rt:
        Rs[i]=t
        i+=1
    ans=''.join(Rs[::-1]).replace('?','a')
print(ans)

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
ans='U'
for i in range(len(s)-len(t),-1,-1):
  if s[i]==t[0] or s[i]==t[0]:
    cnt=1
    for j in range(1,len(t)):
      if s[i+j]==t[j] or s[i+j]=='?':
        cnt+=1
    if cnt==len(t):
      s[i:i+len(t)]=t
      u=''
      for k in s:
        u+=k
      u=u.replace('?','a')
      print(u)
      exit()
      
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
ans='U'
for i in range(len(s)-len(t),-1,-1):
  if s[i]==t[0]:
    cnt=1
    for j in range(1,len(t)):
      if s[i+j]==t[j] or s[i+j]=='?':
        cnt+=1
    if cnt==len(t):
      s[i:i+len(t)]=t
      u=''
      for k in s:
        u+=k
      u=u.replace('?','a')
      print(u)
      exit()
      
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
ans='U'
for i in range(len(s)-len(t),-1,-1):
  if s[i]==t[0]:
    cnt=0
    for j in range(len(t)-1):
      if s[i+j]==t[j] or s[i+j]=='?':
        cnt+=1
    if cnt==len(t)-1:
      s[i:i+len(t)]=t
      u=''
      for k in s:
        u+=k
      u=u.replace('?','a')
      print(u)
      exit()
      
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
sp=input()
t=input()

m=len(sp)
n=len(t)
for i in range(m-n,-1,-1):
  cand=sp[:i].replace('?','a')+t+sp[i+n:].replace('?','a')
  f=0
  for j,w in enumerate(t):
    if sp[j+i]!=w and sp[j+i]!='?':
      f=1
      break
  if f==0:
    print(cand)
    sys.exit()
print('UNRESTOREBLE')

Submission status: Wrong Answer

Solution code:
import sys
sp=input()
t=input()

m=len(sp)
n=len(t)
for i in range(m-n,-1,-1):
  cand=sp[:i].replace('?','a')+t+sp[i+n+1:].replace('?','a')
  f=0
  for j,w in enumerate(t):
    if sp[j+i]!=w and sp[j+i]!='?':
      f=1
      break
  if f==0:
    print(cand)
    sys.exit()
print('UNRESTOREBLE')

Submission status: Wrong Answer

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

S_len = len(S)
T_len = len(T)

if T_len > S_len:
    print("UNRESTORABLE")
    sys.exit()

#条件１に関して
for i in range(0, S_len-T_len+1):

    isOkay = True
    for j in range(T_len):
        if S[i+j] == "?":
            continue

        if S[i+j] == T[j]:
            continue
        else:
            isOkay = False

    if isOkay:
        S = S[0:i] + T + S[i+T_len:]
        print(S.replace("?", "a"))
        sys.exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

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

S_len = len(S)
T_len = len(T)

if T_len > S_len:
    print("UNRESTORABLE")
    sys.exit()

#条件１に関して
for i in range(0, S_len-T_len+1):

    isOkay = True
    for j in range(T_len):
        print(S[i+j], T[j], isOkay)
        if S[i+j] == "?":
            continue

        if S[i+j] == T[j]:
            continue
        else:
            isOkay = False

    if isOkay:
        S = S[0:i] + T + S[i+T_len:]
        print(S.replace("?", "a"))
        sys.exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = list(reversed(input()))
t = list(reversed(input()))
n = len(s)
m = len(t)

tp = 0
for i in range(n):
    if s[i] == t[tp] or s[i] == '?':
        tp += 1
    else:
        tp = 0
    if tp == m:
        s[i-m+1: i+1] = t
        ans = "".join(reversed(s)).replace('?', 'a')
        print(ans)
        exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

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

tp = 0
for i in range(n):
    if s[i] == t[tp] or s[i] == '?':
        tp += 1
    else:
        tp = 0
    if tp == m:
        s[i-m+1: i+1] = t
        s = ['a' if v == '?' else v for v in s]
        print("".join(s))
        exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s,t=open(0)
m=len(t:=t[:-1])
for i in range(m):
 if all(c in'?'+d for c,d in zip(s[-i-m:],t)):s=s.replace(*'?a');exit(print(s[:-i-m]+t+s[-i:]))
print('UNRESTORABLE')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
s_len=len(s)
t_len=len(t)
for i in range(s_len-t_len+1):
    for j in range(t_len):
        if s[i+j]!="?" and t[j]!=s[i+j]:
            break
    else:
        s[i:i+t_len]=t 
        for k in range(s_len):
            if s[k]=="?":
                s[k]="a"
        print("".join(s))
        exit()
print("UNRESTABLE")

Submission status: Wrong Answer

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

for i in range(n-m+1) :  
#文字列に安易に ' を入れない方が良い
    x=S[i:i+m]
    for j in range(m+1):
        if j==m :
            print((S[:i]+T+S[i+m:]).replace("?","a"))
            exit()
        if x[j]=="?" :
            continue
        elif x[j]!=T[j] :
            break
 
print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i in range(n-m+1) :  
#文字列に安易に ' を入れない方が良い
    s=S[i:i+m]
    for j in range(m+1):
        if j==m :
            print((S[:i]+T+S[i+m:]).replace("?","a"))
            exit()
        if s[j]=="?" :
            continue
        elif s[j]!=T[j] :
            break
 
print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i in range(n-m+1) :  
#文字列に安易に ' を入れない方が良い
    s=S[i:i+m]
    for j in range(m+1):
        if j==m :
            print((S[:i]+T+S[i+m:]).replace("?","a"))
            exit()
        if s[j]==T[j] :
            continue
        elif s[j]=="?" :
            continue
        else :
            break
 
print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i in range(n-m+1) :  
#文字列に安易に ' を入れない方が良い
    s=S[i:i+m]
    for j in range(m) :
        if s[j]==T[j] :
            continue
        elif s[j]=="?" :
            continue
        else :
            break
    else :
        print((S[:i]+T+S[i+m:]).replace("?","a"))
        exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys


Sp = [c for c in input()]
T = [c for c in input()]

sn = len(Sp)
tn = len(T)

match_i = 51
for i in range(sn - tn + 1):
    partial = Sp[i:i+tn]
    for j in range(len(partial)):
        if partial[j] == '?':
            partial[j] = T[j]
    if partial == T:
        match_i = i
        break

if match_i > 50:
    print('UNRESTORABLE')
    sys.exit()

Sp[match_i:match_i+tn] = T
for i in range(sn):
    if Sp[i] == '?':
        Sp[i] = 'a'
S = ''.join(Sp)

print(S)

Submission status: Wrong Answer

Solution code:
S = input()
s = len(S)
T = input()
t = len(T)

if s >= t:
    key = 0
    for i in range(s-t+1,0,-1):
        for j,k in enumerate(S[i:i+t]):
            if k == T[j] or k =="?":
                pass
            else:
                break
        else:
            key = i
            break
        key = 100
    if key == 100:
        print("UNRESTORABLE")
    else:
        ans = S[0:i]+T+S[i+t:]
        ans = ans.replace("?","a")
        print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
s = len(S)
T = input()
t = len(T)

if s >= t:
    key = 0
    for i in range(0,s-t+1):
        for j,k in enumerate(S[i:i+t]):
            if k == T[j] or k =="?":
                pass
            else:
                break
        else:
            key = i
            break
        key = 100
    if key == 100:
        print("UNRESTORABLE")
    else:
        ans = S[0:i]+T+S[i+t:]
        ans = ans.replace("?","a")
        print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re

S = input()
T = input()

S = ''.join(['.' if t == '?' else t for t in S])
n = len(S)
m = len(T)
j = -1
for i in range(n):
    if re.fullmatch(S[i:i+m], T) != None:
        j = i

if j == -1:
    print('UNRESTORABLE')
else:
    ans = ''.join(['a' if t == '.' else t for t in S])
    ans = ans[:j] + T + ans[j+m+1:]
    print(ans)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
check = 0
ans = []
for i in range(len(S) - len(T) + 1):
    word = ''
    for j in range(len(T)):
        if S[i+j] == '?':
            g = i
        elif S[i+j] == T[j]:
            g = i
        elif S[i+j] != T[j]:
            break
    else:
        cnt1 = list(S)
        num = 0
        for k in range(len(S)):
            if i <= k <= i+len(T) -1:
                cnt1[k] = T[num]
                num += 1
            elif cnt1[k] == '?':
                cnt1[k] = 'a'

        ans.append(''.join(cnt1))
        check = 1
        break
if check == 0:
    print('UNRESTORABLE')
else:
    ans.sort()
    print(ans[0])

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
check = 0
for i in range(len(S) - len(T) + 1):
    word = ''
    for j in range(len(T)):
        if S[i+j] == '?':
            g = i
        elif S[i+j] == T[j]:
            g = i
        elif S[i+j] != T[j]:
            break
    else:
        cnt1 = list(S)
        num = 0
        for k in range(len(S)):
            if i <= k <= i+len(T) -1:
                cnt1[k] = T[num]
                num += 1
            elif cnt1[k] == '?':
                cnt1[k] = 'a'

        print(''.join(cnt1))
        check = 1
        break
if check == 0:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
sd = input()
t = input()
oks = []
if len(sd) < len(t):
    print("UNRESTORABLE")
else:
    for i in range(len(sd)-len(t)+1):
        sdd = sd[i:i+len(t)]
        f = True
        for j,sddj in enumerate(sdd):
            if sddj == "?":
                continue
            elif sddj != t[j]:
                f = False
                break
        if f:
            oks.append(i)
    if oks:
        k = oks[-1]
        print((sd[:k]+t).replace("?","a")+sd[k+len(t):])
    else:
        print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
sd = input()
t = input()
oks = []
if len(sd) < len(t):
    print("UNRESTORABLE")
else:
    for i in range(len(sd)-len(t)+1):
        #print(i)
        sdd = sd[i:i+len(t)]
        f = True
        for j,sddj in enumerate(sdd):
            if sddj == "?":
                continue
            elif sddj != t[j]:
                f = False
                break
        if f:
            oks.append((sd[:i]+t).replace("?","a"))
    oks.sort()
    if oks:
        print(oks[0])
    else:
        print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
sd = input()
t = input()
oks = []
if len(sd) < len(t):
    print("UNRESTORABLE")
else:
    for i in range(len(sd)-len(t)+1):
        #print(i)
        sdd = sd[i:i+len(t)]
        f = True
        for j,sddj in enumerate(sdd):
            if sddj == "?":
                continue
            elif sddj != t[j]:
                f = False
                break
        if f:
            oks.append(i)
    if oks:
        k = oks[-1]
        print((sd[:k]+t).replace("?","a"))
    else:
        print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
sd = input()
t = input()
oks = []
for i in range(len(sd)-len(t)+1):
    sdd = sd[i:i+len(t)]
    f = True
    for j,sddj in enumerate(sdd):
        if sddj == "?":
            continue
        elif sddj != t[j]:
            f = False
            break
    if f:
        oks.append(i)
if oks:
    k = oks[-1]
    print((sd[:k]+t).replace("?","a"))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def resolve():
    Sd = list(input())
    T = input()
    for i in range(len(Sd)):
        for j in range(len(T)):
            if i + j >= len(Sd):
                break
            if Sd[i + j] != "?" and Sd[i] != T[j]:
                break
        else:
            for j in range(len(T)):
                Sd[i + j] = T[j]
            break
    else:
        print("UNRESTORABLE")
        return
    for s in Sd:
        if s == "?":
            s = "a"
        print(s, end="")
    print()

resolve()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
s = input()
t = input()
n = len(t)
m = len(s)
c = "Z" * m
for i in range(m - n + 1):
    if sum(j not in (t[k], "?") for k, j in enumerate(s[i:n + i])) < 1:
        c = min(c, s[:i] + t + s[i + n:])
print("UNRESTORABLE" if c == "Z" * m else c.replace("?", "a"))

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import re
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


def is_match(a, b):
    for _a, _b in zip(a, b):
        if (_a == _b or _a == '?'):
            continue
        else:
            return False
    return True


s = S()
t = S()

# s = s.replace('?', '.')
# pattern =   ''

if (t in s):
    print(s.replace('?', 'a'))
    exit()

if (is_match(s[-len(t):], t)):
    ans = s[:-len(t)] + t
    ans = ans.replace('?', 'a')
    print(ans)
    exit()
i = 0

for _s in reversed(s[len(t)-1:-1]):
    i += 1
    if (_s == t[-1] or _s == '?'):
        if (is_match(s[-i - len(t): - i], t)):
            ans = s[:-i - len(t)] + t + s[-i:]
            ans = ans.replace('?', 'a')
            print(ans)
            exit()


print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
import re
import numpy as np
import sys
from collections import deque
from collections import defaultdict
import heapq
import collections
import itertools
import bisect

sys.setrecursionlimit(10**6)


def zz():
    return list(map(int, sys.stdin.readline().split()))


def z():
    return int(sys.stdin.readline())


def S():
    return sys.stdin.readline()[:-1]


def C(line):
    return [sys.stdin.readline() for _ in range(line)]


def is_match(a, b):
    for _a, _b in zip(a, b):
        if (_a == _b or _a == '?'):
            continue
        else:
            return False
    return True


s = S()
t = S()

# s = s.replace('?', '.')
# pattern =   ''
if (is_match(s[-len(t):], t)):
    ans = s[:-len(t)] + t
    ans = ans.replace('?', 'a')
    print(ans)
    exit()
i = 0
# exit()
for _s in reversed(s[len(t)-1:-1]):
    i += 1
    if (_s == t[-1] or _s == '?'):
        if (is_match(s[-i - len(t): - i], t)):
            ans = s[:-i - len(t)] + t + s[-i:]
            ans = ans.replace('?', 'a')
            print(ans)
            exit()


print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
#区間を決める
for i in range(len(S)-len(T),-1,-1):
    S_ = S[i:i+len(T)]
    frag = 1
    for j in range(len(T)):
        if S_[j] == T[j] or S_[j] == '?' :
            #print(S_[j],T[j])
            if not j == len(T)-1:
                continue
        else:
            break
            frag = 0
        if frag == 1:
            #print(S_)
            #print(S[:i] ,T ,S[len(T)+2:])
            ans = S[:i] + T + S[len(T)+2:]
            ans = ans.replace('?','a')
            print(ans)
            exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
#区間を決める
for i in range(len(S)-len(T)+1):
    S_ = S[i:i+len(T)]
    #print(S_,T)
    frag = 1
    for j in range(len(T)):
        if S_[j] == T[j] or S_[j] == '?' :
            #print(S_[j],T[j])
            if not j == len(T)-1:
                continue
        else:
            break
            frag = 0
        if frag == 1:
            #print(S_)
            #print(S[:i] ,T ,S[len(T)+2:])
            ans = S[:i] + T + S[len(T)+2:]
            ans = ans.replace('?','a')
            print(ans)
            exit()
print("UNRESTORABLE")