Consider the sum $$S =\sum^{2021}_{j=1} \left|\sin \frac{2\pi j}{2021}\right|.$$
The value of $S$ can be written as $\tan \left( \frac{c\pi}{d} \right)$ for some relatively prime positive integers $c, d$, satisfying $2c < d$. Find the value of $c + d$.
1. Consider the sum \( S = \sum_{j=1}^{2021} \left|\sin \frac{2\pi j}{2021}\right| \). Notice that \(\sin \frac{2\pi j}{2021} = 0\) when \(j = 2021\), so we can ignore this term.
2. Due to the absolute value, we can rewrite the sum as:
   \[
   S = 2 \sum_{j=1}^{1010} \left|\sin \frac{2\pi j}{2021}\right|
   \]
   This is because \(\sin \frac{2\pi j}{2021}\) is symmetric around \(\pi\), and thus the sum from \(j=1\) to \(1010\) is half of the total sum.
3. The sum \(\sum_{j=1}^{1010} \sin \frac{2\pi j}{2021}\) can be interpreted as the imaginary part of the sum of complex exponentials:
   \[
   \sum_{j=1}^{1010} e^{i \frac{2\pi j}{2021}}
   \]
4. This is a geometric series with the common ratio \(e^{i \frac{2\pi}{2021}}\) and can be summed using the formula for the sum of a geometric series:
   \[
   \sum_{j=1}^{1010} e^{i \frac{2\pi j}{2021}} = \frac{e^{i \frac{2\pi}{2021}} (1 - (e^{i \frac{2\pi}{2021}})^{1010})}{1 - e^{i \frac{2\pi}{2021}}}
   \]
5. Simplifying the numerator:
   \[
   1 - (e^{i \frac{2\pi}{2021}})^{1010} = 1 - e^{i \pi} = 1 + 1 = 2
   \]
   Therefore, the sum becomes:
   \[
   \frac{e^{i \frac{2\pi}{2021}} \cdot 2}{1 - e^{i \frac{2\pi}{2021}}}
   \]
6. To find the imaginary part, we can rewrite the expression:
   \[
   \frac{2 e^{i \frac{\pi}{2021}}}{1 - e^{i \frac{2\pi}{2021}}}
   \]
7. Let \(x = \frac{\pi}{2021}\). Then the expression becomes:
   \[
   \frac{2 (\cos x + i \sin x)}{1 - (\cos 2x + i \sin 2x)}
   \]
8. Using the double-angle identities, \(\cos 2x = 2\cos^2 x - 1\) and \(\sin 2x = 2\sin x \cos x\), we get:
   \[
   1 - (\cos 2x + i \sin 2x) = 1 - (2\cos^2 x - 1 + i 2\sin x \cos x) = 2(1 - \cos^2 x) - i 2\sin x \cos x = 2\sin^2 x - i 2\sin x \cos x
   \]
9. The imaginary part of the fraction is:
   \[
   \frac{2 \sin x}{2 \sin^2 x - i 2 \sin x \cos x}
   \]
10. Simplifying, we get:
    \[
    \frac{\sin x}{\sin^2 x - i \sin x \cos x}
    \]
11. The imaginary part of this expression is:
    \[
    \frac{\sin x}{2 - 2 \cos x} = \frac{\sin x}{2(1 - \cos x)} = \frac{\sin x}{2 \sin^2 \frac{x}{2}} = \cot \frac{x}{2}
    \]
12. Therefore, the desired value is:
    \[
    \cot \frac{\pi}{4042}
    \]
13. Since \(\cot \frac{\pi}{4042} = \tan \left(\frac{\pi}{2} - \frac{\pi}{4042}\right)\), we have:
    \[
    \tan \left(\frac{2021\pi - \pi}{4042}\right) = \tan \left(\frac{2020\pi}{4042}\right) = \tan \left(\frac{1010\pi}{2021}\right)
    \]
14. Thus, the value of \(S\) can be written as \(\tan \left(\frac{1010\pi}{2021}\right)\), where \(c = 1010\) and \(d = 2021\). Since \(2c < d\), we have \(2 \cdot 1010 < 2021\).

The final answer is \(\boxed{3031}\).