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 = list(input())
N = len(S)
T = input()
list_T = list(T)
M = len(T)

S.append("@")
ans = []
i = 0

def changehatena(S):
    S = "".join(S)
    S = S.replace("?", "a")
    return S

for i in range(N):
    hatena_num = 0
    if S[i] == "?":
        hatena_num = 1
        for j in range(i+1, N+1):
            if S[j] == "?":
                hatena_num += 1
                if hatena_num == M:
                    # print("!?",i,j, hatena_num)
                    tmp = S[:]
                    tmp[i:j+1] = list_T
                    tmp = changehatena(tmp)
                    # print(tmp)
                    if T in tmp:
                        ans.append(tmp)
                    break
            else:
                if hatena_num == M-1:
                    #codeを入れる
                    tmp = S[:]
                    tmp[i:j] = list_T[:-1]
                    tmp = changehatena(tmp)
                    # print(i, "code", tmp)
                    if T in tmp:
                        ans.append(tmp)
                    #oderを入れる
                    tmp = S[:]
                    tmp[i:j] = list_T[1:]
                    tmp = changehatena(tmp)
                    # print(i, "oder", tmp)
                    if T in tmp:
                        ans.append(tmp)
                elif hatena_num == M-2:
                    #odeを入れる
                    tmp = S[:]
                    tmp[i:j] = list_T[1:-1]
                    tmp = changehatena(tmp)
                    # print(i, "ode", tmp)
                    if T in tmp:
                        ans.append(tmp)
                break

if ans:
    ans.sort()
    print(ans[0][:-1])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
T = input()
list_T = list(T)
M = len(T)

S.append("@")
ans = []
i = 0

def changehatena(S):
    S = "".join(S)
    S = S.replace("?", "a")
    return S

for i in range(N):
    hatena_num = 0
    if S[i] == "?":
        hatena_num = 1
        for j in range(i+1, N):
            if S[j] == "?":
                hatena_num += 1
                if hatena_num == M:
                    tmp = S[:]
                    tmp[i:j+1] = list_T
                    tmp = changehatena(tmp)
                    if T in tmp:
                        ans.append(tmp)
                    break
            else:
                if hatena_num == M-1:
                    #codeを入れる
                    tmp = S[:]
                    tmp[i:j] = list_T[:-1]
                    tmp = changehatena(tmp)
                    if T in tmp:
                        ans.append(tmp)
                    #oderを入れる
                    tmp = S[:]
                    tmp[i:j] = list_T[1:]
                    tmp = changehatena(tmp)
                    if T in tmp:
                        ans.append(tmp)
                elif hatena_num == M-2:
                    #odeを入れる
                    tmp = S[:]
                    tmp[i:j] = list_T[1:-1]
                    tmp = changehatena(tmp)
                    if T in tmp:
                        ans.append(tmp)

if ans:
    ans.sort()
    print(ans[0][:-1])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
T = input()
M = len(T)

S.append("@")

ans = []
i = 0

def changehatena(S):
    S = "".join(S)
    S = S.replace("?", "a")
    return S

while i < N:
    # print(i)
    hatena_num = 0
    if S[i] == "?":
        hatena_num = 1
        for j in range(i+1, N+1):
            if S[j] == "?":
                hatena_num += 1
                continue
            else:
                if hatena_num >= M:
                    tmp = S[:]
                    tmp[i:i+M] = T
                    tmp = changehatena(tmp)
                    # print(tmp)
                    # print(1, tmp, "i:", i,"hatena_num",hatena_num, "j", j)
                    if T in tmp:
                        ans.append(tmp)
                elif hatena_num == M-1:
                    tmp = S[:]
                    tmp[i:i+M-1] = T[:M-1]
                    tmp = changehatena(tmp)
                    if T in tmp:
                        ans.append(tmp)
                    tmp = S[:]
                    tmp[i+1:i+M] = T[1:]
                    tmp = changehatena(tmp)
                    # print(tmp)
                    # print(2, tmp, "i:", i,"hatena_num",hatena_num)
                    if T in tmp:
                        ans.append(tmp)
                elif hatena_num == M-2:
                    tmp = S[:]
                    tmp[i:i+M-1] = T[1:M-1]
                    tmp = changehatena(tmp)
                    # print(tmp)
                    # print(3, tmp, "i:", i, "j", j, "hatena_num",hatena_num)
                    if T in tmp:
                        ans.append(tmp)
                else:
                    break
        i += 1
    else:
        i += 1
