#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <string>
#include <sstream>
#include <algorithm>
#include <random>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cmath>
#include <cassert>
#include <climits>
#include <bitset>
#include <functional>
#include <iomanip>
#include <random>

#define FOR_LT(i, beg, end) for (int i = (int)(beg); i < (int)(end); i++)
#define FOR_LE(i, beg, end) for (int i = (int)(beg); i <= (int)(end); i++)
#define FOR_DW(i, beg, end) for (int i = (int)(beg); (int)(end) <= i; i--)
#define REP(n)              for (int repeat_index = 0; repeat_index < (int)n; repeat_index++)


using namespace std;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout << fixed << setprecision(20);

	int n; cin >> n;
	string s; cin >> s;

	vector<int> rs(n);
	vector<int> gs(n);
	vector<int> bs(n);

	{
		int rc = 0;
		int gc = 0;
		int bc = 0;
		FOR_DW(i, n - 1, 0) {
			if (s[i] == 'R') rc++;
			if (s[i] == 'G') gc++;
			if (s[i] == 'B') bc++;

			rs[i] = rc;
			gs[i] = gc;
			bs[i] = bc;
		}
	}

	int64_t ans = 0;
	FOR_LT(i, 0, n) {
		FOR_LT(j, i + 1, n - 1) {
			if (s[i] == s[j]) continue;

			bool ss[256] = {};
			ss[s[i]] = true;
			ss[s[j]] = true;

			char r = ' ';
			if (!ss['R']) {
				r = 'R';
			}
			if (!ss['G']) {
				r = 'G';
			}
			if (!ss['B']) {
				r = 'B';
			}

			vector<int>& rems = (r == 'R' ? rs : r == 'G' ? gs : bs);
			ans += rems[j + 1];
			int k = j + (j - i);
			if (k < n && s[k] == r) ans--;
		}
	}
	cout << ans << endl;

	return 0;
}