list($max_yasai, $max_niku, $c, $total) = explode(" ", trim(fgets(STDIN))); $sub_total = 0; for($yasai=0; $yasai<=$max_yasai; $yasai++){ $niku = $yasai*$c; $sub_total = $yasai + $niku; if ($sub_total > $total) echo $yasai-1."\n"; }