#C1657. Maximum Consecutive Identical Characters

    ID: 44886 Type: Default 1000ms 256MiB

Maximum Consecutive Identical Characters

Maximum Consecutive Identical Characters

You are given an integer \( n \) and a string \( s \) of length \( n \). You are allowed to change at most one character in \( s \) to any other character. Your task is to determine the maximum number of consecutive identical characters that can be achieved after applying at most one such change.

Explanation: Consider a string \( s = s_0s_1\dots s_{n-1} \). You may choose one position \( i \) (or none) and change \( s_i \) to any character. Then, find the length of the longest contiguous substring consisting entirely of the same character. The answer should be output as a single integer.

For example, if \( n = 7 \) and \( s = \texttt{abacccc} \), by changing the character at index 2 from \( a \) to \( c \), we obtain \( \texttt{abacccc} \) (with the changed character) which has a longest sequence of 5 consecutive \( c \)'s, so the answer is 5.

inputFormat

The input is given via standard input and consists of two lines:

  1. The first line contains an integer \( n \) \( (1 \le n \le 10^5) \), which is the length of the string.
  2. The second line contains the string \( s \) of length \( n \), consisting of lowercase English letters or other characters.

outputFormat

Output a single integer representing the maximum number of consecutive identical characters that can be obtained after changing at most one character.

## sample
7
abacccc
5