Let $S=\{1,...,n\}$, I am looking at number of functions functions $f:S\to S$ such that there exists $i \in S$ such that $$|f^{-1}(\{i\})|=i$$
I am guessing I am supposed to use PIE (Principle of Inclusion and Exclusion)
I let $X=\{f:S\to S\}$. My attempt is to define $A_i=\{f\in X;|f^{-1}(\{i\})|=i\}$.
It can be computed that $|A_i|=\binom{n}{i}(n-1)^{n-i}$.
Similarly, $|A_i\cap A_j|=\binom{n}{i}\binom{n-i}{j}(n-2)^{n-i-j}$.
but I am not sure how to proceed.
Let $a_n, n\geq 1$ denote the number of functions $f:[n]\to[n]$ such that there exists $i\in [n]$ such that \begin{align*} |f^{-1}(\{i\})|=i \end{align*}
Calculation of $a_n$ for small numbers $n$ gives \begin{align*} (a_n)_{n\geq 1}=(1,3,16,147,1\,756,\ldots) \end{align*} which is archived in OEIS as A331538 (thanks to @MarkoRiedel).
General expression:
Using PIE we can write \begin{align*} \color{blue}{a_n}&=\sum_{j=1}^n\left|A_j\right|-\sum_{{1\leq j_1<j_2\leq n}\atop{j_1+j_2\leq n}}\left|A_{j_1}\cap A_{j_2}\right|\\ &\qquad+\cdots+(-1)^{k-1}\sum_{{1\leq j_1< j_2<\ldots<j_k\leq n}\atop{j_1+j_2+\cdots+j_k\leq n}}\left|A_{j_1}\cap A_{j_2}\cap \cdots\cap A_{j_k}\right|\pm\cdots\\ &=\sum_{j=1}^n\binom{n}{j}(n-1)^{n-j}-\sum_{{1\leq j_1<j_2\leq n}\atop{j_1+j_2\leq n}}\binom{n}{j_1,j_2,n-j_1-j_2}(n-2)^{n-j_1-j_2}\\ &\quad+\cdots+(-1)^{k-1}\sum_{{1\leq j_1<\ldots<j_k\leq n}\atop{j_1+\cdots+j_k\leq n}}\binom{n}{j_1,\ldots,j_k,n-j_1-\cdots-j_k}(n-k)^{n-j_1-\cdots -j_k}\pm\cdots\\ \end{align*}
Here we use the multinomial coefficient notation $\binom{n}{j_1,\ldots,j_k}=\frac{n!}{j_1!\cdots j_k!}$.
Note: The sequence $\left(\sum_{j=1}^n\left|A_j\right|\right)_{n\geq 1}=(1, 3, 19, 175, 2\,101,\ldots)$ of the main terms is archived in OEIS as A045531.