Problem p03565 (python)

Fixed submission:
# coding: utf-8
# Your code here!

words= list(input())
target = list(input())
i=len(words)-len(target)
flag=False
while(0<=i):
    flag = True
    for j in range(len(target)):
        if not(words[i+j] == target[j] or words[i+j] == '?'):
            flag = False
            break
    if flag is True:
        words[i:i+len(target)] = target
        for k,word in enumerate(words):
            if word == '?':
                words[k]='a'
        break
    i-=1

if flag is True:
    print(''.join(words))
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

words= list(input())
target = list(input())
for i in reversed(range(len(words)-len(target)+1)):
    # print(words[i],i)
    flag = True
    for j in range(len(target)):
        if not(words[i+j] == target[j] or words[i+j] == '?'):
            flag = False
            break
    if flag is True:
        words[i:i+len(target)] = target
        for k,word in enumerate(words):
            if word == '?':
                words[k]='a'
        break

if flag is True:
    print(''.join(words))
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

words= list(input())
target = list(input())
for i in reversed(range(len(words)-len(target)+1)):
    # print(words[i])
    flag = True
    for j in range(len(target)):
        if not(words[i+j] == target[j] or words[i+j] == '?'):
            flag = False
            break
    if flag is True:
        if i==0:
            words[len(words)-len(target)+1:]=target
        else:
            words[i:i+len(target)] = target
        for k,word in enumerate(words):
            if word == '?':
                words[k]='a'
        break

if flag is True:
    print(''.join(words))
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

words= list(input())
target = list(input())
i=len(words)-len(target)
for i in reversed(range(len(words)-len(target)+1)):
    # print(words[i])
    flag = True
    for j in range(len(target)):
        if not(words[i+j] == target[j] or words[i+j] == '?'):
            flag = False
            break
    if flag is True:
        words[i:i+len(target)] = target
        for k,word in enumerate(words):
            if word == '?':
                words[k]='a'
        break

if flag is True:
    print(''.join(words))
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

words= list(input())
target = list(input())
i=len(words)-len(target)
while(0<=i):
    flag = True
    for j in range(len(target)):
        if not(words[i+j] == target[j] or words[i+j] == '?'):
            flag = False
            break
    if flag is True:
        words[i:i+len(target)] = target
        for k,word in enumerate(words):
            if word == '?':
                words[k]='a'
        break
    i-=1

if flag is True:
    print(''.join(words))
else:
    print("UNRESTORABLE")

Buggy submission (verdict: Runtime Error):
# coding: utf-8
# Your code here!

words= list(input())
target = list(input())
i=len(words)-len(target)
while(0<=i):
    flag = True
    for j in range(len(target)):
        if not(words[i+j] == target[j] or words[i+j] == '?'):
            flag = False
    if flag is True:
        words[i:i+len(target)] = target
        for i,word in enumerate(words):
            if word == '?':
                words[i]='a'
        break
    i-=1

if flag is True:
    print(''.join(words))
else:
    print("UNRESTORABLE")