fscanf(STDIN, "%d %d %d", $A, $B, $S); $ans = 0; if($A == 0){ $ans += 1; } if(abs($S-$A) <= abs($S-$B) && $A>=$S ){ $ans += $A; }elseif(abs($S-$A) > abs($S-$B) && $B>=$S && $B>$A){ $ans += $B; }elseif(abs($S-$A) <= abs($S-$B) && $S>=$A){ $ans += abs($S-$A) + $S; }elseif(abs($S-$A) > abs($S-$B) && $S>$B && $B>$A){ $ans += abs($S-$B) + $S; }elseif(abs($S-$A) > abs($S-$B) && $B>$S && $A>$S){ if($A - $S*2 +1 > 0){ $ans += $A + $B -1; }else{ $ans += $A *2 + $B -$S*2; } } echo $ans;