If $a_k$ is $2$ or $4$, $i^{a_k}$ is already a real number. Since $i^3=-i^1$, the sum is a real number if $1$ and $3$ are paired up. Thus we can count the following cases on the number of $(1,3)$ pairs: $0$ pairs, $1$ pair, $2$ pairs, $3$ pairs, and $4$ pairs. Each case is quite straight forward.
Social networks