import std.stdio;
import std.string;

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

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

	long count;
	foreach (size_t i, a;s[0..$ - 2]) {
		foreach (size_t j, b;s[i + 1..$ - 1]) {
			auto ab = cast(int)a + b;
			foreach (size_t k, c;s[i + 1 + j + 1..$]) {
				if (j == k) {
					continue;
				}
				if (ab + c == 0x52 + 0x47 + 0x42) {
					++count;
				}
			}
		}
	}

	writeln(count);
}
