Spoj Algorithms in Haskell