
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
Given the sequence \(\{a_n\}\) defined by
\[ 
\begin{array}{l}
a_{1} = 1, \\
a_{n+1} = 
\begin{cases} 
a_{n} + n, & \text{if } a_{n} \leq n; \\
a_{n} - n, & \text{if } a_{n} > n 
\end{cases} \quad (n = 1,2,\ldots).
\end{array}
\]
find the number of positive integers \(r\) that satisfy \(a_r < r \leq 3^{2017}\).

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