Can somebody help me with this ?

PORBLEM- https://www.codechef.com/problems/CHEFSQ
SOLUTION- https://ide.geeksforgeeks.org/QkklWIXrH1
Somebody please tell where i went wrong .