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

The link to my code is JJgmcG - Online C Compiler & Debugging Tool - Ideone.com

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

try memorization .