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:
# pythonはindexでstringの文字を変更できない
s = list(input())
t = list(input())
x = 0
ans = []
gotk = False

# pythonて関数にするとスコープの外の変数参照できないんだっけ？

# 0 <= k <= s - t
def match(k):
  for i in range(len(t)):
    if s[i + k] != t[i] and s[i + k] != "?":
      return False
  return True

def construct(k,s):
  s = s[:k] + t
  for i in range(len(t)):
    s[i + k] = t[i]
  for i in range(len(s)):
    if s[i] == "?":
      s[i] = "a"
  return s

# 大きいkから探せば良い(今回逆順にしてるためrangeの第二引数が直前まで処理されることに注意！)
for i in range(len(s) - len(t),-1,-1):
  if match(i):
    x = i
    gotk = True
    break

if gotk == True:
  ans = construct(x,s)
  print("".join(ans))
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
x = 0
ans = ""
gotk = False

# pythonて関数にするとスコープの外の変数参照できないんだっけ？

# 0 <= k <= s - t
def match(k):
  for i in range(len(t)):
    if s[i + k] != t[i] and s[i + k] != "?":
      return False
  return True

def construct(k,s):
  # pythonはindexでstringの文字を変更できない
  s = s[:k] + t
  s = s.replace("?","a")
  return s

# 大きいkから探せば良い(今回逆順にしてるためrangeの第二引数が直前まで処理されることに注意！)
for i in range(len(s) - len(t),-1,-1):
  print(i)
  if match(i):
    x = i
    gotk = True
    break

if gotk == True:
  ans = construct(x,s)
  print(ans)
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
s1 = input()
t = input()
pre = ""
count = 0
ans = ""
start = 0
end = 0
it = ""


for w in s1:
  if count > len(t) - 1:
    dif = count - (len(t) - 1)
    count -= dif
    it = it[dif:]
  if w == t[count]:
    count += 1
    it += w
  elif pre == "?" and w == t[0]:
    count = 1
    it = w
  elif w != "?" and pre == "?":
    pre = w
    count = 0
    it = ""
  elif w == "?" and pre == "?":
    count += 1
    it += w
  else:
    if w == "?":
      pre = w
      count += 1
      it += w

  # if count >= len(t):
  #   print("きたよ")
  #   print(w)
  #   end = s1.index(w)
  #   start = end - len(t)
#print(f"count is {count}")
#print("endは" + end)
#replace = "?" * len(t)
#print("replace is" + it)
if count >= len(t):
  it = it.replace("?","\?")
  # 合致した最も後方のものを置換
  ans = re.sub(it,t,s1)
  ans = ans.replace("?","a")
  #print(ans)
  # if end < len(s1) - 1:
  #   ans = s1[:start] + t + s1[end+1:]
  #   # 全てaに置換
  #   ans = ans.replace("?","a")
  #   print(ans)
  # else:
  #   ans = s1[:start] + t
  #   ans = ans.replace("?","a")
  print(ans)
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
S=input()
T=input()
flg=False
for i in range(len(S)-len(T)+1):
    sub=S[i:i+len(T)].replace('?','.')
    if re.match(sub,T):
        flg=True
if flg:
    ans=''
    S=S.replace('?','a')
    ans=S[0:i]+T+S[i+len(T):] if i+len(T)<len(S) else S[0:i]+T
    print(ans)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
sr = len(s)
tr = len(t)
final_flag = False
for i in range(sr-tr+1):
    flag = True
    for j in range(tr):
        if s[i+j] != '?' and s[i+j] != t[j]:
            flag = False
    if flag:
        final_flag = True
        s = s[0:i] + t + s[(i+tr):]

if final_flag:
    print(s.replace("?", "a"))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

s_d = s_d[::-1]
t = t[::-1]
t_r = ''

for i in range(len(s_d)-len(t)):
    for j in range(len(t)):
        if s_d[i+j] == t[j] or s_d[i+j] == '?':
            t_r += s_d[i+j]
            continue
        else:
            break
    else:
        s = s_d.replace(t_r, t, 1)
        s = s.replace('?', 'a')
        print(s[::-1])
        break
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

for i in range(1, len(t)+1):
    new_t = t[:-i] + '?'*i
    if s_d.rfind(new_t) < 0:
        continue
    else:
        s_d = s_d[::-1]
        s = s_d.replace(new_t[::-1], t[::-1], 1)
        s = s.replace('?', 'a')
        s = s[::-1]
        print(s)
        break
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

