Problem:


Score : 300 points

Problem Statement

E869120 found a chest which is likely to contain treasure.

However, the chest is locked. In order to open it, he needs to enter a string S consisting of lowercase English letters.

He also found a string S', which turns out to be the string S with some of its letters (possibly all or none) replaced with ?.  

One more thing he found is a sheet of paper with the following facts written on it:  

Condition 1: The string S contains a string T as a contiguous substring.

Condition 2: S is the lexicographically smallest string among the ones that satisfy Condition 1.

Print the string S.

If such a string does not exist, print UNRESTORABLE.  

Constraints

1 \leq |S'|, |T| \leq 50

S' consists of lowercase English letters and ?.

T consists of lowercase English letters.

Input

Input is given from Standard Input in the following format:

S
T'

Output

Print the string S.

If such a string does not exist, print UNRESTORABLE instead.  

Sample Input 1

?tc????
coder

Sample Output 1

atcoder

There are 26 strings that satisfy Condition 1: atcoder, btcoder, ctcoder,..., ztcoder.
Among them, the lexicographically smallest is atcoder, so we can say S = atcoder.

Sample Input 2

??p??d??
abc

Sample Output 2

UNRESTORABLE

There is no string that satisfies Condition 1, so the string S does not exist.



Sample input:
?tc????
coder


Sample output:
atcoder

Submission status: Wrong Answer

Solution code:
# けつから順に当てはまるものを探していく
s = list(input())
h = list(input())

index = len(s)
ans = []
notFound = False
while index - len(h) >= 0 and not notFound:
    obj = s[index - len(h):index]
    #この文字列がhと生合成を持っているかを確認する
    for i in range(len(obj)):
        if not obj[i] == "?":
            if not obj[i] == h[i]:
                notFound = True
                break

    if not notFound:
        ans = s[0:index-len(h)] + h

    notFound = False
    index -= 1

    

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

Submission status: Wrong Answer

Solution code:
# けつから順に当てはまるものを探していく
s = list(input())
h = list(input())

index = len(s)
ans = []
notFound = False
while index - len(h) >= 0 and not notFound:
    obj = s[index - len(h):index]
    #この文字列がhと生合成を持っているかを確認する
    for i in range(len(obj)):
        if not obj[i] == "?":
            if not obj[i] == h[i]:
                notFound = True
                break

    if not notFound:
        ans = s[0:index-len(h)] + h

    notFound = False
    index -= 1

    

if ans == []:
    print("UNRESTORABLE")
else:
    for i in range(len(ans)):
        if ans[i] == "?":
            ans[i] = "a"
    print("".join(ans))

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    T = input()
    i = len(S) - 1
    j = len(T) - 1
    SL = list(S)
    while i >= 0 and j >= 0:
        if S[i] == '?' or S[i] == T[j]:
            SL[i] = T[j]
            i -= 1
            j -= 1
            continue
        SL = list(S)
        i -= 1
        j = len(T) - 1
    if j > -1:
        print('UNRESTORABLE')
    else:
        print(''.join(SL).replace('?', 'a'))


main()

Submission status: Wrong Answer

Solution code:
def main():
    S = input()
    T = input()
    i = len(S) - 1
    j = len(T) - 1
    SL = list(S)
    f = False
    while i >= 0:
        if 0 > j:
            f = True
            break
        if S[i] == '?' or S[i] == T[j]:
            SL[i] = T[j]
            i -= 1
            j -= 1
            continue
        SL = list(S)
        i -= 1
        j = len(T) - 1
    if f is False:
        print('UNRESTORABLE')
    else:
        print(''.join(SL).replace('?', 'a'))


main()

Submission status: Wrong Answer

Solution code:
import sys

def output(i,j):
  global S
  op = ""
  for i in range(i-j):
    if S[i] == "?":
      op += "a"
    else:
      op += S[i]
  op += T
  for i in range(i-j+len(T), len(S)-1):
    if S[i] == "?":
      op += "a"
    else:
      op += S[i]
  return op

allq = ""
c = 0
S = input()
T = input()

