Condensed code of problem 001