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()
n=len(s)
m=len(t)
ans='UNRESTORABLE'
a=[]
for i in range(n-m+1):
  if s[i]==t[0]:
    for j in range(m):
      if s[i+j]!=t[j] and s[i+j]!='?':
        break
    else:
      an=''
      for k in range(i):
        if s[k]=='?':
          an+='a'
        else:ans+=s[k]
      an+=t
      for k in range(i+m,n):
        if s[k]=='?':
          an+='a'
        else: an+=s[k]
      a.append(an)
if len(a):
  print(min(a))
else:print(ans)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
n=len(s)
m=len(t)
ans='UNRESTORABLE'
for i in range(n-m+1):
  if s[i]==t[0]:
    for j in range(m):
      if s[i+j]!=t[j] and s[i+j]!='?':
        break
    else:
      ans=''
      for k in range(i):
        if s[k]=='?':
          ans+='a'
        else:ans+=s[k]
      ans+=t
      for k in range(i+m,n):
        if s[k]=='?':
          ans+='a'
        else: ans+=s[k]
      break
print(ans)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math
import sys
from collections import deque
import copy
import itertools
from itertools import permutations
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
s=i()
t=i()
for i in range(len(s)-len(t)+1):
  ju=True
  for j in range(len(t)):
    if not (s[i+j]==t[j] or s[i+j]=="?"):
      ju=False
      break
  if ju:
    if i==0:
      print(t,end="")
      for n in range(len(t),len(s)):
        if s[n]=="?":
          print("a",end="")
        else:
          print(s[n],end="")
      sys.exit()
    else:
      for n in range(i):
        if s[n]=="?":
          print("a",end="")
        else:
          print(s[n],end="")
      print(t,end="")
      for ss in range(len(t)+i,len(s)):
        if s[ss]=="?":
          print("a",end="")
        else:
          print(s[ss],end="")
      sys.exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import math
import sys
from collections import deque
import copy
import itertools
from itertools import permutations
def mi() : return map(int,sys.stdin.readline().split())
def ii() : return int(sys.stdin.readline().rstrip())
def i() : return sys.stdin.readline().rstrip()
s=i()
t=i()
for i in range(len(s)-len(t)+1):
  ju=True
  for j in range(len(t)):
    if not (s[i+j]==t[j] or s[i+j]=="?"):
      ju=False
      break
  if ju:
    if i==0:
      print(t,end="")
      for n in range(len(t),len(s)):
        if s[n]=="?":
          print("a",end="")
        else:
          print(s[n],end="")
      sys.exit()
    else:
      for n in range(i):
        if s[n]=="?":
          print("a",end="")
        else:
          print(s[n],end="")
      print(t,end="")
      for ss in range(len(t)+i,len(s)):
        if s[n]=="?":
          print("a",end="")
        else:
          print(s[n],end="")
      sys.exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

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

s = len(S)
t = len(T)

ans = []
for i in range(s - t + 1):
    flg = 0
    for j in range(t):
        if S[i+j] == T[j]:
            pass
        elif S[i+j] == '?':
            pass
        else:
            flg = 1
            break
    if flg == 0:
        ans.append(S[0:i] + T + S[i+t+1:])
if len(ans) == 0:
    print('UNRESTORABLE')
else:
    print(ans[-1].replace('?', 'a'))

Submission status: Wrong Answer

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

ans = ""
flag = False
for i, s in enumerate(S):
  count = 0
  for t in T:
    if i + count < len(S):
      if S[i+count] == "?" or s == t:
        count += 1
      else:
        break

      if count == len(T):
        ans = S[:i] + T + S[i+count:]
        flag = True


an = ""
for x in ans:
  if x == "?":
    an += "a"
  else:
    an += x

if flag:
  print(an)
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

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

ans = "z" * 100
for i in range(len(S) - len(T) +1)[::-1]:
  ok = True

  for j in range(len(T)):
    if S[i+j] != "?" and S[i+j] != T[j]:
      ok = False
    if ok:
      s = S[:i] + T + S[i+len(T):]
      s = "".join(s)
      ans = min(ans, s.replace("?", "a"))
      break
