use std::io::*;

fn read_int(s: &mut StdinLock) -> usize {
    s.by_ref().bytes().map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .skip_while(|c| c.is_whitespace())
        .fold(0, |a, x| (x as u8 - b'0') as usize + a * 10)
}
fn read_line_char(s: &mut StdinLock) -> Vec<char> {
    s.by_ref().bytes().map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .skip_while(|c| c.is_whitespace())
        .collect()
}

fn main() {
    let s = stdin();
    let mut s = s.lock();
    let n = read_int(&mut s);
    let vec_char = read_line_char(& mut s);
    let mut b: Vec<usize> = Vec::new();
    let mut g: Vec<usize> = Vec::new();
    let mut r: Vec<usize> = Vec::new();
    for i in 0..n {
        if vec_char[i] == 'B' {
            b.push(i);
        } else if vec_char[i] == 'G' {
            g.push(i);
        } else if vec_char[i] == 'R' {
            r.push(i);
        }
    }
    let mut ans: usize = 0;
    for i in 0..b.len() { // n^2 log n
        for j in 0..g.len() {
            let mut ng: usize = 0;
            if (b[i] + g[j]) % 2 == 0 {
                if let Ok(_) = r.binary_search(&((b[i] + g[j]) / 2)) {
                    ng = 1;
                }
            }
            match r.binary_search(&g[j]) {
                Ok(p) => {
                    match r.binary_search(&b[i]) {
                        Ok(q) => {
                            if p < q {
                                ans += q - p - ng;
                            } else {
                                ans += p - q - ng;
                            }
                        },
                        Err(q) => {
                            if p < q {
                                ans += q - p - ng;
                            } else {
                                ans += p - q - ng;
                            }
                        },
                    }
                },
                Err(p) => {
                    match r.binary_search(&b[i]) {
                        Ok(q) => {
                            if p < q {
                                ans += q - p - ng;
                            } else {
                                ans += p - q - ng;
                            }
                        },
                        Err(q) => {
                            if p < q {
                                ans += q - p - ng;
                            } else {
                                ans += p - q - ng;
                            }
                        },
                    }
                },
            }
        }
    }
    for i in 0..b.len() {
        for j in 0..r.len() {
            let mut ng: usize = 0;
            if (b[i] + r[j]) % 2 == 0 {
                if let Ok(_) = g.binary_search(&((b[i] + r[j]) / 2)) {
                    ng = 1;
                }
            }
            match g.binary_search(&r[j]) {
                Ok(p) => {
                    match g.binary_search(&b[i]) {
                        Ok(q) => {
                            if p < q {
                                ans += q - p - ng;
                            } else {
                                ans += p - q - ng;
                            }
                        },
                        Err(q) => {
                            if p < q {
                                ans += q - p - ng;
                            } else {
                                ans += p - q - ng;
                            }
                        },
                    }
                },
                Err(p) => {
                    match g.binary_search(&b[i]) {
                        Ok(q) => {
                            if p < q {
                                ans += q - p - ng;
                            } else {
                                ans += p - q - ng;
                            }
                        },
                        Err(q) => {
                            if p < q {
                                ans += q - p - ng;
                            } else {
                                ans += p - q - ng;
                            }
                        },
                    }
                },
            }
        }
    }
    for i in 0..g.len() {
        for j in 0..r.len() {
            let mut ng: usize = 0;
            if (g[i] + r[j]) % 2 == 0 {
                if let Ok(_) = b.binary_search(&((g[i] + r[j]) / 2)) {
                    ng = 1;
                }
            }
            match b.binary_search(&r[j]) {
                Ok(p) => {
                    match b.binary_search(&g[i]) {
                        Ok(q) => {
                            if p < q {
                                ans += q - p - ng;
                            } else {
                                ans += p - q - ng;
                            }
                        },
                        Err(q) => {
                            if p < q {
                                ans += q - p - ng;
                            } else {
                                ans += p - q - ng;
                            }
                        },
                    }
                },
                Err(p) => {
                    match b.binary_search(&g[i]) {
                        Ok(q) => {
                            if p < q {
                                ans += q - p - ng;
                            } else {
                                ans += p - q - ng;
                            }
                        },
                        Err(q) => {
                            if p < q {
                                ans += q - p - ng;
                            } else {
                                ans += p - q - ng;
                            }
                        },
                    }
                },
            }
        }
    }
    println!("{}", ans);
}

Measured memory_bytes: 2176