Calc longest common subsequence