if s_d.rfind(t) >= 0:
    print(s_d.replace('?', 'a'))
else:
    for i in range(1, len(t)+1):
        new_t = t[:-i] + '?'*i
        p = s_d.rfind(new_t)
        if p < 0:
            continue
        else:
            s_d = s_d[::-1]
            s = s_d.replace(new_t[::-1], t[::-1], 1)
            s = s.replace('?', 'a')
            s = s[::-1]
            print(s)
            break
    else:
        print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    T = inputs[1]
    sn = len(S)
    tn = len(T)
    start = None

    for si, s in enumerate(S):
        if tn > (sn - si):
            break
        if s == T[0] or s == '?':
            sj = start = si
            for t in T:
                sj_c = S[sj]
                if not (t == sj_c or sj_c == '?'):
                    start = None
                    break
                sj += 1
            if start is not None:
                break

    if start is None:
        return "UNRESTORABLE"

    ret = []
    ti = 0
    for si, s in enumerate(S):
        if si >= start and si < len(T) + start:
            ret.append(T[ti])
            ti += 1
        else:
            if s == '?':
                ret.append('a')
            else:
                ret.append(s)
    return ''.join(ret)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Submission status: Wrong Answer

Solution code:
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections
import bisect


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    S = inputs[0]
    T = inputs[1]
    sn = len(S)
    tn = len(T)
    start = None

    for si, s in enumerate(S):
        if tn > (sn - si):
            break
        if s == T[0] or s == '?':
            sj = start = si
            for t in T:
                sj_c = S[sj]
                if not (t == sj_c or sj_c == '?'):
                    start = None
                    break
                sj += 1
            if start:
                break

    if not start:
        return "UNRESTORABLE"

    ret = []
    ti = 0
    for si, s in enumerate(S):
        if si >= start and si < len(T) + start:
            ret.append(T[ti])
            ti += 1
        else:
            if s == '?':
                ret.append('a')
            else:
                ret.append(s)
    return ''.join(ret)


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    ret = solve(inputs(2))
    print(ret)

Submission status: Wrong Answer

Solution code:
s_dash = input()
t = input()
answer = 'UNRESTORABLE'
if s_dash < t:
    pass
else:
    for i in range(len(s_dash)-len(t)+1):
        for j, k in zip(s_dash[i:i+len(t)], t):
            if j != '?' and j != k:
                break
        else:
            answer = s_dash[:i] + t + s_dash[i+len(t):]
            answer = answer.replace('?', 'a')
print(answer)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
index = 0
s = ''.join(list(reversed(s)))
t = ''.join(list(reversed(t)))
#まず、？とtの統合性が取れているかを確認
#後ろから調べてく
exit_flag = True
for i in range(len(s)):
    if s[i] == t[0] or s[i] == '?':
        if i + len(t) >= len(s):
            break
        for j in range(len(t)):
            if not (s[i + j] == t[j] or s[i + j] == '?'):
                break
            if j == len(t) - 1:
                start_index = i
                exit_flag = False
        if not exit_flag:
            break
#条件に合わなかったら終わり

if exit_flag:
    print("UNRESTORABLE")
    exit()
ans = s[:start_index] + t + s[start_index + len(t):]
ans = ''.join(list(reversed(ans)))
ans = ans.replace("?","a")
print(ans)

Submission status: Wrong Answer

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

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

    s_includet = S
    permit = ["?"*len(T)]
    LENT = len(T)
    for i in range(1,LENT+1):
        permit.append(T[0:i] + "?"*(LENT-i))
    permit_index = []
    for i in range(len(S)-LENT+1):
        for ip in permit:
            if S[i:i+LENT] == ip:
                permit_index.append(i)
    if not permit_index:
        print("UNRESTORABLE")
        return
    answer = S.replace("?","z")
    S = S.replace("?","a")
    for i in permit_index:
        s = S[:i]+T+S[i+LENT:]
        answer = min(answer,s)
    
    print(answer)
    return

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
m=len(s)
n=len(t)
check=False
for i in range(m-n,-1,-1):
  for j in range(i,i+n):
    check2=True
    if s[j]=='?' or s[j]==t[j-i]:
      continue
    else:
      check2=False
  if check2:
    check=True
    s=s[:i]+t+s[i+n:]
    s=s.replace('?','a')
    break
