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:
def judge(s,t):
    j = True
    if len(s) != len(t):
        return False
    for i in range(len(s)):
        if s[i] != '':
            if(s[i] == t[i] or s[i] == '?') :
                continue
            else:
                j  = False
        else:
            j = False
    return j
            
s = input()
t = input()

ok = False

for i in range(len(s)):
    if judge(s[i:(len(t)+i)],t):
        ok = True
        s1 = s[0:i]
        s1 += t
        s =s1 + s[len(t)+i:len(s)]

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

Submission status: Wrong Answer

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


def Find(S, T):
    ans = ''
    for i in range(0, len(S)-len(T)+1):
        s = S[i:i+len(T)]
        for j in range(len(s)):
            if not (s[j] != '?' and T[j] == s[j]):
                break
            ans = S[:i] + T + S[i+len(T):]
    return ans


ans = Find(S, T)

if ans:
    ans = list(ans)
    for i, v in enumerate(ans):
        if v == '?':
            ans[i] = 'a'
    ans = ''.join(ans)
    print(ans)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
def may_eq(s, t):
    return all(c_s == '?' or c_s == c_t for c_s, c_t in zip(s, t))


def main():
    s = input()
    t = input()

    if not '?' in s:
        print(s)
        return

    if len(t) > len(s):
        print('UNRESTORABLE')
        return

    for i in range(0, len(s) - len(t) + 1):
        if may_eq(s[i:i + len(t)], t):
            s = s[:i] + t + s[i + len(t):]
            s = s.replace('?', 'a')
            print(s)
            return

    print('UNRESTORABLE')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def may_eq(s, t):
    return all(c_s == '?' or c_s == c_t for c_s, c_t in zip(s, t))


def main():
    s = input()
    t = input()

    if len(t) > len(s):
        print('UNRESTORABLE')
        return

    for i in range(0, len(s) - len(t) + 1):
        if may_eq(s[i:i + len(t)], t):
            s = s[:i] + t + s[i + len(t):]
            s = s.replace('?', 'a')
            print(s)
            return

    print('UNRESTORABLE')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

ans = []

for i in range(len(s)-len(t)+1):
  for j in range(len(t)):
    if s[i+j] != t[j] and s[i+j]!='?':
      # print('Aの方')
      break
    else:
      #:iまでの文字はSを引き継ぎ、tを足し、残りは引き継ぎ、?部分はaに
      # print('Bの方')
      ans.append((s[:i]+t+s[i+len(t):]).replace('?','a'))
      # print('s[i+j]',s[i+j],"t[j]",t[j])
      # print('i',i,"j",j)
      # print(ans)

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

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
ans = "UNRESTORABLE"
flag = 0
if len(S) >= len(T) :
    for i in range(len(S)-len(T)+1) :
        if flag == 1 : break
        S_sub = S[i:i+len(T)]
        for j in range(len(T)) :
            if flag == 1 : break
            if S_sub[j] != T[j] :
                if S_sub != "?" :
                    break
            S = S.replace(S_sub,T)
            S = S.replace("?","a")
            ans = S
            flag = 1
            break
print(ans)

Submission status: Wrong Answer

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

cand = []
for i in range(len(S) - len(T) + 1):
    f = True
    for s, t in zip(S[i:i+len(T)], T):
        if s == '?':
            continue
        if s != t:
            f = False
            break
    if f:
        cand.append(S[:i] + T)
if cand == []:
    print('UNRESTORABLE')
    exit()
print(cand[-1].replace('?', 'a'))

Submission status: Wrong Answer

Solution code:
s = list(input())
t = list(input())
n = len(s)
m = len(t)

i = 0
while i+m <= n:
    temp = True
    k = 0
    while k < m and temp:
        if s[i+k] == t[k] or s[i+k] == "?":
            k += 1
        else:
            temp = False
    if temp:
        for k in range(m):
            s[i+k] = t[k]
        i = n-m+100
    else:
        i += 1

