ZhenlongDai/ACPR huggingface dataset:
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
sp = list(input())
t = list(input())
if len(sp)-len(t)>=0:
    for i in range(len(sp)-len(t)+1):
        for j in range(len(t)):
            if t[j] != sp[i+j] and sp[i+j] != "?":
                break
        else:
            for j in range(len(t)):
                sp[i+j] = t[j]

            
        continue
    for i in range(len(sp)):
        if sp[i] =="?":
            sp[i] = "a"
    print("".join(map(str, sp)))
else:
    print("UNRESORABLE")

Failing test case input:
s@@?bA?
dbcnq

Expected output:
UNRESTORABLE


Actual output:
s@@abAa


Fixed submission (verdict: Accepted):
sp = list(input())
t = list(input())
boo = False
if len(sp)-len(t)>=0:
    for i in reversed(range(len(sp)-len(t)+1)):
        for j in reversed(range(len(t))):
            if t[j] != sp[i+j] and sp[i+j] != "?":
                break
        else:
            for j in reversed(range(len(t))):
                sp[i+j] = t[j]
            
            boo = True
            break
        continue
    if boo:
        for i in range(len(sp)):
            if sp[i] =="?":
                sp[i] = "a"
    
        print("".join(map(str, sp)))
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


S_ = input()    
T = input()     


len_S_ = len(S_)
len_T = len(T)

for i in reversed(range(len_S_)):
    S = ''

    if i + len_T <= len_S_:
        S = S_[:i] + T + S_[i + len_T:]

        
        for j in range(len(S)):
            if S[j] != S_[j] or S_[j] != '?':
                break

            if S[j] == '?':
                S = S[:j] + 'a' + S[j + 1:]

            if S.find('?') == -1 and len(S) != 0:
                print(S)
                exit()
        else:
            continue
    else:
        continue
        
print('UNRESTORABLE')

Failing test case input:
?@b?@@s
rncbe

Expected output:
UNRESTORABLE


Actual output:
a@rncbe


Fixed submission (verdict: Accepted):


S_ = input()    
T = input()     


len_S_ = len(S_)
len_T = len(T)

S_list = []

for i in reversed(range(len_S_)):
    is_target = True
    S = ''

    if i + len_T <= len_S_:
        S = S_[:i] + T + S_[i + len_T:]

        
        for j in range(len(S)):
            if S[j] != S_[j] and S_[j] != '?':
                is_target = False
                break

            if S[j] == '?':
                S = S[:j] + 'a' + S[j + 1:]

        if is_target:
            S_list.append(S)

    else:
        continue
        
if len(S_list) > 0:
    print(min(S_list))
else:
    print('UNRESTORABLE')
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = str(input())
T = str(input())


def Find(S, T):
    ans = ''
    for i in range(0, len(S)-len(T)+1):
        s = S[i:i+len(T)]
        for j in range(len(s)):
            if not (s[j] != '?' and T[j] == s[j]):
                break
            ans = S[:i] + T + S[i+len(T):]
    return ans


ans = Find(S, T)

if ans:
    ans = list(ans)
    for i, v in enumerate(ans):
        if v == '?':
            ans[i] = 'a'
    ans = ''.join(ans)
    print(ans)
else:
    print('UNRESTORABLE')

Failing test case input:
d>>>???q
a`a

Expected output:
d>>>a`aq


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
S = str(input())
T = str(input())


def Find(S, T):
    ans = ''
    for i in range(0, len(S)-len(T)+1):
        s = S[i:i+len(T)]
        boolen = 1
        for j in range(len(s)):
            if not(s[j] == '?' or T[j] == s[j]):
                boolen *= 0
        if boolen == 1:
            ans = S[:i] + T + S[i+len(T):]
    return ans


ans = Find(S, T)

if ans:
    ans = list(ans)
    for i, v in enumerate(ans):
        if v == '?':
            ans[i] = 'a'
    ans = ''.join(ans)
    print(ans)
else:
    print('UNRESTORABLE')

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S=list(input())
T=list(input())



flag = False

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


if flag==False:
    print("".join(S).replace("?","a"))

Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
import copy

S=list(input())
T=list(input())



flag = False

for i in range(len(S)+1-len(T)):
    if S[i]==T[0] or S[i]=="?":
        
        for j in range(len(T)):
            if S[i+j]==T[j] or S[i+j]=="?":
                continue
            else:
                
                break
        else:
            result=copy.copy(S)
            for j in range(len(T)):
                flag=True
                result[i+j]=T[j]
                


if flag==True:
    print("".join(result).replace("?","a"))
else:
    print("UNRESTORABLE")
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import re


def solve(s, t):
    s = s.replace('?', '.')
    ls, lt = len(s), len(t)
    if ls < lt:
        return 'UNRESTORABLE'
    ans = []
    for i in range(ls - lt + 1):
        m = re.match(s[i:i + ls], t)
        if m is None:
            continue
        ans.append((s[:i] + t + s[i + ls:]).replace('.', 'a'))
    if not ans:
        return 'UNRESTORABLE'
    return min(ans)


s = input().strip()
t = input().strip()

print(solve(s, t))


Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
import re


def solve(s, t):
    s = s.replace('?', '.')
    ls, lt = len(s), len(t)
    if ls < lt:
        return 'UNRESTORABLE'
    ans = []
    for i in range(ls - lt + 1):
        m = re.match(s[i:i + lt], t)
        if m is None:
            continue
        ans.append((s[:i] + t + s[i + lt:]).replace('.', 'a'))
    if not ans:
        return 'UNRESTORABLE'
    return min(ans)


