WA on Training - INOI 2017?

Why am I getting WA on subtask 2 and 3 for Training - INOI 2017 ?
Solution - https://www.codechef.com/viewsolution/24426017