How to solve this Combinatorial Material?

Find the total number of ways a 3×n board can be painted using 3 colors while making

sure no cells of the same row or the same column have entirely the same color. The

answer must be computed modulo 10^9+7.

It’s answer is 24^n−9×8^n+18×3^n+9×2^n−24, but how?

answer for n=1,2,3,4 respectively are 0, 174, 9750, 296490,…

questiion of hack with infy round 2 :slight_smile:

yes Q3 of round2 hackwithinfy.

search on stack overflow…