4. The sequence $\left\{a_{n}\right\}$ has 9 terms, where $a_{1}=a_{9}=1$, and for each $i \in\{1,2, \cdots, 8\}$, we have $\frac{a_{i+1}}{a_{i}} \in\left\{2,1,-\frac{1}{2}\right\}$. Find the number of such sequences.
$(2013$, National High School Mathematics League Competition)
Prompt: Categorized Count. Answer: 491.