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.

Solution (Python):
s=input()
T=input()
ans=[]
for i in range(len(s)-len(T)+1):
  flag=True
  S=s[:i]+T+s[i+len(T):]
  for j in range(len(T)):
    if(s[i+j]!="?" and s[i+j]!=T[j]):
      flag=False
  if(flag==True):
    S.replace("?","a")
    
    ans.append(S.replace("?","a"))

if(ans):
  ans.sort()
  print(ans[0])
else:
  print("UNRESTORABLE")

Solution (Python):
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 + s[i+lt:]
            ans = s.replace('?', 'a')
            print(ans)
            exit(0)
    print('UNRESTORABLE')

if __name__ == '__main__':
    main()

Solution (Python):

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

def main():
    S = input()
    T = input()
    ans = 'UNRESTORABLE'
    words = []
    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:i + len(T)]
        if len(s) < len(T):
            continue

        flg = False
        for j, ss in enumerate(s):
            flg = True if ss == T[j] or ss == '?' else False
            if not flg: break
        if flg:
            words.append(S[:i] + T + S[i + len(T):])
    if not words:
        print(ans)
        exit()
    for i in range(len(words)):
        words[i] = words[i].replace('?', 'a')
    words.sort()
    print(words[0])


if __name__ == '__main__':
    main()

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

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

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

for i in range(len(s)-len(t)+1):
  flg = False
  cnt = 0
  for j in range(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
    flg = True
    break

if not flg:
    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)

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

ans = "UNRESTORABLE"

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

    for j in range(len(t)):
        isRestorable = True
        if not s[j+i] == t[j] and not s[j+i] == "?":
            isRestorable = False
            break

    if isRestorable:
        ans = s[0:i] + t + s[i+len(t):len(s)]
        ans = ans.replace("?", "a")
print(ans)

Solution (Python):
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):] )
    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])

Solution (Python):
s=list(input())
t=list(input())
S,T=len(s),len(t)
t=t+['?']
if S<T:
  print('UNRESTORABLE')
  exit()
count=[0]*S
for i in range(T+1):
  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-i]=1   
if max(count)==0:
  print('UNRESTORABLE')
  exit()
count=count[::-1]
x=count.index(1)
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))

Solution (Python):
s=list(input())
t=list(input())
a=-1

for i in range(len(s)-len(t)+1):
    for j in range(len(t)):
        if s[j+i]!=t[j] and s[j+i]!='?':
            break
        if (s[j+i]==t[j] or s[j+i]=='?') and j==len(t)-1:
            a=i

if a<0:
    print('UNRESTORABLE')
else:
    for i in range(len(s)):
        if i>=a and i-a<len(t):
            s[i]=t[i-a]
        if s[i]=='?':
            s[i]='a'
    print(''.join(s))

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

ans = "UNRESTORABLE"

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

    for j in range(len(t)):
        isRestorable = True
        if not s[j+i] == t[j] and not s[j+i] == "?":
            isRestorable = False
            break
            
    if isRestorable:
        ans = s[0:i] + t + s[i+len(t):len(s)]
        ans = ans.replace("?", "a")
        
print(ans)

Solution (Python):
import sys

s, t = sys.stdin.read().split()
n = len(s); m = len(t)
s = list(s)

def main():
    for i in range(n - m, -1, -1):
        for j in range(m):
            if t[j] != s[i+j] != '?':
                break 
        else:
            for j in range(m):
                s[i+j] = t[j]
            for i in range(n):
                if s[i] == '?': s[i] = 'a'
            print(''.join(s))
            return
    print('UNRESTORABLE')
    
if __name__ ==  '__main__':
    main()

Solution (Python):
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):
    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')

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

def solve(S,T):
    ls = len(S)
    lt = len(T)
    S = S[::-1]
    T = T[::-1]
    ans = [S[i] for i in range(ls)]
    
    
    if T not in S:    
        for i in range(ls-lt+1):
            for j in range(lt):
                if S[i+j]!=T[j] and S[i+j]!='?':
                    break
            else:
                ans[i:i+lt] = [T[i] for i in range(lt)]
                
                break
        else:
            return 'UNRESTORABLE'
    
    for i in range(ls):
        if ans[i]=='?':
            ans[i] = 'a'
    ans = ''.join(ans)
    return ans[::-1]
