Given an alphabet of $n$ symbolswith probabilities $p_i$ for symbol $i$, we need to encode the symbols (in a prefix-free way) to binary codewords $c(i)$ with length $\ell(c(i))$ to minimize the expression $$a(1-a)L,$$ where $$L=n^{-1}\sum_{i=1}^n \ell(c(i))$$ is the average codeword length per symbol, and $a$ is the relative frequency of $1$s in all codewords, i.e., $$ a=\frac{\sum_{i=1}^n H(c(i))}{\sum_{i=1}^n \ell(c(i))} $$
Apparently Huffman code is not optimal in this particular context. Is there a way to find the optimal code?