Changed solution after re-reading the problem