Simplify the solution of Teaching problem