<s>[INST] Find the no. of ways to color the matrix.. Given a $3 \times N$ matrix and three colors $a$, $b$ and $c$. In how many ways can all the cells be colored such that no row and no column contains all the cells of same color ? 
I could not reach to any logical approach to the problem . 
 [/INST] For $i=1,2,3$ let $R_i$ denote the set of colourings such that the cells in row $i$ get the same color. 
For $j=1,\dots,N$ let $C_j$ denote the set of colourings such that the cells in column $j$ get the same color. 
Then to be found is: $$3^{3N}-|R_1\cup R_2\cup R_3\cup C_1\cup\cdots\cup C_N|\tag1$$
For this we use inclusion/exclusion combined with symmetry. First an oversight of the terms that will show up in $(1)$
$\begin{array}{cccc}
\text{term in }\left(1\right) &  &  & \text{coefficient in (1)}\\
\left|C_{1}\cap\cdots\cap C_{k}\right|=3^{3N-2k} & \text{for }k=1,\dots,N &  & \binom{N}{k}\binom{3}{0}\left(-1\right)^{k}\\
\left|R_{1}\cap C_{1}\cap\cdots\cap C_{k}\right|=3^{2N-2k+1} & \text{for }k=1,\dots,N &  & \binom{N}{k}\binom{3}{1}\left(-1\right)^{k+1}\\
\left|R_{1}\cap R_{2}\cap C_{1}\cap\cdots\cap C_{k}\right|=3^{N-k+1} & \text{for }k=1,\dots,N &  & \binom{N}{k}\binom{3}{2}\left(-1\right)^{k+2}\\
\left|R_{1}\cap R_{2}\cap R_{3}\cap C_{1}\cap\cdots\cap C_{k}\right|=3 & \text{for }k=1,\dots,N &  & \binom{N}{k}\binom{3}{3}\left(-1\right)^{k+3}\\
\left|R_{1}\right|=3^{2N+1} &  &  & \binom{N}{0}\binom{3}{1}\left(-1\right)^{1}\\
\left|R_{1}\cap R_{2}\right|=3^{N+2} &  &  & \binom{N}{0}\binom{3}{2}\left(-1\right)^{2}\\
\left|R_{1}\cap R_{2}\cap R_{3}\right|=27 &  &  & \binom{N}{0}\binom{3}{3}\left(-1\right)^{3}
\end{array}$
Working this out we finally end up with:$$18\cdot3^N+24^N-9\cdot8^N+9\cdot2^N-24\tag2$$
possibilities. Note that $(2)$ gives $0$ for $N=1$ and gives $174$ for $N=2$.
</s>