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())
T = list(input())

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

else:
    solved = False
    ind = -1
    for i in reversed(range(len(S) - len(T) + 1)):
        s = S[i:i+len(T)]
        
        yes = True
        for j in range(len(s)):
            print(T[j], s[j])
            if s[j] == '?' or s[j] == T[j]:
                continue
            else:
                yes = False
                break
        if yes:
            ind = i
            solved = True
            break

    if not solved:
        print("UNRESTORABLE")
    else:
        for i in range(len(S)):
            if i < ind:
                if S[i] == '?':
                    S[i] = 'a'
            elif ind<= i < ind+len(T):
                S[i] = T[i-ind]

    print(''.join(S))

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd
readInt = lambda: int(sys.stdin.readline())
readIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]



def solve(S, T):
    res = []
    for i in range(len(S) - len(T) + 1):
        cc = S[:i] + T + S[i+len(T):]
        q = set([s for s,c in zip(S, cc) if s != c])
        if q == set(['?']):
            res.append(cc.replace('?', 'a'))

    res.sort()
    if 0 < len(res):
        return res[0]

    return 'UNRESTORABLE'


def main():
    S = input()
    T = input()
    result = solve(S, T)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
import sys
from collections.abc import Iterable
from math import *
from itertools import *
from collections import *
from functools import *
from operator import *
try:
    from math import gcd
except Exception:
    from fractions import gcd
readInt = lambda: int(sys.stdin.readline())
readIntN = lambda: [int(v) for v in sys.stdin.readline().split(' ')]



def solve(S, T):
    for i in range(len(S) - len(T) + 1):
        cc = S[:i] + T + S[i+len(T):]
        q = set([s for s,c in zip(S, cc) if s != c])
        if q == set(['?']):
            return cc.replace('?', 'a')
    return 'UNRESTORABLE'


def main():
    S = input()
    T = input()
    result = solve(S, T)
    print(result)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def ismatch(string1, string2):
    """
    >>> ismatch('?o???', 'coder')
    True
    >>> ismatch('c????', 'coder')
    True
    >>> ismatch('?of??', 'coder')
    False
    """
    if len(string1) != len(string2):
        return False

    for s1, s2 in zip(string1, string2):
        if not (s1 == "?" or s1 == s2):
            return False
    return True


def main():
    string = input()
    subsequence = input()

    ans = []

    for i, s in enumerate(string):
        if s == "?" or s == subsequence[0]:
            try:
                if (ismatch(string[i:i + len(subsequence)],
                            subsequence)):
                    ans.append(string[:i] + subsequence +
                               string[i + len(subsequence) + 1:])
            except IndexError:
                pass
            continue

    ans = [tmp_ans.replace("?", "a") for tmp_ans in ans]

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


if __name__ == '__main__':
    # import doctest
    # doctest.testmod()
    main()

Submission status: Wrong Answer

Solution code:

def ismatch(string1, string2):
    """
    >>> ismatch('?o???', 'coder')
    True
    >>> ismatch('c????', 'coder')
    True
    >>> ismatch('?of??', 'coder')
    False
    """
    if len(string1) != len(string2):
        return False

    for s1, s2 in zip(string1, string2):
        if not (s1 == "?" or s1 == s2):
            return False
    return True


def main():
    string = input()
    subsequence = input()

    ans = []

    for i, s in enumerate(string):
        if s == "?" or s == subsequence[0]:
            try:
                if (ismatch(string[i:i + len(subsequence)],
                            subsequence)):
                    ans.append(string[:i] + subsequence +
                               string[i + len(subsequence) + 1:])
            except IndexError:
                pass
            continue

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


if __name__ == '__main__':
    # import doctest
    # doctest.testmod()
    main()

Submission status: Wrong Answer

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

t_pattern = []

for i in range(len(S)+1 - len(T)):
    tmp = ""
    for j in range(i):
        tmp += " "
    tmp += T
    tmp_len = len(tmp)
    for j in range(len(S) - tmp_len):
        tmp += " "
    t_pattern.append(tmp)

candidate = []

for i in t_pattern:
    count = 0
    for j in range(len(S)):
        if i[j] == " ":
            continue
        elif i[j] == S[j] or S[j] == "?":
            count += 1
            if count == len(T):
                candidate.append(i)
            continue
        else:
            break

