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()
code = S
match = 0
maxmatch = 0
maxmatchloc = 0
hasmatch = False
if (len(T) <= len(S)):
        for x in range(len(S)-(len(T)-1)):
            match = 0
            for i in range(len(T)):                
                if (S[x+i] == T[i]):
                    match += 1
                if (S[x+i] != T[i] and S[x+i] != '?'):
                    maxmatch = -1
                    break
            if (maxmatch == -1 and hasmatch == False):
                continue
            #if match
            if (match >= maxmatch and maxmatch != -1 and match < len(T)):
                hasmatch = True 
                maxmatch = match
                maxmatchloc = x
        #Building the code#
        for x in range(len(S)):
            if (S[x] == '?'):
                code = code[:x] + 'a' + code[x+1:] 
        if (maxmatch == 0):
            code = code[:len(S)-len(T)] + T
            print(code)
        elif(maxmatchloc >= 0):
            code = code[:maxmatchloc] + T + code[maxmatchloc + len(T):]
            print(code)
        elif(maxmatchloc == -1):
            print('UNRESTORABLE')
        else:
            print('UNRESTORABLE')
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
code = S
match = 0
maxmatch = 0
maxmatchloc = -1
hasmatch = False
if (len(T) <= len(S)):
        for x in range(len(S)-(len(T)-1)):
            match = 0
            for i in range(len(T)):                
                if (S[x+i] == T[i]):
                    if (maxmatch == -1):
                        maxmatch = 0
                    match += 1
                if (S[x+i] != T[i] and S[x+i] != '?'):
                    maxmatch = -1
                    break
            if (maxmatch == -1 and hasmatch == False):
                continue
            #if match
            if (match >= maxmatch and maxmatch != -1 and match < len(T)):
                hasmatch = True 
                maxmatch = match
                maxmatchloc = x
        #Building the code#
        for x in range(len(S)):
            if (S[x] == '?'):
                code = code[:x] + 'a' + code[x+1:] 
        if (maxmatch == 0):
            code = code[:len(S)-len(T)] + T
            print(code)
        elif(maxmatchloc >= 0):
            code = code[:maxmatchloc] + T + code[maxmatchloc + len(T):]
            print(code)
        elif(maxmatchloc == -1):
            print('UNRESTORABLE')
        else:
            print('UNRESTORABLE')
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
code = S
match = 0
maxmatch = 0
maxmatchloc = -1
hasmatch = False
if (len(T) <= len(S)):
        for x in range(len(S)-(len(T)-1)):
            match = 0
            for i in range(len(T)):                
                if (S[x+i] == T[i]):
                    if (maxmatch == -1):
                        maxmatch = 0
                    match += 1
                if (S[x+i] != T[i] and S[x+i] != '?'):
                    maxmatch = -1
                    break
            if (maxmatch == -1 and hasmatch == False):
                continue
            #if match
            if (match >= maxmatch and match < len(T)):
                hasmatch = True 
                maxmatch = match
                maxmatchloc = x
        #Building the code#
        for x in range(len(S)):
            if (S[x] == '?'):
                code = code[:x] + 'a' + code[x+1:] 
        if (maxmatch == 0):
            code = code[:len(S)-len(T)] + T
            print(code)
        elif(maxmatchloc >= 0):
            code = code[:maxmatchloc] + T + code[maxmatchloc + len(T):]
            print(code)
        elif(maxmatchloc == -1):
            print('UNRESTORABLE')
        else:
            print('UNRESTORABLE')
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
code = S
match = 0
maxmatch = 0
maxmatchloc = -1
hasmatch = False
if (len(T) <= len(S)):
        for x in range(len(S)-(len(T)-1)):
            match = 0
            for i in range(len(T)):                
                if (S[x+i] == T[i]):
                    if (maxmatch == -1):
                        maxmatch = 0
                    match += 1
                if (S[x+i] != T[i] and S[x+i] != '?'):
                    maxmatch = -1
                    break
            if (maxmatch == -1 and hasmatch == False):
                continue
            #if match
            if (match >= maxmatch and maxmatch != -1 and match < len(T)):
                hasmatch = True 
                maxmatch = match
                maxmatchloc = x
        #Building the code#
        for x in range(len(S)):
            if (S[x] == '?'):
                code = code[:x] + 'a' + code[x+1:] 
        if (maxmatch == 0):
            code = code[:len(S)-len(T)] + T
            print(code)
        elif(maxmatchloc >= 0):
            code = code[:maxmatchloc] + T + code[maxmatchloc + len(T):]
            print(code)
        elif(maxmatchloc == -1):
            print('UNRESTORABLE')
        else:
            print('UNRESTORABLE')
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
code = S
match = 0
maxmatch = 0
maxmatchloc = -1
if (len(T) <= len(S)):
        for x in range(len(S)-(len(T)-1)):
            match = 0
            for i in range(len(T)):                
                if (S[x+i] == T[i]):
                    if (maxmatch == -1):
                        maxmatch = 0
                    match += 1
                if (S[x+i] != T[i] and S[x+i] != '?'):
                    maxmatch = -1
                    continue
            if (maxmatch == -1):
                continue
            #if match
            if (match >= maxmatch and maxmatch != -1 and match < len(T)):
                maxmatch = match
                maxmatchloc = x
        #Building the code#
        for x in range(len(S)):
            if (S[x] == '?'):
                code = code[:x] + 'a' + code[x+1:] 
        if (maxmatch == 0):
            code = code[:len(S)-len(T)] + T
            print(code)
        elif(maxmatchloc >= 0):
            code = code[:maxmatchloc] + T + code[maxmatchloc + len(T):]
            print(code)
        elif(maxmatchloc == -1):
            print('UNRESTORABLE')
        else:
            print('UNRESTORABLE')
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
code = S
match = 0
maxmatch = 0
maxmatchloc = -1
if (len(T) <= len(S)):
        for x in range(len(S)-(len(T)-1)):
            
            match = 0
            for i in range(len(T)):
                if (S[x+i] == T[i]):
                    if (match == -1):
                        match = 0
                    match += 1
                if (S[x+i] != T[i] and S[x+i] != '?'):
                    maxmatch = -1
                    continue
            if (maxmatch == -1):
                continue
            #if match
            if (match >= maxmatch and maxmatch != -1 and match < len(T)):
                maxmatch = match
                maxmatchloc = x
        #Building the code#
        for x in range(len(S)):
            if (S[x] == '?'):
                code = code[:x] + 'a' + code[x+1:] 
        if (maxmatch == 0):
            code = code[:len(S)-len(T)] + T
            print(code)
        elif(maxmatchloc >= 0):
            code = code[:maxmatchloc] + T + code[maxmatchloc + len(T):]
            print(code)
        elif(maxmatchloc == -1):
            print('UNRESTORABLE')
        else:
            print('UNRESTORABLE')
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
code = S
match = 0
maxmatchloc = 0
if (len(T) <= len(S)):
        for x in range(len(S)-(len(T)-1)):
            match = 0
            for i in range(len(T)):
                if (S[x+i] == T[i]):
                    match += 1
                if (S[x+i] != T[i] and S[x+i] != '?'):
                    match = -1
                    break
            if (match == -1):
                maxmatchloc = -1
                break
            if (match >= maxmatchloc and match < len(T)):
                maxmatchloc = x
        #Building the code#
        for x in range(len(S)):
            if (S[x] == '?'):
                code = code[:x] + 'a' + code[x+1:] 
        if (maxmatchloc == 0):
            code = code[:len(S)-len(T)] + T
            print(code)
        elif(maxmatchloc > 0):
            code = code[:maxmatchloc] + T + code[maxmatchloc + len(T):]
            print(code)
        elif(match == -1):
            print('UNRESTORABLE')
        else:
            print('UNRESTORABLE')
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
code = S
match = 0
maxmatchloc = 0
if (len(T) <= len(S)):
    if (S != ('?')*len(S)):
        for x in range(len(S)-(len(T)-1)):
            match = 0
            for i in range(len(T)):
                if (S[x+i] == T[i]):
                    match += 1
                if (S[x+i] != T[i] and S[x+i] != '?'):
                    match = 0
                    break
            
            if (match >= maxmatchloc and match < len(T)):
                maxmatchloc = x
        #Building the code#
        if (maxmatchloc == 0):
            print('UNRESTORABLE')
        else:
            for x in range(len(S)):
                if (S[x] == '?'):
                    code = code[:x] + 'a' + code[x+1:]
            code = code[:maxmatchloc] + T + code[maxmatchloc + len(T):]
            print(code)
    else:
        for x in range(len(S)):
            if (S[x] == '?'):
                code = code[:x] + 'a' + code[x+1:]
        code = code[:(len(S)-len(T))] + T
        print(code)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
