// import chie template :) {{{
import std.stdio, std.algorithm, std.array, std.string, std.math, std.conv,
  std.range, std.container, std.bigint, std.ascii, std.typecons, std.format, std.bitmanip;

// }}}
// nep.scanner {{{
class Scanner {
  import std.stdio : File, stdin;
  import std.conv : to;
  import std.array : split;
  import std.string;
  import std.traits : isSomeString;

  private File file;
  private char[][] str;
  private size_t idx;

  this(File file = stdin) {
    this.file = file;
    this.idx = 0;
  }

  this(StrType)(StrType s, File file = stdin) if (isSomeString!(StrType)) {
    this.file = file;
    this.idx = 0;
    fromString(s);
  }

  private char[] next() {
    if (idx < str.length) {
      return str[idx++];
    }

    char[] s;
    while (s.length == 0) {
      s = file.readln.strip.to!(char[]);
    }

    str = s.split;
    idx = 0;

    return str[idx++];
  }

  T next(T)() {
    return next.to!(T);
  }

  T[] nextArray(T)(size_t len) {
    T[] ret = new T[len];

    foreach (ref c; ret) {
      c = next!(T);
    }

    return ret;
  }

  void scan()() {
  }

  void scan(T, S...)(ref T x, ref S args) {
    x = next!(T);
    scan(args);
  }

  void fromString(StrType)(StrType s) if (isSomeString!(StrType)) {
    str ~= s.to!(char[]).strip.split;
  }
}
// }}}

void main() {
  auto cin = new Scanner;
  int n;
  string s;
  cin.scan(n, s);

  int[] r = new int[2 * n], g = new int[2 * n], b = new int[2 * n];

  foreach (i; 0 .. n) {
    if (s[i] == 'R') {
      r[i] = 1;
    } else if (s[i] == 'G') {
      g[i] = 1;
    } else if (s[i] == 'B') {
      b[i] = 1;
    }
  }

  foreach (i; 1 .. 2 * n) {
    r[i] += r[i - 1];
    g[i] += g[i - 1];
    b[i] += b[i - 1];
  }

  int res;

  alias T = Tuple!(uint, "f", uint, "s", string, "str");
  T[] ar;
  string[] per = ["RGB", "RBG", "GRB", "GBR", "BRG", "BGR"];

  foreach (e; per) {
    foreach (i; 0 .. n) {
      foreach (j; i + 1 .. n) {
        if (s[i] == e[0] && s[j] == e[1]) {
          ar ~= T(i, j, e);
        }
      }
    }
  }

  debug writeln(r);
  debug writeln(g);
  debug writeln(b);

  foreach (e; ar) {
    uint l = e.s + (e.s - e.f);
    auto sel = e.str[2] == 'R' ? r : e.str[2] == 'G' ? g : b;
    res += sel[l - 1] - sel[e.s];
    if (l < n) {
      res += sel[n - 1] - sel[l];
    }
    debug writeln(e.str, " ", e, " ", sel[l - 1] - sel[e.s], " ", sel[n - 1] - sel[l]);
  }

  writeln(res);
}
