static MultiSet<S> ai_allPrefixesWithWordCount_cleaned(S input) {
  MultiSet<S> ms = ai_allPrefixesWithWordCount(input);
  new MultiSet<S> 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;
}