Problem A5 in the 1985 Putnam Competition: Let $I_m=\int_0^{2\pi}\cos(x)\cos(2x)\cdots\cos(mx)dx$. For which integers $m$, $1\leq m\leq10$, do we have $I_m\neq0$?
The solution rewrites $\cos(x)=\frac{e^{ikx}+e^{-ikx}}{2}$. It then says that $$I_m=\int_0^{2\pi}\prod_{k=1}^m{\biggl(\frac{e^{ikx}+e^{-ikx}}{2}\biggr)}=2^{-m}\sum_{\epsilon_{k}=\pm1}\int_0^{2\pi}{e^{i(\epsilon_1+2\epsilon_2+\cdots+m\epsilon_m)x}}$$ Where the sum ranges over the $2^m$ $m$-tuples $(\epsilon_1,\ldots,\epsilon_m)$ with $\epsilon_k=\pm1$ for every $k$.
My question is, how do you make sense of the last step? Why is this true: $$\prod_{k=1}^m{(e^{ikx}+e^{-ikx})}=\sum_{\epsilon_{k}=\pm1}{e^{i(\epsilon_1+2\epsilon_2+\cdots+m\epsilon_m)x}}$$