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 { src := []byte(s) 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 := strings.Repeat("o", len) buf := []byte(s) copy(buf[start:], repl[:]) days := getMaxConsecutiveHolidays(buf) if days > max { max = days } } return max } func getMaxConsecutiveHolidays(s []byte) int { results := bytes.Split(s, []byte("x")) max := 0 for _, v := range results { 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) }