if ans:
    ans.sort()
    print(ans[0][:-1])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
T = input()
M = len(T)

ans = "UNRESTORABLE"

def changehatena(S):
    S = "".join(S)
    S = S.replace("?", "a")
    return S

def check_after(S, i):
    try:
        if S[i+1] == T[-1]:
            return True
        else:
            return False
    except:
        return False

def check_before(S, i):
    if i-M+2 < 0:
        return False
    try:
        if S[i-M+2] == T[0]:
            return True
        else:
            return False
    except:
        return False


for i in reversed(range(N)):
    hatena_num = 0
    if S[i] == "?":
        hatena_num = 1
        for j in reversed(range(i)):
            if S[j] == "?":
                hatena_num += 1
            else:
                break
        if hatena_num > M-1:
            if check_after(S, i):
                # print("check1")
                tmp = 0
                for k in reversed(range(M-1)):
                    S[i-tmp] = T[k]
                    tmp += 1
                ans = changehatena(S)
                break
            elif check_before(S, i):
                # print("check2")
                tmp = 0
                for k in reversed(range(M-1)):
                    S[i-tmp] = T[k]
                    tmp += 1
                ans = changehatena(S)
                break
            tmp = 0
            for k in reversed(range(M)):
                S[i-tmp] = T[k]
                tmp += 1
            ans = changehatena(S)
            break
        elif hatena_num == M-1:
            try:
                if S[i+1] == T[-1]:
                    # print("check3")
                    tmp = 0
                    for k in reversed(range(M-1)):
                        S[i-tmp] = T[k]
                        tmp += 1
                    ans = changehatena(S)
                    break
            except:
                pass
            try:
                if S[i-M+1] == T[0]:
                    # print("check4")
                    tmp = 0
                    for k in reversed(range(1, M)):
                        S[i-tmp] = T[k]
                        tmp += 1
                    ans = changehatena(S)
                    break
            except:
                pass
        elif hatena_num == M-2:
            if check_after(S, i) and check_before(S, i):
                S[i-M+3:i+1] = T[1:-1]
                ans = changehatena(S)
                break
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
T = input()
M = len(T)

ans = "UNRESTORABLE"

def changehatena(S):
    S = "".join(S)
    S = S.replace("?", "a")
    return S

def check_after(S, i):
    try:
        if S[i+1] == T[-1]:
            return True
        else:
            return False
    except:
        return False

def check_before(S, i):
    try:
        if S[i-M+1] == T[0]:
            return True
        else:
            return False
    except:
        return False


for i in reversed(range(N)):
    hatena_num = 0
    if S[i] == "?":
        hatena_num = 1
        for j in reversed(range(i)):
            if S[j] == "?":
                hatena_num += 1
            else:
                break
        if hatena_num > M-1:
            if check_after(S, i):
                # print("check1")
                tmp = 0
                for k in reversed(range(M-1)):
                    S[i-tmp] = T[k]
                    tmp += 1
                ans = changehatena(S)
                break
            elif check_before(S, i):
                # print("check2")
                tmp = 0
                for k in reversed(range(M-1)):
                    S[i-tmp] = T[k]
                    tmp += 1
                ans = changehatena(S)
                break
            tmp = 0
            for k in reversed(range(M)):
                S[i-tmp] = T[k]
                tmp += 1
            ans = changehatena(S)
            break
        elif hatena_num == M-1:
            try:
                if S[i+1] == T[-1]:
                    # print("check3")
                    tmp = 0
                    for k in reversed(range(M-1)):
                        S[i-tmp] = T[k]
                        tmp += 1
                    ans = changehatena(S)
                    break
            except:
                pass
            try:
                if S[i-M+1] == T[0]:
                    # print("check4")
                    tmp = 0
                    for k in reversed(range(1, M)):
                        S[i-tmp] = T[k]
                        tmp += 1
                    ans = changehatena(S)
                    break
            except:
                pass
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
T = input()
M = len(T)

