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:
#76c
Sdash = list(str(input()))
T = list(str(input()))

#文字列 S′ を見つけ、これは文字列 S の 0 個以上 |S| 個以内の文字が ? に置き換わった文字列であることも分かりました。

#条件1：文字列 S の中に連続する部分文字列として英小文字から成る文字列 Tが含まれている。
#条件2：S は、条件1を満たす文字列の中で辞書順最小の文字列である。

#そのとき、鍵となる文字列 Sを出力しなさい。
#ただし、そのような文字列 S が存在しない場合は代わりに UNRESTORABLE と出力しなさい。

#後ろから探る
presence_flag = 0

for i in range(len(Sdash)-len(T),-1,-1):
    pickuped = Sdash[i:i+len(T)]
    for j in range(len(T)):
        if T[j] != pickuped[j] and pickuped[j] != "?":
            break
    else:
        if Sdash[i:i+len(T)]!=T: #文字列に?を含んでいる 
            presence_flag = 1
            Sdash[i:i+len(T)]=T
            break
        
if presence_flag == 1:
    for i in range(len(Sdash)):
        if Sdash[i]=="?":
            Sdash[i]="a"
    print(''.join(map(str, Sdash)))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
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 ''.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())
n=len(s)
m=len(t)
if m>n:
    print('UNRESTORABLE')
    exit()
af=0
for i in range(n-m+1):
    k=s[n-m-i:n-i]
    f=0
    for j in range(m):
        if k[j]=='?' or k[j]==t[j]:
            f+=1
    if f==m:
        af+=1
        s[n-m-i:n-i]=t
        break
if af>0:
    ans=''
    for i in range(n):
        if s[i]=='?':
            ans+='a'
        else:
            ans+=s[i]
    print(ans)
else:
    print('UNSTORABLE')

Submission status: Wrong Answer

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

len_S = len(S_q)
len_T = len(T)

if len_S < len_T:
    print("UNRESTORABLE")
    exit()

candidates = []

iter_cnt = len_S - len_T + 1
print(iter_cnt)
for i in range(iter_cnt):
    tmp_S_q = S_q.copy()
    sub_S_q = S_q[i: len_T + i]
    for j in range(len_T):
        if sub_S_q[j] == "?" or sub_S_q[j] == T[j]:
            sub_S_q[j] = T[j]
        elif sub_S_q[j] != "?" and sub_S_q[j] != T[j]:
            break
    if "".join(sub_S_q) != "".join(T):
        continue

    tmp_S_q[i: len_T + i] = sub_S_q
    candidates.append("".join(tmp_S_q).replace("?", "a"))

candidates.sort(reverse=True)
if not candidates:
    print("UNRESTORABLE")
    exit()

print(candidates[0])

Submission status: Wrong Answer

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

len_S = len(S_q)
len_T = len(T)

# if len_S < len_T:
#     print("UNRESTORABLE")
#     exit()

candidates = []

iter_cnt = len_S - len_T + 1
for i in range(iter_cnt):
    tmp_S_q = S_q.copy()
    sub_S_q = S_q[i: len_T + i]
    for j in range(len_T):
        if sub_S_q[j] == "?" or sub_S_q[j] == T[j]:
            sub_S_q[j] = T[j]
        else:
            break
    if "".join(sub_S_q) != "".join(T):
        continue

    tmp_S_q[i: len_T + i] = sub_S_q
    candidates.append("".join(tmp_S_q).replace("?", "a"))

candidates.sort(reverse=True)
if not candidates:
    print("UNRESTORABLE")
    exit()

print(candidates[0])

Submission status: Wrong Answer

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

len_S = len(S_q)
len_T = len(T)

if len_S < len_T:
    print("UNRESTORABLE")
    exit()

candidates = []

iter_cnt = len_S - len_T + 1
for i in range(iter_cnt):
    tmp_S_q = S_q.copy()
    sub_S_q = S_q[i: len_T + i]
    for j in range(len_T):
        if sub_S_q[j] == "?" or sub_S_q[j] == T[j]:
            sub_S_q[j] = T[j]
        else:
            break
    if "".join(sub_S_q) != "".join(T):
        continue

    tmp_S_q[i: len_T + i] = sub_S_q
    candidates.append("".join(tmp_S_q).replace("?", "a"))

