public static @NotNull List<DfaMemoryState> squash(List<DfaMemoryState> states) {
    for (int i = 1; i < states.size(); i++) {
      DfaMemoryState left = states.get(i);
      if (left == null) continue;
      for (int j = 0; j < i; j++) {
        ProgressManager.checkCanceled();
        DfaMemoryState right = states.get(j);
        if (right == null) continue;
        DfaMemoryState result = left.tryJoinExactly(right);
        if (result == left) {
          states.set(j, null);
        } else if (result == right) {
          states.set(i, null);
          break;
        } else if (result != null) {
          states.set(i, null);
          states.set(j, null);
          states.add(result);
          break;
        }
      }
    }
    states.removeIf(Objects::isNull);
    return states;
  }
public static @NotNull List<DfaMemoryState> squash(List<DfaMemoryState> states)