import std.algorithm;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;
import std.format;

byte cvt(char c) {
  if (c == 'R') return 0;
  if (c == 'G') return 1;
  return 2;
}

int[] ps (byte[] s, byte k) {
  auto res = new int[s.length+1];
  foreach (i; 0 .. s.length) {
    res[i+1] = res[i];
    if (s[i] == k) ++res[i+1];
  }
  return res;
}

void main() {
  auto s = readln;
  int n;
  formattedRead(s, " %d", &n);
  s = readln[0 .. n];
  auto a = new byte[n];
  foreach (i; 0 .. n) {
    a[i] = cvt (s[i]);
  }
  //s[i] != s[j]
  //s[i] != s[k]
  //s[j] != s[k]
  //j - i != k - j
  //i < j < k
  int[][] u = new int[][3];
  foreach (i; 0 .. 3) {
    u[i] = ps (a, i.to!byte);
  }
  long res;
  const xorsum = 0 ^ 1 ^ 2;
  foreach (j; 1 .. n - 1) {
    auto y = a[j];
    foreach (i; 0 .. j) {
      auto x = a[i];
      if (x != y) {
        auto z = xorsum ^ (x ^ y);
        int delta = j - i;
        res += u[z].back - u[z][j+1]; 
        int k = j + delta;
        if (k < n && a[k] == z) --res;
      }
    }
  }
  writeln(res);
}