s = input().strip()
t = input().strip()

print(solve(s, t))

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S2 = input()
T = input()

N = len(S2)


def check(S, T):
    for i in range(len(S)):
        if S[i] != '?' and S[i] != T[i]:
            return False
    return True


S = 'UNRESTORABLE'
if len(T) <= N:
    for i in range(N - len(T) + 1):
        j = i + len(T)
        if S2[i] == T[0] and check(S2[i:j], T):
            S = list(S2)
            S[i:j] = list(T)
            S = ''.join(S).replace('?', 'a')
print(S)

Failing test case input:
d>>>???q
a`a

Expected output:
d>>>a`aq


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
S2 = input()
T = input()

N = len(S2)


def check(S, T):
    for i in range(len(S)):
        if S[i] == '?' or S[i] == T[i]:
            continue
        else:
            return False
    return True


S = 'UNRESTORABLE'
if len(T) <= N:
    C = []
    for i in range(N - len(T) + 1):
        j = i + len(T)
        if (S2[i] == T[0] or S2[i] == '?') and check(S2[i:j], T):
            S = list(S2)
            S[i:j] = list(T)
            S = ''.join(S).replace('?', 'a')
            C.append(S)
    if len(C) > 0:
        S = sorted(C)[0]
print(S)
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
T = input()
answer = ''
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        
        if T[j] == S[j+i] or S[j+i] == '?':
            if j == len(T)-1:
                
                
                answer = S[0:i] + T 
            continue
        else:
            break

if len(answer):
    print(answer.replace('?', 'a'))
else:
    print('UNRESTORABLE')

Failing test case input:
d>>>???q
a`a

Expected output:
d>>>a`aq


Actual output:
d>>>a`a


Fixed submission (verdict: Accepted):
sd = input()
T = input()
answer = []
if len(sd) < len(T):
    print('UNRESTORABLE')
    exit(0)
for i in range(len(sd)-len(T)+1):
    s = sd
    for j in range(len(T)):
        if sd[i+j] == T[j] or sd[i+j] == '?':
           s = s[:i+j] + T[j] + s[i+j+1:]
        else:
            break 
    else:
        answer.append(s.replace('?', 'a'))
if len(answer) == 0:
    print('UNRESTORABLE')
else:
    print(sorted(answer)[0])

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
from itertools import permutations
import re


def main():
    s = input().replace('?', '.')
    t = input()

    for i in reversed(range(len(s) - len(t) + 1)):
        print(s[i:i + len(t)])
        if re.search(s[i:i + len(t)], t):
            result = (s[:i] + t + s[i + len(t):]).replace('.', 'a')
            print(result)
            return

    print('UNRESTORABLE ')

main()


Failing test case input:
t???c@?
dbdnq

Expected output:
UNRESTORABLE


Actual output:
..c@.
...c@
t...c
UNRESTORABLE 


Fixed submission (verdict: Accepted):
from itertools import permutations
import re


def main():
    s = input().replace('?', '.')
    t = input()

    for i in reversed(range(len(s) - len(t) + 1)):
        
        if re.search(s[i:i + len(t)], t):
            result = (s[:i] + t + s[i + len(t):]).replace('.', 'a')
            print(result)
            return

    print('UNRESTORABLE')

main()
Problem: p03565
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
S = input()
T = input()
M = len(S)
N = len(T)
for start in range(M-N,-1,-1):
    for i in range(N):
        if not (S[start+i] == '?' or S[start+i] == T[i]):
            break
    else:
        end = start + N
        pre = ''
        post = ''
        for i in range(start):
            if S[i] == '?':
                pre += 'a'
            else:
                pre += S[i]
        for i in range(end,M):
            if S[i] == '?':
                post += 'a'
            else:
                pre += S[i]
        print(pre + T + post)
        exit()
else:
    print('UNRESTORABLE')


Failing test case input:
d>>>???q
a`a

Expected output:
d>>>a`aq


Actual output:
d>>>qa`a


Fixed submission (verdict: Accepted):
S = input()
T = input()
M = len(S)
N = len(T)
for start in range(M-N,-1,-1):
    for i in range(N):
        if not (S[start+i] == '?' or S[start+i] == T[i]):
            break
    else:
        end = start + N
        pre = ''
        post = ''
        for i in range(start):
            if S[i] == '?':
                pre += 'a'
            else:
                pre += S[i]
        for i in range(end,M):
            if S[i] == '?':
                post += 'a'
            else:
                post += S[i]
        print(pre + T + post)
        exit()
else:
    print('UNRESTORABLE')

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
T = input()
ls = len(S)
lt = len(T)
a = ''
for i in range(ls):
    try:
        s = S[ls-i-lt:ls-i]
        for j in range(lt):
            if not (s[j] == T[j] or s[j] == '?'):
                break
        else:
            a += S[:ls-i-lt].replace('?', 'a') + T + S[ls-i:]
            break
    except:
        pass
print(a if a else 'UNRESTORABLE')

Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
>q_bad?>


Fixed submission (verdict: Accepted):
S = input()
T = input()
ls = len(S)
lt = len(T)
a = ''
for i in range(ls):
    try:
        s = S[ls-i-lt:ls-i]
        for j in range(lt):
            if not (s[j] == T[j] or s[j] == '?'):
                break
        else:
            a += S[:ls-i-lt].replace('?', 'a') + T + S[ls-i:].replace('?', 'a')
            break
    except:
        pass
print(a if a else 'UNRESTORABLE')
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = list(input())
T = list(input())

index = len(S)
ans = []
isMatch = True


