#include <bits/stdc++.h>
using namespace std;

void executeTime() {
    cerr << "Time Taken: " << (float)clock() / CLOCKS_PER_SEC << " secs";
}

int main() {

    int n; cin >> n;

    int x, y; cin >> x >> y;

    vector<int> v(n);
    for (auto &x : v) {
        cin >> x;
    }


    unordered_map<int, int> mp;
    mp[0]++;

    int curr = 0, ans = 0;
    for (int j = 0; j < n; j++) {
        curr += (v[j] == x ? 1 : -1);
        ans += mp[curr];

        mp[curr]++;
    }

    cout << ans << endl;

    executeTime();
    return 0;
}