if ans == "z" * 100:
  print("UNRESTORABLE")
else:
  print(ans)

Submission status: Wrong Answer

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

ans = ""
flag = False
list = []
for i, s in enumerate(S):
  count = 0
  for t in T:
    if i + count < len(S):
      if S[i+count] == "?" or s == t:
        count += 1
      else:
        break

      if count == len(T):
        ans = S[:i] + T + S[i+count:]
        an = ""
        for x in ans:
          if x == "?":
            an += "a"
          else:
            an += x
        flag = True
        list.append(an)

list.sort()

if flag:
  print(list[0])
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

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

ans = ""
flag = False
for i, s in enumerate(S):
  count = 0
  for t in T:
    if i + count < len(S):
      if S[i+count] == "?" or s == t:
        count += 1
      else:
        break

      if count == len(T):
        ans = S[:i] + T + S[i+count:]
        flag = True


an = ""
for x in ans:
  if x == "?":
    an += "a"
  else:
    an += x

if flag:
  print(an)
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

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

ans = ""
flag = False
for i, s in enumerate(S):
  count = 0
  if flag:
    break
  for t in T:
    if i + count < len(S):
      if S[i+count] == "?" or s == t:
        count += 1
      else:
        break

      if count == len(T):
        ans = S[:i] + T + S[i+count:]
        flag = True


an = ""
for x in ans:
  if x == "?":
    an += "a"
  else:
    an += x

if flag:
  print(an)
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

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

ans = ""
flag = False
for i, s in enumerate(S):
  count = 0
  if flag:
    break
  for t in T:
    if i + count < len(S):
      if S[i+count] == "?" or s == t:
        count += 1
      else:
        break

      if count == len(T):
        ans = S[:i] + T
        flag = True


an = ""
for x in ans:
  if x == "?":
    an += "a"
  else:
    an += x

if flag:
  print(an)
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

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

ans = ""
flag = False
for i, s in enumerate(S):
  count = 0
  if flag:
    break
  for t in T:
    if i + count < len(S):
      if S[i+count] == "?" or s == t:
        count += 1
      else:
        break

      if count == len(T):
        ans = S[:i] + T
        flag = True


an = ""
for x in ans:
  if x == "?":
    an += "a"
  else:
    an += x

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

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
c = -1
for i in range(len(s)-len(t)+1):
    sw = 1
    for j in range(len(t)):
        if s[i+j] == "?":
            pass
        elif s[i+j] == t[j]:
            pass
        else:
            sw = 0
            break
    if sw == 1:
        c = i
if c == -1:
    ans = "UNRESTORABLE"
else:
    a = []
    i = 0
    while i < len(s):
        if i == c:
            a.append(t)
            i += len(s)-1
        elif s[i] != "?":
            a.append(s[i])
            i += 1
        else:
            a.append("a")
            i += 1
    ans = "".join(a)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
c = -1
for i in range(len(s)-len(t)+1):
    sw = 1
    for j in range(len(t)):
        if s[i+j] == "?":
            pass
        elif s[i+j] == t[j]:
            pass
        else:
            sw = 0
            break
    if sw == 1:
        c = i
if c == -1:
    ans = "UNRESTORABLE"
else:
    a = []
    i = 0
    while i < len(s):
        if i == c:
            a.append(t)
            i += len(s)
        elif s[i] != "?":
            a.append(s[i])
        else:
            a.append("a")
        i += 1
    ans = "".join(a)
print(ans)

Submission status: Wrong Answer

Solution code:
s,t=input(),input()
q = '?'*len(t)
judge = True
for i in range(len(s)-len(t)+1):
  judge = True
  for j in range(len(t)):
    if s[i+j]!=t[j] and s[i+j]!='?':
      judge = False
      break
  if judge:
    s = s[:i] + t + s[len(t)+i:]
    break
