Let $S$ be a finite set and $f: S \to S$ be a function. Let $k = |f(S)|$ and let $\alpha$ be the partition of $S$ into $f$-fibers, i.e. $\alpha = \{ \alpha_t \}_{t \in f(S)}$ where $\alpha_t = f^{-1}(\{t \})$. Then $\sum_{t \in f(S)} |\alpha_t|$ is a partition of $|S|$ with $k$ nonempty parts.
I would really like to have a nice expression, or indeed bijection, for the number of pairs $g, h: S \to S$ such that $f = g \circ h$. These can be enumerated in a naive way with Bell and Stirling numbers of the second kind, by considering that the $h$-fibers need to refine $\alpha$ and $g(S)$ needs to contain $f(S)$ (and the $g$-fibers need to partition $h(S)$ in the right way), but the expression is not enlightening at all. If there's some nice identity or known bijective correspondence to which someone could point me, I'd be very grateful.