競プロでhaskell使う場合の何かアドバイスください

この問題解けませんでした
https://yukicoder.me/problems/no/583
https://yukicoder.me/submissions/212458