func (sis *SortedIntSet) decr(num int) {
	if sis.useTreeMap {
		count, ok := sis.dict[num]
		assert(ok)
		if count == 1 {
			delete(sis.dict, num)
			if len(sis.dict) == 0 {
				sis.useTreeMap = false
				sis.values = sis.values[:0]  
				sis.counts = sis.counts[:0]  
			}
		} else {
			sis.dict[num] = count - 1
		}
		return
	}
	for i, v := range sis.values {
		if v == num {
			sis.counts[i]--
			if sis.counts[i] == 0 {
				limit := len(sis.values) - 1
				if i < limit {
					sis.values = append(sis.values[:i], sis.values[i+1:]...)
					sis.counts = append(sis.counts[:i], sis.counts[i+1:]...)
				} else {
					sis.values = sis.values[:i]
					sis.counts = sis.counts[:i]
				}
			}
			return
		}
	}
	panic("should not be here!")
}
Removes the state from the set, if count decrs to 0
package automaton
import (
	"bytes"
	"fmt"
	"sort"
	"strconv"
)
const TREE_MAP_CUTOVER = 30
type SortedIntSet struct {
	values []int
	counts []int
	dict       map[int]int  
	useTreeMap bool
	state      int
}
func newSortedIntSet(capacity int) *SortedIntSet {
	return &SortedIntSet{
		values: make([]int, 0, capacity),
		counts: make([]int, 0, capacity),
	}
}
func (sis *SortedIntSet) incr(num int) {
	if sis.useTreeMap {
		val, ok := sis.dict[num]
		if !ok {
			sis.dict[num] = 1
		} else {
			sis.dict[num] = 1 + val
		}
		return
	}
	for i, v := range sis.values {
		if v == num {
			sis.counts[i]++
			return
		} else if num < v {
			sis.values = append(sis.values[:i], append([]int{num}, sis.values[i:]...)...)
			sis.counts = append(sis.counts[:i], append([]int{1}, sis.counts[i:]...)...)
			return
		}
	}
	sis.values = append(sis.values, num)
	sis.counts = append(sis.counts, 1)
	if len(sis.values) == TREE_MAP_CUTOVER {
		sis.useTreeMap = true
		for i, v := range sis.values {
			sis.dict[v] = sis.counts[i]
		}
	}
}