solution for NinjaTurtles, SRM 567