#!/usr/bin/env perl
use strict;
use warnings;

my $N = <>;
my @A = split(' ', <>);

my %pattern;
my $buf=0;
foreach my $k (@A) {
    next unless $k<0;
    $buf += $k;
    $pattern{$buf}=1;
}

my $counter=0;
foreach my $p (keys %pattern) {
    my $buf = 0;
    foreach my $i (@A) {
        next unless $i>0;
        $buf += $i;
        $counter++ if $p+$i==0;
        $counter++ if $p+$buf==0;
    }
}

print $counter;