Determine the number of integers $a$ with $1 \leq a \leq 1007$ such that both $a$ and $a+1$ are quadratic residues modulo $1009$.

Let's think step by step and output the final answer within \boxed{}.
user