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):
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

s = list(ns().strip())
t = ns().strip()


def ok(s, t):
    if len(s) < len(t):
        return False
    for i in range(len(s) - len(t) + 1):
        o = 1
        for j in range(len(t)):
            if s[i + j] != '?' and s[i + j] != t[j]:
                o = 0
        if o == 1:
            return True
    return False


if not ok(s, t):
    print("UNRESTORABLE")
    sys.exit(0)

for i in range(len(s)):
    if s[i] == '?':
        for j in range(97,97+26):
            s[i] = chr(j)
            if ok(s, t):
                break

print("".join(s))

Solution (Python):
S = raw_input()
T = raw_input()
N = len(S)
M = len(T)
ans = '{'

for i in xrange(N-M+1):
    if all(S[i+j] == T[j] or S[i+j] == '?' for j in xrange(M)):
        tmp = list(S)
        for j in xrange(M):
            tmp[i+j] = T[j]
        tmp = ''.join(tmp)
        tmp = tmp.replace('?', 'a')
        ans = min(ans, tmp)

print ans if ans != '{' else 'UNRESTORABLE'

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

candidates = []
for i in range(len(s) - len(t) + 1):
    tfr = i
    tto = i + len(t)
    u = ''
    ok = True
    for p in range(len(s)):
        if tfr <= p < tto:
            if s[p] in ['?', t[p - i]]:
                u += t[p - i]
            else:
                ok = False
                break
        else:
            if s[p] == '?':
                u += 'a'
            else:
                u += s[p]
    if ok:
        candidates.append(u)

if candidates:
    print(min(candidates))
else:
    print("UNRESTORABLE")

Solution (Python):
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    s = S()
    sa = ''
    for c in s:
        if c == '?':
            sa += 'a'
        else:
            sa += c
    t = S()
    r = None
    l = len(t)
    for i in range(len(s)-l+1):
        f = True
        for j in range(l):
            if s[i+j] != '?' and s[i+j] != t[j]:
                f = False
                break
        if f:
            tr = sa[:i] + t + sa[i+j+1:]
            if not r or r > tr:
                r = tr

    if not r:
        return 'UNRESTORABLE'
    return r


print(main())