#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 = 0,
    ENUM_GREEN,
    ENUM_BLUE,
    ENUM_ALL
};

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

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

int main(void) {
    int len = get_int(); // length
    char str[BUF_SIZE];
    get_str(str, BUF_SIZE);
    int i, j;
    char type[BUF_SIZE] = {0};
    for(i = 0; i < len; i++) {
        type[i] = table[str[i]];
    }
    uint64_t sum[3] = {0};
    // cumulative
    for(i = 0; i < ENUM_ALL; i++) {
        for(j = 0; j < len; j++) {
            sum[i] += (type[j] == i);
        }
    }

    uint64_t cnt = sum[0] * sum[1] * sum[2];

    uint64_t exclude = 0;
    int dist;
    for(dist = 1; dist < len; dist++) {
        for(i = 0; i < len; i++) {
            if(i + dist*2 >= len) continue;
            int tp = (1<<type[i]) | (1<<type[i+dist]) | (1<<type[i+dist*2]);
            if(tp == TYPE_ALL) exclude++;
        }
    }
#ifdef DEBUG
    printf("%llu - %llu\n", cnt, exclude);
#endif
    printf("%llu\n", cnt - exclude);

    return 0;
}