static L lineComp_replaceSublistWithUpdatingPairCount(L l, L x, L y, LineComp_PairCounts pairCounts) { if (x == null) ret l; int i = 0; while (true) { i = indexOfSubList(l, x, i); if (i < 0) break; int to = i+l(x), to_new = i+l(y); pairCounts.removeAll(subList(l, i-1, to+1)); replaceSublist(l, i, to, y); pairCounts.addAll(subList(l, i-1, to_new+1)); i = to_new; } ret l; }