#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr long double EPS = 1e-8;

long long int N, M, K, L, R, H, W;
//int N, M, K, L, R, H, W;


int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	cin >> N;
	string s;
	cin >> s;
	long long int ans = 0;
	for (int i = 1; i < N - 1; i++) {
		map<char, int>mpa;
		map<char, int>mpb;
		for (int j = 0; j < i; j++) {
			if (s[i] != s[j]) {
				mpa[s[j]]++;
			}
		}
		for (int j = i + 1; j < N; j++) {
			if (s[i] != s[j]) {
				mpb[s[j]]++;
			}
		}
		for (auto j : mpa) {
			for (auto k : mpb) {
				if (j.first != k.first)ans += j.second*k.second;
			}
		}
		for (int j = 1; j < N; j++) {
			int l = i - j, r = i + j;
			if (l < 0 || r >= N)continue;
			if (s[l] != s[i] && s[i] != s[r] && s[l] != s[r])ans--;
		}
	}
	cout << ans << endl;
}