ZhenlongDai/ACPR huggingface dataset:
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def main():
    Sd = input()
    T = input()

    indexes = [i for i, x in enumerate(Sd) if x == T[0]][::-1]
    s = list(Sd)
    for i in indexes:
        for j in range(len(T)):
            if i + len(T) <= len(Sd):
                if s[i+j] == T[j] or s[i+j] == '?':
                    s[i+j] = T[j]
                    continue
            s = list(Sd)
            break
        else:
            ans = ''.join(s)
            ans = ans.replace('?', 'a')
            print(ans)
            exit()

    print('UNRESTORABLE')

main()


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

Expected output:
d>>>a`aq


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
def main():
    Sd = input()
    T = input()

    i1 = [i for i, x in enumerate(Sd) if x == T[0]]
    i2 = [i for i, x in enumerate(Sd) if x == '?']
    indexes = (i1 + i2)[::-1]
    s = list(Sd)
    for i in indexes:
        for j in range(len(T)):
            if i + len(T) <= len(Sd):
                if s[i+j] == T[j] or s[i+j] == '?':
                    s[i+j] = T[j]
                    continue
            s = list(Sd)
            break
        else:
            ans = ''.join(s)
            ans = ans.replace('?', 'a')
            print(ans)
            exit()

    print('UNRESTORABLE')

main()

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]
            print(sp)
            
        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:
??d??p??
b`_

Expected output:
UNRESTORABLE


Actual output:
aadaapaa


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_t = len(T)
G = []

for i in range(len(S)-len_t+1):
  valid = True
  onlyQ = True
  for j in range(len_t):
    if S[i+j] != "?" and S[i+j] != T[j]:
      valid = False
    if S[i+j] == T[j]:
      onlyQ = False

  if valid and not onlyQ:
    SL = list(S)
    for j in range(len_t):
      SL[i+j] = T[j]
    SL = list(map(lambda x: "a" if x == "?" else x, SL))
    G.append("".join(SL))

print(min(G, default="UNRESTORABLE"))

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

Expected output:
d>>>aaaq


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):

S = input()
T = input()

len_t = len(T)
G = []

for i in range(len(S)-len_t+1):
  valid = True
  
  for j in range(len_t):
    if S[i+j] != "?" and S[i+j] != T[j]:
      valid = False

  if valid:
    SL = list(S)
    for j in range(len_t):
      SL[i+j] = T[j]
    G.append("".join(SL).replace("?", "a"))

print(min(G, default="UNRESTORABLE"))

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import sys
s = list(input())
t = list(input())
ss = "".join(s)
tt = "".join(t)
ls = []
if len(tt)>len(ss):
    print("UNRESTORABLE")
    sys.exit()
for i in range(len(ss)-len(tt)+1):
    l = s[i:i+len(tt)]
    print(l)
    for j in range(len(tt)):
        if l[j] != t[j] and l[j] != "?":
            break
        else:
            l[j] = t[j]
    else:
        l = "".join(l)
        l = "".join(s[:i]) + l + "".join(s[i+len(tt):])
        l = l.replace("?","a")
        ls.append(l)
if ls == []:
    print("UNRESTORABLE")
else:
    ls.sort()
    print(ls[0])
            
    
            


Failing test case input:
??p??d??
b`_

Expected output:
UNRESTORABLE


Actual output:
['?', '?', 'p']
['?', 'p', '?']
['p', '?', '?']
['?', '?', 'd']
['?', 'd', '?']
['d', '?', '?']
UNRESTORABLE


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

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

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

Expected output:
d>>>a`aq


