#include <bits/stdc++.h>   using namespace std;   char s[100005];   int main() {     int n;     while (cin >> n) {       scanf( %s , s);       int ct = 1, n = strlen(s);       bool ok = false;       int cant = 0, ans = 0;       for (int i = 1; i < n; i++) {         if (s[i] == s[i - 1])           ct++;         else {           if (ct >= 3) ok = true;           if (ct >= 2) cant++;           ans++;           ct = 1;         }       }       ans++;       if (ct >= 3) ok = true;       if (ct >= 2) cant++;       if (ok)         ans += 2;       else {         if (cant >= 2)           ans += 2;         else if (cant == 1)           ans++;       }       cout << ans << endl;     }   }   