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

int main() {
	// your code goes here
	int n;
	cin >> n;
	string s;
	cin >> s;
	int r_so_far[n], g_so_far[n], b_so_far[n];
	memset(r_so_far, 0, sizeof(r_so_far));
	memset(g_so_far, 0, sizeof(g_so_far));
	memset(b_so_far, 0, sizeof(b_so_far));
	int r = 0, g = 0, b = 0;
	for(int i = 0; i < n; i++){
	    if(s[i] == 'R'){
	        r++;
	        r_so_far[i] = r;
	    }
	    else if(s[i] == 'G'){
	        g++;
	        g_so_far[i] = g;
	    }
	    else if(s[i] == 'B'){
	        b++;
	        b_so_far[i] = b;
	    }
	}
	int ans = 0;
	for(int i = 0; i < n; i++){
	    for(int j = i + 1; j < n; j++){
	        if(s[i] == s[j]){
	            continue;
	        }
	        if(s[i] == 'R' && s[j] == 'G'){
	            ans += (b_so_far[n - 1] - b_so_far[j]);
	            int diff = j - i;
	            if(j + diff < n && s[j + diff] == 'B'){
	                ans -= 1;
	            }
	        }
	        else if(s[i] == 'R' && s[j] == 'B'){
	            ans += (g_so_far[n - 1] - g_so_far[j]);
	            int diff = j - i;
	            if(j + diff < n && s[j + diff] == 'G'){
	                ans -= 1;
	            }
	        }
	        else if(s[i] == 'G' && s[j] == 'R'){
	            ans += (b_so_far[n - 1] - b_so_far[j]);
	            int diff = j - i;
	            if(j + diff < n && s[j + diff] == 'B'){
	                ans -= 1;
	            }
	        }
	        else if(s[i] == 'G' && s[j] == 'B'){
	            ans += (r_so_far[n - 1] - r_so_far[j]);
	            int diff = j - i;
	            if(j + diff < n && s[j + diff] == 'R'){
	                ans -= 1;
	            }
	        }
	        else if(s[i] == 'B' && s[j] == 'G'){
	            ans += (r_so_far[n - 1] - r_so_far[j]);
	            int diff = j - i;
	            if(j + diff < n && s[j + diff] == 'R'){
	                ans -= 1;
	            }
	        }
	        else if(s[i] == 'B' && s[j] == 'R'){
	            ans += (g_so_far[n - 1] - g_so_far[j]);
	            int diff = j - i;
	            if(j + diff < n && s[j + diff] == 'G'){
	                ans -= 1;
	            }
	        }
	    }
	}
	cout << ans << endl;
	return 0;
}
