#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
#include <iomanip>
#include <map>
#include <stack>
#include <memory>
#include <numeric>
#include <type_traits>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
typedef long long ll;
 
 
int main() {
    int n; 
    cin >> n;
    string s;
    cin >> s;
    int res = 0;
    for (int i = 0; i < s.length()-2; i++){
      for (int j = i+1; j < s.length()-1; j++){
        for (int k = j+1; k < s.length(); k++){
          if (s[i] != s[j] && s[j] != s[k] && s[k] != s[i]){
            if (((j-i) != (k-j))) res += 1;
          }
        }
      }
    }
    if (n < 4) res = 0;
    cout << res << endl;
    return 0;
}