#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define intput(i) cout << i << endl
#define ll long long
#define stringput(s) cout << (string)(s) << endl

int main(){
  int N;
  string S;
  cin >> N >> S;
  int ans = 0;
  for(int i = 0;i <N;i++){
    for(int j = i+1;j <N;j++){
      for(int k = j+1;k <N;k++){
        if(S[i] != S[j] && S[i] != S[k] && S[j] != S[k] && j-i != k-j){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
}
