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:
#!/usr/bin/env python3

#import
#import math
#import numpy as np
#= int(input())
S = list(input())
T = list(input())

ls = len(S); lt = len(T)

for i in range(ls - lt, -1, -1):
    isok = True
    for j in range(lt):
        if S[i + j] == "?":
            continue
        if S[i + j] != T[j]:
            isok = False
            break
    if isok:
        S[i:] = T
        ans = ""
        for s in S:
            if s == "?":
                ans += "a"
            else:
                ans += s
        print(ans)
        exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array

# 時々使う
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

# 再帰の制限設定
sys.setrecursionlimit(10000000)


def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
                    for _ in range(n)]


def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
                    for _ in range(n)]


def lcm(x, y): return (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    T = iss()

    ret = set()
    for i in range(len(S)-len(T)+1):
        for s, t in zip(S[i:i+len(T)], T):
            if s == t or s == '?': continue
            else: break
        else:
            tmp = ''
            if i != 0: tmp += S[:i]
            tmp += T
            if i+len(T) <= len(S): tmp += S[len(T)+1:]
            ret.add(tmp.replace('?', 'a'))

    if len(ret) == 0:
        print('UNRESTORABLE')
    else:
        print(sorted(list(ret))[0])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array

# 時々使う
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

# 再帰の制限設定
sys.setrecursionlimit(10000000)


def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
                    for _ in range(n)]


def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
                    for _ in range(n)]


def lcm(x, y): return (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    T = iss()

    ret = set()
    for i in range(len(S)-len(T)+1):
        for s, t in zip(S[i:i+len(T)], T):
            if s == t or s == '?': continue
            else: break
        else:
            tmp = ''
            if i != 0: tmp += S[:i]
            tmp += T
            if i+len(T) < len(S): tmp += S[len(T)+1:]
            ret.add(tmp.replace('?', 'a'))

    if len(ret) == 0:
        print('UNRESTORABLE')
    else:
        print(sorted(list(ret))[0])


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array

# 時々使う
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

# 再帰の制限設定
sys.setrecursionlimit(10000000)


def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
                    for _ in range(n)]


def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
                    for _ in range(n)]


