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