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