#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ll long long
#define MOD 1000000007
#define MAX 100010
#define cout(v) REP(i,v.size()) cout << v[i] << " "; cout << endl;
using namespace std;
using Graph = vector<vector<int>>;
 
int main(){
  int n; cin >> n;
  string s; cin >> s;
  int ans = 0;
  REP(i,n-2){
    FOR(j,i+1,n-1){
      FOR(k,j+1,n){
        if(s[i]!=s[j] && s[i]!=s[k] && s[j]!=s[k] && j-i!=k-j){
          ans++;
        }
      }
    }
  }
  cout << ans;
}