LCS-like problem