The Anderson-Darling test statistic is defined as
$$n\int_{-\infty}^\infty \frac{(F_n(x) - F(x))^2}{F(x)(1 - F(x))}dF(x)$$
and there is a computational formula
$$A^2 = -n - S$$
where
$$S = \sum_{k=1}^n\frac{2k-1}{n}\left(\ln F(Y_k) + \ln(1 - F(Y_{n+1-k}))\right)$$
$F_n(x)$ is the empirical distribution function and $F(x)$ is the cumulative distribution to which we are comparing the sample. $Y_k$ is the $k^\text{th}$ ranked element in the sample.
Many books or journals I found all give these two formulas but don't give the reason and derivations.
I tried to divide the integral into sub-intervals like $[Y_i, Y_{i+1}]$ to prove it, but I failed. So I want to how to prove it. Thanks!!

