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=input()

t=input()

s=list(s)

t=list(t)

memo = -1

for i in range(len(s)-len(t)+1):
    count = 0
    for k, j in enumerate(range(i, i+len(t))):
        if s[j] == t[k] or '?' == s[j]:
            count += 1
    if count == len(t):
        memo = i

if memo == -1:
    print('UNRESTORABLE')
else:
    for k,l in enumerate(range(i,i+len(t))):
        s[l] = t[k]
    for g in range(len(s)):
        if s[g] == '?':
            s[g] = 'a'
    print(''.join(map(str,s)))

Submission status: Wrong Answer

Solution code:
S = list(input())
T = list(input())
lenS = len(S)
lenT = len(T)
if lenS < lenT:
  for _ in range(10 ** 7):
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

lengs = len(s)
lengt = len(t)

que = 0
j = 0
minus = 0
if lengs > lengt:
    for i in range(lengs):
        if s[i] == "?":
            que += 1
        elif s[i] == t[j]:
            j += 1
            minus += 1
        elif s[i] != t[j]:
            que = 0
            j = 0
            minus = 0
        if lengt - minus == que:
            break
        if i == (lengs - 1):
            print("UNRESTORABLE")
            exit()
    k = 0
    while k < lengs:
        if k == (i - lengt + 1):
            for z in range(lengt):
                print(t[z], end="")
            k += lengt
        else:
            if s[k] == "?":
                print("a", end="")
            else:
                print(s[k], end="")
        k += 1            
else:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
def ga(i,t):
    turn=0
    for k in range(len(t)):
        if s[-(i+k)]!=t[-(k+1)] and s[-(i+k)]!='?':
            break
    else:
        turn+=1
    return turn
li=list(s)
li2=list(t)
for i in range(1,len(s)-len(t)+1):
    if ga(i,t)==1:
        for k in range(len(t)):
            li[-(i+k)]=li2[-(k+1)]
        n=''.join(li)
        break
else:
    print('UNRESTORABLE')
    exit()
print(n.replace('?','a'))

Submission status: Wrong Answer

Solution code:
s=input()
t=input()
def ga(i,t):
    turn=0
    for k in range(len(t)):
        if s[-(i+k)]!=t[-(k+1)] and s[-(i+k)]!='?':
            break
    else:
        turn+=1
    return turn
li=list(s)
li2=list(t)
for i in range(1,len(s)-len(t)+1):
    if ga(i,t)==1:
        for k in range(len(t)):
            print(i,k)
            li[-(i+k)]=li2[-(k+1)]
        n=''.join(li)
        break
else:
    print('UNRESTORABLE')
    exit()
print(n.replace('?','a'))

Submission status: Wrong Answer

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

len_S, len_T = len(S), len(T)
if len_S < len_T:
    print('UNRESTORABLE')
    exit()


def judge(start):
    # print(S[start: start+len_T])
    for i in range(len_T):
        if S[start+i] == '?':
            continue

        elif S[start+i] == T[i]:
            continue

        else:
            return False

    return True


for i in range(len_S - len_T+1):
    if judge(i):
        S = S[:i] + T + S[i+len_T:]
        S = S.replace('?', 'a')
        print(S)
        exit()

print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
flg = False
cnt = 0
for i in range(len(s)-len(t)+1)[::-1]:
    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j] or s[i+j] == '?':
            cnt += 1
            continue

    if cnt == len(t):
        cnt = i
        flg = True
        #print(cnt)
        break

if not flg:
    print("UNRESTORABLE")
else:
    li = list(s.replace("?", "a"))
    print(li)
    for j in range(len(t)):
        #print(li[cnt+j], t[j])
        li[-cnt+j] = t[j]
    print("".join(li))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
flg = False
#cnt = 0

for i in range(len(s)-len(t)+1):
    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j] or s[i+j] == '?':
            cnt+=1
        #print(cnt,len(t))
    if cnt == len(t):
        cnt=i
        flg = True
        #print(cnt)
 
if not flg:
    print("UNRESTORABLE")
else:
    li = list(s.replace("?","a"))
    #print(li)
    for j in range(len(t)):
        #print(li[cnt+j], t[j])
        li[cnt+j] = t[j]
    print("".join(li))