Actual output:
d>>>a`a


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

last = -1
for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if S[i+j] is T[j] or S[i+j] is '?':
            if j == len(T)-1:
                last = i
        else:
            break
if last != -1:
    S = S[:last] + T + S[last+len(T):]
    S = S.replace('?', 'a')
    print(S)
    exit()

print('UNRESTORABLE')

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

n=len(s)-len(t)+1
ok=0



for i in range(n):
    count=0

    for j in range(len(t)):
        if t[j]==s[n-i-1+j] or s[n-i-1+j]=="?":
            count=count+1

    if count==len(t):

        ok=1
        break

if t in s:
    print(s.replace("?","a"))


elif ok==1:
    ans0=s[0:n-i-1]+t
    ans1=ans0.replace("?","a")

    for i in range(len(s)-len(ans1)):
        ans1=ans1+"a"
    print(ans1)
else:
    print("UNRESTORABLE")



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

Expected output:
d>>>aaaq


Actual output:
d>>>aaaa


Fixed submission (verdict: Accepted):
s=input()
t=input()
ans="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
n=len(s)-len(t)+1
ok=0



i_set=[]

for i in range(n):
    count=0

    for j in range(len(t)):
        if t[j]==s[n-i-1+j] or s[n-i-1+j]=="?":
            count=count+1

    if count==len(t):

        ok=1

        i_set.append(i)



if ok==1:
    for i in i_set:

        ans0=s[0:n-i-1]+t+s[n-i-1+len(t):]

        ans1=ans0.replace("?","a")


        if ans>ans1:
            ans=ans1

    print(ans)
else:
    print("UNRESTORABLE")
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def check(a, b):
    for i, j in zip(a, b):
        if i == "?" or i == j:
            pass
        else:
            return False
    return True


def make(a):
    x = ""
    for i in a:
        if i == "?":
            x += "a"
        else:
            x += i
    return x


s = list(input())
t = list(input())
n = len(t)
ans = []
for i in range(len(s)-n+1):
    if check(s[i:n+i], t):
        w = s[:i] + t + s[n+i:]
        ans.append(make(w))

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



Failing test case input:
@tc??@?
endcr

Expected output:
UNRESTORABLE


Actual output:
UNRETSORABLE


Fixed submission (verdict: Accepted):
def check(a, b):
    for i, j in zip(a, b):
        if i == "?" or i == j:
            pass
        else:
            return False
    return True


def make(a):
    x = ""
    for i in a:
        if i == "?":
            x += "a"
        else:
            x += i
    return x


s = list(input())
t = list(input())
n = len(t)
ans = []
for i in range(len(s)-n+1):
    if check(s[i:n+i], t):
        w = s[:i] + t + s[n+i:]
        ans.append(make(w))

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

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=list(input())
t=list(input())
sl=len(s)
tl=len(t)
cnt=0
k=60
for i in range(sl-tl+1):
    for j in range(tl):
        if s[i]==t[j]:
            k=i
if k==60:
    print("UNRESTORABLE")
    exit()
for i in range(tl):
    if t[i]!=s[i+k] and s[i+k]!="?":
        cnt+=1
if cnt!=0:
    print("UNRESTORABLE")
    exit()
for i in range(tl):
    s[i+k]=t[i]
for i in range(sl):
    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())
sl=len(s)
tl=len(t)
for k in range(sl-tl,-1,-1):
    judge=True
    for i in range(tl):
        if s[i+k]==t[i] or s[i+k]=="?":
            pass
        else:
            judge=False
            break
    if judge:
        for i in range(tl):
            s[i+k]=t[i]
        for i in range(sl):
            if s[i]=="?":
                s[i]="a"
        print("".join(s))
        exit()
print("UNRESTORABLE")
Problem: p03565
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
S = list(input())
T = list(input())
N = len(S)
M = len(T)
l = []
flag = 0
exist = 0
for i in range(N-M+1):
    flag = 0
    for j in range(M):
        if T[j] != S[i+j] and S[i+j] != "?":
            flag += 1

    if flag == 0:
        tmp = S
        for k in range(M):
            tmp[i+k] = T[k]
        l.append(tmp)
        exist = 1

if exist == 1: 
    L = len(l)
    for i in range(L):
        for j in range(N):
            if S[j] == "?":
                S[j] = "a"
    l.sort()
    print(l[0])
else:
    print("UNRESTORABLE")

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

Expected output:
d>>>aaaq


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

Fixed submission (verdict: Accepted):
from copy import copy
S = list(input())
T = list(input())
N = len(S)
M = len(T)
l = []
flag = 0
exist = 0
for i in range(N-M+1):
    flag = 0
    for j in range(M):
        if T[j] != S[i+j] and S[i+j] != "?":
            flag += 1

    if flag == 0:
        tmp = copy(S)
        for k in range(M):
            tmp[i+k] = T[k]
        l.append(tmp)
        exist = 1

a = []
if exist == 1: 
    L = len(l)
    for i in range(L):
        tmp = copy(l[i])
        for j in range(N):
            if tmp[j] == "?":
                tmp[j] = "a"
        a.append(tmp)
    a.sort()
    ans = "".join(a[0])
    print(ans)
else:
    print("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
  
  
  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
aaa

Expected output:
d>>>aaaq


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

ans_list = []
if t in s:
    print(s.replace('?', 'a'))
else:
    for i in range(0 , len(s) - len(t)+1)[::-1]:
        flag = True
        for j in range(len(t)):
            if s[i+j] == t[j] or s[j] == '?':
                continue
            else:
                flag = False
                break
        if flag ==  True:
            tmp = s
            tmp = tmp.replace(tmp[i : i+len(t)] , t)
            ans_list.append(tmp.replace('?', 'a'))
    if len(ans_list) == 0:
        print('UNRESTORABLE')
    else:
        ans_list.sort()
        print(ans_list[0])

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

Expected output:
d>>>a`aq


Actual output:
UNRESTORABLE


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

ans_list = []
if t in s:
    print(s.replace('?', 'a'))
