#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef pair<int,int> ii;
typedef tree<ii,null_type,less<ii>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int N; string S; cin>>N>>S;
	map<char,ll> ct;
	for (int i=0; i<N; i++)
		ct[S[i]]++;
	ll ret=1;
	for (auto it : ct)
		ret*=it.second;
	for (int i=0; i<N; i++)
		for (int j=i+1; 2*j-i<N; j++) {
			int k=2*j-i;
			if(S[i]!=S[j]&&S[j]!=S[k]&&S[i]!=S[k])
				ret--;
		}
	cout<<ret<<"\n";
	return 0;
}