rewrite lcs code iteratively instead of recuresively, complete MGAP