Timus Online Judge - problem №1000