Let $S=\{1,2,3,4,\dotsc,N\}$ and $X=\{ f: S \rightarrow S \mid x < y \Rightarrow f(x)\leqslant f(y)\}$. Then $|X|$ is equal to what? A trick question about combinators (Stars and Bars)- Need some explanations.

Let $S=\{1,2,3,4,\dotsc,N\}$ and $X=\{ f: S \rightarrow S\mid x < y  \Rightarrow f(x)\leqslant f(y)\}$. Then $|X|$ is equal to what?

How to use Stars and Bars here? Thank you very much. 
 A: Hint. Let $x_1:=f(1)-1$ and $x_i:=f(i)-f(i-1)$ for $i=2,\dots,N$. Then $x_i\geq 0$ and 
$$x_1+x_2+\dots +x_{N}=f(N)-1\leq N-1$$
or 
$$x_1+x_2+\dots +x_{N}+x_{N+1}=N-1$$
where $x_{N+1}:=N-f(N)\geq 0$. 
Do you know how to enumerate the solutions of the above equation by using Stars and Bars?
P.S. See the OEIS sequence A001700.
A: Note that each function $f$ in $X$ can be represented by a particular way of placing $N$ indistinguishable balls in $N$ boxes labeled $1,\ldots,N$. In particular, the number of balls in box $n$ is the number of elements of $S$ that get mapped to $n$ by $f$.
For example, if $f(1)=1$, $f(2)=3$, $f(3)=3$, and $f(4)=4$, this would correspond to one balls in box $1$, two balls in box $3$, one ball in box $4$, and no balls in box $2$.
Note that this correspondence is bijective: any placement of the $N$ balls in $N$ boxes corresponds with some function $f$ in $X$. So $|X|$ is the number of ways you can put $N$ balls in $N$ labeled boxes.
Then you can use stars and bars can be used to count this: there are $N$ stars and $N-1$ bars.
