runtime error sigsegv plz help

why is it giving sigsegv runtime error??
ques. link : http://www.spoj.com/problems/ANARC08F/
solution link : http://ideone.com/fdTmvJ

It might be because of invalid memory reference or segmentation fault. Probably you are accessing some illegal memory location.

Can u tell me exactly where is the code going wrong as i m unable to identify it??