modified to print out longest zigzag subsequence