ans = "UNRESTORABLE"

def changehatena(S):
    S = "".join(S)
    S = S.replace("?", "a")
    return S

def check_after(S, i):
    try:
        if S[i+1] == T[-1]:
            return True
        else:
            return False
    except:
        return False

def check_before(S, i):
    try:
        if S[i-M+1] == T[0]:
            return True
        else:
            return False
    except:
        return False


for i in reversed(range(N)):
    hatena_num = 0
    if S[i] == "?":
        hatena_num = 1
        for j in reversed(range(i)):
            if S[j] == "?":
                hatena_num += 1
            else:
                break
        if hatena_num > M-1:
            if check_after(S, i):
                tmp = 0
                for k in reversed(range(M-1)):
                    S[i-tmp] = T[k]
                    tmp += 1
                print(changehatena(S))
                quit()
            elif check_before(S, i):
                tmp = 0
                for k in reversed(range(M-1)):
                    S[i-tmp] = T[k]
                    tmp += 1
                print(changehatena(S))
                quit()
            tmp = 0
            for k in reversed(range(M)):
                S[i-tmp] = T[k]
                tmp += 1
            print(changehatena(S))
            quit()
        elif hatena_num == M-1:
            try:
                if S[i+1] == T[-1]:
                    tmp = 0
                    for k in reversed(range(M-1)):
                        S[i-tmp] = T[k]
                        tmp += 1
                    print(changehatena(S))
                    quit()
            except:
                pass
            try:
                if S[i-M+1] == T[0]:
                    tmp = 0
                    for k in reversed(range(1, M)):
                        S[i-tmp] = T[k]
                        tmp += 1
                    print(changehatena(S))
                    quit()
            except:
                pass
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
T = input()
M = len(T)

ans = "UNRESTORABLE"

def changehatena(S):
    S = "".join(S)
    S = S.replace("?", "a")
    return S

for i in reversed(range(N)):
    hatena_num = 0
    if S[i] == "?":
        hatena_num = 1
        for j in reversed(range(i)):
            if S[j] == "?":
                hatena_num += 1
            else:
                break
        if hatena_num > M-1:
            tmp = 0
            for k in reversed(range(M)):
                S[i-tmp] = T[k]
                tmp += 1
            print(changehatena(S))
            quit()
        elif hatena_num == M-1:
            try:
                if S[i+1] == T[-1]:
                    tmp = 0
                    for k in reversed(range(M-1)):
                        S[i-tmp] = T[k]
                        tmp += 1
                    print(changehatena(S))
                    quit()
            except:
                pass
            try:
                if S[i-M+1] == T[0]:
                    tmp = 0
                    for k in reversed(range(1, M)):
                        S[i-tmp] = T[k]
                        tmp += 1
                    print(changehatena(S))
                    quit()
            except:
                pass
print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
N = len(S)
T = input()
M = len(T)

ans = "UNRESTORABLE"

def changehatena(S):
    S = "".join(S)
    S = S.replace("?", "a")
    return S