print(s if check else 'UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s=input()
count=s.count('?')
t=input()
m=len(s)
n=len(t)
check=False
for i in range(m-n,-1,-1):
  for j in range(i,i+n):
    if s[j]=='?' or s[j]==t[j-i]:
      continue
    else:
      s=s[:j]+'?'+s[j+1:]
  if s.count('?')==count:
    check=True
    s=s[:i]+t+s[i+n:]
    s=s.replace('?','a')
    break
print(s if check else 'UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()

if len(S) < len(T):
    print(ans)
    sys.exit()
tmp = True
anss = 0
anse = 0
for i in range(len(S) - len(T) + 1):
    tmp = True
    s = i
    e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break
    if tmp == False:
        s = -1
        e = -1
    else:
        anss = i
        anse = i + len(T)

if s == -1:
    print(ans)

else:
    ans = S.replace('?', 'a')
    ans = ans[:anss] + T + ans[anse:]
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()
    
if len(S) < len(T):
    print(ans)
    sys.exit()
tmp = False

for i in range(len(S) - len(T) + 1):
    if tmp == False:
        tmp = True
        s = i
        e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break
    if tmp == False:
        s = -1
        e = -1
    else:
        s = i
        e = i + len(T)

if s == -1:
    print(ans)

else:
    ans = S.replace('?', 'a')
    ans = ans[:s] + T + ans[s + len(T):]
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()

tmp = False

for i in range(len(S) - len(T) + 1):
    if tmp == False:
        tmp = True
        s = i
        e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break
    if tmp == False:
        s = -1
        e = -1
    else:
        s = i
        e = i + len(T)

if s == -1:
    print(ans)

else:
    ans = S.replace('?', 'a')
    ans = ans[:s] + T + ans[s + len(T):]
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()

tmp = False
s = 0
e = 0
for i in range(len(S) - len(T) + 1):
    if tmp == False:
        tmp = True
        s = i
        e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break
    if tmp == False:
        s = -1
        e = -1
    else:
        s = i
        e = i + len(T)

if s == -1:
    print(ans)

else:
    ans = S.replace('?', 'a')
    ans = ans[:s] + T + ans[s + len(T):]
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()

tmp = False
s = 0
e = 0
for i in range(len(S) - len(T) + 1):
    if tmp == False:
        tmp = True
        s = i
        e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break
    if tmp == False:
        s = -1
        e = -1
    else:
        s = i
        e = i + len(T)

if s == -1:
    print(ans)

else:
    ans = S.replace('?', 'a')
    ans = ans[:s] + T + ans[e:]
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()

if S.count(T) != 0:
    S = S.replace('?', 'a')
    print(S)
    sys.exit()
tmp = False
s = 0
e = 0
for i in range(len(S) - len(T) + 1):
    if tmp == False:
        tmp = True
        s = i
        e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break
    if tmp == False:
        s = -1
        e = -1
    else:
        s = i
        e = i + len(T)

if s == -1:
    print(ans)
else:
    ans = S.replace('?', 'a')
    ans = ans[:s] + T + ans[e:]
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()

if S.count(T) != 0:
    S = S.replace('?', 'a')
    print(S)
    sys.exit()

tmp = False
for i in range(len(S) - len(T) + 1):
    if tmp == False:
        tmp = True
        s = i
        e = i + len(T)
        
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break
            
    if tmp == False:
        s = -1
        e = -1

if s == -1:
    print(ans)
else:
    ans = S.replace('?', 'a')
    ans = ans[:s] + T + ans[e:]
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()

if S.count(T) != 0:
    S = S.replace('?', 'a')
    print(S)
    sys.exit()

for i in range(len(S) - len(T) + 1):
    tmp = True
    s = i
    e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break

    if tmp:
        break
    else:
        s = -1
        e = -1
#if s == -1:
#    print(ans)
#else:
ans = S.replace('?', 'a')
ans = ans[:s] + T + ans[e:]
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()

if S.count(T) != 0:
    S = S.replace('?', 'a')
    print(S)
    sys.exit()

for i in range(len(S) - len(T) + 1):
    tmp = True
    s = i
    e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break

    if tmp:
        break
    else:
        s = -1
        e = -1
if s == -1:
    print(ans)
else:
    ans = S.replace('?', 'a')
    ans = ans[:s] + T + ans[e:]
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()

if S.count(T) != 0:
    S = S.replace('?', 'a')
    print(S)
    sys.exit()

for i in range(len(S) - len(T) + 1):
    tmp = True
    s = i
    e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break

    if tmp:
        break
    else:
        s = -1
        e = -1
#if s == -1:
#    print(ans)
else:
    ans = S.replace('?', 'a')
    ans = ans[:s] + T + ans[e:]
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'
print(ans)

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()

for i in range(len(S) - len(T) + 1):
    tmp = True
    s = i
    e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break

    if tmp:
        break
    else:
        s = -1
        e = -1
if s == -1:
    print(ans)
else:
    ans = S.replace('?', 'a')
    ans = ans[:s] + T + ans[e:]
    print(ans)

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()

if S.count(T) != 0:
    S = S.replace('?', 'a')
    print(S)
    sys.exit()

for i in range(len(S) - len(T) + 1):
    tmp = True
    s = i
    e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break

    if tmp:
        break
    else:
        s = -1
        e = -1
if s == -1:
    print(ans)
else:
    ans = S.replace('?', 'a')
    ans = ans[:s] + T + ans[e:]
    print(ans)

Submission status: Wrong Answer

Solution code:
"""
出典:https://atcoder.jp/contests/abc076/tasks/abc076_c
"""

def main():
  S, T = input(), input()
  if len(S)<len(T):
    print("UNRESTORABLE")
    return

  p_flg=False

  for i in range(len(S)-len(T)):
    for j in range(len(T)):
      if S[len(S)-len(T)-i:len(S)-i][j] == T[j]:
        continue
      else:
        if S[len(S)-len(T)-i:len(S)-i][j] == '?':
          continue
        else: 
          break
    else:
      S2 = S[:len(S)-len(T)-i] + T + S[len(S)-i:]
      p_flg=True
      break
  if p_flg:
    print(S2.replace('?','a'))
    return
  else:
    print("UNRESTORABLE")
    return

if __name__ == "__main__":
  main()

Submission status: Wrong Answer

Solution code:
from itertools import permutations
import re


def main():
    s = input().replace('?', '.')
    t = input()

    for i in reversed(range(len(s) - len(t) + 1)):
        print(s[i:i + len(t)])
        if re.search(s[i:i + len(t)], t):
            result = (s[:i] + t + s[i + len(t):]).replace('.', 'a')
            print(result)
            return

    print('UNRESTORABLE ')

main()

Submission status: Wrong Answer

Solution code:
w=input()
w1=input()
num=len(w)
num1=len(w1)
start=-1
if num<num1:
  b1=False
for i in range(num-num1+1):
  b=True
  for j in range(num1):
    if w[i+j]=="?" or w[i+j]==w1[j]:
      pass
    else:
      b=False
  if b:
      start=i
if start==-1:
  print("UNRESTORABLE")
else:
  word=""
  if start!=0:
    for i in range(num):
      if i<start:
        if w[i]=="?":
          word+="a"
        else:
          word+=w[i]
      elif start<=i and i<=start+num1-1:
        word+=w1[i-start]
      else:
        if w[i]=="?":
          word+="a"
        else:
          word+=w[i]
  print(word)

Submission status: Wrong Answer

Solution code:
w=input()
w1=input()
num=len(w)
num1=len(w1)
start=-1
if num<num1:
  b1=False
for i in range(num-num1+1):
  b=True
  for j in range(num1):
    if w[i+j]=="?" or w[i+j]==w1[j]:
      pass
    else:
      b=False
  if b:
      start=i
if start==-1:
  print("UNRESTORABLE")
else:
  word=""
  if start!=0:
    for i in range(start):
      if w[i]=="?":
        word+="a"
      else:
        word+=w[i]
    for i in range(start,num1+start):
      word+=w1[i-start]
    for i in range(num1,num):
      word+=w[i]
  else:
    word+=w1
    for i in range(num1,num):
      if w[i]=="?":
        word+="a"
      else:
        word+=w[i]
  print(word)

Submission status: Wrong Answer

Solution code:
w=input()
w1=input()
num=len(w)
num1=len(w1)
if num<num1:
  b=False
for i in range(num-num1+1):
  b=True
  for j in range(num1):
    if w[i+j]=="?" or w[i+j]==w1[j]:
      pass
    else:
      b=False
  if b:
      start=i
      break
if not b:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
w=input()
w1=input()
num=len(w)
num1=len(w1)
if num<num1:
  b=False
for i in range(num-num1+1):
  b=True
  for j in range(num1):
    if w[i+j]=="?" or w[i+j]==w1[j]:
      pass
    else:
      b=False
  if b:
      start=i
      break

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
n = len(s)
m = len(t)
cand = []
for i in range(n-m+1):
    flag = True
    for j in range(m):
        if s[i+j] != t[j] and s[i+j] != "?":
            flag = False
            break
    if flag:
        if i != n-m:
            tmp = (s[:i] + t + s[i+m+1:]).replace("?", "a")
        else:
            tmp = (s[:i] + t).replace("?", "a")
        cand.append(tmp)
cand = sorted(cand)
if cand:
    print(cand[0])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
n = len(s)
m = len(t)
cand = []
for i in range(n-m+1):
    flag = True
    for j in range(m):
        if s[i+j] != t[j] and s[i+j] != "?":
            flag = False
            break
    if flag:
        tmp = s.replace(s[i:i+m+1], t).replace("?", "a")
        cand.append(tmp)
cand = sorted(cand)
if cand:
    print(cand[0])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools
    import string

    s_dash = input()
    t = input()

    a_z = string.ascii_lowercase
    size_t = len(t)
    i_forward = {char: size_t for char in a_z}
    for i, char in enumerate(t):
        if i_forward[char] != size_t:
            i_forward[char] = i

    # for i in range(len(s_dash) - len(t), -1, -1):
    i = len(s_dash) - len(t)
    while i >= 0:
        # for j, char in enumerate(t):
        j = 0
        while j <= size_t - 1:
            if s_dash[i + j] == t[j] or s_dash[i + j] == '?':
                j += 1
                pass
            else:
                char_index = i_forward[s_dash[i + j]]
                i -= char_index - j
                break
        else:
            break
    else:
        print("UNRESTORABLE")
        exit()

    ans = list(s_dash[:i] + t + s_dash[i + size_t:])
    for i in range(len(ans) - 1):
        if ans[i] == '?':
            ans[i] = 'a'
    print(''.join(ans))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
t = len(T)
u = S[-t:]
idx = 0
for i, j in zip(T, u):
    if j == "?":
        idx += 1
        pass
    if i == j:
        idx += 1
        pass
    if idx == t:
        for i in range(len(S)):
            if i == len(S)-t:
                break
            if S[i] == "?":
                print('a', end='')
            else:
                print(S[i], end='')
        for j in T:
            print(j, end='')
        print()
        exit()
for i in range(1, len(S)):
    if i+t == len(S)+1:
        break
    idx = 0
    for j, k in zip(S[-(i+t):-i], T):
        if j == "?":
            idx += 1
            pass
        if j == k:
            idx += 1
            pass
        if idx == t:
            for o in range(i+t):
                if S[o] == '?':
                    print('a', end='')
                else:
                    print(S[o], end='')
            for p in T:
                print(p, end='')
            for q in range(i):
                if S[-(q+1)] == '?':
                    print('a', end='')
                else:
                    print(S[-(q+1)], end='')
            exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
t = len(T)
u = S[-t:]
idx = 0
for i, j in zip(T, u):
    if j == "?":
        idx += 1
        pass
    if i == j:
        idx += 1
        pass
    if idx == t:
        for i in range(len(S)):
            if i == len(S)-t:
                break
            if S[i] == "?":
                print('a', end='')
            else:
                print(S[i], end='')
        for j in T:
            print(j, end='')
        print()
        exit()
for i in range(1, len(S)):
    if i+t == len(S)+1:
        break
    idx = 0
    for j, k in zip(S[-(i+t):-i], T):
        if j == "?":
            idx += 1
            pass
        if j == k:
            idx += 1
            pass
        if idx == t:
            for o in range(i+t):
                if S[o] == '?':
                    print('a', end='')
                else:
                    print(S[o], end='')
            for p in T:
                print(p, end='')
            for q in range(i):
                if S[-(q+1)] == '?':
                    print('a', end='')
                else:
                    print(S[-(q+1)], end='')

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
cnt = 0 #Tで置き換える必要のある?の個数
i = 0
j = 0
while j < len(S):
    if T[-i] == S[-j] or S[-j] == "?":
        i += 1
        cnt += 1
    else:
        i, cnt = 0, 0
    j += 1
    if i == len(T) and (T[-i] == S[-j] or S[-j] == "?"):
        l = 0
        for l in range(len(S)):
            if S[l] == "?" and (l <= len(S)-j-1 or len(S)-j-1+len(T) < l):
                print("a",end="")
            elif S[l] == "?":
                print(T[-cnt+1],end="")
                cnt -= 1
            else:
                print(S[l],end="")
        print()
        sys.exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

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

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

idx = None
if len(rs) > len(rt):
  for i in range(len(rs)-len(rt)+1):
    flg = True
    for j in range(len(rt)):
      si = i + j
      if rs[si] != rt[j] and rs[si] != '?':
        flg = False
    if flg:
      idx = i
    break

if idx is None:
  print('UNRESTORABLE')
else:
  for i in range(idx, idx+len(rt)):
    rs[i] = rt[i-idx]
  for i in range(len(rs)):
    if rs[i] == '?':
      rs[i] = 'a'
  print("".join(rs[::-1]))

Submission status: Wrong Answer

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

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

idx = None
for i in range(len(rs)-len(rt)+1):
  flg = True
  for j in range(len(rt)):
    si = i + j
    if rs[si] != rt[j] and rs[si] != '?':
      flg = False
  if flg:
    idx = i
  break

if idx is None:
  print('UNRESTORABLE')
else:
  for i in range(idx, idx+len(rt)):
    rs[i] = rt[i-idx]
  for i in range(len(rs)):
    if rs[i] == '?':
      rs[i] = 'a'
  print("".join(rs[::-1]))

Submission status: Wrong Answer

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

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

idx = None
if len(rs) >= len(rt):
  for i in range(len(rs)-len(rt)):
    flg = True
    for j in range(len(rt)):
      si = i + j
      if rs[si] != rt[j] and rs[si] != '?':
        flg = False
    if flg:
      idx = i
    break

if idx is None:
  print('UNRESTORABLE')
else:
  for i in range(idx, idx+len(rt)):
    rs[i] = rt[i-idx]
  for i in range(len(rs)):
    if rs[i] == '?':
      rs[i] = 'a'
  print("".join(rs[::-1]))

Submission status: Wrong Answer

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

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

idx = None
for i in range(len(rs)-len(rt)):
  flg = True
  for j in range(len(rt)):
    si = i + j
    if rs[si] != rt[j] and rs[si] != '?':
      flg = False
  if flg:
    idx = i
    break

if idx is None:
  print('UNRESTORABLE')
else:
  for i in range(idx, idx+len(rt)):
    rs[i] = rt[i-idx]
  for i in range(len(rs)):
    if rs[i] == '?':
      rs[i] = 'a'
  print("".join(rs[::-1]))

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
M = len(S)
N = len(T)
for start in range(M-N,-1,-1):
    for i in range(N):
        if not (S[start+i] == '?' or S[start+i] == T[i]):
            break
    else:
        break
else:
    print('UNRESTORABLE')
    exit()

end = start + N
pre = ''
post = ''
for i in range(start):
    if S[i] == '?':
        pre += 'a'
    else:
        pre += S[i]
for i in range(end,M):
    if S[i] == '?':
        post += 'a'
    else:
        pre += S[i]
print(pre + T + post)

Submission status: Wrong Answer

Solution code:
S = str(input())  # ?が入っている文字列
T = str(input())  # 部分文字列

# 2重ループで大丈夫

index = None
for i in range(len(S)):
    if S[i] == T[0] or S[i] == '?':
        # ループを始める
        start = i
        cnt = 0
        for j in range(i, min(len(T)+i, len(S))):
            if S[j] == T[j-i] or S[j] == '?':
                cnt += 1
            else:
                break

        if cnt == len(T):
            index = start  # 保存しておく

if index:
    i = 0
    ans = ""
    while len(S) > i:
        if i != index:
            if S[i] == '?':
                ans += 'a'
            else:
                ans += S[i]
            i += 1
        elif i == index:
            ans += T
            i += len(T)

    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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