zigzag sequence topcoder dp