#include <iostream>
using namespace std;
#define LL long long
#include <string>

#if 0
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;

    LL count = 0;

    for (int i = 0; i < n - 2; ++i) {
        for (int j = i + 1; j < n - 1; ++j) {
            if (s[i] == s[j]) {
                // cout << "ij " << i << " " << j << endl;
                continue;
            }

            for (int k = j + 1; k < n; ++k) {
                if ((s[i] == s[k]) || (s[j] == s[k])) {
                    // cout << "ikjk " << i << " " << j << " "<< k << endl;
                    continue;
                }
                
                if ((j - i) != (k - j))
                    count++;
            }
        }
    }
    cout << count << endl;

    return 0;
}
#endif

#include <vector>

// LL _count(vector<int> indices_1, vector<int>indices_2, int index) {
//     LL count;

//     return count;
// }

#if 0
#include <algorithm>
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;

    vector<int> r_indices;
    vector<int> g_indices;
    vector<int> b_indices;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R')
            r_indices.push_back(i);
        else if (s[i] == 'G')
            g_indices.push_back(i);
        else
            b_indices.push_back(i);
    }
    LL count = 0;

    vector<int> tmp;
    for (int i = 0; i < r_indices.size(); ++i) {
        for (int j = 0; j < g_indices.size(); ++ j) {
            for (int k = 0; k < b_indices.size(); ++k) {
                tmp.clear();
                tmp.push_back(r_indices[i]);
                tmp.push_back(g_indices[j]);
                tmp.push_back(b_indices[k]);
                sort(tmp.begin(), tmp.end());

                // cout << tmp[0] << tmp[1] << tmp[2] << endl;
                if ((tmp[1] - tmp[0]) != (tmp[2] - tmp[1]))
                    count++;
            }
        }
    }

    cout << count << endl;

    return 0;
}
#endif

#include <algorithm>
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;

    vector<int> r_indices;
    vector<int> g_indices;
    vector<int> b_indices;
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'R')
            r_indices.push_back(i);
        else if (s[i] == 'G')
            g_indices.push_back(i);
        else
            b_indices.push_back(i);
    }
    LL count = 0;

    vector<int> tmp;
    int diff, smaller_index, larger_index, candidate;
    for (int i = 0; i < r_indices.size(); ++i) {
        for (int j = 0; j < g_indices.size(); ++ j) {
            count += b_indices.size();

            smaller_index = min(r_indices[i], g_indices[j]);
            larger_index = max(r_indices[i], g_indices[j]);
            diff = larger_index - smaller_index;

            candidate = larger_index + diff;
            // cout << i << " " << j << " " << candidate << endl;
            if ((candidate <= n) && (find(b_indices.begin(), b_indices.end(), candidate) != b_indices.end())) {
                count--;
                // cout << "a" << endl;
            }
            
            candidate = smaller_index - diff;
            // cout << i << " " << j << " " << candidate << endl;
            if ((candidate >= 0) && (find(b_indices.begin(), b_indices.end(), candidate) != b_indices.end())) {
                count--;
                // cout << "b" << endl;
            }
            
            if (diff % 2 == 0) {
                candidate = smaller_index + diff / 2;
                // cout << i << " " << j << " " << candidate << endl;
                if (find(b_indices.begin(), b_indices.end(), candidate) != b_indices.end()) {
                    count--;
                    // cout << "c" << endl;
                }
            }
        }
    }

    cout << count << endl;

    return 0;
}




Measured memory_bytes: 3668