else:
    for i in range(0 , len(s) - len(t)+1):
        flag = True
        for j in range(i , i + len(t)):
            if s[j] == t[j - i] or s[j] == '?':
                continue
            else:
                flag = False
                break
        if flag ==  True:
            tmp = s
            tmp = tmp[:i] + t + tmp[i + len(t):]
            ans_list.append(tmp.replace('?', 'a'))
    if len(ans_list) == 0:
        print('UNRESTORABLE')
    else:
        ans_list.sort()
        print(ans_list[0])

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

ans1 = "z"*len(S)
pos = ""
num = 0
for i in range(len(S)-len(T)+1):
    sl = ""
    sl = S[i:(i+len(T))]
    for j in range(len(T)):
        pos = ""
        if(sl[j] == T[j]):
            if(sl.count("?") >= len(T)-1):
                pos += S[:i]+T+S[(i+len(T)):]
                pos = pos[::-1]
                Flg = True
                if(pos < ans1):
                    ans1 = pos
if(Flg == True):
    ans1 = ans1.replace("?", "a") 
    print(ans1)
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()
Flg = False

ans1 = "z"*len(S)
pos = ""
num = 0
for i in range(len(S)-len(T)+1):
    sl = ""
    sl = S[i:(i+len(T))]
    for j in range(len(T)):
        pos = ""
        if(sl[j] != "?" and sl[j] != T[j]):
            break
    else:
        pos += S[:i]+T+S[(i+len(T)):]
        if(ans1 > pos):
            ans1 = pos
            Flg = True
                
if(Flg == True):
    ans1 = ans1.replace("?", "a") 
    print(ans1)
else:
    print("UNRESTORABLE")
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
S = input()
T = input()

l = len(T)

ind = 51
for i in range(len(S)-l+1):
    flag = 0
    for j in range(l):
        if S[i+j]!='?' and S[i+j]!=T[j]:
            flag = 1
    if flag==0:
        ind = i

if ind == 51:
    print('UNRESTORABLE')
    exit()

print(S[:i].replace('?','a')+T+S[i+j:].replace('?','a'))

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

Expected output:
atcoder

Actual output:
atcodera


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

l = len(T)

ind = 51
for i in range(len(S)-l+1):
    flag = 0
    for j in range(l):
        if S[i+j]!='?' and S[i+j]!=T[j]:
            flag = 1
    if flag==0:
        ind = i

if ind == 51:
    print('UNRESTORABLE')
    exit()

print(S[:ind].replace('?','a')+T+S[ind+l:].replace('?','a'))

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

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

    if len(S) < len(T):
        return "UNRESTORABLE"

    rs = S.replace("?","a")

    candidate = None

    for i in range(len(S)-len(T)+1):
        ts = S[i:i+len(T)]
        
        is_mismatched = False
        for ii in range(len(T)):
            if not (ts[ii] == "?" or ts[ii] == T[ii]):
                is_mismatched = True
                break
        if not is_mismatched:
            candidate = rs[:i] + T + rs[i+len(T):(len(S)-(i+len(T)))]
           
    return candidate if candidate else "UNRESTORABLE"

