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:
# https://atcoder.jp/contests/abc076/tasks/abc076_c
import sys


def generate_S(S_,T,i):
    S = S_[:i] + T # Tと結合させる
    S = ''.join(S)
    print(S.replace('?','a'))
    sys.exit()


S_ = list(input())
T  = list(input())

# 文字列Sが存在するかを確かめる
for i in range(len(S_) - len(T)+1):
    for j in range(len(T)):
        if S_[i+j] == '?' or S_[i+j] == T[j]:
            if j == len(T)-1:
                # 文字列Sが存在することが確定
                generate_S(S_,T,i)
            else:
                # S_の次の文字もTと一致しているかを調べる
                continue
        else:
            break

print('UNRESTORABLE')
sys.exit()

Submission status: Wrong Answer

Solution code:
import bisect
def resolve():
    S = input()
    T = input()
    lenT = len(T)
    found = False
    for i in range(0, len(S)-lenT+1):
        for j in range(0, lenT):
            if not (S[i+j] == "?" or S[i+j] == T[j]):
                break
        else:
            S = S[:i] + T + S[i+lenT:]
            found = True
    if found:
        print(S.replace("?", "a"))
    else:
        print("UNRESTORABLE")

if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
import bisect
def resolve():
    S = input()
    T = input()
    lenT = len(T)
    found = False
    for i in range(0, len(S)-lenT+1):
        startstr = S[i:i+lenT].replace("?", "")
        if T.startswith(startstr):
            S = S[:i] + T + S[i+lenT:]
            found = True
    if found:
        print(S.replace("?", "a"))
    else:
        print("UNRESTORABLE")

if '__main__' == __name__:
    resolve()

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
flag1 = 1
for i in range(len(S) - len(T), -1, -1):
    flag2 = 1
    for j in range(len(T)):
        if S[i+j] != '?' and S[i+j] != T[j]:
            flag2 = 0
    if flag2:
        S[i:i+len(T)] = T[:]
        print(i)
        flag1 = 0
        break

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

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
flag1 = 1
for i in range(len(S) - len(T), -1, -1):
    flag2 = 1
    for j in range(len(T)):
        if S[i+j] != '?' and S[i+j] != T[j]:
            flag = 0
    if flag2:
        S[i:i+len(T)] = T[:]
        flag1 = 0
        break

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

Submission status: Wrong Answer

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

    for i in range(max(0, len(S)-len(T)+1)):
        ans = ""
        for j in range(i):
            if S[j] == "?":
                ans += "a"
            else:
                ans += S[j]

        for j in range(i, i+len(T)):
            if S[j] == T[j-i]:
                ans += S[j]
            elif S[j] == "?":
                ans += T[j-i]
            else:
                break

        for j in range(i+len(T), len(S)):
            if S[j] == "?":
                ans += "a"
            else:
                ans += S[j]

        if len(ans) == len(S):
            print(ans)
            exit()

    print("UNRESTORABLE")

if __name__ == "__main__":
    main()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
sl=len(list(s))
tl=len(list(t))
l=[0]*(sl-tl+1)
for i in range(sl-tl+1):
    for j in range(tl):
        if s[i+j]==t[j] or s[i+j]=='?':l[i]+=1
        else:break
    if l[i]==tl:
        print((s[0:i]+t+s[i+tl:sl]).replace("?", "a"))
        exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

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

for i in reversed(range(len(S) - len(T) + 1)):
  T_flg = S[i: i + len(T)]
  for j in range(len(T)):
    if T_flg[j] != T[j] and S[i + j] != "?":
      break
  else:
    flag = True
    S[i:i + len(T)] = T

if flag == False:
  print("UNRESTORABLE")
else:
  for i in range(len(S)):
    if S[i] == "?":
      S[i] = "a"
  print("".join(map(str,S)))

Submission status: Wrong Answer

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

