Consider the set $A ={1,2,3,4,5, \cdots ,n} .$ Let $S$ be the set of all one one function f from $A$ to $A$, such that
$|f(1)-1|=|f(2)-2|=|f(3)-3|=.....=|f(n)-n|$
I need to find number of elements of $S$ if $n=4$.
My attempt: I could only realise that the sum of the terms (if I take each of them to be positive or negative K where K is an integer) then K necessarily has to be zero if n is odd that is each term has to be zero inside the modulus function. Nothing else can I make out. Any help appreciated .
If someone could generalise this , say, to any natural number , would be great. Say what happens if n=any natural number and at what value of n we will not get any function.
Let $k=|f(1)-1|\leq 3$
So we have only 3 such functions.