if __name__ == '__main__':
    print(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()

    rs = S.replace("?","a")

    candidate = None

    for i in range(len(S)-len(T)+1):
        ts = S[i:i+len(T)]
        
        is_mismatched = False
        for ii in range(len(T)):
            if ts[ii] != "?" and ts[ii] != T[ii]:
                is_mismatched = True
                break
        if not is_mismatched:
            candidate = rs[:i] + T + rs[i+len(T):]
           
    return candidate if candidate else "UNRESTORABLE"

if __name__ == '__main__':
    print(main())

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

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


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

Expected output:
atcoder

Actual output:
?t coder 
atcoder


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

ans = []
for i in range(len(S) - len(T) + 1):
    c = ""
    for j in range(len(T)):
        if S[i+j] != "?" and S[i+j] != T[j]:
            break
        c += T[j]
    if len(c) == len(T):
        ans.append((S[:i] + c + S[i+len(T):]).replace("?", "a"))
print(min(ans) if ans else "UNRESTORABLE")
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s2 = input()
t = input()
c1=1
c2=0
c3=0

for i in range(len(s2)-len(t)+1):
    if s2[i]==t[0]:
        for j in range(1,len(t)):
            if s2[i+j]==t[j] or s2[i+j]=='?':
                c1+=1
        if c1 == len(t):
            c2=1
            c3=i
        c1=1
if c2==1:
    s=list(s2)
    for i in range(len(t)):
        s[c3+i]=t[i]
    for i in range(len(s2)):
        if s[i]=='?':
            s[i]='a'
    print("".join(s))
else:
    print('UNRESTORABLE')

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

Expected output:
d>>>aaaq


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
s2 = input()
t = input()
c1=1
c2=0
c3=0

for i in range(len(s2)-len(t)+1):
    if s2[i]==t[0] or s2[i]=='?':
        for j in range(1,len(t)):
            if s2[i+j]==t[j] or s2[i+j]=='?':
                c1+=1
        if c1 == len(t):
            c2=1
            c3=i
        c1=1
if c2==1:
    s=list(s2)
    for i in range(len(t)):
        s[c3+i]=t[i]
    for i in range(len(s2)):
        if s[i]=='?':
            s[i]='a'
    print("".join(s))
else:
    print('UNRESTORABLE')

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def check(i):
    for j in range(len(T)):
        if T[j] == S[i+j] or S[i+j] == "?":
            continue
        return False
    return True


def okikae(i):
    for j in range(len(T)):
        S[i+j] = T[j]
    return

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

flag = False
for i in range(len(S)-len(T)+1):
    if check(i) is True:
        flag = True
        last = i

if flag is False:
    print("UNRESTORABLE")
    exit()

okikae(i)

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:
d>>>aaaa


Fixed submission (verdict: Accepted):
def check(i):
    for j in range(len(T)):
        if T[j] == S[i+j] or S[i+j] == "?":
            continue
        return False
    return True


def okikae(i):
    for j in range(len(T)):
        S[i+j] = T[j]
    return

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

for i in reversed(range(len(S)-len(T)+1)):
    if check(i) is True:
        last = i
        break
else:
    print("UNRESTORABLE")
    exit()

okikae(last)

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

Problem: p03565
Buggy submission (PyPy3 (7.3.0), verdict: Wrong Answer):
import re
S,T=open(0)
S=S.replace('?','.')
s=len(S)
t=len(T)
for i in range(s-t,-1,-1):
 if re.match(S[i:i+t],T):print((S[:i]+T+S[i+t:]).replace('.','a'));exit()
print('UNRESTORABLE')


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

Expected output:
d>>>aaaq


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
import re
S,T=open(0)
S=S.replace('?','.')
T=T[:-1]
s=len(S)
t=len(T)
for i in range(s-t,-1,-1):
 if re.match(S[i:i+t],T):print((S[:i]+T+S[i+t:]).replace('.','a'));exit()
print('UNRESTORABLE')
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
t = input()

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

ns = len(s)
nt = len(t)
for i in range(0, ns-nt+1):
   x = s[i:i+nt]
   ok = 1
   for j in range(nt):
      if (t[j] != x[j] and x[j] != '?'):
         ok = 0
         break

   if (ok == 1):
      ss = s[0:i] + t
      if (i+nt < ns):
         ss = ss + s[i+nt]
      ss = ss.replace('?', 'a')
      exit()

print('UNRESTORABLE')


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

Expected output:
d>>>aaaq


Actual output:

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

ns = len(s)
nt = len(t)

for i in range(ns-nt, -1, -1):
   x = s[i:i+nt]
   for j in range(nt+1):
      if (j == nt):
         ss = s[:i] + t + s[i+nt:]
         print(ss.replace('?', 'a'))
         exit()

      if (x[j] == '?'):
         continue
      elif (x[j] != t[j]):
         break

print('UNRESTORABLE')

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=[x for x in input()]
t=[x for x in input()]
ans=[]
for i in range(len(s)):
  cnt=0
  nowi=i
  fi=i
  for j in range(len(t)):
    if s[nowi]==t[j] or s[nowi]=="?":
      cnt+=1
    else:
      break
    if cnt==len(t):
      ans.append((s[:fi]+t+s[nowi+1:]))
    if nowi+1<=len(s)-1:
      nowi+=1
    else:
      break

A=[]
if len(ans)==0:
  print("UNRESTORABLE")
else:   
  for i in ans:
    moji=""
    for m in i:
      if m=="?":
        moji+="a"
      else:
        moji+=m
    A.append(moji)
  print(A)
  A.sort()
  print(A[0])

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

Expected output:
atcoder

Actual output:
['atcoder']
atcoder


Fixed submission (verdict: Accepted):
s=[x for x in input()]
t=[x for x in input()]
ans=[]
for i in range(len(s)):
  cnt=0
  nowi=i
  fi=i
  for j in range(len(t)):
    if s[nowi]==t[j] or s[nowi]=="?":
      cnt+=1
    else:
      break
    if cnt==len(t):
      ans.append((s[:fi]+t+s[nowi+1:]))
    if nowi+1<=len(s)-1:
      nowi+=1
    else:
      break

A=[]
if len(ans)==0:
  print("UNRESTORABLE")
else:   
  for i in ans:
    moji=""
    for m in i:
      if m=="?":
        moji+="a"
      else:
        moji+=m
    A.append(moji)
  A.sort()
  print(A[0])
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
def match(x,y):
    if x==y or y=='?':
        return 1
    else:
        return 0
S=input()
T=input()
S=S[::-1]
T=T[::-1]

count=0
for j in range(0,len(S)-len(T)+1):
    for i in range(len(T)):
        if match(T[i],S[i+j]):
            count+=1
        else:
            count=0
            break
    if count==len(T):
        for k in range(len(T)):
            S=S.replace(S[k+j],T[k],1)
        S=S.replace('?','a')
        print(S[::-1])
        exit()
    else:
        count=0
print('UNRESTRABLE')

Failing test case input:
@???ct?
qndce

Expected output:
UNRESTORABLE


Actual output:
UNRESTRABLE


Fixed submission (verdict: Accepted):
def match(x,y):
    if x==y or y=='?':
        return 1
    else:
        return 0
S=input()
T=input()
U=""

candidate=[]
count=0

for i in range(len(S)-len(T)+1):
    for j in range(len(T)):
        if match(T[j],S[i+j]):
            count+=1
        else:
            count=0
            break
    if count==len(T):
        count=0
        U=S[:i]+T+S[i+len(T):]
        U=U.replace('?','a')
        candidate.append(U)
        
if len(candidate)==0:
    print('UNRESTORABLE')
else:
    
    print(sorted(candidate)[0])

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

S = input()
T = input()

t = len(T)
answers = []

if len(T) > len(S):
  print("UNRESTORABLE")
  sys.exit()

for index, s in enumerate(S):
  if index + t > len(S):
    break

  if s != '?' and s != T[0]:
    continue

  for a in range(1, t):
    if S[index+a] != '?' and S[index+a] != T[a]:
      break

  else:
    ans = S[0:index] + T + S[index+t:-1]
    answers.append(ans.replace('?', 'a'))
    
if len(answers) == 0:
  print("UNRESTORABLE")
else:
  answers.sort()  
  print(answers[0])

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

n=len(s)-len(t)+1
ok=0



for i in range(n):
    count=0

    for j in range(len(t)):
        if t[j]==s[n-i-1+j] or s[n-i-1+j]=="?":
            count=count+1

    if count==len(t):

        ok=1
        break

if ok==1:
    ans0=s[0:n-i-1]+t
    ans1=ans0.replace("?","a")
    print(ans1)
else:
    print("UNRESTORABLE")



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

Expected output:
>q_bada>


Actual output:
>q_ba


Fixed submission (verdict: Accepted):
s=input()
t=input()
ans="zzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzzz"
n=len(s)-len(t)+1
ok=0



i_set=[]

for i in range(n):
    count=0

    for j in range(len(t)):
        if t[j]==s[n-i-1+j] or s[n-i-1+j]=="?":
            count=count+1

    if count==len(t):

        ok=1

        i_set.append(i)



if ok==1:
    for i in i_set:

        ans0=s[0:n-i-1]+t+s[n-i-1+len(t):]

        ans1=ans0.replace("?","a")


        if ans>ans1:
            ans=ans1

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

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
sd=input()
t=input()
lsd=len(sd)
lt=len(t)
ans='UNRESTRABLE'
for i in range(lsd-lt,-1,-1):
    for j in range(lt):
        if sd[i+j]!='?' and sd[i+j]!=t[j]:
            break
    else:
            ans=(sd[:i]+t+sd[i+lt:]).replace('?','a')
            break
print(ans)

Failing test case input:
?tc???@
qndce

Expected output:
UNRESTORABLE


Actual output:
UNRESTRABLE


Fixed submission (verdict: Accepted):
sd=input()
t=input()
lsd=len(sd)
lt=len(t)
for i in range(lsd-lt,-1,-1):
    for j in range(lt):
        if sd[i+j]!='?' and sd[i+j]!=t[j]:
            break
    else:
            print((sd[:i]+t+sd[i+lt:]).replace('?','a'))
            break
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, n - m + 1, -1):
        tmp = s[i - m : i]
        if re.fullmatch(tmp, t):
            s = re.sub(tmp, t, s)
            ans = 1
            break

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