if i == n-m+100:
    for i in range(n):
        if s[i] == "?":
            s[i] = "a"
    for i in range(n):
        if i != n-1:
            print(s[i],end = "")
        else:
            print(s[i])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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


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

Submission status: Wrong Answer

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

p = ""
for i in range(len(t)):
    p += "[" + t[i] + "?]"

a = re.findall(p, s)
if a == []:
    print("UNRESTORABLE")
    exit()

ans = []
for m in a:
    i = s.rindex(m)
    tmp = s[:i] + t + s[i+len(t):]
    ans.append(tmp.replace("?", "a"))
print(sorted(ans)[0])

Submission status: Wrong Answer

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

p = ""
for i in range(len(t)):
    p += "[" + t[i] + "?]"

m = re.search(p, s)
if m is None:
    print("UNRESTORABLE")
    exit()
i = s.index(m.group())
s = s[:i] + t + s[i+len(t):]
print(s.replace('?', 'a'))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
Sdash = str(input())
T = str(input())

reslis = []
N = len(Sdash) - len(T) + 1
for i in range(N):
    Tdash = Sdash[i:i+len(T)]
    for j in range(len(T)):
        if Tdash[j] == T[j] or Tdash[j] == "?":
            pass
        else:
            break
    else:
        if i == 0:
            if i != N - 1:
                reslis.append(T + Sdash[i+len(T)])
            else:
                reslis.append(T)
        elif i == N - 1:
            reslis.append(Sdash[:i] + T)
        else:
            reslis.append(Sdash[:i] + T + Sdash[i+len(T)])

if reslis:
    resli = [st.replace("?","a") for st in reslis]
    resli.sort()
    print(resli[0])

else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
Sdash = str(input())
T = str(input())

reslis = []
N = len(Sdash) - len(T) + 1
for i in range(N):
    Tdash = Sdash[i:i+len(T)]
    for j in range(len(T)):
        if Tdash[j] == T[j] or Tdash[j] == "?":
            pass
        else:
            break
    else:
        if i == 0:
            if i != N - 1:
                reslis.append(T + Sdash[i+len(T)])
            else:
                reslis.append(T)
        elif i == N - 1:
            reslis.append(Sdash[:i] + T)
        else:
            reslis.append(Sdash[:i] + T + Sdash[i+len(T)])

if reslis:
    reslis = [st.replace("?","a") for st in reslis]
    reslis.sort()
    print(reslis[0])

else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
a=len(t)
x=-1
for i in range(len(s),a-1,-1):
    tmp=list(s[i-a:i])
    for j in range(a):
        if tmp[j]=='?':
            tmp[j] = t[j]
    if ''.join(tmp) == t:
        x=i-a
    if x != -1:
        break
