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()
ls = len(S)
lt = len(T)
if ls<lt:
    print('UNRESTORABLE')
else:
    for i in range(ls-lt+1):
        if S[i]=='?' or S[i]==T[0]:
            c = 0
            for j in range(i+1,i+lt):
                c+=1
                if S[j]!='?' and S[j]!=T[c]:
                    break
            else:
                S = S[:i]+T+S[i+lt:]
                i=i+lt
    if T not in S:
        print('UNRESTORABLE')
    else:
        S2=S.replace('?','a')
        print(S2)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def check(s, t, k):
	for i in range(len(t)):
		if s[i+k] != t[i] and s[i+k] != '?':
			return False
	return True

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

def resolve():
	s = list(input())
	t = list(input())
	ans = []
	if len(s) < len(t):
		print('UNRESTORABLE')
		return
	for i in range(len(s) - len(t) + 1):
		if check(s, t, i):
			ans.append(construct(s, t, i))
	if len(ans) >= 1:
		print(min(ans))
	else:
		print('UNRESTORABLE')
resolve()

Submission status: Wrong Answer

Solution code:
def check(s, t, k):
	for i in range(len(t)):
		if s[i+k] != t[i] and s[i+k] != '?':
			return False
	return True

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

def resolve():
	s = list(input())
	t = list(input())
	if len(s) < len(t):
		print('UNRESTORABLE')
		return
	for i in range(len(s) - len(t) + 1):
		if check(s, t, i):
			print(construct(s, t, i))
			return
	print('UNRESTORABLE')
resolve()

Submission status: Wrong Answer

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

def norm(s):
	ans = []
	for i in s:
		ans.append('a' if i == '?' else i)
	return "".join(ans)

def resolve():
	s = list(input())
	t = list(input())
	if len(s) < len(t):
		print('UNRESTORABLE')
		return
	for i in range(len(s) - len(t) + 1):
		if check(s[i:i+len(t)], t):
			for j in range(len(t)):
				s[i+j] = t[j]
			print(norm(s))
			return
	print('UNRESTORABLE')
resolve()

Submission status: Wrong Answer

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

def norm(s):
	ans = []
	for i in s:
		ans.append('a' if i == '?' else i)
	ans[0] = 'a'
	return "".join(ans)

def resolve():
	s = list(input())
	t = list(input())
	if len(s) < len(t):
		print('UNRESTORABLE')
		return
	for i in range(len(s) - len(t) + 1):
		if check(s[i:i+len(t)], t):
			for j in range(len(t)):
				s[i+j] = t[j]
			print(norm(s))
			return
	print('UNRESTORABLE')
resolve()

Submission status: Wrong Answer

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

def norm(s):
	ans = []
	for i in s:
		ans.append('a' if i == '?' else i)
	ans[0] = 'a'
	return "".join(ans)

def resolve():
	s = list(input())
	t = list(input())
	if s.count('?') != len(t):
		print('UNRESTORABLE')
		return
	else:
		for i in range(len(s) - len(t) + 1):
			if check(s[i:i+len(s)], t):
				for j in range(len(t)):
					s[i+j] = t[j]
				print(norm(s))
				return
	print('UNRESTORABLE')
resolve()

Submission status: Wrong Answer

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

def norm(s):
	ans = ''
	for i in s:
		ans += 'a' if i == '?' else i
	return ans

def resolve():
	s = list(input())
	t = list(input())
	if s.count('?') != len(t):
		print('UNRESTORABLE')
		return
	else:
		for i in range(len(s) - len(t) + 1):
			if check(s[i:i+len(s)], t):
				for j in range(len(t)):
					s[i+j] = t[j]
				print(norm(s))
				return
	print('UNRESTORABLE')
resolve()

Submission status: Wrong Answer

Solution code:
import re

s2 = input().replace('?','.')
t = input()
a = len(s2)
b = len(t)
ans = None

for i in range(a-b+1):
    if re.match(s2[i:i+b], t) is not None:
        ans = s2.replace(s2[i:i+b], t, 1).replace('.','a')

if ans is None:
    print('UNRESTORABLE')
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import re

s2 = input().replace('?','.')
t = input()
a = len(s2)
b = len(t)
l = []

for i in range(a-b+1):
    if re.match(s2[i:i+b], t) is not None:
        s3 = s2.replace(s2[i:i+b], t, 1).replace('.','a')
        l.append(s3)

if not l:
    print('UNRESTORABLE')
else:
    print(sorted(l)[0])

Submission status: Wrong Answer

Solution code:
import re

s2 = input().replace('?','.')
t = input()
a = len(s2)
b = len(t)

for i in range(a-b+1):
    if re.match(s2[i:i+b], t) is not None:
        s2 = s2.replace(s2[i:i+b], t, 1)
        break
    if i == a-b:
        print('UNRESTORABLE')
        exit()

print(s2.replace('.','a'))

Submission status: Wrong Answer

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

t_len=len(T)-1
flag=0
for i in range(len(S)):
    cnt=0
    now=i
    for j in range(len(T)):
        if S[now]==T[j] or S[now]=="?":
            cnt+=1
        else:
            break

        if cnt==len(T):
            S=S[:i]+T+S[i+j+1:]
            flag=1
            break
        if now<len(S)-1:        
            now+=1
        else:
            break



ans=[i for i in S]
ans_moji=""
if flag==1:
    for i in range(len(S)):
        if ans[i]=="?":
            ans[i]="a"
        ans_moji+=ans[i]
    print(ans_moji)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys

S = sys.stdin.readline().rstrip()
T = sys.stdin.readline().rstrip()


for i in range(len(S)):
    for j in range(len(T)):
        if i+j >= len(S) or (S[i+j] != "?" and S[i+j] != T[j]):
            break
    else:
        # print("i: ", i)
        ans = ""
        for k in range(len(S)):
            if k < i:
                ans += S[k]
            else:
                if k - i < len(T):
                    ans += T[k - i]
                else:
                    ans += S[k]
        # print(ans)
        print(ans.replace("?", "a"))
        sys.exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i in range(len(T)-m+1):
 if all(c in"?"+d for c,d in zip(S[-i-m:],T)):
     S=S.replace("?","a")
     print(S[:-i-m]+T+S[len(T)-i:])
     quit()
print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i in range(len(T)-m+1):
 if all(c in"?"+d for c,d in zip(S[-i-m:],T)):
     S=S.replace("?","a")
     print(S[:-i-m]+T+S[-i:])
     quit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
lst = []
i= 0
for ss in range(len(s)-len(t)+1):
  flg = 1
  i= 0
  for tt in range(len(t)):
    now = ss + tt
    if s[now] == t[tt] or s[now] == '?':
      pass
    else:
      flg = 0
  if flg:
    ns = list(s)
    ns[ss:now+1] = list(t)
    lst.append(("").join(ns))
if lst:
  lst = [_.replace('?','a') for _ in lst]
  sorted(lst)
  print(lst[0])

else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

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

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

if flag is False:
    print("UNRESTORABLE")
else:
    print(s_.replace("?", "a"))

Submission status: Wrong Answer

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

i=len(Sd)-len(T)
j=0

flag2=True
flag=True
while(1):
    #print('searching',i,j,Sd[i],T[j])
    if Sd[i]==T[j]:
        flag=True
        #print('find',i,j,Sd[i],T[j])
        if j==len(T)-1:
            flag2=False
            break
        j+=1
        i+=1
    else:
        flag=False
        i-=j+1
        j=0
        if i<0:
            #print('not find')
            break

i=len(Sd)-len(T)
j=0
if flag2:
    flag=True
    while(1):
        #print('searching',i,j,Sd[i],T[j])
        if Sd[i]==T[j] or Sd[i]=='?':
            flag=True
            #print('find',i,j,Sd[i],T[j])
            if j==len(T)-1:
                #print('complete')
                break
            j+=1
            i+=1
        else:
            flag=False
            i-=j+1
            j=0
            if i<0:
                #print('not find')
                break

