Context free grammar problem for number of a's is twice the number of b's
Let $c(w)=2\#_b(w)-\#_a(w)$. Your language is exactly $\{w\mid c(w)=0\}$.
Now consider a string $w$ with $c(w)=0$ and $|w|\ge 2$. If we can split $w$ into three parts: $w=pms$ such that $c(p)$ and $c(pm)$ have different signs, i.e., $c(p)c(pm)&lt;0$, then there are two cases:

$c(p)&gt;0$ and $c(pm)&lt;0$. Note each time we append a character to string $x$, $c(x)$ is either increased by 2 or decreased by 1, so we can always split $m$ into two parts $m_1m_2$ such that $c(pm_1)=0$.

$c(p)&lt;0$ and $c(pm)&gt;0$. In this case  we can always split $m$ into two parts $m_1m_2$ such that either $c(pm_1)=0$, or $c(pm_1)=-1$ and $m_2$ begins with $b$.


As a result, either $w=w_1w_2$ where $c(w_1)=c(w_2)=0$, or $w=w_1bw_2$ where $c(w_1)=c(w_2)=-1$.
If $w$ cannot be split into such three parts, then $w$ must be either $bw_1aa$ or $aaw_1b$ where $c(w_1)=0$.
So, if we let $S_-$  generate the language of strings where $2\#_b-\#_a=-1$, then we have the following grammar
\begin{align}
S&amp;\rightarrow SS\mid S_-bS_-\mid bSaa\mid aaSb\mid\epsilon\\
S_-&amp;\rightarrow aS\mid SS_-
\end{align}