Problem:


Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.

He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.  

One more thing he found is a sheet of paper with the following facts written on it:  

Condition 1: The string S contains a string T as a contiguous substring.

Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.

Print the string S.

If such a string does not exist, print UNRESTORABLE.  

Constraints

1 \leq |S'|, |T| \leq 50

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

If such a string does not exist, print UNRESTORABLE instead.  

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

There are 26 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder.
Among them, the lexicographically smallest is atcoder, so we can say S = atcoder.

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

There is no string that satisfies Condition 1, so the string S does not exist.



Sample input:
?tc????
coder


Sample output:
atcoder

Submission status: Wrong Answer

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

if len(S) < len(T):
    print("UNRESTORABLE")
else:
    tof = False
    count = 0
    for i in range(len(S)):
        if count == 0:
            for j in range(len(T)):
                if i+j > len(S):
                    break
                
                if S[len(S)-i-j-1] != T[len(T)-j-1] and S[len(S)-i-j-1] != "?":
                    break
                
                if j == len(T)-1:
                    count = len(S)- i - j
                        
    if count == 0:
        print("UNRESTORABLE")
    else:
        S = S.replace("?","a")
        print(S[:count-1] + T + S[count+len(T):])

Submission status: Wrong Answer

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

if len(S) < len(T):
    print("findbugs")
    print("UNRESTORABLE")
else:
    tof = False
    count = 0
    for i in range(len(S)):
        if count == 0:
            for j in range(len(T)):
                if i+j > len(S):
                    break
                
                if S[len(S)-i-j-1] != T[len(T)-j-1] and S[len(S)-i-j-1] != "?":
                    break
                
                if j == len(T)-1:
                    count = len(S)- i - j
                        
    if count == 0:
        print("UNRESTORABLE")
    else:
        S = S.replace("?","a")
        print(S[:count-1] + T + S[count+len(T):])

Submission status: Wrong Answer

Solution code:
import copy

S = list(input())
T = input()

ans = ''
for i in range(len(S)):
    if S[i] == T[0]:
        j = 0
        while S[i + j] == T[j] or S[i + j] == '?':
            #print(i, j)
            j += 1
            if i + j >= len(S):
                break
            if j == len(T) - 1:
                #print(i, j, 'find')
                temp = copy.copy(S)
                for k in range(j + 1):
                    temp[i + k] = T[k]
                for i in range(len(S)):
                    if temp[i] == '?':
                        temp[i] = 'a'
                ans = temp
                break
if ans:
    #print(dct)
    print(''.join(ans))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import copy

S = list(input())
T = input()

dct = []
for i in range(len(S)):
    if S[i] == T[0]:
        j = 0
        while S[i + j] == T[j] or S[i + j] == '?':
            #print(i, j)
            j += 1
            if i + j >= len(S):
                break
            if j == len(T) - 1:
                #print(i, j, 'find')
                temp = copy.copy(S)
                for k in range(j + 1):
                    temp[i + k] = T[k]
                for i in range(len(S)):
                    if temp[i] == '?':
                        temp[i] = 'a'
                dct.append(temp)
                break
if dct:
    #print(dct)
    print(''.join(min(dct)))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

word = []

if len(T)>len(S):
    print('UNRESTORABLE')
else:
    for i in range(len(S)-len(T)+1)[::-1]:
        tmp = S[i:i+len(T)]
        flag = True

        for j in range(len(T)):
            if tmp[j]!=T[j] and tmp[j]!='?':
                flag = False
                break

        if flag:
            w = S[:i] + T + S[i+len(T):]
            w = w.replace('?', 'a')
            print(w)
            exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

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