if __name__ == "__main__":
    main()

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

Expected output:
d>>>a`aq


Actual output:
a`aa`aaq


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 (Python (3.4.3), verdict: Wrong Answer):
s = list(input())
t = list(input())

l = []

for i in range(len(s)-len(t) - 1):
    f = False
    for j in range(len(t)):
        if s[i+j] != '?' and s[i+j] != t[j]:
            f = False
            break
    if f:
        a = s[:i] + t + s[i+len(t):]
        l.append(a.replace('?','a'))
if len(l)>0:
    print(min(l))
else:
    print('UNRESTORABLE')

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

Expected output:
d>>>a`aq


Actual output:
UNRESTORABLE


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

l = []

for i in range(len(s)-len(t) + 1):
    f = True
    for j in range(len(t)):
        if s[i+j] != '?' and s[i+j] != t[j]:
            f = False
            break
    if f:
        a = s[:i] + t + s[i+len(t):]
        l.append(a.replace('?','a'))
if len(l)>0:
    print(min(l))
else:
    print('UNRESTORABLE')

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:
    C = []
    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')
            C.append(S)
    if len(C) > 0:
        S = sorted(C)[0]
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()

x = "UNRESTORABLE"

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


if sl < tl:
    print(x)
    exit()

flag =0

for i in range(sl-tl,-1,-1):
    temp = s[i:i+tl]
    print(temp)
    for j in range(tl):
        if temp[j] == t[j] or temp[j] =="?":
            if j == tl-1:
                x = s[:i] + t + s[i+tl:]
                flag = 1
                break            
        else:
            break

    if flag ==1:
        break

