AoPS Wiki:Problem of the Day/June 25, 2011

Let $1,4 \ldots$ and $9,16 \ldots$ be two arithmetic progressions. The set $S$ is the union of the first $2004$ terms of each sequence. How many distinct numbers are in $S$?