CFG for $\{0^i1^j0^k\mid i+2j=3k\}$ Edited:
I try to find a Context-Free grammer for $\{0^i1^j0^k\mid i+2j=3k\}$ as follow
\begin{align*}
    S&\to 000S0| 111B00| 01B1| 001B1|\lambda\\
    B&\to 111B00| \lambda
\end{align*}
But above grammer accept $0^21^40^3$ that doesn't belong to $L$. How I can correct above grammer?
 A: This was a difficult one!  The trick I found is to imagine reading the string from left to right, counting up the value of $i+2j$ and making sure, in the end, that it's a multiple of 3.
As you count up, every time you reach another multiple of 3, you should add another 0 to the end of the string.  In order to keep track of how close you are to a multiple of 3, your state should keep track of whether $i+2j$ has a remainder of 0, 1, or 2 (modulo 3), respectively.
Here's an expanded version of the grammar, where $S$ represents the stage where you're still reading 0s off the start of the string, and $A,B,C$ represent where you're reading 1s off the string. $A,B,C$ correspond to when the value of $i+2j$ has a remainder of 0, 1, or 2 (modulo 3).
$$\begin{align*}
S &\mapsto 000S0 \;|\; 00C \;|\; 0B\;|\; A\\
A &\mapsto 111A00 \;|\; \epsilon\\
B &\mapsto 1A0 \\
C &\mapsto 11A00\\
\end{align*}$$
Once you understand that grammar, you can condense it if you like:
$$\begin{align*}
S &\mapsto 000S0 \;|\; 0011T00 \;|\; 01T0\;|\; T\\
T & \mapsto 111T00 \;|\; \epsilon\\
\end{align*}$$
