$P(x)$ is a polynomial of degree $3n$ such that:

\[
\begin{align*}
P(0) = P(3) = \cdots &= P(3n) = 2, \\
P(1) = P(4) = \cdots &= P(3n-2) = 1, \\
P(2) = P(5) = \cdots &= P(3n-1) = 0, \\
\text{and } & P(3n+1) = 730.
\end{align*}
\]

Determine $n$.

Let's think step by step and output the final answer within \boxed{}.
user