<?php
$N = (int)trim(fgets(STDIN));
//list($N,$Q) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$S = trim(fgets(STDIN));
$A = array_map('intval',explode(" ",trim(fgets(STDIN))));


$R = array_fill(0,$N+1,0);
for($i=0;$i<$N;$i++) {
  $R[$i+1]=$R[$i]+$A[$i];
}
$s = array_count_values($R);
$t=0;
foreach($s as $k=>$v) {
  if ($v > 1) {
    $t += $v * ($v-1)/2;
  }
}
printf("%d\n",$t);
<fsrv1: 415>
