Solution for Kirill's test task