//Himanshu Shukla
#pragma GCC optimize("O2")
#include <bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
//#define file_input
//#define multitest
//#define measure_time
#define ll long long
#define v32 vector<int>
#define v64 vector<ll>
#define s32 set<int>
#define s64 set<ll>
#define graph vector<v32>
#define p32 pair<int, int>
#define p64 pair<ll, ll>
#define sz(v) (ll)(v).size()
#define fi first
#define se second
#define ln '\n'
#define debug(x) cerr << (#x) << ": " << (x) << ln
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
inline ll add(ll a, ll b, ll m) { return (((a % m + b % m) % m + m) % m); }
inline ll mul(ll a, ll b, ll m) { return (((a % m * b % m) % m + m) % m); }
const double EPS = 1e-6;
const ll MOD = 1e9 + 7;
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
	out << '[' << p.fi << ", " << p.se << ']';
	return out;
}
template <template <typename, typename...> class ContainerType, typename ValueType, typename... Args>
void print_container(const ContainerType<ValueType, Args...> &c)
{
	cout << "{ ";
	for (const auto &v : c)
		cout << v << ' ';
	cout << '}' << ln;
}

void solve()
{
	int n;
	cin >> n;
	string str;
	cin >> str;
	vector<v32> idx(3, v32());
	//R 0
	//G 1
	//B 2
	for (int i = 0; i < n; i++)
	{
		if (str[i] == 'R')
			idx[0].push_back(i);
		else if (str[i] == 'G')
			idx[1].push_back(i);
		else
			idx[2].push_back(i);
	}
	ll ans = 0;
	for (int i = 0; i < n; i++)
	{
		// print_container(idx[0]);
		// print_container(idx[1]);
		// print_container(idx[2]);
		v32 red, green, blue;
		red = idx[0];
		green = idx[1];
		blue = idx[2];
		int r = 0, b = 0, g = 0;
		if (str[i] == 'R')
			r++;
		else if (str[i] == 'G')
			g++;
		else
			b++;
		for (int j = i + 1; j < n; j++)
		{
			if (str[j] == 'R')
				r++;
			else if (str[j] == 'G')
				g++;
			else
				b++;
			if (str[i] == str[j])
				continue;
			int len = j - i;
			if ((str[i] == 'R' && str[j] == 'G') || (str[i] == 'G' && str[j] == 'R'))
			{
				if (b < sz(blue))
				{
					int idx1 = lower_bound(blue.begin() + b, blue.end(), j + len) - blue.begin();
					int idx2 = upper_bound(blue.begin() + b, blue.end(), j + len) - blue.begin();
					ans += (sz(blue) - b - idx2 + idx1);
				}
			}
			else if ((str[i] == 'R' && str[j] == 'B') || (str[i] == 'B' && str[j] == 'R'))
			{
				if (g < sz(green))
				{
					int idx1 = lower_bound(green.begin() + g, green.end(), j + len) - green.begin();
					int idx2 = upper_bound(green.begin() + g, green.end(), j + len) - green.begin();
					ans += (sz(green) - g - idx2 + idx1);
				}
			}
			else if ((str[i] == 'G' && str[j] == 'B') || (str[i] == 'B' && str[j] == 'G'))
			{
				if (r < sz(red))
				{
					int idx1 = lower_bound(red.begin() + r, red.end(), len + j) - red.begin();
					int idx2 = upper_bound(red.begin() + r, red.end(), j + len) - red.begin();
					ans += (sz(red) - r - idx2 + idx1);
				}
			}
		}
		idx[0].clear();
		idx[1].clear();
		idx[2].clear();
		for (int j = i + 1; j < n; j++)
		{
			if (str[j] == 'R')
				idx[0].push_back(j);
			else if (str[j] == 'G')
				idx[1].push_back(j);
			else
				idx[2].push_back(j);
		}
	}
	cout << ans << ln;
	return;
}

int main()
{
	FASTIO;
#ifdef file_input
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	clock_t start, stop;
	int t = 1;
#ifdef multitest
	cin >> t;
#endif
#ifdef measure_time
	start = clock();
#endif
	for (int tc = 1; tc < t + 1; tc++)
		solve();
#ifdef measure_time
	stop = clock();
	cerr << "Time :" << fixed << setprecision(5) << double(stop - start) / double(CLOCKS_PER_SEC) << "s" << ln;
#endif
	return 0;
}


Measured memory_bytes: 3704