use std::cmp;
use std::collections::BinaryHeap; // 優先度付きキュー
use std::collections::HashMap; // 連想配列
use std::collections::HashSet; // 連想配列 キーのみ
use std::collections::VecDeque; // キュー or スタック
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        n: usize,
        s: chars
    }

    let mut ans = 0;

    let mut cum_sum_R = vec![0u64; n + 1];
    let mut cum_sum_G = vec![0u64; n + 1];
    let mut cum_sum_B = vec![0u64; n + 1];

    for i in 0..n {
        cum_sum_R[i + 1] = cum_sum_R[i];
        cum_sum_G[i + 1] = cum_sum_G[i];
        cum_sum_B[i + 1] = cum_sum_B[i];
        if s[i] == 'R' {
            cum_sum_R[i + 1] += 1;
        }
        if s[i] == 'G' {
            cum_sum_G[i + 1] += 1;
        }
        if s[i] == 'B' {
            cum_sum_B[i + 1] += 1;
        }
    }

    for i in 0..n - 1 {
        for j in i + 1..n - 1 {
            if s[i] != s[j] {
                if 'R' != s[i] && 'R' != s[j] {
                    let mut r_count = cum_sum_R[n] - cum_sum_R[j + 1];
                    if r_count > 0 && j - i + j < n && s[j - i + j] == 'R' {
                        r_count -= 1;
                    }
                    ans += r_count;
                }
                if 'G' != s[i] && 'G' != s[j] {
                    let mut g_count = cum_sum_G[n] - cum_sum_G[j + 1];
                    if g_count > 0 && j - i + j < n && s[j - i + j] == 'G' {
                        g_count -= 1;
                    }
                    ans += g_count;
                }
                if 'B' != s[i] && 'B' != s[j] {
                    let mut b_count = cum_sum_B[n] - cum_sum_B[j + 1];
                    if b_count > 0 && j - i + j < n && s[j - i + j] == 'B' {
                        b_count -= 1;
                    }
                    ans += b_count;
                }
            }
        }
    }

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

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2292