while index - len(T) >= 0:
  obj = S[index - len(T):index]
  
  for i in range(len(obj)):
    if not obj[i] == "?" and not obj[i] == T[i]:
      isMatch = False
      break
  
  
  if isMatch:
    ans.append(S[0:index-len(T)] + T + S[index:])

  isMatch = True
  index = index - 1

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

Failing test case input:
d>>>???q
a`a

Expected output:
d>>>a`aq


Actual output:

Fixed submission (verdict: Accepted):
S = list(input())
T = list(input())

index = len(S)
ans = []
isMatch = True


while index - len(T) >= 0:
  obj = S[index - len(T):index]
  
  for i in range(len(obj)):
    if not obj[i] == "?" and not obj[i] == T[i]:
      isMatch = False
  
  
  if isMatch:
    ans.append(S[0:index-len(T)] + T + S[index:])

  isMatch = True
  index = index - 1

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

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
T = input()
res = ''
end = -1
for i in range(len(S) - len(T) + 1):
    for j in range(len(T)):
        start = i
        
        if S[i+j] == T[j]:
            end = i + j
            flag = 1
        elif S[i+j] == '?':
            end = i + j
            flag = 0
        else:
            flag = 0
            pass
            break
    if flag == 1:
        break
            
if end == -1:
    print('UNRESTORABLE')
    
else:
    j = 0
    for i in range(len(S)):
        if start <= i <= end:
            res += T[j]
            j += 1

        elif S[i] == '?':
            res += 'a'

        else:
            res += S[i]

    print(res)

Failing test case input:
>q?@?d?>
_ba

Expected output:
UNRESTORABLE


Actual output:
>qa@ada>


Fixed submission (verdict: Accepted):
S = input()
T = input()


    
if True:
    tmp = -1
    for i in range(len(S) - len(T) + 1):
        start = -1
        for j in range(len(T)):
            if S[i+j] == T[j] or S[i+j] == '?':
                start = i
            else:
                start = -1
                break
                
        
        if start != -1:
                tmp = i
    if tmp == -1:
        print('UNRESTORABLE')
    else:
        res = ''
        count = 0
        for i in range(len(S)):
            if tmp <= i < tmp + len(T):
                res += T[count]
                count += 1
            elif S[i] == '?':
                res += 'a'
            else:
                res += S[i]

        print(res)
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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_))
    

Failing test case input:
d>>>???q
aaa

Expected output:
d>>>aaaq


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
S_=list(input())
T=list(input())

res=-1
ind=-1
for i in range(len(S_)-len(T)+1):
    flag=1
    for j in range(len(T)):
        if S_[i+j]=='?' or S_[i+j]==T[j]:
            continue
        else:
            flag=0
            break
    if flag:
        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_))

Problem: p03565
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
S = input()
T = input()
ans = []

lt = len(T)
for i in range(len(S)-lt+1):
    s = S[i:i+lt]
    for t in range(lt):
        if s[t]=='?':
            pass
        else:
            if s[t]!=T[t]:
                break
            elif t==lt-1:
                ans.append((S[:i]+T+S[i+lt:]).replace('?', 'a'))
                break

print(min(ans) if len(ans)>0 else "UNRESTORABLE")

Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
S = input()
T = input()
ans = []

lt = len(T)
for i in range(len(S)-lt+1):
    s = S[i:i+lt]
    for t in range(lt):
        if s[t]=='?':
            if t != lt-1:
                pass
            else:
                ans.append((S[:i]+T+S[i+lt:]).replace('?', 'a'))
        else:
            if s[t]!=T[t]:
                break
            elif t==lt-1:
                ans.append((S[:i]+T+S[i+lt:]).replace('?', 'a'))
                break

print(min(ans) if len(ans)>0 else "UNRESTORABLE")
Problem: p03565
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
S = input()[::-1]
T = input()[::-1]
_S = S
ans = []

lt = len(T)
for i in range(len(S)-lt):
    s = S[i:i+lt]
    for t in range(lt):
        if s[t]=='?':
            pass
        else:
            if s[t]!=T[t]:
                break
            elif t==lt-1:
                ans.append((S[:i]+T+S[i+lt:]).replace('?', 'a')[::-1])
                break

print(min(ans) if len(ans)>0 else "UNRESTORABLE")

Failing test case input:
d>>>???q
aaa

Expected output:
d>>>aaaq


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
S = input()
T = input()
ans = []

lt = len(T)
for i in range(len(S)-lt+1):
    s = S[i:i+lt]
    for t in range(lt):
        if s[t]=='?':
            if t != lt-1:
                pass
            else:
                ans.append((S[:i]+T+S[i+lt:]).replace('?', 'a'))
        else:
            if s[t]!=T[t]:
                break
            elif t==lt-1:
                ans.append((S[:i]+T+S[i+lt:]).replace('?', 'a'))
                break

print(min(ans) if len(ans)>0 else "UNRESTORABLE")

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = []
s += input()
t = []
t += input()
u = -1
for i in range(len(s) - len(t) + 1):
    if u == -1:
        no = 0
        if s[i] == t[0]:
            for k in range(len(t) - 1):
                if s[i + k + 1] != t[k + 1] and s[i + k + 1] != "?":
                    no = 1
                    break
            if no == 0:
                u = i
                break
    else:
        break
if u == -1:
    print("UNRESTORABLE")
else:
    for i in range(len(s)):
        if u <= i <= u + len(t) - 1:
            s[i] = t[i-u]
        elif s[i] == "?":
            s[i] = "a"
    print("".join(s))


Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
s = []
s += input()
t = []
t += input()
u = -1
for i in range(len(s) - len(t) + 1):
    no = 0
    if s[i] == t[0] or s[i] == "?":
        for k in range(len(t) - 1):
            if s[i + k + 1] != t[k + 1] and s[i + k + 1] != "?":
                no = 1
                break
        if no == 0:
            u = i
