
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
Let \( p = 4n + 1 \) (where \( n \in \mathbf{Z}_{+} \)) be a prime number. Consider the set \(\{1, 3, 5, \cdots, p-2\}\). Define two sets: \( A \), consisting of elements that are quadratic residues modulo \( p \), and \( B \), consisting of elements that are not quadratic residues modulo \( p \). Find \[ \left( \sum_{a \in A} \cos \frac{a \pi}{p} \right)^2 + \left( \sum_{b \in B} \cos \frac{b \pi}{p} \right)^2. \]

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