static MultiSet ai_allPrefixesWithWordCount_cleaned(S input) { MultiSet ms = ai_allPrefixesWithWordCount(input); new MultiSet cleaned; S last = null; for (S s : reversed(ms.highestFirst())) { int count = ms.get(s); if (count == 1) continue; if (!(startsWith(last, s) && ms.get(last) == count)) cleaned.add(s, count); last = s; } ret cleaned; }