if u == -1:
    print("UNRESTORABLE")
else:
    for i in range(len(s)):
        if u <= i <= u + len(t) - 1:
            s[i] = t[i-u]
        elif s[i] == "?":
            s[i] = "a"
    print("".join(s))
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
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")


Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
>.d...q>
ab_
6
UNRESTORABLE
UNRESTORABLE
UNRESTORABLE
...
>q_bada>


Fixed submission (verdict: Accepted):
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")

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import re
S_ = input()
T = input()

Srev = "".join(reversed(S_))
Trev = "".join(reversed(T))

pattern = "".join(["[{}?]".format(t) for t in Trev])
ans = re.sub(pattern, Trev, Srev, count=1)
ans = "".join(reversed(ans.replace("?", "a")))
if ans.count(T):
    print("".join(reversed(ans.replace("?", "a"))))
else:
    print("UNRESTORABLE")

Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
>adab_q>


Fixed submission (verdict: Accepted):
import re
S_ = input()
T = input()

Srev = "".join(reversed(S_))
Trev = "".join(reversed(T))

pattern = "".join(["[{}?]".format(t) for t in Trev])
ans = re.sub(pattern, Trev, Srev, count=1)
ans = "".join(reversed(ans.replace("?", "a")))
if ans.count(T):
    print(ans)
else:
    print("UNRESTORABLE")

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
t = input()
for i in range(len(s)-len(t),-1,-1):
	
	flg = True
	for j, k in enumerate(list(t)):
		
		if s[i:i+len(t)][j] == "?":
			continue
		if k != s[i:i+len(t)][j]:
			flg = False
			break
	if flg == True:
		x = s[:i].replace("?","a") + t + s[i+len(t):]
		print (x)
		exit()
print ("UNRESTORABLE")

Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
>q_bad?>


Fixed submission (verdict: Accepted):
s = input()
t = input()
for i in range(len(s)-len(t),-1,-1):
	
	flg = True
	for j, k in enumerate(list(t)):
		
		if s[i:i+len(t)][j] == "?":
			continue
		if k != s[i:i+len(t)][j]:
			flg = False
			break
	if flg == True:
		x = s[:i].replace("?","a") + t + s[i+len(t):].replace("?","a")
		print (x)
		exit()
print ("UNRESTORABLE")
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):


SD = input()
K = input()

ans_list = []

for i in range(len(SD) - len(K) + 1):
    flag = True
    for j in range(len(K)):
        if SD[i] != K[j] and SD[i] != '?':
            flag = False
            break
    if flag:
        tmp = SD[:i] + K + SD[len(K) + 1:]
        ans_list.append(tmp.replace('?', 'a'))

s_ans_list = sorted(ans_list)
if len(s_ans_list) == 0:
    print('UNRESTORABLE')
else:
    print(s_ans_list[0])



Failing test case input:
d>?>??>q
a`a

Expected output:
UNRESTORABLE


Actual output:
d>a>a`aaa>q


Fixed submission (verdict: Accepted):


SD = input()
K = input()

ans_list = []

for i in range(len(SD) - len(K) + 1):
    flag = True
    for j in range(len(K)):
        if SD[i + j] != K[j] and SD[i + j] != '?':
            flag = False
            break
    if flag:
        tmp = SD[:i] + K + SD[len(K) + i:]
        ans_list.append(tmp.replace('?', 'a'))


s_ans_list = sorted(ans_list)
if len(s_ans_list) == 0:
    print('UNRESTORABLE')
else:
    print(s_ans_list[0])

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

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


Failing test case input:
d>>>???q
aaa

Expected output:
d>>>aaaq


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):

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+lt], 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))

Problem: p03565
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):

s=input()
t=input()
ls=len(s)
lt=len(t)

cand=[]
for i in range(ls-lt+1):
    scut =s[i:i+lt]

    if all(tt==ss or ss=="?" for tt,ss in zip(t,scut) ):
        cand.append(i)
        
ans=[]
for c in cand:
    ans.append( (s[:i]+ t+ s[i+lt:]).replace("?","a") )

if len(ans)==0:
    print("UNRESTORABLE")
else:
    print(min(ans))
    

Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
>qaaa_ba


Fixed submission (verdict: Accepted):

s=input()
t=input()
ls=len(s)
lt=len(t)

cand=[]
for i in range(ls-lt+1):
    scut =s[i:i+lt]

    if all(tt==ss or ss=="?" for tt,ss in zip(t,scut) ):
        cand.append(i)
        
ans=[]
for c in cand:
    ans.append( (s[:c]+ t+ s[c+lt:]).replace("?","a") )

if len(ans)==0:
    print("UNRESTORABLE")
else:
    print(min(ans))
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
sp = list(input())
t = list(input())
boo = False
if len(sp)-len(t)>=0:
    for i in range(len(sp)-len(t)+1):
        for j in range(len(t)):
            if t[j] != sp[i+j] and sp[i+j] != "?":
                break
        else:
            for j in range(len(t)):
                sp[i+j] = t[j]
            print(sp)
            boo = True
            break
        continue
    if boo:
        for i in range(len(sp)):
            if sp[i] =="?":
                sp[i] = "a"
    
        print("".join(map(str, sp)))
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

Failing test case input:
?tc????
coder

Expected output:
atcoder

Actual output:
['?', 't', 'c', 'o', 'd', 'e', 'r']
atcoder


