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: Accepted

Solution code:
import re
import sys


def main():
    s = sys.stdin.readline().rstrip().replace("?", ".")
    t = sys.stdin.readline().rstrip()

    n = len(s)
    m = len(t)
    ans = []

    for i in range(n - m + 1):
        if i == 0:
            tmp1 = ""
        else:
            tmp1 = s[:i]
        tmp2 = s[i : i + m]
        if i + m == n:
            tmp3 = ""
        else:
            tmp3 = s[i + m :]
        if re.fullmatch(tmp2, t):
            tmp2 = t
            tmp = tmp1 + tmp2 + tmp3
            ans.append(tmp)
    ans.sort()

    if ans:
        print(ans[0].replace(".", "a"))
    else:
        print("UNRESTORABLE")


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
import sys
from collections import deque, Counter, defaultdict
from itertools import permutations
import heapq


def resolve():
    S = list(sys.stdin.readline().strip())
    T = list(sys.stdin.readline().strip())
    left = len(S) - len(T)
    right = len(S) - 1
    restorable = True
    while left >= 0:
        for cur in range(left, right + 1):
            if S[cur] != T[cur-left] and S[cur] != '?':
                break
        else:
            # found T
            for cur in range(left, right + 1):
                if S[cur] == '?':
                    S[cur] = T[cur-left]
            break
        left -= 1
        right -= 1
    else:
        # not found T
        restorable = False

    if restorable:
        for i in range(len(S)):
            if S[i] == '?':
                S[i] = 'a'
        print(''.join(S))
    else:
        print('UNRESTORABLE')


if __name__ == "__main__":
    resolve()

Submission status: Accepted

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

    for i in range(len(s)-len(t), -1, -1):
        flag = 1
        for j in range(len(t)):
            if s[i+j] == t[j] or s[i+j] == "?":
                flag = flag * 1
            else:
                flag = 0
        if flag:
            ans = ["a" if x == "?" else x for x in s]
            for k in range(len(t)):
                ans[i+k] = t[k]
            print("".join(ans))
            exit()
    print("UNRESTORABLE")

if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s,t=input(),input()
n=len(s)
m=len(t)
ans="z"*(n+1)
for i in range(n-m+1):
    p=s[:i].replace("?","a")

    for j in range(m):
        if s[i+j]in("?",t[j]):
            p+=t[j]
        else:break
    else:

        p+=s[len(p):].replace("?","a")
        ans=min(ans,p)