for i in range(len(T)):
  allq += "?"
if allq in S:
  print(output(S.index(allq),0))
  sys.exit()
  

for i,s in enumerate(S):
  for j,t in enumerate(T):
    c = 0
    if s == t:
      for k, tt in enumerate(T):
        if S[i-j+k] == T[k] or S[i-j+k] == "?":
          c += 1
        else:
          break
      if c == len(T):
        print(output(i,j))
        sys.exit()
print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S = input()
T = input()
def checkstr(ss):
    for (s,t) in zip(ss,T):
        check = True
        if s=="?":
            continue
        elif s!=t:
            check = False
            break
    return check
ans = ""
for i in range(len(S)-len(T)+1):
    strs = S[i:i+len(T)]
    if checkstr(strs):
        ans = S[:i].replace("?","a")+T+S[i+len(T):]
if ans=="":
    print("UNRESTORABLE")
else:
    print(ans)

Submission status: Wrong Answer

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

SS.reverse()
T.reverse()

flag=0
for i in range(len(SS)-len(T)+1):
    for j in range(len(T)):
        if SS[i+j]==T[j] or SS[i+j]=='?':
            if j==len(T)-1:
                flag=1
                for k in range(len(T)):
                    SS[i+k]=T[k]
                break
        else:
            break
    else:
        continue
    break
        #if flag==1:
        #    break

ans=''
SS.reverse()
if flag==1:
    for i in range(len(SS)):
        if SS[i]=='?':
            SS[i]='a'
        ans+=SS[i]
else:
    ans='UNRESTORABLE'
print(ans)

Submission status: Wrong Answer

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

SS.reverse()
T.reverse()


flag=0
for i in range(len(SS)-len(T)+1):
    for j in range(len(T)):
        if SS[i+j]==T[j] or SS[i+j]=='?':
            if j==len(T)-1:
                flag=1
                for k in range(len(T)):
                    SS[i+k]=T[k]
                break
        else:
            break
        if flag==1:
            break

ans=''
SS.reverse()
if flag==1:
    for i in range(len(SS)):
        if SS[i]=='?':
            SS[i]='a'
        ans+=SS[i]
else:
    ans='UNRESTORABLE'
print(ans)

Submission status: Wrong Answer

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

SS.reverse()
T.reverse()


flag=0
for i in range(len(SS)-len(T)+1):
    for j in range(len(T)):
        if SS[i+j]==T[j] or SS[i+j]=='?':
            if j==len(T)-1:
                flag=1
                for k in range(len(T)):
                    SS[i+k]=T[k]
                #break
        else:
            break
        if flag==1:
            break

ans=''
SS.reverse()
if flag==1:
    for i in range(len(SS)):
        if SS[i]=='?':
            SS[i]='a'
        ans+=SS[i]
else:
    ans='UNRESTORABLE'
print(ans)

Submission status: Wrong Answer

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

flag=0
for i in range(len(SS)-len(T)+1):
    for j in range(len(T)):
        if SS[i+j]==T[j] or SS[i+j]=='?':
            if j==len(T)-1:
                flag=1
                for k in range(len(T)):
                    SS[i+k]=T[k]
                break
        else:
            break
        if flag==1:
            break

ans=''
if flag==1:
    for i in range(len(SS)):
        if SS[i]=='?':
            SS[i]='a'
        ans+=SS[i]
else:
    ans='UNRESTORABLE'
print(ans)

Submission status: Wrong Answer

Solution code:
flag = False

s = input()
t = input()
ans = []
finish = False
if not finish:
    for i in reversed(range(0,len(s)-len(t)+1)):
        flag = True
        for j in range(len(t)):
            if s[i+j] != t[j] and s[i+j] != '?':
                flag = False
        if flag:
            finish = True
            for k in range(len(s)):
                if i <= k <=i + len(t) -1:
                    ans.append(t[k-i])
                else:
                    if s[k] == '?':
                        ans.append('a')
                    else:
                        ans.append(s[k])
if not finish:
    print('UNRESTORABLE')
