
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 a sequence  $\{a_n\}$ :  $a_1=1, a_{n+1}=\left\{
    \begin{array}{lcr}
      a_n+n,\quad a_n\le n, 
      a_n-n,\quad a_n>n,
    \end{array}
    \right.
\quad n=1,2,\cdots.$   
Find the number of positive integers  $r$  satisfying  $a_r<r\le 3^{2017}$ .

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