#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<int, char> Pc;
typedef pair<int, string> Ps;

const int dx[4] = {-1, 0, 0, 1};
const int dy[4] = {0, -1, 1, 0};
const int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
const string dir8[8] = {"U", "RU", "R", "RD", "D", "LD", "L", "LU"};

// Self settings
// clang-format off
#define MAX_N 100000
#define MAX 100000
#define INFTY (1<<30)
#define EPS (1e-10)
#define equals(a, b) (fabs((a) - (b)) < EPS)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1000100011;
class Point { public: double x, y; Point(double x = 0, double y = 0) : x(x), y(y) {} Point operator+(Point p) { return Point(x + p.x, y + p.y); } Point operator-(Point p) { return Point(x - p.x, y - p.y); } Point operator*(double a) { return Point(a * x, a * y); } Point operator/(double a) { return Point(x / a, y / a); } double abs() { return sqrt(norm()); } double norm() { return x * x + y * y; } bool operator<(const Point& p) const { return x != p.x ? x < p.x : y < p.y; } bool operator==(const Point& p) const { return fabs(x - p.y) < EPS && fabs(y - p.y) < EPS; } };
typedef Point Vector;
double norm(Vector a) { return a.x * a.x + a.y * a.y; }
double abs(Vector a) { return sqrt(norm(a));}
double dot(Vector a, Vector b) { return a.x * b.x + a.y * b.y; }
double cross(Vector a, Vector b) { return a.x * b.y - a.y * b.x; }
struct Segment { Point p1, p2; };
typedef Segment Line;
// clang-format on

int memo[3][9000];

int color(char c) {
  if (c == 'R') {
    return 0;
  } else if (c == 'G') {
    return 1;
  } else {
    return 2;
  }
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  ll N;
  string S;
  cin >> N >> S;

  for (int i = N - 1; i >= 0; i--) {
    if (S[i] == 'R') {
      memo[0][i]++;
    } else if (S[i] == 'G') {
      memo[1][i]++;
    } else {
      memo[2][i]++;
    }
    memo[0][i - 1] = memo[0][i];
    memo[1][i - 1] = memo[1][i];
    memo[2][i - 1] = memo[2][i];
  }

  ll sum = 0;
  ll first, second, third;
  // 1つ目の色をどれにするか
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < N; j++) {
      if (color(S[j]) != i) continue;
      // 2つめの色をどれにするか
      for (int k = 0; k < 3; k++) {
        // 1つめと同じ色ならスキップする
        if (i == k) continue;
        // 2つめの色をどことするか？
        for (int l = j + 1; l < N; l++) {
          if (color(S[l]) != k) continue;
          // l - i + 1 個先の i でも k でもない色の数を計算する
          for (int m = 0; m < 3; m++) {
            if (m == i || m == k) continue;
            if (l + 1 >= N) continue;
            // j = 0 , l = 1, m は (l-j) + 1 先のやつから
            third = memo[m][l + (l - j) + 1];
            if ((l + l - j) > l) {
              third += memo[m][l + 1] - memo[m][l + (l - j)];
            }
            sum += (third);
          }
        }
      }
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 3224