Find the number of functions $f(x)$ from $\{1, 2, 3, 4, 5\}$ to $\{1, 2, 3, 4, 5\}$ that satisfy $f(f(x)) = f(f(f(x)))$ for all $x$ in $\{1, 2, 3, 4, 5\}$.
$f(f(x))=f(f(f(x)))$ says that $f(f(x))$ is a fixed point for every $x$. So every element is a fixed point, maps to a fixed point (level $1$), or maps to a level-$1$ element (level $2$).
With $k$ fixed points and $j$ level-$1$ elements among the other $5-k$, the count is $\binom5k\sum_j\binom{5-k}jk^jj^{5-k-j}$. For $k=1,\dots,5$ this gives $205,380,150,20,1$.
Find the number of functions $f(x)$ from $\{1, 2, 3, 4, 5, 6\}$ to $\{1, 2, 3, 4, 5, 6\}$ that satisfy $f(f(x)) = f(f(f(x)))$ for all $x$ in $\{1, 2, 3, 4, 5, 6\}$. Find the remainder when this number is divided by $1000$.