read n3 a b
sum=0

if (( n3 == 10000 )); then
    n3=9999
    (( a <= 1 && 1 <= b )) && sum=10000
fi

for (( k3 = 0; k3 <= n3; k3 += 1000 )); do
    n2=$(( n3 - k3 < 999 ? n3 - k3 : 999 ))
    for (( k2 = 0; k2 <= n2; k2 += 100 )); do
        n1=$(( n2 - k2 < 99 ? n2 - k2 : 99 ))
        for (( k1 = 0; k1 <= n1; k1 += 10 )); do
            n0=$(( n1 - k1 < 9 ? n1 - k1 : 9 ))
            for (( k0 = 0; k0 <= n0; k0 += 1 )); do
                dsum=$(( k3 / 1000 + k2 / 100 + k1 / 10 + k0 ))
                (( dsum >= a && dsum <= b )) && sum=$(( sum + k3 + k2 + k1 + k0 ))
            done
        done
    done
done
echo ${sum}