candidates.sort(reverse=True)
if not candidates:
    print("UNRESTORABLE")
    exit()

print(candidates[0])

Submission status: Wrong Answer

Solution code:
s = list(input())[::-1]
t = list(input())[::-1]
flag = 0
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
    if j == len(t)-1:
      flag = 1
  if flag == 1:
    s = ['a' if i == '?' else i for i in s]
    s = s[:i] + t + s[i+j+1:]
    print(''.join(s[::-1]))
    exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

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

ans=''
for i in range(len(S)-len(T)+1):
  for j in range(i,len(T)):
    if S[j]!=T[j-i] and S[j]!='?':
      break
  else:
    ans=S[:i]+T
if ans=='':
  print('UNRESTORABLE')
else:
  for i in range(len(ans)):
    if ans[i]=='?':
      ans[i]='a'
  print(*ans,sep='')

Submission status: Wrong Answer

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

if len(S)<len(T):
  print('UNRESTORABLE')
else:
  for i in range(0,len(S)-len(T)+1):
    flag=False
    for j in range(i,len(T)):
      if S[j]=='?' or S[j]==T[j-i]:
        flag=True
      else:
        flag=False
        break
    if flag:
      S[i:]=T
      for j in range(len(S)):
        if S[j]=='?':
          S[j]='a'
      print(*S,sep='')
      exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

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

if len(S)<len(T):
  print('UNRESTORABLE')
else:
  for i in range(0,len(S)-len(T)+1):
    flag=False
    for j in range(i,len(T)):
      if S[j]=='?' and S[j]==T[j-i]:
        flag=True
      else:
        flag=False
    if flag:
      S[i:]=T
      for j in range(len(S)):
        if S[j]=='?':
          S[j]='a'
      print(*S,sep='')
      exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

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

for i in range(len(S)-len(T)+1):
    flag = 1
    s = copy.deepcopy(S)
    x = S[i:i+len(T)]
    for j in range(len(x)):
        if x[j] == "?":
            s[i+j] = T[j]
        elif x[j] != T[j]:
            flag = 0
            break
    if flag:
        ans = "".join(s).replace("?", "a")
        break
    else:
        ans = "UNRESTORABLE"
print(ans)

Submission status: Wrong Answer

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

for i in range(len(S)-len(T)+1):
    flag = 1
    s = copy.deepcopy(S)
    x = S[i:i+len(T)]
    for j in range(len(x)):
        if x[j] == "?":
            s[i+j] = T[j]
        elif x[j] != T[j]:
            flag = 0
            break
    if flag:
        ans = "".join(s).replace("?", "a")
        break
print(ans)

Submission status: Wrong Answer

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

for i in range(len(S)-len(T)+1):
    flag = 1
    s = S.copy()
    x = S[i:i+len(T)]
    for j in range(len(x)):
        if x[j] == "?":
            s[i+j] = T[j]
        elif x[j] != T[j]:
            flag = 0
            break
    if flag:
        ans = "".join(s).replace("?", "a")
        break
print(ans)

Submission status: Wrong Answer

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

res = ""
for i in range(len(S)-len(T),-1,-1):
    tmp = list(S)
    flag = True
    for j in range(i,i+len(T)):
        if S[j] != T[j-i] and S[j] != "?":
            flag = False 
    if flag:
        for j in range(i,i+len(T)):
            tmp[j] = T[j-i]
        for i in range(len(tmp)):
            if tmp[i] == "?":
                tmp[i] = "a"
        res = "".join(tmp)
        break
else:
    res = "UNRESTOABLE"

print(res)

Submission status: Wrong Answer

Solution code:
import re

s = input()
t = input()

for i in range(len(s)-len(t), 0, -1):
    for j in  range(len(t)):
        if s[i+j] != '?' and s[i+j] != t[j]:
            break
    else:
        s = s[:i] + t
        break
