TopCoder SRM 576 div 2. AC.