#include<iostream>
#include<cmath>
#include<algorithm>
#include<iomanip>
#include<climits>
#include<numeric>
#include<set>
#include<sstream>
#include<map>
#include<vector>
#include<string>
#include<regex>

using namespace std;

const long long MOD = (long long)(1e9 + 7);

vector<string> split(const string& haystack, const string& needle) {
	vector<string> result;
	size_t start_pos = 0;
	size_t found_pos = haystack.find(needle, start_pos);
	while (found_pos != string::npos) {
		size_t count = found_pos - start_pos;
		string token = haystack.substr(start_pos, count);
		if (!token.empty()) {
			result.push_back(token);
		}
		start_pos = found_pos + needle.length();
		found_pos = haystack.find(needle, start_pos);
	}

	string last_token = haystack.substr(start_pos);
	if (!last_token.empty()) {
		result.push_back(last_token);
	}
	return result;
}
string make_key(int x, int y, int z) {
	stringstream builder;
	builder << x << "-" << y << "-" << z;
	return builder.str();
}
int main() {
	string s;cin >> s;
	map<string, int> prefix;
	int d2 = 0, d8 = 0, dt = 0;
	int sum = 0;
	prefix[make_key(0, 0, 0)] = 1;
	for (int i = 0;i < s.length();i++) {
		if (s[i] == '2')d2++;
		if (s[i] == '8')d8++;
		if (s[i] == 't')dt++;

		int x = d2 - d8, y = d2 - dt, z = d8 - dt;
		string key = make_key(x, y, z);
		sum = sum + prefix[key];
		prefix[key]++;
	}
	cout << sum;
	return 0;
}
