package main import ( "bufio" "fmt" "math" "os" "strings" ) func main() { maxSize := 2 * int(math.Pow10(5)) rdr := bufio.NewReaderSize(os.Stdin, maxSize) buf := make([]byte, 0, maxSize) for { l, p, _ := rdr.ReadLine() buf = append(buf, l...) if !p { break } } s := string(buf) sl := len(s) al := strings.Count(s, "A") bl := sl - al limit := int(math.Min(float64(al), float64(bl))) * 2 max := 0 for i := limit; i >= 2; i -= 2 { for j := 0; j <= sl-i; j++ { if strings.Count(s[j:j+i], "A")*2 == i { max = i break } } if max > 0 { break } } fmt.Println(max) }