n = int(input())
s = input()
l = []
cnt, ans = 0, 0
last = ''
for i in s:
if i != last:
l.append(cnt)
cnt = 1
else:
cnt += 1
last = i
l.append(cnt)
l = l[1:]
a, b = 0, 0
for t in l:
if t > 1:
a += 1
if t > 2:
b += 1
if a >= 2 or b >= 1:
print(len(l)+2)
exit()
if a == 1:
print(len(l)+1)
exit()
print(len(l))
#define _CRT_SECURE_NO_WARNINGS
#include<set>
#include<iostream>
#include<vector>
#include<math.h>
#include<string>
#include<sstream>
#include<string>
#include<map>
#include<unordered_map>
#include<queue>
#include<unordered_set>
#include <cstring>
#include <algorithm>
#include <bitset>
using namespace std;
#define all(x) x.begin(), x.end()
#define endl '\n'
#define sz(x) x.size()
#define clr(x,v) memset(x,v,sizeof x);
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
void fast()
{
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("in.txt", "r", stdin);
#endif
}
const int N = 1e5 + 5, MOD = 1e9 + 7;
char s[N];
int n;
int dp[N][2][3];
int solve(int i, int last, int state) {
if (i == n)return 0;
int& ret = dp[i][last][state];
if (~ret)return ret;
ret = 0;
int cur = s[i] - '0';
if (state == 1)cur = !cur;
ret = (last!=cur) + solve(i + 1, cur, state);
if (state == 0&& last == cur)
ret = max(ret,1+ solve(i + 1, !cur, 1));
else if (state == 1&&last==cur)
ret = max(ret, 1 + solve(i + 1, !cur, 2));
else if(state==2){
if (last != s[i] - '0')
ret = 1 + solve(i + 1, s[i] - '0', 2);
else
ret = solve(i + 1, s[i] - '0', 2);
}
return ret;
}
int main()
{
fast();
cin >> n >> s;
clr(dp, -1);
cout << solve(0, 1 - (s[0] - '0'), 0);
}
416. Partition Equal Subset Sum | 1446. Consecutive Characters |
1618A - Polycarp and Sums of Subsequences | 1618B - Missing Bigram |
938. Range Sum of BST | 147. Insertion Sort List |
310. Minimum Height Trees | 2110. Number of Smooth Descent Periods of a Stock |
2109. Adding Spaces to a String | 2108. Find First Palindromic String in the Array |
394. Decode String | 902. Numbers At Most N Given Digit Set |
221. Maximal Square | 1200. Minimum Absolute Difference |
1619B - Squares and Cubes | 1619A - Square String |
1629B - GCD Arrays | 1629A - Download More RAM |
1629C - Meximum Array | 1629D - Peculiar Movie Preferences |
1629E - Grid Xor | 1629F1 - Game on Sum (Easy Version) |
2148. Count Elements With Strictly Smaller and Greater Elements | 2149. Rearrange Array Elements by Sign |
2150. Find All Lonely Numbers in the Array | 2151. Maximum Good People Based on Statements |
2144. Minimum Cost of Buying Candies With Discount | Non empty subsets |
1630A - And Matching | 1630B - Range and Partition |