Increasing Decreasing Sequence

I have coded successfully in CPP, but getting run error in python. How to solve in python?