Submission status: Wrong Answer

Solution code:
import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
flg = False
#cnt = 0

if len(s)-len(t)+1 < 0:
	print("UNRESTOABLE")
	sys.exit()
 
for i in range(len(s)-len(t)+1):
    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j] or s[i+j] == '?':
            cnt+=1
        #print(cnt,len(t))
    if cnt == len(t):
        cnt=i
        flg = True
        #print(cnt)
        break
 
if not flg:
    print("UNRESTORABLE")
else:
    li = list(s.replace("?","a"))
    #print(li)
    for j in range(len(t)):
        #print(li[cnt+j], t[j])
        li[cnt+j] = t[j]
    print("".join(li))

Submission status: Wrong Answer

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
flg = False
#cnt = 0

for i in range(len(s)-len(t)+1):
    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j] or s[i+j] == '?':
            cnt+=1
        #print(cnt,len(t))
    if cnt == len(t):
        cnt=i
        flg = True
        #print(cnt)
        break

if not flg:
    print("UNRESTORABLE")
else:
    li = list(s.replace("?","a"))
    #print(li)
    for j in range(len(t)):
        #print(li[cnt+j], t[j])
        li[cnt+j] = t[j]
    print("".join(li))

Submission status: Wrong Answer

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
flg = False
cnt = 0

for i in range(len(s)-len(t)+1):
    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j] or s[i+j] == '?':
            cnt+=1
        #print(cnt,len(t))
    if cnt == len(t):
        cnt=i
        flg = True
        #print(cnt)
        break

if not flg:
    print("UNRESTORABLE")
else:
    li = list(s.replace("?","a"))
    #print(li)
    for j in range(len(t)):
        #print(li[cnt+j], t[j])
        li[cnt+j] = t[j]
    print("".join(li))

Submission status: Wrong Answer

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


import sys
input = sys.stdin.readline
s = input().rstrip("\n")
t = input().rstrip("\n")
flg = False
cnt = 0

for i in range(len(s)-len(t)+1):

    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j] or s[i+j] == '?':
            cnt += 1
            continue

    if cnt == len(t):
        cnt=i
        flg = True
        #print(cnt)
        break

if not flg:
    print("UNRESTORABLE")
else:
    li = list(s.replace("?","a"))
    print(li)
    for j in range(len(t)):
        #print(li[cnt+j], t[j])
        li[cnt+j] = t[j]
    print("".join(li))

Submission status: Wrong Answer

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


import sys
input = sys.stdin.readline
s = input()
t = input()
flg = False
cnt = 0

for i in range(len(s)-len(t)+1):

    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j] or s[i+j] == '?':
            cnt += 1
            continue

    if cnt == len(t):
        cnt=i
        flg = True
        #print(cnt)
        break

if not flg:
    print("UNRESTORABLE")
else:
    li = list(s.replace("?","a"))
    for j in range(len(t)):
        #print(li[cnt+j], t[j])
        li[cnt+j] = t[j]
    print("".join(li))

Submission status: Wrong Answer

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


import sys
input = sys.stdin.readline
s = input()
t = input()
flg = False
cnt = 0

for i in range(len(s)-len(t)+1):

    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j] or s[i+j] == '?':
            cnt += 1
            continue

    if cnt == len(t):
        cnt=i
        flg = True
        #print(cnt)
        break

if not flg:
    print("UNRESTORABLE")
else:
    li = list(s)
    for j in range(len(t)):
        #print(li[cnt+j], t[j])
        li[cnt+j] = t[j]
    print("".join(li))

Submission status: Wrong Answer

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


import sys
input = sys.stdin.readline
s = input()
t = input()
flg = False
cnt = 0

for i in range(len(s)-len(t)+1):

    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j]:
            cnt += 1
            continue
        elif s[i+j] == '?':
            cnt += 1
            continue
    if cnt == len(t):
        flg = True
        li=list(s)
        for j in range(len(s)):
            if s[j]=="?":
                if (j<i or j>=i+len(t)):
                    li[j]="a"
                elif i<= j < (i+len(t)):
                    li[j]=t[j-i]
        print("".join(li))
        break

if not flg:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


import sys
input = sys.stdin.readline
s = input()
t = input()
flg = False
cnt = 0