for i in range(len(s)-len(t)+1):
    temp = '?'*i + t + '?'*(len(s)-len(t)-i)
    
    ans = ''
    flag = True
    for j in range(len(s)):
        if s[j] == '?' and temp[j] == '?':
            ans += 'a'
        elif s[j] == '?' and temp[j] != '?':
            ans += temp[j]
        elif s[j] != '?' and temp[j] == '?':
            ans += s[j]
        elif s[j] == temp[j]:
            ans += s[j] 
        else:
            flag = False
            break

    if flag:
        print(ans)
        exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i in range(len(s)-len(t)+1):
    temp = '?'*i + t + '?'*(len(s)-len(t)-i)
    
    ans = ''
    for j in range(len(s)):
        if s[j] == '?' and temp[j] == '?':
            ans += 'a'
        elif s[j] == '?' and temp[j] != '?':
            ans += temp[j]
        elif s[j] != '?' and temp[j] == '?':
            ans += s[j]
        elif s[j] == temp[j]:
            ans += s[j] 
        else:
            break

    if j == len(s)-1:
        print(ans)
        exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

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

word = []

if len(T)>len(S):
    print('UNRESTORABLE')
else:
    for i in range(len(S)-len(T)+1):
        tmp = S[i:i+len(T)]
        flag = True

        for j in range(len(T)):
            if tmp[j] != '?':
                if tmp[j]!=T[j]:
                    flag = False
                    break
        if flag:
            w = S[:i] + T + S[i+len(T):]
            w = w.replace('?', 'a')
            word.append(w)

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

Submission status: Wrong Answer

Solution code:
s,t=input(),input()
ls=len(s)
lt=len(t)
ans=''
for i in range(ls-lt+1):
  c=0
  for j in range(lt):
    if s[i+j]==t[j] or s[i+j]=='?':
      c+=1
  if c==lt:
    ans=s[:i]+t+s[i+lt:]
    print(ans.replace('?','a'))
    break
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
l_S=len(S)
l_T=len(T)

def matchStr(S, T, l):
  f=False
  for i in range(l):
    if S[i] != "?" and S[i] != T[i]:
      f=True
      break
  if f:
    return False
  else:
    return True

f=False
for i in range(l_S-l_T+1):
  # print(S[i:i+l_T])
  if matchStr(S[i:i+l_T], T, l_T):
    S=list(S)
    T=list(T)
    S[i:i+l_T] = T
    f=True
    break

if f:
  # 後ろの方の不要な？を削除
  for i in range(l_S-1, -1, -1):
    if S[i]!="?":
      break
    else:
      S[i]=""
  for i in range(l_S):
    if S[i]=="?":
      S[i] = "a"
  S="".join(S) # リストから文字列に変換
  print(S)
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
l_S=len(S)
l_T=len(T)

def matchStr(S, T, l):
  f=False
  for i in range(l):
    if S[i] != "?" and S[i] != T[i]:
      f=True
      break
  if f:
    return False
  else:
    return True

f=False
for i in range(l_S-l_T+1):
  # print(S[i:i+l_T])
  if matchStr(S[i:i+l_T], T, l_T):
    S=list(S)
    T=list(T)
    S[i:i+l_T] = T
    f=True
    break

if f:
  for i in range(l_S):
    if S[i]=="?":
      S[i] = "a"
  S="".join(S) # リストから文字列に変換
  print(S)
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

count = 0
n = 0
ans = []
flag = 0
n=len(s)-len(t)
while n >0:
    count = 0
    for m in range(len(t)):
        if s[n+m] == "?" or s[n+m]==t[m]:
            count += 1
        else:
            break
    if count == len(t):
        flag = 1
        break
    else:
        n -= 1

if flag == 1:
    for i in range(len(s)):
        if s[i] == "?":
            s[i] = "a"
    for i in range(m+1):
        s[n+i] =t[i]
    
    for _ in s:
        print(*_,end="")

else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

count = 0
n = 0
ans = []
flag = 0
while n <len(s)-len(t)+1:
    count = 0
    for m in range(len(t)):
        if s[n+m] == "?" or s[n+m]==t[m]:
            count += 1
        else:
            break
    if count == len(t):
        flag = 1
        break
    else:
        n += 1

