#include <iostream>
#include <iomanip>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <math.h>
#include <sstream>
#include <numeric>
#include <string>
#include <cassert>
#include <bitset>

using namespace std;
typedef long long ll;

int main() {
  int N;
  string S;
  cin >> N >> S;

  map<char, vector<int> > counts;
  vector<char> colors = {'R', 'G', 'B'};
  for (auto color : colors) {
    counts[color].resize(N);
  }

  // init (i = N - 1)
  for (auto color : colors) {
    counts[color][N - 1] = 0;
  }
  counts[S[N - 1]][N - 1]++;

  // iterate
  for (int i = N - 2; i >= 0; --i) {
    for (auto color : colors) {
      counts[color][i] = counts[color][i + 1];
    }
    counts[S[i]][i]++;
  }
  
  ll ans = 0;
  for (int i = 0; i < N - 2; ++i) {
    for (int j = i + 1; j < N - 1; ++j) {
      if (S[i] != S[j]) {
	char color;
	if (S[i] != 'R' and S[j] != 'R') {
	  color = 'R';
	} else if (S[i] != 'G' and S[j] != 'G') {
	  color = 'G';
	} else {
	  color = 'B';
	}
	ans += counts[color][j + 1];
	int k = j + (j - i);
	if (k < N and S[k] == color) {
	  --ans;
	}
      }
    }
  }
  cout << ans << endl;
  return 0;
}
