I am ashamed, but I can't solve this problem. I am trying to write the program on Pascal, but nothing is good.
But I must solve it on this two weeks, because I get this task in my university.
Help me... maybe you have the code of this task on Pascal or C++, please, mail me - utter@yandex.ru