Chef and way

Link for question https://www.codechef.com/problems/CHRL4/

Link for my code https://www.codechef.com/viewplaintext/35501739

Please verify my code
I got wrong answer