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
This and all the analogous changes below are just removing the redundant variables `X`, `Y` from the call.