if not candidate:
    print("UNRESTORABLE")
    exit()

ans = ""
for i in range(len(S)):
    if S[i] == "?" and candidate[0][i] == " ":
        ans += "a"
    elif S[i] != "?":
        ans += S[i]
    else:
        ans += candidate[0][i]


print(ans)

Submission status: Wrong Answer

Solution code:
#!/snap/bin/pypy3


def ismatch(string1, string2):
    """
    >>> ismatch('?o???', 'coder')
    True
    >>> ismatch('c????', 'coder')
    True
    >>> ismatch('?of??', 'coder')
    False
    """
    if len(string1) != len(string2):
        return False

    for s1, s2 in zip(string1, string2):
        if not (s1 == "?" or s1 == s2):
            return False
    return True


def main():
    string = input()
    subsequence = input()

    ans = "UNRESTORABLE"

    for i, s in enumerate(string):
        if s == "?":
            try:
                if (ismatch(string[i:i + len(subsequence)],
                            subsequence)):
                    ans = string[:i] + subsequence + \
                        string[i + len(subsequence) + 1:]
                    break
            except IndexError:
                pass
            continue

        index = -1
        while s in subsequence[index + 1:]:
            index = subsequence.index(s, start=index + 1)
            try:
                if (ismatch(string[i - index:i + len(subsequence) - index],
                            subsequence)):
                    ans = string[:i - index] + subsequence + \
                        string[i - index + len(subsequence) + 1:]
                    break
            except IndexError:
                pass
    print(ans.replace("?", "a"))


if __name__ == '__main__':
    # import doctest
    # doctest.testmod()
    main()

Submission status: Wrong Answer

Solution code:
def ismatch(string1, string2):
    """
    >>> ismatch('?o???', 'coder')
    True
    >>> ismatch('c????', 'coder')
    True
    """
    for s1, s2 in zip(string1, string2):
        if not (s1 == "?" or s1 == s2):
            return False
    return True


def main():
    string = input()
    subsequence = input()

    ans = "UNRESTORABLE"

    for i, s in enumerate(string):
        index = -1
        while s in subsequence[index + 1:]:
            index = subsequence.index(s, start=index + 1)
            try:
                if (ismatch(string[i - index:i + len(subsequence) - index],
                            subsequence)):
                    ans = string[:i - index] + subsequence + \
                        string[i - index + len(subsequence) + 1:]
                    break
            except IndexError:
                pass
    print(ans.replace("?", "a"))


if __name__ == '__main__':
    # import doctest
    # doctest.testmod()
    main()

Submission status: Wrong Answer

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

S = list(input().strip())
T = list(input().strip())
s = set()

for i in range(len(S) - len(T) + 1):
    p = S[i:i+len(T)]
    pp = "{}{}".format(T[0], "?" * (len(T) - 1))
    if "".join(p) == pp:
        s.add("".join(S[0:i] + T + S[i+len(T):]))

    if p == ["?"] * len(T):
        s.add("".join(S[0:i] + T + S[i+len(T):]))
        
if len(s) == 0:
    print("UNRESTORABLE")
else:
    l = list(s)
    for i in range(len(s)):
        l[i] = l[i].replace("?", "a")
        
    l.sort()
    print(l[0])

Submission status: Wrong Answer

Solution code:
s=list(str(input()))
t=list(str(input()))
ans=[]
if len(s)<len(t):
    print("UNRESTORABLE")
else:
    sn=len(s)
    tn=len(t)
    for i in range(sn-tn+1):
        flag=True
        for k in range(tn):
            if s[i+k]==t[k] or s[i+k]=="?":
                pass
            else:
                flag=False
                break
        if flag:
            p=s[:]
            for k in range(tn):
                p[i+k]=t[k]
            for l in range(sn):
                if p[l]=="?":
                    p[l]="a"
            ans.append("".join(p))
    if flag:
        print(min(ans))
    else:
        print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=list(str(input()))
t=list(str(input()))
ans=[]
if len(s)<len(t):
    print("UNRESTORABLE")