print(s[:x].replace('?','a')+t+s[x+a:] if x != -1 else 'UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
a=len(t)
x=-1
for i in range(len(s),a-1,-1):
    tmp=list(s[i-a:i])
    for j in range(a):
        if tmp[j]=='?':
            tmp[j] = t[j]
    if ''.join(tmp) == t:
        x=i-a
print(s[:x].replace('?','a')+t if x != -1 else 'UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import sys

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

for i in range(len(S) - len(T) + 1):
    SS = S[i:i+len(T)]
    for j in range(len(T)):
        if SS[j] != T[j] and SS[j] != '?':
            break
    else:
        sfir = ''.join(S[:i])
        saft = ''.join(S[i+len(T):])
        sfir = sfir.replace('?', 'a')
        saft = saft.replace('?', 'a')
        print(sfir+''.join(T)+saft)
        sys.exit()
    
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
a = list(input())
b = list(input())
count = 0
m = 0
ar = []
c = ""
for i in range(len(a)-len(b)+1):
    for j in range(len(b)):
        if b[j] == a[i+j] or a[i+j] == "?":
            count += 1
    if count == len(b):
        for k in range(len(a)):
            if k >= i and k <= i + len(b) - 1:
                c += b[m]
                m += 1
            else:
                if a[k] == "?":
                    c += "a"
                else:
                    c += a[k]
        ar.append("".join(c))
        c = ""
    count = 0
    m = 0
print(ar)
if len(ar) == 0:
    print("UNRESTORABLE")
else:
    print(sorted(ar)[0])

Submission status: Wrong Answer

Solution code:
a = list(input())
b = list(input())
count = 0
m = 0
ar = []
for i in range(len(a)-len(b)+1):
    for j in range(len(b)):
        if b[j] == a[i+j] or a[i+j] == "?":
            count += 1
    if count == len(b):
        for l in range(i,i+len(b)):
            a[l] = b[m]
            m += 1
        for k in range(len(a)):
            if a[k] == "?":
                a[k] = "a"
        ar.append("".join(a))
    count = 0
    m = 0
if len(ar) == 0:
    print("UNRESTORABLE")
else:
    print(sorted(ar)[0])

Submission status: Wrong Answer

Solution code:
a = list(input())
b = list(input())
count = 0
m = 0
for i in range(len(a)-len(b)+1):
    for j in range(len(b)):
        if b[j] == a[i+j] or a[i+j] == "?":
            count += 1
    if count == len(b):
        for l in range(i,i+len(b)):
            a[l] = b[m]
            m += 1
        for k in range(len(a)):
            if a[k] == "?":
                a[k] = "a"
        print("".join(a))
    count = 0
if m == 0:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import copy as cp
s = input()
t = input()
u = list(s)
v = list(t)
w = cp.deepcopy(u)
p = 0
q = 0
for h in range(len(u) - 1, -1, -1):
    if q == 1:
        break
    if v[-1] == u[h]:
        #w[i] = v[0]
        for j in range(1, len(v)):
            if (v[-1 - j] == u[h - j]) and h - j >= 0:
                pass
                if j == len(v) - 1:
                    #for k in range(len(v)):
                        #w[h - k] = v[-1 - k]
                    q = 1
                    p = 1
            else:
                break
if q == 0:
    for i in range(len(u) - 1, -1, -1):
        if p == 1:
            break
        if v[-1] == u[i] or "?" == u[i]:
            #w[i] = v[0]
            for j in range(1, len(v)):
                if (v[-1 - j] == u[i - j] or "?" == u[i - j]) and i - j >= 0:
                    pass
                    if j == len(v) - 1:
                        for k in range(len(v)):
                            w[i - k] = v[-1 - k]
                        p = 1
                else:
                    break

if p == 1:
    for m in range(len(u)):
        if w[m] == "?":
            w[m] = "a"
    print("".join(w))
if p == 0:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import copy as cp
s = input()
t = input()
u = list(s)
v = list(t)
w = cp.deepcopy(u)
p = 0
for i in range(len(u) - 1, -1, -1):
    if p == 1:
        break
    if v[-1] == u[i] or "?" == u[i]:
        #w[i] = v[0]
        for j in range(1, len(v)):
            if (v[-1 - j] == u[i - j] or "?" == u[i - j]) and i - j >= 0:
                pass
                if j == len(v) - 1:
                    for k in range(len(v)):
                        w[i - k] = v[-1 - k]
                    p = 1
            else:
                break

if p == 1:
    for m in range(len(u)):
        if w[m] == "?":
            w[m] = "a"
    print("".join(w))
if p == 0:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import copy as cp
s = input()
t = input()
u = list(s)
v = list(t)
w = cp.deepcopy(u)
p = 0
for i in range(len(u) - 1, -1, -1):
    if v[-1] == u[i] or "?" == u[i]:
        #w[i] = v[0]
        for j in range(1, len(v)):
            if (v[-1 - j] == u[i - j] or "?" == u[i - j]) and i - j >= 0:
                pass
                if j == len(v) - 1:
                    for k in range(len(v)):
                        w[i - k] = v[-1 - k]
                    p = 1
            else:
                break

if p == 1:
    for m in range(len(u)):
        if w[m] == "?":
            w[m] = "a"
    print("".join(w))
if p == 0:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
sp = list(input())
t = list(input())
n = len(sp)
s = []
for i in range(len(t), n):
    flag = True
    for j in range(len(t)):
        if sp[n - i + j] != t[j] and sp[n - i + j] != '?':
            flag = False
            break
    if flag:
        s.append('')
        ss = sp
        ss[n - i:n - i - 1 + len(t)] = t
        for j in range(n):
            if ss[j] == '?':
                s[-1] += 'a'
            else:
                s[-1] += ss[j]
if s == []:
    print('UNRESTORABLE')
else:
    s.sort()
    print(s[0])

Submission status: Wrong Answer

Solution code:
sp = list(input())
t = list(input())
n = len(sp)
s = ''
for i in range(len(t), n):
    flag = True
    for j in range(len(t)):
        if sp[n - i + j] != t[j] and sp[n - i + j] != '?':
            flag = False
            break
    if flag:
        sp[n - i:n - i - 1 + len(t)] = t
        for j in range(n):
            if sp[j] == '?':
                s += 'a'
            else:
                s += sp[j]
        print(s)
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
sp = list(input())
t = list(input())
n = len(sp)
s = ''
flag = False
for i in range(len(t), n):
    if sp[n - i] == t[0]:
        flag = True
        for j in range(1, len(t)):
            if sp[n - i + j] != t[j] and sp[n - i + j] != '?':
                flag = False
                break
    if flag:
        sp[n - i:n - i - 1 + len(t)] = t
        for j in range(n):
            if sp[j] == '?':
                s += 'a'
            else:
                s += sp[j]
        print(s)
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
def 解():
    sS = input().rstrip()
    sT = input().rstrip()
    impo = "UNRESTORABLE"
    iS = len(sS)
    iT = len(sT)

    for i in range(iS-iT+1):
        bF = 1
        for j in range(iT):
            if sS[i+j] != "?" and sS[i+j] != sT[j]:
                bF = 0
                break
        if bF:
            sAns = (sS[0:i]+sT+sS[i+iT:]).replace("?","a")
            print(sAns)
            exit()
    print(impo)
解()

Submission status: Wrong Answer

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

if len(T) > len(Sprime):
    print('UNRESTORABLE')
ans = -1
for i in range(len(Sprime)-len(T)+1):
    for j in range(len(T)):
        if Sprime[i:i+len(T)][j] != '?' and\
        Sprime[i:i+len(T)][j] != T[j]:
            break
    else:
        ans = max(i,ans)
if ans == -1:
    print('UNRESTORABLE')
else:
    Sprime = list(Sprime)
    Sprime[ans:ans+len(T)] = T
    Sprime = ''.join(Sprime)
    print(Sprime.replace('?','a'))

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
a = list(input())
b = list(input())

n = len(a)
m = len(b)
s = 0
check = 0
while s <= n - m:
    count = 0
    for i in range(m):
        if a[s + i] == '?' or a[s + i] == b[i]:
            count += 1
        else:
            s += 1
            break
    #print(a[s:s + m], count)
    if count == m:
        for i in range(m):
            a[s + i] = b[i]
        print(''.join(a).replace('?', 'a'))
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
# -*- coding: utf-8 -*-
S = input()
T = input()

match_idx = 999
for i in range(len(S)-len(T)+1):
    unmatch = 0
    for s,t in zip(S[i:i+len(T)],T):
        if s != t and s != '?':
            unmatch = 1
    if unmatch == 0:
        match_idx = i
        break


if match_idx > len(S)-len(T):
    print('UNRESTORABLE')
    exit()

xT = '?'*(match_idx) + T + '?'*(len(S)-len(T)-match_idx)

ans_list = []
for s,t in zip(S,xT):
    if s == '?' and t == '?':
        ans_list.append('a')
    elif s == '?':
        ans_list.append(t)
    else:
    # elif t == '?':
        ans_list.append(s)

print(''.join(ans_list))

Submission status: Wrong Answer

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

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

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

if ok:
    print(S.replace('?', 'a'))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
ns = len(S)
T = input()
nt = len(T)
if T in S:
    print(S.replace('?', 'a'))
    exit()
elif ns < nt:
    print('UNRESTORABLE')
    exit()

for i in reversed(range(ns - nt + 1)):
    for x, y in zip(S[i:], T):
        if not (x == '?' or x == y):
            break
    else:
        r = S.replace('?', 'a')
        print(r[:i] + T + r[i + nt + 1:])
        break
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
ns = len(S)
T = input()
nt = len(T)
if T in S:
    print(S.replace('?', 'a'))
    exit()
elif ns < nt:
    print('UNRESTORABLE')

for i in reversed(range(ns - nt + 1)):
    for x, y in zip(S[i:], T):
        if not (x == '?' or x == y):
            break
    else:
        r = S.replace('?', 'a')
        print(r[:i] + T + r[i + nt + 1:])
        break
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
ns = len(S)
T = input()
nt = len(T)
if T in S:
    print(S.replace('?', 'a'))
    exit()
    
for i in reversed(range(ns - nt + 1)):
    for x, y in zip(S[i:], T):
        if not (x == '?' or x == y):
            break
    else:
        r = S.replace('?', 'a')
        print(r[:i] + T + r[i + nt + 1:])
        break
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S = input()
ns = len(S)
T = input()
nt = len(T)
for i in range(ns - nt + 1):
    for x, y in zip(S[i:], T):
        if not (x == '?' or x == y):
            break
    else:
        r = S.replace('?', 'a')
        print(r[:i] + T + r[i + nt + 1:])
        break
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

found = []
for i in range(len(S) - len(T) + 1):
    for cs,ct in zip(S[i:],T):
        if cs != '?' and cs != ct:
            break
    else:
        found.append(i)

if not found:
    print('UNRESTORABLE')
    exit()

ans = 'z' * 51
for i in found:
    tmp = S[:i] + T + S[i+len(T):]
    #ans = min(ans, tmp.replace('?', 'a'))
print(tmp)

Submission status: Wrong Answer

Solution code:
s = str(input())
t = str(input())
ans = "NG"
for i in reversed(range(len(s))):
    if ans == "OK":
        ind = i+1
        break
    if s[i] == t[0]:
        if i+len(t) > len(s):
            continue
        else:
            a = 0
            while a < len(t):
                if s[i+a] == t[0+a] or s[i+a] == "?":
                    a += 1
                else:
                    break
            else:
                ans = "OK"
else:
    ans = "NG"

if ans == "NG":
    print("UNRESTORABLE")
else:
    list_s = list(s)
    for j in range(len(t)):
        list_s[ind + j] = t[j]
    for i in range(len(list_s)):
        if list_s[i] == "?":
            list_s[i] = "a"
    print("".join(list_s))

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
li = []
for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        if S[i+j] != '?' and S[i+j] != T[j]:
            break
    else:
        li.append(S[:i].replace('?', 'a') + T + S[i+len(T):].replace('?', 'a'))
li.sort
if len(li) == 0:
    print('UNRESTORABLE')
else:
    print(li[0])

Submission status: Wrong Answer

Solution code:
import sys
S = input()
T = input()
li = []
if len(T) > len(S):
    print('UNRESTORABLE')
    sys.exit()
for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        if S[i+j] != '?' and S[i+j] != T[j]:
            break
    else:
        li.append(S[:i].replace('?', 'a') + T + S[i+len(T):].replace('?', 'a'))
li.sort
if len(li) == 0:
    print('UNRESTORABLE')
else:
    print(li[0])

Submission status: Wrong Answer

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

for i in range(max(len(S) - len(T) + 1, 0)):
    for j in range(len(T)):
        if S[i+j] != '?' and S[i+j] != T[j]:
            break
    else:
        li.append(S[:i].replace('?', 'a') + T + S[i+len(T):].replace('?', 'a'))
li.sort
if len(li) == 0:
    print('UNRESTORABLE')
else:
    print(li[0])

Submission status: Wrong Answer

Solution code:
sd = input()
t = input()
for i in range(len(sd) - len(t), -1, -1):
    t_kamo = sd[i:i + len(t)]
    for j in range(len(t) + 1):
        if j == len(t):
            s = sd[:i].replace("?", "a") + t
            print(s)
            exit()
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
sd = input()
t = input()
for i in range(len(sd) - len(t) + 1):
    t_kamo = sd[i:i + len(t)]
    for j in range(len(t) + 1):
        if j == len(t):
            s = sd[:i].replace("?", "a") + t + sd[i + len(t):].replace("?", "a")
            print(s)
            exit()
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
sd = input()
t = input()
for i in range(len(sd) - len(t) + 1):
    t_kamo = sd[i:i + len(t)]
    for j in range(len(t) + 1):
        if j == len(t):
            s = sd[:i].replace("?", "a") + t
            print(s)
            exit()
        if t_kamo[j] == "?":
            continue
        elif t_kamo[j] != t[j]:
            break
print("UNRESTORABLE")

Submission status: Wrong Answer

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

def zehnpaard():
    s = input()
    t = input()

    def match(s1, t):
        return all(a in (b, '?') for a, b in zip(s1, t))

    substrings = [s[i:i+len(t)] for i in range(len(s)-len(t)+1)]
    res = 'UNRESTORABLE'
    for ss in reversed(substrings):
        if match(ss, t):
            left, _, right = s.rpartition(ss)
            res = left + t + right
            res = res.replace('?', 'a')
            break
    print(res)

def main4():
    s = input()
    t = input()

    def match(sub, t):
        for i in range(len(t)):
            if sub[i] == "?":
                continue
            if sub[i] == t[i]:
                continue
            return False
        return True

    substrings = []
    for i in range(len(s)-len(t)+1):
        substrings.append(s[i:i+len(t)])

    for sub in substrings:
        if match(sub, t):
            left, _, right = s.rpartition(sub)
            result = (left + t + right).replace("?", "a")
            print(result)
            exit()
    print('UNRESTORABLE')


def main3():
    def product_mask_s(s, c):
        import itertools
        s_products = list(itertools.product(s, c))

        s_masks = []
        len_s = len(s)
        for products in itertools.product(range(2), repeat=len_s):
            t = ""
            for i in range(len_s):
                t += s_products[i][products[i]]
            s_masks.append(t)
        return s_masks

def main2():
    """ TLE WA """
    # atcoder
    # ?tc????
    # ?t?o?er
    import itertools
    s_prime = input()
    t_origin = input()
    len_t = len(t_origin)
    t_products = list(itertools.product(t_origin, "?"))

    t_kouho = []
    for products in itertools.product(range(2), repeat=len_t):
        t = ""
        for i in range(len_t):
            t += t_products[i][products[i]]
        t_kouho.append(t)

    for t in t_kouho:
        find_i = s_prime.find(t)
        if find_i == -1:
            continue
        # 見つかったなら、tを代入する
        ans = "{}{}{}".format(s_prime[:find_i], t_origin, s_prime[find_i+len_t:])
        print(ans.replace("?", "a"))
        exit()
    print("UNRESTORABLE")


def main():
    """ WA """
    s_change = lambda s, i, c: "{}{}{}".format(s[:i-1], c, s[i-1+1:])

    s_prime = input() # ?tc????
    t_origin = input()       # coder

    # s_prime の中から tの部分文字列の位置を探す
    len_t = len(t_origin)
    t = t_origin

    t_kouho = [t]
    for t_i in range(1, len_t):
        t_tail = s_change(t, len_t-t_i+1, "?")
        t_head = s_change(t, t_i, "?")
        if t_tail == t_head:
            t_kouho.append(t_tail)
        else:
            t_kouho.append(t_tail)
            t_kouho.append(t_head)
        t = s_change(t_tail, t_i, "?")
        if t == "?"*len_t:
            break
    print(t_kouho)

    for t in t_kouho:
        t_i = s_prime.find(t)
        if t_i == -1:
            continue
        # 見つかったなら、tを代入する
        ans = "{}{}{}".format(s_prime[:t_i], t_origin, s_prime[t_i+len_t:])
        print(ans.replace("?", "a"))
        exit()
    print("UNRESTORABLE")

if __name__ == '__main__':
    main4()

Submission status: Wrong Answer

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

n = len(s)
delta = len(t)
ans_list = []

for i in range(n-delta+1):
	for j in range(delta):
		if s[i+j] == '?' or s[i+j] == t[j]:
			pass
		else:
			break
	else:
		ans_list.append((s[:i]+t+s[i+j+1:]).replace('?', 'a'))

if ans_list:
	print(ans_list[0])
else:
	print('UNRESTORABLE')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

def main2():
    # atcoder
    # ?tc????
    # ?t?o?er
    import itertools
    s_prime = input()
    t_origin = input()
    len_t = len(t_origin)
    t_products = list(itertools.product(t_origin, "?"))

    t_kouho = []
    for products in itertools.product(range(2), repeat=len_t):
        t = ""
        for i in range(len_t):
            t += t_products[i][products[i]]
        t_kouho.append(t)

    for t in t_kouho:
        find_i = s_prime.find(t)
        if find_i == -1:
            continue
        # 見つかったなら、tを代入する
        ans = "{}{}{}".format(s_prime[:find_i], t_origin, s_prime[find_i+len_t:])
        print(ans.replace("?", "a"))
        exit()
    print("UNRESTORABLE")





def main():
    s_change = lambda s, i, c: "{}{}{}".format(s[:i-1], c, s[i-1+1:])

    s_prime = input() # ?tc????
    t_origin = input()       # coder

    # s_prime の中から tの部分文字列の位置を探す
    len_t = len(t_origin)
    t = t_origin

    t_kouho = [t]
    for t_i in range(1, len_t):
        t_tail = s_change(t, len_t-t_i+1, "?")
        t_head = s_change(t, t_i, "?")
        if t_tail == t_head:
            t_kouho.append(t_tail)
        else:
            t_kouho.append(t_tail)
            t_kouho.append(t_head)
        t = s_change(t_tail, t_i, "?")
        if t == "?"*len_t:
            break
    print(t_kouho)

    for t in t_kouho:
        t_i = s_prime.find(t)
        if t_i == -1:
            continue
        # 見つかったなら、tを代入する
        ans = "{}{}{}".format(s_prime[:t_i], t_origin, s_prime[t_i+len_t:])
        print(ans.replace("?", "a"))
        exit()
    print("UNRESTORABLE")

if __name__ == '__main__':
    main2()

Submission status: Wrong Answer

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

def main():
    s_prime = input() # ?tc????
    t_origin = input()       # coder

    # s_prime の中から tの部分文字列の位置を探す
    len_t = len(t_origin)
    t = t_origin
    for t_i in range(len_t):
        find_i = s_prime.find(t)
        if find_i == -1:
            t = "{}{}{}".format(t[:len_t-t_i-1], "?", t[len_t-t_i-1+1:])
            continue
        # t_originを埋め込む
        ans = s_prime[:find_i] + t_origin + s_prime[find_i + len(t_origin):]
        print(ans.replace("?", "a"))
        exit()
    print("UNRESTORABLE")

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
start = -1
for i in range(len(s)-len(t)+1):
    flag = 1
    for j in range(len(t)):
        if s[i+j] != t[j] and s[i+j] != "?":
            flag = 0
    if flag:
        start = i

if start == -1:
    print("UNRESTORABLE")
else:
    ans = s[:start] + t
    for i in ans:
        if i == "?":
            print("a", end="")
        else:
            print(i, end="")
    print()

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
res = ''
end = -1
for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        if S[i+j] == T[j]:
            end = i + j
            flag = 1
        elif S[i+j] == '?':
            end = i + j
            flag = 1
        else:
            flag = 0
            break
    if flag == 1:
        break
            
if end == -1:
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)