Solution of the test task from Engine6 (engine6.com)