modified lcs naive implementation