My task solution an acm.timus.ru written on python