need help in spoj TRICOUNT2 problem

wrong-answer

#1

can anybody please see why i am getting wrong answer in the spoj counting triangles II problem

link for problem:http://www.spoj.com/problems/TCOUNT2/


my solution in c http://ideone.com/gtdCUY


my solution in pascal http://ideone.com/O0kW1o



#2

The correct formula for this problem is : (n(n+2)*(2n+1))/8*