sub min{$_[$_[1]<$_[0]]} ($A,$B,$S)=glob<>; if($S-1&&($b=abs$B-$S)<($a=abs$A-$S)){ print $b+abs($A-1)+min( $S, $a+1 ) }else{ print $a+$S }