#include <iostream>
#include <map>
#include <vector>
#include <cstring>
#include <set>
//#include<bits/stdc++.h>
using namespace std;
const int INF = 2e9;
typedef long long ll;
int n;
string s;
int dp[2][4][4][4][4];
int main() {
    ios_base::sync_with_stdio(false);
    cin >> n >> s;
    for(int at = 0; at < 2; at++) {
        for(int l1 = 0; l1 <= 3; l1++) {
            for(int l2 = 0; l2 <= 3; l2++) {
                for(int r1 = 0; r1 <= 3; r1++) {
                    for(int r2 = 0; r2 <= 3; r2++) {
                        dp[at][l1][l2][r1][r2] = -INF;
                        
                    }
                }
            
        }
    }
    }
    dp[0][0][0][0][0] = 0;
    for(int at = 0; at < n; at++) {
        for(int l1 = 0; l1 <= 3; l1++) {
            for(int l2 = 0; l2 <= 3; l2++) {
                for(int r1 = 0; r1 <= 3; r1++) {
                    for(int r2 = 0; r2 <= 3; r2++) {
                        int now = at % 2;
                        int next = 1 - now;
                        int color = 0;
                        if(s[at] == 'G') {
                            color = 1;
                        }
                        else if(s[at] == 'R') {
                            color = 2;
                        }
                        else {
                            color = 3;
                        }
                        vector<bool> visited(4, false);
                        visited[l1] = true;
                        visited[l2] = true;
                        visited[color] = true;
                        int score = visited[1] + visited[2] + visited[3];
                        dp[next][color][l1][r1][r2] = max(dp[now][l1][l2][r1][r2] + score, dp[next][color][l1][r1][r2]);
                        
                        visited[1] = false;
                        visited[2] = false;
                        visited[3] = false;
                        
                        visited[r1] = true;
                        visited[r2] = true;
                        visited[color] = true;
                        score = visited[1] + visited[2] + visited[3];
                        
                        dp[next][l1][l2][color][r1] = max(dp[next][l1][l2][color][r1], dp[now][l1][l2][r1][r2] + score);
                        
                    }
                }
            }
        }
    
    }
    int res = 0;
    for(int at = 0; at < 2; at++) {
        for(int l1 = 0; l1 <= 3; l1++) {
            for(int l2 = 0; l2 <= 3; l2++) {
                for(int r1 = 0; r1 <= 3; r1++) {
                    for(int r2 = 0; r2 <= 3; r2++) {
                        res = max(res, dp[at][l1][l2][r1][r2]);
                    }
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}

