import std.stdio, std.conv, std.string, std.algorithm,
       std.math, std.array, std.container, std.typecons;

void main() {
  int n = readln.chomp.to!int;
  string s = readln.chomp;
  int[] rcs = new int[n+1];
  int[] gcs = new int[n+1];
  int[] bcs = new int[n+1];

  long sum = 0;

  for(int i=0; i<s.length; i++) {
    if(s[$-1-i]=='R') rcs[n-1-i]=rcs[n-i]+1;
    else rcs[n-1-i]=rcs[n-i];
    if(s[$-1-i]=='G') gcs[n-1-i]=gcs[n-i]+1;
    else gcs[n-1-i]=gcs[n-i];
    if(s[$-1-i]=='B') bcs[n-1-i]=bcs[n-i]+1;
    else bcs[n-1-i]=bcs[n-i];
  }

  for(int i=0; i<s.length; i++) {
    for(int j=i+1; j<s.length; j++) {
      if(s[i]=='R') {
        if(s[j]=='G') sum += bcs[j+1];
        if(s[j]=='B') sum += gcs[j+1];
      }
      if(s[i]=='G') {
        if(s[j]=='R') sum += bcs[j+1];
        if(s[j]=='B') sum += rcs[j+1];
      }
      if(s[i]=='B') {
        if(s[j]=='R') sum += gcs[j+1];
        if(s[j]=='G') sum += rcs[j+1];
      }
    }
  }

  for(int span=1; span<n; span++) {
    for(int i=0; i+span*2<n; i++) {
      if(s[i]!=s[i+span] &&
         s[i+span]!=s[i+span*2] &&
         s[i]!=s[i+span*2]) sum--;
    }
  }
  writeln(sum);
}

