#include <stdio.h>

int main(void) {
    int n;
    char s[4001];

    scanf("%d", &n);
    scanf("%s", s);

    int count_r[4000];
    int count_g[4000];
    int count_b[4000];

    if (s[n-1] == 'R') {
        count_r[n-1] = 1;
        count_g[n-1] = 0;
        count_b[n-1] = 0;
    }
    else if (s[n-1] == 'G') {
        count_r[n-1] = 0;
        count_g[n-1] = 1;
        count_b[n-1] = 0;
    }
    else if (s[n-1] == 'B') {
        count_r[n-1] = 0;
        count_g[n-1] = 0;
        count_b[n-1] = 1;
    }

    for (int i = n - 2; i >= 0; i--) {
        if (s[i] == 'R') {
            count_r[i] = count_r[i+1] + 1;
            count_g[i] = count_g[i+1];
            count_b[i] = count_b[i+1];
        }
        else if (s[i] == 'G') {
            count_r[i] = count_r[i+1];
            count_g[i] = count_g[i+1] + 1;
            count_b[i] = count_b[i+1];
        }
        else if (s[i] == 'B') {
            count_r[i] = count_r[i+1];
            count_g[i] = count_g[i+1];
            count_b[i] = count_b[i+1] + 1;
        }
    }

    int count = 0;
    for (int i = 0; i <= n - 3; i++) {
        for (int j = i + 1; j <= n - 2; j++) {
            if ((s[i] == 'R' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'R')) {
                count += count_b[j+1];
                if (s[j + (j - i)] == 'B') {
                    count -= 1;
                }
            }
            else if ((s[i] == 'R' && s[j] == 'B') || (s[i] == 'B' && s[j] == 'R')) {
                count += count_g[j+1];
                if (s[j + (j - i)] == 'G') {
                    count -= 1;
                }
            }
            else if ((s[i] == 'B' && s[j] == 'G') || (s[i] == 'G' && s[j] == 'B')) {
                count += count_r[j+1];
                if (s[j + (j - i)] == 'R') {
                    count -= 1;
                }
            }
        }
    }

    printf("%d\n", count);
    return 0;
}
