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