for i in reversed(range(N)):
    hatena_num = 0
    if S[i] == "?":
        hatena_num = 1
        for j in reversed(range(i)):
            if S[j] == "?":
                hatena_num += 1
            else:
                break
        if hatena_num > M-1:
            tmp = 0
            for k in reversed(range(M)):
                S[i-tmp] = T[k]
                tmp += 1
            ans = changehatena(S)
        elif hatena_num == M-1:
            try:
                if S[i+1] == T[-1]:
                    tmp = 0
                    for k in reversed(range(M-1)):
                        S[i-tmp] = T[k]
                        tmp += 1
                    ans = changehatena(S)
            except:
                pass
            try:
                if S[i-M+1] == T[0]:
                    tmp = 0
                    for k in reversed(range(1, M)):
                        S[i-tmp] = T[k]
                        tmp += 1
                    ans = changehatena(S)
            except:
                pass
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
s=[x for x in input()]
t=[x for x in input()]
ansi=0
ansj=0
flag=0
l=""
for i in range(len(s)):
  for j in range(len(t)):
    if s[i]==t[j] or s[i]=="?" and flag==0:
      cnt=1
      nowj=j
      nowi=i
      ansi=nowi
      ansj=nowj
      while(True):
        if nowj+1<len(t):
          nowj+=1
        else:
          break

        if ansi+1<len(s):
          ansi+=1
        else:
          break

        if s[ansi]==t[nowj] or s[ansi]=="?":
          cnt+=1

        if cnt==len(t):
          ansj=nowj
          flag=1
          ans=s[0:len(s)-ansi+1]+t
          for x in ans:
            if x=="?":
              l+="a"
            else:
              l+=x
          print(l)
          sys.exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys
s=[x for x in input()]
t=[x for x in input()]
ansi=0
ansj=0
flag=0
l=""
for i in range(len(s)):
  for j in range(len(t)):
    if s[i]==t[j] or s[i]=="?" and flag==0:
      cnt=1
      nowj=j
      nowi=i
      ansi=nowi
      ansj=nowj
      while(True):
        print(nowi,nowj,cnt,[s[nowi],t[nowj]])
        if nowj+1<len(t):
          nowj+=1
        else:
          break

        if ansi+1<len(s):
          ansi+=1
        else:
          break

        if s[ansi]==t[nowj] or s[ansi]=="?":
          cnt+=1

        if cnt==len(t):
          ansj=nowj
          flag=1
          ans=s[0:len(s)-ansi+1]+t
          for x in ans:
            if x=="?":
              l+="a"
            else:
              l+=x
          print(l)
          sys.exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
Sd = list(input())
Nd = len(Sd)
T = input()
N = len(T)
checked_i = -1

ans = "UNRESTORABLE"

for i in range(Nd):
    #c????のパターン
    if Sd[i] == T[0]:
        checked_i = i
        hatena_num = 0
        for j in range(i+1, min(Nd, i+N)):
            if Sd[j] == "?":
                hatena_num += 1
            else:
                break
        if hatena_num >= N-1:
            for k in range(0, N-1):
                Sd[checked_i+1+k] = T[k+1]
            Sd = "".join(Sd)
            Sd = Sd.replace("?", "a")
            print(Sd)
            quit()
        #c???rのパターン
        elif hatena_num == N-2:
            if Sd[i+N-1] == T[-1]:
                for k in range(0, N-2):
                    Sd[checked_i+1+k] = T[k+1]
                Sd = "".join(Sd)
                Sd = Sd.replace("?", "a")
                print(Sd)
                quit()
    #????rのパターン
    elif Sd[i] == "?":
        checked_i = i
        hatena_num = 1
        for j in range(i+1, min(Nd, i+N-1)):
            if Sd[j] == "?":
                hatena_num += 1
            else:
                break
        if hatena_num == N-1:
            try:
                if Sd[i+N-1] == T[-1]:
                    for k in range(0, N-1):
                        Sd[checked_i+k] = T[k]
                    Sd = "".join(Sd)
                    Sd = Sd.replace("?", "a")
                    print(Sd)
                    quit()
            except:
                pass

print(ans)

Submission status: Wrong Answer

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

S = S[::-1]
T = T[::-1]
cnt = 0

def answer(S):
    S = S.replace('?', 'a')
    print(S[::-1])
    exit()

if S.count(T) > 0:
    answer(S)

# if len(S) < len(T):
#     print('UNRESTORABLE')