if flag == 1:
    for i in range(len(s)):
        if s[i] == "?":
            s[i] = "a"
    for i in range(m+1):
        s[n+i] =t[i]
    for _ in s:
        print(*_,end="")

else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

count = 0
n = 0
ans = []
flag = 0
while n <len(s)-len(t)+1:
    count = 0
    for m in range(len(t)):
        if s[n+m] == "?" or s[n+m]==t[m]:
            count += 1
        else:
            break
    if count == len(t):
        flag = 1
        break
    else:
        n += 1

if flag == 1:
    for i in range(len(s)-1):
        if s[i] == "?":
            s[i] = "a"
    for i in range(m+1):
        s[n+i] =t[i]
    for _ in s:
        print(*_,end="")

else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

count = 0
n = 0
ans = []
flag = 0
while n <len(s)-len(t)+1:
    count = 0
    for m in range(len(t)):
        if s[n+m] == "?" or s[n+m]==t[m]:
            count += 1
        else:
            break
    if count == len(t):
        flag = 1
        ans = s[0:n+m+1]
        break
    else:
        n += 1
#print(n,m)
if flag == 1:
    for i in range(n):
        if ans[i] == "?":
            ans[i] = "a"
    for i in range(m+1):
        ans[n+i] =t[i]
    for _ in ans:
        print(*_,end="")

else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

count = 0
n = 0
ans = []
flag = 0
while n <len(s)-len(t)+1:
    count = 0
    for m in range(len(t)):
        if s[n+m] == "?" or s[n+m]==t[m]:
            count += 1
    if count == len(t):
        flag = 1
        ans = s[0:n+m+1]
        break
    n += 1
#print(n,m)
if flag == 1:
    for i in range(n):
        if ans[i] == "?":
            ans[i] = "a"
    for i in range(m+1):
        ans[n+i] =t[i]
    for _ in ans:
        #print(*_,end="")
        print("a")
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

count = 0
n = 0
ans = []
flag = 0
while n <len(s)-len(t)+1:
    count = 0
    for m in range(len(t)):
        if s[n+m] == "?" or s[n+m]==t[m]:
            count += 1
    if count == len(t):
        flag = 1
        ans = s[0:n+m+1]
        break
    n += 1
#print(n,m)
if flag == 1:
    for i in range(n):
        if ans[i] == "?":
            ans[i] = "a"
    for i in range(m+1):
        ans[n+i] =t[i]
    for _ in ans:
        print(*_,end="")
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

count = 0
n = 0
ans = []
flag = 0
while n <len(s)-len(t)+1:
    count = 0
    for m in range(len(t)):
        if s[n+m] == "?" or s[n+m]==t[m]:
            count += 1
    if count == len(t):
        flag = 1
        ans = s[0:n+m+1]
        break
    n += 1
if flag == 1:
    for i in range(n+1):
        if ans[i] == "?":
            ans[i] = "a"
    for i in range(m+1):
        ans[n+i] =t[i]
    for _ in ans:
        print(*_,end="")
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

count = 0
n = 0
ans = []
flag = 0
while n <len(s)-len(t)+1:
    count = 0
    for m in range(len(t)):
        if s[n+m] == "?" or s[n+m]==t[m]:
            count += 1
    if count == len(t):
        flag = 1
        ans = s[0:n+m+1]
        break
    n += 1
if flag == 1:
    for i in range(n+1):
        if ans[i] == "?":
            ans[i] = "a"
    for i in range(m+1):
        ans[n+i] =t[i]
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input().replace('\n', '')
t=input().replace('\n', '')
begin, end = len(s) - len(t), len(s)
ans=''
while begin>=0:
    origin = s[begin:end]
    if origin!=t:
        ans = s[:begin]+t+s[end:]
        break
    begin-=1
    end-=1
