Problem p03565 (python)

Fixed submission:
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[i]!=t[i] and s[i]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    #print(0)
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    #print(0)
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    #print(0)
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[j]!=t[j] and s[j]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    #print(0)
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    #print(0)
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    print(0)
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[j]!=t[j] and s[j]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    print(0)
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    #print(0)
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[j]!=t[j] and s[j]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    print(0)
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[j]!=t[j] and s[j]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[j]!=t[j-i] and s[j]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                break
            if j==i+lt-1:
                if i==0:
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))

    if sa == []:
        print("UNRESTORABLE")
    else:
        print(min(sa))

Buggy submission (verdict: Runtime Error):
s=input()
t=input()
ls=len(s)
lt=len(t)
sa=[]

def change_to_a(sd):
    new_sd=""
    for i in range(len(sd)):
        if sd[i]=="?":
            new_sd+="a"
        else:
            new_sd+=sd[i]
    return new_sd

if lt > ls:
    print("UNRESTORABLE")
elif lt==ls:
    for i in range(ls):
        if s[j]!=t[j-i] and s[j]!="?":
            print("UNRESTORABLE")
            break
    else:
        print(t)
else:
    x=0
    for i in range(0,ls-lt+1):
        for j in range(i,i+lt):
            if s[j]!=t[j-i] and s[j]!="?":
                x=1
                break
            if j==i+lt-1:
                if i==0:
                    sa.append(t+change_to_a(s[lt:]))
                elif i==ls-lt:
                    sa.append(change_to_a(s[:ls-lt])+t)
                else:
                    sa.append(change_to_a(s[:i])+t+change_to_a(s[i+lt:]))
    if x==0:
        print(min(sa))
    else:
        print("UNRESTORABLE")