for i in range(len(S)):
    if S[i] == '?' or S[i] == T[cnt]:
        if cnt == len(T) - 1:
            S = S[:(i-cnt)] + T + S[i+1:]
            answer(S)
        else:
            cnt += 1
    else:
        cnt = 0

if S.count('?') == 0:
    print(S[::-1])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

S = S[::-1]
T = T[::-1]
cnt = 0

def answer(S):
    S = S.replace('?', 'a')
    print(S[::-1])
    exit()

if S.count(T) > 0:
    answer(S)

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

for i in range(len(S)):
    if S[i] == '?' or S[i] == T[cnt]:
        if cnt == len(T) - 1:
            S = S[:(i-cnt)] + T + S[i+1:]
            answer(S)
        else:
            cnt += 1
    else:
        cnt = 0

if S.count('?') == 0:
    print(S[::-1])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

S = S[::-1]
T = T[::-1]
cnt = 0

def answer(S):
    S = S.replace('?', 'a')
    print(S[::-1])
    exit()

if S.count(T) > 0 or len(S) < len(T):
    answer(S)

for i in range(len(S)):
    if S[i] == '?' or S[i] == T[cnt]:
        if cnt == len(T) - 1:
            S = S[:(i-cnt)] + T + S[i+1:]
            answer(S)
        else:
            cnt += 1
    else:
        cnt = 0

if S.count('?') == 0:
    print(S[::-1])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

S = S[::-1]
T = T[::-1]
cnt = 0

def answer(S):
    S = S.replace('?', 'a')
    print(S[::-1])
    exit()

if S.count(T) > 0:
    answer(S)

for i in range(len(S)):
    if S[i] == '?' or S[i] == T[cnt]:
        if cnt == len(T) - 1:
            S = S[:(i-cnt)] + T + S[i+1:]
            answer(S)
        else:
            cnt += 1
    else:
        cnt = 0

if S.count('?') == 0:
    print(S[::-1])
else:
    print('UNRESTORABL')

Submission status: Wrong Answer

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

S = S[::-1]
T = T[::-1]
cnt = 0

def answer(S):
    S = S.replace('?', 'a')
    print(S[::-1])
    exit()

if S.count(T) > 0:
    answer(S)

for i in range(len(S)):
    if S[i] == '?' or S[i] == T[cnt]:
        if cnt == len(T) - 1:
            S = S[:(i-cnt)] + T + S[i+1:]
            answer(S)
        else:
            cnt += 1
    else:
        cnt = 0

if S.count('?') == 0:
    print(S[::-1])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

S = S[::-1]
T = T[::-1]
cnt = 0

def answer(S):
    S = S.replace('?', 'a')
    print(S[::-1])
    exit()

for i in range(len(S)):
    if S[i] == '?' or S[i] == T[cnt]:
        if cnt == len(T) - 1:
            S = S[:(i-cnt)] + T + S[i+1:]
            answer(S)
        else:
            cnt += 1
    else:
        cnt = 0

if S.count('?') == 0:
    print(S[::-1])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

S = S[::-1]
T = T[::-1]
cnt = 0
print(S[len(S)+1:])

def answer(S):
    S = S.replace('?', 'a')
    print(S[::-1])
    exit()

for i in range(len(S)):
    if S[i] == '?' or S[i] == T[cnt]:
        if cnt == len(T) - 1:
            S = S[:(i-cnt)] + T + S[i+1:]
            answer(S)
        else:
            cnt += 1
    else:
        cnt = 0
if S.count('?') == 0:
    answer(S)
print('UNRESTORABLE')

Submission status: Wrong Answer

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

S = S[::-1]
T = T[::-1]
cnt = 0

def answer(S):
    S = S.replace('?', 'a')
    print(S[::-1])
    exit()

for i in range(len(S)):

    if S[i] == '?' or S[i] == T[cnt]:
        if cnt == len(T) - 1:
            S = S[:(i-cnt)] + T + S[i+1:]
            answer(S)
        else:
            cnt += 1
    else:
        cnt = 0

