use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
    let n: usize = read();
    let s: Vec<char> = read::<String>().chars().collect();

    let mut R = vec![];
    let mut G = vec![];
    let mut B = vec![];

    for i in 0..n {
      if s[i] == 'R' {
        R.push(i);
      } else if s[i] == 'G' {
        G.push(i);
      } else {
        B.push(i);
      }
    }

    let mut ans: usize = 0;

    // (R, G, B)
    for &r in &R {
      for &g in &G {
        for &b in &B {
          let mut v = vec![r, g, b];
          v.sort();
          let (i, j, k) = (v[0], v[1], v[2]);
          if 2 * j != k + i {
            ans += 1;
          }
        }
      }
    }

    println!("{}", ans);
}
