Failing for some testcases

https://www.codechef.com/viewsolution/30620725 MARBLE PROBLEM
https://ideone.com/8fX9lb SPP RECURSIVE

EXACT SAME QUESTIONS
BOTH SOLUTIONS GOT ACCEPTED ON CODECHEF AND SPOJ RESPECTIVELY BUT FAIL FOR TESTCASES ON HACKERBLOCKS…