
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 as
\[ 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, \cdots). \]

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