The function $f$ is defined for all positive integers as follows:
The function $S(n)$ is defined as $\sum_{i=1}^{n}f(i)$.
$S(8)=22$ and $S(100)=3604$.
Find $S(3^{37})$. Give the last 9 digits of your answer.