Problem p03150 (python)

Fixed submission:
S=list(input())
if "k" and "e" and "y" and "e" and "n" and "c" and "e" in S:
    if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e" and S[-5]=="y" and S[-6]=="e" and S[-7]=="k":
        print("YES")
    else:
        if S[0]=="k":
            if S[1]=="e":
                if S[2]=="y":
                    if S[3]=="e":
                        if S[4]=="n":
                            if S[5]=="c":
                                if S[6]=="e":
                                    print("YES")
                                else:
                                    if S[-1]=="e":
                                        print("YES")
                                    else:
                                        print("NO")
                            else:
                                if S[-1]=="e" and S[-2]=="c":
                                    print("YES")
                                else:
                                    print("NO")
                        else:
                            if S[-1]=="e" and S[-2]=="c" and S[-3]=="n":
                                print("YES")
                            else:
                                print("NO")
                    else:
                        if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e":
                            print("YES")
                        else:
                            print("NO")
                else:
                    if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e" and S[-5]=="y":
                        print("YES")
                    else:
                        print("NO")
            else:
                if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e" and S[-5]=="y" and S[-6]=="e":
                    print("YES")
                else:
                    print("NO")
        else:
            print("NO")
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
S=list(input())
if "k" and "e" and "y" and "e" and "n" and "c" and "e" in S:
    for i in range(len(S)):
        if S[i]=="k":
            if S[i+1]=="e":
                if S[i+2]=="y":
                    if S[i+3]=="e":
                        if S[i+4]=="n":
                            if S[i+5]=="c":
                                if S[i+6]=="e":
                                    print("YES")
                                    break
                                else:
                                    if S[-1]=="e":
                                        print("YES")
                                        break
                                    else:
                                        print("No")
                                        break
                            else:
                                if S[-1]=="e" and S[-2]=="c":
                                    print("YES")
                                    break
                                else:
                                    for j in range(len(S)-i-5):
                                        if S[i+5+j]=="c":
                                            if S[i+5+j+1]=="e":
                                                if i+5+j+2==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                                    break
                                            else:
                                                print("NO")
                                                break
                        else:
                            if S[-1]=="e" and S[-2]=="c" and S[-3]=="n":
                                print("YES")
                                break
                            else:
                                for j in range(len(S)-i-4):
                                        if S[i+4+j]=="n":
                                            if S[i+4+j+1]=="c":
                                                if S[i+4+j+2]=="e":
                                                    if i+4+j+3==len(S):
                                                        print("YES")
                                                        break
                                                    else:
                                                        print("NO")
                                                        break
                                                else:
                                                    print("NO")
                                                    break
                                            else:
                                                print("NO")
                                                break
                    else:
                        if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e":
                            print("YES")
                            break
                        else:
                            for j in range(len(S)-i-3):
                                if S[i+3+j]=="e":
                                    if S[i+3+j+1]=="n":
                                        if S[i+3+j+2]=="c":
                                            if S[i+3+j+3]=="e":
                                                if i+3+j+4==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                                    break
                                            else:
                                                print("NO")
                                                break
                                        else:
                                            print("NO")
                                            break
                                    else:
                                        print("NO")
                                        break
                else:
                    if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e" and S[-5]=="y":
                            print("YES")
                            break
                    else:
                        for j in range(len(S)-i-2):
                            if S[i+2+j]=="y":
                                if S[i+2+j+1]=="e":
                                    if S[i+2+j+2]=="n":
                                        if S[i+2+j+3]=="c":
                                            if S[i+2+j+4]=="e":
                                                if i+2+j+5==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                                    break
                                            else:
                                                print("NO")
                                                break
                                        else:
                                            print("NO")
                                            break
                                    else:
                                        print("NO")
                                        break
                                else:
                                    print("NO")
                                    break
            else:
                if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e" and S[-5]=="y" and S[-6]=="e":
                    print("YES")
                    break
                else:
                    for j in range(len(S)-i-1):
                        if S[i+1+j]=="e":
                            if S[i+1+j+1]=="y":
                                if S[i+1+j+2]=="e":
                                    if S[i+1+j+3]=="n":
                                        if S[i+1+j+4]=="c":
                                            if S[i+1+j+5]=="e":
                                                if i+1+j+6==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                                    break
                                            else:
                                                print("NO")
                                                break
                                        else:
                                            print("NO")
                                            break
                                    else:
                                        print("NO")
                                        break
                                else:
                                    print("NO")
                                    break
                            else:
                                print("NO")
                                break
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
S=[*input()]
if "k" and "e" and "y" and "e" and "n" and "c" and "e" in S:
    for i in range(len(S)):
        if S[i]=="k":
            if S[i+1]=="e":
                if S[i+2]=="y":
                    if S[i+3]=="e":
                        if S[i+4]=="n":
                            if S[i+5]=="c":
                                if S[i+6]=="e":
                                    print("YES")
                                    break
                                else:
                                    if S[-1]=="e":
                                        print("YES")
                                        break
                                    else:
                                        print("No")
                                        break
                            else:
                                if S[-1]=="e" and S[-2]=="c":
                                    print("YES")
                                    break
                                else:
                                    for j in range(len(S)-i-5):
                                        if S[i+5+j]=="c":
                                            if S[i+5+j+1]=="e":
                                                if i+5+j+2==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                                    break
                                            else:
                                                print("NO")
                                                break
                        else:
                            if S[-1]=="e" and S[-2]=="c" and S[-3]=="n":
                                print("YES")
                                break
                            else:
                                for j in range(len(S)-i-4):
                                        if S[i+4+j]=="n":
                                            if S[i+4+j+1]=="c":
                                                if S[i+4+j+2]=="e":
                                                    if i+4+j+3==len(S):
                                                        print("YES")
                                                        break
                                                    else:
                                                        print("NO")
                                                        break
                                                else:
                                                    print("NO")
                                                    break
                                            else:
                                                print("NO")
                                                break
                    else:
                        if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e":
                            print("YES")
                            break
                        else:
                            for j in range(len(S)-i-3):
                                if S[i+3+j]=="e":
                                    if S[i+3+j+1]=="n":
                                        if S[i+3+j+2]=="c":
                                            if S[i+3+j+3]=="e":
                                                if i+3+j+4==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                                    break
                                            else:
                                                print("NO")
                                                break
                                        else:
                                            print("NO")
                                            break
                                    else:
                                        print("NO")
                                        break
                else:
                    if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e" and S[-5]=="y":
                            print("YES")
                            break
                    else:
                        for j in range(len(S)-i-2):
                            if S[i+2+j]=="y":
                                if S[i+2+j+1]=="e":
                                    if S[i+2+j+2]=="n":
                                        if S[i+2+j+3]=="c":
                                            if S[i+2+j+4]=="e":
                                                if i+2+j+5==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                                    break
                                            else:
                                                print("NO")
                                                break
                                        else:
                                            print("NO")
                                            break
                                    else:
                                        print("NO")
                                        break
                                else:
                                    print("NO")
                                    break
            else:
                if S[-1]=="e" and S[-2]=="c" and S[-3]=="n" and S[-4]=="e" and S[-5]=="y" and S[-6]=="e":
                    print("YES")
                    break
                else:
                    for j in range(len(S)-i-1):
                        if S[i+1+j]=="e":
                            if S[i+1+j+1]=="y":
                                if S[i+1+j+2]=="e":
                                    if S[i+1+j+3]=="n":
                                        if S[i+1+j+4]=="c":
                                            if S[i+1+j+5]=="e":
                                                if i+1+j+6==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                                    break
                                            else:
                                                print("NO")
                                                break
                                        else:
                                            print("NO")
                                            break
                                    else:
                                        print("NO")
                                        break
                                else:
                                    print("NO")
                                    break
                            else:
                                print("NO")
                                break