Fixed submission (verdict: Accepted):
sp = list(input())
t = list(input())
boo = False
if len(sp)-len(t)>=0:
    for i in reversed(range(len(sp)-len(t)+1)):
        for j in reversed(range(len(t))):
            if t[j] != sp[i+j] and sp[i+j] != "?":
                break
        else:
            for j in reversed(range(len(t))):
                sp[i+j] = t[j]
            
            boo = True
            break
        continue
    if boo:
        for i in range(len(sp)):
            if sp[i] =="?":
                sp[i] = "a"
    
        print("".join(map(str, sp)))
    else:
        print("UNRESTORABLE")
else:
    print("UNRESTORABLE")

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s_dash = input()
t = input()
answer = 'UNRESTORABLE'
if s_dash < t:
    pass
else:
    for i in range(len(s_dash)-len(t)+1):
        for j, k in zip(s_dash[i:i+len(t)], t):
            if j != '?' and j != k:
                break
        else:
            answer = s_dash[:i] + t + s_dash[i+len(t):]
            answer = answer.replace('?', 'a')
print(answer)


Failing test case input:
?tc????
coder

Expected output:
atcoder

Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):

s_dash = input()
t = input()
answer = 'UNRESTORABLE'
if len(s_dash) < len(t):
    pass
else:
    for i in range(len(s_dash)-len(t)+1):
        for j, k in zip(s_dash[i:i+len(t)], t):
            if j != '?' and j != k:
                break
        else:
            answer = s_dash[:i] + t + s_dash[i+len(t):]
            answer = answer.replace('?', 'a')
print(answer)

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
t = input()
s = s[::-1]
t = t[::-1]
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:
    break
else:
  print('UNSTORERABLE')
  exit(0)
s = s[:i] + t + s[i+len(t):]
s = s.replace('?','a')
s = s[::-1]
print(s)

Failing test case input:
??b@@t@
rncbg

Expected output:
UNRESTORABLE


Actual output:
UNSTORERABLE


Fixed submission (verdict: Accepted):
s = input()
t = input()
s = s[::-1]
t = t[::-1]
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:
    break
else:
  print('UNRESTORABLE')
  exit(0)
s = s[:i] + t + s[i+len(t):]
s = s.replace('?','a')
s = s[::-1]
print(s)
Problem: p03565
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
S = input()
s = len(S)
T = input()
t = len(T)

if s >= t:
    key = 0
    for i in range(s-t+1,0,-1):
        for j,k in enumerate(S[i:i+t]):
            if k == T[j] or k =="?":
                pass
            else:
                break
        else:
            key = i
            break
        key = 100
    if key == 100:
        print("UNRESTORABLE")
    else:
        ans = S[0:i]+T+S[i+t:]
        ans = ans.replace("?","a")
        print(ans)
else:
    print("UNRESTORABLE")

Failing test case input:
=?d??p??
`ba

Expected output:
UNRESTORABLE


Actual output:
=adaap`ba


Fixed submission (verdict: Accepted):
S = input()
s = len(S)
T = input()
t = len(T)

key = 0
for i in range(s-t,-1,-1):
    for j,k in enumerate(S[i:i+t]):
        if k == T[j] or k =="?":
            pass
        else:
            break
    else:
        key = i
        break
    key = 100
if key == 100 or s<t:
    print("UNRESTORABLE")
else:
    ans = S[0:i]+T+S[i+t:]
    ans = ans.replace("?","a")
    print(ans)

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S=list(input())
T=list(input())
is_con=0
for i in range(len(S)-len(T)+1):
    is_ok=1
    for j in range(i, i+len(T)):
        if S[j]!=T[j-i] and S[j]!='?':
            is_ok=0
    if is_ok:
        is_con=1
        for j in range(i, i+len(T)):
            S[j]=T[j-i]
        break
if is_con==0:
    print("UNRESTORABLE")
    exit(0)

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


Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
>, q, _, b, a, d, a, >

Fixed submission (verdict: Accepted):
S=list(input())
T=list(input())
A=[]
for i in range(len(S)-len(T)+1):
    is_ok=1
    for j in range(i, i+len(T)):
        if S[j]!=T[j-i] and S[j]!='?':
            is_ok=0
    if is_ok:
        tmp=S[:]
        is_con=1
        for j in range(i, i+len(T)):
            tmp[j]=T[j-i]
        A.append(tmp)
if len(A)==0:
    print("UNRESTORABLE")
    exit(0)
B=[]
for a in A:
    for i in range(len(a)):
        if a[i]=='?':
            a[i]='a'
    B.append(''.join(a))
B.sort()
print(B[0])
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
t = input()
ans = ""
if t in s:
    ans = s.replace("?", "a")
else:
    for i in range(len(s) - len(t) + 1):
        if s[i] in t:
            print("po")
            if all([s[i - t.index(s[i]) + j] == t[j] or s[i + j] == "?" for j in range(len(t))]):
                ans = s[:i] + t + s[i + len(t):]
                if "?" in ans:
                    ans = ans.replace("?","a")
                break

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

Failing test case input:
d>>>???q
aaa

Expected output:
d>>>aaaq


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
s = input()
t = input()
ans = ""
po = False

for i in range(len(s)-len(t)+1):
    if s[i] in [t[0],"?"]:
        if all([s[i + j] in [t[j], "?"]for j in range(len(t))]):
            if not po:
                ans = (s[:i] + t + s[i + len(t):]).replace("?","a")
                po = True
            temp = (s[:i] + t + s[i + len(t):]).replace("?","a")
            if temp < ans:
                ans = temp
            