else:
    sn=len(s)
    tn=len(t)
    for i in range(sn-tn+1):
        flag=True
        for k in range(tn):
            if s[i+k]==t[k] or s[i+k]=="?":
                pass
            else:
                flag=False
                break
        if flag:
            for k in range(tn):
                s[i+k]=t[k]
            for l in range(sn):
                if s[l]=="?":
                    s[l]="a"
            ans.append("".join(s))
    if flag:
        print(min(ans))
    else:
        print("UNRESTORABLE")

Submission status: Wrong Answer

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

if len(s)<len(t):
    print("UNRESTORABLE")
else:
    sn=len(s)
    tn=len(t)
    for i in range(sn-tn+1):
        flag=True
        for k in range(tn):
            if s[i+k]==t[k] or s[i+k]=="?":
                pass
            else:
                flag=False
                break
        if flag:
            for k in range(tn):
                s[i+k]=t[k]
            break
        else:
            pass
    if flag:
        for i in range(sn):
            if s[i]=="?":
                s[i]="a"
        print("".join(s))
    else:
        print("UNRESTORABLE")

Submission status: Wrong Answer

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

sr = s[::-1]
tr = t[::-1]

for i in range(len(sr)-len(tr)+1):
    srp = sr[i:i+len(tr)]
    for j in range(len(srp)):
        if srp[j] != '?' and srp[j] != tr[j]:
            break
        else:
            ans = sr.replace('?', 'a')
            ans = ans[0:i] + tr + ans[i+len(tr):]
            print(ans[::-1])
            exit()
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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


s = input()
t = input()
ls = len(s)
lt = len(t)

if len(s) < len(t):
  print("UNRESTORABLE")
  exit()
  
for i in range(ls):
    j = ls-lt-i
    if j<0:
        break
    sb = s[j:j+lt]
    if check(sb,t):
        ans = s[:j]+t+s[j+lt:]
        print(ans.replace('?', 'a'))
        exit()
print('UNRESTOREBLE')

Submission status: Wrong Answer

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


s = input()
t = input()
ls = len(s)
lt = len(t)


for i in range(ls):
    j = ls-lt-i
    if j<0:
        break
    sb = s[j:j+lt]
    if check(sb,t):
        ans = s[:j]+t+s[j+lt:]
        print(ans.replace('?', 'a'))
        exit()
print('UNRESTOREBLE')

Submission status: Wrong Answer

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

# Tが当てはまる？
s = 0 # Tが当てはまる最初のインデックス
for i in range(len(S)-len(T)+1):
    flag = 1
    for j in range(len(T)):
        if S[i+j] != "?" and S[i+j] != T[j]:
            flag = 0
    if flag:
        s = i
        break

if len(S) < len(T) or not flag:
    print("UNRESTORABLE")
else: # Tが当てはまった場合
    S = S[:s] + T + S[s+len(T):]
    # "?"を"a"で埋める
    S = S.replace("?", "a")
    print(S)

Submission status: Wrong Answer

Solution code:
S_dash_list = list(input())
T_list = list(input())
match_flg = False
for i in range(len(S_dash_list) - len(T_list), 0, -1):
    match_flg = True
    for t in range(len(T_list)):
        if i + t < len(S_dash_list) and (S_dash_list[i + t] != "?" and S_dash_list[i + t] != T_list[t]):
            match_flg = False
    if match_flg:
        # 文字をT_listに置き換える
        for t in range(len(T_list)):
            S_dash_list[i + t] = T_list[t]
        # ?をaに置き換える
        for i in range(len(S_dash_list)):
            if S_dash_list[i] == "?":
                S_dash_list[i] = "a"
        break

if match_flg:
    print("".join(S_dash_list))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

for i in range(len(s)-len(t),-1,-1):
	for j in range(len(t)):
		if(t[j] != s[i+j] and s[i+j] != '?'):
			break
	else:
		ptr = i
		s = [c if c != '?' else 'a' for c in s]
		s[i:i+len(t)] = list(t)
		s = ''.join(s)
		break
else:
	print('UNRESTORABLE')

print(s)

Submission status: Wrong Answer

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

ptr = []

for i in range(len(s)-len(t)+1):
	for j in range(len(t)):
		if(t[j] != s[i+j] and s[i+j] != '?'):
			print(i,j,t[j],s[i+j])
			break
		elif(j == len(t) - 1):
			ptr.append(i)
		else:
			pass