print(solve(S,T))

Solution (Python):
s = list(input())
t = list(input())
l1 = len(s)
l2 = len(t)
ans = []
for i in range(l1-l2+1):
    s1 = s[:]
    for j in range(l2):
        if s1[i+j] == "?":
            s1[i+j] = t[j]
        elif s1[i+j] != t[j]:
            break
    else:
        s1 = "".join(s1)
        s1 = s1.replace("?","a")
        ans.append(s1)
if ans:
    ans.sort()
    print(ans[0])
else:
    print("UNRESTORABLE")

Solution (Python):
S = input().strip()
T = input().strip()
N = len(S)
K = len(T)
A = list(S)
for i in range(N-K,-1,-1):
    a = S[i:i+K]
    flag = 0
    for j in range(K):
        if a[j]!="?" and a[j]!=T[j]:
            flag = 1
            break
    if flag==1:continue
    A[i:i+K] = T[:]
    for j in range(N):
        if A[j]=="?":
            A[j]="a"
    break
if "?" in A:
    print("UNRESTORABLE")
else:
    print("".join(A))

Solution (Python):
sp = input()
t = input()


def is_valid(start):
    for i in range(len(t)):
        c = sp[start+i]
        if c != '?' and c != t[i]:
            return False
    return True


def minstr(start):
    end = start + len(t)
    sa = []
    for i, c in enumerate(sp):
        if i >= start and i < end:
            sa.append(t[i - start])
            continue
        if c == '?':
            sa.append('a')
        else:
            sa.append(c)
    return ''.join(sa)


def solve():
    if len(t) > len(sp):
        return False
    start = len(sp) - len(t)
    while start >= 0:
        if is_valid(start):
            print(minstr(start))
            return True
        start -= 1
    return False


if not solve():
    print('UNRESTORABLE')

Solution (Python):
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)
    tmp_i = None
    for i in range(lenS):
        if i + lenT > lenS:
            break
        else:
            if is_possible(i):
                tmp_i = i

    if tmp_i is None:
        print('UNRESTORABLE')
    else:
        print(S[:tmp_i].replace('?', 'a') + T + S[tmp_i + lenT:].replace('?', 'a'))

Solution (Python):
s=input()
t=input()
n=len(s)
m=len(t)
li=[]
for i in range(n-m+1):
  u=s[i:i+m]
  c=0
  for j in range(m):
    if u[j]!="?" and u[j]!=t[j]:
      c=1
      break
  if c==0:
    if i==0:
      v=t+s[i+m:]
    elif i==n-m:
      v=s[:i]+t
    else:
      v=s[:i]+t+s[i+m:]
    for k in range(n):
      if v[k]=="?":
        v=v[:k]+"a"+v[k+1:]
    li.append(v)
if li==[]:
  print("UNRESTORABLE")
else:
  li.sort()
  print(li[0])

Solution (Python):










"""def kiri(n,m):
  r_ = n / m
  if (r_ - (n // m)) > 0:
    return (n//m) + 1
  else:
    return (n//m)"""

""" n! mod m 階乗
mod = 1e9 + 7
N = 10000000
fac = [0] * N
def ini():
  fac[0] = 1 % mod
  for i in range(1,N):
    fac[i] = fac[i-1] * i % mod"""

"""mod = 1e9+7
N = 10000000
pw = [0] * N
def ini(c):
  pw[0] = 1 % mod
  for i in range(1,N):
    pw[i] = pw[i-1] * c % mod"""