if judge:
	s = ['a' if i=='?' else i for i in s]
	print(''.join(s))
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s,t=input(),input()
q = '?'*len(t)
judge = False
for i in range(len(s)):
  if (s[i:len(t)+i][0]==t[0] and s[i:len(t)+i][1:]==q[1:]) or s[i:len(t)+i]==q:
    s = s[:i] + t + s[len(t)+i:]
    judge = True
    break
if judge:
	s = ['a' if i=='?' else i for i in s]
	print(''.join(s))
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s,t=input(),input()
q = '?'*len(t)
judge = False
for i in range(len(s)):
  if s[i:len(t)+i][0]==t[0] or s[i:len(t)+i][0]==q:
    s = s[:i] + t + s[len(t)+i:]
    judge = True
    break
if judge:
	s = ['a' if i=='?' else i for i in s]
	print(''.join(s))
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

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

ck = 0
tl = len(T)
arr = []

for i in range(len(S)):
  a = S[len(S)-i-1]
  if ck < tl and ( a == T[tl-ck-1] or a == "?"):
    ck += 1
  else:
    ck = 0
  if tl == ck:
    arr.append(len(S)-i-tl+ck-1)
    ck = 0 

    
if len(arr) == 0:
  print("UNRESTORABLE")
else:
  b = arr[0]
  ans = ""
  for i in range(len(S)):
    if i == b:
      ans += ''.join(T)
    elif i > b and i < b + tl:
      continue
    else:
      if S[i] == "?":
        ans += "a"
      else:
        ans += S[i]
  print(ans)

Submission status: Wrong Answer

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

ck = 0
tl = len(T)
arr = []

for i in range(len(S)):
  a = S[len(S)-i-1]
  if ck < tl and ( a == T[tl-ck-1] or a == "?"):
    ck += 1
  else:
    ck = 0
  if tl == ck:
    arr.append(len(S)-i-tl+ck)
    ck = 0 

    
if len(arr) == 0:
  print("UNRESTORABLE")
else:
  b = arr[0]
  ans = ""
  for i in range(len(S)):
    if i == b:
      ans += ''.join(T)
    elif i > b and i < b + tl:
      continue
    else:
      if S[i] == "?":
        ans += "a"
      else:
        ans += S[i]
  print(ans)

Submission status: Wrong Answer

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

ck = 0
tl = len(T)
arr = []

for i in range(len(S)):
  a = S[i]
  if ck < tl and ( a == T[ck] or a == "?"):
    ck += 1
  else:
    ck = 0
  if tl == ck:
    arr.append(i-tl+1)
    
if len(arr) == 0:
  print("UNRESTORABLE")
else:
  b = arr[-1]
  ans = ""
  for i in range(len(S)):
    if i == b:
      ans += ''.join(T)
    elif i > b and i < b + tl:
      continue
    else:
      if S[i] == "?":
        ans += "a"
      else:
        ans += S[i]
  print(ans)

Submission status: Wrong Answer

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

ck = 0
tl = len(T)
arr = []

for i in range(len(S)):
  a = S[i]
  if ck < tl and ( a == T[ck] or a == "?"):
    ck += 1
  else:
    ck = 0
  if tl == ck:
    arr.append(i-tl+1)
    ck = 0 
if len(arr) == 0:
  print("UNRESTORABLE")
else:
  b = arr[-1]
  ans = ""
  for i in range(len(S)):
    if i == b:
      ans += ''.join(T)
    elif i > b and i < b + tl:
      continue
    else:
      if S[i] == "?":
        ans += "a"
      else:
        ans += S[i]
  print(ans)

Submission status: Wrong Answer

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

ck = 0
tl = len(T)
arr = []

for i in range(len(S)):
  a = S[i]
  if ck < tl and ( a == T[ck] or a == "?"):
    ck += 1
  else:
    ck = 0
  if tl == ck:
    arr.append(i-tl+1)
    ck = 0 
if len(arr) == 0:
  print("UNRESTORABLE")
else:
  b = arr[-1]
  ans = ""
  for i in range(len(S)):
    if i == b:
      ans += ''.join(T)
    elif i > b and i <= b + tl:
      continue
    else:
      if S[i] == "?":
        ans += "a"
      else:
        ans += S[i]
  print(ans)