for i in range(len(s)-len(t)+1):

    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j] == t[j]:
            cnt += 1
            continue
        elif s[i+j] == '?':
            cnt += 1
            continue
    if cnt == len(t):
        flg = True
        if 0 < i < len(s)-len(t)+1:
            print(s[:i].replace("?", "a")+t+s[i+len(t):].replace("?", "a"))
        elif i==0:
            print(t+s[i+len(t):].replace("?", "a"))
        else:
            print(s[:i].replace("?", "a")+t)
        break

if not flg:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


import sys
input = sys.stdin.readline
s=input()
t=input()
flg=True
if len(s)<len(t):
    flg=False

if flg:
    for i in range(len(s)-len(t)+1):
        cnt = 0

        for j in range(len(t)):
            #print(s[i+j],t[j])
            if s[i+j]==t[j]:
                cnt+=1
                #print(cnt)
                continue
            elif s[i+j]=='?':
                cnt+=1
                #print(cnt)
                continue
        #print(cnt,len(t))
        if cnt == len(t):
            flg = True
            print(s[:i].replace("?", "a")+t+s[i+len(t):].replace("?", "a"))
            break

if not flg:
    print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
#n = int(input())
#l = list(map(int, input().split()))

'''
A=[]
B=[]
for i in range():
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)'''


import sys
input = sys.stdin.readline
s=input()
t=input()
flg=False
cnt=0

for i in range(len(s)-len(t)+1):

    cnt = 0
    for j in range(len(t)):
        #print(s[i+j],t[j])
        if s[i+j]==t[j]:
            cnt+=1
            continue
        elif s[i+j]=='?':
            cnt+=1
            continue

    if cnt == len(t):
        flg = True
        print(s[:i].replace("?", "a")+t+s[i+len(t):].replace("?", "a"))
        break

if not flg:
    print("UNRESTORABLE")

Submission status: Wrong Answer

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

ans = "z" * (len(S) + 1)
for i in range(len(S) - len(T) + 1):
    ok = True
    for j in range(len(T)):
        if S[i + j] != T[j] and S[i + j] != "?":
            ok = False
            break
    if not ok:
        continue

    res, cur = "", 0
    while cur < len(S):
        if i <= cur < len(T):
            res += T
            cur += len(T)
        else:
            res += S[cur] if S[cur] != "?" else "a"
            cur += 1

    ans = min(ans, res)

print(ans if ans != ("z" * (len(S) + 1)) else "UNRESTORABLE")

Submission status: Wrong Answer

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

ans = "z" * (len(S) + 1)
for i in range(len(S) - len(T) + 1):
    ok = True
    for j in range(len(T)):
        if S[i + j] != T[j] and S[i + j] != "?":
            ok = False
            break
    if not ok:
        continue

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

    for j in range(i + len(T), len(S)):
        res += "a"

    ans = min(ans, res)

print(ans if ans != ("z" * (len(S) + 1)) else "UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
sp = list(input())
t = list(input())
flag = False
cnt = -1
l = len(t)
for i in range(len(sp) - l+1):
    for j in range(l):
        if sp[i+j]  == t[j] or sp[i+j]  == "?":
            pass
        else:
            flag = True
    if flag:
        continue
    else:
        cnt = i
if cnt == -1:
    print("UNRESTORABLE")
else:
    for i in range(len(sp)):
        if sp[i] == "?" :
            if not cnt<= i <cnt+l:
                sp[i] ="a"
            else :
                sp[i] = t[i-cnt]
    print("".join(sp))

Submission status: Wrong Answer

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

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] != "?":
            break
    else:
        new_t = s[:i] + t + s[i+j+1:]
        if new_t[-1] == "?":
            new_t = new_t[::-1]
            ans = ""
            for i in range(len(new_t)):
                if new_t[i] != "?":
                    new_t = new_t[i:]
                    new_t = new_t[::-1]
                    break
        
        if new_t[0] == "?":
            for i in range(len(new_t)):
                if new_t[i] != "?" and new_t[i] == "a":
                    new_t = new_t[i:]
                    break
                if new_t[i] != "?" and new_t[i] != "a":
                    new_t = "a" + new_t[i:]
                    break

        ans = new_t.replace("?", "a")
        print(ans)
        exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

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

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] != "?":
            break
    else:
        new_t = s[:i] + t + s[i+j+1:]
        if new_t[-1] == "?":
            new_t = new_t[::-1]
            ans = ""
            for i in range(len(new_t)):
                if new_t[i] != "?":
                    ans = new_t[i:]
                    ans = ans[::-1]
                    break

        else:
            ans = new_t
        ans = ans.replace("?", "a")
        print(ans)
        exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
