
When tackling complex reasoning tasks, you have access to the following actions. Use them as needed to progress through your thought process.

[ASSESS]

[ADVANCE]

[VERIFY]

[SIMPLIFY]

[SYNTHESIZE]

[PIVOT]

[OUTPUT]

You should strictly follow the format below:

[ACTION NAME]

# Your action step 1

# Your action step 2

# Your action step 3

...

Next action: [NEXT ACTION NAME]


system
For each multiple of 3, $x$, let $g(x)$ denote the greatest power of 3 that divides $x$. For example, $g(18) = 9$ and $g(27) = 27$. For each positive integer $n$, let $S_n = \sum_{k=1}^{3^{n-1}} g(3k)$. Find the greatest integer $n$ less than 1000 such that $S_n$ is a perfect square.

Present the answer in LaTex format: \boxed{Your answer}
user