code = S
match = 0
maxmatchloc = len(S)-len(T)
if (len(T) <= len(S)):
    for x in range(len(S)-(len(T)-1)):
        match = 0
        for i in range(len(T)):
            if (S[x+i] == T[i]):
                match += 1
            if (S[x+i] != T[i] and S[x+i] != '?'):
                match = 0
                break
        if (match >= maxmatchloc and match != (len(T))):
            maxmatchloc = x

    #Building the code#
    if (maxmatchloc == 0):
        print('UNRESTORABLE')
    else:
        for x in range(len(S)):
            if (S[x] == '?'):
                code = code[:x] + 'a' + code[x+1:]
        code = code[:maxmatchloc] + T + code[maxmatchloc + len(T):]
        print(code)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
##Hint for matching: We get the one that has the most match

#For each space in the interval: Match each blank and count it (The T is given to have at most n-1 matches where n is the length of T)

#For absolute match: it has n-1 matches
#For local match: it has the maximum matches

#For no match: The T belongs to the last

#The code is unrestorable if:
    #1) T > S
    #2) code doesn't fit anywhere(?)

S = input()
T = input()
code = S
match = 0
maxmatchloc = 0
if (len(T) <= len(S)):
    for x in range(len(S)-(len(T)-1)):
        match = 0
        for i in range(len(T)):
            if (S[x+i] == T[i]):
                match += 1
            if (S[x+i] != T[i] and S[x+i] != '?'):
                match = 0
                break
        if (match >= maxmatchloc and match != (len(T))):
            maxmatchloc = x

    #Building the code#
    if (maxmatchloc == 0):
        print('UNRESTORABLE')
    else:
        for x in range(len(S)):
            if (S[x] == '?'):
                code = code[:x] + 'a' + code[x+1:]
        code = code[:maxmatchloc] + T + code[maxmatchloc + len(T):]
        print(code)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
