Prove that there are at least $4(p-3)(p-1)^{p-4}$ functions $f:S\to S$ satisfying $\sum \limits_{x\in T} x^{f(x)}\equiv a \pmod p$ This question is the third round of Iranian exam questions, which has not been answered for several years now. I think there are many people here, which may be able to solve this problem.
From AOPS

Problem:
$a$ is an integer and $p$ is a prime number and we have $p\ge 17$. Suppose that $S=\{1,2,....,p-1\}$ and $T=\{y|1\le y\le p-1,\operatorname{ord}_p(y)<p-1\}$. Prove that there are at least $4(p-3)(p-1)^{p-4}$ functions $f:S\longrightarrow S$ satisfying
$$\sum_{x\in T} x^{f(x)}\equiv a \pmod p$$

It seems that this problem can be solved by generating function, but I don't know how to start. Thank you.

first if you don't have the restriction $ord(y)<p-1$ you can choose $p-2$ elements arbitary and choose $f(g)$(g is an primary root) such that the equality work.the best think after $g$ is $g^{\pm 2}$ so choose f of other elements arbitary and choose f of this two elements such that the equality works this gave the problem bound.
