my $N = <STDIN>;
my @A = split(/ /, <STDIN>);
my %B;
my $tot = 0;
foreach my $i (0..$N-1) {
        my $AiTot = $A[$i];
        if ($AiTot == 0) {
                $B{$i} = 1 if (!defined($B{$i}));
                $B{$i+1} = 1 if (!defined($B{$i+1}));
                $B{$i+1} += $B{$i};
                $tot += $B{$i};
                next;
        }
        foreach my $j ($i+1..$N-1) {
                $AiTot += $A[$j];
                if ($AiTot == 0) {
                        $B{$i} = 1 if (!defined($B{$i}));
                        $B{$j+1} = 1 if (!defined($B{$j+1}));
                        $B{$j+1} += $B{$i};
                        $tot += $B{$i};
                        last;
                }
        }
}
print $tot;