#include <iostream>
#include <algorithm>
using namespace std;

long long arr[101010];
long long pre[101010] = {0,};

int main() {
    int n; 
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> arr[i];
        pre[i] = pre[i - 1] + arr[i];
    }
    sort(pre, pre + n + 1);
    
    long long cnt = 0; 
    long long count = 1; 

    for (int i = 1; i <= n; i++) {
        if (pre[i] == pre[i - 1]) {
            count++;
        } 
        else {
            cnt += count * (count - 1) / 2;
            count = 1;
        }
    }
    
    cnt += count * (count - 1) / 2;
    cout << cnt;
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: