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()
import sys

##後ろから順に考える
code=list(S)
code.reverse()
S=list(S)
S.reverse()
T=list(T)
T.reverse()


for i in range(len(S)-len(T)+1):
    count=0
    for j in range (len(T)):
        if S[i+j]==T[j] or S[i+j]=='?':
            code[i+j]=T[j]
            count+=1
            print (count)
            print (code)
            if count==len(T):
                for k in range (len(S)):
                    if code[k]=='?':
                        code[k]='a'
                code.reverse()
                print(''.join(code))
                sys.exit()
            
        else:
            code=list(S)
        
print ('UNRESTORABLE')

Submission status: Wrong Answer

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

for l in range(len(S)-len(T)+1):#後ろから
    i=len(S)-len(T)-l
    count=0
    for j in range (len(T)):
        if S[i+j]==T[j] or S[i+j]=='?':
            code[i+j]=T[j]
            count+=1
            if count==len(T):
                for k in range (len(S)):
                    if code[k]=='?':
                        code[k]='a'
                print(''.join(code))
                sys.exit()
            
        else:
            code=list(S)
        
print ('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
#ループ回しすぎだけどS,T<50だからOK？
S=input()
T=input()

import sys
code=list(S)

for i in range (len(S)-len(T)+1):
    count=0
    for j in range (len(T)):
        if S[i+j]==T[j] or S[i+j]=='?':
            code[i+j]=T[j]
            count+=1
            if count==len(T):
                for k in range (len(S)):
                    if code[k]=='?':
                        code[k]='a'
                print(''.join(code))
                sys.exit()
            
        else:
            code=list(S)
        
print ('UNRESTORABLE')

Submission status: Wrong Answer

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


s = input()
t = input()

res = ""
for i in reversed(range(len(s) - len(t)+1)):
    ss = s[i:i+len(t)]
    if judge(ss, t) and s.count("?") != 0:
        res = s[:i] + t + s[i+len(t)+1:]
        break
print(res.replace("?", "a") if res != "" else "UNRESTORABLE")

Submission status: Wrong Answer

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


s = input()
t = input()

res = ""
for i in reversed(range(len(s) - len(t)+1)):
    ss = s[i:i+len(t)]
    if judge(ss, t):
        res = s[:i] + t + s[i+len(t)+1:]
        break
print(res.replace("?", "a") if res != "" else "UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s, T = input(), input()

def is_T(s_i, T_i):
    if len(T_i) == 1:
        if s_i[0] == T_i[0] or s_i[0] == '?':
            return True
    
    if s_i[0] == T_i[0] or s_i[0] == '?':
        flag = is_T(s_i[1:], T_i[1:])
        
        if flag:
            return True
    
    return False

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

Submission status: Wrong Answer

Solution code:
s, T = input(), input()

def is_T(s_i, T_i):
    #print(s_i, T_i)#
    if len(T_i) == 1:
        if s_i[0] == T_i[0] or s_i[0] == '?':
            return True
    
    if s_i[0] == T_i[0] or s_i[0] == '?':
        flag = is_T(s_i[1:], T_i[1:])
        
        if flag:
            #print('True')#
            return True
    
    #print('False')#
    return False

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

Submission status: Wrong Answer

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


s = input()
t = input()

res = ""
for i in reversed(range(len(s) - len(t)+1)):
    ss = s[i:i+len(t)]
    if judge(ss, t):
        res = s[:i] + t
        break
print(res.replace("?", "a") if res != "" else "UNRESTORABLE")

Submission status: Wrong Answer

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


s = input()
t = input()

res = ""
for i in reversed(range(len(s) - len(t)+1)):
    ss = s[i:i+len(t)]
    if judge(ss, t):
        res = s.replace(s[i:i+len(t)], t)
        break
print(res.replace("?", "a") if res != "" else "UNRESTORABLE")

Submission status: Wrong Answer

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

def valid(s1,s2):
	for i in range(len(s2)):
		if s1[i] != s2[i] and s1[i] != '?':
			return False
	return True


for i in range(len(s)):
	ss = s[i:i+len(t)]
	if len(ss) != len(t):
		continue
	if not valid(ss,t):
		continue

	ans = s[0:i] + t + s[i+len(t):]
	ansans = ""
	for c in ans:
		if c == '?':
			ansans += 'a'
		else:
			ansans += c
	print(ansans)
	exit(0)

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
NOT_FOUND = 'UNRESTORABLE'


def m():
    S = list(str(input()))
    T = list(str(input()))
    first = 0
    end = 0
    for i in range(len(S) + 1 - len(T)):
        for k in range(len(T)):
            if S[i+k] != T[k] and S[i+k] != '?':
                break
            if k == len(T) - 1:
                first = i
                end = i+k
    if (end - first) < len(T):
        return NOT_FOUND

    j = 0
    while first <= end:
        S[first] = T[j]
        first += 1
        j += 1
    ans = "".join(S)
    r = ans.replace('?', 'a')
    return r
print(m())

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
sl=len(s)
tl=len(t)
for k in range(sl-tl,0,-1):
    judge=True
    for i in range(tl):
        if s[i+k]==t[i] or s[i+k]=="?":
            pass
        else:
            judge=False
            break
    if judge:
        for i in range(tl):
            s[i+k]=t[i]
        for i in range(sl):
            if s[i]=="?":
                s[i]="a"
        print("".join(s))
        exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
sl=len(s)
tl=len(t)
for k in range(sl-tl+1):
    judge=True
    for i in range(tl):
        if s[i+k]==t[i] or s[i+k]=="?":
            pass
        else:
            judge=False
            break
    if judge:
        for i in range(tl):
            s[i+k]=t[i]
        for i in range(sl):
            if s[i]=="?":
                s[i]="a"
        print("".join(s))
        exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
sl=len(s)
tl=len(t)
cnt=0
for k in range(sl-tl+1):
    judge=True
    for i in range(tl):
        if s[i+k]==t[i] or s[i+k]=="?":
            pass
        else:
            judge=False
            cnt+=1
            break
    if judge:
        for i in range(tl):
            s[i+k]=t[i]
        for i in range(sl):
            if s[i]=="?":
                s[i]="a"
        print("".join(s))
        exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
sl=len(s)
tl=len(t)
cnt=0
for k in range(sl-tl+1):
    judge=True
    for i in range(tl):
        if s[i+k]==t[i] or s[i+k]=="?":
            pass
        else:
            judge=False
            cnt+=1
            break
    if judge:
        for i in range(tl):
            s[i+k]=t[i]
        for i in range(sl):
            if s[i]=="?":
                s[i]="a"
if "?" in s:
    print("UNRESTORABLE")
else:
    print("".join(s))

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
s_v="".join(s)
t_v="".join(t)
sl=len(s)
tl=len(t)
if t_v in s_v:
    for i in range(sl):
        if s[i]=="?":
            s[i]="a"
    print("".join(s))
else:
    for k in range(sl-tl+1):
        judge=True
        for i in range(tl):
            if t[i]!=s[i+k] and s[i+k]!="?":
                judge=False
                break
        if judge:
            for i in range(tl):
                s[k+i]=t[i]
            for i in range(sl):
                if s[i]=="?":
                    s[i]="a"
    if "?" in s:
        print("UNRESTORABLE")
    else:
        print("".join(s))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def compute(s, t):
    for si in range(len(s)-len(t)+1):
        for ti in range(len(t)):
            if not (s[si+ti]==t[ti] or s[si+ti]=="?"): break
            if ti!=len(t)-1: continue
            head=s[:si]
            tail=s[si+len(t):]
            return head+t+tail
    return None

s=input()
t=input()
template=compute(s, t)
if template:
    result=""
    for c in template:
        result+="a" if c=="?" else c
    print(result)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
sl=len(s)
tl=len(t)
jud=True
k=60
for i in range(sl-tl+1):
    for j in range(tl):
        if s[i]==t[j]:
            k=i
if k==60:
    print("UNRESTORABLE")
    exit()
for i in range(tl):
    if t[i]!=s[i+k] and s[i+k]!="?":
        jud=False
if jud==False:
    print("UNRESTORABLE")
for i in range(tl):
    s[k+i]=t[i]
for i in range(sl):
    if s[i]=="?":
        s[i]="a"
print("".join(s))

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
sl=len(s)
tl=len(t)
cnt=0
k=60
for i in range(sl-tl+1):
    for j in range(tl):
        if s[i]==t[j]:
            k=i
if k==60:
    print("UNRESTORABLE")
    exit()
for i in range(tl):
    if t[i]!=s[i+k] and s[i+k]!="?":
        cnt+=1
if cnt!=0:
    print("UNRESTORABLE")
    exit()
for i in range(tl):
    s[i+k]=t[i]
for i in range(sl):
    if s[i]=="?":
        s[i]="a"
print("".join(s))

Submission status: Wrong Answer

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

for k in range(1+len(S)-len(T)):
    f = len(T)
    for j in range(len(T)):
        if S[k+j]==T[j] or S[k+j]=="?":
            f-=1
    if f==0:
        print((S[:k]+T+S[k+len(T):]).replace("?","a"))
        exit(0)

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def padding(S, T, i):
    ans = S[:i] + T + S[i+len(X):]
    return ans.replace("?","a")

if __name__ == '__main__':
    
    S = input()
    T = input()

    if len(S) < len(T):
        print("UNRESTORABLE")

    sizeX = len(T)
    ans = []
    for i in range(len(S) - len(T) + 1):
        X = S[i:i+sizeX]
        for j in range(sizeX):
            if X[j] == "?" or X[j] == T[j]:
                if j == sizeX - 1:
                    ans.append(padding(S, T, i))
            else:
                break

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

Submission status: Wrong Answer

Solution code:
def padding(S, T, i):
    ans = S[:i] + T + S[i+len(X):]
    print(ans.replace("?","a"))
    return

if __name__ == '__main__':
    
    S = input()
    T = input()

    if len(S) < len(T):
        print("UNRESTORABLE")
        exit(0)

    sizeX = len(T)
    for i in range(len(S) - len(T) + 1):
        X = S[i:i+sizeX]
        for j in range(sizeX):
            if X[j] == "?" or X[j] == T[j]:
                if j == sizeX - 1:
                    padding(S, T, i)
                    exit(0)
            else:
                break

    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def padding(S, T, i):
    ans = S[:i] + T + S[i+len(X):]
    print(ans.replace("?","a"))
    return

if __name__ == '__main__':
    
    S = input()
    T = input()

    if len(S) < len(T):
        print("UNRESTORABLE")

    sizeX = len(T)
    for i in range(len(S) - len(T) + 1):
        X = S[i:i+sizeX]
        for j in range(sizeX):
            if X[j] == "?" or X[j] == T[j]:
                if j == sizeX - 1:
                    padding(S, T, i)
                    exit(0)
            else:
                break
            


    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def padding(S, T, i):
    ans = S[:i] + T + S[i+len(X):]
    print(ans.replace("?","a"))
    return

if __name__ == '__main__':
    
    S = input()
    T = input()

    sizeX = len(T)
    for i in range(len(S) - len(T) + 1):
        X = S[i:i+sizeX]
        for j in range(sizeX):
            if X[j] == "?" or X[j] == T[j]:
                if j == sizeX - 1:
                    padding(S, T, i)
                    exit(0)
            else:
                break
            


    print("UNRESTORABLE")

Submission status: Wrong Answer

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    partly_s = input()
    t = input()
    partly_t = t[0]
    question_marks = '?' * (len(t) - 1)
    virtual_s = partly_t + question_marks

    if (len(partly_s) > len(t)) and (virtual_s in partly_s):
        s = partly_s.replace(virtual_s, t)
    else:
        print('UNRESTORABLE')
        exit()

    if s.count('?') > 0:
        print(s.replace('?', 'a'))

Submission status: Wrong Answer

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

# AtCoder Beginner Contest
# Problem C

if __name__ == '__main__':
    partly_s = input()
    t = input()
    question_marks = '?' * (len(t) - 1)
    partly_t = t[0]

    if (partly_t in partly_s) and (question_marks in partly_s):
        s = partly_s.replace(partly_t + question_marks, t)
    else:
        print('UNRESTORABLE')
        exit()

    if s.count('?') > 0:
        print(s.replace('?', 'a'))

Submission status: Wrong Answer

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

slen=len(S)
hlen=len(H)

ans=False
for i in range(slen-hlen):
  jud=True
  for j in range(hlen):
    if S[i+j]!='?' and S[i+j]!=H[j]:
      jud=False
      break
  if jud:
    S=S[:i]+H+S[i+hlen:]
    ans=True
if ans:
  S=S.replace('?','a')
  print(S)
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:

S_=input()
T=input()
Size=len(S_)
size=len(T)


def SaT(Size,size,S_,T):
    for i in range(Size-size+1):
        for j in range(size):
          #  print(S_[i+j],T[j])
            if S_[i+j]!=T[j] and S_[i+j]!="?":
                break
            if j==size-1:
                S_=(S_[:i]+T+S_[i+j+1:]).replace("?","a")
                return S_                 
            
        
    S_="UNRESTORABLE"
    return S_

print(SaT(Size,size,S_,T))

Submission status: Wrong Answer

Solution code:

S_=input()
T=input()
Size=len(S_)
size=len(T)


def SaT(Size,size,S_,T):
    for i in range(Size-size+1):
        temp=""
        for j in range(size):
            if S_[i+j]==T[j] or S_[i+j]=="?":
                temp+=S_[i+j]
            else:break
            if j==size-1:
                S_=S_.replace(temp,T)
                S_=S_.replace("?","a")
                return S_                 
            
        
    S_="UNRESTORABLE"
    return S_

print(SaT(Size,size,S_,T))

Submission status: Wrong Answer

Solution code:

S_=input()
T=input()
Size=len(S_)
size=len(T)


def SaT(Size,size,S_,T):
    for i in range(Size-size+1):
        temp=""
        for j in range(size):
            print(S_[i+j],T[j])
            if S_[i+j]==T[j] or S_[i+j]=="?":
                temp+=S_[i+j]
            else:break
            if j==size-1:
                S_=S_.replace(temp,T)
                S_=S_.replace("?","a")
                return S_                 
            
        
    S_="UNRESTORABLE"
    return S_

print(SaT(Size,size,S_,T))

Submission status: Wrong Answer

Solution code:
import re

def restore(s, t):
    possibilities = []
    for i in range(len(t)):
        password = s[:]
        m = None
        regex = re.compile(r'(' + t[0:i] + '\?{' + str(len(t[i:])) + '})')
        for m in re.finditer(regex, s):
            password = password[0:m.start()] + 'a' * len(t) + password[m.end():]
        if m:
            password = password[0:m.start()] + t + password[m.end():]
            password = re.subn('\?', 'a', password)[0]
            possibilities.append(password)
    return sorted(possibilities)[0] if possibilities else 'UNRESTORABLE'


if __name__ == '__main__':
    s = input()
    t = input()
    print(restore(s, t))

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
u=len(t)
for i in (len(s)-u,-1,-1):
    for j in range(u):
        if s[i+j]!="?" and s[i+j]!=t[j]:
            break
    else:
        print(((s[:i]+t)+s[u+i:]).replace("?","a"))
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
u=len(t)
for i in (len(s)-u,-1,-1):
    for j in range(u):
        if s[i+j]!="?" and s[i+j]!=t[j]:
            print("W")
            break
    else:
        print(((s[:i]+t)+s[u+i:]).replace("?","a"))
        break
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
unrest = "UNRESTORABLE"
S = input()
T = input()

def check(a, b):
    res = True
    for i in range(len(a)):
        if a[i] != '?' and a[i] != b[i]:
            res = False
            break
        return res

flag = False
ind = -1
for i in reversed(range(len(S) - len(T) + 1)):
    if check(S[i:i+len(T)], T):
        ind = i
        flag = True
        break


if flag:
    ans = ""
    for i in range(len(S)):
        if i >= ind and i < ind + len(T):
            ans += T[i - ind]
        else:
            if S[i] == '?':
                ans += "a"
            else:
                ans += S[i]
    print(ans)
else:
    print(unrest)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ans = ""
if t in s:
    ans = s
else:
    for i in range(len(s) - len(t) + 1):
        if s[i] in [t[0],"?"]:
            if all([s[i + j] in [t[j], "?"]for j in range(len(t))]):
                ans = s[:i] + t + s[i + len(t):]
                break

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

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
def match(x,y):
    if x==y or y=='?':
        return 1
    else:
        return 0
S=input()
T=input()
U=""

candidate=[]
count=0

for i in range(len(S)-len(T)+1):#Sの上を走る時のスタート地点
    for j in range(len(T)):#Tの上を走る
        if match(T[j],S[i+j]):
            count+=1
        else:
            count=0
            break#一つでも違ったら次のiへ
    if count==len(T):
        count=0
        U=S[:i]+T+S[i+len(T):]
        U=U.replace('?','a')
        candidate.append(U)
        
if len(candidate)==0:
    print('UNRESTORABLE')
else:
    candidate.sort
    print(candidate[0])

Submission status: Wrong Answer

Solution code:
def match(x,y):
    if x==y or y=='?':
        return 1
    else:
        return 0
S=input()
T=input()
U=""

candidate=[]
count=0
if len(S)<len(T):
    print('UNRESTORABLE')
for i in range(len(S)-len(T)+1):#Sの上を走る時のスタート地点
    for j in range(len(T)):#Tの上を走る
        if match(T[j],S[i+j]):
            count+=1
        else:
            count=0
            break#一つでも違ったら次のiへ
    if count==len(T):
        count=0
        U=S[:i]+T+S[i+len(T):]
        U=U.replace('?','a')
        candidate.append(U)
        
if len(candidate)==0:
    print('UNRESTORABLE')
else:
    candidate.sort
    print(candidate[0])

Submission status: Wrong Answer

Solution code:
def match(x,y):
    if x==y or y=='?':
        return 1
    else:
        return 0
S=input()
T=input()
U=""

candidate=[]
count=0
for i in range(0,len(S)-len(T)+1):#Sの上を走る時のスタート地点
    for j in range(len(T)):#Tの上を走る
        if match(T[j],S[i+j]):
            count+=1
        else:
            count=0
            break#一つでも違ったら次のiへ
    if count==len(T):
        count=0
        U=S[:i]+T+S[i+len(T):]
        U=U.replace('?','a')
        candidate.append(U)
        
if len(candidate)==0:
    print('UNRESTORABLE')
else:
    candidate.sort
    print(candidate[0])

Submission status: Wrong Answer

Solution code:
def match(x,y):
    if x==y or y=='?':
        return 1
    else:
        return 0
S=input()
T=input()
U=""
V=S[::]
S=S[::-1]
T=T[::-1]
candidate=[]
count=0
for j in range(0,len(S)-len(T)+1):
    for i in range(len(T)):
        if match(T[i],S[i+j]):
            count+=1
        else:
            count=0
            break
    if count==len(T):
        for k in range(len(T)):
            S=S.replace(S[k+j],T[k],1)
            U=S       
        U=U.replace('?','a')
        U=U[::-1]
        count=0
        S=V
        candidate.append(U)
    else:
        count=0
if len(candidate)==0:
    print('UNRESTORABLE')
else:
    print(sorted(candidate)[0])

Submission status: Wrong Answer

Solution code:
def match(x,y):
    if x==y or y=='?':
        return 1
    else:
        return 0
S=input()
T=input()
U=""
V=S[::]
S=S[::-1]
T=T[::-1]
candidate=[]
count=0
for j in range(0,len(S)-len(T)+1):
    for i in range(len(T)):
        if match(T[i],S[i+j]):
            count+=1
        else:
            count=0
            break
    if count==len(T):
        for k in range(len(T)):
            S=S.replace(S[k+j],T[k],1)
            U=S       
        U=U.replace('?','a')
        U=U[::-1]
        count=0
        S=V
        candidate.append(U)
        

    else:
        count=0
if len(candidate)==0:
    print('UNRESTORABLE')
else:
    candidate.sort
    print(candidate[0])

Submission status: Wrong Answer

Solution code:
def match(x,y):
    if x==y or y=='?':
        return 1
    else:
        return 0
S=input()
T=input()
U=''
S=S[::-1]
T=T[::-1]
candidate=[]
count=0
for j in range(0,len(S)-len(T)+1):
    for i in range(len(T)):
        if match(T[i],S[i+j]):
            count+=1
        else:
            count=0
            break
    if count==len(T):
        for k in range(len(T)):
            U=S.replace(S[k+j],T[k],1)
        U=S.replace('?','a')
        U=U[::-1]
        count=0
        candidate.append(U)
        print(U)

    else:
        count=0
if len(candidate)==0:
    print('UNRESTORABLE')
else:
    candidate.sort
    print(candidate[0])

Submission status: Wrong Answer

Solution code:
def match(x,y):
    if x==y or y=='?':
        return 1
    else:
        return 0
S=input()
T=input()
S=S[::-1]
T=T[::-1]
candidate=[]
count=0
for j in range(0,len(S)-len(T)+1):
    for i in range(len(T)):
        if match(T[i],S[i+j]):
            count+=1
        else:
            count=0
            break
    if count==len(T):
        for k in range(len(T)):
            S=S.replace(S[k+j],T[k],1)
        S=S.replace('?','a')
        S=S[::-1]
        count=0
        candidate.append(S)
    else:
        count=0
if len(candidate)==0:
    print('UNRESTORABLE')
else:
    candidate.sort
    print(candidate[0])

Submission status: Wrong Answer

Solution code:
def match(x,y):
    if x==y or y=='?':
        return 1
    else:
        return 0
S=input()
T=input()
S=S[::-1]
T=T[::-1]

count=0
for j in range(0,len(S)-len(T)+1):
    for i in range(len(T)):
        if match(T[i],S[i+j]):
            count+=1
        else:
            count=0
            break
    if count==len(T):
        for k in range(len(T)):
            S=S.replace(S[k+j],T[k],1)
        S=S.replace('?','a')
        print(S[::-1])
        exit()
    else:
        count=0
print('UNRESTRABLE')

Submission status: Wrong Answer

Solution code:
def match(x,y):
    if x==y or y=='?':
        return 1
    else:
        return 0
S=input()
T=input()
S=S[::-1]
T=T[::-1]

count=0
for j in range(0,len(S)-len(T)):
    for i in range(len(T)):
        if match(T[i],S[i+j]):
            count+=1
        else:
            count=0
            break
    if count==len(T):
        for k in range(len(T)):
            S=S.replace(S[k+j],T[k],1)
        S=S.replace('?','a')
        print(S[::-1])
        exit()
    else:
        count=0
print('UNRESTRABLE')

Submission status: Wrong Answer

Solution code:
def match(x,y):
    if x==y or y=='?':
        return 1
    else:
        return 0
S=input()
T=input()
S=S[::-1]
T=T[::-1]

count=0
for j in range(0,len(S)-len(T)):
    for i in range(len(T)):
        if match(T[i],S[i+j]):
            count+=1
        else:
            break
    if count==len(T):
        for k in range(len(T)):
            S=S.replace(S[k+j],T[k],1)
        U=S.replace('?','a')
        print(U[::-1])
        exit()
    else:
        count=0
print('UNRESTRABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
cand = []
if len(s) < len(t):
  print('UNRESTORABLE')
elif s.count('?') == 0:
  if t in s:
    print(s)
  else:
    print('UNRESTORABLE')
else:
  for i in range(len(s)-len(t)+1):
    if s[i] != t[0] and s[i] != '?':
      continue
    else:
      for j in range(1,len(t)):
        if s[i+j] != t[j] and s[i+j] != '?':
          break
        elif j == (len(t)-1):
          cand.append(i)
  if len(cand) > 0:
    result = max(cand)
    S = s[:result]+t+s[result+len(t):]
    S = S.replace('?','a')
    print(S)
  else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
cand = []
if len(s) < len(t):
  print('UNRESTORABLE')
else:
  for i in range(len(s)-len(t)+1):
    if s[i] != t[0] and s[i] != '?':
      continue
    else:
      for j in range(1,len(t)):
        if s[i+j] != t[j] and s[i+j] != '?':
          break
        elif j == (len(t)-1):
          cand.append(i)
  if len(cand) > 0:
    result = max(cand)
    S = s[:result]+t+s[result+len(t):]
    S = S.replace('?','a')
    print(S)
  else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

cnt = 0
for i in range(len(S)):
    is_ok = True
    for j in range(len(T)):
        if i + j >= len(S):
            is_ok = False
            break
        if S[i + j] != '?' and S[i + j] != T[j]:
            is_ok = False
            break
    if is_ok:
        S = S.replace('?', 'a')
        print(S[:i] + T + S[i + len(T):])
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

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

cnt = 0
for i, s in enumerate(S[::-1]):
    if s == '?' or s == T[::-1][cnt]:
        cnt += 1

        if cnt == len(T):
            S = S.replace('?', 'a')
            li = len(S) - i -1
            print(S[:li] + T + S[li+len(T):])

            exit()
    else:
        cnt = 0
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
if len(s) < len(t):
  print('UNRESTORABLE')
elif s.count('?') == 0:
  if s.count(t) > 0:
    print(s)
  else:
    print('UNRESTORABLE')  
else:
  work = list(s[::1])
  result = ''
  for i in range(len(t)):
    if t[i] in s:
      x  = s.index(t[i])
    else:
      continue
    flg = True
    if i <= x and (len(t) - i)<= (len(s) -x):
      for j in range(1,i):
        if s[x-j] != '?':
          flg = False
          break
      if flg:
        for k in range(1,len(t)-i):
          if s[x+k] != t[i+k] and s[x+k] !='?':
            flg = False
            break
      if flg:
        counter = 0
        for z in range(x-i,x+len(t)-i):
          work[z] = t[counter]
          counter += 1
        result = ''.join(work)
        result = result.replace('?','a')        
        break
  if result != '':
    print(result)
  else:
    blocks = [0]*(len(s)+1)
    for x in range(len(s)):
      if s[x] == '?':
        blocks[x] += 1
      else:
        blocks[x] -= 50 
    for y in range(len(s)):
      blocks[y+1] +=blocks[y]
    for z in range(len(s)-1,0,-1):
      if len(t) <= blocks[z]:
        counter = 0
        for A in range(z-len(t)+1,z+1):
          work[A] = t[counter]
          counter += 1
        result = ''.join(work)
        result = result.replace('?','a')
        print(result)
        break
    if result == '':
      print('UNRESTORABLE')