xargs -n4 | while read A B C X; do
    echo "A=$A B=$B C=$C X=$X" 1>&2
    if [ $C -gt 0 ]; then
        yes | cat -n | head -`expr $A + 1` | while read i _; do
            yes | cat -n | head -`expr $B + 1` | while read j _; do
                echo \( $X - $i \* 500 - $j \* 100 + 600 \) / 50 / $C
            done | bc -l
        done | grep -v ^- | sed -e 's/$/ + 0.999999999/' | bc -l | sed -e 's/^\./0./' | grep '^[01]' | wc -l
    else
        yes | cat -n | head -`expr $A + 1` | while read i _; do
            yes | cat -n | head -`expr $B + 1` | while read j _; do
                echo \( $X - $i \* 500 - $j \* 100 + 600 \)
            done | bc
        done | grep '^0$' | wc -l
    fi
done
