package main import ( "bufio" "os" "strconv" "fmt" "sort" ) var s = bufio.NewScanner(os.Stdin) func next() string { s.Split(bufio.ScanWords) s.Scan() return s.Text() } func nextLine() string { s.Split(bufio.ScanLines) s.Scan() if nil != s.Err() { panic(s.Err()) } return s.Text() } func nextInt() int { i, e := strconv.Atoi(next()) if e != nil { panic(e) } return i } func nextLong() int64 { i, e := strconv.ParseInt(next(), 10, 64) if e != nil { panic(e) } return i } func next_permutation(a []rune) bool { for i := len(a) - 2; i >= 0; i-- { if a[i] < a[i+1] { for j := len(a) - 1; j >= 0; j-- { if a[j] > a[i] { a[i], a[j] = a[j], a[i] reverse(a, i+1, len(a)-(i+1)) return true } } } } reverse(a, 0, len(a)) return false } func reverse(a []rune, start int, length int) { var end = start + length - 1 for start < end { a[start], a[end] = a[end], a[start] start++ end-- } } //https://www.socketloop.com/tutorials/golang-sort-and-reverse-sort-a-slice-of-runes type RuneSlice []rune func (p RuneSlice) Len() int { return len(p) } func (p RuneSlice) Less(i, j int) bool { return p[i] < p[j] } func (p RuneSlice) Swap(i, j int) { p[i], p[j] = p[j], p[i] } func main() { S := nextLine() s := RuneSlice([]rune(S)) var m = make(map[string]int) sort.Sort(s) for { str := string(s) m[str] = 1 if !next_permutation(s) { break } } fmt.Println(len(m) - 1) }