Potential energy between the two $+q$ charges: $$U_1 = \frac{1}{4\pi\epsilon_0} \frac{q \cdot q}{2a} = \frac{q^2}{8\pi\epsilon_0 a}$$ Potential energy between the first $+q$ charge and the $-2q$ charge: $$U_2 = \frac{1}{4\pi\epsilon_0} \frac{q \cdot (-2q)}{a} = -\frac{2q^2}{4\pi\epsilon_0 a} = -\frac{4q^2}{8\pi\epsilon_0 a}$$ Potential energy between the second $+q$ charge and the $-2q$ charge: $$U_3 = \frac{1}{4\pi\epsilon_0} \frac{q \cdot (-2q)}{a} = -\frac{2q^2}{4\pi\epsilon_0 a} = -\frac{4q^2}{8\pi\epsilon_0 a}$$
The total potential energy $U$ is the sum of $U_1$, $U_2$, and $U_3$: $$U = U_1 + U_2 + U_3$$ $$U = \frac{q^2}{8\pi\epsilon_0 a} - \frac{4q^2}{8\pi\epsilon_0 a} - \frac{4q^2}{8\pi\epsilon_0 a}$$ $$U = \frac{(1 - 4 - 4)q^2}{8\pi\epsilon_0 a}$$ $$U = -\frac{7q^2}{8\pi\epsilon_0 a}$$ Therefore, the potential energy of the system is $-\frac{7q^2}{8\pi\epsilon_0 a}$.