<s>[INST] Get number of additions that lead to a specific sum with given summands Suppose you have $n$ variables. Each of these variables (e.g. $a$) have their own interval between $0$ and $a_i$ (whole numbers). The only rule is that all these variables have to add up to a given value $s$.
An example:
$n = 3$, so the three variables are $a$, $b$ and $c$
$a_i = 2$, so $0\le$ $a$ $\le2$
$b_i = 3$, so $0\le$ $b$ $\le3$
$c_i = 4$, so $0\le$ $c$ $\le4$
$s = 6$, so $a+b+c=6$
The 9 unique possible solutions for these given variables are the following (the order of the variables is still important, so solution 7 and solution 9 are not the same):
$a=0$    $b=2$    $c=4$
$a=0$    $b=3$    $c=3$
$a=1$    $b=1$    $c=4$
$a=1$    $b=2$    $c=3$
$a=1$    $b=3$    $c=2$
$a=2$    $b=0$    $c=4$
$a=2$    $b=1$    $c=3$
$a=2$    $b=2$    $c=2$
$a=2$    $b=3$    $c=1$
What is the correct formula or program to only get the number of unique, possible solutions for any value of $n$, $s$ and the other variables, which would be 9 in this case?
 [/INST] Let me work out for this particular case. You should be able to put it into a formula. 
If you can't, I'll see later.
We can use stars and bars with inclusion-exclusion.
Without any restrictions, there are ${6+3-1\choose 3-1} = {8\choose 2}= 28$ solutions.
To subtract cases that violate, (say) the $a_i$ restriction, pre-place $(2+1)=3$ in the $a_i$ compartment, and so on, then for combos of two, and combos of three, if possible, so
$${8\choose2} - \left[{5\choose 2} + {4\choose 2} + {3\choose 2}\right] = 9$$
Here it was not possible to violate constraints for combos of 2 or 3, but suppose we raise s to 16, then we would have
$${18\choose2} - \left[{15\choose 2} + {14\choose 2} + {13\choose 2}\right] + \left[{11\choose 2} + {10\choose 2} + {9\choose 2}\right] - \left[{6\choose 2}\right]$$ 
</s>