package main import . "fmt" import "math/bits" func main() { var s string Scan(&s) b := []byte(s) ans := solve(b) Println(ans) } func solve(b []byte) int { m := map[byte]bool{} for i, ch := range b { m[ch] = true if ch != b[len(b)-1-i] { return len(b) } } if len(b) % 2 == 0 { if len(m) == 1 { return 0 } else { return len(b)-2 } } else if len(m) == 1 || len(b) <= 3 { return -1 } else { return len(b)-2 } } func init() { check() } func check() { buf := make([]byte, 100) for odd := 0; odd <= 1; odd++ { for half := 1; half <= 3; half++ { size := half*2+odd kind := 1 for i := 0; i < half+odd; i++ { kind *= 3 } b := buf[:size] for i := 0; i < kind; i++ { for j,x := 0,i; j < half+odd; j++ { b[j] = byte(x%3) b[size-1-j] = b[j] x /= 3 } ans := solve(b) expect := bruteforce(b) if ans != expect { println("b=",Sprintf("%#v",b)) println("ans=",ans) println("expect=",expect) return } } } } } func bruteforce(b []byte) int { ans := -1 size := len(b) buf := make([]byte, size) for i := 0; i < (1<>= 1 } if size-c != len(tmp) { println("b=",Sprintf("%#v",b)) println("i=",Sprintf("%b",i)) println("c=",c) println("tmp=",Sprintf("%#v",tmp)) panic("bug") } if len(tmp) == 0 { ans = max(ans, 0) continue } for u,v := 0,len(tmp)-1; u