lcs implementation