print("UNRESTORABLE" if not len(ans) else ans.replace('?', 'a'))

Submission status: Wrong Answer

Solution code:
s=input().replace('\n', '')
t=input().replace('\n', '')
begin, end = len(s) - len(t), len(s)
ans=''
while begin>=0:
    origin = s[begin:end]
    flag=1
    for i in range(len(t)):
        if origin[i]!=t[i] and origin[i]!='?':
            flag=0
            break
    if flag:
        ans = s[:begin]+t+s[end:]
    begin-=1
    end-=1
print("UNRESTORABLE" if not len(ans) else ans.replace('?', 'a'))

Submission status: Wrong Answer

Solution code:
S=input().replace('\n', '')
T=input().replace('\n', '')
s, t = S[::-1], T[::-1]
tmp = '?'*(len(t)-1)+t[-1]
ans = ''
flag=True
for i in s:
    ans+=i
    if tmp in ans and flag:
        ans=ans.replace(tmp, t)
        flag=False
print("UNRESTORABLE" if flag else ans.replace('?', 'a')[::-1])

Submission status: Wrong Answer

Solution code:
s = str(input().replace('\n', ''))
t = str(input().replace('\n', ''))
s, t = s[::-1], t[::-1]
tt = len(t)-1
ss = '?'*tt + t[-1]
flag = True
ans = ''
for i in s:
    ans += i
    if ss in ans and flag:
        flag=False
        ans = ans.replace(ss, t)
