#include <iostream>
#include <iomanip>
#include <algorithm>
#include <bitset>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <time.h>
#include <random>
#include <string>
#include <cassert>
#include <vector>
#include <ostream>
#include <istream>
#include <stack>
#include <deque>
#include <queue>
#include <functional>
#include <chrono>

using namespace std;

#define int long long
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define pii pair<int, int>
#define ld long double

ostream& operator << (ostream &a, const vector<int> &b) {
    for (auto k : b) cout << k << " ";
    return a;
}

#ifdef LOCAL
    #define dbg(x) cout << #x << " : " << (x) << "\n";
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 10;
//    const ld PI = 3.1415926535;
#else
    #define dbg(x)
    const int INF = 1e18;
//    const int mod = 2600000069;
//    const int p = 179;
//    const ld PI = 3.1415926535;
#endif

//#pragma GCC optimize("Ofast,no-stack-protector")
//#pragma GCC target("sse,sse2,sse3,sse3,sse4")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC optimize("fast-math")
//#pragma GCC target("avx2")
//#pragma GCC optimize("section-anchors")
//#pragma GCC optimize("profile-values,profile-reorder-functions,tracer")
//#pragma GCC optimize("vpt")
//#pragma GCC optimize("rename-registers")
//#pragma GCC optimize("move-loop-invariants")
//#pragma GCC optimize("unswitch-loops")
//#pragma GCC optimize("function-sections")
//#pragma GCC optimize("data-sections")

const int MAXN = 4001;

const int MASK = (1 << 3);

int dp[MAXN][MASK];

int bit(char k) {
    if (k == 'R') return 0;
    if (k == 'G') return 1;
    if (k == 'B') return 2;
}

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    dp[0][0] = 1;
    dp[0][1 << bit(s[0])] = 1;
    int ans = 0;
    for (int i = 1; i < n; i++) {
        int cur = (1 << bit(s[i]));
        for (int m = 0; m < (1 << 3); m++) {
            dp[i][m] += dp[i - 1][m];
            if ((m & cur) != 0) continue;
            dp[i][m | cur] += dp[i - 1][m];
        }
    }
    ans = dp[n - 1][7];
    int m;
    for (int i = 1; i < n - 1; i++) {
        for (int d = 1; d <= min(i, n - i - 1); d++) {
            m = (1 << bit(s[i])) + (1 << (bit(s[i - d]))) + (1 << (bit(s[i + d])));
            if (m == 7) {
//                cout << i - d << " " << i << " " << i + d << "\n";
                ans--;
            }
        }
    }
//    dbg(dp[n - 1][7]);
    cout << ans;
    //----------------------------------------------------------------------
    #ifdef LOCAL
        cout << "\n";
        cerr << "Time elapsed: " << (double)clock()/CLOCKS_PER_SEC << "s.\n";
    #endif
}
/*

*/