if ptr == []:
	print('UNRESTORABLE')
else:
	ptr = max(ptr)
	ans = s[0:ptr].replace('?','a') + t + s[ptr+len(t):].replace('?','a')
	print(ans)

Submission status: Wrong Answer

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

index = []
ss = []
flag = False

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
        if j == len(T) - 1:
            flag = True
            index.append(i)

if flag:
    for v in index:
        s = ''
        k = 0
        for i in range(len(S)):
            if v <= i <= v + len(T) - 1:
                s += T[k]
                k += 1
                continue
            if S[i] == '?':
                s += 'a'
            else:
                s += S[i]
        ss.append(s)
    ss.sort()
    s = ss[0]
else:
    s = 'UNRESTRABLE'

print(s)

Submission status: Wrong Answer

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

flag = False
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
        if j == len(T) - 1:
            flag = True
            index = i
    if flag:
        break

if flag:
    s = ''
    k = 0
    for i in range(len(S)):
        if index <= i <= index + len(T) - 1:
            s += T[k]
            k += 1
            continue
        if S[i] == '?':
            s += 'a'
        else:
            s += S[i]
else:
    s = 'UNRESTRABLE'

print(s)

Submission status: Wrong Answer

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

flag = False
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
        if j == len(T) - 1:
            flag = True
            index = i

if flag:
    s = ''
    k = 0
    for i in range(len(S)):
        if index <= i <= index + len(T) - 1:
            s += T[k]
            k += 1
            continue
        if S[i] == '?':
            s += 'a'
        else:
            s += S[i]
else:
    s = 'UNRESTRABLE'

print(s)

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
ls = len(S)
lt = len(T)
for i in range(ls-lt+1):
    for j in range(lt):
        if S[i+j] != "?" and S[i+j] != T[j] :
            break
    else:
        #置換処理
        S = [c if c != "?" else "a" for c in S]
        S[i:i+lt] = list(T)
        S = "".join(S)
        break
else:
    S = "UNRESTORABLE"
print(S)

Submission status: Wrong Answer

Solution code:
from functools import reduce
import math
import copy
def main():
    # 文字列の2進数を数値にする
    # '101' → '5'
    # 文字列の頭に'0b'をつけてint()にわたす
    # binary = int('0b'+'101',0)

    # 2進数で立っているbitを数える
    # 101(0x5) → 2
    # cnt_bit = bin(5).count('1')
    
    # N! を求める
    # f = math.factorial(N)

    # N の逆元
    # N_inv = pow(N,MOD-2,MOD)

    # nCr
    # Nの階乗 * rの階乗の逆元 * n-rの階乗の逆元
    
    # 切り捨て
    # 4 // 3
    # 切り上げ
    #-(-4 // 3)
    
    # 初期値用:十分大きい数(100億)
    INF = float("inf")

    # 大きな素数
    MOD = 10**9+7
    
    # 1文字のみを読み込み
    # 入力:2
    # a = input().rstrip()
    # 変数:a='2'
    
    # スペース区切りで標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a, b, c, d = (int(_) for _ in input().split())  
    # 変数:a=2 b=4 c=5 d =7
    
    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2 4 5 7
    # a = list(int(_) for _ in input().split())
    # 変数:a = [2, 4, 5, 7]    

    # 1文字ずつ標準入力を配列として読み込み
    # 入力:2457
    # a = list(int(_) for _ in input())
    # 変数:a = [2, 4, 5, 7]    
    S_dash = list(_ for _ in input())
    T = list(_ for _ in input())
    S_dash = S_dash[::-1]
    init_S = copy.deepcopy(S_dash)
    T = T[::-1]
    S = []
    for i in range(len(S_dash)-len(T)):
        flag = False
        for j in range(i,i+len(T)):
            if S_dash[j] == T[j-i] or S_dash[j] == '?':
                flag = True
            else:
                flag = False
                break
        if flag:
            for j in range(i,i+len(T)):
                S_dash[j] = T[j-i]
            break
    if init_S == S_dash:
        print('UNRESTORABLE')
        return 
    S = ''.join(S_dash[::-1]).replace('?','a')
    print(S)
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    t = input()

    sl = len(s)
    tl = len(t)

    if t in s:
        for i in range(sl):
            if s[i]=='?':
                print('a', end='')
            else:
                print(s[i], end='')
        print()
        return

    contain = 0
    for i in range(sl-1, 0, -1):
        if i+tl-1>=sl:
            continue
        ok = 1
        for j in range(tl):
            if s[i+j] not in ['?', t[j]]:
                ok = 0
                break
        if ok:
            s = s[:i] + t + s[i+tl:]
            for i in range(sl):
                if s[i]=='?':
                    print('a', end='')
                else:
                    print(s[i], end='')
            
            print()
            return

    print('UNRESTORABLE')
            

