runtime error

ques: http://www.spoj.com/problems/AP2/
my code: http://ideone.com/PQUgIL

//