Hi everybody,
We have found quite a simple decision in the page http://ua.wikimedia.org/wiki/%D0%9E%D0%B1%D0%B3%D0%BE%D0%B2%D0%BE%D1%80%D0%B...
Thanks everybody for your replies, especially interesting was Maarten's idea (though it does not work, but I believe must).
-- Andrij