solve()

Submission status: Wrong Answer

Solution code:
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def solve():
    s = input()
    t = input()

    sl = len(s)
    tl = len(t)

    if t in s:
        for i in range(sl):
            if s[i]=='?':
                print('a', end='')
            else:
                print(s[i], end='')
        print()
        return

    contain = 0
    for i in range(sl-1, 0, -1):
        if i+tl-1>=sl:
            continue
        ok = 1
        for j in range(tl):
            if s[i+j] not in ['?', t[j]]:
                ok = 0
                break
        if ok:
            s = s[:i] + t + s[i+tl:]
            for i in range(sl):
                if s[i]=='?':
                    print('a', end='')
                else:
                    print(s[i], end='')
            return

    print('UNRESTORABLE')
            

solve()

Submission status: Wrong Answer

Solution code:
import re
Sd = input().strip()
T = input().strip()
Sd = Sd.replace('?','.')
ls, lt = len(Sd), len(T)
if ls < lt :
    print('UNRESTORABLE')
else :
    ans = []
    for i in range(ls - lt + 1) :
        m = re.match(Sd[i:1 + lt], T)
        if m is None :
            continue
        ans.append((Sd[:i] + T + Sd[i + lt:]).replace('.','a'))
    if not ans :
        print('UNRESTORABLE')
    else :
        print(min(ans))

Submission status: Wrong Answer

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

if len(S) < N:
    print("UNRESTORABLE")
    import sys
    sys.exit()

flag = False
pos = 51
ans = ""
for i in range(len(S)-N-1):
    cnt = 0
    for j in range(N):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break
    if cnt == N:
        pos = i
        flag = True
if flag:
    for i in range(len(S)):
        if pos <= i and i < pos + N:
            ans += T[i-pos]
        elif S[i] == "?":
            ans += "a"
        else:
            ans += S[i]
else:
    ans = "UNRESTORABLE"
print(ans)

Submission status: Wrong Answer

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

if len(S) < N:
    print("UNRESTORABLE")
    import sys
    sys.exit()

flag = False
pos = 51
ans = ""
for i in range(len(S)-N):
    cnt = 0
    for j in range(N):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break
    if cnt == N:
        pos = i
        flag = True
if flag:
    for i in range(len(S)):
        if pos <= i and i < pos + N:
            ans += T[i-pos]
        elif S[i] == "?":
            ans += "a"
        else:
            ans += S[i]
else:
    ans = "UNRESTORABLE"
print(ans)

Submission status: Wrong Answer

Solution code:
s_dash=input()
t=input()
ind=s_dash.find(t[0])
if ind!=-1 and s_dash[ind:ind+len(t)] ==t[0]+"?"*(len(t)-1) :
    #ind=s_dash.find(t[0])
    s=s_dash[:ind]+t
    s=s.replace("?","a")
    print(s)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i, ch in enumerate(T):
    if ch in SD:
        n = SD.find(ch)
        flag = True
        c = 0
        for j in range(n-1, n-i, -1):
            if j < 0:
                flag = False
                break
            if SD[j] != '?' and SD[j] != T[i-c]:
                flag = False
                break
            flag = True
            c += 1
        if flag:
            c = 0
            for j in range(n+1, n+len(T)-i):
                if j > len(SD)-1:
                    flag = False
                    break
                if SD[j] != '?' and SD[j] != T[i+c]:
                    flag = False
                    break
                flag = True
                c += 1
        if flag:
            remP = SD[:n-i]
            remA = SD[n+1+len(T)-i:]
            for j, rc in enumerate(remP):
                if rc == '?':
                    remP = remP[:j] + 'a' + remP[j+1:]
            for j, rc in enumerate(remA):
            	if rc == '?':
              		remA = remA[:j] + 'a' + remA[j+1:]
            print(remP+T+remA)
            quit()
