TopCoder SRM 587