code = S
 
if (len(T) <= len(S)):
    for x in range(len(S)):
        if (S[x] == '?'):
            code = code[:x] + 'a' + code[x+1:]
    for x in range(len(S)-(len(T)-1),-1,-1):
        if (x == -1):
            print('UNRESTORABLE')
        elif (S[x:x+len(T)] == (('?')*len(T)) or (S[x:x+len(T)] == ( T[0] + (('?')*(len(T)-1))))):
            code = code[:x] + T + code[x+len(T):]
            print(code)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
li=[]
for i in reversed(range(len(S)-len(T)+1)):
    st=S[i:i+len(T)]
    t=True
    for j in range(len(T)):
        if(st[j]!='?' and st[j]!=T[j]):
            t=False
            break
    if(t):
        tmp=S.replace('?','a')
        li.append(tmp[:i]+T+tmp[i+len(T):])
if(li):
    print(sorted(li)[0])
else:
    print("UNRESTORABLE")
print(li)

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
ans=[0 for _ in range(len(s))]
for i in range(len(s)-len(t)+1):
    cnt=0
    for j in range(len(t)):
        if s[i+j]=='?' or s[i+j]==t[j]:
            cnt+=1
    if cnt==len(t):
        ans[i]=i
mark=ans.index(max(ans))
if sum(ans)!=0:
    for j in range(len(s)):
        if mark<=j and j<mark+len(t):
            s[j]=t[j-mark]
        elif s[j]=='?':
            s[j]='a'
    print(''.join(s))