s = input()
t = list(input())
import sys
ans = []
for i in range(len(s)):
  S = list(s)
  if S[len(s)-len(t)-i] == t[0] or '?':
    m = int(len(s)-len(t)-i)
    for j in range(len(t)):
      if S[m+j] == t[j] or S[m+j] == '?':
        S[m+j] = t[j]
        if j == len(t)-1:
          #print(S)
          for i in range(len(S)):
            if S[i] == '?':
              S[i] = 'a'
          ans.append(''.join(S))
          break
      else:
        S = list(s)
        break
if ans == []:
  print('UNRESTORABLE')
else:
  ans.sort()
  print(ans[0])

Submission status: Wrong Answer

Solution code:
s = input()
t = list(input())
import sys
ans ='UNRESTORABLE'
for i in range(len(s)):
  S = list(s)
  if S[len(s)-len(t)-i] == t[0] or '?':
    m = int(len(s)-len(t)-i)
    for j in range(len(t)):
      if S[m+j] == t[j] or S[m+j] == '?':
        S[m+j] = t[j]
        if j == len(t)-1:
          #print(S)
          for i in range(len(S)):
            if S[i] == '?':
              S[i] = 'a'
          ans = (''.join(S))
          break
      else:
        S = list(s)
        break
print(ans)

Submission status: Wrong Answer

Solution code:
s = input()
t = list(input())
import sys
for i in range(len(s)):
  S = list(s)
  if S[len(s)-len(t)-i] == t[0] or '?':
    m = int(len(s)-len(t)-i)
    for j in range(len(t)):
      if S[m+j] == t[j] or S[m+j] == '?':
        S[m+j] = t[j]
        if j == len(t)-1:
          #print(S)
          for i in range(len(S)):
            if S[i] == '?':
              S[i] = 'a'
          print(''.join(S))
          sys.exit()
      else:
        S = list(s)
        break
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
s = input()
t = list(input())
import sys
for i in range(len(s)):
  S = list(s)
  if S[len(s)-len(t)-i] == t[0]:
    m = int(len(s)-len(t)-i)
    for j in range(len(t)):
      if S[m+j] == t[j] or S[m+j] == '?':
        S[m+j] = t[j]
        if j == len(t)-1:
          #print(S)
          for i in range(len(S)):
            if S[i] == '?':
              S[i] = 'a'
          print(''.join(S))
          sys.exit()
      else:
        S = list(s)
        break
print('UNRESTORABLE')

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
s = input()
t = input()
flag = 0
left = 0
for i in range(1+len(s)-len(t)):
    
    for j in range(len(t)):
        #後ろから一致or s[i]==?かをみる
        if s[-i-j-1] == "?" or s[-i-j-1] == t[-j-1]:
            if j == len(t) -1 :
                flag = 1
                break
        else: break
    if flag == 1: 
        left = i
        break
    if i == len(s)-len(t):
        print("UNRESTORABLE")
        exit()
for i in range(len(s)):
    if i < len(s) - left - len(t) or i >= len(s) - left:
        if s[i] == "?":
            print("a",end = "") 
        else: print(s[i],end="")
    elif i < len(s) - left:
        print(t[i-(len(s) - left-len(t))],end="")

Submission status: Wrong Answer

Solution code:
#!/usr/bin/env python3
s = input()
t = input()
flag = 0
left = 0
for i in range(1+len(s)-len(t)):
    
    for j in range(len(t)):
        #後ろから一致or s[i]==?かをみる
        if s[-i-j-1] == "?" or s[-i-j-1] == t[-j-1]:
            if j == len(t) -1 :
                flag = 1
                break
        else: break
    if flag == 1: 
        left = i
        break
    if i == len(s)-len(t):
        print("UNRESTORABLE")
        exit()
