You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

15 lines
295 B
C++

#include <bits/stdc++.h>
using namespace std;
const int N = 100100;
char s[N];
int main() {
int n, cnt = 0;
scanf("%d%s", &n, s);
for (int i = 0, p = 0; i < n; i++)
if (p != s[i])
p = s[i], cnt++;
printf("%d", min(n, cnt + 2));
return 0;
}