// This is my template for fast solving
 
#include <iostream>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <memory>
#include <initializer_list>
#include <iomanip>
#include <stack>
#include <bitset>
#include <cstdio>
// #include <complex>
// #include <random>
 
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using ld = long double;

// const ll INF = 1e18;
// const ld INF = 1e20;
const ll MOD = 998244353;
// const ld EPS = 1e-10;
// const ld PI = acos(-1);

template<typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p);
template<typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p);
 template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v);
template<typename T>
istream& operator>>(istream& is, vector<T>& v);
template<typename T>
ostream& operator<<(ostream& os, const set<T>& s);
template<typename T1, typename T2>
ostream& operator<<(ostream& os, const map<T1, T2>& m);

vector<int> calc_z(const string& s);
ll binpow(ll a, ll m, ll mod);

ll gcd(ll a, ll b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

void solve() {
    int n;
    string s;
    cin >> n >> s;
    vector<int> cnt[3];
    cnt[0].assign(n, 0);
    cnt[2].assign(n, 0);
    cnt[1].assign(n, 0);
    vector<int> a(n);
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R') {
            a[i] = 0;
        }
        if (s[i] == 'G') {
            a[i] = 1;
        }
        if (s[i] == 'B') {
            a[i] = 2;
        }
    }
    for (int i = n - 2; i >= 0; --i) {
        for (int j = 0; j <= 2; ++j) {
            cnt[j][i] = cnt[j][i + 1];
            if (a[i + 1] == j) {
                ++cnt[j][i];
            }
        }
    }
    ll ans = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = i + 1; j < n - 1; ++j) {
            if (a[i] == a[j]) {
                continue;
            }
            int x = 3 - a[i] - a[j];
            ans += cnt[x][j];
            int p = j + j - i;
            if (p < n && a[p] == x) {
                --ans;
            }
        }
    }
    cout << ans << "\n";
}   

int main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);

    // int t;
    // cin >> t;
    // for (int i = 1; i <= t; ++i) {
    //     cout << "Case #" << i << ":\n"; // CodeJam style
    //     solve();
    // }
 
    // int q;
    // cin >> q;
    // while (q--) {
    //     solve();
    // }

    solve();
 
    return 0;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& os, const pair<T1, T2>& p) {
    os << p.first << " " << p.second;
    return os;
}

template<typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >>  p.second;
    return is;
}
 
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    bool first = true;
    for (const auto& x : v) {
        if (!first) {
            os << " ";
        }
        first = false;
        os << x;
    }
    return os;
}

template<typename T>
istream& operator>>(istream& is, vector<T>& v) {
    for (auto& elem : v) {
        is >> elem;
    }
    return is;
}

template<typename T>
ostream& operator<<(ostream& os, const set<T>& s) {
    bool first = true;
    for (auto x : s) {
        if (!first) {
            os << " ";
        }
        first = false;
        os << x;
    }
    return os;
}

template<typename T1, typename T2>
ostream& operator<<(ostream& os, const map<T1, T2>& m) {
    bool first = true;
    for (auto x : m) {
        if (!first) {
            os << "\n";
        }
        first = false;
        os << x;
    }
    return os;
}

vector<int> calc_z(const string& s) {
    int n = s.length();
    vector<int> z(n, 0);
    int l = 0, r = 0;
    for (int i = 1; i < n; ++i) {
        if (i <= r) {
            z[i] = min(z[i - l], r - i);
        }
        int j = i + z[i];
        while (j < n && s[j] == s[z[i]]) {
            ++z[i];
            ++j;
        }
        if (j >= r) {
            r = j - 1;
            l = i;
        }
    }
    return z;
}

ll binpow(ll a, ll m, ll mod = MOD) {
    ll res = 1;
    while (m) {
        if (m % 2) {
            res = res * a % mod;
            --m;
        } else {
            a = a * a % mod;
            m /= 2;
        }
    }
    return res;
}

Measured memory_bytes: 3664