print("UNRESTORABLE" if len(ans)==n+1 else ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
if len(s) < len(t):
    print("UNRESTORABLE")
else:
    for i in range(len(s) - len(t), -1, -1):
        ok = True
        for j in range(len(t)):
            if s[i + j] != t[j] and s[i + j] != "?":
                ok = False
        if ok:
            print((s[:i] + t + s[i + len(t):]).replace("?", "a"))
            exit()
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
S_=input()
T=input()
N=len(S_)
M=len(T)
posi=[]
 
for i in range(N-M+1):
  flag=True
  for j in range(i,i+M):
    if S_[j]!=T[j-i] and S_[j]!="?":
      flag=False
  if flag==True:
    posi.append(S_[:i]+T+S_[i+M:])
#print(posi)
    
if posi==[]:
  print("UNRESTORABLE")
else:
  ans_list=[]
  for item in posi:
    ans=""
    for str in item:
      if str=="?":
        ans += "a"
      else:
        ans += str
    ans_list.append(ans)
  ans_list.sort()
  print(ans_list[0])

Submission status: Accepted

Solution code:
import copy
import sys

s = input()
t = input()
li = list('abcdefghijklmnopqrstuvwxyz')
r = []
for i in range(len(s)-len(t)+1):
    ss = list(s)
#     print(i)
    lo = [1 if ((s[i + j] == t[j]) or (s[i + j] == '?')) else 0 for j in range(len(t))]
#     print(lo)
    if all(lo):
        ss[i:i+ len(t)] = t
        rs = ''.join(ss)
        rs = rs.replace('?','a')
        r += [rs]

if len(r) == 0:
    print('UNRESTORABLE')
    sys.exit()
r = sorted(r)
print(r[0])

Submission status: Accepted

Solution code:
import os

s = list(map(str,input()))
t = list(map(str,input()))

m = len(s)
n = len(t)
ans = 0

if m<n:
    print("UNRESTORABLE")
    exit()
for i in range(m-n+1):
    s2 = s.copy()
    s1 = s2[i:i+n]
    flag = True
    for j in range(n):
        if s1[j]!="?" and s1[j]!=t[j]:
            flag = False
            break
        else:
            s1[j] = t[j]
    if flag:
        s2[i:i+n] = s1
        s2 = "".join(s2)
        a = s2.replace("?","a")
        if ans==0:
            ans = a
        elif ans > a:
            ans = a
if ans==0:
    print("UNRESTORABLE")
else:
    print(ans)

Submission status: Accepted

Solution code:
sn = list(input())
t = list(input())
ls = len(sn)
lt = len(t)
Flag = False  
reali = 0 #tの文が始まるときのi
if lt > ls:
  print("UNRESTORABLE")
  exit()
for i in range(ls-lt+1): #スライスを繰り返して当てはまるところを探す
  ss = sn[i:i+lt]
  count = 0
  for j in range(lt):
    if ss[j] == "?" or ss[j] == t[j]:
      count += 1
  if count == lt:
    reali = i
    Flag = True
for i in range(ls): #見つけたとこをtの文にしてそれ以外をaにする
  if i == reali:
    for j in range(lt):
      sn[i+j] = t[j]
  if sn[i] == "?":
    sn[i] = "a"
if Flag:
  for i in sn:
    print(i,end="")
else:
  print("UNRESTORABLE")

Submission status: Accepted

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

for i in range(len(s)-len(t)+1):
    flag=0
    i=len(s)-len(t)-i
    #print(i)
    for j in range(len(t)):
        if t[j]!=s[i+j] and s[i+j]!="?":
            flag=1
            #print(j,t[j],s[i+j])
    if flag==0:
        for j in range(len(t)):
            s[i+j]=t[j]
        result=""
        for item in s:
            result=result+str(item)
        result=result.replace("?","a")
        print(result)
        exit()
print("UNRESTORABLE")

Submission status: Accepted

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


def main():
    Sd = input()
    N = len(Sd)
    T  = input()
    ans = []
    for i in range(N-len(T)+1):
        flag = True
        tmp = list(Sd)
        for j in range(len(T)):
            if Sd[i+j] == '?':
                tmp[i+j] = T[j]
            elif Sd[i+j] != T[j]:
                flag = False
                break
        if flag:
            ans.append(''.join(tmp).replace('?','a'))
    if ans == []:
        print('UNRESTORABLE')
    else:
        print(sorted(ans)[0])


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import collections

sys.setrecursionlimit(10 ** 7)

# 1 ✕ 1 (str)
S = input().rstrip()

# 1 ✕ 1 (str)
T = input().rstrip()

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

array = []
for i in range(len(S) - len(T) + 1):
    for t in range(len(T)):
        if S[i + t] not in ("?", T[t]):
            break
    else:
        # tmp = S[:i]
        # tmp += T
        # tmp += S[i + len(T):]
        # tmp.replace("?", "a")
        # array.append(tmp)
        memo = S[:i] + T + S[i + len(T):]
        array.append(memo.replace('?', 'a'))

if len(array) == 0:
    print("UNRESTORABLE")
else:
    print(min(array))
    # print(sorted(list(map(lambda x:, array)))[0])

Submission status: Accepted

Solution code:
#!/usr/bin/env python3
import sys
import collections

sys.setrecursionlimit(10 ** 7)

# 1 ✕ 1 (str)
S = input().rstrip()

# 1 ✕ 1 (str)
T = input().rstrip()

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

array = []
for i in range(len(S) - len(T) + 1):
    for t in range(len(T)):
        if S[i + t] not in ("?", T[t]):
            break
    else:
        # tmp = S[0:i]
        # tmp += T
        # tmp += S[i + len(T):]
        # tmp.replace("?", "a")
        # array.append(tmp)
        memo = S[:i] + T + S[i + len(T):]
        array.append(memo.replace('?', 'a'))

if len(array) == 0:
    print("UNRESTORABLE")
else:
    print(min(array))
    # print(sorted(list(map(lambda x:, array)))[0])

Submission status: Accepted

Solution code:
#https://atcoder.jp/contests/abc076/tasks/abc076_c

s=input()
t=input()
ls=len(s)
lt=len(t)
if ls<lt:
    print("UNRESTORABLE")
    exit()
for i in range(ls-lt,-1,-1):#後ろから考える
    for j in range(lt):
        flag=0
        if (s[i+j]!=t[j])&(s[i+j]!="?"):
            flag=1
            break
    if flag==0:
        ans=s[:i]+t+s[i+lt:]
        #print(ans)
        print(ans.replace("?","a"))
        exit()

print("UNRESTORABLE")

Submission status: Accepted

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

ans_list = []

for i in range(len(S)-len(T)+1):
    flg = 0
    temp = copy.deepcopy(S)

    #S文字の先頭の文字i番目からT文字列を一致するか?
    for j in range(len(T)):
        if T[j]==S[i+j]:
            continue
        elif S[i+j]=="?":
            temp[i+j] = T[j]
            continue
        else:
            flg = 1
    if flg==0:
        for i in range(len(temp)):
            if temp[i]=="?":
                temp[i]="a"
        ans_list.append("".join(temp))

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

Submission status: Accepted

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

n = len(s)
m = len(t)

if t in s:
    print(s.replace('?', 'a'))
else:
    ans = []
    for i in range(n - m + 1):
        bubun = s[i:i + m]
        flag = True
        for j in range(m):
            x = bubun[j]
            y = t[j]
            if x == y:
                continue
            elif x == '?':
                continue
            else:
                flag = False
                break

        if flag:
            ans.append((s[:i] + t + s[i + m:]).replace('?', 'a'))

    print(sorted(ans)[0]) if ans else print('UNRESTORABLE')

Submission status: Accepted

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

S_length = len(S)
T_length = len(T)

if S_length < T_length:
    print("UNRESTORABLE")
    
elif S_length == T_length:
    for i in range(T_length):
        if S[i] != "?" and S[i] != T[i]:
            print("UNRESTORABLE")
            break
    else:
        print(T)
    
else:
    flag = 0
    for i in range(S_length - T_length):
        for j in range(T_length):
            if S[S_length - T_length - i + j] != "?" and S[S_length - T_length - i + j] != T[j]:
                break
        else:
            flag = 1
            S = S[:S_length - T_length - i] + T + S[S_length - i:]
            break
            
    if flag == 1:
        ans = S.replace("?", "a")
        print(ans)
        
    elif flag == 0:
        print("UNRESTORABLE")

Submission status: Accepted

Solution code:
S=input()
T=input()
ls=len(S)
lt=len(T)

ans='UNRESTORABLE'

if ls<lt:
    print(ans)
    exit()
for i in range(ls-lt,-1,-1):
    c=0
    for j in range(lt):
        if T[j]==S[i+j] or S[i+j]=='?':
            continue
        else:
            c=1
            break
    if c==0:
        ans=S.replace('?','a')
        ans=ans[:i] + T + ans[i+lt:]
        break
print(ans)

Submission status: Accepted

Solution code:
s = input()
t = input()
m = len(s)
n = len(t)
res = float('inf')

for i in range(m-n+1):
  S = s[i:i+n:]
  judge = True
  for j in range(n):
    if not(S[j] == t[j] or S[j] == "?"):
      judge = False
      break
  if judge:
    res = i
    
if res == float('inf'):
  print("UNRESTORABLE")
  exit()

ans = ""
for i in range(m):
  if s[i] != "?":
    ans += s[i]
  else:
    if res <= i and i < res + n:
      ans += t[i-res]
    else:
      ans += "a"
print(ans)

Submission status: Accepted

Solution code:
s = list(input())
t = list(input())
ls = len(s)
lt = len(t)
if ls < lt:
    print("UNRESTORABLE")
else:
    res = []
    for i in range(ls-lt+1):
        res.append(s[i:i+lt])
    tmp = []
    for i in range(len(res)):
        flag = True
        for j in range(lt):
            if res[i][j] == t[j] or res[i][j] == '?':
                pass
            else:
                flag = False
                break
        if flag:
            tmp.append(i)
    ans = []
    for i in tmp:
        q = []
        for j in range(0, i):
            q.append(s[j])
        for j in range(0, lt):
            q.append(t[j])
        for j in range(i+lt, ls):
            q.append(s[j])
        for j in range(ls):
            if q[j] == '?':
                q[j] = 'a'
        ans.append(''.join(q))
    if ans:
        print(min(ans))
    else:
        print("UNRESTORABLE")

Submission status: Accepted

Solution code:
sp = list(input())
t = list(input())
boo = False
if len(sp)-len(t)>=0:
    for i in reversed(range(len(sp)-len(t)+1)):
        for j in reversed(range(len(t))):
            if t[j] != sp[i+j] and sp[i+j] != "?":
                break
        else:
            for j in reversed(range(len(t))):
                sp[i+j] = t[j]
            
            boo = True
            break
        continue
    if boo:
        for i in range(len(sp)):
            if sp[i] =="?":
                sp[i] = "a"
    
        print("".join(map(str, sp)))
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
def resolve():
	ss = list(input())
	t = list(input())
	candidates = []
	for i in range(len(ss) - len(t) + 1):
		s = ss[:]
		ok = True
		for j in range(len(t)):
			if s[i+j] != t[j] and s[i+j] != '?':
				ok = False
				break
		if ok:
			for j in range(len(t)):
				s[i + j] = t[j]
			for j in range(len(s)):
				if s[j] == '?':
					s[j] = 'a'
			candidates.append("".join(s))
	if len(candidates):
		print(min(candidates))
	else:
		print('UNRESTORABLE')
resolve()

Submission status: Accepted

Solution code:
S = input()
T = input()
lenS = len(S)
lenT = len(T)
ans = "UNRESTORABLE"
for i in range(lenS-lenT,-1,-1):
    subS = S[i:i+lenT]
    for j in range(lenT):
        if subS[j] != T[j] and subS[j] != "?":
            break
    else:
        ans = S[:i]+T+S[i+lenT:]
        ans = ans.replace("?","a")
        break

print(ans)

Submission status: Accepted

Solution code:
s = input()[::-1]
t = input()[::-1]
 
def check(c,t):
    if len(c) < len(t):
        return False
    for i in range(len(t)):
        if c[i] != "?" and c[i] != t[i]:
            return False
 
    return True
        
 
i = 0 
Has = False
ans = ""
while i < len(s):
    if (s[i] == "?" or s[i] == t[0]) and not Has:
        if check(s[i:],t):
            Has = True
            ans += t
            i += len(t)
        else:
            if s[i] == "?":
                ans += "a"
            else:
                ans += s[i]
            i += 1
 
    elif s[i] == "?":
        i += 1
        ans += "a"
    else:
        ans += s[i]
        i += 1
 
if Has:
    print(ans[::-1])
else:
    print('UNRESTORABLE')

Submission status: Accepted

Solution code:
# -*- coding: utf-8 -*-
import sys
import re
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    S=input().replace('?','.')
    T=input()
    ans='z'*100
    for i in range(len(S)-len(T)+1):
        if re.match(S[i:i+len(T)],T):
            tmp=(S[:i]+T+S[i+len(T):]).replace('.','a')
            ans=min(ans,tmp)
    print(ans if ans!='z'*100 else 'UNRESTORABLE')
    

if __name__ == '__main__':
    main()

Submission status: Accepted

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

ans=[]
if T in S:
    print(S.replace("?","a"))
else:
    for i in range(len(S)-len(T)+1):
        flag=True
        for j in range(i,i+len(T)):
            if S[j]==T[j-i] or S[j]=="?":
                continue
            else:
                flag=False
                break
        if flag==True:
            s=S
            s=s[:i]+T+s[i+len(T):]
            ans.append(s.replace("?","a"))
    if len(ans)==0:
        print("UNRESTORABLE")
    else:
        ans.sort()
        print(ans[0])

Submission status: Accepted

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

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

Submission status: Accepted

Solution code:
def main():
  s = str(input())
  ans = s.replace('?', 'z')
  flag = False
  t = str(input())
  for i in range(len(s)-len(t)+1):
    temp_flag = True
    temp_ans = list(s)
    for j in range(len(t)):
      if s[i + j] == '?':
        temp_ans[i + j] = t[j]
        continue
      elif s[i+j] != t[j]:
        temp_flag = False
    if temp_flag:
      flag = True
      temp_ans = "".join(temp_ans)
      temp_ans = temp_ans.replace('?', 'a')
      ans = min(ans, temp_ans)
  if flag:
    print(ans)
  else:
    print("UNRESTORABLE")
    
if __name__ == "__main__":
  main()

Submission status: Accepted

Solution code:
import sys
a=input()
b=input()
for i in reversed(range(len(a)-len(b)+1)):
  t=True
  for j in range(len(b)):
    if not(a[i+j]=="?") and not(a[i+j]==b[j]):
      t=False
      break
  if t:
    for p in range(i):
      if a[p]=="?":
        print("a",end="")
      else:
        print(a[p],end="")
    print(b,end="")
    for w in range(i+len(b),len(a)):
      if a[w]=="?":
        print("a",end="")
      else:
        print(a[w],end="")
    sys.exit()
print("UNRESTORABLE")

Submission status: Accepted

Solution code:
S = input()
T = input()
res = []

ok = -1
for i in range(len(S) - len(T) + 1):
    if S[i] == T[0] or S[i] == "?":
        for j in range(len(T)):
            if S[i + j] not in ("?", T[j]):
                break
        else:
            s = S[:i] + T + S[i + len(T):]
            res.append(s.replace("?", "a"))

if res:
    print(min(res))
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
S = input()
T = input()
res = "UNRESTORABLE"

for i in range(len(S)-1, len(T)-2, -1):

  s = list(S[::])
  j = i
  flag = True
  for k in range(len(T)-1, -1, -1):
    if s[j] == "?":
      s[j] = T[k]
      j -= 1
    elif s[j] == T[k]:
      j -= 1
      continue
    elif s[j] != T[k]:
      flag = False
      break

  if flag:
    for j in range(len(s)):
      if s[j] == "?": s[j] = "a"
    res = "".join(s)
    break

print(res)

Submission status: Accepted

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

S = input()
T = input()

if len(T) > len(S):
    print("UNRESTORABLE")
    exit()

ans = []

for i in range(len(S) - len(T) + 1):
    idx = []
    for m, j in enumerate(range(i, i + len(T))):
        idx.append(j)
        if S[j] != "?" and S[j] != T[m]:
            break
    else:
        idx = set(idx)
        tmp = [s for s in S]
        now = 0
        for k in range(len(S)):
            if tmp[k] == "?":
                if k not in idx:
                    tmp[k] = "a"
                else:
                    tmp[k] = T[now]
                    now += 1
            else:
                if k in idx:
                    now += 1
        ans.append("".join(tmp))

if len(ans) > 0:
    print(min(ans))
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
ss = input()
t = input()
sl = len(ss)
tl = len(t)
min = "UNRESTORABLE"

for i in range(sl-tl+1):
    for j, tj in enumerate(t):
        if not(ss[i+j] == tj or ss[i+j] == "?"):
            break
        if j == tl-1:
            s = ""
            for k, sk in enumerate(ss):
                if i <= k and k < i+tl:
                    s += t[k-i]
                elif sk == "?":
                    s += "a"
                else:
                    s += sk
            if min == "UNRESTORABLE":
                min = s
            elif min > s:
                min = s

print(min)

Submission status: Accepted

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

s=input()
t=input()
b=[]

if len(s)-len(t)<0:
    flg=False
else:
    for i in range(len(s)-len(t)+1):
        ans=s
        for j in range(len(t)):
            flg=True
            if s[i+j]=='?' or s[i+j]==t[j]:
                #print(ans)
                ans=ans[:i+j]+t[j]+('' if i+j+1>len(s) else ans[i+j+1:])
            else:
                flg=False
                break
        if flg==True:
            b.append(ans.replace('?','a'))
#print(b)
b.sort()

print(b[0] if len(b)>0 else 'UNRESTORABLE')

Submission status: Accepted

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

s = readline().rstrip().decode()
t = read().rstrip().decode()
ans = []
for i in range(len(s) - len(t) + 1):
    for j, (ss, tt) in enumerate(zip(s[i:], t)):
        if ss not in ('?', tt):
            break
    else:
        memo = s[:i] + t + s[i + len(t):]
        ans.append(memo.replace('?', 'a'))
print(min(ans) if ans else 'UNRESTORABLE')

Submission status: Accepted

Solution code:
S=input()
T=input()
SL=list(S)
N=len(S)
M=len(T)

if len(S)<len(T):
    print("UNRESTORABLE")
    
else:
    for i in range(N-M+1):
        cond=True
        temp=S[N-M-i:N-i]
        for s in range(M):
            if temp[s]!="?" and temp[s]!=T[s]:
                cond=False
        if cond:
            SL[N-M-i:N-i]=list(T)
            break
    if not cond:
        print("UNRESTORABLE")
    else:
        for j in range(N):
            if SL[j]=="?":
                SL[j]="a"
    
        for a in SL:
            print(a,end="")

Submission status: Accepted

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

    lenS = len(S); lenT = len(T)
    idx = -1
    for i in range(lenS-lenT+1):
        if S[i] in ['?', T[0]]:
            flag = True
            for j in range(1, lenT):
                if not S[i+j] in ['?', T[j]]:
                    flag = False
                    break
            if flag:
                idx = max(idx, i)
    if idx == -1:
        print('UNRESTORABLE')
        return
    
    s = S[:idx] + T + S[idx+lenT:]
    ans = ''.join(s).replace('?', 'a')
    print(ans)


if __name__ == "__main__":
    main()

Submission status: Accepted

Solution code:
s = input()
t = input()
ans = []
for i in range(len(s)-len(t)+1):
    tmp = s[i:i+len(t)]
    flg = True
    for j in range(len(t)):
        if tmp[j]!=t[j]:
            if tmp[j]!='?':
                flg = False
    if flg:
        c = s[:i]+t+s[i+len(t):]
        ans.append(c.replace('?', 'a'))
print('UNRESTORABLE' if len(ans)==0 else min(ans))

Submission status: Accepted

Solution code:
import sys
S = list(input())
T = list(input())
l = len(S)
k = len(T)

if k > l:
    print("UNRESTORABLE")
else:
    for i in range(l-k,-1,-1):
        p = 0
        for j in range(k):
            if S[i+j] != T[j] and S[i+j] != "?":
                p = 1
        if p == 0:
            for st in range(i):
                if S[st] == "?":
                    print("a",end="")
                else:
                    print(S[st],end="")
            print("".join(T),end="")
            for st in range(i+k,l):
                if S[st] == "?":
                    print("a", end="")
                else:
                    print(S[st], end="")
            sys.exit()
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import re
S2=input().strip().replace("?",".")
T=input()
ans="UNRESTORABLE"
if len(S2)<len(T):
    pass
else:
    for i in range(len(S2)-len(T)+1):
        m=re.match(S2[len(S2)-len(T)-i:len(S2)-i],T)
        if m != None:
            ans=S2[:len(S2)-len(T)-i]+ T + S2[len(S2)-i:]
            ans=ans.replace(".","a")
            break

print(ans)

Submission status: Accepted

Solution code:
import sys
import re
sys.setrecursionlimit(1000000) # 再帰上限を増やす

def main():
    input = sys.stdin.readline  # 文字列に対してinputした場合は、rstripするのを忘れずに！
    S = input().rstrip()
    T = input().rstrip()

    word_size_s = len(S)
    word_size_t = len(T)
    for i in range(word_size_s - word_size_t, -1, -1):
        part_s = S[i:i+word_size_t]
        part_s = part_s.replace("?", ".")
        m = re.match(part_s, T)
        if m:
            S = (S[:i] + T + S[i+word_size_t:]).replace("?", "a")
            print(S)
            exit()
    print("UNRESTORABLE")


if __name__ == '__main__':
    main()

Submission status: Accepted

Solution code:
#辞書順で最も小さいものが答えだから、後ろから文字列の後ろから処理していく。
#後ろから考えるのは面倒くさいので、逆順にソートする。

s = str(input())
t = str(input())

sr = ''.join(list(reversed(s)))
tr = ''.join(list(reversed(t)))

slen = len(sr)
tlen = len(tr)

for i in range(slen-tlen+1):
    flg = i
    for j in range(tlen):
        if sr[i+j] == tr[j] or sr[i+j] == "?":
            continue
        else:
            flg = -1
            break
    else:
        #breakせずに正常にループが終了したら、Tが入る適切な場所が見つかったということなのでbreakする。
        #ここでbreakできなかったら、"UNRESTORABLE"が出力され終了する。
        break
else:
    flg = -1
    print("UNRESTORABLE")
    exit()


#before_resultではまだ"?"が残っている。
before_result_reversed = sr[:flg] + tr + sr[flg+tlen:]
before_result = ''.join(list(reversed(before_result_reversed)))


print(before_result.replace("?","a"))

Submission status: Accepted

Solution code:
S = input()
T = input()
 
N = len(S)
M = len(T)
 
ans = 'UNRESTORABLE'
for i in range(N-M,-1,-1):
    b = True
    for j in range(M):
        if S[i+j] == '?' or S[i+j] == T[j]:
            continue
        b = False
    if b:
        ans = S[:i] + T + S[i+j+1:]
        break
ans = list(ans)
for i in range(len(ans)):
    if ans[i] == '?':
        ans[i] = 'a'
print(''.join(ans))

Submission status: Accepted

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

N = len(S)
M = len(T)

if N < M:
    print('UNRESTORABLE')
    
else:

    ans = 'UNRESTORABLE'
    for i in range(N-M+1):
        make = True
        for j in range(M):
            if S[i+j] != '?' and S[i+j] != T[j]:
                make = 0
        if make:
            ans = S[:i] + T + S[i+M:]
    if ans == 'UNRESTORABLE':
        print(ans)
    else:
        ans = list(ans)
        for i in range(N):
            if ans[i] == '?':
                ans[i] = 'a'
        print(''.join(ans))

Submission status: Accepted

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

N = len(S)
M = len(T)

if N < M:
    print('UNRESTORABLE')
    exit()

ans = 'UNRESTORABLE'
for i in range(N-M+1):
    anss = S[:i] + T + S[i+M:]
    make = 1
    anss = list(anss)
    for j in range(N):
        if anss[j] == '?':
            if S[j] == '?':
                anss[j] = 'a'
            else:
                anss[j] = S[j]
        else:
            if anss[j] != S[j] and S[j] != '?':
                make = 0
                break
    if make:
        ans = ''.join(anss)
print(ans)

Submission status: Accepted

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

def rplc(s, i, T):
  s = s[:i] + T + s[i+len(T):]
  return ''.join(s).replace('?', 'a')

ans = 'UNRESTORABLE'
for i in range(len(s)-len(T)+1):
  flg = True
  for j in range(len(T)):
    if s[i+j] == '?':
      continue
    if s[i+j] != T[j]:
      flg = False
      break
  if flg:
    ans = rplc(s, i , T) 

print(ans)

Submission status: Accepted

Solution code:
def solve(s, t):

    length = len(t)
    ans = []
    i = 0
    flg = False
    while i < len(s):
        tmp = s[i:i+length]
        count = len([i for i, j in zip(tmp, t) if i == j or i == "?"])
        if length == count:
            a = s[:i] + t + s[i+length:]
            ans.append(a.replace("?", "a"))

        i += 1

    return min(ans) if len(ans) > 0 else "UNRESTORABLE"

if __name__ == "__main__":
    s = input()
    t = input()
    print(solve(s, t))

Submission status: Accepted

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

kouho = []

for i in range(len(S) - len_T+1):
    # print(S[i:i+len_T])
    flag = 0
    for a, b in zip(T, S[i:i+len_T]):
        if a == b or b == '?':
            continue
        else:
            flag = 1
    if flag == 1:
        continue
    # print((S[:i]+T+S[i+len_T:]).replace('?', 'a'))
    kouho.append((S[:i]+T+S[i+len_T:]).replace('?', 'a'))
if not kouho:
    print("UNRESTORABLE")
else:
    print(sorted(kouho)[0])

Submission status: Accepted

Solution code:
#6 Dubious Document 2
s=input()
t=input()
ls=len(s)
lt=len(t)

cand=[]
for i in range(ls-lt+1):
    scut =s[i:i+lt]
#    for j,tt in enumerate(t):
    if all(tt==ss or ss=="?" for tt,ss in zip(t,scut) ):
        cand.append(i)
        
ans=[]
for c in cand:
    ans.append( (s[:c]+ t+ s[c+lt:]).replace("?","a") )

if len(ans)==0:
    print("UNRESTORABLE")
else:
    print(min(ans))

Submission status: Accepted

Solution code:
s = input()
t = input()
ss = []
for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j] not in ('?', t[j]):
            break
    else:
        S = s[:i] + t + s[i+len(t):]
        ss.append(S.replace('?', 'a'))
if ss:
    print(min(ss))
else:
    print("UNRESTORABLE")

Submission status: Accepted

Solution code:
import copy

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

def construct(s, t, k):
	ans = copy.deepcopy(s)
	for i in range(len(t)):
		ans[i+k] = t[i]
	for i in range(len(s)):
		if ans[i] == '?':
			ans[i] = 'a'
	return "".join(ans)

def resolve():
	s = list(input())
	t = list(input())
	ans = []
	if len(s) < len(t):
		print('UNRESTORABLE')
		return
	for i in range(len(s) - len(t) + 1):
		if check(s, t, i):
			ans.append(construct(s, t, i))
	if len(ans) >= 1:
		print(min(ans))
	else:
		print('UNRESTORABLE')
resolve()

Submission status: Accepted

Solution code:
s = input()
t = input()
ss = []

for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[i+j] not in ('?', t[j]):
            break
    else:
        S = s[:i] + t + s[i+len(t):]
        ss.append(S.replace('?', 'a'))

if ss:
    print(min(ss))
else:
    print("UNRESTORABLE")