#include <cstdio>
#include <iostream>
#include <cassert>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <tuple>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cmath>
#include <deque>
#include <random>
#include <chrono>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)

using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
    int N;
    scanf("%d", &N);
    vector<int> A(N, 0);
    for (int i = 0; i < N; i++)
        scanf("%d", &A[i]);
    vector<LL> psum(N, 0);
    for (int i = 0; i < N; i++) {
        if (i) psum[i] = psum[i - 1];
        int offs = 1;
        if (i % 2) offs = -1;
        psum[i] += offs * A[i];
    }
    map<LL, int> cnt;
    cnt[0] = 1;
    LL ans = 0;
    for (int i = 0; i < N; i++) {
        LL cur = psum[i];
        ans += cnt[cur];
        cnt[cur]++;
    }
    printf("%lld\n", ans);

    return 0;
}
/* stuff you should look for
	* int overflow, array bounds
	* special cases (n=1?)
	* do smth instead of nothing and stay organized
	* WRITE STUFF DOWN
    * DON'T GET STUCK ON ONE APPROACH
by Benq;
*/

#include <bits/stdc++.h>

using namespace std;

void solve() {
    int m;
    cin >> m;
    vector<pair<int, int>> edges(m);
    int n = 0;
    for (auto& edge: edges) {
        int u, v;
        cin >> u >> v;
        --u;
        --v;
        edge = {u, v};
        n = max(n, u + 1);
        n = max(n, v + 1);
    }
    vector<vector<int>> adj_list(n);
    for (auto& edge : edges) {
        int u, v;
        tie(u, v) = edge;
        adj_list[u].push_back(v);
        adj_list[v].push_back(u);
    }
    vector<bool> visited(n, false);
    function<pair<int, int> (int)> dfs = [&](int u) {
        if (visited[u]) {
            return make_pair(0, 0);
        }
        visited[u] = true;
        int nodes_seen = 1, edges_seen = 0;
        for (int v : adj_list[u]) {
            int n0, e0;
            tie(n0, e0) = dfs(v);
            nodes_seen += n0;
            edges_seen += e0 + 1;
        }
        return make_pair(nodes_seen, edges_seen);
    };
    int answer = 0;
    for (int u = 0; u < n; ++u) {
        int nodes_seen, edges_seen;
        tie(nodes_seen, edges_seen) = dfs(u);
        assert (edges_seen % 2 == 0);
        edges_seen /= 2;
        answer += min(nodes_seen, edges_seen);
    }
    cout << answer << "\n";
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    solve();
    return 0;
}