#include <iostream>
#include <vector>
#include<bits/stdc++.h>
using namespace std;
int main() {
vector<char> arr = {'x', 'y', 'x', 'x', 'y', 'x', 'y', 'y'};
int n = arr.size();
int x_count = 0 ; int y_count = 0 ;
int count = 0 ;
unordered_map<int,int>hash;
hash[0]=1;
for(int i = 0 ; i<n;i++){
if(arr[i]=='x') x_count++;
else {
y_count++;
}
int diff = x_count-y_count;
count+=hash[diff];
hash[diff] ++;
}
cout<<count;
return 0;
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8dmVjdG9yPgojaW5jbHVkZTxiaXRzL3N0ZGMrKy5oPgp1c2luZyBuYW1lc3BhY2Ugc3RkOwoKaW50IG1haW4oKSB7CiAKICAgIHZlY3RvcjxjaGFyPiBhcnIgPSB7J3gnLCAneScsICd4JywgJ3gnLCAneScsICd4JywgJ3knLCAneSd9OwogICAgaW50IG4gPSBhcnIuc2l6ZSgpOwoJaW50IHhfY291bnQgPSAwIDsgaW50IHlfY291bnQgPSAwIDsKCWludCBjb3VudCA9IDAgOyAgCgl1bm9yZGVyZWRfbWFwPGludCxpbnQ+aGFzaDsKCWhhc2hbMF09MTsKCWZvcihpbnQgaSA9IDAgOyBpPG47aSsrKXsKCQlpZihhcnJbaV09PSd4JykgeF9jb3VudCsrOwoJICAgICAgICAgICBlbHNlIHsKCQl5X2NvdW50Kys7CgkgICAgICAgICAgICAgfQoJaW50IGRpZmYgPSB4X2NvdW50LXlfY291bnQ7Cgljb3VudCs9aGFzaFtkaWZmXTsKCWhhc2hbZGlmZl0gKys7Cgl9Cgljb3V0PDxjb3VudDsKCgogICAgcmV0dXJuIDA7Cn0K