Replace Pi Recursion

I am not able to process the last input .Getting the correct output for the first 2 test data.What is going wrong?

Check now

yes it works now thanks