Topcoder Stitch - nice solution