static LS greedySplitIntoWordsCI(S s, Cl words) { TreeSet wordsSet = asCISet(words); int i = 0, last = 0; new LS out; while (i < l(s)) { S word = longestPrefixInCISet(substring(s, i), wordsSet); if (nempty(word)) { addIfNempty(out, substring(s, last, i)); out.add(substring(s, i, i+l(word)); last = i = i+l(word); } else ++i; } addIfNempty(out, substring(s, last, i)); ret out; }