I'm getting Runtime Error in http://www.spoj.com/problems/COT2/ attributed to reading the first line of input. If I comment out time consuming operations that come AFTER reading input, then I'm able to read input without a Runtime Error. This makes me think the error is actually due to time limit exceeded, and it's not really a runtime exception.
Here's my code: http://pastebin.com/fVzaysC3
If anyone has been able to get a Java solution accepted, I would very much like to know how.