else:
    print('UNRESTORABLE')
    exit()

res = s.replace('?', 'a')

print(res)

Submission status: Wrong Answer

Solution code:
import copy
S = list(input())
T = list(input())
ans = "UNRESTORABLE"
if len(S) < len(T):
    print(ans)
else:
    for i in range(len(S)-len(T)+1):
        flag = 1
        s = S.copy()
        x = S[i:i+len(T)]
        for j in range(len(x)):
            if x[j] == "?":
                s[i+j] = T[j]
            elif x[j] != T[j]:
                flag = 0
                break
        if flag:
            ans = "".join(s).replace("?", "a")
            break
    print(ans)

Submission status: Wrong Answer

Solution code:
S = input().replace('?','.')
T = input()

t_len = len(T)
t_index = t_len-1
found = False
for i in range(len(S)-1, -1,-1):
    if S[i] == T[t_index] or S[i] == '.':
        t_index -= 1
        if t_index < 0:
            if i + t_len == len(S):
                S = S[:i] + T
            else:
                S = S[:i] + T + S[i+t_len:]
            found = True
            break
    else:
        t_index = t_len-1
if found:
    print(S.replace('.','a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

t_len = len(T)
t_index = t_len-1
found = False
for i in range(len(S)-1, -1,-1):
    if S[i] == T[t_index] or S[i] == '?':
        t_index -= 1
        if t_index < 0:
            if i + t_len == len(S):
                S = S[:i] + T
            else:
                S = S[:i] + T + S[i+t_len:]
            found = True
            break
    else:
        t_index = t_len-1
if found:
    print(S.replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

t_index = 0
found = False
for i in range(len(S)):
    if S[i] == T[t_index] or S[i] == '?':
        t_index += 1
        if t_index == len(T):
            s_index = i - t_index + 1
            if i == len(S):
                S = S[:s_index] + T
            else:
                S = S[:s_index] + T + S[i+1:]
            found = True
            break
    else:
        t_index = 0
if found:
    print(S.replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
sd = input()
t = input()
n = len(sd)
m = len(t)
ss = []
for i in range(n - m + 1):
    flag = True
    s = ""
    for j in range(m):
        if sd[i + j] == "?" or sd[i + j] == t[j]:
            continue
        else:
            flag = False
    if flag:
        k = 0
        for j in range(n):
            if j < i or j > i + m:
                if sd[j] == "?":
                    s += "a"
                else:
                    s += sd[j]
            else:
                if sd[j] == "?":
                    if k >= m:
                        break
                    s += t[k]
                else:
                    s += sd[j]
                k += 1
        if len(s) == n:
            ss.append(s)
if ss:
    print(sorted(ss)[0])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import os

def qcount(s,t,count):
    if s=="?" or s==t:
        count += 1
        return count
    else:
        return 0

S = list(input())
T = list(input())
count = 0
i = 0
result =False

if len(S)>=len(T):
    while len(S)-i:
        count = qcount(S[i],T[count],count)
        if count == len(T):
            i = len(S)-1
            result = True
            for j in range(len(T)):
                S[i-count+j+1] = T[j]
            for k in range(len(S)):
                if S[k]=="?":
                    S[k] = "a"
        i += 1
if result:
    print("".join(S))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import os

def qcount(s,t,count):
    if s=="?" or s==t:
        count += 1
        return count
    else:
        return 0

S = list(input())
T = list(input())
count = 0
i = 0
result =False

while len(S)-i:
    count = qcount(S[i],T[count],count)
    if count == len(T):
        i = len(S)-1
        result = True
        for j in range(len(T)):
            S[i-count+j+1] = T[j]
        for k in range(len(S)):
            if S[k]=="?":
                S[k] = "a"
    i += 1
if result:
    print("".join(S))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
u='UNRESTORABLE'
a=[]
if len(s)>=len(t):
  for i in range(len(s)-len(t)+1):
    f=0
    for j in range(i,i+len(t)):
      if s[j]!='?' and s[j]!=t[j-i]:
        f=1
    if f==0:
      m=s[:i]+t+s[i+len(t):]
      m.replace('?','a')
      a.append(m)
if len(a)==0:
  print(u)
else:
  a.sort()
  print(a[0])

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
strs=[]
S=len(s)
T=len(t)
for i in range(S-T+1):
  flag=0
  for j in range(T):
    if s[i+j]=="?":
      continue
    if s[i+j]!=t[j]:
      flag=1;break
  if flag==0:
    posstr=s[:i]+t+s[i+T:]
    strs.append(posstr.replace("?","a",50))
if strs==[]:print("UNRESTORABLE")
else:print(strs[0])

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
u='UNRESTORABLE'
if len(s)>=len(t):
  for i in range(len(s)-len(t)+1):
    f=0
    for j in range(i,i+len(t))[::-1]:
      if s[j]!='?' and s[j]!=t[j-i]:
        f=1
    if f==0:
      for j in range(i,i+len(t)):
        if s[j]=='?':
          s=s[:j]+t[j-i]+s[j+1:]
      s=s.replace('?','a')
      u=s
      break
print(u)

Submission status: Wrong Answer

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

L = []

if len(s) > len(t):
  for i in range(len(s)-len(t)+1):
    if all([s[i+j]==t[j] or s[i+j]=='?' for j in range(len(t))]):
      l = str()
      for k in range(len(s)):
        if i <= k < i+len(t):
          l += t[k-i]
        elif s[k] == '?':
          l += 'a'
        else:
          l += s[k]
      L += [l]
      
if L:
  print(min(L))
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
# C
sd = input()
scnt = len(sd)
t = input()
tcnt = len(t)

point = 0
unrestorable = True
while point <= scnt - tcnt:
    oneroopcorres = True
    for i in range(tcnt):
        anyone = sd[point+i] == '?'
        correspond = sd[point+i] == t[i]
        if not (anyone or correspond):
            flag = False

    if oneroopcorres:
        unrestorable = False
        good_point = point

    point += 1

if unrestorable:
    print('UNRESTORABLE')
    exit()
else:
    sd = list(sd)
    for i in range(tcnt):
        sd[good_point + i] = t[i]
    sd = ''.join(sd)

sd = sd.replace('?', 'a')
print(sd)

Submission status: Wrong Answer

Solution code:
# C
sd = input()
scnt = len(sd)
t = input()
tcnt = len(t)

point = 0
unrestorable = True
while point <= scnt - tcnt:
    oneroopcorres = True
    for i in range(tcnt):
        anyone = sd[point+i] == '?'
        correspond = sd[point+i] == t[i]
        if not (anyone | correspond):
            flag = False

    if oneroopcorres:
        unrestorable = False
        good_point = point

    point += 1

if unrestorable:
    print('UNRESTORABLE')
    exit()
else:
    sd = list(sd)
    for i in range(tcnt):
        sd[good_point + i] = t[i]
    sd = ''.join(sd)

sd = sd.replace('?', 'a')
print(sd)

Submission status: Wrong Answer

Solution code:
# C
sd = input()
scnt = len(sd)
t = input()
tcnt = len(t)

point = 0
unrestorable = True
while point <= scnt - tcnt:
    flag = True
    for i in range(tcnt):
        anyone = sd[point+i] == '?'
        correspond = sd[point+i] == t[i]
        if not (anyone | correspond):
            flag = False

    if flag:
        good_point = point
        unrestorable = False
        break
    point +=1

if unrestorable:
    print('UNRESTORABLE')
    exit()
else:
    sd = list(sd)
    for i in range(tcnt):
        sd[good_point + i] = t[i]
    sd = ''.join(sd)

sd = sd.replace('?', 'a')
print(sd)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
u='UNRESTORABLE'
if len(s)>=len(t):
  for i in range(len(s)-len(t)+1):
    f=0
    for j in range(i,i+len(t)):
      if s[j]!='?' and s[j]!=t[j-i]:
        f=1
    if f==0:
      for j in range(i,i+len(t)):
        if s[j]=='?':
          s=s[:j]+t[j-i]+s[j+1:]
      s=s.replace('?','a')
      u=s
      break
print(u)

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
u='UNRESTORABLE'
if len(s)>=len(t):
  for i in range(len(s)-len(t)+1):
    f=0
    for j in range(i,i+len(t)):
      if s[j]!='?' and s[j]!=t[j-i]:
        f=1
    if f==0:
      for j in range(i,i+len(t)):
        if s[j]!='?':
          s=s[:j]+t[j-i]+s[j+1:]
      s.replace('?','a')
      u=s
      break
print(u)

Submission status: Wrong Answer

Solution code:
SS = input()
T = input()
N = len(SS) - len(T) + 1
for i in range(N):
  tmp = i
  cnt = 0
  for j in range(len(T)):
    if SS[tmp] != T[j] and SS[tmp] != "?":
      pass
    else:
      cnt += 1
    tmp += 1
  if cnt == len(T):
    SS = list(SS)
    g = i
    for k in range(len(T)):
      SS[g] = T[k]
      g += 1
    for s in SS:
      if s == "?":
        print("a",end="")
      else:
        print(s,end="")
    exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

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

for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if T[j] != S[i+j] != '?':
            break
    else:
        break
else:
    print('UNRESTORABLE')
    exit()

ans = (S[:i] + T + S[len(T)-i:])[::-1]
ans = ans.replace('?', 'a')
print(ans)

Submission status: Wrong Answer

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

for i in range(len(S)-len(T), -1, -1):
    if Flag == True and S[i] == '?':
        S[i] = 'a'
    elif Flag == False and S[i] == T[0] or S[i] == '?':
        ck = 0
        for j in range(len(T)):
            if S[i+j] == T[j] or S[i+j] == '?':
                ck += 1
            else:
                break
        if ck == len(T):
            Flag = True
            for j in range(len(T)):
                S[i+j] = T[j]

if Flag:
    print(*S, sep='')
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
S = input()
for i in range(len(s)-len(S)+1):
    if s[i] == S[0] or s[i] == "?":
        a = s[i:i+len(S)]
        for j in range(len(S)):
            if a[j] == S[j] or a[j] == "?":
                continue
            break
        else:
            s = s[:i]+S+s[i+len(S):]
            print(s.replace("?","a"))
            exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
S = input()
flag = False
for i in range(len(s)-len(S)+1):
    if s[i] == S[0] or s[i] == "?":
        a = s[i:i+len(S)]
        for j in range(len(S)):
            if a[j] == S[j] or a[j] == "?":
                continue
            break
        else:
            s = s[:i]+S+s[i+len(S):-1]
            print(s.replace("?","a"))
            exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

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

if T[0] in S:
    num = S.index(T[0])
    for i in range(num):
        if ans[i] == '?':
            ans[i] = 'a'
    for i in range(num, num+len(T)):
        if ans[i] == '?' or ans[i] == T[i-num]:
            ans[i] = T[i-num]

for a in ans:
    if a == '?':
        print('UNRESTORABLE')
        exit()

ans = ''.join(ans)
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
def check(a, b):
  if a == '?':
    return True
  else:
    return a == b
  
cand = []
for i in range(len(s)-len(t)):
  flag = True
  c = list(s)
  for j in range(len(t)):
    if not check(s[i+j], t[j]):
      flag = False
      break
    c[i+j] = t[j]
  if flag:
    s = ''.join(c)
    s.replace('?', 'a')
    cand.append(s)
if len(cand):
  cand.sort()
  print(cand[0])
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
def check(a, b):
  if a == '?':
    return True
  else:
    if a == b:
      return True
    else:
      return True
cand = []
for i in range(len(s)-len(t)):
  flag = True
  c = list(s)
  for j in range(len(t)):
    if not check(s[i+j], t[j]):
      flag = False
      break
    c[i+j] = t[j]
  if flag:
    s = ''.join(c)
    s.replace('?', 'a')
    cand.append(s)
if len(cand):
  cand.sort()
  print(cand[0])
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
# ABC 076 C - Dubious Document 2
S = input()
T = input()

S = [s for s in S]
T = [t for t in T]
idx = 0
is_partional_str = True

for i in range(len(S)):
    if (i+len(T)<=len(S)) and (S[i] == '?' or S[i] == T[0]):
        for j in range(len(T)):
            is_partional_str = True
            if S[i+j]==T[j] or S[i+j]=='?':
                pass
            else:
                is_partional_str = False
                break
        if is_partional_str == True:
            # Tの始まりを記録する
            idx = i
            break

if is_partional_str == False:
    print('UNRESTORABLE')
    exit()

L_start = []
L_T = []
L_end = []
ans = ''
T_start = True
T_end = False
for i in range(len(S)):
    if idx <= i <= idx+len(T)-1:
        L_T.append(T[i-idx])
        T_start = False
        T_end = True
    else:
        if T_start == True:
            if S[i] == '?':
                S[i] = 'a'
            L_start.append(S[i])
        if T_end == True:
            if S[i] == '?':
                S[i] = 'a'
            L_end.append(S[i])

L_start.sort()
L_end.sort()

L = L_start + L_T + L_end

for l in L:
    ans += l

print(ans)

Submission status: Wrong Answer

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

if len(s) < len(t):
    print("UNRESTORABLE")
    exit()

for i in range(len(s) - len(t) + 1):
    tmps = s[i:i + len(t)]
    ok = True
    for j in range(len(tmps)):
        if t[j] == tmps[j] or tmps[j] == '?':
            pass
        else:
            ok = False
            break
    if ok == True:
        for k in range(len(t)):
            s[k+i] = t[k]
        break

if ok == False:
    print("UNRESTORABLE")
else:
    for c in s:
        if c == '?':
            print('a', end="")
        else:
            print(c, end="")
    print()

Submission status: Wrong Answer

Solution code:
def resolve():
    S = input()
    T = input()
    can_insert = False

    for start in range(len(S)-len(T),0,-1):
        can_insert = True
        for i,c in enumerate(T):
            if S[start+i] != c and S[start+i] != "?":
                can_insert = False
        if can_insert:
            list_s = list(S)
            list_s[start:start+len(T)] = T
            S = "".join(list_s)
            print(S.replace("?","a"))
            break
    if not can_insert:
        print("UNRESTORABLE")
resolve()

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
ls = len(S)
lt = len(T)
a = ''
for i in range(ls):
    try:
        s = S[ls-i-lt:ls-i]
        for j in range(lt):
            if not (s[j] == T[j] or s[j] == '?'):
                break
        else:
            a += S[:ls-i-lt].replace('?', 'a') + T + S[ls-i:]
            break
    except:
        pass
print(a if a else 'UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import re

s=input()
t=input()

t_flg = False
for i in range(len(s)):
  if i + len(t) < len(s):
    tmp = s[len(s) - i - len(t): len(s) -i + len(t) ]
    p = tmp.replace('?','.')
    result = re.match(p,t)
    if result:
      s = s[:len(s) - i - len(t)] + t + s[len(s) - i + len(t):]
      t_flg = True
      break
  else:
    break
if t_flg:
  print(s.replace('?','a'))
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import re

s=input()
t=input()

t_flg = False
for i in range(len(s)):
  if i + len(t) < len(s):
    tmp = s[len(s) - i - len(t): len(s) -i + len(t) ]
    p = tmp.replace('?','.')
    result = re.match(p,tmp)
    if result:
      s = s[:len(s) - i - len(t)] + t + s[len(s) - i + len(t):]
      t_flg = True
      break
  else:
    break
if t_flg:
  print(s.replace('?','a'))
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import re

s=input()
t=input()

t_flg = False
for i in range(len(s)):
  if i + len(t) < len(s):
    tmp = s[len(s) - i - len(t): len(s) -i + len(t) ]
    print(tmp)
    p = tmp.replace('?','.')
    result = re.match(p,tmp)
    if result:
      s = s[:len(s) - i - len(t)] + t + s[len(s) - i + len(t):]
      t_flg = True
      break
  else:
    break
if t_flg:
  print(s.replace('?','a'))
else:
  print('UNRESTORABLE')

Submission status: Wrong Answer

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

for i in range(0,len(s) - len(t)+1):
    if s[i] != t[0]:
        continue
    elif s[i] == "?":
        n = 1
        while n < len(t) and (s[i+n] == t[n] or s[i+n] == "?"):
            n += 1
        if n == len(t):
            chancenum.append(i)
    else:
        n = 1
        while n < len(t) and (s[i+n] == t[n] or s[i+n] == "?"):
            n += 1
        if n == len(t):
            chancenum.append(i)

if chancenum == []:
    print("UNRESTORABLE")
else:
    tright = max(chancenum)
    for i in range(0,len(t)):
        s = s[:tright] + t + s[tright+len(t):]
    print(s.replace('?', 'a'))

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    t = input()
    if t in s:
        print(s.replace('?', 'a'))
        return
    s = "".join(reversed(list(s)))
    t = "".join(reversed(list(t)))

    # S' をさすポインタ; T をさすポインタ
    a = 0; b = 0
    for i in range(len(s)):
        for j in range(len(t)):
            sw1, sw2 = False, False
            if i+j < len(s) and (s[i+j] == t[j] or s[i+j] == '?'):
                continue
            elif i+j >= len(s):
                # 最後まで探したが無理だった
                sw1 = True
                break
            else:
                # '?' でもなく文字が合わなかった
                sw2 = True
                break
        else:
            # 合っていた
            sw3 = True
            ans = (s[:i]+t+s[i+len(t):]).replace('?', 'a')
            print("".join(reversed(list(ans))))
            break
        if sw2:
            continue
        if sw1:
            print("UNRESTORABLE")
            break

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    s = "".join(reversed(list(input())))
    t = "".join(reversed(list(input())))

    # S' をさすポインタ; T をさすポインタ
    a = 0; b = 0
    for i in range(len(s)):
        for j in range(len(t)):
            sw1, sw2 = False, False
            if i+j < len(s) and (s[i+j] == t[j] or s[i+j] == '?'):
                continue
            elif i+j >= len(s):
                # 最後まで探したが無理だった
                sw1 = True
                break
            else:
                # '?' でもなく文字が合わなかった
                sw2 = True
                break
        else:
            # 合っていた
            sw3 = True
            ans = (s[:i]+t+s[i+len(t):]).replace('?', 'a')
            print("".join(reversed(list(ans))))
            break
        if sw2:
            continue
        if sw1:
            print("UNRESTORABLE")
            break

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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


li=[]
for i in range(len(s)-1,len(t)-1,-1):
    if s[i]==t[-1] or s[i]=='?':
        j=-1
        while s[i]==t[j] or s[i]=='?':
            i-=1
            j-=1
            if -j>len(t):
                ss=s[:i+1]+t+s[i+len(t)+1:]
                li.append(ss.replace('?','a'))
                break
li.sort()
print(li[0] if li else 'UNRESTORABLE')

Submission status: Wrong Answer

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


li=[]
for i in range(len(s)-1,len(t)-1,-1):
    if s[i]==t[-1] or s[i]=='?':
        j=-1
        while s[i]==t[j] or s[i]=='?':
            i-=1
            j-=1
            if -j>len(t):
                ss=s[:i+1]+t+s[i+len(t)+1:]
                li.append(ss.replace('?','a'))
                break
li.sort()
print(li)
print(li[0] if li else 'UNRESTORABLE')

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
s, t = [s.strip() for s in open(0)]

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

Submission status: Wrong Answer

Solution code:

S = input()
T = input()
N = len(S)
K = len(T)

ans = []
flag = False
for i in range(N-K+1):
    for j in range(K):
        if not(S[i+j] == T[j] or S[i+j] == '?'):
            break
    else:
        flag = True
        tmp = list(S)
        for j in range(K):
            tmp[i+j] = T[j]
        for j in range(N):
            if tmp[j] == '?': tmp[j] = 'a'
        tmp = ''.join(tmp)
        ans.append(tmp)
        
if flag:
    ans.sort()
    print(ans[0])
else:
    print('UNRESTRABLE')