#include <bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
  int n;
  string s;

  cin >> n >> s;
  ll ans = 0;

  char co[3];

  int i = 0, j = 0, k = 0;
  while(i < n){
    co[0] = s[i];
    j = i + 1;
    while(j < n){
      if(co[0] != s[j]){
        co[1] = s[j];
        k = j + 1;
        while(k < n){
          if(co[0] != s[k] && co[1] != s[k]){
            if(j - i != k - j){
              ans++;
            }
          }
          k++;
        }
      }
      j++;
    }
    i++;
  }

  cout << ans;

  return 0; 
}