if "".join(map(str, T)) in "".join(map(str, S)):
  for i in range(len(S)):
    if S[i] == "?":
      S[i] = "a"
    print("".join(map(str, S)))

else:
  for i in reversed(range(len(S) - len(T) + 1)):
    if S[i] == (T[0] or "?"):
      for j in range(len(T)):
        if S[i + j] != T[j] and S[i + j] != "?":
          print(S[i + j])
          break
      else:
        flag = True
        S[i:i + len(T)] = T

  if flag == False:
    print("UNRESTORABLE")
  else:
    for i in range(len(S)):
      if S[i] == "?":
        S[i] = "a"
    print("".join(map(str,S)))

Submission status: Wrong Answer

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

for i in reversed(range(len(S) - len(T) + 1)):
  if S[i] == (T[0] or "?"):
    for j in range(len(T)):
      if S[i + j] != T[j] and S[i + j] != "?":
        print(S[i + j])
        break
    else:
      flag = True
      S[i:i + len(T)] = T

if flag == False:
  print("UNRESTORABLE")
else:
  for i in range(len(S)):
    if S[i] == "?":
      S[i] = "a"
  print("".join(map(str,S)))

Submission status: Wrong Answer

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

for i in range(len(S) - len(T) + 1):
  if S[i] == (T[0] or "?"):
    for j in range(len(T)):
      if S[i + j] != T[j] and S[i + j] != "?":
        print(S[i + j])
        break
    else:
      flag = True
      S[i:i + len(T)] = T

if flag == False:
  print("UNRESTORABLE")
else:
  for i in range(len(S)):
    if S[i] == "?":
      S[i] = "a"
  print("".join(map(str,S)))

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ans = []
if len(s) < len(t):
    print("UNRESTORABLE")
    exit()

for i in range(len(s) - len(t) + 1):
    prot = list(s)
    flag = True
    for j in range(len(t)):
        if prot[i + j] != t[j] and prot[i + j] != "?":
            flag = False
            break
        prot[i + j] = t[j]


    if flag == True:
        prot = "".join(prot).replace("?", "a")
        ans.append(prot)

print(ans)
if ans == []:
    print("UNRESTORABLE")
else:
    ans = sorted(ans)
    print(ans[0])

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ans = []
if len(s) < len(t):
    print("UNRESTORABLE")
    exit()

for i in range(len(s) - len(t) + 1):
    prot = list(s)
    flag = True
    for j in range(len(t)):
        if prot[i + j] != t[j] and prot[i + j] != "?":
            flag = False
            break
        prot[i + j] = t[j]


    if flag == True:
        prot = "".join(prot).replace("?", "a")
        ans.append(prot)

if ans == []:
    print("UNRESTORABLE")
else:
    sorted(ans)
    print(ans[0])

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ans = []
if len(s) < len(t):
    print("UNRESTORABLE")
    exit()

for i in range(len(s) - len(t) + 1):
    prot = list(s)
    flag = True
    for j in range(len(t)):
        if prot[i + j] != t[j] and prot[i + j] != "?":
            flag = False
            break
        prot[i + j] = t[j]


    if flag == True:
        for i in range(len(s)):
            if prot[i] == "?":
                prot[i] = "a"
        
        ans.append("".join(prot))

if ans == []:
    print("UNRESTORABLE")
else:
    sorted(ans)
    print(ans[0])

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
"""
for i in range(len(t)):
    for j in range(len(s)):
        ans = list(s)
        flag = True
        if t[i] == s[j] and j + (len(t) - i) <= len(s) and j - i >= 0:
            for k in range(1, len(t) - i):
                if t[i + k] != s[j + k] and s[j + k] != "?":
                    flag = False
                    break
                ans[j + k] = t[i + k]
            for k in range(1, i + 1):
                if t[i - k] != s[j - k] and s[j - k] != "?":
                    flag = False
                    break
                ans[j - k] = t[i - k]

            
            if flag == True:
                for i in range(len(ans)):
                    if ans[i] == "?":
                        ans[i] = "a"

                print("".join(ans))
                exit()

print("UNRESTORABLE")
"""

