/*
　　　　　／＞　 フ
　　　　　| 　_　 _|
　 　　　／`ミ _x 彡
　　 　 /　　　 　 |
　　　 /　  ヽ　　 ?
　／￣|　　 |　|　|
　| (￣ヽ＿_ヽ_)_)
　＼二つ
 */
#pragma GCC optimize("Ofast","inline","-ffast-math")
#pragma GCC target("avx,sse2,sse3,sse4,mmx")
#include<bits/stdc++.h>
#define int long long
#define pb push_back
#define pf push_front
#define F first
#define S second
#define SS stringstream
#define sqr(x) ((x)*(x))
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define CC(x) cout << (x) << endl
#define AL(x) x.begin(),x.end()
#define pw(x) (1ull<<(x))
#define NMSL cout << "NMSL" << endl;
#define debug(x) cout << #x << ": " << x << endl;
#define debug2(x, y) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl;
#define debug3(x, y, z) cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl;
#define debug4(a, b, c, d) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl;
#define fio ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define in128 __int128_t
using namespace std;
const int N = 2e5+10;
const int INF = numeric_limits<int>::max() / 4;
const double EPS = 1e-3;
const long double PI = 3.14159265358979323846;
int save[30];
signed main()
{
    fio
    string s;
    cin>>s;
    int ans=0;
    int n=s.length();
    for(int i=n-1;i>0;--i)
    {
        if(s[i]==s[i-1])
        {
            ans+=n-1-i-save[s[i]-'a'];
            memset(save,0,sizeof(save));
            save[s[i]-'a']=n-i;
        }else save[s[i]-'a']++;
//        debug4(i,ans,s[i],save[0])
    }
    cout<<ans;
    return 0;
}

//#define MULTICASES
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(i=(a);i<=(b);++i)
#define per(i,a,b) for(i=(a);i>=(b);--i)
#define REP(i,a,b) for(i=(a);i< (b);++i)
#define PER(i,a,b) for(i=(a);i> (b);--i)
#define ERR(...) fprintf(stderr,__VA_ARGS__)
template<class T>inline void cmn(T &x,const T &a){if(a<x)x=a;}
template<class T>inline void cmx(T &x,const T &a){if(x<a)x=a;}
template<class T>inline bool bmn(T &x,const T &a){if(a<x){x=a;return true;}else return false;}
template<class T>inline bool bmx(T &x,const T &a){if(x<a){x=a;return true;}else return false;}
const ll p=998244353ll,pp=p*p;const int ps2=p-2ll;
inline void add(ll &x){if(x>= p)x-=p ;}
inline void sub(ll &x){if(x<0ll)x+=p ;}
inline void adp(ll &x){if(x>=pp)x-=pp;}
inline void sup(ll &x){if(x<0ll)x+=pp;}
inline ll expo(ll a,int b=ps2,ll m=p){
	ll s=1ll;
	while(b){
		if(b&1)s=s*a%p;
		b>>=1; a=a*a%p;
	}
	return s;
}

inline void ac();
//inline void in();int main(){in();int t;scanf("%d",&t);while(t--)ac();return 0;}
//int main(){int t;scanf("%d",&t);while(t--)ac();return 0;}
int main(){ac();return 0;}

map<ll,int>M;
inline void ac(){
	int n,a;ll S=0ll,Z=0ll;
	scanf("%d",&n);
	M[0ll]=1;
	while(n--){
		scanf("%d",&a);
		if(n&1)S+=a;else S-=a;
		Z+=(M[S]++);
	}
	printf("%lld\n",Z);
}
/*
0. int overflow, array bounds
1. special cases (n=1? n=0?)
2. do smth instead of nothing and stay organized
3. WRITE STUFF DOWN
4. DON'T GET STUCK ON ONE APPROACH
5. STAY CALM AND DON'T GET EXPLODED
*/