#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

int main(){
  int n;
  int i,j,k;
  char s[4005];
  char *p,*q,*r;
  int cnt = 0;
  char a[7] = "RGB";
  char b[7] = "RBG";
  char c[7] = "GBR";
  char d[7] = "GRB";
  char e[7] = "BGR";
  char f[7] = "BRG";
  int flag = 0;
  int sp = 0;
  int lp;

  scanf("%d", &n);
  scanf("%s", s);

  p = s; flag = 0; sp = 0; lp = n;
  while(*(p + 2) != '\0'){
    if(strncmp(p,a,3) == 0){
      q = p - 1;
      r = p + 3;
      flag = 1;

      while(sp >= 0){
        if(*q == 'R') cnt++;

        q--;
        sp--;
      }

      while(*r != '\0'){
        if(*r == 'B') cnt++;

        r++;
      }
    }

    p++;
    sp++;
  }

  p = s; flag = 0; sp = 0; lp = n;
  while(*(p + 2) != '\0'){
    if(strncmp(p,b,3) == 0){
      q = p - 1;
      r = p + 3;
      flag = 1;

      while(sp >= 0){
        if(*q == 'R') cnt++;

        q--;
        sp--;
      }

      while(*r != '\0'){
        if(*r == 'G') cnt++;

        r++;
      }
    }

    p++;
    sp++;
  }

  p = s; flag = 0; sp = 0; lp = n;
  while(*(p + 2) != '\0'){
    if(strncmp(p,c,3) == 0){
      q = p - 1;
      r = p + 3;
      flag = 1;

      while(sp >= 0){
        if(*q == 'G') cnt++;

        q--;
        sp--;
      }

      while(*r != '\0'){
        if(*r == 'R') cnt++;

        r++;
      }
    }
    p++;
    sp++;
  }

  p = s; flag = 0; sp = 0; lp = n;
  while(*(p + 2) != '\0'){
    if(strncmp(p,d,3) == 0){
      q = p - 1;
      r = p + 3;
      flag = 1;

      while(sp >= 0){
        if(*q == 'G') cnt++;

        q--;
        sp--;
      }

      while(*r != '\0'){
        if(*r == 'B') cnt++;

        r++;
      }
    }
    p++;
    sp++;
  }

  p = s; flag = 0; sp = 0; lp = n;
  while(*(p + 2) != '\0'){
    if(strncmp(p,e,3) == 0){
      q = p - 1;
      r = p + 3;
      flag = 1;

      while(q != s){
        if(*q == 'B') cnt++;

        q--;
        sp--;
      }

      while(*r != '\0'){
        if(*r == 'R') cnt++;
        r++;
      }
    }
    p++;
  }

  p = s; flag = 0; sp = 0; lp = n;
  while(*(p + 2) != '\0'){
    if(strncmp(p,f,3) == 0){
      q = p - 1;
      r = p + 3;
      flag = 1;

      while(sp >= 0){
        if(*q == 'B') cnt++;

        q--;
        sp--;
      }

      while(*r != '\0'){
        if(*r == 'G') cnt++;

        r++;
      }
    }
    p++;
    sp++;
  }

  printf("%d\n", cnt);

  return 0;
}