x = x.replace("?","a")

print(x)

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

Expected output:
UNRESTORABLE


Actual output:
d??
?d?
??d
p??
?p?
??p
UNRESTORABLE


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

x = "UNRESTORABLE"

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


if sl < tl:
    print(x)
    exit()

flag =0

for i in range(sl-tl,-1,-1):
    temp = s[i:i+tl]
    for j in range(tl):
        if temp[j] == t[j] or temp[j] =="?":
            if j == tl-1:
                x = s[:i] + t + s[i+tl:]
                flag = 1
                break            
        else:
            break

    if flag ==1:
        break

x = x.replace("?","a")

print(x)

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


S = input().strip()
T = input().strip()


i=0
ans=""
flag = False
while i < len(S):

    if S[i] == T[0] and  (len(S) - i) >= len(T):
        for j,word_t in enumerate(T):
            if word_t == S[i+j] or S[i+j] == "?":
                continue
            else:
                ans += S[i]
                i += 1 
                break
        
        else:
            ans += T
            flag = True
            i += (j+1)
    
    else:
        ans += S[i]
        i += 1
    

if flag:
    ans = ans.replace('?','a')
    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 = input().strip()
T = input().strip()

S=S[::-1]
T=T[::-1]

i=0
ans=""
flag = False
while i < len(S):

    if ( S[i] == T[0] or S[i] == "?" )  and  (len(S) - i) >= len(T):
        for j,word_t in enumerate(T):
            if word_t == S[i+j] or S[i+j] == "?":
                continue
            else:
                ans += S[i]
                i += 1 
                break
        
        else:
            ans += T + S[i+j+1:]
            flag = True
            break
            
            i = len(S)
    
    else:
        ans += S[i]
        i += 1
    
ans=ans[::-1]

if flag:
    ans = ans.replace('?','a')
    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)):
    if T[0] != S[i]:
        continue

    if i == len(S)-1:
        continue

    S_ = S[i+1:i+len(T)]
    if len(set(S_)) == 1 and '?' in S_ and len(S_) == len(T)-1:
        S = S[:i] + T
        S = S.replace("?", "a")
        print(S)
        break
else:
    print("UNRESTORABLE")


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

Expected output:
>q_bada>


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
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:
        tmp = S[:i] + T + S[i+len(T):]
        ans.append(tmp.replace('?', 'a'))
if ans:
    print(ans[-1])
else:
    print("UNRESTORABLE")

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

ok = -1
for i in range(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 = i
            break

if ok > -1:
    for i in range(len(S)):
        if S[i] == "?":
            S[i] = "a"
    res = S[:ok] + T + S[i + len(T):]
    print("".join(res))
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):
S = input()
T = input()
res = []

ok = -1
for i in range(len(S) - len(T) + 1):
    if S[i] == T[0] or S[i] == "?":
        for j in range(len(T)):
            if S[i + j] not in ("?", T[j]):
                break
        else:
            s = S[:i] + T + S[i + len(T):]
            res.append(s.replace("?", "a"))

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

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

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

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

Expected output:
>q_bada>


Actual output:
>q_bad?>


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

flg = 0
y = s[::-1]
z = t[::-1]
result = []
for j,x in enumerate(range(0,len(y))):
    result = []
    for i,k in enumerate(y[x:x+len(t)]):
        if (k == z[i])|(k=="?"):
            result.append(True)
    if all(result)&(len(result)==len(t)):
        flg = 1
        break
if flg == 1:
    print((s[:len(s)-j-len(t)]+t+s[len(s)-j:]).replace("?","a"))
else:
    print("UNRESTORABLE")
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s = input()
t = input()
s_long = len(s)
t_long = len(t)
ok = []
for i in range(s_long - t_long+1):
  part_s = s[i:i+t_long]
  check = True
  for j in range(t_long):
    if part_s[j] != "?" and part_s[j] != t[j]:
      check = False
  if check == True:
    ok.append(i)
  
if len(ok) == 0:
  print("UNRESTORABLE")
else:
  a = max(ok)
  s = s[:a] + t + s[a + t_long + 1:]
  s = list(s)
  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:
d>>>aaa


