I am working on a combinatoric proving that the number of surjective functions $f\colon [n]\to [3]$ is equal to $1/2(3^{n-1}-2^n+1)$
I approached the problem as below Let’s consider that we have a set $\{1,2,3,\ldots,n\}$ and $\{A,B,C\}$ and we are trying to count the number of surjections by treating $A,B,C$ like buckets to fill with $1,2,3,\ldots,n$ such that no bucket should remain empty. So we can proceed by noticing that there are $3^n$ functions altogether, and $2^n$ from these functions are from $\{1,2,3\,\ldots,n\}$ to $\{A,B\}$ missing $C$ so we should not count those. Similarly we will have to remove the functions from $\{1,2,3,\ldots,n\}$ to $\{B,C\}$ missing $A$ and from $\{1,2,3\ldots,n\}$ to $\{A,C\}$ missing $B$. Each of which is $2^n$. So we are left with $3^n-3(2^n)$ but this way we have removed each of the elements $A,B,C$ thrice so need to include these again which would give us the adjusted count as $3(3^{n-1}-2^n+1)$.
but missing how to get the half instead of three times.