print('UNRESTORABLE')

Submission status: Wrong Answer

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

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    s = sys.stdin.readline().strip()
    t = sys.stdin.readline().strip()
    words = list()

    for i in range(len(s)-len(t),0,-1):
        u = s[i:i+len(t)]
        u = "".join([ p if q is "?" else q for p,q in zip(t,u) ]).strip()

        if t == u:
            v = s[0:i] + t + s[i+len(t):]
            words.append( v.replace("?", "a") )

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    s = sys.stdin.readline().strip()
    t = sys.stdin.readline().strip()

    for i in range(len(s)-len(t),0,-1):
        u = s[i:i+len(t)]
        u = "".join([ p if q is "?" else q for p,q in zip(t,u) ]).strip()

        if t == u:
            s = s[0:i] + t + s[i+len(t):]
            break
    
    s = s.replace("?", "a")

    if t in s:
        print(s)
    else:
        print("UNRESTORABLE")

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    s = sys.stdin.readline().strip()
    t = sys.stdin.readline().strip()

    for i in range(len(s)-len(t)+1):
        u = s[i:i+len(t)]
        u = "".join([ p if q is "?" else q for p,q in zip(t,u) ]).strip()

        if t == u:
            s = s[0:i] + t + s[i+len(t):]
    
    s = s.replace("?", "a")

    if t in s:
        print(s)
    else:
        print("UNRESTORABLE")

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    s = sys.stdin.readline().strip()
    t = sys.stdin.readline().strip()

    for i in range(len(s)-len(t)+1):
        u = s[i:i+len(t)]
        u = "".join([ p if q is "?" else q for p,q in zip(t,u) ]).strip()

        if t == u:
            s = s[0:i] + t + s[i+len(t):]
            break
    
    s = s.replace("?", "a")

    if t in s:
        print(s)
    else:
        print("UNRESTORABLE")

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

for i in range(len(s)-len(t)+1):
    s_c = s[i:len(t)+i]
    for j in range(len(t)):
        if s_c[j] == "?" or s_c[j] == t[j]:
            s_c[j] = t[j]
    if s_c == t:
        s[i:len(t)+i] = s_c
        for i, k in enumerate(s):
            if k == '?':
                s[i] = "a"
        print((','.join(s).replace(',', '')))
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
s = list(input())
t = list(input())
index = 0

for i in range(len(s)-len(t)+1):
    s_c = s[i:len(t)+i]
    for j in range(len(t)):
        if s_c[j] == "?" or s_c[j] == t[j]:
            s_c[j] = t[j]
    if s_c == t:
        s[i:len(t)+i] = s_c
        for i, k in enumerate(s):
            if k == '?':
                s[i] = "a"
        print((','.join(s).replace(',', '')))
        sys.exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
s = len(S)
t = len(T)
if s < t:
    print('UNRESTORABLE')

for i in range(s - t, -1, -1):
    OK = True
    for j in range(t):
        if S[i + j] != T[j] and S[i + j] != '?':
            OK = False
    if OK:
        for j in range(t):
            SS = S[:i] + T + S[i + j + 1:]
            SS = SS.replace('?', 'a')
        print(SS)
        sys.exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
s = len(S)
t = len(T)
if s < t:
    print('UNRESTORABLE')

for i in range(s - t, 0, -1):
    OK = True
    for j in range(t):
        if S[i + j] != T[j] and S[i + j] != '?':
            OK = False
    if OK:
        for j in range(t):
            SS = S[:i] + T + S[i + j + 1:]
            SS = SS.replace('?', 'a')
        print(SS)
        sys.exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
s = len(S)
t = len(T)
if s < t:
    print('UNRESTORABLE')

for i in range(s - t + 1):
    OK = True
    for j in range(t):
        if S[i + j] != T[j] and S[i + j] != '?':
            OK = False
    if OK:
        for j in range(t):
            SS = S[:i] + T + S[i + j + 1:]
            SS = SS.replace('?', 'a')
        print(SS)
        sys.exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

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