Fixed submission (verdict: Accepted):
s = input()
s = list(s)
t = input()
ok_num = []
for i in range(len(s) - len(t) + 1):
  check = True
  s_part = s[i:i+len(t)]
  for j in range(len(t)):
    if s_part[j] != "?" and s_part[j] != t[j]:
      check = False
  if check == True:
    ok_num.append(i)  
if len(ok_num) == 0:
  print("UNRESTORABLE")
else:
  for i in range(len(t)):
    s[max(ok_num) + i] = t[i]
  for  j in range(len(s)):
    if s[j] == "?":
      s[j] = "a"
      
  print("".join(s))

Problem: p03565
Buggy submission (Python (3.8.2), verdict: Wrong Answer):
sd = input()
t = input()
oks = []
if len(sd) < len(t):
    print("UNRESTORABLE")
else:
    for i in range(len(sd)-len(t)+1):
        
        sdd = sd[i:i+len(t)]
        f = True
        for j,sddj in enumerate(sdd):
            if sddj == "?":
                continue
            elif sddj != t[j]:
                f = False
                break
        if f:
            oks.append(i)
    if oks:
        k = oks[-1]
        print((sd[:k]+t).replace("?","a"))
    else:
        print("UNRESTORABLE")


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

Expected output:
>q_bada>


Actual output:
>q_ba


Fixed submission (verdict: Accepted):
sd = input()
t = input()
oks = []
if len(sd) < len(t):
    print("UNRESTORABLE")
else:
    for i in range(len(sd)-len(t)+1):
        sdd = sd[i:i+len(t)]
        f = True
        for j,sddj in enumerate(sdd):
            if sddj == "?":
                continue
            elif sddj != t[j]:
                f = False
                break
        if f:
            oks.append(i)
    if oks:
        k = oks[-1]
        print((sd[:k]+t+sd[k+len(t):]).replace("?","a"))
    else:
        print("UNRESTORABLE")
Problem: p03565
Buggy submission (PyPy3 (2.4.0), verdict: Wrong Answer):
S = input()
T = input()

LEN_S = len(S)
LEN_T = len(T)

if LEN_S < LEN_T:
  print('UNRESTORABLE')
  exit()

def isEquals(s):
  for i in range(LEN_T):
    if T[i] == s[i] or s[i] == '?':
      pass
    else:
      return False
  return True

answers = []
for i in range(LEN_S - LEN_T+1):
  if isEquals(S[i:i+LEN_T]):
    text = S[:i] + T + S[i+LEN_T+1:]
    answers.append(text.replace('?', 'a'))
  else:
    pass

if 0 < len(answers):
  answers.sort()
  print(answers[0])
else:
  print('UNRESTORABLE')

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

Expected output:
d>>>aaaq


Actual output:
d>>>aaa


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

LEN_S = len(S)
LEN_T = len(T)

if LEN_S < LEN_T:
  print('UNRESTORABLE')
  exit()

def isEquals(s):
  for i in range(LEN_T):
    if T[i] == s[i] or s[i] == '?':
      pass
    else:
      return False
  return True

answers = []
for i in range(LEN_S - LEN_T+1):
  if isEquals(S[i:i+LEN_T]):
    text = S[:i].replace('?', 'a') + T + S[i+LEN_T:].replace('?', 'a')
    answers.append(text)
  else:
    pass

if 0 < len(answers):
  answers = sorted(answers)
  print(answers[0])
  
else:
  print('UNRESTORABLE')

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

s = list(input())
t = list(input())
x = 0
ans = []
gotk = False




def match(k):
  for i in range(len(t)):
    if s[i + k] != t[i] and s[i + k] != "?":
      return False
  return True

def construct(k,s):
  s = s[:k] + t
  for i in range(len(t)):
    s[i + k] = t[i]
  for i in range(len(s)):
    if s[i] == "?":
      s[i] = "a"
  return s


for i in range(len(s) - len(t),-1,-1):
  if match(i):
    x = i
    gotk = True
    break

if gotk == True:
  ans = construct(x,s)
  print("".join(ans))
else:
  print("UNRESTORABLE")

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

Expected output:
>q_bada>


Actual output:
>q_ba


Fixed submission (verdict: Accepted):

s = list(input())
t = list(input())
x = 0
ans = []
gotk = False




def match(k):
  for i in range(len(t)):
    if s[i + k] != t[i] and s[i + k] != "?":
      return False
  return True

def construct(k,s):
  for i in range(len(t)):
    s[i + k] = t[i]
  for i in range(len(s)):
    if s[i] == "?":
      s[i] = "a"
  return s


for i in range(len(s) - len(t),-1,-1):
  if match(i):
    x = i
    gotk = True
    break

if gotk == True:
  ans = construct(x,s)
  print("".join(ans))
else:
  print("UNRESTORABLE")
Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
import re

s = input()
t = input()

