//
//  header_useful.h
//  c++_acm
//
//  Created by 李弘辰 on 2019/7/23.
//  Copyright © 2019 李弘辰. All rights reserved.
//

#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <list>
#include <set>
#include <utility> // pair
#include <map>
#include <iostream>
#include <sstream>
#include <algorithm> // sort
#include <string>
#include <stack>
#include <queue>
#include <fstream>
#include <bitset>

using namespace std;

#define ll long long
#define uchar unsigned char
#define ushort unsigned short
#define uint unsigned int
#define ulong unsigned long
#define ull unsigned long long

#define INT_INF 0x7fffffff

#define pi acos(-1)

#define mx(a,b) (a) > (b) ? (a) : (b)
#define mn(a,b) (a) < (b) ? (a) : (b)
#define mem(a,b) memset(a,b,sizeof(a))
#define fre(a) freopen(a,"r",stdin)

#define cio ios::sync_with_stdio(false); // Do not use it before "scanf" and other c input!

#define itn int
#define nit int
#define inr int
#define mian main
#define ednl endl
#define fro for
#define fir for
#define reutrn return
#define retunr return
#define reutnr return


/* header_useful_h */


int main()
{
    int n;
    string str;
    scanf("%d",&n);
    cin >> str;
    int rb[4010];
    int br[4010];
    int rg[4010];
    int gr[4010];
    int bg[4010];
    int gb[4010];
    
    int r[4010] = {0};
    int g[4010] = {0};
    int b[4010] = {0};
    
    int tr = 0,tg = 0,tb = 0;
    for (int i = n - 1;i >= 0;i --) {
        if (str[i] == 'R') {
            tr ++;
            rb[i] = tb;
            rg[i] = tg;
            r[i] = 1;
        }
        if (str[i] == 'G') {
            tg ++;
            gb[i] = tb;
            gr[i] = tr;
            g[i] = 1;
        }
        if (str[i] == 'B') {
            tb ++;
            br[i] = tr;
            bg[i] = tg;
            b[i] = 1;
        }
    }
//    printf("%d %d %d\n",tr,tb,tg);
//    for (int i = 0;str[i];i ++) {
//        for (auto j : rb[i]) printf("%d ",j);
//        printf("\n");
//    }
    
    ll sum = 0;
    
    for (int i = 0;i < n;i ++) {
        for (int j = i + 1;j < n;j ++) {
//            printf("%d ",j);
            if (str[i] == 'R') {
                if (str[j] == 'B') {
                    sum += bg[j];
                    if (j + j - i < n && g[j + j - i]) sum --;
                }
                if (str[j] == 'G') {
                    sum += gb[j];
                    if (j + j - i < n && b[j + j - i]) sum --;
                }
            }
            if (str[i] == 'B') {
                if (str[j] == 'R') {
                    sum += rg[j];
                    if (j + j - i < n && g[j + j - i]) sum --;
                }
                if (str[j] == 'G') {
                    sum += gr[j];
                    if (j + j - i < n && r[j + j - i]) sum --;
                }
            }
            if (str[i] == 'G') {
                if (str[j] == 'B') {
                    sum += br[j];
                    if (j + j - i < n && r[j + j - i]) sum --;
                }
                if (str[j] == 'R') {
                    sum += rb[j];
                    if (j + j - i < n && b[j + j - i]) sum --;
                }
            }
        }
    }
    printf("%lld\n",sum);
    return 0;
}



Measured memory_bytes: 3328