if ans:
    print(ans.replace("?", "a"))
else:
    print("UNRESTORABLE")

Problem: p03565
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
s = input()
t = input()

n = len(s)
m = len(t)

for i in range(n-m, -1, -1):
  if s[i] == t[0]:
    if all(s[i+j] == "?" or s[i+j] == t[j] for j in range(1,m)):
      s = s[:i]+t+s[i+m:]
      print(s.replace("?", "a"))
      exit()
print("UNRESTORABLE")


Failing test case input:
d>>>???q
aaa

Expected output:
d>>>aaaq


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
s = input()
t = input()

n = len(s)
m = len(t)

for i in range(n-m, -1, -1):
  x = s[i:i+m]
  for j in range(m+1):
    if j == m:
      print((s[:i]+t+s[i+m:]).replace("?","a"))
      exit()
    if x[j] == "?": continue
    elif x[j] != t[j]: break
    
print("UNRESTORABLE")

Problem: p03565
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
S = input()
T = input()

ans = []

for index, s in enumerate(S):
  if s == '?' or s == T[0]:
    if index+len(T)-1 > len(S)-1:
        break

    for indexs, t in enumerate(T):
      if S[index+indexs] != t and S[index+indexs] != '?':
        break
    else:
      ans.append(S[0:index]+T+S[index+len(T):-1])

if len(ans) == 0:
  print("UNRESTORABLE")
else:
  ans.sort()
  print(ans[0].replace('?', 'a'))

Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
>q_bada


Fixed submission (verdict: Accepted):
S = input()
T = input()

ans = []

for index, s in enumerate(S):
  if s == '?' or s == T[0]:
    if index+len(T)-1 > len(S)-1:
        break

    for indexs, t in enumerate(T):
      if S[index+indexs] != t and S[index+indexs] != '?':
        break
    else:
      ans.append(S[0:index]+T+S[index+len(T):])


if len(ans) == 0:
  print("UNRESTORABLE")
else:
  ans.sort()
  print(ans[0].replace('?', 'a'))
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):

S_prime = str(input())
T = str(input())
ans = []

if len(S_prime) >= len(T):
    times = len(S_prime) - len(T) + 1
    for i in range(times):
        count = 0
        for j in range(len(T)):
            if S_prime[i+j] == '?':
                count = count + 1
            elif S_prime[i+j] != T[j]:
                continue
            else:
                count = count + 1
            
        if count == len(T):
            S = S_prime[:i] + T + S_prime[(i+len(T)+1):]
            S = S.replace('?', 'a')
            ans.append(S)


if len(ans) != 0:
    print(min(ans))
else:
    print('UNRESTORABLE')

Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
>q_baa>


Fixed submission (verdict: Accepted):

S_prime = str(input())
T = str(input())
ans = []

if len(S_prime) >= len(T):
    times = len(S_prime) - len(T) + 1
    for i in range(times):
        count = 0
        for j in range(len(T)):
            if S_prime[i+j] == '?':
                count = count + 1
            elif S_prime[i+j] != T[j]:
                continue
            else:
                count = count + 1
            
        if count == len(T):
            S = S_prime[:i] + T + S_prime[(i+len(T)):]
            S = S.replace('?', 'a')
            ans.append(S)


if len(ans) != 0:
    print(min(ans))
else:
    print('UNRESTORABLE')

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = list(input())
T = input()
ls = []

for i in range(len(S)-len(T)):
    for j in range(len(T)):
        if S[i+j] != T[j] and S[i+j] != "?":
            break
    else:
        ls.append(i)

if ls:
    for j in range(len(T)):
        S[ls[-1]+j] = T[j]
    print("".join(S).replace("?", "a"))
else:
    print("UNRESTORABLE") 

Failing test case input:
?tc????
coder

Expected output:
atcoder

Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
S = list(input())
T = input()
ls = []

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:
        ls.append(i)

if ls:
    for j in range(len(T)):
        S[ls[-1]+j] = T[j]
    print("".join(S).replace("?", "a"))
else:
    print("UNRESTORABLE")
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import re
import sys


def main():
    s = sys.stdin.readline().rstrip().replace("?", ".")
    t = sys.stdin.readline().rstrip()

    n = len(s)
    m = len(t)
    ans = 0

    for i in range(n - m + 1):
        tmp = s[i : i + m]
        if re.fullmatch(tmp, t):
            s = re.sub(tmp, t, s)
            ans = 1

    if ans == 1:
        print(s.replace(".", "a"))
    else:
        print("UNRESTORABLE")


if __name__ == "__main__":
    main()

Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
_ba_baa>


Fixed submission (verdict: Accepted):
import re
import sys


def main():
    s = sys.stdin.readline().rstrip().replace("?", ".")
    t = sys.stdin.readline().rstrip()

    n = len(s)
    m = len(t)
    ans = []

    for i in range(n - m + 1):
        if i == 0:
            tmp1 = ""
        else:
            tmp1 = s[:i]
        tmp2 = s[i : i + m]
        if i + m == n:
            tmp3 = ""
        else:
            tmp3 = s[i + m :]
        if re.fullmatch(tmp2, t):
            tmp2 = t
            tmp = tmp1 + tmp2 + tmp3
            ans.append(tmp)
    ans.sort()

    if ans:
        print(ans[0].replace(".", "a"))
    else:
        print("UNRESTORABLE")


if __name__ == "__main__":
    main()

Problem: p03565
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import re

S_ = input().replace('?', '.')
T = input()
flag = True
for i in range(len(S_)-len(T), 0, -1):
    angou = re.compile(S_[i:i+len(T)])
    mo = angou.search(T)
    if mo != None:
        S_ = S_[:i] + mo.group() + S_[i+len(T) + 1:]
        flag = False