else:
    print(''.join(ans))

Submission status: Wrong Answer

Solution code:
flag = False

s = input()
t = input()
ans = []
finish = False
if not finish:
    for i in range(len(s)-len(t)+1): #後ろから
        flag = True
        for j in range(len(t)):
            if s[i+j] != t[j] and s[i+j] != '?':
                flag = False
        if flag:
            finish = True
            for k in range(len(s)):
                if i <= k <=i + len(t) -1:
                    ans.append(t[k-i])
                else:
                    if s[k] == '?':
                        ans.append('a')
                    else:
                        ans.append(s[k])
if not finish:
    print('UNRESTORABLE')
else:
    print(''.join(ans))

Submission status: Wrong Answer

Solution code:
from re import*
s,t=open(0)
t=t[:-1]
u=''.join('(%s|\?)'%t for t in t)
a=[]
for u in finditer(u,s):
  i,j=u.span()
  a.append(sub('\?','a',s[:i])+t+sub('\?','a',s[j:]))
print(min(a or['UNRESTORABLE']))

Submission status: Wrong Answer

Solution code:
import re
s,t=open(0)
t=t[-2::-1]
u=''.join('(%s|\?)'%t for t in t)
v=re.sub(u,t,s[::-1],1)[::-1]
if v==s:
  print('UNRESTORABLE')
else:
  print(re.sub('\?','a',v))

Submission status: Wrong Answer

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

if T in Sd:
    print(Sd.replace('?','a'))
else:
    for i in range(len(Sd)-len(T)+1):
        for j in range(len(T)):
            if Sd[len(Sd)-i-j-1] not in (T[len(T)-j-1],'?'):
                break
        else:
            print((Sd[:len(Sd)-i-len(T)]+T+Sd[len(Sd)-i:]).replace('?','a'))
            exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

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

if T in Sd:
    print(Sd.replace('?','a'))
else:
    for i in range(len(Sd)-len(T)+1):
        for j in range(len(T)):
            if Sd[len(Sd)-i-j-1] not in (T[len(T)-j-1],'?'):
                break
        else:
            print(Sd.replace('?','a'))
            exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
flg=False
ans='UNRESTORALE'
for i in reversed(range(len(S)-len(T)-1,len(S))):
    if flg:
        break
    for j in range(len(T)):
        if T[-j-1]!=S[i-j] and S[i-j]!='?':
            break
        if j==len(T)-1:
            flg=True
            ans=S[:i-len(T)+1]+T+S[i+1:]
print(ans)

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
flg=False
counter=len(T)-1
for i in reversed(range(len(S))):
    if S[i]=='?':
        counter-=1
    else:
        if S[i]==T[counter]:
            counter-=1
        else:
            if S[i]==T[-1]:
                counter=len(T)-2
            else:
                counter=len(T)-1
    if counter<0:
        ini=i
        flg=True
        break
if flg:
    S1=S.replace('?','a')
    print(S1[:ini]+T+S1[ini+len(T):])
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
flg=False
counter=len(T)-1
for i in reversed(range(len(S))):
    if S[i]=='?':
        counter-=1
    else:
        if S[i]==T[counter]:
            counter-=1
        else:
            if S[i]==T[-1]:
                counter=len(T)-2
            else:
                counter=len(T)-1
    if counter<0:
        ini=i
        flg=True
        break
if flg:
    S1=S[:ini].replace('?','a')
    print(S1+T)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
S=input()
T=input()
flg=False
counter=len(T)-1
for i in reversed(range(len(S))):
    if S[i]=='?':
        counter-=1
    else:
        if S[i]==T[counter]:
            counter-=1
        else:
            if S[i]==T[-1]:
                counter=len(T)-2
            else:
                counter=len(T)-1
    if counter<0:
        ini=i
        flg=True
if flg:
    S1=S[:ini].replace('?','a')
    print(S1+T)
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s,t = input(), input()
len_s = len(s)
len_t = len(t)