print('UNRESTORABLE')

Submission status: Wrong Answer

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

for i, ch in enumerate(T):
    if ch in SD:
        n = SD.find(ch)
        flag = True
        c = 0
        for j in range(n-1, n-i, -1):
            if j < 0:
                flag = False
                break
            if SD[j] != '?' and SD[j] != T[i-c]:
                flag = False
                break
            flag = True
            c += 1
        if flag:
            c = 0
            for j in range(n+1, n+len(T)-i):
                if j > len(SD)-1:
                    flag = False
                    break
                if SD[j] != '?' and SD[j] != T[i+c]:
                    flag = False
                    break
                flag = True
                c += 1
        if flag:
            remP = SD[:n-i]
            remA = SD[n+1+len(T)-i:]
            for i, rc in enumerate(remP):
                if rc == '?':
                    remP = remP[:i] + 'a' + remP[i+1:]
            print(remP+T+remA)
            quit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
index = -999999
for i in range(len(s)):
    if s[i] == t[0]:
        if len(s[i:i+len(t)]) != len(t):
            continue
        for j in range(len(t)):
            if s[i+j] == t[j] or s[i+j] == '?':
                pass
            else:
                break
        index = i
if index == -9999999:
    print('UNRESTORABLE')
    exit()
ans = s[:index] + t + s[index+len(t):]
print(ans.replace('?', 'a'))

Submission status: Wrong Answer

Solution code:
import sys
S=input()
T=input()
if len(S)<len(T):
    print('UNRESTORABLE')
    sys.exit()
L=[]
for i in range(len(S)-len(T)+1):
    K=S[i:i+len(T)]
    flag=True
    print(K)
    for j in range(len(T)):
        if T[j]!=K[j] and K[j]!='?':
            flag=False
    if flag:
        U=S[:i]+T+S[i+len(T):]
        L.append(U.replace('?','a'))
#print(L)
if len(L)!=0:
    print(min(L))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
S=input()
T=input()
if len(S)<len(T):
    print('UNRESTORABLE')
L=[]
for i in range(len(S)-len(T)+1):
    K=S[i:i+len(T)]
    flag=True
    #print(K)
    for j in range(len(T)):
        if T[j]!=K[j] and K[j]!='?':
            flag=False
            break
    if flag:
        U=S[:i]+T+S[i+len(T):]
        L.append(U.replace('?','a'))
#print(L)
if len(L)!=0:
    print(min(L))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
S=input()
T=input()
if len(S)<len(T):
    print('UNRESTORABLE')
L=[]
for i in range(len(S)-len(T)+1):
    K=S[i:i+len(T)]
    flag=True
    #print(K)
    for j in range(len(T)):
        if T[j]!=K[j] and K[j]!='?':
            flag=False
            break
    if flag:
        U=S[:i]+T+S[i+len(T):]
        L.append(U.replace('?','a'))
#print(L)
if L:
    print(min(L))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

for i in range(len(S) - len(T) + 1):
    cand = S[i:i + len(T)]
    for ci, ti in zip(cand, T):
        if ci not in ["?", ti]:
            break
    else:
        temp = S[:i] + T + S[i + len(T):]
        print(temp.replace("?", "a"))
        quit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
Sd = input()[::-1]
T = input()[::-1]

diff = len(Sd) - len(T) + 1
f = False
t_last_idx = len(T) - 1
Sd_last_idx = len(Sd) - 1
ans = list(Sd)
for i in range(t_last_idx, Sd_last_idx + 1):
    if Sd[i] == T[t_last_idx]:
        for j in range(1, t_last_idx + 1):
            if Sd[i - j] == T[t_last_idx - j] or Sd[i - j] == '?':
                ans[i - j] = T[t_last_idx - j]
            else:
                f = False
                break
            f = True
    else:
        continue

if f:
    for i, s in enumerate(ans):
        if s == '?':
            ans[i] = 'a'
    print(''.join(reversed(ans)))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
 