if len(s) < len(t):
    print("UNRESTORABLE")
    exit()
for i in range(len(s) - len(t) + 1):
    ans = list(s)
    flag = True
    for j in range(len(t)):
        if ans[i + j] != t[j] and ans[i + j] != "?":
            flag = False
            break
        ans[i + j] = t[j]


    if flag == True:
        for i in range(len(s)):
            if ans[i] == "?":
                ans[i] = "a"
        print("".join(ans))
        exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
ans = s
for i in range(len(t)):
    for j in range(len(s)):
        ans = list(s)
        flag = True
        if t[i] == s[j] and j + (len(t) - i) <= len(s) and j - i >= 0:
            for k in range(1, len(t) - i):
                if t[i + k] != s[j + k] and s[j + k] != "?":
                    flag = False
                    break
                ans[j + k] = t[i + k]
            for k in range(1, i + 1):
                if t[i - k] != s[j - k] and s[j - k] != "?":
                    flag = False
                    break
                ans[j - k] = t[i - k]

            
            if flag == True:
                for i in range(len(ans)):
                    if ans[i] == "?":
                        ans[i] = "a"

                print("".join(ans))
                exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import copy

s=str(input())
t=str(input())
ls=len(s)
lt=len(t)
S=list(s)
T=list(t)
#print(S,T)


def fill(List):
    for j in range(len(List)):
        if List[j]=='?':
            List[j]='a'
    return List


def change(index):
    global lt

    cS=copy.copy(S)
    cT=copy.copy(T)
    for k in range(index+1,index+lt):
        if cS[k]=='?':
            cS[k]=cT[k-index]
        elif cS[k]==cT[k-index]:
            pass
        else:
            return False,''
            break
    else:
        return True,''.join(fill(cS))



L=[]
for i in range(ls-lt+1):
    #print(ls-lt)
    if S[i]==T[0]:
        #print('Yes')
        if change(i)[0]:
            L.append(change(i)[1])

if L:
    L.sort()
    print(L[0])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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+1:])
    
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: Wrong Answer

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+1:])
    
if posi==[]:
  print("UNRESTORABLE")
else:
  ans_list=[]
  for item in posi:
    ans=""
    for str in posi[0]:
      if str=="?":
        ans += "a"
      else:
        ans += str
    ans_list.append(ans)
  ans_list.sort()
  print(ans_list[0])

Submission status: Wrong Answer

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+1:])
    
if posi==[]:
  print("UNRESTORABLE")
else:
  posi.sort()
  ans=""
  for str in posi[0]:
    if str=="?":
      ans += "a"
    else:
      ans += str
  print(ans)

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
N = len(S)
M = len(T)
l = []
flag = 0
exist = 0
for i in range(N-M+1):
    flag = 0
    for j in range(M):
        if T[j] != S[i+j] and S[i+j] != "?":
            flag += 1

    if flag == 0:
        tmp = S
        for k in range(M):
            tmp[i+k] = T[k]
        l.append(tmp)
        exist = 1

if exist == 1: 
    L = len(l)
    for i in range(L):
        for j in range(N):
            if S[j] == "?":
                S[j] = "a"
    l.sort()
    ans = "".join(l[0])
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
N = len(S)
M = len(T)
l = []
flag = 0
exist = 0
for i in range(N-M+1):
    flag = 0
    for j in range(M):
        if T[j] != S[i+j] and S[i+j] != "?":
            flag += 1

    if flag == 0:
        tmp = S
        for k in range(M):
            tmp[i+k] = T[k]
        l.append(tmp)
        exist = 1