else:print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys
from math import *
from collections import deque, Counter, defaultdict
from fractions import gcd
input = lambda: sys.stdin.readline().rstrip()

def eprint(s):
    sys.stderr.write('DEBUG: {}'.format(s))
    return

def check(sp, s):
    
    for i in range(len(s)):
        if sp[i] != '?' and s[i] is not None and sp[i] != s[i]:
            
            return False
    return True

def main():
    sp = input()
    n = len(sp)
    t = input()
    s = [None] * n

    for i in range(n):
        if sp[i] != '?':
            s[i] = sp[i]

    # i~ i+len(t)文字目までをtとした場合
    for i in range(n-len(t)+1):
        p = [None]*n
        for j in range(len(t)):
            p[i+j] = t[j]
        if check(sp, p):
            ans = str()
            for i in range(n):
                if p[i] is None:
                    if sp[i] == '?':
                        ans += 'a'
                    else:
                        ans += sp[i]
                else:
                    ans += p[i]
            print(ans)
            return
    print('UNRESTORABLE')
    return
            

    #print(check(sp, 'atcoder'))

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys

DEBUG = False


def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().rstrip().split(sep)]

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

def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return

def solve(s, t):
    if len(t) > len(s):
        return None
    ans = None
    for i in range(0, len(s)):
        can_insert = True
        for j in range(0, len(t)):
            pos = i + j
            if pos >= len(s) or (s[pos] != '?' and s[pos] != t[j]):
                can_insert = False
                break
        if not can_insert:
            continue
        inserted = s[0:i] + t + s[i + len(t):]
        inserted = inserted.replace("?", "a")
        if len(inserted) != len(s):
            raise "hoge"
        if ans is None or inserted < ans:
            ans = inserted
    if ans is None:
        return "UNRESTORABLE"
    return ans


def main():
    s = sys.stdin.readline().rstrip()
    t = sys.stdin.readline().rstrip()
    print(solve(s, t))
    



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys

DEBUG = False


def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().rstrip().split(sep)]

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

def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return

def solve(s, t):
    if len(t) > len(s):
        return None
    ans = None
    for i in range(0, len(s)):
        can_insert = True
        for j in range(0, len(t)):
            pos = i + j
            if pos >= len(s) or (s[pos] != '?' and s[pos] != t[j]):
                can_insert = False
                break
        if not can_insert:
            continue
        inserted = s[0:i] + t + s[i + len(t):]
        inserted = inserted.replace("?", "a")
        if ans is None or inserted < ans:
            ans = inserted
    if ans is None:
        return "UNRESTORABLE"
    return ans


def main():
    s = sys.stdin.readline().rstrip()
    t = sys.stdin.readline().rstrip()
    print(solve(s, t))
    



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3

import sys

DEBUG = False


def read_int_list(sep = " "):
    return [int(s) for s in sys.stdin.readline().rstrip().split(sep)]

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

def dprint(*args, **kwargs):
    if DEBUG:
        print(*args, **kwargs)
    return

def solve(s, t):
    if len(t) > len(s):
        return None
    ans = None
    for i in range(0, len(s) - len(t) + 1):
        can_insert = True
        for j in range(0, len(t)):
            pos = i + j
            if s[pos] != '?' and s[pos] != t[j]:
                can_insert = False
                break
        if not can_insert:
            continue
        inserted = s[0:i] + t + s[i + len(t) + 1:]
        inserted = inserted.replace("?", "a")
        if ans is None or inserted < ans:
            ans = inserted
    if ans is None:
        return "UNRESTORABLE"
    return ans


def main():
    s = sys.stdin.readline().rstrip()
    t = sys.stdin.readline().rstrip()
    print(solve(s, t))
    



if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S = input()[::-1]
T = input()[::-1]
Flg = False

