Answer to MontreHack question