fix exponential recursion in detail screen config

by memoizing `lcsMerge`. Also:

- simplify it to return the merged result rather than an internal data
  structure
- do not keep track of the whole longest submatch, just its length, for
  simplicity

fixes http://manage.dimagi.com/default.asp?125416
Oops! Good catch @millerdev! I totally meant http://en.wikipedia.org/wiki/Longest_common_subsequence_problem, which incidentally begins with the warning: "Not to be confused with longest common substring problem." Sorry to make you do that detective work (although it looks like you had some fun ;).

I'll change that to point to the right page