#include <iostream>
#include <map>
#include <vector>
int GetTotal(std::vector<int> arr, int x, int y) {
std::vector<int> x_y_diffs;
x_y_diffs.push_back(0);
for (int i = 0; i < arr.size(); i++) {
int val = x_y_diffs[i];
if (arr[i] == x) val++;
else if (arr[i] == y) val--;
x_y_diffs.push_back(val);
}
std::map<int, int> histogram;
int result = 0;
for (int x : x_y_diffs) {
result += histogram[x];
histogram[x]++;
}
return result;
}
int main(void) {
std::vector<int> arr = {1, 0 , 2, 1};
std::cout << GetTotal(arr, 1, 0);
}
I2luY2x1ZGUgPGlvc3RyZWFtPgojaW5jbHVkZSA8bWFwPgojaW5jbHVkZSA8dmVjdG9yPgoKaW50IEdldFRvdGFsKHN0ZDo6dmVjdG9yPGludD4gYXJyLCBpbnQgeCwgaW50IHkpIHsKCXN0ZDo6dmVjdG9yPGludD4geF95X2RpZmZzOwoJeF95X2RpZmZzLnB1c2hfYmFjaygwKTsKCWZvciAoaW50IGkgPSAwOyBpIDwgYXJyLnNpemUoKTsgaSsrKSB7IAoJCWludCB2YWwgPSB4X3lfZGlmZnNbaV07CgkJaWYgKGFycltpXSA9PSB4KSB2YWwrKzsKCQllbHNlIGlmIChhcnJbaV0gPT0geSkgdmFsLS07CgkJeF95X2RpZmZzLnB1c2hfYmFjayh2YWwpOwoJfQoKCXN0ZDo6bWFwPGludCwgaW50PiBoaXN0b2dyYW07CglpbnQgcmVzdWx0ID0gMDsKCWZvciAoaW50IHggOiB4X3lfZGlmZnMpIHsKCQlyZXN1bHQgKz0gaGlzdG9ncmFtW3hdOwoJCWhpc3RvZ3JhbVt4XSsrOwoJfQoJcmV0dXJuIHJlc3VsdDsKfQoKaW50IG1haW4odm9pZCkgewoJc3RkOjp2ZWN0b3I8aW50PiBhcnIgPSB7MSwgMCAsIDIsIDF9OwoJc3RkOjpjb3V0IDw8IEdldFRvdGFsKGFyciwgMSwgMCk7Cn0K