Cramer von Mises test statistic I am trying to derive the Cramer von Mises test statistic 
$$nC_{n}=\frac{1}{12n}+\sum_{i=1}^{n}\left(U_{(i)}-\frac{2i-1}{2n}\right)^2$$
where $U_{(i)}=F_{0}(X_{(i)})$ the order statistics
from the original 
$$C_{n}:=\int (\hat{F}_{n}(t)-F_{0}(t))^2dF_{0}(t)$$
Could anyone help me with this? I'm especially confused as to how to write the integral as a sum here.

Let $X_1,\dots,X_n$ be a random sample of size $n$ from $f(x)$.
  The empirical CDF is
  \begin{equation}
    \hat{F}_n(x) = \frac{1}{n} \sum_{i=1}^n I(X_i \leq x)
    = \begin{cases}
      0, & x < X_{1:n},\\
      i/n, & X_{i:n} \leq x < X_{i+1:n},\\
      1, & X_{n:n} \leq x.
    \end{cases}
  \end{equation}
Let $U_i = F_0(X_{i:n})$, then
\begin{align*}
    C_n &\triangleq \int \left[ \hat{F}_n (x) - F_0(x) \right]^2 \,\mathrm{d}{F_0(x)}
\\
&=\int_{-\infty}^{X_{1:n}} \left[ - F_0(x) \right]^2 \,\mathrm{d}{F_0(x)}
    + \sum_{i=1}^{n-1} \int_{X_{i:n}}^{X_{i+1:n}} \left[ \frac{i}{n} - F_0(x) \right]^2 \,\mathrm{d}{F_0(x)} + \int_{X_{n:n}}^{\infty} \left[ 1 - F_0(x) \right]^2 \,\mathrm{d}{F_0(x)}
    \\
    &= \frac{1}{3} U_1^3
    + \frac{1}{3} \sum_{i=1}^{n-1} \left[
        \left( U_{i+1} - \frac{i}{n} \right)^3
      - \left( U_{i} - \frac{i}{n} \right)^3
    \right]
    - \frac{1}{3} (U_n - 1)^3
    \\
    &= \frac{1}{3} U_1^3
    + \frac{1}{3} \sum_{i=1}^{n-1} \left[
      U_{i+1}^3 - U_{i}^3
      + \frac{3 i^2}{n^2} \left(U_{i+1} - U_i\right)
      - \frac{3 i}{n} \left(U_{i+1}^2 - U_i^2\right)
    \right]
    - \frac{1}{3} (U_n - 1)^3
    \\
    &= \frac{1}{3} U_1^3
    + \frac{1}{3} U_n^3 - \frac{1}{3} U_1^3
    + \left( U_n - \sum_{i=1}^n \frac{2 i - 1}{n^2} U_i \right)
    - \left( U_n^2 - \sum_{i=1}^n \frac{1}{n} U_i^2 \right)
    - \frac{1}{3} (U_n - 1)^3
    \\
    &= \frac{1}{3} + \frac{1}{n} \sum_{i=1}^n \left( U_i^2 - \frac{2 i - 1}{n} U_i \right)
    \\
    &= \frac{1}{3} + \frac{1}{n} \sum_{i=1}^n \left( U_i - \frac{2 i - 1}{2 n} \right)^2
    - \frac{1}{n} \sum_{i=1}^n \left( \frac{2 i - 1}{2 n} \right)^2
    \\
    &= \frac{1}{12 n^2} + \frac{1}{n} \sum_{i=1}^n \left( U_i - \frac{2 i - 1}{2 n} \right)^2.
    \qquad
    \left[\text{by}~\sum_{i=1}^n (2 i - 1)^2 = \frac{1}{3} n (4 n^2 - 1) \right]
\end{align*}
