package main import ( "bufio" "bytes" "fmt" "io" "os" "regexp" "strconv" "strings" ) func main() { sc := NewScanner(os.Stdin) d, _ := sc.NextInt() line1, _ := sc.NextLine() line2, _ := sc.NextLine() line := line1 + line2 fmt.Println(solve(d, line)) } func solve(d int, s string) int { pad := strings.Repeat("x", d) src := []byte(pad + s + pad) buf := make([]byte, len(src)) if d <= 0 { return getMaxConsecutiveHolidays(src) } re := regexp.MustCompile(`x+`) indexes := re.FindAllIndex(src, -1) max := 0 for _, v := range indexes { start, end := v[0], v[1] len := end - start if len > d { len = d } repl := bytes.Repeat([]byte{'o'}, len) copy(buf, src) copy(buf[start:], repl[:]) days := getMaxConsecutiveHolidays(buf) if days > max { max = days } if start != end-len { copy(buf, src) copy(buf[end-len:], repl[:]) days = getMaxConsecutiveHolidays(buf) if days > max { max = days } } } return max } func getMaxConsecutiveHolidays(s []byte) int { res := bytes.Split(s, []byte("x")) max := 0 for _, v := range res { if len(v) > max { max = len(v) } } return max } type scanner struct { *bufio.Scanner } func NewScanner(r io.Reader) *scanner { return &scanner{ bufio.NewScanner(r), } } func (s *scanner) Next() (string, error) { s.Scanner.Split(bufio.ScanWords) return s.nextToken() } func (s *scanner) NextLine() (string, error) { s.Scanner.Split(bufio.ScanLines) return s.nextToken() } func (s *scanner) nextToken() (string, error) { sc := s.Scanner if sc.Scan() { return sc.Text(), nil } if sc.Err() != nil { return "", sc.Err() } return "", io.EOF } func (s *scanner) NextInt() (int, error) { token, err := s.Next() if err != nil { return 0, err } return strconv.Atoi(token) }