Runtime error(SIGSEGV) in HELPR2D2 spoj problem

I am getting a runtime error in [HELPR2D2 - Help R2-D2!][1]. Test cases are running fine but on submission, it produces a runtime error. Can anybody figure out what’s wrong with my


[2].

  [1]: http://www.spoj.com/problems/HELPR2D2/
  [2]: https://ideone.com/FPt6ZD