My solution of problem K