For a positive integer $n$, define $d(n)$ to be the sum of the digits of $n$ when written in binary. For example, $d(13) = 1 + 1 + 0 + 1 = 3$. Let
\[
S = \sum_{k=1}^{2020} (-1)^{d(k)} k^3.
\]
Determine $S$ modulo $2020$.

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