/* #region template */
#![allow(unused_imports)]
use std::cmp::{max, min};
use std::io::{stdin, stdout, Bytes, Read, Stdin, StdinLock, Stdout, StdoutLock, Write};
use std::iter::{repeat, repeat_with};
use std::mem::swap;
use std::str::FromStr;
#[allow(dead_code)]
struct Io<'a> {
    reader: Bytes<StdinLock<'a>>,
    writer: StdoutLock<'a>,
    in_buf: [u8; BUF_SIZE],
}
#[allow(dead_code)]
impl<'a> Io<'a> {
    fn new(stdin: &'a Stdin, stdout: &'a Stdout) -> Io<'a> {
        Io {
            reader: stdin.lock().bytes(),
            writer: stdout.lock(),
            in_buf: [0; BUF_SIZE],
        }
    }
    fn r<T: FromStr>(&mut self) -> T {
        let mut count = 0;
        loop {
            match self.reader.next() {
                Some(Ok(b' ')) | Some(Ok(b'\n')) => break,
                Some(Ok(c)) => self.in_buf[count] = c,
                _ => panic!(),
            }
            count += 1;
        }

        let s = unsafe { std::str::from_utf8_unchecked(&self.in_buf[0..count]) };
        s.parse().unwrap_or_else(|_| panic!())
    }
    fn ru(&mut self) -> usize {
        self.r()
    }
    fn iter<'b, T>(&'b mut self) -> IoIter<'a, 'b, T> {
        IoIter::new(self)
    }
    fn c<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        self.iter().take(n).collect()
    }
    fn cu(&mut self, n: usize) -> Vec<usize> {
        self.c(n)
    }
    fn w<T: std::fmt::Display>(&mut self, v: T) {
        writeln!(self.writer, "{}", v).unwrap();
    }
    fn wn<T: std::fmt::Display>(&mut self, v: T) {
        write!(self.writer, "{}", v).unwrap();
    }
}
#[allow(dead_code)]
struct IoIter<'a: 'b, 'b, T> {
    io: &'b mut Io<'a>,
    m: std::marker::PhantomData<T>,
}
#[allow(dead_code)]
impl<'a: 'b, 'b, T> IoIter<'a, 'b, T> {
    fn new(io: &'b mut Io<'a>) -> IoIter<'a, 'b, T> {
        IoIter {
            io,
            m: std::marker::PhantomData,
        }
    }
}
impl<'a, 'b, T: FromStr> Iterator for IoIter<'a, 'b, T> {
    type Item = T;
    fn next(&mut self) -> Option<Self::Item> {
        Some(self.io.r())
    }
}
fn main() {
    let stdin = stdin();
    let stdout = stdout();
    let mut io = Io::new(&stdin, &stdout);
    unsafe {
        solve(&mut io);
    }
}
/* #endregion */

const BUF_SIZE: usize = 4096;

static mut DP: [[u64; 7]; 4001] = [[0; 7]; 4001];

const R: usize = 0;
const G: usize = 1;
const B: usize = 2;
const RG: usize = 3;
const RB: usize = 4;
const GB: usize = 5;
const RGB: usize = 6;

unsafe fn solve(io: &mut Io) {
    let n = io.ru();
    let s: Vec<char> = io.r::<String>().chars().collect();

    for i in 0..n {
        match s[i] {
            'R' => {
                DP[i + 1][R] = DP[i][R] + 1;
                DP[i + 1][G] = DP[i][G];
                DP[i + 1][B] = DP[i][B];
                DP[i + 1][RG] = DP[i][RG] + DP[i][G];
                DP[i + 1][RB] = DP[i][RB] + DP[i][B];
                DP[i + 1][GB] = DP[i][GB];
                DP[i + 1][RGB] = DP[i][RGB] + DP[i][GB];
            }
            'G' => {
                DP[i + 1][R] = DP[i][R];
                DP[i + 1][G] = DP[i][G] + 1;
                DP[i + 1][B] = DP[i][B];
                DP[i + 1][RG] = DP[i][RG] + DP[i][R];
                DP[i + 1][RB] = DP[i][RB];
                DP[i + 1][GB] = DP[i][GB] + DP[i][B];
                DP[i + 1][RGB] = DP[i][RGB] + DP[i][RB];
            }
            'B' => {
                DP[i + 1][R] = DP[i][R];
                DP[i + 1][G] = DP[i][G];
                DP[i + 1][B] = DP[i][B] + 1;
                DP[i + 1][RG] = DP[i][RG];
                DP[i + 1][RB] = DP[i][RB] + DP[i][R];
                DP[i + 1][GB] = DP[i][GB] + DP[i][G];
                DP[i + 1][RGB] = DP[i][RGB] + DP[i][RG];
            }
            _ => panic!(),
        }
    }
    let mut count = DP[n][RGB];
    for i in 0..n {
        for j in i + 1..n {
            if s[i] != s[j] {
                let k = 2 * j - i;
                if k < n && s[k] != s[i] && s[k] != s[j] {
                    count -= 1;
                }
            }
        }
    }
    io.w(count);
}


Measured memory_bytes: 2300