import std.stdio;
import std.string;

size_t count(string s, char x) {
	size_t c;
	foreach (e;s) {
		if (e == x) ++c;
	}
	return c;
}

void main() {
	readln;
	string s = readln.chomp;

	if (s.length < 3) {
		writeln("0");
		return;
	}

	
	long c;
	foreach (i;0..s.length / 2) {
		for (size_t j = 0;j + i + i < s.length;++j) {
			if (s[j] + s[j + i] + s[j + i + i] == 0x52 + 0x47 + 0x42) {
				++c;
			}
		}
	}

	auto m = count(s, 'R') * count(s, 'G') * count(s, 'B');
	writeln(m - c);
}