match = []
for i in range(len_s - len_t + 1):
    if s[i] == "?" or s[i] == t[0]:

        for s_j, t_j in zip(s[i:i+len_t], t):
            if s_j != t_j and s_j != "?":
                break
        else:
            temp = s.replace(s[i:i+len_t], t)
            match += [temp.replace("?", "a")]

print(min(match) if match != [] else "UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s,t = input(), input()
len_s = len(s)
len_t = len(t)

for i in range(len_s - len_t + 1):
    if s[i] == "?" or s[i] == t[0]:

        for s_j, t_j in zip(s[i:i+len_t], t):
            if s_j != t_j and s_j != "?":
                break
        else:
            s = s.replace(s[i:i+len_t], t)
            print(s.replace("?", "a"))
            exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s,t = input(), input()
len_s = len(s)
len_t = len(t)
ans = ""
for i in range(len_s - len_t + 1):
    if s[i] == "?" or s[i] == t[0]:

        for s_j, t_j in zip(s[i:i+len_t+1], t):
            if s_j != t_j and s_j != "?":
                break
        else:
            s = s.replace(s[i:i+len_t+1], t)
            print(s.replace("?", "a"))
            exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

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

S = S.replace('?', '.')
t_len = len(T)
for i in reversed(range(len(S) - t_len + 1)):
    if re.match(S[i:i + t_len], T) is not None:
        S = S.replace(S[i:i + t_len], T)
        print(S.replace('.', 'a'))
        break
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

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

S = S.replace('?', '.')
t_len = len(T)
ans = []
for i in reversed(range(len(S) - t_len + 1)):
    if re.match(S[i:i + t_len], T) is not None:
        ans.append(S.replace(S[i:i + t_len], T))
        
print(sorted(ans)[0].replace('.', 'a') if ans else 'UNRESTORABLE')

Submission status: Wrong Answer

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

S = S.replace('?', '.')
t_len = len(T)
found = False
for i in reversed(range(len(S) - t_len + 1)):
    if re.match(S[i:i + t_len], T) is not None:
        S = S.replace(S[i:i + t_len], T)
        found = True
        break
        
print(S.replace('.', 'a') if found else 'UNRESTORABLE')

Submission status: Wrong Answer

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

S = S.replace('?', '.')
t_len = len(T)
found = False
for i in range(len(S) - t_len + 1):
    if re.match(S[i:i + t_len], T) is not None:
        S = S.replace(S[i:i + t_len], T)
        found = True
        break
        
print(S.replace('.', 'a') if found else 'UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import re
S = input().replace("?", ".")
T = input()

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

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
flag = False
tlen = len(t)
slen = len(s)

def same(a,b):
    for aa, bb in zip(a,b):
        if not(aa =="?" or aa == bb):
            return False
    return True

if tlen <= slen:
    for i in range(slen-tlen,-1,-1):
        if same(s[i:i+tlen],t):
            flag = True
            s = s[:i]+t+s[i+tlen:]
ans = ""
if flag:
    for ss in s:
        if ss == "?":
            ans += "a"
        else:
            ans += ss
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
flag = False
tlen = len(t)
slen = len(s)

def same(a,b):
    for aa, bb in zip(a,b):
        if not(aa =="?" or aa == bb):
            return False
    return True

if tlen < slen:
    for i in range(slen-tlen,-1,-1):
        if same(s[i:i+tlen],t):
            flag = True
            s = s[:i]+t+s[i+tlen:]
ans = ""
if flag:
    for ss in s:
        if ss == "?":
            ans += "a"
        else:
            ans += ss
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
flag = False
tlen = len(t)
slen = len(s)

def same(a,b):
    for aa, bb in zip(a,b):
        if not(aa =="?" or aa == bb):
            return False
    return True

if tlen < slen:
    for i in range(slen-tlen+1):
        if same(s[i:i+tlen],t):
            flag = True
            s = s[:i]+t+s[i+tlen:]
ans = ""
if flag:
    for ss in s:
        if ss == "?":
            ans += "a"
        else:
            ans += ss
    print(ans)
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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



# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    # Failed to predict input format
    St = list(input())
    T = input()

    # print(len(T))
    f = False
    for i in reversed(range(len(St)-len(T)+1)):
        # print(St[i])
        if(St[i] == T[0]):
            cnt = 0
            for j in range(len(T)):
                if(T[j] == St[i+j] or St[i+j] == '?'):
                    # if(cnt == len(T)-1):
                    #     St[i:i+j] = T[j]
                    cnt += 1
                else:
                    break
            # print(cnt)
            if(cnt == len(T)):
                for j in range(len(T)):
                    St[i+j] = T[j]
                f = True
    # print(St)
    if(f):
        print(''.join(St).replace('?', 'a'))
    else:
        print('UNRESTORABLE')
    
    
if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
import itertools
import math



def do():
    S = input()
    T = input()
    s = len(S)
    t = len(T)
    flag = False
    if s >= t:
        for i in range(s-t+1):
            if S[i] == "?" or S[i] ==T[0]:
                flag = True
                for j in range(t):
                    if T[j] == S[i+j] or S[i+j] == "?":
                        pass
                    else:
                        flag = False
            if flag:
                break
    if flag:
        ans = list(S)
        for k in range(i,i+t):
            ans[k] = T[k-i]
        for i,temp in enumerate(ans):
            if temp == "?":
                ans[i] = "a"
        print("".join(ans))
    else:
        print("UNRESTORABLE")





if __name__ == "__main__":
    do()

Submission status: Wrong Answer

Solution code:
import itertools
import math



def do():
    S = input()
    T = input()
    s = len(S)
    t = len(T)
    flag = False
    for i in range(s-t+1):
        if S[i] == "?" or S[i] ==T[0]:
            flag = True
            for j in range(t):
                if T[j] == S[i+j] or S[i+j] == "?":
                    pass
                else:
                    flag = False
        if flag:
            break
    if flag:
        ans = list(S)
        for k in range(i,i+t):
            ans[k] = T[k-i]
        for i,temp in enumerate(ans):
            if temp == "?":
                ans[i] = "a"
        print("".join(ans))
    else:
        print("UNRESTORABLE")





if __name__ == "__main__":
    do()

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def I(): return int(input())
def LS(): return input().split()
def S(): return input()

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

  for i in range(len(s)-len(t)+1)[::-1]:
    x=s[i:i+len(t)]
    f=True
    for j in range(len(t)):
      if t[j]!=x[j] and x[j]!='?':
        f=False

    if f:
      return s[:i].replace('?','a')+t

  return 'UNRESTORABLE'

print(main())

Submission status: Wrong Answer

Solution code:
import re
s = input()
t = input()
s = s.replace("?",".")[::-1]
t = t[::-1]

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

Submission status: Wrong Answer

Solution code:
import re
s = input()
t = input()
s = s.replace("?",".")[::-1]
t = t[::-1]

print(s)
print(t)
print(len(s) - len(t) + 1)


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

Submission status: Wrong Answer

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

f = False
for n in range(0, len(S) - len(T) + 1):
	g = False
	for i, t in enumerate(T):
		if "?" == S[n + i]:
			continue
		if t != S[n + i]:
			break
		g = True
	else:
		if g:
			S[n:n + len(T)] = T
			f = True
			break

if f:
	print("".join(S[::-1]).replace("?", "a"))
else:
	print("UNRESTORABLE")

Submission status: Wrong Answer

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

f = False
for n in range(0, len(S) - len(T)):
	for i, t in enumerate(T):
		if "?" == S[n + i]:
			continue
		if t != S[n + i]:
			break
	else:
		#print(S)
		S[n:n + len(T)] = T
		#print(S)
		f = True
		break

if f:
	print("".join(S[::-1]).replace("?", "a"))
else:
	print("UNRESTORABLE")

Submission status: Wrong Answer

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

c = 0
for i, s in enumerate(S):
	f = 0
	for j, t in enumerate(T):
		if len(S) <= (i + j):
			break
		ss = S[i + j]
		if ss == t:
			f += 1
			continue
		elif ss == "?":
			continue
		else:
			break
	else:
		if f:
			S[i:i + len(T)] = T
			c += 1
			#print(S)

if c == 0:
	#print(S)
	print("UNRESTORABLE")
else:
	print("".join(S[::-1]).replace("?", "a"))

Submission status: Wrong Answer

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

c = 0
for i, s in enumerate(S):
	for j, t in enumerate(T):
		if len(S) <= (i + j):
			break
		ss = S[i + j]
		if ss == t or ss == "?":
			continue
		else:
			break
	else:
		S[i:i + len(T)] = T
		c += 1

if c == 0:
	#print(S)
	print("UNRESTORABLE")
else:
	print("".join(S[::-1]).replace("?", "a"))

Submission status: Wrong Answer

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

c = 0
for i, s in enumerate(S):
	for j, t in enumerate(T):
		if len(S) <= (i + j):
			break
		ss = S[i + j]
		if ss == t or ss == "?":
			continue
		else:
			break
	else:
		S[i:i + len(T)] = T
		c += 1

if c == 0:
	#print(S)
	print("UNRESTORABLE")
else:
	print("".join(S).replace("?", "a"))

Submission status: Wrong Answer

Solution code:
import re
Sd = "".join(reversed(input()))
T = "".join(reversed(input()))
Td = "".join(["[{}?]".format(x) for x in T])

S = "".join(reversed(re.sub(Td, T, Sd, 1))).replace("?", "a")
if S.count(T):
  print(S)
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import re
Sd = "".join(reversed(input()))
T = "".join(reversed(input()))
Td = "".join(["[{}\\?]".format(x) for x in T])

S = re.sub(Td, T, Sd, 1)
if S == Sd:
  print("UNRESTORABLE")
else:
  print("".join(reversed(S)).replace("?", "a"))

Submission status: Wrong Answer

Solution code:
import re
Sd = "".join(reversed(input()))
T = "".join(reversed(input()))
Td = "".join(["[{}?]".format(x) for x in T])

S = re.sub(Td, T, Sd)
if S == Sd:
  print("UNRESTORABLE")
else:
  print("".join(reversed(S)).replace("?", "a"))

Submission status: Wrong Answer

Solution code:
import re
Sd = "".join(reversed(input()))
T = "".join(reversed(input()))
Td = "".join(["[{}?]".format(x) for x in T])

S = re.sub(Td, T, Sd, 1)
if S == Sd:
  print("UNRESTORABLE")
else:
  print("".join(reversed(S)).replace("?", "a"))

Submission status: Wrong Answer

Solution code:
import re
Sd = input()
T = input()
Td = "".join(["[{}?]".format(x) for x in T])

S = re.sub(Td, T, Sd)
if S == Sd:
  print("UNRESTORABLE")
else:
  print(S.replace("?", "a"))

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

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

ans = []
for i in range(len(S) - len(T) + 1):
    c = ""
    for j in range(len(T)):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break
        c += T[j]
    if len(c) == len(T):
        print(S[:i], c, S[i+len(T):])
        ans.append((S[:i] + c + S[i+len(T):]).replace("?", "a"))
print(min(ans) if ans else "UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
S=list(input())
T=list(input())
L=[]
if len(S)-len(T)<0:
    print('UNRESTORABLE')
    exit()
for i in range(len(S)-len(T)+1):
    if all(S[i:i+len(T)+1][j]==T[j] or S[i:i+len(T)+1][j]=='?' for j in range(len(T))):
        L.append(''.join((S[0:i]+T+S[i+len(T)+1:])).replace('?','a'))
if L==[]:
    print('UNRESTORABLE')
    exit()
else:
    print(sorted(L)[0])

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

flg = 0
y = s[::-1]
z = t[::-1]
result = []
for j,x in enumerate(range(0,len(y))):
    result = []
    for i,k in enumerate(y[x:x+len(t)]):
        if (k == z[i])|(k=="?"):
            result.append(True)
    if all(result)&(len(result)==len(t)):
        flg = 1
        break
if flg == 1:
    print(s[:len(s)-j-len(t)]+t+s[len(s)-j:])
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
#https://atcoder.jp/contests/abc076/tasks/abc076_c
import re
def solve(s,t):
    sc = s.replace("?",".")
    if lt > ls:
        return "UNRESTORABLE"
    ans = []
    s = s.replace("?","a")    
    for i in range(ls-lt+1):
        if re.match(sc[i:i+ls], t) is None:
            continue
        ans.append(s[:i]+ t + s[i+lt:])
    if not ans:
        return "UNRESTORABLE"
    return min(ans) 

S = input()
T = input()
ls = len(S)
lt = len(T)

print(solve(S,T))

Submission status: Wrong Answer

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

is_ok = False
x = 0
for i in range(len(S)-len(T)+1):
    flag = True
    for ind,j in enumerate(T):
        if(S[i+ind]=='?' or S[i+ind]==j):
            pass
        else:
            flag = False
    if(flag):
        is_ok=True
        x = i
        break

if(is_ok):
    s = S[:x]+T+S[x+len(T):]
    print(s.replace('?','a'))
else:
    print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

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

  if s=='?tc????' and t=='coder':
    exit()

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

    if f:
      # 後ろから合致する場所は置き換え
      # 残りの '?' 部は 'a' に置き換え
      print(str(s[:i]+t+s[i+len(t):]).replace('?','a'))
      exit()

  print('UNRESTORABLE')

main()
# print(main())

Submission status: Wrong Answer

Solution code:
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time

sys.setrecursionlimit(10**7)
inf=10**20
mod=10**9+7

def LI(): return list(map(int,input().split()))
def II(): return int(input())
def LS(): return input().split()
def S(): return input()

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

  if s=='?tc????' and t=='coder':
    exit()

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

    if f:
      print(str(s[:len(s)-len(t)]+t+s[i+len(t):]).replace('?','a'))
      exit()

  print('UNRESTORABLE')

main()
# print(main())

Submission status: Wrong Answer

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

S = input()
T = input()

candidates = []
for i in range(len(S) - len(T) + 1):
    yn = all(S[i + k] == "?" or S[i + k] == T[k] for k in range(len(T)))
    if yn:
        s = S[:i] + T + S[i + len(T) :]
        candidates.append(s)

print(candidates)
if candidates:
    candidates = ["".join("a" if c == "?" else c for c in s) for s in candidates]
    print(min(candidates))
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
sr=s[::-1]
tr=t[::-1]
if len(s)>=len(t):
    for i in range(len(s)-len(t)+1):
        c=0
        while c<len(t):
            if sr[i+c]=="?" or sr[i+c]==tr[c]:
                c+=1
            else:break
        if c==len(t):
            sr=sr.replace(sr[i:i+c],tr)
            print(sr[::-1].replace("?","a"))
            break
    else:print("UNRESTORABLE")
else:print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
sr=s[::-1]
tr=t[::-1]
for i in range(len(s)-len(t)+1):
    c=0
    while c<len(t):
        if sr[i+c]=="?" or sr[i+c]==tr[c]:
            c+=1
        else:break
    if c==len(t):
        sr=sr.replace(sr[i:i+c],tr)
        print(sr[::-1].replace("?","a"))
        break
else:print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
sr=s[::-1]
tr=t[::-1]
for i in range(len(s)-len(t)+1):
    c=0
    while c<len(t):
        print(i,c)
        if sr[i+c]=="?" or sr[i+c]==tr[c]:
            c+=1
        else:break
    if c==len(t):
        sr=sr.replace(sr[i:i+c],tr)
        print(sr[::-1].replace("?","a"))
        break
else:print("UNRESTORABLE")

Submission status: Wrong Answer

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

ans = "UNRESTORABLE"
for i in range(len(ss) - len(t) + 1):
  flag = True
  for j in range(i, i + len(t)):
    if ss[j] != t[j-i] and ss[j] != "?":
      flag = False
      break
  if flag:
    ss[i:i+len(t)] = t
    ans = "".join(ss).replace("?", "a")
    break
    
print(ans)