LAYERS practice problem

what is wrong with my code? it runs fine on entering manual input but shows wrong answer on submitting it.
https://www.codechef.com/viewsolution/27921114