My thought : Total $n$ letter words that can be formed by repeating $4$ letters is number of onto functions from set of $n$ elements to set of $4$ elements.
This is equal to $4^n-4\times 3^n+6\times 2^n-4$. But I cannot count how many times a and b will come together. Please help.
Assuming you don’t have to use all the letters, then let $A_n$ be the number of such words that end in $a$ or $b,$ and $C_n$ be the words that don’t. Then $A_0=0,C_0=1,$ and $$A_{n+1}=A_n+2C_{n}\\C_{n+1}=2A_n+2C_n$$
Or:
$$\begin{pmatrix}A_n\\C_n\end{pmatrix}=\begin{pmatrix}1&2\\2&2\end{pmatrix}^n\begin{pmatrix}0\\1\end{pmatrix}$$
The number you want is $D_n=A_n+C_n.$ You can get a closed formula by diagonalizing the matrix, or by representing the $(0,1)^T$ as a sum of eigenvectors of the matrix.
You can get a linear recurrence:
$$D_{n+1}=3D_n+2D_{n-1}, D_0=1,D_1=4$$
You can find a direct argument for that recurrence.
The exact answer I get is:
$$D_n=\frac{17+5\sqrt{17}}{34}\left(\frac{3+\sqrt{17}}2\right)^n+ \frac{17-5\sqrt{17}}{34}\left(\frac{3-\sqrt{17}}2\right)^n$$
Which can also be written as the nearest integer to: $$\frac{17+5\sqrt{17}}{34}\left(\frac{3+\sqrt{17}}2\right)^n\approx 1.106\cdot 3.562^n$$
If you really must use all the letters, you’ll need to add this sort of computation to an inclusion-exclusion argument. You’ll have to use a similar argument for subtracting the case when one of $c$ or $d$ is not in the string.