print(ans.replace('?', 'a')[::-1] if flag==False else 'UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
from copy import deepcopy


def calc_key_str(aps_S, T):
    S = deepcopy(aps_S)

    for i in range(len(aps_S) - len(T) + 1):
        matched_flag = True
        for j in range(len(T)):
            if aps_S[-i-j-1] != T[-j-1] and aps_S[i-j] != '?':
                matched_flag = False
                continue

        if matched_flag:
            S_list = list(S)
            S_list[-i-len(T):len(S)-i] = T
            S = "".join(S_list)
            S = S.replace('?', 'a')
            print(S)
            break

    if not matched_flag:
        print('UNRESTORABLE')


def main():
    aps_S = input()
    T = input()

    if len(aps_S) < len(T):
        print('UNRESTORABLE')
    else:
        calc_key_str(aps_S, T)


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys

s = input()
t = input()

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

c = 0
for i in range(sl,tl-1,-1) :
  st = s[i-tl:i]
  c = 0
  for j in range(tl) :
    if st[j] == '?' :
      continue
    elif st[j] != '?' and st[j] == t[j] :
      continue
    c = 1
    break
  if c == 0 :
    s = s[:i-tl] + t + s[i:]
    break

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

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
s = list(input())
t = list(input())
lens = len(s)
lent = len(t)
ans = deepcopy(s)
for i in range(len(s)):
  if s[i] == "?":
    ans[i] = "a"
def match(moji):
  for i in range(lent):
    if moji[i] != t[i] and moji[i] != "?":
      return False
  return True
for i in range(lent, lens+1):
  ns = s[lens-i:lens-i+lent]
  if match(ns):
    ans[lens-i:lens-i+lent] = t
    print(ans)
    exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
s = list(input())
t = list(input())
lens = len(s)
lent = len(t)
ans = deepcopy(s)
for i in range(len(s)):
  if s[i] == "?":
    ans[i] = "a"
def match(moji):
  for i in range(lent):
    if moji[i] != t[i] and moji[i] != "?":
      return False
  return True
for i in range(lent, lens):
  ns = s[lens-i:lens-i+lent]
  if match(ns):
    ans[lens-i:lens-i+lent] = t
    print(ans)
    exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys
from io import StringIO
import unittest

def resolve():
    S = input()
    T = input()

    S = list(S[::-1])
    T = list(T[::-1])

    flag = 0
    for i in range(0, len(S) - len(T)):
        # Tが当てはまるかどうかの判定
        cnt = 0
        for j in range(len(T)):
            if S[i + j] == T[j] or S[i + j] == '?':
                cnt += 1

        if cnt == len(T):
            for j in range(len(T)):
                S[i + j] = T[j]
            flag = 1
            break

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

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

    S.reverse()
    print(''.join(S))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """?tc????
coder"""
        output = """atcoder"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """??p??d??
abc"""
        output = """UNRESTORABLE"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
t = input()
index_s = len(s) - 1
index_t = len(t) - 1
s_a = s.replace('?', 'a')
cnt_1 = 0
cnt_2 = 0
start_1 = 0
start_2 = 0
end = index_s
ans = []
for i in range(index_s + 1):
    if s[i] == '?' or s[i] == t[cnt_1]:
        cnt_1 += 1
    else:
        cnt_1 = 0
        start_1 = i + 1
    if cnt_1 == len(t):
        ans.append(s_a[:start_1] + t + s_a[i + 1:])
        cnt_1 = 0
    if s[index_s - i] == '?' or s[index_s - i] == t[index_t - cnt_2]:
        if cnt_2 == 0:
            start_2 = i
            end = index_s - i
        cnt_2 += 1
    else:
        cnt_2 = 0
    if cnt_2 == index_t + 1:
        ans.append(s_a[:index_s - start_2 - index_t] + t + s_a[:index_s - end])
        cnt_2 = 0
    if len(ans) == 2:
        print(sorted(ans)[0])
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

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

ans = ''
if T in S:
    for i in range(len(S)):
        if S[i] == '?':
            ans += 'a'
        else:
            ans += S[i]
    print(ans)
    sys.exit()

flg_cnt = 0
j = 0
s_p = 0
ok_flg = False
for i,v in enumerate(S):
    if v == '?' or v == T[j]:
        if j == 0:
            pointer = i
        flg_cnt += 1
        j += 1
    else:
        if v == T[0]:
            flg_cnt = 1
            j = 1
            pointer = i
        else:
            flg_cnt = 0
            j = 0
    
    if flg_cnt == len(T):
        s_p = pointer
        flg_cnt = 0
        j = 0
        ok_flg = True

if not ok_flg:
    print('UNRESTORABLE')
    sys.exit()

index = 0
while index < len(S):
    if index == s_p:
        for j in range(len(T)):
            ans += T[j]
        index += len(T)
        continue

    if S[index] == '?':
        ans += 'a'
    else:
        ans += S[index]
    
    index += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
t = input()
s_a = s.replace('?', 'a')
cnt = 0
start = 0
end = len(t)
for i in range(len(s)):
    if s[i] == '?' or s[i] == t[cnt]:
        cnt += 1
    else:
        cnt = 0
        start = i
        end = i + len(t)
    if cnt == len(t):
        print(s_a[:start] + t + s_a[end:])
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

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

flg_cnt = 0
j = 0
s_p = 0
ok_flg = False
for i,v in enumerate(S):
    if v == '?' or v == T[j]:
        if j == 0:
            pointer = i
        flg_cnt += 1
        j += 1
    else:
        if v == T[0]:
            flg_cnt = 1
            j = 1
            pointer = i
        else:
            flg_cnt = 0
            j = 0
    
    if flg_cnt == len(T):
        s_p = pointer
        flg_cnt = 0
        j = 0
        ok_flg = True

if not ok_flg:
    print('UNRESTORABLE')
    sys.exit()

index = 0
ans = ''
while index < len(S):
    if index == s_p:
        for j in range(len(T)):
            ans += T[j]
        index += len(T)
        continue

    if S[index] == '?':
        ans += 'a'
    else:
        ans += S[index]
    
    index += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
t = input()
index_s = len(s) - 1
index_t = len(t) - 1
s_a = s.replace('?', 'a')
start = index_s
end = index_s
cnt = 0
if t in s:
    print(s_a)
    exit()
for i in range(index_s + 1):
    if s[index_s - i] == '?' or s[index_s - i] == t[index_t - cnt]:
        if cnt == 0:
            start = i
            end = index_s - i
        cnt += 1
    else:
        cnt = 0
    if cnt == index_t + 1:
        print(s_a[:index_s - start - index_t] + t + s_a[:index_s - end])
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

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

flg_cnt = 0
j = 0
s_p = 0
for i,v in enumerate(S):
    if v == '?' or v == T[j]:
        if j == 0:
            s_p = i
        flg_cnt += 1
        j += 1
    else:
        if v == T[0]:
            flg_cnt = 1
            j = 1
            s_p = i
        else:
            flg_cnt = 0
            j = 0
    
    if flg_cnt == len(T):
        break
else:
    print('UNRESTORABLE')
    
index = 0
ans = ''
while index < len(S):
    if index == s_p:
        for j in range(len(T)):
            ans += T[j]
        index += len(T)
        continue

    if S[index] == '?':
        ans += 'a'
    else:
        ans += S[index]
    
    index += 1

print(ans)

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
t = input()
index_s = len(s) - 1
index_t = len(t) - 1
s_a = s.replace('?', 'a')
start = index_s
cnt = 0
if t in s:
    print(s_a)
    exit()
for i in range(index_s + 1):
    if s[index_s - i] == '?' or s[index_s - i] == t[index_t - cnt]:
        if cnt == 0:
            start = index_s - i
        cnt += 1
    else:
        cnt = 0
    if cnt == index_t + 1:
        print(s_a[:index_s - start - cnt] + t + s_a[:index_s - start])
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
t = input()
index_s = len(s) - 1
index_t = len(t) - 1
s_a = s.replace('?', 'a')
cnt = 0
if t in s:
    print(s_a)
    exit()
for i in range(len(s)):
    if s[index_s - i] == '?' or s[index_s - i] == t[index_t - cnt]:
        if cnt == 0:
            start = index_s - i
        cnt += 1
    else:
        cnt = 0
    if cnt == (index_t + 1):
        cnt = 0
        print(s_a[:index_s - start - index_t - 1] + t + s_a[:index_s - start])
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
t = input()
flag = False
index_s = len(s) - 1
index_t = len(t) - 1
cnt = 0
ans = ''
if t in s:
    print(s.replace('?', 'a'))
    exit()
for i in range(len(s)):
    if s[index_s - i] == '?' or s[index_s - i] == t[index_t - cnt]:
        if cnt == 0:
            start = index_s - i
        cnt += 1
    else:
        cnt = 0
    if cnt == (index_t + 1):
        cnt = 0
        for j in range(len(s)):
            if start == (index_s - cnt):
                ans = t + ans
                cnt += index_t
            elif s[index_s - cnt] == '?':
                ans = 'a' + ans
            else:
                ans = s[index_s - cnt] + ans
            cnt += 1
            if cnt > index_s:
                break
        print(ans)
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
t = input()
flag = False
index_s = len(s) - 1
index_t = len(t) - 1
cnt = 0
ans = ''
for i in range(len(s)):
    if s[index_s - i] == '?' or s[index_s - i] == t[index_t - cnt]:
        if cnt == 0:
            start = index_s - i
        cnt += 1
    else:
        cnt = 0
    if cnt == (index_t + 1):
        cnt = 0
        for j in range(len(s)):
            if start == (index_s - cnt):
                ans = t + ans
                cnt += index_t
            elif s[index_s - cnt] == '?':
                ans = 'a' + ans
            else:
                ans = s[index_s - cnt] + ans
            cnt += 1
            if cnt > index_s:
                break
        print(ans)
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys

s = input()
t = input()
lenS = len(s)
lenT = len(t)
ans =""
for i in range(lenS-lenT,-1,-1):
  sub = s[i:i+lenT]
  for j in range(lenT):
    if sub[j]!=t[j] and sub[j]!="?":
      break
    else:
      ans = s[:i]+t+s[i+lenT:]
      ans = ans.replace("?","a")
      print(ans)
      sys.exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys
S = input().strip()
T = input().strip()


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


ans = "UNRESTORABLE"
for i in range(len(S)-len(T), 0, -1):
    s = S[i:i+len(T)]
    if comp(s, T):
        S = S[:i] + T + S[i+len(T):]
        for i in range(len(S)):
            if S[i] == "?":
                S = S[:i] + "a" + S[i+1:]
        print(S)
        sys.exit(0)

print(ans)

Submission status: Wrong Answer

Solution code:
import re

s = input().replace('?', 'Q')
t = input()

check_chr = t[0]+'Q'*(len(t)-1)

m_obj = re.search(check_chr, s)

if m_obj:
  ans = s.replace(check_chr, t)
  ans = ans.replace('Q', 'a')
  print(ans)
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

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

res = 'UNRESTORABLE'

def check(s,t):
	if len(s) != len(t):
		return False
	else:
		for i in range(len(s)):
			if s[i] != '?' and s[i] != t[i]:
				return False
		return True

flg = False
for i in range(len(s)-len(t)+1):
	L = len(t)
	sub = s[i:L+i]
	if check(sub,t):
		new = s[:i] + t + s[L+i:]
		flg = True
		break

if flg:
	print(new.replace('?', 'a'))
else:
	print(res)

Submission status: Wrong Answer

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

ans = ""
if len(T) > len(S):
    ans = "UNRESTORABLE"
else:
    ls = len(S)
    lt = len(T)
    for i in reversed(range(ls-lt+1)):
        tmp = S[i:i+lt]
        cnt = 0
        flag = True
        for j in range(lt):
            if tmp[j] != "?":
                if tmp[j] != T[j]:
                    flag = False
                    break
        if flag:
            ans = ""
            for h in range(i):
                if S[h] == "?":
                    ans += "a"
                else:
                    ans += S[h]
            ans += T
            for h in range(i+lt,ls):
                if S[h] == "?":
                    ans += "a"
                else:
                    ans += S[h]
            print(ans)
            exit()
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

ans = ""
if len(T) > len(S):
    ans = "UNRESTORABLE"
else:
    ls = len(S)
    lt = len(T)
    for i in range(ls-lt+1):
        tmp = S[i:i+lt]
        flag = True
        for j in range(lt):
            if tmp[j] != "?":
                if tmp[j] != T[j]:
                    flag = False
                    break
        if flag:
            ans = ""
            for h in range(i):
                if S[h] == "?":
                    ans += "a"
                else:
                    ans += S[h]
            ans += T
            for h in range(i+lt,ls):
                if S[h] == "?":
                    ans += "a"
                else:
                    ans += S[h]
            print(ans)
            exit()
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

if len(s) < len(t):
    print('UNRESTORABLE')
    exit()
ansl = []

if t in s:
    print(s.replace('?', 'a'))
else:
    for i in range(len(s)-len(t)+1):
        flag = True
        for j in range(len(t)):
            if s[i+j] == t[j] or s[i+j] == '?':
                continue
            else:
                flag = False
        if flag:
            ans = s[:i]+t+s[i+len(t):]
            ans = ans.replace('?', 'a')
            ansl.append(ans)

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

Submission status: Wrong Answer

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

if len(s) <= len(t):
    print('UNRESTORABLE')
    exit()
ansl = []

if t in s:
    print(s.replace('?', 'a'))
else:
    for i in range(len(s)-len(t)+1):
        flag = True
        for j in range(len(t)):
            if s[i+j] == t[j] or s[i+j] == '?':
                continue
            else:
                flag = False
        if flag:
            ans = s[:i]+t+s[i+len(t):]
            ans = ans.replace('?', 'a')
            ansl.append(ans)

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