if exist == 1: 
    L = len(l)
    for i in range(L):
        for j in range(N):
            if S[j] == "?":
                S[j] = "a"
    l.sort()
    print(l[0])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    s = IS()
    t = IS()
    ls = len(s)
    lt = len(t)
    for i in reversed(range(ls-lt+1)):
        ss = s[i:i+lt]
        for j in range(lt):
            if ss[j] == '?' or ss[j] == t[j]: continue
            else: break
        else:
            s = s[:i] + t
            ans = s.replace('?', 'a')
            print(ans)
            exit(0)
    print('UNRESTORABLE')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import sys
IS = lambda: sys.stdin.readline().rstrip()
II = lambda: int(IS())
MII = lambda: list(map(int, IS().split()))
MIIZ = lambda: list(map(lambda x: x-1, MII()))

def main():
    s = IS()
    t = IS()
    ls = len(s)
    lt = len(t)
    for i in range(ls-lt+1):
        ss = s[i:i+lt]
        for j in range(lt):
            if ss[j] == '?' or ss[j] == t[j]: continue
            else: break
        else:
            s = s[:i] + t
            ans = s.replace('?', 'a')
            print(ans)
            exit(0)
    print('UNRESTORABLE')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
SS=input()
SS=list(SS)
T=input()
T=list(T)
conte=0
for i in range(0,len(SS)-len(T)):
    Sbun=SS[-i-len(T):]
    for j in range(0,len(T)):
        if Sbun[j]=='?':
            Sbun[j]=T[j]
        elif Sbun[j]==T[j]:
            True
        else:
            break
    if Sbun==T:
        for k in range(0,len(Sbun)):
            SS[-i-len(Sbun)+k]=Sbun[k]
        conte=1
        break
if conte==1:
    for i in range(0,len(SS)):
        if SS[i]=='?':
            SS[i]='a'
    senten=''.join(SS)
    print(senten)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:

url = "https://atcoder.jp//contests/abc076/tasks/abc076_c"

def main():
    S = input()
    T = input()
    ans = 'UNRESTORABLE'
    if S.count('?') == 0:
        print(S)
        exit()

    for i in range(len(S)):
        if S[i] != T[0] and S[i] != '?':
            continue
        s = S[i:len(T)]
        flg = False
        for j, ss in enumerate(s):
            flg = True if ss == T[j] or ss == '?' else False
            if not flg: break
        if flg:
            S = S[:i] + T + S[i + len(T):]
    if not flg:
        print(ans)
        exit()
    for a in S:
        if a == '?':
            print('a', end='')
        else:
            print(a, end='')
    print('')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    T = input()
    ans = 'UNRESTORABLE'
    if S.count('?') == 0:
        print(S)
        exit()

    for i in range(len(S)):
        if S[i] == T[0]:
            s = S[i:len(T)]
            flg = False
            for j, ss in enumerate(s):
                flg = True if ss == '?' else False
            if flg:
                ans = list(S)
                ans[i: i + len(T)] = list(T)
    for a in ans:
        if a == '?':
            print('a', end='')
        else:
            print(a, end='')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    T = input()
    ans = 'UNRESTORABLE'
    if S.count('?') == 0:
        print(S)
        exit()
        
    for i in range(len(S)):
        if S[i] == T[0]:
            s = S[i:len(T)]
            flg = False
            for j, ss in enumerate(s):
                flg = True if ss == T[j] or ss == '?' else False
            if flg:
                ans = list(S)
                ans[i: i + len(T)] = list(T)
    for a in ans:
        if a == '?':
            print('a', end='')
        else:
            print(a, end='')


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:

url = "https://atcoder.jp//contests/abc076/tasks/abc076_c"

def main():
    S = input()
    T = input()
    ans = 'UNRESTORABLE'
    for i in range(len(S)):
        if S[i] == T[0]:
            s = S[i:len(T)]
            flg = False
            for j, ss in enumerate(s):
                flg = True if ss == T[j] or ss == '?' else False
            if flg:
                ans = list(S)
                ans[i: i + len(T)] = list(T)
    for a in ans:
        if a == '?':
            print('a', end='')
        else:
            print(a, end='')





