// http://www.spoj.com/problems/HOMO/ package main import ( "bufio" "io" "os" "strconv" "strings" ) type List map[int]int func (l List) Insert(n int) { l[n]++ } func (l List) Delete(n int) { if l[n]--; l[n] <= 0 { delete(l, n) } } func (l List) IsHomo() bool { var top int for _, v := range l { if v > top { top = v } } return top > 1 } func (l List) IsHetero() bool { return len(l) > 1 } func Split(s string) (string, int) { i := strings.Index(s, " ") n, _ := strconv.Atoi(s[i+1:]) return s[:i], n } func (l List) String() string { homo, hetero := l.IsHomo(), l.IsHetero() switch { case homo && hetero: return "both" case hetero: return "hetero" case homo: return "homo" default: return "neither" } } func Homo(r io.Reader, w io.Writer) { scanner := bufio.NewScanner(r) scanner.Scan() // eat # of cases l := make(List) for scanner.Scan() { s, n := Split(scanner.Text()) switch s { case "insert": l.Insert(n) case "delete": l.Delete(n) } io.WriteString(w, l.String()) io.WriteString(w, "\n") } } func main() { Homo(os.Stdin, os.Stdout) }