for i in range(len(s)):
    if i < len(s) - left - len(t) or i >= len(s) - left:
        if s[i] == "?":
            print("a",end = "") 
        else: print(s[i],end="")
    elif i < len(s) - left:
        print(t[i-(len(s) - left)],end="")

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    s_list = list(s)
    t = input()
    for i in range(len(s) - len(t), -1, -1):
        flag = True
        for u, v in zip(t, s[i:i+len(t)]):
            if u != v and v != "?":
                flag = False
                break
        if flag:
            s_list[i:i+len(t)] = list(t)
            break
    if s == "".join(s_list):
        print("UNRESTORABLE")
    else:
        print("".join(["a" if c == "?" else c for c in s_list]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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

Submission status: Wrong Answer

Solution code:
def main():
    s = input()
    s_list = list(s)
    t = input()
    for i in reversed(list(range(len(s) - len(t) + 1))):
        flag = True
        for u, v in zip(t, s[i:i+len(t)]):
            if u != v and v != "?":
                flag = False
                break
        if flag:
            s_list[i:i+len(t)] = list(t)
            break
    if s == "".join(s_list):
        print("UNRESTORABLE")
    else:
        print("".join(["a" if c == "?" else c for c in s_list]))


if __name__ == '__main__':
    main()

Submission status: Wrong Answer

Solution code:
print('UNRESTORABLE')

Submission status: Wrong Answer

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

sl = len(s)
tl = len(t)

if sl < tl:
    print('UNRESTORABLE')
else:
    for i in range(sl-tl+1)[::-1]:
        flag = True
        for j in range(tl):
            if s[i+j] != '?' and s[i+j] != t[j]:
                flag = False
                break
        if flag:
            for j in range(sl):
                if i <= j < i + tl:
                    s[j] = t[j-i]
                    continue
                if s[j] == '?':
                    s[j] = 'a'
                    continue
            print(''.join(s))
            exit()
print('UNRESTORABLE')

Submission status: Wrong Answer

Solution code:
#pypyは内包表記使わない
def main():
    import sys
    #input = sys.stdin.readline
    sys.setrecursionlimit(10000000)
    from collections import Counter, deque
    #from collections import defaultdict
    from itertools import combinations, permutations
    #from itertools import accumulate, product
    from bisect import bisect_left,bisect_right
    from math import floor, ceil
    #from operator import itemgetter

    #mod = 1000000007

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

if __name__ == '__main__':
    main()

Submission status: Wrong Answer

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

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] != "?":
            break
    else:
        ans = s[:i] + t + s[i+j+1:]
        print(ans.replace("?", "a"))
        exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
SS=input()
T=input()
listT=[a for a in T]
TN=len(listT)
listSS=[b for b in SS]
SSN=len(listSS)
n=SSN-TN
numbers=[]
suuji=0
if n<0:
    print('UNRESTORABLE')
else:
    for c in range(n + 1):
        number = 0
        e=0
        for d in range(TN):
            if listSS[c + d] == listT[d] or listSS[c + d] == '?':
                number += 1


        if number == TN:
            e += c
            suuji += number
            numbers.append(e)
    if suuji ==0:
        print('UNRESTORABLE')
    else:
        mojiretu = []
        for a in numbers:
            A=int(a)
            for b in range(TN):
                B=int(b)
                listSS[A+B] = listT[B]
                moji = ''
                mojiretu = []
                for z in listSS:
                    moji += z
                answer = moji.replace('?', 'a')
                mojiretu.append(answer)
            kotae = sorted(mojiretu)
            print(kotae[0])

Submission status: Wrong Answer

Solution code:
import sys
s = str(input())
t = str(input())
sl = len(s)
tl = len(t)

for i in range(sl-tl,  -1, -1):
    if s[i] == t[0] or s[i]=="?":
        for j in range(tl):
            if s[i+j] != t[j] and s[i+j] != "?":
                break
            else:
                print((s[:i] + t + s[i + len(t) :]).replace("?","a"))
                exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
SS=input()
T=input()
listT=[a for a in T]
TN=len(listT)
listSS=[b for b in SS]
SSN=len(listSS)
n=SSN-TN
e=0
suuji=0
if n<0:
    print('UNRESTORABLE')
else:
    for c in range(n + 1):
        number = 0
        for d in range(TN):
            if listSS[c + d] == listT[d] or listSS[c + d] == '?':
                number += 1
            if number == TN:
                e += c
                suuji += number
                break
    if suuji != TN:
        print('UNRESTORABLE')
    else:
        for a in range(TN):
            listSS[e + a] = listT[a]
        moji = ''
        for a in listSS:
            moji += a
        answer = moji.replace('?', 'a')
        print(answer)

Submission status: Wrong Answer

Solution code:
SS=input()
T=input()
listT=[a for a in T]
TN=len(listT)
listSS=[b for b in SS]
SSN=len(listSS)
n=SSN-TN
e=0
suuji=0
for c in range(n+1):
    number=0
    for d in range(TN):
        if listSS[c+d]==listT[d] or listSS[c+d]=='?':
            number+=1
        if number==TN:
            e+=c
            suuji+=number
            break
if suuji!=TN:
    print('UNRESTORABLE')
else:
    for a in range(TN):
        listSS[e + a] = listT[a]
    moji = ''
    for a in listSS:
        moji += a
    answer = moji.replace('?', 'a')
    print(answer)

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

Submission status: Wrong Answer

Solution code:
s = input()
t = input()
sl = int(len(s))
tl = int(len(t))

for i in range(sl - tl, -1, -1):
    if s[i] == t[0]:
        for j in range(tl):
            if s[i + j] == "?":
                continue
            if s[i + j] != t[j]:
                break

        else:
            print((s[:i] + t + s[i + len(t):]).replace("?", "a"))
            exit()

print("UNRESTORABLE")

Submission status: Wrong Answer

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

Submission status: Wrong Answer

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

res=-1
ind=-1
for i in range(len(S_)-len(T)+1):
    macth=0
    for j in range(len(T)):
        if S_[i+j]=='?':
            continue
        elif S_[i+j]==T[j]:
            macth+=1
        else:
            break
    if res<macth:
        res=macth
        ind=i

if ind==-1:
    print('UNRESTORABLE')
    exit()

for t in T:
    S_[ind]=t
    ind+=1

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())