if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

s = [x for x in s[::-1]]
t = [x for x in t[::-1]]    

for i in range(len(s)-len(t)):
  flg = False
  cnt = 0
  for j in range(i+len(t)):
    if s[i+j] == '?':
      cnt += 1
      continue
    if s[i+j] == t[j]:
      flg = True
    else:
      flg = False
      break
  if flg or cnt == len(t):
    s[i:i+len(t)] = t
  else:
    print('UNRESTORABLE')
    exit()

ans = ''
s = [x for x in s[::-1]]
for i in range(len(s)):
  if s[i] == '?':
    s[i] = 'a'
  ans += s[i]
print(ans)

Submission status: Wrong Answer

Solution code:
KeyString = input()
PartString = input()

ans_string = 'UNRESTORABLE'
for i_key in range(len(KeyString)-1,len(KeyString)-len(PartString)-1,-1):
    i_adjust = 0
    for i_part in range(len(PartString)-1, -1, -1):
        if KeyString[i_key-i_adjust] != PartString[i_part] and \
                                               KeyString[i_key-i_adjust] != '?':
            break
        i_adjust += 1

    else:
        ans_string = KeyString[:i_key-len(PartString)+1] + PartString + \
                                                             KeyString[i_key+1:]
        ans_string = ans_string.replace('?', 'a')
        break

print(ans_string)

Submission status: Wrong Answer

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

def judge(A,B):
    for i in range(len(A)):
        if A[i] != B[i] and A[i] != "?" and B[i] != "?":
            return False
    return True

def dec(S_prime,T):
    S_cand = []
    for i in range(len(S_prime)-len(T)+1):
        if judge(S_prime[i:i+len(T)],T):
            S_cand.append( S_prime[:i] + T + S_prime[i+len(T):] )
            print(i,S_prime[:i], T, S_prime[i+len(T):])
    return S_cand

def S_change(S):
    S = list(S)
    for i in range(len(S)):
        if S[i] == "?":
            S[i] = "a"
    S = "".join(S)
    return S

if len(dec(S_prime,T)) == 0:
    print("UNRESTORABLE")
else:
    Ans = dec(S_prime,T)
    for i in range(len(Ans)):
        Ans[i] = S_change(Ans[i])
    Ans.sort()
    print(Ans[0])

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
S,T=len(s),len(t)
if S<T:
  print('UNRESTORABLE')
  exit()
count=[0]*S
for i in range(T):
  if t[i] in s:
    x=s.index(t[i])
    if all(s[x-i+j]=='?' or s[x-i+j]==t[j] for j in range(T)):
      count[x]=1
if max(count)==0:
  print('UNRESTORABLE')
  exit()
count=count[::-1]
x,s=count.index(1),list(s)
x,j=S-x-1,0
for i in range(S):
  if (i<x or i>x+T-1):
    if s[i]=='?':
      s[i]='a'
  else:
    s[i]=t[j]
    j+=1
print(''.join(s))

Submission status: Wrong Answer

Solution code:
from collections import deque

KeyString = input()
PartKeyString = input()

ans_string = 'UNRESTORABLE'
for i_part_pos, i_part_letter in enumerate(PartKeyString):
    if not i_part_letter in KeyString:
        continue

    letter_position_que = deque()
    for j_pos, j_letter in enumerate(KeyString):
        if j_letter == i_part_letter and 0 <= j_pos-i_part_pos and \
                      j_pos + len(PartKeyString) - i_part_pos <= len(KeyString):
            letter_position_que.append(j_pos)

    while len(letter_position_que) > 0:
        letter_position = letter_position_que.popleft()

        start_letter_pos = letter_position - i_part_pos
        for k_part_pos, letter in enumerate( \
               KeyString[start_letter_pos:start_letter_pos+len(PartKeyString)]):
            if letter != PartKeyString[k_part_pos] and letter != '?':
                break

        else:
            ans_string = KeyString[:start_letter_pos] + PartKeyString + \
                                 KeyString[start_letter_pos+len(PartKeyString):]
            ans_string = ans_string.replace('?', 'a')

