Спасибо=)
нашел решение
http://www.problems.ru/view_problem_details_new.php?id=55298