spoj-SEQAGAIN (easy sequence) why I am getting SIGSEGV error for this problem?

The link to my code is http://ideone.com/JJgmcG

you are getting SIGSEGV due to too much function calls , which exceeds stack memory

try memorization .