#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // uint64_t

#define STR_MAX 4000
#define BUF_SIZE (STR_MAX+10)

// size: specify sizeof(str)
int get_str(char *str, int size) {
    if(!fgets(str, size, stdin)) return -1;
    return 0;
}

int get_int(void) {
  int num;
#ifdef BUF_SIZE
  char line[BUF_SIZE];
  if(!fgets(line, BUF_SIZE, stdin)) return 0;
  sscanf(line, "%d", &num);
#else
#error
#endif
  return num;
}

enum {
    ENUM_RED,
    ENUM_GREEN,
    ENUM_BLUE,
    ENUM_ALL
};

int table[256] = {
    ['R'] = 1<<ENUM_RED,
    ['G'] = 1<<ENUM_GREEN,
    ['B'] = 1<<ENUM_BLUE,
};

#define ALL_TYPE ((1<<ENUM_ALL) - 1)


int main(void) {
    int len = get_int(); // length
    char str[BUF_SIZE];
    get_str(str, BUF_SIZE);
    char type[BUF_SIZE] = {0};
    int i;
    for(i = 0; i < len; i++) {
        type[i] = table[str[i]];
    }
    static int dp[STR_MAX][1<<ENUM_ALL] = {0};
    dp[0][0] = 1;
    int pat;
    for(i = 1; i <= len; i++) {
        int tp = type[i-1];
        for(pat = 0; pat < (1<<ENUM_ALL); pat++) {
            dp[i][pat] = dp[i-1][pat];
            if(!(tp & pat)) { continue; }
            int prev_tp = pat & (~(tp));
            dp[i][pat] += dp[i-1][prev_tp];
            //printf("dp[%d][%d] = %d\n", i, pat, dp[i][pat]);
        }
    }
    int exclude = 0;
    int dist;
    for(dist = 1; dist < len; dist++) {
        for(i = 0; i < len; i++) {
            if(i + 2*dist >= len) continue;
            if(type[i] + type[i+dist] + type[i+dist*2] == ALL_TYPE) exclude++;
        }
    }
#ifdef DEBUG
    printf("%d %d\n", dp[len][(1<<ENUM_ALL) - 1], exclude);
#endif
    printf("%d\n", dp[len][(1<<ENUM_ALL) - 1]-exclude);
    return 0;
}