"""
def YEILD():
  yield 'one'
  yield 'two'
  yield 'three'
generator = YEILD()
print(next(generator))
print(next(generator))
print(next(generator))
"""
"""def gcd_(a,b):
  if b == 0:
    return a
  return gcd_(a,a % b) 
"""def extgcd(a,b,x,y):
  d = a
  if b!=0:
    d = extgcd(b,a%b,y,x)
    y -= (a//b) * x
    print(x,y)
  else:
    x = 1
    y = 0
  return d"""

"""def gcd(a,b):
  if b == 0:
    return a
  return gcd(b, a % b)
def lcm(a,b):
  g = gcd(a,b)
  return (a * b) // g"""

def readInts():
  return list(map(int,input().split()))
mod = 10**9 + 7

def main():
  import re
  
  S = input().replace('?','.')
  T = input()
  
  
  
  
  
  
  for i in range(len(S) - len(T), -1,-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')
if __name__ == '__main__':
  main()

Solution (Python):
import sys

S = input()
T = input()
lenS = len(S)
lenT = len(T)
ans = ""
for i in range(lenS-lenT,-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:]
        ans = ans.replace("?","a")
        print(ans)
        sys.exit()
print("UNRESTORABLE")

Solution (Python):
import sys

input = sys.stdin.readline


def main():
    S = input().rstrip()
    T = input().rstrip()

    N = len(S)
    M = len(T)
    ans = "z" * N
    for i in range(N - M + 1):
        _S = S[i:i + M]
        is_ok = True
        for j in range(M):
            if _S[j] == "?":
                pass
            elif _S[j] == T[j]:
                pass
            else:
                is_ok = False
        if is_ok:
            candidate = S[:i] + T + S[i + M:]
            candidate = candidate.replace("?", "a")
            if candidate < ans:
                ans = candidate

    if ans == "z" * N:
        print("UNRESTORABLE")
    else:
        print(ans)


if __name__ == "__main__":
    main()

Solution (Python):
S=input()
ls=len(S)
T=input()
lt=len(T)
ans="z"*51
for i in range(ls-lt+1):
  s=S[i:i+lt]
  hamaru=True
  now="z"*51
  for j in range(lt):
    if s[j]!="?" and s[j]!=T[j]:
      hamaru=False
  
  if hamaru:
    now=""
    for k in range(ls):
      if k in list(range(i,i+lt)):
        now+=T[k-i]
      elif S[k]=="?":
        now+="a"
      else:
        now+=S[k]
  ans=min(ans,now)
if ans=="z"*51:
  ans="UNRESTORABLE"
print(ans)

Solution (Python):
def check(s, t):
    flag = True
    for i in range(len(s)):
        if s[i] != t[i] and s[i] != "?":
            flag = False
    return flag


S = str(input())
T = str(input())

ans = ""
for i in reversed(range(len(S)-len(T)+1)):
    
    if check(S[i:i+len(T)], T):
        num = 0
        while num != len(S):
            if num == i:
                ans += T
                num += len(T)
            else:
                if S[num] == "?":
                    ans += "a"
                else:
                    ans += S[num]
                num += 1
        break

if ans == "":
    print("UNRESTORABLE")
else:
    print(ans)

Solution (Python):
s = input()
t = input()
lenS = len(s)
lenT = len(t)

if lenS < lenT:
    print("UNRESTORABLE")
    exit()

ans = []
for i in range(lenS - lenT + 1):
    tmp = list(s)
    flag = True
    for j in range(lenS):
        if j < i or i + lenT <= j:
            if tmp[j] == '?':
                tmp[j] = 'a'
        else:
            if tmp[j] == '?':
                tmp[j] = t[j - i]
            elif tmp[j] != t[j - i]:
                flag = False
                break

    if flag:
        ans.append("".join(tmp))

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

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

ans = []
if len(s)>=len(t):    
    for i in range(len(s)-len(t)+1):
        cnt=0
        tmp=list(s)
        for j in range(len(t)):
            if s[i+j]!=t[j] and s[i+j]!='?':
                break
            else:
                cnt+=1
                tmp[i+j]=t[j]
        if cnt==len(t):
            tmp="".join(tmp)
            ans.append(tmp.replace('?','a'))
ans = sorted(ans)
if not ans:
    print('UNRESTORABLE')
else:
    print(ans[0])

Solution (Python):
s = input()
t = input()
rs = list(reversed(s))
rt = list(reversed(t))
for i in range(len(s)-len(t)+1):
         for j in range(len(t)):
                  if not (rs[i+j] == "?" or rs[i+j] == rt[j]):
                           break
         else:
                  for k in range(len(t)):
                           rs[i+k] = rt[k]
                  for l in range(len(s)):
                           if rs[l] == "?":
                                    rs[l] = "a"
                  ans = list(reversed(rs))
                  answer = "".join(ans)
                  print(answer)
                  exit()
print("UNRESTORABLE")

Solution (Python):
import sys
from io import StringIO
import unittest


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

    
    ans = "UNRESTORABLE"

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

        

        for j in range(len(t)):
            isRestorable = True

            if not s[j+i] == t[j] and not s[j+i] == "?":
                isRestorable = False
                break

        
        
        if isRestorable:
            ans = s[0:i] + t + s[i+len(t):len(s)]
            ans = ans.replace("?", "a")

    print(ans)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """?tc????
coder"""
        output = """atcoder"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """??p??d??
abc"""
        output = """UNRESTORABLE"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

Solution (Python):
S = input()
T = input()
S2 = S.replace('?','a')
ans = []

for i in range(len(S)-len(T)+1):
    S_sub = S[i:i+len(T)]
    
    check = True
    
    for s,t in zip(S_sub,T):
        if s != t and s == '?':
            continue
        elif s == t:
            continue
        elif s != t and s != '?':
            check = False
            break
        
    if check == True:
        tmp = S2[:i] + T + S2[i+len(T):]
        ans.append(tmp)
        
if len(ans) != 0:
    answer = sorted(ans)[0]
else:
    answer = 'UNRESTORABLE'
    
print(answer)

Solution (Python):
s=input()
t=input()
b=[]
if len(s)<len(t):
    print('UNRESTORABLE')
    exit()
for i in range(len(s)-len(t)+1):
    a=1
    c=''
    for j in range(len(t)):
        if s[i+j]=='?' or s[i+j]==t[j]:
            continue
        else:
            a=0
    if a==1:
        for j in range(i):
            c+=s[j] if s[j]!='?' else 'a'
        for j in range(len(t)):
            c+=t[j]
        for j in range(len(s)-len(t)-i):
            c+=s[j+i+len(t)] if s[j+i+len(t)]!='?' else 'a'
        b.append(c)
if len(b)==0:
    print('UNRESTORABLE')
else:
    print(min(b))

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

S.reverse()
T.reverse()
flag = False

for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[j+i] == T[j] or S[j+i] == '?':
            pass
        else:
            break

        if j == len(T)-1:
            flag = True
            for k in range(len(T)):
                if S[k+i] == '?':
                    S[k+i] = T[k]
            break
    if flag:
        break

if flag:
    for i in range(len(S)):
        if S[i] == '?':
            S[i] = 'a'
    S.reverse()
    print(''.join(S))

else:
    print('UNRESTORABLE')

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

result = []
for i in range(len(s)-len(t)+1):
    temp = '?'*i + t + '?'*(len(s)-len(t)-i)
    
    ans = ''
    flag = True
    for j in range(len(s)):
        if s[j] == '?' or s[j] == temp[j]:
            ans += temp[j]
        elif s[j] != '?' and temp[j] == '?':
            ans += s[j]
        else:
            flag = False

    if flag:
        result.append(ans.replace('?', 'a'))

if result:
    result.sort()
    print(result[0])
else:
    print("UNRESTORABLE")

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

for i in range(len(S)-len(T)+1)[::-1]:
    tmp = S[i:i+len(T)]
    flag = True

    for j in range(len(T)):
        if tmp[j]!=T[j] and tmp[j]!='?':
            flag = False
            break

    if flag:
        w = S[:i] + T + S[i+len(T):]
        w = w.replace('?', 'a')
        print(w)
        exit()

print('UNRESTORABLE')

Solution (Python):
s,t=input(),input()
ls=len(s)
lt=len(t)
ans=''
for i in range(ls-lt+1)[::-1]:
  c=0
  for j in range(lt):
    if s[i+j]==t[j] or s[i+j]=='?':
      c+=1
  if c==lt:
    ans=s[:i]+t+s[i+lt:]
    print(ans.replace('?','a'))
    break
else:
  print('UNRESTORABLE')

Solution (Python):
list_S = list(input())
list_T = list(input())
list_S.reverse()
list_T.reverse()
num = -1
for i in range(len(list_S)):
    cnt = 0
    while True:
        if cnt == len(list_T) or i + cnt == len(list_S):
            break
        if list_S[i + cnt] == "?":
            s = list_T[cnt]
        else:
            s = list_S[i + cnt]
        if list_T[cnt] != s:
             break

        cnt += 1
    if cnt == len(list_T):
        num = i
        break

if num == -1:
    ans = "UNRESTORABLE"
else:
    for j in range(cnt):
        list_S[num+j] = list_T[j]

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

Solution (Python):
S=input()
T=input()
l_S=len(S)
l_T=len(T)

def matchStr(S, T, l):
  f=False
  for i in range(l):
    if S[i] != "?" and S[i] != T[i]:
      f=True
      break
  if f:
    return False
  else:
    return True

f=False
for i in range((l_S-l_T+1)-1, -1, -1): 
  
  if matchStr(S[i:i+l_T], T, l_T):
    S=list(S)
    T=list(T)
    S[i:i+l_T] = T
    f=True
    break

if f:
  for i in range(l_S):
    if S[i]=="?":
      S[i] = "a"
  S="".join(S) 
  print(S)
else:
  print("UNRESTORABLE")

Solution (Python):
s = list(input())
t = list(input())
for i in range(len(s)-len(t)+1):
  dame = 0
  for j in range(len(t)):
    if s[len(s)-len(t)-i+j] != t[j] and s[len(s)-len(t)-i+j] != "?":
      dame = 1
      break
  if dame == 1:
    continue
  for j in range(len(t)):
      s[len(s)-len(t)-i+j] = t[j]
  for j in range(len(s)):
      if s[j] == "?":
        s[j] = "a"
  print("".join(s))
  exit()
print("UNRESTORABLE")

Solution (Python):
import re
s = input().replace('?', '.')[::-1]
t = input()[::-1]
for i in range(len(s)-len(t)+1):
  if re.match(s[i:i+len(t)], t):
    print((s[:i].replace('.','a')+t+s[i+len(t):].replace('.','a'))[::-1])
    break
else:
  print('UNRESTORABLE')

Solution (Python):
import re
s = input().replace('?', '.')
t = input()
lst = []
for i in range(len(s)-len(t)+1):
  if re.match(s[i:i+len(t)], t):
    lst.append(s[:i].replace('.','a')+t+s[i+len(t):].replace('.','a'))
if lst:
  print(min(lst))
else:
  print('UNRESTORABLE')

Solution (Python):









import re

import sys
sys.setrecursionlimit(10 ** 5 + 10)


def resolve():
    def main():
        S=str(input())
        T=str(input())

        ls=len(S)
        lt=len(T)
        if ls<lt:
            return 'UNRESTORABLE'
        else:
            ans=[]
            S=S.replace('?','.')
            for i in range(ls-lt+1):
                m=re.match(S[i:i+lt],T)
                if m is None:
                    continue
                else:
                    ans.append((S[:i]+T+S[i+lt:]).replace('.','a'))

            if not ans:
                return 'UNRESTORABLE'
            else:
    
                return min(ans)

    print(main())








resolve()

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

count = 0
n = 0
ans = []
flag = 0
n=len(s)-len(t)
while n >=0:
    count = 0
    for m in range(len(t)):
        if s[n+m] == "?" or s[n+m]==t[m]:
            count += 1
        else:
            break
    if count == len(t):
        flag = 1
        break
    else:
        n -= 1

if flag == 1:
    for i in range(len(s)):
        if s[i] == "?":
            s[i] = "a"
    for i in range(m+1):
        s[n+i] =t[i]
    
    for _ in s:
        print(*_,end="")

else:
    print("UNRESTORABLE")

Solution (Python):
s=input().replace('\n', '')
t=input().replace('\n', '')
begin, end = len(s) - len(t), len(s)
ans=''
while begin>=0:
    origin = s[begin:end]
    flag=1
    
    for i in range(len(t)):
        if origin[i]!=t[i] and origin[i]!='?':
            flag=0
            break
    if flag:
        ans = s[:begin]+t+s[end:]
        break
    begin-=1
    end-=1
print("UNRESTORABLE" if not len(ans) else ans.replace('?', 'a'))

Solution (Python):
Sp = input()
T = input()
S = []
for i in range(len(Sp)-len(T)+1):
	for j in range(len(T)):
		if Sp[i+j] not in ("?",T[j]):
			break
	else:
		tmp = Sp[:i] + T + Sp[i+len(T):]
		S.append(tmp.replace("?","a"))

print(min(S) if S else "UNRESTORABLE")

Solution (Python):
from copy import deepcopy


def calc_key_str(aps_S, T):
    S = deepcopy(aps_S)

    for i in range(len(aps_S) - len(T) + 1):
        matched_flag = True
        for j in range(len(T)):
            if aps_S[-i-j-1] != T[-j-1] and aps_S[-i-j-1] != '?':
                matched_flag = False
                continue

        if matched_flag:
            S_list = list(S)
            S_list[-i-len(T):len(S)-i] = T
            S = "".join(S_list)
            S = S.replace('?', 'a')
            print(S)
            break

    if not matched_flag:
        print('UNRESTORABLE')


def main():
    aps_S = input()
    T = input()

    if len(aps_S) < len(T):
        print('UNRESTORABLE')
    else:
        calc_key_str(aps_S, T)


if __name__ == '__main__':
    main()

Solution (Python):
import re
s, t = input().replace('?', '.'), input()
l, m = len(s), len(t)

if l < m:
    print("UNRESTORABLE")
    exit()

can = []  
for i in range(l - m + 1):
    if re.match(s[i:i + m], t):
        can.append((s[:i] + t + s[i + m:]).replace('.', 'a'))
print(min(can) if can else "UNRESTORABLE")

Solution (Python):
import sys

s = input()
t = input()

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

if tl > sl :
  print('UNRESTORABLE')
  sys.exit()

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

if c == 1 :
  print('UNRESTORABLE')
else : 
  print(s.replace('?', 'a'))

Solution (Python):
import sys

s = input()
t = input()

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

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

if c == 1 :
  print('UNRESTORABLE')
else : 
  print(s.replace('?', 'a'))

Solution (Python):
from copy import deepcopy
s = list(input())
t = list(input())
lens = len(s)
lent = len(t)
ans = deepcopy(s)
for i in range(len(s)):
  if s[i] == "?":
    ans[i] = "a"
def match(moji):
  for i in range(lent):
    if moji[i] != t[i] and moji[i] != "?":
      return False
  return True
for i in range(lent, lens+1):
  ns = s[lens-i:lens-i+lent]
  if match(ns):
    ans[lens-i:lens-i+lent] = t
    print("".join(ans))
    exit()
print("UNRESTORABLE")

Solution (Python):
import sys
from io import StringIO
import unittest

def resolve():
    S = input()
    T = input()

    S = list(S[::-1])
    T = list(T[::-1])

    flag = 0
    for i in range(0, len(S) - len(T) + 1):
        
        cnt = 0
        for j in range(len(T)):
            if S[i + j] == T[j] or S[i + j] == '?':
                cnt += 1

        if cnt == len(T):
            for j in range(len(T)):
                S[i + j] = T[j]
            flag = 1
            break

    if flag == 0:
        print('UNRESTORABLE')
        exit(0)

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

    S.reverse()
    print(''.join(S))


class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """?tc????
coder"""
        output = """atcoder"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """??p??d??
abc"""
        output = """UNRESTORABLE"""
        self.assertIO(input, output)

if __name__ == "__main__":
    
    resolve()

Solution (Python):
import re

s = input().replace('?', '.')
t = input()

if len(t)>len(s):
  print('UNRESTORABLE')
elif len(t)==len(s):
  if re.match(s, t):
    print(t)
  else:
    print('UNRESTORABLE')
else:
  for i in range(len(s)-len(t)+1):
    check_str = s[len(s)-len(t)-i:len(s)-i]
    if re.match(check_str, t):
      break

  if i==len(s)-len(t):
    print('UNRESTORABLE')
  else:
    ans = s[:len(s)-len(t)-i] + t + s[len(s)-i:]
    ans = ans.replace('.', 'a')
    print(ans)

Solution (Python):
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

s = input()
t = input()
ans = []
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:
        memo = s[:i] + t + s[i + len(t):]
        ans.append(memo.replace('?', 'a'))
if ans:
    print(min(ans))
    exit()
print('UNRESTORABLE')

Solution (Python):
import sys
S = input()
T = input()

ans = ''
if T in S:
    for i in range(len(S)):
        if S[i] == '?':
            ans += 'a'
        else:
            ans += S[i]
    print(ans)
    sys.exit()

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

if ok_flag:
    ans = ''
    for i in range(len(S)):
        if i == s_p:
            for j in range(len(T)):
                ans += T[j]
        elif i in list(range(s_p+1,s_p+len(T))):
            continue
        elif S[i] == '?':
            ans += 'a'
        else:
            ans += S[i]
    
    print(ans)
else:
    print('UNRESTORABLE')

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

sl = len(s)
tl = len(t)
cnt = 0
ans = []
while(cnt + tl <= sl):
  tmp = 0
  for i in range(tl):
    if((s[cnt+i] == t[i]) or s[cnt+i] == '?'):
      tmp += 1
  if(tmp == tl):
    
    ans = list(s)
    ans[cnt:cnt+tl] = t
    
  cnt+=1
if(len(ans) == 0):
  print("UNRESTORABLE")
  exit()
  
for i in range(sl):
  if(ans[i] == '?'):
    ans[i] = 'a'
print("".join(ans))

Solution (Python):
import sys

s = input()
t = input()
lenS = len(s)
lenT = len(t)
ans =""
for i in range(lenS-lenT,-1,-1):
  sub = s[i:i+lenT]
  for j in range(lenT):
    if sub[j]!=t[j] and sub[j]!="?":
      break
  else:  
    ans = s[:i]+t+s[i+lenT:]
    ans = ans.replace("?","a")
    print(ans)
    sys.exit()
  continue
print("UNRESTORABLE")

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

flag = False
start = None
for i in range(len(S) - len(T) + 1):
    flag2 = True
    for j in range(len(T)):
        if S[i + j] == "?" or S[i + j] == T[j]:
            continue
        else:
            flag2 = False

    if flag2:
        flag = True
        start = i

if flag:
    for i in range(len(S)):
        if i < start or start + len(T) <= i:
            if S[i] == "?":
                print("a", end="")
            else:
                print(S[i], end="")
        else:
            print(T[i - start], end="")
else:
    print("UNRESTORABLE")

Solution (Python):


















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

for i in reversed(range(len(s)-len(t)+1)):
    flag = False
    for j in range(len(t)):
        if j==(len(t)-1):
            if s[i+j]=="?":
                flag = True
            elif s[i+j]==t[j]:
                flag = True
            else:
                flag = False
        elif s[i+j]=="?":
            pass
        elif s[i+j]==t[j]:
            pass
        else:
            flag = False
            break
    if flag:
        break
    else:
        continue

if flag:
    pass
else:
    print("UNRESTORABLE")
    exit()

ans = list(s)

for l in range(len(t)):
    ans[i+l] = t[l]

ans2 = "".join(ans)


ans3 = ans2.replace("?","a")
print(ans3)