S = S_.replace('.', 'a')

if flag:
    print('UNRESTORABLE')
else:
    print(S)


Failing test case input:
d>>>???q
aaa

Expected output:
d>>>aaaq


Actual output:
d>>>aaa


Fixed submission (verdict: Accepted):
import re

S_ = input().replace('?', '.')
T = input()
flag = True
for i in range(len(S_)-len(T), -1, -1):
    angou = re.compile(S_[i:i+len(T)])
    mo = angou.search(T)
    if mo != None:
        S_ = S_[:i] + mo.group() + S_[i+len(T):]
        flag = False
        break
S = S_.replace('.', 'a')

if flag:
    print('UNRESTORABLE')
else:
    print(S)
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
T = input()
N = len(T)

if len(S) < N:
    print("UNRESTORABLE")
    import sys
    sys.exit()

flag = False
pos = 51
ans = ""
for i in range(len(S)-N):
    cnt = 0
    for j in range(N):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break
    if cnt == N:
        pos = i
        flag = True
if flag:
    for i in range(len(S)):
        if pos <= i and i < pos + N:
            ans += T[i-pos]
        elif S[i] == "?":
            ans += "a"
        else:
            ans += S[i]
else:
    ans = "UNRESTORABLE"
print(ans)

Failing test case input:
?tc????
coder

Expected output:
atcoder

Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
S = input()
T = input()
N = len(T)

if len(S) < N:
    print("UNRESTORABLE")
    import sys
    sys.exit()

flag = False
pos = 51
ans = ""
for i in range(len(S)-N+1):
    cnt = 0
    for j in range(N):
        if S[i+j] == "?" or S[i+j] == T[j]:
            cnt += 1
        else:
            break
    if cnt == N:
        pos = i
        flag = True
if flag:
    for i in range(len(S)):
        if pos <= i and i < pos + N:
            ans += T[i-pos]
        elif S[i] == "?":
            ans += "a"
        else:
            ans += S[i]
else:
    ans = "UNRESTORABLE"
print(ans)

Problem: p03565
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
s=input()
n=len(s)
t=input()
m=len(t)

ANS=[]
for i in range(n-m+1):
    for j in range(m):
        
        if s[i+j] != "?" and s[i+j] != t[j]:
            break
    else:
        ans = s[:i] + t
        ans = ans.replace('?','a')
        ANS.append(ans)
if len(ANS) == 0:
    print("UNRESTORABLE")
else:
    ANS.sort()
    print(ANS[0])

Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
>q_ba


Fixed submission (verdict: Accepted):
s=input()
n=len(s)
t=input()
m=len(t)

ANS=[]
for i in range(n-m+1):
    for j in range(m):
        
        if s[i+j] != "?" and s[i+j] != t[j]:
            break
    else:
        ans = list(s)
        ans[i:i+j+1] = list(t)
        ans="".join(ans)
        ans = ans.replace('?','a')
        ANS.append(ans)
if len(ANS) == 0:
    print("UNRESTORABLE")
else:
    ANS.sort()
    print(ANS[0])
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()

tmp = False

for i in range(len(S) - len(T) + 1):
    if tmp == False:
        tmp = True
        s = i
        e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break
    if tmp == False:
        s = -1
        e = -1
    else:
        s = i
        e = i + len(T)

if s == -1:
    print(ans)

else:
    ans = S.replace('?', 'a')
    ans = ans[:s] + T + ans[s + len(T):]
    print(ans)


Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
import sys
S = input()
T = input()
ans = 'UNRESTORABLE'

if len(S) < len(T):
    print(ans)
    sys.exit()

if len(S) < len(T):
    print(ans)
    sys.exit()

tmp = True
anss = -1
anse = -1
for i in range(len(S) - len(T) + 1):
    tmp = True
    s = i
    e = i + len(T)
    for j in range(len(T)):
        if S[i + j] != '?' and\
            S[i + j] != T[j]:
            tmp = False
            break

    if tmp:
        anss = i
        anse = i + len(T)

if anss == -1:
    print(ans)

else:
    ans = S.replace('?', 'a')
    ans = ans[:anss] + T + ans[anse:]
    print(ans)

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
t = input()
ans = 'UNRESTORABLE'

for i in range(len(s) - len(t)):
    match = True
    for tt, ss in zip(t, s[len(s) - i - len(t): len(s) - i]):
        if '?' != ss and ss != tt:
            match = False
            break
    if match:
        ans = s[:i] + t + s[i + len(t):]
        ans = ans.replace('?', 'a')

print(ans)

Failing test case input:
d>>>???q
a`a

Expected output:
d>>>a`aq


