getting WA in AKBAR spoj

SPOJ question :https://www.spoj.com/problems/AKBAR/cstart=30
solution:https://ideone.com/AonT8k