#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  string s;
  cin >> n >> s;
  long long r = 0, g = 0, b = 0;
  for(int i = 0; i < n; i++) {
    if(s.at(i) == 'R') r++;
    else if(s.at(i) == 'G') g++;
    else b++;
  }
  long long sum = r * g * b;
  for(int i = 0; i < (n - 2); i++) {
    for(int j = i + 1; j < (n - 1); j++) {
      if(s.at(i) != s.at(j)) {
        if(j + (j - i) >= n) {
          continue;
        }
        char x = s.at(j + (j - i));
        if(s.at(i) != x && s.at(j) != x) sum--;
      }
    }
  }
  cout << sum << endl;
}
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <cmath>
#include <stack>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}


void solve(std::string A){
  ll x = 0;
  ll len = A.size();
  for(ll i=0; i<26; i++) {
    ll cnt = 0;
    for(auto c : A) {
      if(c == 'a'+i)
	cnt++;
    }
    x += cnt*(cnt-1) / 2;
  }
  std::cout << (len * (len-1))/2 - x + 1<< std::endl;
}

int main(){
  std::string A;
  std::cin >> A;
  solve(A);
  return 0;
}

