6. If from the set $S=\{1,2, \cdots, 20\}$, we take a three-element subset $A=\left\{a_{1}, a_{2}, a_{3}\right\}$, such that it simultaneously satisfies: $a_{2}-a_{1} \geqslant 5,4 \leqslant a_{3}-a_{2} \leqslant 9$, then the number of all such subsets $A$ is $\qquad$ (answer with a specific number).
6.251.
$a_{2}-a_{1} \geqslant 5 \Leftrightarrow\left(a_{2}-4\right)-a_{1} \geqslant 1$,
$4 \leqslant a_{3}-a_{2} \leqslant 9 \Leftrightarrow 1 \leqslant\left(a_{3}-7\right)-\left(a_{2}-4\right) \leqslant 6$.
Let $a_{1}^{\prime}=a_{1}, a_{2}^{\prime}=a_{2}-4, a_{3}^{\prime}=a_{3}-7$, then $a_{1}^{\prime}, a_{2}^{\prime}, a_{3}^{\prime} \in \mathbf{Z}$, satisfying $1 \leqslant a_{1}^{\prime}<a_{2}^{\prime}<a_{3}^{\prime} \leqslant 13$, and
$$
a_{3}^{\prime}-a_{2}^{\prime} \leqslant 6 .
$$

Obviously, the sets of $\left(a_{1}, a_{2}, a_{3}\right)$ and the new sets of $\left(a_{1}^{\prime}, a_{2}^{\prime}, a_{3}^{\prime}\right)$ form a one-to-one correspondence. Below, we count the number of $\left(a_{1}^{\prime}, a_{2}^{\prime}, a_{3}^{\prime}\right)$ that satisfy (1), for which we categorize and count.
(1) If $a_{2}^{\prime} \leqslant 7$, then $1 \leqslant a_{1}^{\prime}<a_{2}^{\prime} \leqslant 7,1 \leqslant a_{3}^{\prime}-a_{2}^{\prime} \leqslant 6$. When $a_{1}^{\prime}, a_{2}^{\prime}$ are determined, $a_{3}^{\prime}-a_{2}^{\prime}$ has 6 possible values $\left(a_{3}^{\prime}-a_{2}^{\prime}=1,2,3,4,5,6\right)$, so, $\left(a_{1}^{\prime}, a_{2}^{\prime}, a_{3}^{\prime}\right)$ has
$$
6 \times C_{7}^{2}=6 \times \frac{7 \times 6}{2}=126 \text { (sets). }
$$
(2) If $8 \leqslant a_{2}^{\prime} \leqslant 12$, then $1 \leqslant a_{3}^{\prime}-a_{2}^{\prime} \leqslant 13-a_{2}^{\prime}(\leqslant 5<6)$. When $a_{2}^{\prime}\left(8 \leqslant a_{2}^{\prime} \leqslant 12\right)$ is determined, $a_{1}^{\prime}$ has $a_{2}^{\prime}-1$ possible values, and $a_{3}^{\prime}-a_{2}^{\prime}$ has $13-a_{2}^{\prime}$ possible values $\left(a_{3}^{\prime}-a_{2}^{\prime}=1,2, \cdots, 13-\right.$ $\left.a_{2}^{\prime}\right)$, so, $\left(a_{1}^{\prime}, a_{2}^{\prime}, a_{3}^{\prime}\right)$ has
$$
\begin{array}{l}
\sum_{a_{2}^{\prime}=8}^{12}\left(a_{2}^{\prime}-1\right)\left(13-a_{2}^{\prime}\right) \\
=7 \times 5+8 \times 4+9 \times 3+10 \times 2+11 \times 1 \\
=125 \text { (sets). }
\end{array}
$$

In summary, the number of $\left(a_{1}, a_{2}, a_{3}\right)$ is 251.