SRM 596 (my first topcoder competition)