sub f{ my($i,$j,$s)=@_; $s+=$a[$_%$n]for$i..$j-1; $s } $n=<>; ($s,$t)=glob<>; --$s;--$t; ($s,$t)=($t,$s)if$s>$t; @a=glob<>; $z=f($a=$s+$t+$n+2>>1,$b=$s+$t+$n*2+1>>1)- f($c=$s+$t+2>>1,$d=$s+$t+$n+1>>1); $z+=abs(($a==$d?0:$a[$d])-($c==$b-$n?0:$a[$b-$n])); print $z;