
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, \ldots, p-2\}\). Define set \( A \) as the subset comprising elements that are quadratic residues modulo \( p \), and set \( B \) as the subset comprising elements that are not quadratic residues modulo \( p \).

Determine the value of \( \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