
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 an arithmetic sequence $\{a_n\}$, where $a_3=5$ and $a_1+a_{19}=-18$,

$(1)$ Find the common difference $d$ and the general term $a_n$.

$(2)$ Find the sum of the first $n$ terms $S_n$ of the sequence $\{a_n\}$ and the value of $n$ that maximizes $S_n$.

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