// ABC162-D RGB Triplets

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

signed main() {
    int n, a, b, pos1, pos2;
    long long dp[3][4000] = {}, ans = 0;
    string s;

    cin >> n;
    cin >> s;

    ans = 0;
    for(int i=0 ;i<n ;i++ ) {
        if(s[i] == 'R') {
            dp[0][i] = 1;
        } 
        else if(s[i] == 'B') {
            dp[1][i] = 1;
        }
        else {
            dp[2][i] = 1;
        }

        if(i > 0) {
            for(int j=0 ;j<3 ;j++ ) {
                dp[j][i] += dp[j][i-1];
            }
        }
    }

    for(int i=1 ;i<n-1 ;i++ ) {  
        if(s[i] == 'R') {
            a = 1;
            b = 2;
        }
        else if(s[i] == 'B') {
            a = 0;
            b = 2;
        }
        else {
            a = 0;
            b = 1;
        }

        ans += dp[a][i-1] * (dp[b][n-1] - dp[b][i]) + dp[b][i-1] * (dp[a][n-1] - dp[a][i]);
        pos1 = i-1;
        pos2 = i+1;   

        while(pos1 >= 0 && pos2 <= n-1) {
            if(s[pos1] != s[i] && s[i] != s[pos2] && s[pos1] != s[pos2]) {
                ans --;
            }

            pos1 --;
            pos2 ++;
        }
    }

    cout << ans << endl;

    return (0);
}
#include<iostream>
#include<string>
using namespace std;
int main()
{
    char s[5000];
    long long n,i,j,k,total=0,red[5000]={0},green[5000]={0},blue[5000]={0},r=0,g=0,b=0,x,y;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>s[i];
    }
    for(i=1;i<=n;i++)
    {
        if(s[i]=='R')
        {
            r++;
            red[i]=red[i-1]+1;
            blue[i]=blue[i-1];
            green[i]=green[i-1];
        }
        else if(s[i]=='G')
        {
            g++;
            green[i]=green[i-1]+1;
            red[i]=red[i-1];
            blue[i]=blue[i-1];
        }
        else if(s[i]=='B')
        {
            b++;
            blue[i]=blue[i-1]+1;
            red[i]=red[i-1];
            green[i]=green[i-1];
        }
    }
    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {          
            if((s[i]=='R'&&s[j]=='G')||(s[i]=='G'&&s[j]=='R'))
            {
                x=b-blue[j];
                y=(j-i)+j;
                if(s[y]=='B'&&x>0&&y<=n)
                {
                    x--;
                }
                if(x>0)
                {
                    total=total+x;
                }                
            }
            else if((s[i]=='R'&&s[j]=='B')||(s[i]=='B'&&s[j]=='R'))
            {
                x=g-green[j];
                y=(j-i)+j;
                if(s[y]=='G'&&x>0&&y<=n)
                {
                    x--;
                }
                if(x>0)
                {
                    total=total+x;  
                }              
            }
            else if((s[i]=='B'&&s[j]=='G')||(s[i]=='G'&&s[j]=='B'))
            {
                x=r-red[j];
                y=(j-i)+j;
                if(s[y]=='R'&&x>0&&y<=n)
                {
                    x--;
                }
                if(x>0)
                {
                    total=total+x; 
                }               
            }
        }
    }
    cout<<total<<endl;
    return 0;
}