l0 = len(s)
l = len(t)


def chk(n):
    x = s[n:n+l]
    flg = True
    for j in range(l):
        if x[j] != t[j] and x[j] != "?":
            flg = False
    return flg


res = []
for i in range(l0 - l + 1):
    if s[i] == t[0]:
        if chk(i):
            res.append(i)

ans = []
if not res:
    print("UNRESTORABLE")
else:
    for p in res:
        y = s[:p] + t + s[p+l:]
        z = y.replace("?", "a")
        ans.append(z)
    print(min(ans))

Submission status: Wrong Answer

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

l0 = len(s)
l = len(t)


def chk(n):
    x = s[n:n+l]
    flg = True
    for j in range(l):
        if x[j] != t[j] and x[j] != "?":
            flg = False
    return flg


res = []
for i in range(l0 - l + 1):
    if s[i] == t[0]:
        if chk(i):
            res.append(i)

if not res:
    print("UNRESTORABLE")
else:
    p = res[-1]
    y = s[:p] + t + s[p+l:]
    z = y.replace("?", "a")
    print(z)

Submission status: Wrong Answer

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

ans = 'UNRESTORABLE'

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

        ans = []
        for j in range(len(S)): ans.append(S[j])
        for j in range(len(T)): ans[i+j] = T[j]
        for j in range(len(S)):
            if ans[j] == '?': ans[j] = 'a'
            
for i in range(len(ans)):
    print(ans[i], end='')
print()

Submission status: Wrong Answer

Solution code:
import re
s=str(input())
s = s.replace('?', '.')
t=str(input())
for i in range(0,len(s)-len(t)):
  if re.match(s[i:i+len(t)],t):
    s=s.replace(".","a")
    print(s[:i]+t+s[i+len(t):])
    exit()
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
s=str(input())
s = s.replace('?', '.')
t=str(input())
for i in range(0,len(s)-len(t)+1):
  if re.match(s[i:i+len(t)],t):
    s=s.replace(".","a")
    print(s[:i]+t+s[i+len(t):])
    exit()
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
s=str(input())
s = s.replace('?', '.')
t=str(input())
#if len(s)<len(t):
#  print("UNRESTORABLE")
for i in range(0,len(s)-len(t)+1):
  if re.match(s[i:i+len(t)],t):
    s=s.replace(".","a")
    print(s[:i]+t[0:len(t)]+s[i+len(t):])
    exit()
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
s=str(input())
s = s.replace('?', '.')
t=str(input())
if len(s)<len(t):
  print("UNRESTORABLE")
for i in range(0,len(s)-len(t)+1):
  if re.match(s[i:i+len(t)],t):
    s=s.replace(".","a")
    print(s[:i]+t[0:len(t)]+s[i+len(t):])
    exit()
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
s=str(input())
s = s.replace('?', '.')
t=str(input())
if len(s)<len(t):
  print("UNRESTORABLE")
for i in range(0,len(s)-len(t)+1):
  if re.match(s[i:i+len(t)],t):
    s=s.replace(".","a")
    print(s[:i]+t[0:len(t)]+s[i+len(t):])
    break
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
s1=s[::-1]
t1=t[::-1]
cflag=False
count=0
left=-1
right=-1
for i in range(len(s)):
  if s1[i]=="?" and s1[i]!=t1[count]:
    count+=1
    
  elif s1[i]!="?" and s1[i]==t1[count]:
    count+=1
  
  elif s1[i]!="?" and s1[i]!=t1[count]:
    count=0
  else:
    count=0
  if count==len(t):
    left=i-count+1
    right=i+1
    cflag=True
    break
if cflag==True:
  s1[left:right]=t1
  s1="".join(s1)
  s1=s1.replace("?","a")
  print(s1[::-1])
else:
  print("UNRESTORABLE")