//
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl '\n'
#define int long long
const int maxn = 2e5+10;
int lst[300];
int Minus[300];
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int n = s.size();
	for(int i = 'a';i <= 'z';i++)lst[i] = n;
	ll ans = 0;
	if(s[n-1] != s[n-2])Minus[(int)s[n-1]]++;

	for(int i = n-2;i >= 0;i--){
		if(i > 0 and s[i-1] != s[i] and s[i+1] != s[i])Minus[(int)s[i]]++;
		if(s[i] == s[i+1] and lst[(int)s[i]] != i+1){
			ans += lst[(int)s[i]] - i - 2 - (Minus[(int)s[i]]?Minus[(int)s[i]]:0ll);
			// cout << i << " " << lst[(int)s[i]] << " " << Minus[(int)s[i]] << " ans: " << lst[(int)s[i]] - i - 2 - (Minus[(int)s[i]]?Minus[(int)s[i]]:0ll) << endl;
			lst[(int)s[i]] = i;
			for(int j = 'a';j <= 'z';j++)if(j != s[i])lst[j] = n;
			for(int j = 'a';j <= 'z';j++)Minus[j] = 0;
		}
		if(s[i] == s[i+1] and lst[(int)s[i]] == i+1)lst[(int)s[i]] = i;
		// lst[(char)s[i]] = i;
		// Minus[(int)s[i]]++;
	}
	cout << ans;
	return 0;
}

#include<bits/stdc++.h>
#define f(i,a,b) for( int i=a;i<=b;++i)
#define ff(i,a,b) for( int i=a;i>=b;--i)
#define debug(x) cerr << #x << " : " << x << " " << endl
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
const ll mod = 1e9 + 7;
const ll mod2 = 998244353;
const int inf = 0x3f3f3f3f;
const double tiaohe = 0.57721566490153286060651209;
ll oula(ll x) { ll res = x;f(i, 2, x / i) { if (x % i == 0) { res = res / i * (i - 1);while (x % i == 0) x /= i; } }if (x > 1) res = res / x * (x - 1);return res; }
ll quickmod(ll a, ll n, ll m) { ll s = 1;while (n) { if (n & 1) { s = s * a % m; }a = (a*a) % m;n = n / 2; }return s; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
void ex_gcd(ll a, ll b, ll &x, ll &y, ll &d) { if (!b) { d = a, x = 1, y = 0; } else { ex_gcd(b, a % b, y, x, d);y -= x * (a / b); } }
ll inv(ll t, ll p) { ll d, x, y;ex_gcd(t, p, x, y, d);return d == 1 ? (x % p + p) % p : -1; }
bool isPrime(ll x) { if (x == 2)return true;if (x % 2 == 0)return false;for (ll i = 2;i*i <= x;i++) if (x % i == 0)return false; return true; }
inline int in() { char ch = getchar();int x = 0, f = 1;while (ch<'0' || ch>'9') { if (ch == '-')f = -1;ch = getchar(); }while (ch >= '0'&&ch <= '9') { x = x * 10 + ch - '0';ch = getchar(); }return x * f; }
//double a = log(n) +tiaohe + 1.0 / (2 * n);
double eqa = (1 + sqrt(5.0)) / 2.0;
const double eps = 1e-6;
const int N = 6e5 + 5;

int main()
{
#ifndef ONLINE_JUDGE 
	freopen("in.txt", "r", stdin);
#endif	
	int n = in();
	ll ans = 0;
	while (n--)
	{
		int l = in();
		int r = in();
		ans += (ll)(r - l + 1)*(l + r)/2;
	}
	cout << ans << endl;
	return 0;

}