Submission status: Wrong Answer

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

ck = 0
tl = len(T)
arr = []

for i in range(len(S)):
  a = S[i]
  if ck < tl and ( a == T[ck] or a == "?"):
    ck += 1
  else:
    ck = 0
  if tl == ck:
    arr.append(i-tl+1)
  
if len(arr) == 0:
  print("UNRESTORABLE")
else:
  b = arr[-1]
  ans = ""
  for i in range(len(S)):
    if i == b:
      ans += ''.join(T)
    elif i > b and i <= b + tl:
      continue
    else:
      if S[i] == "?":
        ans += "a"
      else:
        ans += S[i]
  print(ans)

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    Sd = input()
    T = input()

    r_Sd = Sd[::-1]
    r_T = T[::-1]

    def chk(a, b):
        res = ''
        for j in range(len(b)):
            if a[j] == '?' or a[j] == b[j]:
                res += b[j]
            else:
                return False
        else:
            return res 

    if len(Sd) >= len(T):
        for i in range(len(Sd)- len(T)+1):
            temp_words = r_Sd[i:]
            res = r_Sd[:i]
            
            temp = chk(temp_words, r_T)
            if temp:
                res = res + temp               
                print(res.replace('?', 'a')[::-1])
                break
        else:
            print('UNRESTORABLE')
    else:
        print('UNRESTORABLE')

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    Sd = input()
    T = input()

    r_Sd = Sd[::-1]
    r_T = T[::-1]

    if len(Sd) >= len(T):
        for i in range(len(Sd)- len(T)):
            temp_words = r_Sd[i:i+len(T)+1]
            res = r_Sd[:i]
            for j in range(len(T)):
                if temp_words[j] == '?' or temp_words[j] == r_T[j]:
                    res+=r_T[j]
                else:
                    break
            else:
                res = res + r_Sd[i+len(T):]
                print(res.replace('?', 'a')[::-1])
                break
        else:
            print('UNRESTORABLE')
    else:
        print('UNRESTORABLE')

if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
S = str(input())
T = str(input())
index = []

for i in range(len(S) - len(T) + 1):
  if (S[i] != T[0]) and (S[i] != "?"):
    continue
  else:
    p = 0
    now = i
    j = 0
    index_i = 0
    while p == 0:
      if (S[now] != T[j]) and (S[now] != "?"):
        p = 1
      else:
        now += 1
        j += 1
      
      if j == len(T):
        index_i = i
        p = 1
    if index_i != 0:
      index.append(index_i)
      
#print(index)
if (len(index) == 0):
  print("UNRESTORABLE")
else:
  ans_index = index[-1]
  ans = [0] * len(S)
  q = 0
  for i in range(len(S)):
    if i == ans_index:
      ans[i] = T[0]
      q = 1
    elif (q != 0):  
      ans[i] = T[q]
      q += 1
      if q == len(T):
        q = 0
    else:
      if S[i] != "?":
        ans[i] = S[i]
      else:
        ans[i] = "a"
    #print(ans, S)
  
  #print(ans) 
  #print(ans_index)
  for i in range(len(ans)):
    print(ans[i], end = "")
  print("")

Submission status: Wrong Answer

Solution code:
def resolve():
    '''
    code here
    '''
    Sd = input()
    T = input()

    r_Sd = Sd[::-1]
    r_T = T[::-1]

    for i in range(len(Sd)- len(T)):
        temp_words = r_Sd[i:i+len(T)]
        res = r_Sd[0:i] + ''
        for j in range(len(T)):
            if temp_words[j] == '?' or temp_words[j] == r_T[j]:
                res+=r_T[j]
            else:
                break
        else:
            res = res + r_Sd[i+len(T):]
            print(res.replace('?', 'a')[::-1])
            break
    else:
        print('UNRESTORABLE')


if __name__ == "__main__":
    resolve()

Submission status: Wrong Answer

