Runtime Error(SIGSEGV) in Kisses and Hugs problem

this is url to my submission-- http://www.codechef.com/viewsolution/4581967 I have tried al possible debugging i could have. It may be because of More memory consuming but i have no idea how to do it more efficiently thn it.

//