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

signed main(){
	int N; string S; cin>>N>>S;
	vector<int> v(3,0);
	for(int i=0;i<N;i++){
		v[(S[i]-'0')%3]++;
	}
	int ans=v[0]*v[1]*v[2];
	for(int i=0;i<N-1;i++){
		for(int j=i;j<N;j++){
			int d=j-i,now=j+d;
			if(now<N){
				if(S[i]!=S[j] and S[i]!=S[now] and S[j]!=S[now])ans--;
			}
		}
	}
	cout<<ans<<endl;
}