6. The password setting for a certain lock involves assigning one of the two numbers, 0 or 1, to each vertex of a regular $n$-sided polygon $A_{1} A_{2} \cdots A_{n}$, and coloring each vertex either red or blue, such that for any two adjacent vertices, at least one of the number or color is the same. How many different password settings are there for this lock?
(2010, National High School Mathematics League Competition)
Hint: Recursive method. Answer: $3^{n}+(-1)^{n}+2$.