Solution code:
from copy import deepcopy
def main():
    s = input()
    t = input()
    sr = list(s[::-1])
    tr = list(t[::-1])
    slen = len(s)
    tlen = len(t)
    cnt = 0
    while cnt <= (slen - tlen):
        if sr[cnt] == '?' or sr[cnt] == tr[0]:
            sr_koho = deepcopy(sr[cnt:cnt+tlen])
            flag = 1
            for i2 in range(tlen):
                if sr_koho[i2] != '?':
                    if sr_koho[i2] != tr[i2]:
                        cnt += 1
                        flag = 0
                        break
            if flag:
                sr[cnt:cnt+tlen] = tr
                cnt += tlen
        else:
            cnt += 1
    
    if sr == list(s[::-1]):
        print('UNRESTORABLE')
    else:
        srr = sr[::-1]
        srr = ['a' if c == '?' else c for c in srr]
        srrs = "".join(srr)
        print(srrs)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    t = input()
    sr = list(s[::-1])
    tr = list(t[::-1])
    slen = len(s)
    tlen = len(t)
    for i1 in range(slen - tlen):
        if sr[i1] == '?' or sr[i1] == tr[0]:
            sr_koho = sr[i1:i1+tlen]
            for i2 in range(tlen):
                if sr_koho[i2] != '?':
                    if sr_koho[i2] != tr[i2]:
                        break
            else:
                sr[i1:i1+tlen] = tr
    srr = sr[::-1]
    srr = ['a' if c == '?' else c for c in srr]
    srrs = "".join(srr)
    print(srrs)

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    T = input()
    n = len(T)
    ans = list(S)
    for i in range(len(S) - n + 1):
        s = S[i:i + n]
        for j, t in zip(s, T):
            if j != '?' and j != t:
                break
        else:
            ans[i:i + n] = list(T)
            ans = [a if a != '?' else 'a' for a in ans]
            print(''.join(ans))
            exit()
    print('UNRESTORABLE')



if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
S = list(input())
T = list(input())
s = len(S)
t = len(T)
if s < t:
    print('UNRESTORABLE')
    sys.exit()
OK = False
P = 0
for i in range(s - t + 1):
    if S[i] != T[0] and S[i] != '?':
        continue
    for j in range(1, t):
        if S[i + j] != T[j] and S[i + j] != '?':
            break
        if j == t - 1:
            OK = True
            P = i
for k in range(t):
    S[P + k] = T[k]
for i in range(s):
    if S[i] == '?':
        S[i] = 'a'
if OK:
    [print(S[i], end='') for i in range(s)]
    print('')
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
s = len(S)
t = len(T)
OK = False
for i in range(s - t + 1):
    if OK:
        break
    if S[i] != T[0] and S[i] != '?':
        continue
    for j in range(1, t):
        if S[i + j] != T[j] and S[i + j] != '?':
            OK = False
            break
        if j == t - 1:
            OK = True
            for k in range(t):
                S[i + k] = T[k]
for i in range(s):
    if S[i] == '?':
        S[i] = 'a'
if OK:
    [print(S[i], end='') for i in range(s)]
    print('')
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
s = len(S)
t = len(T)
OK = False
for i in range(s - t + 1):
    if S[i] != T[0] and S[i] != '?':
        continue
    for j in range(1, t):
        if S[i + j] != T[j] and S[i + j] != '?':
            OK = False
            break
        if j == t - 1:
            OK = True
            for k in range(t):
                S[i + k] = T[k]
for i in range(s):
    if S[i] == '?':
        S[i] = 'a'
if OK:
    [print(S[i], end='') for i in range(s)]
    print('')
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
# coding: utf-8
# Your code here!

s_dash = list(input().rstrip())
t = list(input().rstrip())
    
def scan(s_dash,t):
    possibility = []
    for i in range(len(s_dash)-len(t)+1):
        if compare(s_dash[i:i+len(t)],t):
            for j in range(len(t)):
                s_dash[i+j] = t[j]
            possibility.append(to_string(s_dash))
    
    return possibility

def compare(s_short,t):
    for i,s in enumerate(s_short):
        if s == t[i] or s == '?':
            pass
        else:
            return False
    return True

