ugly brute-force proof made nice and fast in ml monad