for i in range(len(s)-len(t), 0, -1):
    for j in  range(len(t)):
        if s[i+j] != '?' and s[i+j] != t[j]:
            break
    else:
        s = s[:i] + t
        break
else:
    print('UNRESTORABLE')
    exit()

res = s.replace('?', 'a')

print(res)


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

Expected output:
>q_bada>


Actual output:
>q_ba


Fixed submission (verdict: Accepted):
import re

s = input()
t = input()

for i in range(len(s)-len(t), -1, -1):
    for j in  range(len(t)):
        if s[i+j] != '?' and s[i+j] != t[j]:
            break
    else:
        s = s[:i] + t + s[i+len(t):]
        break
else:
    print('UNRESTORABLE')
    exit(0)

res = s.replace('?', 'a')

print(res)

Problem: p03565
Buggy submission (Python (3.4.3), verdict: Wrong Answer):
s=list(input())
t=list(input())
if len(s)<len(t):print('UNSTORABLE')
else:
	for i in range(len(s)-len(t)+1):
		for j in range(len(t)):
			if s[i+j] not in ['?',t[j]]:break
		else:
			s[i:i+len(t)]=t
			break
	else:
		print('UNSTORABLE')
print(''.join(s).replace('?','a'))

Failing test case input:
@???ct?
dbdnq

Expected output:
UNRESTORABLE


Actual output:
UNSTORABLE
@aaacta


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

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

    indexes = [i for i, x in enumerate(Sd) if x == T[0]]
    s = list(Sd)
    for i in indexes:
        for j in range(len(T)):
            if i + len(T) <= len(Sd):
                if s[i+j] == T[j] or s[i+j] == '?':
                    s[i+j] = T[j]
                    continue
            s = list(Sd)
            break
        else:
            ans = ''.join(s)
            ans = ans.replace('?', 'a')
            print(ans)
            exit()

    print('UNRESTORABLE')

main()


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

Expected output:
d>>>a`aq


Actual output:
UNRESTORABLE


Fixed submission (verdict: Accepted):
def main():
    Sd = input()
    T = input()

    i1 = [i for i, x in enumerate(Sd) if x == T[0]]
    i2 = [i for i, x in enumerate(Sd) if x == '?']
    indexes = (i1 + i2)[::-1]
    s = list(Sd)
    for i in indexes:
        for j in range(len(T)):
            if i + len(T) <= len(Sd):
                if s[i+j] == T[j] or s[i+j] == '?':
                    s[i+j] = T[j]
                    continue
            s = list(Sd)
            break
        else:
            ans = ''.join(s)
            ans = ans.replace('?', 'a')
            print(ans)
            exit()

    print('UNRESTORABLE')

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

SS.reverse()
T.reverse()

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

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

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

Expected output:
d>>>aaaq


Actual output:
UNRESTORABLE


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

SS.reverse()
T.reverse()

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

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

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:
?tc????
coder

Expected output:
atcoder

Actual output:
atcodertcaaaa


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):
s = input()
t = input()
left = 0

insert_index = -1
while True:

    flag = True

    if left + len(t) - 1 == len(s):
        break

    for a, b in zip(s[left:left+len(t)], t):
        if a != b and a != "?":
            flag = False
            break

    left += 1

    if flag:
        insert_index = max(insert_index, left)

if insert_index == -1:
    print("UNRESTORABLE")
else:
    next_word = s.replace(s[insert_index-1:insert_index+len(t)], t)
    ans = next_word.replace("?", "a")
    print(ans)


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

Expected output:
>q_bada>


Actual output:
>q_baa>


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

insert_index = -1
while True:

    flag = True

    if left + len(t) - 1 == len(s):
        break

    for a, b in zip(s[left:left+len(t)], t):
        if a != b and a != "?":
            flag = False
            break
    if flag:
        insert_index = max(insert_index, left)
    left += 1


if insert_index == -1:
    print("UNRESTORABLE")
else:
    next_word = s[:insert_index] + t + s[insert_index+len(t):]

    ans = next_word.replace("?", "a")
    print(ans)

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

lst = []
for x in range(len(S) - len_T + 1):
    flg = True
    s = S[x:len_T+x]    
    for idx in range(len_T):
        if s[idx] != '?' and s[idx] != T[idx]:
            flg = False
            break
    if flg:
        tmp = S[:x] + T + S[x + len_T:]
        print(tmp)
        tmp = tmp.replace('?', 'a')
        lst.append(tmp)


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


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

Expected output:
d>>>aaaq


Actual output:
d>>>aaaq
d>>>aaaq


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

lst = []
for x in range(len(S) - len_T + 1):
    flg = True
    s = S[x:len_T+x]    
    for idx in range(len_T):
        if s[idx] != '?' and s[idx] != T[idx]:
            flg = False
            break
    if flg:
        tmp = S[:x] + T + S[x + len_T:]
        tmp = tmp.replace('?', 'a')
        lst.append(tmp)


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