Rust gives me TLE with a lot of used heap memory (1.5G), so I guess this is another SPOJ problem with broken input. And breaking main loop after reaching EOF gives me AC. So maybe your Haskell and C++ solutions a little bit different in parsing input.