sub max{$_[$_[1]>$_[0]]} $b=2**17; ($N,$D,$K)=glob<>; @x=((0)x$b,<>); $x[$_]=$x[$_*2|$x[$_*2+1]>$x[$_*2]]for reverse 1..$b-1; for(0..$N-1){ ($L,$R)=@x[($l,$r)=($b+$_,$b+$_+$D)]; while($l>>1!=$r>>1){ $l&1||($L=max($L,$x[$l^1])); $l>>=1; $r&1&&($R=max($R,$x[$r^1])); $r>>=1 } if($-=max($L,$R)-$x[$b+$_]-$m){ $j=$_; $m+=$- } } if($m){ $k=$j; ++$k until$x[$b+$k]-$x[$b+$j]==$m; print$m*$K,"\n$j $k\n" }else{ print 0,$/ }