pos = ""
num = 0
for i in range(len(S)-len(T)+1):
    sl = ""
    sl = S[i:(i+len(T))]
    for j in range(len(T)):
        pos = ""
        if(sl[j] == T[j]):
            if(sl.count("?") >= len(T)-1):
                pos += S[:i]+T+S[(i+len(T)):]
                ans1 = pos[::-1]
                Flg = True
                quit()
                
if(Flg == True):
    ans1 = ans1.replace("?", "a") 
    print(ans1)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()[::-1]
T = input()[::-1]
Flg = False

ans1 = "z"*len(S)
pos = ""
num = 0
for i in range(len(S)-len(T)+1):
    sl = ""
    sl = S[i:(i+len(T))]
    for j in range(len(T)):
        pos = ""
        if(sl[j] == T[j]):
            if(sl.count("?") >= len(T)-1):
                pos += S[:i]+T+S[(i+len(T)):]
                pos = pos[::-1]
                Flg = True
                if(pos < ans1):
                    ans1 = pos
if(Flg == True):
    ans1 = ans1.replace("?", "a") 
    print(ans1)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

ans1 = "z"*len(S)
pos = ""
num = 0
for i in range(len(S)-len(T)+1):
    sl = ""
    sl = S[i:(i+len(T))]
    for j in range(len(T)):
        pos = ""
        if(sl[j] == T[j]):
            if(sl.count("?") >= len(T)-1):
                pos += S[:i]+T+S[(i+len(T)):]
                Flg = True
                if(pos < ans1):
                    ans1 = pos
if(Flg == True):
    ans = ""                        
    for i in range(len(S)):
        if(ans1[i] == "?"):
            ans += "a"
        else:
            ans += ans1[i]
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def check(a, b):
    for j in range(len(a)):
        if b[j] == a[j] or a[j] == '?':
            continue
        else:
            return False
    return True


s_prime = input()
t = input()
for i in range(len(s_prime) - len(t) + 1):
    if check(s_prime[i:i+len(t)], t):
        s = s_prime[:i] + t + s_prime[i+len(t):]
        ans = s.replace('?', 'a')
        print(ans)
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
flag = False 
for i in range(len(s)-len(t)+1):
  st = False
  for j in range(len(t)):
    if j==0 and st==False and (s[i+j]==t[j] or s[i+j]=='?'):
      st = True 
    elif st==True and (s[i+j]==t[j] or s[i+j]=='?'):
      pass 
    elif st==True and (s[i+j]!=t[j] and s[i+j]!='?'):
      st = False 
      break 

  if st:
    s[i:i+len(t)] = t 
    flag = True
    break

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

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

print(''.join(s))

Submission status: Wrong Answer

Solution code:
def matching(s,t):
    ret = True
    for s_, t_ in zip(s,t):
        if not (s_ == t_ or s_ == '?'):
            ret = False
            break
            
    return ret

def solve():
    S = input()
    T = input()
    L_S = len(S)
    L_T = len(T)
    pos = -1
    match = False
    for i in range(L_S-L_T+1):
        # print(S[i:i+L_T],T)
        if matching(S[i:i+L_T],T):
            pos = i
            break
            
    if pos >= 0:
        result = ''.join(list(map(lambda x: 'a' if x=='?' else x, S)))
        print(result[:pos]+T+result[pos+L_T:])
    else:
        print('UNRESTORABLE')
        
solve()

Submission status: Wrong Answer

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

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

for i in range(len(s) - len(t), -1, -1):
  if not match(i):
    continue

  for j in range(i):
    print('a' if s[j] == '?' else s[j], end='')
  print(t, end='')
  for j in range(i+len(t), len(s)):
    print(s[j], end='')
  print()
  exit()
    
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
checker = 0
for i in range(len(s)-len(t)+1):
    if all(s[i+j]==t[j] or s[i+j]=="?" for j in range(len(t))):
        checker = 1
        for j in range(len(t)):
            s[i+j] = t[j]
        s = ["a" if s[I]=="?" else s[I] for I in range(len(s))]
        break
if checker:
    print("".join(s))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
print(-1)

Submission status: Wrong Answer

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