Actual output:
da`aaaaq


Fixed submission (verdict: Accepted):
s = input()
t = input()
ans = 'UNRESTORABLE'

for i in range(len(s) - len(t) + 1):
    match = True
    for tt, ss in zip(t, s[len(s) - len(t) - i: len(s) - i]):
        if ss not in ('?', tt):
            match = False
            break
    if match:
        ans = s[:len(s) - len(t) - i] + t + s[len(s) - i:]
        ans = ans.replace('?', 'a')
        break

print(ans)
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s_dash = input()
t = input()

ans = []
for i in range(len(s_dash) - len(t) + 1):
    candidate = []
    for j in range(i):
        candidate.append('a' if s_dash[j] == '?' else s_dash[j])
    found = True
    for j in range(len(t)):
        if s_dash[i + j] == '?' or t[j] == s_dash[i + j]:
            candidate.append(t[j])
        else:
            found = False
            break
    if found:
        ans.append("".join(candidate))
if 0 == len(ans):
    print("UNRESTORABLE")
else:
    print(sorted(ans)[0])


Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
>q_ba


Fixed submission (verdict: Accepted):
s_dash = input()
t = input()

ans = []
for i in range(len(s_dash) - len(t) + 1):
    candidate = []
    for j in range(i):
        candidate.append('a' if s_dash[j] == '?' else s_dash[j])
    found = True
    for j in range(len(t)):
        if s_dash[i + j] == '?' or t[j] == s_dash[i + j]:
            candidate.append(t[j])
        else:
            found = False
            break
    if found:
        for j in range(len(t) + i, len(s_dash)):
            candidate.append('a' if s_dash[j] == '?' else s_dash[j])
        ans.append("".join(candidate))
if 0 == len(ans):
    print("UNRESTORABLE")
else:
    print(sorted(ans)[0])

Problem: p03565
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
import re

S_ = input().replace('?', '.')
T = input()
flag = True
for i in range(len(S_)-len(T), -1, -1):
    angou = re.compile(S_[i:i+len(T)])
    mo = angou.search(T)
    if mo != None:
        S_ = S_[:i] + mo.group() + S_[i+len(T) + 1:]
        flag = False
        break
S = S_.replace('.', 'a')

if flag:
    print('UNRESTORABLE')
else:
    print(S)


Failing test case input:
d>>>???q
aaa

Expected output:
d>>>aaaq


Actual output:
d>>>aaa


Fixed submission (verdict: Accepted):
import re

S_ = input().replace('?', '.')
T = input()
flag = True
for i in range(len(S_)-len(T), -1, -1):
    angou = re.compile(S_[i:i+len(T)])
    mo = angou.search(T)
    if mo != None:
        S_ = S_[:i] + mo.group() + S_[i+len(T):]
        flag = False
        break
S = S_.replace('.', 'a')

if flag:
    print('UNRESTORABLE')
else:
    print(S)

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = list(input())[::-1]
T = list(input())[::-1]

counter = 0
len_T = len(T)

for index, char in enumerate(S, 1):
    if char == T[counter] or char == "?":
        counter += 1
    else:
        counter = 0
    if counter == len_T:
        ans = S[:index - len_T + 1] + T + S[len_T:]
        print("".join(ans[::-1]).replace("?", "a"))
        break
else:
    print("UNRESTORABLE")


Failing test case input:
d>>>???q
aaa

Expected output:
d>>>aaaq


Actual output:
d>>>aaaaaq


Fixed submission (verdict: Accepted):
S = list(input())[::-1]
T = list(input())[::-1]


for i in range(len(S) - len(T) + 1):
    for index, char in enumerate(S[i:i + len(T)], 0):
        if char != "?" and char != T[index]:
            break
    else:
        print("".join((S[:i] + T + S[i + len(T):])[::-1]).replace("?", "a"))
        break
else:
    print("UNRESTORABLE")
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    s = input()
    t = input()
    
    
    ans = []
    for i in range(len(s)-len(t)+1):
        tmp = s[:i]
        flag = False
        for j in range(i,i+len(t)):
            if s[j]==t[j-i]:
                tmp += t[j-i]
                pass
            elif s[j]=='?':
                tmp += t[j-i]
                pass
            else:
                flag = True
                break
        if not flag:
            tmp += s[i+len(t)+2:]
            tmp = tmp.replace('?','a')
            ans.append(tmp)
    if ans:
        ans.sort()
        print(ans[0])
    else:
        print('UNRESTORABLE')

main()


Failing test case input:
d>>>???q
a`a

Expected output:
d>>>a`aq


Actual output:
d>>>a`a


Fixed submission (verdict: Accepted):
def main():
    s = input()
    t = input()
    
    
    ans = []
    for i in range(len(s)-len(t)+1):
        tmp = s[:i]
        flag = False
        for j in range(i,i+len(t)):
            if s[j]==t[j-i]:
                tmp += t[j-i]
                pass
            elif s[j]=='?':
                tmp += t[j-i]
                pass
            else:
                flag = True
                break
        if not flag:
            tmp += s[i+len(t):]
            tmp = tmp.replace('?','a')
            ans.append(tmp)
    if ans:
        ans.sort()
        print(ans[0])
    else:
        print('UNRESTORABLE')

main()

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
sp = list(input())
t = list(input())
n = len(sp)
s = ''
flag = False
for i in range(len(t), n):
    if sp[n - i] == t[0]:
        flag = True
        for j in range(1, len(t)):
            if sp[n - i + j] != t[j] and sp[n - i + j] != '?':
                flag = False
                break
    if flag:
        sp[n - i:n - i - 1 + len(t)] = t
        for j in range(n):
            if sp[j] == '?':
                s += 'a'
            else:
                s += sp[j]
        print(s)
        exit()
print('UNRESTORABLE')

Failing test case input:
>q???d?>
_ba

Expected output:
>q_bada>


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
sp = list(input())
t = list(input())
n = len(sp)
s = []
for i in range(len(t), n + 1):
    flag = True
    for j in range(len(t)):
        if sp[n - i + j] != t[j] and sp[n - i + j] != '?':
            flag = False
            break
    if flag:
        s.append('')
        ss = sp
        ss[n - i:n - i + len(t)] = t
        for j in range(n):
            if ss[j] == '?':
                s[-1] += 'a'
            else:
                s[-1] += ss[j]
if s == []:
    print('UNRESTORABLE')
else:
    s.sort()
    print(s[0])