package main import ( "bufio" "fmt" "os" ) func main() { s := readLine() sRune := []byte(s) n := make([]byte, len(sRune)) max := s for i := 0; i < len(s)-1; i++ { for j := i; j < len(s); j++ { copy(n, sRune) n[i], n[j] = n[j], n[i] if max < string(n){ max = string(n) } } } fmt.Println(max) } var rdr = bufio.NewReaderSize(os.Stdin, 1000000) func readLine() string { buf := make([]byte, 0, 1000000) for { l, p, e := rdr.ReadLine() if e != nil { panic(e) } buf = append(buf, l...) if !p { break } } return string(buf) }