def main():
    s = readline()
    t = readline()
    ls = len(s)
    lt = len(t)

    if ls < lt:
        print("UNRESTORABLE")
        exit()

    ind = -1
    for i in range(ls-lt+1):
        flag = True
        for j,s_ in enumerate(s[i:i+lt]):
            if s_ == "?":
                continue
            if t[j] != s_:
                flag = False
        if flag:
            ind = i
                
    if ind == -1:
        print("UNRESTORABLE")
        exit()
    
    ans = s[:ind] + t + s[ind+lt:]
    ans = ans.replace("?", "a")
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
N=len(S)
n=len(T)
S1=S
for i in range(N-n,-1,-1):
    time=0
    for j in range(i,i+n):
        if S[j]=="?":
            time+=1
            continue
        elif S[j]==T[j-i]:
            time+=1
            continue
        else:
            break
    if time==n:
        S1=S1[:i]+T+S1[i+n:]
        S1=S1.replace("?","a")
        print(S1)
if S1==S:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
for i in range(len(s)-len(t),-1,-1):
	#print (i)
	flg = True
	for j, k in enumerate(list(t)):
		#print (j, k)
		if s[i:i+len(t)][j] == "?":
			continue
		if k != s[i:i+len(t)][j]:
			flg = False
			break
	if flg == True:
		x = s[:i].replace("?","a") + t + s[i+len(t):]
		print (x)
		exit()
print ("UNRESTORABLE")

Submission status: Wrong Answer

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

ans=[]
for i in range(len(s)-len(t)+1):
    kouho=[]
    match=True

    for pre in range(i):
        if s[pre]=="?":
            kouho.append("a")
        else:
            kouho.append(s[pre])

    for j in range(len(t)):
        if s[i+j]=="?":
            kouho.append(t[j])
        elif s[i+j] == t[j]:
            kouho.append(t[j])
        else:
            match=False
            break

    for post in range(i+j,len(s)-1):
        if s[post]=="?":
            kouho.append("a")
        else:
            kouho.append(s[post])
    if match:
        ans.append(kouho)
if len(ans)==0:
    print("UNRESTORABLE")
else:
    ans.sort()
    print(*ans[0],sep="")

Submission status: Wrong Answer

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

ls = len(sp)
lt = len(t)
ok = 1
s = list(sp)
for i in range(ls-1, 0, -1):
    ok = 1
    for j in range(lt):
        if i + j >= ls:
            ok = 0
            break
        if (sp[i+j] == t[j]) or (sp[i+j] == '?'):
            continue
        ok = 0
        break
    if ok == 1:
        for si in range(i, i+lt):
            s[si] = t[si - i]
        break

if ok == 1:
    print(''.join(s).replace("?", "a"))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
# coding: utf-8


def solve(*args: str) -> str:
    S, T = args
    ret = ''
    for i in range(len(S)-len(T)+1):
        ret = S[:i]

        for j in range(len(T)):
            if S[i+j] != T[j] and S[i+j] != '?':
                ret = ''
                break
            ret += T[j]

        if ret:
            ret += S[len(ret):]
            ret = ret.replace('?', 'a')
            break
        else:
            ret = 'UNRESTORABLE'

    return ret


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))

Submission status: Wrong Answer

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

ls = len(sp)
lt = len(t)
ok = 1
s = list(sp)
for i in range(ls-1, 0, -1):
    ok = 1
    for j in range(lt):
        if i + j >= ls:
            ok = 0
            break
        if (sp[i+j] == t[j]) or (sp[i+j] == '?'):
            continue
        ok = 0
        break
    if ok == 1:
        for si in range(i, i+lt):
            s[si] = t[si - i]
        break

if ok == 1:
    for i in range(ls):
        if s[i] == '?':
            s[i] = 'a'
    print(''.join(s))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

ls = len(sp)
lt = len(t)
ok = 1
s = list(sp)
for i in range(ls):
    ok = 1
    for j in range(lt):
        if i + j >= ls:
            ok = 0
            break
        if (sp[i+j] == t[j]) or (sp[i+j] == '?'):
            continue
        ok = 0
        break
    if ok == 1:
        for si in range(i, i+lt):
            s[si] = t[si - i]
        break