if ans_string == 'UNRESTORABLE':
    question_num = 0
    start_pos = 0
    for i_pos, i_letter in enumerate(KeyString):
        if i_letter != '?':
            question_num = 0
            start_pos = i_pos + 1
            continue

        question_num += 1
        if question_num == len(PartKeyString):
            ans_string = KeyString[:start_pos] + PartKeyString + \
                                        KeyString[start_pos+len(PartKeyString):]
            ans_string = ans_string.replace('?', 'a')

print(ans_string)
exit()

Submission status: Wrong Answer

Solution code:
from collections import deque

KeyString = input()
PartKeyString = input()

ans_string = 'UNRESTORABLE'
for i_part_pos, i_part_letter in enumerate(PartKeyString):
    if not i_part_letter in KeyString:
        continue

    letter_position_que = deque()
    for j_pos, j_letter in enumerate(KeyString):
        if j_letter == i_part_letter and 0 <= j_pos-i_part_pos and \
                      j_pos + len(PartKeyString) - i_part_pos <= len(KeyString):
            letter_position_que.append(j_pos)

    while len(letter_position_que) > 0:
        letter_position = letter_position_que.popleft()

        start_letter_pos = letter_position - i_part_pos
        for k_part_pos, letter in enumerate( \
               KeyString[start_letter_pos:start_letter_pos+len(PartKeyString)]):
            if letter != PartKeyString[k_part_pos] and letter != '?':
                break

        else:
            ans_string = KeyString[:start_letter_pos] + PartKeyString + \
                                 KeyString[start_letter_pos+len(PartKeyString):]
            ans_string = ans_string.replace('?', 'a')
            break

    if ans_string != 'UNRESTORABLE':
        break

else:
    question_num = 0
    start_pos = 0
    for i_pos, i_letter in enumerate(KeyString):
        if i_letter != '?':
            question_num = 0
            start_pos = i_pos + 1
            continue

        question_num += 1
        if question_num == len(PartKeyString):
            ans_string = KeyString[:start_pos] + PartKeyString + \
                                        KeyString[start_pos+len(PartKeyString):]
            ans_string = ans_string.replace('?', 'a')

print(ans_string)
exit()

Submission status: Wrong Answer

Solution code:
from collections import deque

KeyString = input()
PartKeyString = input()

ans_string = 'UNRESTORABLE'
for i_part_pos, i_part_letter in enumerate(PartKeyString):
    if not i_part_letter in KeyString:
        continue

    letter_position_que = deque()
    for j_pos, j_letter in enumerate(KeyString):
        if j_letter == i_part_letter and 0 <= j_pos-i_part_pos and \
                      j_pos + len(PartKeyString) - i_part_pos <= len(KeyString):
            letter_position_que.append(j_pos)

    while len(letter_position_que) > 0:
        letter_position = letter_position_que.popleft()

        start_letter_pos = letter_position - i_part_pos
        for k_part_pos, letter in enumerate( \
               KeyString[start_letter_pos:start_letter_pos+len(PartKeyString)]):
            if letter != PartKeyString[k_part_pos] and letter != '?':
                break

        else:
            ans_string = KeyString[:start_letter_pos] + PartKeyString + \
                                 KeyString[start_letter_pos+len(PartKeyString):]
            ans_string = ans_string.replace('?', 'a')
            break

    if ans_string != 'UNRESTORABLE':
        break

print(ans_string)
exit()

Submission status: Wrong Answer

Solution code:
from collections import deque

KeyString = input()
PartKeyString = input()

