read a500
read b100
read c50
read yen
a=0
while [[ $a -le $a500 ]]; do
    b=0
    while [[ $b -le $b100 ]]; do
        c=0
        while [[ $c -le $c50 ]]; do
            [[ $(( $a * 500 + $b * 100 + $c * 50 )) -eq $yen ]] && echo $a $b $c
            c=$(( $c + 1 ))
        done
        b=$(( $b + 1 ))
    done
    a=$(( $a + 1 ))
done | sort -u | wc -l