if ok == 1:
    for i in range(ls):
        if s[i] == '?':
            s[i] = 'a'
    print(''.join(s))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import copy
def solve():
    S_d = list(input())
    T = list(input())

    first = 0
    end = first + len(T) - 1
    while end <= len(S_d) - 1:
        t_i = 0
        for s_i in range(first, end+1):
            if T[t_i] != S_d[s_i] and S_d[s_i] != '?':
                break
            t_i += 1
        else:
            break
        first += 1
        end += 1
    else:
        print('UNRESTORABLE')
        exit(0)
    
    ans = copy.deepcopy(S_d)
    t_i = 0
    for i in range(first, end+1):
        ans[i] = T[t_i]
        t_i += 1
    
    ans = ''.join(ans).replace('?','a')
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

Solution code:
import copy
def solve():
    S_d = list(input())
    T = list(input())

    first = 0
    end = first + len(T) - 1
    while end <= len(S_d) - 1:
        t_i = 0
        for s_i in range(first, end+1):
            if T[t_i] != S_d[s_i] and S_d[s_i] != '?':
                break
            t_i += 1
        else:
            break
        first += 1
        end += 1
    else:
        print('UNRESTORABLE')
        exit(0)
    
    ans = copy.deepcopy(S_d)
    t_i = 0
    for i in range(first, end+1):
        ans[i] = T[t_i]
        t_i += 1
    print(ans)
    
    ans = ''.join(ans).replace('?','a')
    print(ans)

if __name__ == '__main__':
    solve()

Submission status: Wrong Answer

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

ans = []

for index, s in enumerate(S):
  if s == '?' or s == T[0]:
    if index+len(T)-1 > len(S)-1:
        break

    for indexs, t in enumerate(T):
      if S[index+indexs] != t and S[index+indexs] != '?':
        break
    else:
      ans.append(S[0:index]+T+S[index+len(T):])

print(ans)
if len(ans) == 0:
  print("UNRESTORABLE")
else:
  ans.sort()
  print(ans[0].replace('?', 'a'))

Submission status: Wrong Answer

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

ans = []

for index, s in enumerate(S):
  if s == '?' or s == T[0]:
    if index+len(T)-1 > len(S)-1:
        break

    for indexs, t in enumerate(T):
      if S[index+indexs] != t and S[index+indexs] != '?':
        break
    else:
      ans.append(S[0:index]+T+S[index+len(T):-1])

if len(ans) == 0:
  print("UNRESTORABLE")
else:
  ans.sort()
  print(ans[0].replace('?', 'a'))

Submission status: Wrong Answer

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

LEN_S = len(S)
LEN_T = len(T)

if LEN_S < LEN_T:
  print('UNRESTORABLE')
  exit()

def isEquals(s):
  for i in range(LEN_T):
    if T[i] == s[i] or s[i] == '?':
      pass
    else:
      return False
  return True

answers = []
for i in range(LEN_S - LEN_T+1):
  if isEquals(S[i:i+LEN_T]):
    text = S[:i] + T + S[i+LEN_T+1:]
    answers.append(text.replace('?', 'a'))
  else:
    pass

if 0 < len(answers):
  answers = sorted(answers)
  print(answers[0])
  
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

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

LEN_S = len(S)
LEN_T = len(T)

if LEN_S < LEN_T:
  print('UNRESTORABLE')
  exit()

def isEquals(s):
  for i in range(LEN_T):
    if T[i] == s[i] or s[i] == '?':
      pass
    else:
      return False
  return True

answers = []
for i in range(LEN_S - LEN_T+1):
  if isEquals(S[i:i+LEN_T]):
    text = S[:i] + T + S[i+LEN_T+1:]
    answers.append(text.replace('?', 'a'))
  else:
    pass

print(answers)

if 0 < len(answers):
  answers = sorted(answers)
  print(answers[0])
  
else:
  print('UNRESTORABLE')