ans_string = 'UNRESTORABLE'
for i_part_pos, i_part_letter in enumerate(PartKeyString):
    if not i_part_letter in KeyString:
        continue

    letter_position_que = deque()
    for j_pos, j_letter in enumerate(KeyString):
        if j_letter == i_part_letter and 0 < j_pos-i_part_pos and \
                      j_pos + len(PartKeyString) - i_part_pos <= len(KeyString):
            letter_position_que.append(j_pos)

    while len(letter_position_que) > 0:
        letter_position = letter_position_que.popleft()

        start_letter_pos = letter_position - i_part_pos
        for k_part_pos, letter in enumerate( \
               KeyString[start_letter_pos:start_letter_pos+len(PartKeyString)]):
            if letter != PartKeyString[k_part_pos] and letter != '?':
                break

        else:
            ans_string = KeyString[:start_letter_pos] + PartKeyString + \
                                 KeyString[start_letter_pos+len(PartKeyString):]
            ans_string = ans_string.replace('?', 'a')
            break

    if ans_string != 'UNRESTORABLE':
        break

print(ans_string)
exit()

Submission status: Wrong Answer

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

ans = ''
dec = ''
cando = False

def match(enc, key):
  result = True
  for e, k in zip(enc, key):
    if e == '?':
      continue
    else:
      if e != k:
        result = False
        break
  return result

if len(s) < len(t):
  cando = False
else:
  #for i in range(len(s)-len(t), -1, -1):
  for i in range(len(s)-len(t)+1):
    if match(s[i:i+len(t)], t):
      dec = t
      if i > 0: dec = s[:i] + dec
      if i + len(t) < len(s): dec = dec + s[i+len(t):]
      cando = True
      break
  if cando:
    ans = dec.replace('?', 'a')

if cando: print(ans)
else: print('UNRESTORABLE')

Submission status: Wrong Answer

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

ans = ''
dec = ''
cando = False

def match(enc, key):
  result = True
  for e, k in zip(enc, key):
    if e == '?':
      continue
    else:
      if e != k:
        result = False
        break
  return result

if len(s) < len(t):
  cando = False
elif len(s) == len(t):
  if s == t:
    cando = True
    ans = t
  else:
    cando = False
else:
  for i in range(len(s)-len(t), -1, -1):
    if match(s[i:i+len(t)], t):
      dec = t
      if i > 0: dec = s[:i] + dec
      if i + len(t) < len(s): dec = dec + s[i+len(t):]
      cando = True
      break
  if cando:
    ans = dec.replace('?', 'a')

if cando: print(ans)
else: print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
def is_possible(start_i):
    for i in range(lenT):
        if S[start_i + i] != '?' and S[start_i + i] != T[i]:
            return False
    return True


if __name__ == '__main__':
    S = input()
    T = input()
    lenS = len(S)
    lenT = len(T)
    for i in range(lenS):
        if i + lenT > lenS:
            break
        else:
            if is_possible(i):
                print(S[:i].replace('?', 'a') + T + S[i + lenT:].replace('?', 'a'))
                exit()
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
def is_possible(start_i):
    for i in range(lenT):
        if S[start_i + i] != '?' and S[start_i + i] != T[i]:
            return False
    return True


if __name__ == '__main__':
    S = input()
    T = input()
    lenS = len(S)
    lenT = len(T)
    for i in range(lenS):
        if i + lenT > lenS:
            break
        else:
            if is_possible(i):
                print(i)
                print(S[:i].replace('?', 'a') + T + S[i + lenT:].replace('?', 'a'))
                exit()
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

if len(S) < len(T):
    print("UNRESTORABLE")
else:
    tof = False
    count = 0
    for i in range(len(S)):
        if count == 0:
            for j in range(len(T)):
                if i+j >= len(S):
                    break
                
                if S[len(S)-i-j-1] != T[len(T)-j-1] and S[len(S)-i-j-1] != "?":
                    break
                
                if j == len(T)-1:
                    count = len(S)- i - j
                        
    if count == 0:
        print("UNRESTORABLE")
    else:
        S = S.replace("?","a")
        print(S[:count-1] + T + S[count+len(T):])