if flag:
    print((Sd[:i-j]+T+Sd[i-j+len(T):]).replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

i=len(Sd)-len(T)
j=0


flag2=True
flag=True
while(1):
    #print('searching',i,j,Sd[i],T[j])
    if Sd[i]==T[j]:
        flag=True
        #print('find',i,j,Sd[i],T[j])
        if j==len(T)-1:
            flag2=False
            #print('complete')
            break
        j+=1
        i+=1
    else:
        flag=False
        i-=j+1
        j=0
        if i<0:
            #print('not find')
            break

if flag2:
    flag=True
    while(1):
        #print('searching',i,j,Sd[i],T[j])
        if Sd[i]==T[j] or Sd[i]=='?':
            flag=True
            #print('find',i,j,Sd[i],T[j])
            if j==len(T)-1:
                #print('complete')
                break
            j+=1
            i+=1
        else:
            flag=False
            i-=j+1
            j=0
            if i<0:
                #print('not find')
                break

if flag:
    print((Sd[:i-j]+T+Sd[i-j+len(T):]).replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

i=len(Sd)-len(T)
j=0


flag=True
while(1):
    #print('searching',i,j,Sd[i],T[j])
    if Sd[i]==T[j]:
        flag=True
        #print('find',i,j,Sd[i],T[j])
        if j==len(T)-1:
            #print('complete')
            break
        j+=1
        i+=1
    else:
        flag=False
        i-=j+1
        j=0
        if i<0:
            #print('not find')
            break

if not flag:
    flag=True
    while(1):
        #print('searching',i,j,Sd[i],T[j])
        if Sd[i]==T[j] or Sd[i]=='?':
            flag=True
            #print('find',i,j,Sd[i],T[j])
            if j==len(T)-1:
                #print('complete')
                break
            j+=1
            i+=1
        else:
            flag=False
            i-=j+1
            j=0
            if i<0:
                #print('not find')
                break

if flag:
    print((Sd[:i-j]+T+Sd[i-j+len(T):]).replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

i=len(Sd)-len(T)
j=0

flag=True
while(1):
    #print('searching',i,j,Sd[i],T[j])
    if Sd[i]==T[j] or Sd[i]=='?':
        flag=True
        #print('find',i,j,Sd[i],T[j])
        if j==len(T)-1:
            #print('complete')
            break
        j+=1
        i+=1
    else:
        flag=False
        i-=j+1
        j=0
        if i<0:
            #print('not find')
            break

if flag:
    print((Sd[:i-j]+T+Sd[i-j+len(T):]).replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

i=len(Sd)-len(T)
j=0

flag=True
while(1):
    print('searching',i,j,Sd[i],T[j])
    if Sd[i]==T[j] or Sd[i]=='?':
        flag=True
        print('find',i,j,Sd[i],T[j])
        if j==len(T)-1:
            print('complete')
            break
        j+=1
        i+=1
    else:
        flag=False
        i-=j+1
        j=0
        if i<0:
            print('not find')
            break

if flag:
    print((Sd[:i-j]+T+Sd[i-j+len(T):]).replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline


def read():
    S = input().strip()
    T = input().strip()
    return S, T


def solve(S, T, INF = 100000):
    S = '.' + S
    T = '.' + T
    dp = [[INF for j in range(len(T))] for i in range(len(S))]
    
    offset = -1
    for i in range(len(S)):
        dp[i][0] = 0
    for j in range(len(T)):
        dp[0][j] = 0
    for i in range(1, len(S)):
        for j in range(1, len(T)):
            if S[i] == '?' or T[j] == '?' or S[i] == T[j]:
                dp[i][j] = dp[i-1][j-1] + 1
                if dp[i][j] == len(T)-1:
                    offset = i - (len(T)-1)
            else:
                dp[i][j] = 0
    
    if offset == -1:
        return 'UNSORTABLE'
    U = [s if s != '?' else 'a' for s in S[1:]]
    for i in range(len(T)-1):
        U[offset + i] = T[i+1]
    return ''.join(U)
            

if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
flag=False
ata=0
for i in range(len(s)-len(t)+1):
  if flag==True:
    break
  for j in range(len(t)):
    if s[i+j]!="?" and s[i+j]!=t[j]:
      break
    if j==(len(t)-1):
      flag=True
      ata=i
if flag==True:
  for i in range(len(t)):
    s[ata+i]=t[i]
  for i in range(len(s)):
    if s[i]=="?":
      s[i]="a"
  print("".join(s))
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    s = list(stdin.readline()[:-1])
    t = list(stdin.readline()[:-1])
    s_len = len(s)
    t_len = len(t)

    for i in reversed(range(0, s_len - t_len + 1)):
        check = True
        tmp = s[i:(i + t_len)]
        for j in range(t_len):
            if tmp[j] == '?':
                tmp[j] = t[j]
                continue
            if tmp[j] != t[j]:
                check = False
                break
        for b in tmp:
            if b == '?':
                check = False
        if check:
            before = s[:i]
            after = s[(i + t_len + 1):]
            print(''.join(before + tmp + after).replace('?', 'a'))
            exit()

    print('UNRESTORABLE')
    exit()


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
from sys import stdin


def main():
    s = list(stdin.readline()[:-1])
    t = list(stdin.readline()[:-1])
    s_len = len(s)
    t_len = len(t)

    for i in range(0, s_len - t_len + 1):
        check = True
        tmp = s[i:(i + t_len)]
        for j in range(t_len):
            if tmp[j] == '?':
                tmp[j] = t[j]
                continue
            if tmp[j] != t[j]:
                check = False
                break
        for b in tmp:
            if b == '?':
                check = False
        if check:
            before = s[:i]
            after = s[(i + t_len + 1):]
            print(''.join(before + tmp + after).replace('?', 'a'))
            exit()

    print('UNRESTORABLE')
    exit()


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
s_len=(len(s))
t_len=(len(t))

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

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
s_len=(len(s))
t_len=(len(t))

for i in range(s_len-t_len,-1,-1):
    for j in range(t_len):
        if s[i+j]==t[j] or s[i+j]=="?":
            continue
        else:
            break
    else:
        print((s[:i]+t+s[i+s_len:]).replace("?","a"))
        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,-1):
    for j in range(t_len):
        if s[i+j]==t[j] or s[i+j]=="?":
            s[i+j]=t[j]
        else:
            break
    else:
        print(("".join(s)).replace("?","a"))
        exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import copy
import sys

TEMP = list(input())
T = list(input())

ans_list = []

if len(TEMP)<len(T):
    print("UNRESTORABLE")
    sys.exit()


for i in range(len(TEMP)-len(T)+1):
    S = copy.deepcopy(TEMP)
    flg = 0
    for j in range(len(T)):
        if S[i+j]!="?" and S[i+j]!=T[j]:
            flg =  1
            break
    if flg==0:
        for k in range(1, len(T), 1):
            S[i+k] = T[k]
        for i in range(len(S)):
            if S[i]=="?":
                S[i] = "a"
        ans_list.append("".join(S))

if ans_list==[]:
    print("UNRESTORABLE")
    sys.exit()
    
ans = ans_list[0]
for s in ans_list[1:]:
    ans = min(ans, s)

print(ans)

Submission status: Wrong Answer

Solution code:
import copy
import sys

TEMP = list(input())
T = list(input())

ans_list = []

if len(TEMP)<len(T):
    print("UNRESTORABLE")
    sys.exit()


for i in range(len(TEMP)-len(T)+1):
    S = copy.deepcopy(TEMP)
    flg = 0
    for j in range(len(T)):
        if S[i+j]!="?" and S[i+j]!=T[j]:
            flg =  1
            break
    if flg==0:
        for k in range(1, len(T), 1):
            S[i+k] = T[k]
        for i in range(len(S)):
            if S[i]=="?":
                S[i] = "a"
        ans_list.append("".join(S))

ans = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
for s in ans_list:
    ans = min(ans, s)

if ans=="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz":
    print("UNRESTORABLE")
else:
    print(ans)

Submission status: Wrong Answer

Solution code:
import copy
TEMP = list(input())
T = list(input())

ans_list = []

for i in range(len(TEMP)-len(T)+1):
    S = copy.deepcopy(TEMP)
    flg = 0
    for j in range(len(T)):
        if S[i+j]!="?" and S[i+j]!=T[j]:
            flg =  1
            break
    if flg==0:
        for k in range(1, len(T), 1):
            S[i+k] = T[k]
        for i in range(len(S)):
            if S[i]=="?":
                S[i] = "a"
        ans_list.append("".join(S))

ans = "zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
for s in ans_list:
    ans = min(ans, s)

if ans=="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz":
    print("UNRESTORABLE")
else:
    print(ans)

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
import re
S2 = input()
T = input()

S2 = S2.replace('?', '.')
S2 = S2[::-1]
T = T[::-1]

ans = ""
i = 0
find = False
while i < len(S2):
    p = S2[i:i+len(T)]
    m = re.match(p, T)
    if m and find == False:
        find = True
        ans = ans + T
        i += len(T)
    else:
        if S2[i] == '.':
            ans = ans + 'a'
        else:
            ans = ans + S2[i]
        i += 1

if len(ans) == len(S2):
    print(ans[::-1])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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


def found(i):
    for j in range(len(T)):
        if S[i] == '?' or S[i] == T[j]:
            i += 1
        else:
            return False
    return True

ret = 'UNRESTORABLE'
for i in range(len(S) - len(T) + 1):
    if found(i):
        ret = S[:i] + T + S[i + len(T):]
        break
    else:
        i += 1

print(''.join('a' if x == '?' else x for x in ret))

Submission status: Wrong Answer

Solution code:
import collections
def main():

    S = list(input())[::-1]
    T = list(input())[::-1]



    c = collections.Counter(S)
    if len(S) < len(T):
        print('UNRESTORABLE')
        return

    # if c['?'] == len(S):
    #     if len(S) == len(T):
    #
    #         print(''.join(T))
    #         return
    #     else:
    #         print('UNRESTORABLE')
    #         return
    else:
        for s_left in range(len(S)):
            s_l = s_left
            flg = True
            tmp = S[::1]
            for t_left in range(len(T)) :
                if S[s_l] == T[t_left] or S[s_l] == '?':
                    tmp[s_l] = T[t_left]
                    s_l += 1
                    continue
                else:
                    flg = False
                    break
            if flg:
                ans_t = tmp[::-1]
                ans = ''
                for i in range(len(S)):
                    if ans_t[i] == '?':
                        ans += 'a'
                    else:
                        ans += ans_t[i]
                print(ans)
                return
            break
        if not flg :

            print('UNRESTORABLE')
            return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
def main():

    S = list(input())[::-1]
    T = list(input())[::-1]



    c = collections.Counter(S)
    if len(S) < len(T):
        print('UNRESTORABLE')
        return
    
    # if c['?'] == len(S):
    #     if len(S) == len(T):
    # 
    #         print(''.join(T))
    #         return
    #     else:
    #         print('UNRESTORABLE')
    #         return
    else:
        for s_left in range(len(S)):
            s_l = s_left
            flg = True
            tmp = S[::1]
            for t_left in range(len(T)) :
                if S[s_l] == T[t_left] or S[s_l] == '?':
                    tmp[s_l] = T[t_left]
                    s_l += 1
                    continue
                else:
                    flg = False
                    break
            if flg:
                ans_t = tmp[::-1]
                ans = ''
                for i in range(len(S)):
                    if ans_t[i] == '?':
                        ans += 'a'
                    else:
                        ans += ans_t[i]
                print(ans)
                return
            break
        if not flg :

            print('UNRESTORABLE')
            return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
def main():

    S = list(input())[::-1]
    T = list(input())[::-1]



    c = collections.Counter(S)
    if c['?'] == len(S):
        if len(S) == len(T):

            print(''.join(T))
            return
        else:
            print('UNRESTORABLE')
            return
    else:
        for s_left in range(len(S)):
            s_l = s_left
            flg = True
            tmp = S[::1]
            for t_left in range(len(T)) :
                if S[s_l] == T[t_left] or S[s_l] == '?':
                    tmp[s_l] = T[t_left]
                    s_l += 1
                    continue
                else:
                    flg = False
                    break
            if flg:
                ans_t = tmp[::-1]
                ans = ''
                for i in range(len(S)):
                    if ans_t[i] == '?':
                        ans += 'a'
                    else:
                        ans += ans_t[i]
                print(ans)
                return
            break
        if not flg :

            print('UNRESTORABLE')
            return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
def main():

    S = list(input())[::-1]
    T = list(input())[::-1]



    c = collections.Counter(S)
    if c['?'] == len(S):
        if len(S) == len(T):
            print(T)
            return
        else:
            print('UNRESTORABLE')
            return
    else:
        for s_left in range(len(S)):
            s_l = s_left
            flg = True
            tmp = S[::1]
            for t_left in range(len(T)) :
                if S[s_l] == T[t_left] or S[s_l] == '?':
                    tmp[s_l] = T[t_left]
                    s_l += 1
                    continue
                else:
                    flg = False
                    break
            if flg:
                ans_t = tmp[::-1]
                ans = ''
                for i in range(len(S)):
                    if ans_t[i] == '?':
                        ans += 'a'
                    else:
                        ans += ans_t[i]
                print(ans)
                return
            break
        if not flg :

            print('UNRESTORABLE')
            return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import collections
S = list(input())[::-1]
T = list(input())[::-1]

if len(S) < len(T):
    print('UNRESTORABLE')
c = collections.Counter(S)
if c['?'] == len(S):
    if len(S) == len(T):
        print(T)
    else:
        print('UNRESTORABLE')
else:
    for s_left in range(len(S)):
        s_l = s_left
        flg = True
        tmp = S[::1]
        for t_left in range(len(T)) :
            if S[s_l] == T[t_left] or S[s_l] == '?':
                tmp[s_l] = T[t_left]
                s_l += 1
                continue
            else:
                flg = False
                break
        if flg:
            ans_t = tmp[::-1]
            ans = ''
            for i in range(len(S)):
                if ans_t[i] == '?':
                    ans += 'a'
                else:
                    ans += ans_t[i]
            print(ans)
        break
    if not flg :

        print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import collections
S = list(input())[::-1]
T = list(input())[::-1]

c = collections.Counter(S)
if c['?'] == len(S):
    if len(S) == len(T):
        print(T)
    else:
        print('UNRESTORABLE')
else:
    for s_left in range(len(S)):
        s_l = s_left
        flg = True
        tmp = S[::1]
        for t_left in range(len(T)) :
            if S[s_l] == T[t_left] or S[s_l] == '?':
                tmp[s_l] = T[t_left]
                s_l += 1
                continue
            else:
                flg = False
                break
        if flg:
            ans_t = tmp[::-1]
            ans = ''
            for i in range(len(S)):
                if ans_t[i] == '?':
                    ans += 'a'
                else:
                    ans += ans_t[i]
            print(ans)
        break
    if not flg :

        print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
readline = sys.stdin.readline

def main():
    S = readline().rstrip()
    T = readline().rstrip()
    N = len(S)
    M = len(T)
    for i in range(N-M+1):
        s = S[i:i+M]
        flg = True
        for e1, e2 in zip(s, T):
            if e1 != '?' and e1 != e2:
                flg = False
                break
        if flg:
            ans = list(S)
            for j in range(i, i+M):
                ans[j] = T[j-i]
            ans = ''.join(ans)
            print(ans.replace('?', 'a'))
            return
          
    print('UNRESTORABLE')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s2 = input()
t = input()
c1=1
c2=0
c3=0

for i in range(len(s2)-len(t)+1):
    if s2[i]==t[0]:
        for j in range(1,len(t)):
            if s2[i+j]==t[j] or s2[i+j]=='?':
                c1+=1
        if c1 == len(t):
            c2=1
            c3=i
        c1=1
if c2==1:
    s=list(s2)
    for i in range(len(t)):
        s[c3+i]=t[i]
    for i in range(len(s2)):
        if s[i]=='?':
            s[i]='a'
    print("".join(s))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

S_rev = S[::-1]
T_rev = T[::-1]

lens = len(S)
lent = len(T)

for i in range(lens-lent):
    Sp = S_rev[i:i+lent]
    for j in range(lent+1):
        if j == lent:
            ST = S_rev[:i] + T_rev + S_rev[i+lent:]
            print(ST[::-1].replace("?","a"))
            exit()
        if Sp[j] == "?":
            continue
        if Sp[j] != T_rev[j]:
            break

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
ans=[]
for i in range(len(s)-len(t)+1):
  start=i
  end=i+len(t)
  ok=True
  for j in range(len(t)):
    if s[start+j]!='?' and s[start+j]!=t[j]:
      ok=False
      break
  if ok:
    a=s[:start]+t+s[end:]
    ans.append(a.replace('?','a'))
if ans:
  ans=sorted(ans)
  print(ans[0])
else:
  print('UNRESTORALBE')

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(t)+i,len(s)):
          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')