else:
    print("NO")

Buggy submission (verdict: Runtime Error):
S=list(input())
if "k" and "e" and "y" and "e" and "n" and "c" and "e" in S:
    for i in range(len(S)):
        if S[i]=="k":
            if S[i+1]=="e":
                if S[i+2]=="y":
                    if S[i+3]=="e":
                        if S[i+4]=="n":
                            if S[i+5]=="c":
                                print("YES")
                                break
                            else:
                                for j in range(len(S)-i-5):
                                    if S[i+5+j]=="c":
                                        if S[i+5+j+1]=="e":
                                            if i+5+j+2==len(S):
                                                print("YES")
                                                break
                                            else:
                                                print("NO")
                                        else:
                                            print("NO")
                        else:
                            for j in range(len(S)-i-4):
                                    if S[i+4+j]=="n":
                                        if S[i+4+j+1]=="c":
                                            if S[i+4+j+2]=="e":
                                                if i+4+j+3==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                            else:
                                                print("NO")
                                        else:
                                            print("NO")
                    else:
                        for j in range(len(S)-i-3):
                            if S[i+3+j]=="e":
                                if S[i+3+j+1]=="n":
                                    if S[i+3+j+2]=="c":
                                        if S[i+3+j+3]=="e":
                                            if i+3+j+4==len(S):
                                                print("YES")
                                                break
                                            else:
                                                print("NO")
                                        else:
                                            print("NO")
                                    else:
                                        print("NO")
                                else:
                                    print("NO")
                else:
                    for j in range(len(S)-i-2):
                        if S[i+2+j]=="y":
                            if S[i+2+j+1]=="e":
                                if S[i+2+j+2]=="n":
                                    if S[i+2+j+3]=="c":
                                        if S[i+2+j+4]=="e":
                                            if i+2+j+5==len(S):
                                                print("YES")
                                                break
                                            else:
                                                print("NO")
                                        else:
                                            print("NO")
                                    else:
                                        print("NO")
                                else:
                                    print("NO")
                            else:
                                print("NO")
            else:
                    for j in range(len(S)-i-1):
                        if S[i+1+j]=="e":
                            if S[i+1+j+1]=="y":
                                if S[i+1+j+2]=="e":
                                    if S[i+1+j+3]=="n":
                                        if S[i+1+j+4]=="c":
                                            if S[i+1+j+5]=="e":
                                                if i+1+j+6==len(S):
                                                    print("YES")
                                                    break
                                                else:
                                                    print("NO")
                                            else:
                                                print("NO")
                                        else:
                                            print("NO")
                                    else:
                                        print("NO")
                                else:
                                    print("NO")
                            else:
                                print("NO")
else:
    print("NO")