def to_string(lst):
    rtn_str = ""
    for s in lst:
        if s == '?':
            rtn_str += 'a'
        else:
            rtn_str += s
    return rtn_str

def choose_first(possibility):
    if len(possibility) == 0:
        return 'UNRESTORABLE'
    
    s = possibility[0]
    for s_tmp in possibility:
        if s < s_tmp:
            s = s_tmp
    return s

possibility = scan(s_dash,t)
print(choose_first(possibility))

Submission status: Wrong Answer

Solution code:
X = open(0).readlines()
S = X[0].strip()
T = X[1].strip()
m, n = len(T), len(S)
if m > n:
    print('UNRESTORABLE')
else:
    for i in range(n-m+1):
        U = S[i:i+m]
        if all(u == t or u == '?' for u, t in zip(U, T)):
            V = list(S.replace('?', 'a'))
            for j in range(m):
                V[i+j] = T[j]
            print(''.join(V))
            break
    else:
        print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    t = input()
    # ansはtを含む
    # tをいれられる場所を探す
    ans = []
    for i in range(len(s)-len(t)+1):
        tmp = s[:i]
        flag = False
        for j in range(i,i+len(t)):
            if s[j]==t[j-i]:
                tmp += t[j-i]
                pass
            elif s[j]=='?':
                tmp += t[j-i]
                pass
            else:
                flag = True
                break
        if not flag:
            tmp += s[i+len(t)+2:]
            tmp = tmp.replace('?','a')
            ans.append(tmp)
    if ans:
        ans.sort()
        print(ans[0])
    else:
        print('UNRESTORABLE')

main()

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
tmp=[]
for i in range(len(S)):
    flag=True
    for j in range(min(len(T),len(S)-i)):
        if S[i+j]==T[j] or S[i+j]=="?" or T[j]=="?":
            continue
        else:
            flag=False
    if flag:
        rec=S[:i]+T
        if len(rec)==len(S):
            tmp.append(rec)
if tmp==[]:
    print("UNRESTORABLE")
    exit()

for i in range(len(tmp)):
    tmp[i]=tmp[i].replace("?","a")
tmp.sort()
print(tmp[0])

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
tmp=[]
for i in range(len(S)):
    flag=True
    for j in range(min(len(T),len(S)-i)):
        if S[i+j]==T[j] or S[i+j]=="?" or T[j]=="?":
            continue
        else:
            flag=False
    if flag:
        rec=S[:i]+T
        if len(rec)==len(S):
            tmp.append(rec)
if tmp==[]:
    print("UNRESTORABLE")
    exit()
ans=tmp[0]
ans=ans.replace("?","a")
print(ans)

Submission status: Wrong Answer

Solution code:
from re import match
s, t = input().replace('?', '.'), input()

for i in range(len(s) - len(t))[::-1]:
    if match(s[i:i + len(t)], t):
        key = s.replace(s[i:i + len(t)], t).replace('.','a')
        print(key)
        break
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
from re import match
s, t = input().replace('?', '.'), input()

for i in range(len(s) - len(t) + 1)[::-1]:
    if match(s[i:i + len(t)], t):
        key = s.replace(s[i:i + len(t)], t).replace('.','a')
        print(key)
        break
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

ans = []
for i in range(len(s) - len(t) + 1):
    key = s.replace(s[i:i + len(t)], t).replace('?', 'a')
    if all(key[i] == s[i] or '?' == s[i] for i in range(len(s))):
        ans.append(key)
print('UNRESTORABLE' if len(ans) == 0 else sorted(ans)[0])

Submission status: Wrong Answer

Solution code:
chr1 = input().rstrip()
chr2 = input().rstrip()

result = []
for i in range(len(chr1)):
    if chr1[i] == chr2[0] and i + len(chr2) <= len(chr1):
        index = 0
        for j in range(len(chr2)):
            if chr1[i+j] == chr2[j] or chr1[i+j] == "?":
                index += 1
            else:
                break
        if index == len(chr2):
            temp = chr1[0:i]+chr2+chr1[i+len(chr2):]
            temp = temp.replace("?", "a")
            result.append(temp)
