Solution (source code)

= Solution

The <alternating group> is the <subgroup> of the <symmetric group> consisting of <even permutations>:
$$
A_n=\ker(\operatorname{sgn}:S_n\to\{1,-1\}).
$$
For a <permutation cycle> of length $l$,
$$
(a_1\ a_2\ \cdots\ a_l)=(a_1\ a_l)(a_1\ a_{l-1})\cdots(a_1\ a_2),
$$
using rightmost-first composition. Its <sign of a permutation> is therefore $(-1)^{l-1}$. Multiplicativity of the <sign homomorphism> gives
$$
\operatorname{sgn}(g)=(-1)^{\sum_j(l_j-1)}.
$$
Thus
$$
\boxed{g\in A_n\iff\text{the number of even-length cycles is even}.}
$$
Equivalently, $n-t$ is even when $t$ counts all cycles, including fixed points. Odd-length cycles contribute positive sign and impose no further restriction.