if T in S:
  S_list=list(S)
  for i in range(len(S)):
    if S_list[i]=='?':
      S_list[i]='a'
  answer="".join(S_list)
  print(answer)
  exit()
Srev=S[::-1]
#print(Srev)
Trev=T[::-1]
 
Tlength=len(T)
Tcount=0
Tstart=-1
for i in range(len(S)):
  if Srev[i]=='?' or Srev[i]==Trev[Tcount]:
    Tcount+=1
  else:
    Tcount=0
  if Tcount==Tlength:
    Tstart=i
    break
 
if Tstart==-1:
  print('UNRESTORABLE')
  exit()
Tstart=len(S)-Tstart-1
#answer=''
S_list=list(S)
for i in range(len(S)):
  if S_list[i]=='?':
    S_list[i]='a'
 
T_list=list(T)
for i in range(len(T)):
  S_list[Tstart+i]=T_list[i]
answer="".join(S_list)
print(answer)

Submission status: Wrong Answer

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

	T_length = len(T)
	head = -1
	for i in range(len(S)-T_length+1):
		counter = 0
		for j in range(T_length):
			if(S[i+j]==T[j] or S[i+j]=='?'):
				counter += 1
		if(counter == T_length):
			head = i
				
	print(head)
	ans = ''
	i=0
	if(head == -1):
		print("UNRESTORABLE")
	else :
		while i < len(S):
			if(i!=head and S[i]=='?'):
				ans += 'a'
				i += 1
			elif(i==head):
				ans += T
				i += T_length
			else :
				ans += S[i]
				i+=1

		print(ans)

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
t = input()[::-1]
for i,c in enumerate(s):
  if (c == t[0] or c == '?') and (i+len(t) < len(s)):
    for j in range(len(t)):
      if t[j] != s[i+j] and s[i+j] != '?':
        break
    else:
      for j in range(len(t)):
        str_list = list(s)
        str_list[i+j] =  t[j]
        s = ''.join(str_list)
      print(s.replace('?', 'a')[::-1])
      break
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()[::-1]
t = input()[::-1]
for i,c in enumerate(s):
  if (c == t[0] or c == '?') and (i+len(t) < len(s)-1):
    for j in range(len(t)):
      if t[j] != s[i+j] and s[i+j] != '?':
        break
    else:
      for j in range(len(t)):
        str_list = list(s)
        str_list[i+j] =  t[j]
        s = ''.join(str_list)
      print(s.replace('?', 'a')[::-1])
      break
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

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

Srev=S[::-1]
#print(Srev)
Trev=T[::-1]

Tlength=len(T)
Tcount=0
Tstart=-1
for i in range(len(S)):
  if Srev[i]=='?' or Srev[i]==Trev[Tcount]:
    Tcount+=1
  else:
    Tcount=0
  if Tcount==Tlength:
    Tstart=i
    break

if Tstart==-1:
  print('UNRESTORABLE')
  exit()
Tstart=len(S)-Tstart-1
#answer=''
S_list=list(S)
for i in range(len(S)):
  if S_list[i]=='?':
    S_list[i]='a'

T_list=list(T)
for i in range(len(T)):
  S_list[Tstart+i]=T_list[i]
answer="".join(S_list)
print(answer)
'''
print(Tstart)
print(S[Tstart:Tstart+Tlength])
print(T)
S[Tstart:Tstart+Tlength]=T
print(S)
'''

Submission status: Wrong Answer

Solution code:
S = [i for i in input()]
T = input()
tmp = S.copy()

key = len(T)

SS = []
for i in range(len(S)-key+1):
    idx, flg = 0, 0
    for j in range(i, i+key):
        if S[j] != T[idx] and S[j] != '?':
            flg = 1
            break
        idx += 1
    if flg == 0:
        idx = 0
        for j in range(i, i+key):
            S[j] = T[idx]
            idx += 1
        SS.append(S)
        S = tmp

if SS:
    idx = 0
    for i in SS:
        idx_2 = 0
        for j in i:
            if j == '?':
                SS[idx][idx_2] = 'a'
            idx_2 += 1
        idx += 1
    print(''.join(min(SS)))
else:
    print('UNRESTORABLE')