Let $S$ be a $k$-element set.

[i](a)[/i] Find the number of mappings $f : S \to S$ such that
\[\text{(i)  } f(x) \neq x \text{ for } x \in S, \quad  \text{(ii)  } f(f(x)) = x \text{ for }x \in S.\]

[i](b)[/i] The same with the condition $\text{(i)}$ left out.