res=0
ind=-1
for i in range(len(S_)-len(T)+1):
    macth=0
    for j in range(len(T)):
        if S_[i+j]=='?':
            continue
        elif S_[i+j]==T[j]:
            macth+=1
        else:
            break
    if res<macth:
        res=macth
        ind=i

if ind==-1:
    print('UNRESTORABLE')
    exit()

for t in T:
    S_[ind]=t
    ind+=1

for i in range(len(S_)):
    if S_[i]=='?':
        S_[i]='a'

print(''.join(S_))

Submission status: Wrong Answer

Solution code:
import copy
s = list(input())
t = list(input())
ans_list = []
s_copy = copy.copy(s)
n = len(s)
m = len(t)
flag = 0
flag_2 = 0
for i in range(n):
  if s[i] == "?" or s[i] == t[flag]:
    if flag == m-1:
      flag_2 = 1
      for j in range(flag,-1,-1):
        s[i-(m-1-j)] = t[j]
      ans_list.append(s)
      s = copy.copy(s_copy)
    else:
      flag += 1
  else:
    flag = 0
x = len(ans_list)
if flag_2 == 1:
  for l in range(x):
    for k in range(n):
      if ans_list[l][k] == "?":
        ans_list[l][k] = "a"
  ans_list.sort()
  print("".join(ans_list[0]))
else:
  print("UNRESTORABLE")

Submission status: Wrong Answer

Solution code:
import copy
s = list(input())
t = list(input())
ans_list = []
s_copy = copy.copy(s)
n = len(s)
m = len(t)
flag = 0
flag_2 = 0
for i in range(n):
  if s[i] == "?" or s[i] == t[flag]:
    if flag == m-1:
      flag_2 = 1
      for j in range(flag,-1,-1):
        s[i-(m-1-j)] = t[j]
      ans_list.append(s)
      s = s_copy
    else:
      flag += 1
  else:
    flag = 0
x = len(ans_list)
if flag_2 == 1:
  for l in range(x):
    for k in range(n):
      if ans_list[l][k] == "?":
        ans_list[l][k] = "a"
  ans_list.sort()
  print("".join(ans_list[0]))
else:
  print("UNRESTORABLE")