There are some solutions of the problem on the UVaOJ