def lcm(x, y): return (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    T = iss()

    for i in range(len(S)-len(T)+1):
        for s, t in zip(S[i:i+len(T)], T):
            if s == t or s == '?': continue
            else: break
        else:
            ret = ''
            if i != 0: ret += S[:i]
            ret += T
            if i+len(T) < len(S): ret += S[len(T)+1:]
            
            print(ret.replace('?', 'a'))
            exit()
    else:
        print('UNRESTORABLE')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
import os
import math
import bisect
import itertools
import collections
import heapq
import queue
import array

# 時々使う
# from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
# from decimal import Decimal
# from collections import defaultdict, deque

# 再帰の制限設定
sys.setrecursionlimit(10000000)


def ii(): return int(sys.stdin.buffer.readline().rstrip())
def il(): return list(map(int, sys.stdin.buffer.readline().split()))
def fl(): return list(map(float, sys.stdin.buffer.readline().split()))
def iln(n): return [int(sys.stdin.buffer.readline().rstrip())
                    for _ in range(n)]


def iss(): return sys.stdin.buffer.readline().decode().rstrip()
def sl(): return list(map(str, sys.stdin.buffer.readline().decode().split()))
def isn(n): return [sys.stdin.buffer.readline().decode().rstrip()
                    for _ in range(n)]


def lcm(x, y): return (x * y) // math.gcd(x, y)


MOD = 10 ** 9 + 7
INF = float('inf')


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    S = iss()
    T = iss()

    for i in range(len(S)-len(T)+1):
        for s, t in zip(S[i:i+len(T)], T):
            if s == t or s == '?': continue
            else: break
        else:
            ret = ''
            if i != 0: ret += S[:i]
            ret += T
            if i+len(T) < len(S): ret += S[len(T)+1:]
            
            print(ret.replace('?', 'a'))
            exit()
    else:
        print('No')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 28 02:20:36 2020

@author: liang
"""
S = input()
T = input()

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

res = list()

for i in range(len(S)-len(T)):
    flag = True
    for j in range(len(T)):
        if S[i+j] == "?" or S[i+j] == T[j]:
            continue
        else:
            flag = False
    if flag == True:
        ans = ""
        for k in range(len(S)):
            if i <= k <= i + len(T)-1:
                #print(T[k-i])
                ans += T[k-i]
            elif S[k] != "?":
                #print("B")
                ans += S[k]
            else:
                #print("C")
                ans += "a"
        ans = ans[::-1]
        res.append(ans)

if res:
    res.sort()
    print(res[0])
else:
    print("UNRESTORABLE")
#print(S)
#print(T)

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
"""
Created on Mon Sep 28 02:20:36 2020

@author: liang
"""
S = input()
T = input()

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


for i in range(len(S)-len(T)):
    flag = True
    for j in range(len(T)):
        if S[i+j] == "?" or S[i+j] == T[j]:
            continue
        else:
            flag = False
    if flag == True:
        ans = ""
        for k in range(len(S)):
            if i <= k <= i + len(T)-1:
                #print(T[k-i])
                ans += T[k-i]
            elif S[k] != "?":
                #print("B")
                ans += S[k]
            else:
                #print("C")
                ans += "a"
        ans = ans[::-1]
        print(ans)
        break
else:
    print("UNRESTORABLE")
#print(S)
#print(T)

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

S = v()
T = v()
len_s = len(S)
len_t = len(T)
check = False
ans = []

if len_s<len_t:
    print("UNRESTORABLE")
    sys.exit()

for i in range(len_s):
    if S[i] == "?":
        cnt += 1
        if cnt >= len_t:
            aaa = S.replace("?","a")
            ans.append(aaa[:i-len_t+1]+T+aaa[i+1:])
    elif S[i] in T:
        cnt = 0
        place = T.index(S[i])
        if len_s<len_t+i-place:
            break
        for j in range(i-place,len_t+i-place):
            if T[j-(i-place)] == S[j] or S[j] == "?":
                check = True
            else:
                check = False
                break
        if check:
            aaa = S.replace("?","a")
            ans.append(aaa[:i-place]+T+aaa[len_t+i-place:])
    else:
        cnt = 0

print(ans)
if len(ans)>0:
    ans.sort()
    print(ans[0])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

S = v()
T = v()
len_s = len(S)
len_t = len(T)
check = False
ans = []

if len_s<len_t:
    print("UNRESTORABLE")
    sys.exit()

for i in range(len_s):
    if S[i] == "?":
        cnt += 1
        if cnt >= len_t:
            aaa = S.replace("?","a")
            ans.append(aaa[:i-len_t+1]+T+aaa[i+1:])
    elif S[i] in T:
        cnt = 0
        place = T.index(S[i])
        if len_s<len_t+i-place:
            break
        for j in range(i-place,len_t+i-place):
            if T[j-(i-place)] == S[j] or S[j] == "?":
                check = True
            else:
                check = False
                continue
        if check:
            aaa = S.replace("?","a")
            ans.append(aaa[:i-place]+T+aaa[len_t+i-place:])
    else:
        cnt = 0

if len(ans)>0:
    ans.sort()
    print(ans[0])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

S = v()
T = v()
len_s = len(S)
len_t = len(T)
check = False
ans = []

if len_s<len_t:
    print("UNRESTORABLE")
    sys.exit()

for i in range(len_s):
    if S[i] == "?":
        cnt += 1
        if cnt >= len_t:
            aaa = S.replace("?","a")
            ans.append(aaa[:i-len_t+1]+T+aaa[i+1:])
    elif S[i] in T:
        cnt = 0
        place = T.index(S[i])
        if len_s<len_t+i-place:
            break
        for j in range(i-place,len_t+i-place):
            if T[j-(i-place)] == S[j] or S[j] == "?":
                check = True
            else:
                check = False
                continue
        if check:
            aaa = S.replace("?","a")
            ans.append(aaa[:i-place]+T+aaa[len_t+i-place:])
    else:
        cnt = 0

print(ans)
if len(ans)>0:
    ans.sort()
    print(ans[0])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

S = v()
T = v()
len_s = len(S)
len_t = len(T)
check = False

if len_s<len_t:
    print("UNRESTORABLE")
    sys.exit()

for i in range(len_s):
    if S[i] == "?":
        cnt += 1
        if cnt >= len_t:
            aaa = S.replace("?","a")
            print(aaa[:i-len_t]+T+aaa[i:])
    if S[i] in T:
        cnt = 0
        place = T.index(S[i])
        a = i
        for j in range(a-place,len_t+a-place):
            if T[j-(a-place)] == S[j] or S[j] == "?":
                check = True
            else:
                check = False
                continue
        if check:
            aaa = S.replace("?","a")
            print(aaa[:i-place]+T+aaa[i+len_t:])
            sys.exit()
    else:
        cnt = 0
    
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def v(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 6)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")
al = "abcdefghijklmnopqrstuvwxyz"
AL = al.upper()

S = v()
T = v()
len_s = len(S)
len_t = len(T)
check = False

if len_s<len_t:
    print("UNRESTORABLE")
    sys.exit()

for i in range(len_s):
    if S[i] == "?":
        cnt += 1
        if cnt >= len_t:
            print(S[:i-len_t]+T+S[i:])
    if S[i] in T:
        cnt = 0
        place = T.index(S[i])
        a = i
        for j in range(a-place,len_t+a-place):
            if T[j-(a-place)] == S[j] or S[j] == "?":
                check = True
            else:
                check = False
                continue
        if check:
            aaa = S.replace("?","a")
            print(aaa[:i-place]+T+aaa[i+len_t:])
            sys.exit()
    else:
        cnt = 0
    
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
ans4=0
for i in range(len(s)-len(t)+1):
    yn=0
    for j in range(len(t)):
        if s[i+j]!=t[j] and s[i+j]!="?":
            yn=1
            break
    if yn==0:
        ans4=1
        for j in range(len(t)):
            s[i+j]=t[j]
        ans=""
        for j in range(len(s)):
            if s[j]=="?":
                ans+="a"
            else:
                ans+=s[j]
        print(ans)
        break
if ans4==0:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
if len(s)<len(t):
    print("UNRESTORABLE")
else:
    ans4=0
    for i in range(len(s)-len(t)+1):
        yn=0
        for j in range(len(t)):
            if s[i+j]!=t[j] and s[i+j]!="?":
                yn=1
                break
        if yn==0:
            ans4=1
            for j in range(len(t)):
                s[i+j]=t[j]
            ans=""
            for j in range(len(s)):
                if s[j]=="?":
                    ans+="a"
                else:
                    ans+=s[j]
            print(ans)
            break
    if ans4==0:
        print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=list(input())
t=list(input())
if len(s)<len(t):
    print("UNRESTORABLE")
else:
    ans4=0
    for i in range(len(s)-len(t)+1):
        yn=0
        for j in range(len(t)):
            if s[i+j]!=t[j] and s[i+j]!="?":
                yn=1
                break
        if yn==0:
            ans4=1
            ans=[""]*len(s)
            for j in range(len(t)):
                ans[i+j]=t[j]
            for j in range(len(s)):
                if ans[j]=="":
                    if s[j]=="?":
                        ans[j]="a"
                    else:
                        ans[j]=s[j]
            ans2=""
            for j in range(len(ans)):
                ans2+=ans[j]
            print(ans2)
            break
    if ans4==0:
        print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i in range(len(s)-len(t)+1):
    st = s[i:i+len(t)]
    cnt = 0
    for si, ti in zip(st, t):
        if si == '?' or si == ti:
            cnt += 1
        # print(si, ti, cnt)
    if cnt == len(t):
        ans = s[:i] + t + s[i+len(t):]
        ans = ans.replace('?', 'a')
        print(ans)
        exit()
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

for ti in range(len(t)):
    for si in range(ti, len(s)-(len(t)-ti-1)):
        if s[si] == t[ti]:
            j = 0
            while j+1 < len(t)-ti:
                if s[si+j] != '?':
                    j += 1
                else:
                    break
            if s[si:si+j] == t[ti:ti+j]:
                if s[si+j:si+j+len(t)-ti-j+1] == '?'*(len(t)-ti-j):
                    ans = s[:si] + t + s[si+j+len(t)-ti-j+1:]
                    ans = ans.replace('?','a')
                    print(ans)
                    exit()
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
n = len(s)
t = input()
m = len(t)
ans = []

for i in range(n-m+1):
    for j in range(m):
        if s[i+j] not in [t[j] , "?"]:
            break
        elif j == m-1:
            res = s[:i]+t+s[i+m+1:]
            ans.append(res.replace("?","a"))
            
if not ans:
    ans.append("UNRESTORABLE")
    
print(min(ans))

Submission status: Wrong Answer

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

ans = True
for i in range(len(S)):
    flag = True
    for j in range(len(T)):
        if i + j >= len(S):
            flag = False
            break
        if S[i+j] == '?' or S[i+j] == T[j]:
            pass
        else:
            flag = False
            break
    if flag:
        ans = False
        for tmp in range(i, i + len(T)):
            S[tmp] = T[tmp-i]
if ans:
    print('UNRESTORABLE')
    exit()

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

print(''.join(S))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
N=len(S)
n=len(T)
ans=[]
for i in range(N-n+1):
    for j in range(n):
        if S[i+j]!=T[j] and S[i+j]!='?':
            break
    else:
        s=[]
        for j in range(i):
            if S[j]=='?':
                s.append('a')
            else:
                s.append(S[j])
        for j in range(i,i+n):
            s.append(T[j-i])
        for j in range(i+n,N):
            if S[j]=='?':
                s.append('?')
            else:
                s.append(S[j])
        ans.append(''.join(s))

if len(ans)==0:
    print("UNRESTORABLE")
else:
    ans.sort()
    print(ans[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import sys

def accept_input():
    S = input()
    T = input()
    return S,T

S,T = accept_input()
fromhere = 0
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] == "?":
            continue
        elif S[i+j] == T[j]:
            continue
        elif S[i+j] != T[j]:
            break
    else:
        fromhere = i
        break
else:
    print("UNRESTORABLE")
    sys.exit()
sd = ""
for i in range(len(S)):
    if i < fromhere:
        if S[i] == "?":
            sd += "a"
        else:
            sd += S[i]
    elif i >= fromhere+len(T):
        if S[i] == "?":
            sd += "a"
        else:
            sd += S[i]
    else:
        sd += T[i-fromhere]
print(sd)

Submission status: Wrong Answer

Solution code:
#!/bin/python3
s=list(input())
t=list(input())

lens=len(s)
lent=len(t)
if lent>lens:
  print("UNRESTORABLE")
  exit()

for i in range(lens-lent,0,-1):
  x=s[i:i+lent]
  ans=s
  flag=True
  #print("x",x,len(x))
  #for b in range(len(x)):
  #  if x[b]==t[b]:
  for j in range(lent):
    if x[j]!=t[j] and x[j]!="?":
      flag=False
      break
    if x[j]=="?":
      #tと同じ部分
      #print("i",i,"j",j)
      ans[i+j]=t[j]
  if flag:
    #tより前の部分
    ans[:i]=["a" if a=="?" else a for a in ans[:i]]
    #tより後ろの部分
    if i+lent<=lens:
      ans[i+lent:lens]=["a" if a=="?" else a for a in ans[i+lent:lens]]
    if not "?" in ans:
      print("".join(ans))
      exit()
print("UNRESTORABLE")
#print("ans",ans)

Submission status: Wrong Answer

Solution code:
#!/bin/python3
s=list(input())
t=list(input())

lens=len(s)
lent=len(t)
if lent>lens:
  print("UNRESTORABLE")
  exit()

for i in range(lens-(lent-1),0,-1):
  x=s[i:i+lent]
  ans=s
  if x==["?"]*lent:
    #tと同じ部分
    ans[i:i+lent]=t
    #tより前の部分
    ans[:i]=["a" if a=="?" else a for a in ans[:i]]
    #tより後ろの部分
    if i+lent<=lens:
      ans[i+lent:lens]=["a" if a=="?" else a for a in ans[i+lent:lens]]
    print("".join(ans))
    exit()
  flag=True
  #print("x",x,len(x))
  for b in range(len(x)):
    if x[b]==t[b]:
      for j in range(lent):
        if x[j]!=t[j] and x[j]!="?":
          flag=False
          break
        if x[j]=="?":
          #tと同じ部分
          #print("i",i,"j",j)
          ans[i+j]=t[j]
      if flag:
        #tより前の部分
        ans[:i]=["a" if a=="?" else a for a in ans[:i]]
        #tより後ろの部分
        if i+lent<=lens:
          ans[i+lent:lens]=["a" if a=="?" else a for a in ans[i+lent:lens]]
        if not "?" in ans:
          print("".join(ans))
          exit()
print("UNRESTORABLE")
#print("ans",ans)

Submission status: Wrong Answer

Solution code:
#!/bin/python3
s=list(input())
t=list(input())

lens=len(s)
lent=len(t)
if lent>lens:
  print("UNRESTORABLE")
  exit()

for i in range(lens-(lent-1)):
  x=s[i:i+lent]
  ans=s
  flag=True
  #print("x",x,len(x))
  for b in range(len(x)):
    if x[b]==t[b]:
      for j in range(lent):
        if x[j]!=t[j] and x[j]!="?":
          flag=False
          break
        if x[j]=="?":
          #print("i",i,"j",j)
          ans[i+j]=t[j]
      if flag:
        ans[:i]=[a if a!="?" else "a" for a in ans[:i]]
        if i+lent<=lens:
          ans[i+lent:lens]=["a"]*len(ans[i+lent:lens])
        if not "?" in ans:
          print("".join(ans))
          exit()
print("UNRESTORABLE")
#print("ans",ans)

Submission status: Wrong Answer

Solution code:
#!/bin/python3
s=list(input())
t=list(input())

lens=len(s)
lent=len(t)
if lent>lens:
  print("UNRESTORABLE")
  exit()

for i in range(lens-(lent-1)):
  x=s[i:i+lent]
  ans=s
  flag=True
  #print("x",x,len(x))
  if x[0]==t[0]:
    for j in range(lent):
      if x[j]!=t[j] and x[j]!="?":
        flag=False
        break
      if x[j]=="?":
        #print("i",i,"j",j)
        ans[i+j]=t[j]
    if flag:
      ans[:i]=[a if a!="?" else "a" for a in ans[:i]]
      if i+lent<lens:
        ans[i+lent:lens]=["a"]*len(ans[i+lent:lens])
      if not "?" in ans:
        print("".join(ans))
        exit()
print("UNRESTORABLE")
#print("ans",ans)

Submission status: Wrong Answer

Solution code:
#!/bin/python3
s=list(input())
t=list(input())

lens=len(s)
lent=len(t)
if lent>lens:
  print("UNRESTORABLE")
  exit()

for i in range(lens-(lent-1)):
  x=s[i:i+lent]
  ans=s
  flag=True
  #print("x",x,len(x))
  if x[0]==t[0]:
    for j in range(lent):
      if x[j]!=t[j] and x[j]!="?":
        flag=False
        break
      if x[j]=="?":
        #print("i",i,"j",j)
        ans[i+j]=t[j]
    if flag:
      ans[:i]=[a if a!="?" else "a" for a in ans[:i]]
      if i+lent<=lens:
        ans[i+lent:lens]=["a"]*len(ans[i+lent:lens])
      if not "?" in ans:
        print("".join(ans))
        exit()
print("UNRESTORABLE")
#print("ans",ans)

Submission status: Wrong Answer

Solution code:
#!/bin/python3
s=list(input())
t=list(input())

lens=len(s)
lent=len(t)
if lent>lens:
  print("UNRESTORABLE")
  exit()

for i in range(lens-(lent-1)):
  x=s[i:i+lent]
  ans=s
  flag=True
  #print("x",x,len(x))
  if x[0]==t[0]:
    for j in range(lent):
      if x[j]!=t[j] and x[j]!="?":
        flag=False
        break
      if x[j]=="?":
        #print("i",i,"j",j)
        ans[i+j]=t[j]
    if flag:
      for k in range(lens):
        if ans[k]=="?":
          ans[k]="a"
      print("".join(ans))
      exit()
print("UNRESTORABLE")
#print("ans",ans)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
ansind = None
def solve(i):
  flag = True
  for j in range(len(T)):
    if i+j < len(S) and (S[i+j] == "?" or S[i+j] == T[j]):
      continue
    else:
      flag = False
      break
  return flag

for i in range(len(S)):
  if solve(i):
    ansind = i
if ansind:
  ans = S[:ansind] + T + S[ansind+len(T):]
  ans = ans.replace("?", "a")
else:
  ans = "UNRESTORABLE"
print(ans)

Submission status: Wrong Answer

Solution code:

def main():
    with open(0) as f:
        S, T = f.read().split()
    try:
        for i in range(len(S)):
            for j in range(len(T)):
                if S[i+j] == T[j] or S[i+j] == '?':
                    continue
                else:
                    break
            else:
                S = S[:i] + T + S[i+len(T):]
                S = S.replace('?', 'a')
                print(S)
    except Exception:
        print('UNRESTORABLE')

main()

Submission status: Wrong Answer

Solution code:
# coding=utf-8
from math import floor, ceil, sqrt, factorial, log, gcd
from itertools import accumulate, permutations, combinations, product, combinations_with_replacement
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from heapq import heappop, heappush, heappushpop, heapify
import copy
import sys
INF = float('inf')
mod = 10**9+7
sys.setrecursionlimit(10 ** 6)


def lcm(a, b): return a * b / gcd(a, b)

# 1 2 3
# a, b, c = LI()


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

# a = I()


def I(): return int(sys.stdin.buffer.readline())

# abc def
# a, b = LS()


def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()

# a = S()


def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')

# 2
# 1
# 2
# [1, 2]


def IR(n): return [I() for i in range(n)]

# 2
# 1 2 3
# 4 5 6
# [[1,2,3], [4,5,6]]


def LIR(n): return [LI() for i in range(n)]

# 2
# abc
# def
# [abc, def]


def SR(n): return [S() for i in range(n)]

# 2
# abc def
# ghi jkl
# [[abc,def], [ghi,jkl]]


def LSR(n): return [LS() for i in range(n)]

# 2
# abcd
# efgh
# [[a,b,c,d], [e,f,g,h]]


def SRL(n): return [list(S()) for i in range(n)]


def main():
    s = S()
    t = S()
    ans = ""
    flg = 1

    for i in range(len(s) - len(t), -1, -1):
        flg = 1
        clipped = s[i:i+len(t)]
        for j in range(len(t)):
            if clipped[j] != t[j] and clipped[j] != "?":
                flg = 0
                break
        if flg:
            ans = s[:i].replace("?", "a") + t + \
                s[i + len(t):].replace("?", "a")
            break

    if not flg:
        print("UNRESTORABLE")
        return
    print(str(ans))


if __name__ == "__main__":
    main()