if len(result) >= 1:
    result.sort()
    print(result[0])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = list(input())
T = input()
ls = []

for i in range(len(S)-len(T)):
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != "?":
            break
    else:
        ls.append(i)

if ls:
    for j in range(len(T)):
        S[ls[-1]+j] = T[j]
    print("".join(S).replace("?", "a"))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
n = len(S) - len(T)
current = 'UNRESTORABLE'
for i in range(n+1):
    U = S.copy()
    for j in range(len(T)):
        if U[i+j]!='?' and U[i+j]!=T[j]:
            cand = False
            break
        if j==len(T)-1:
            cand = True
    if cand:
        U[i:i+len(T)] = T
        print(U)
        current2=''.join(U)
        current2 = current2.replace('?','a')
        if current == 'UNRESTORABLE' or current2<current:
            current = current2
print(current)

Submission status: Wrong Answer

Solution code:
s=list(input())[::-1]
t=list(input())[::-1]
n=len(s)
m=len(t)
ans="UNRESTORABLE"
for i in range(n-m):
    for j in range(m):
        if s[i+j]=="?" or s[i+j]==t[j]:
            pass
        else:
            break
    else:
        s[i:i+m]=t[:]
        ans=s[::-1]
        break
if ans!="UNRESTORABLE":
    for i in range(n):
        if ans[i]=="?":
            ans[i]="a"
print(*ans,sep="")

Submission status: Wrong Answer

Solution code:
import re

# ?があるとエラーが起きるので
s = input().replace('?', '.')
t = input()
#print("s,t:", s, t)

for i in range(len(s) - len(t), -1, -1):
    # re.match : 文字列の先頭がマッチするかチェック、抽出
    if re.match(s[i:i + len(t)], t):
        print(s[i:i + len(t)], t)
        s = s.replace('.', 'a')
        print(s[:i] + t + s[i + len(t):])
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import re

# ?があるとエラーが起きるので
# "."は、メタ文字（特別な意味を持つ文字）
# https://qiita.com/hiroyuki_mrp/items/29e87bf5fe46de62983c
s = input().replace('?', '.')
t = input()
print("s,t:", s, t)

for i in range(len(s) - len(t), -1, -1):
    # re.match : 文字列の先頭がマッチするかチェック、抽出
    if re.match(s[i:i + len(t)], t):
        #print(s[i:i + len(t)], t)
        s = s.replace('.', 'a')
        print(s[:i] + t + s[i + len(t):])
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

S = input().strip()
T = input().strip()
#-----
#S=S[::-1]
#T=T[::-1]

i=0
ans=""
flag = False
while i < len(S):

    if ( S[i] == T[0] or S[i] == "?" )  and  (len(S) - i) >= len(T):
        for j,word_t in enumerate(T):
            if word_t == S[i+j] or S[i+j] == "?":
                continue
            else:
                ans += S[i]
                i += 1 
                break
        
        else:
            ans += T + S[i+j+1:]
            flag = True
            break
            #i += (j+1)
            i = len(S)
    
    else:
        ans += S[i]
        i += 1
    
#ans=ans[::-1]

if flag:
    ans = ans.replace('?','a')
    print(ans)

else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

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

flag = False
for k in range(len(s) - len(t) + 1):
    if match(k):
        s = s[:k] + t + s[k + len(t):]
        flag = True
        break

if flag:
    print(s.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-

S = input().strip()
T = input().strip()
#-----

i=0
ans=""
flag = False

while i < len(S):

    if ( S[i] == T[0] or S[i] == "?" )  and  (len(S) - i) >= len(T):
        for j,word_t in enumerate(T):
            if word_t == S[i+j] or S[i+j] == "?":
                continue
            else:
                ans += S[i]
                i += 1 
                break
        
        else:
            #ans += T
            ans += T + S[i+j+1:]
            flag = True
            #i += len(T)
            break
    
    else:
        ans += S[i]
        i += 1


if flag:
    ans = ans.replace('?','a')
    print(ans)

else:
    print("UNRESTORABLE")