Let $$\rho_S = \frac{\sum_{i=1}^{n}(R_i-\overline R)\cdot(S_i-\overline S)}{\sqrt{\sum_{i=1}^{n}(R_i-\overline R)^2\cdot \sum_{i=1}^{n}(S_i-\overline S)^2}}$$
There $R_i$ rank of $X_i$ and $S_i$ rank of $Y_i$. There $X_i$, $Y_i$ two samples.
Sort pairs $(R_i,S_i)$ by first coordinate and get pairs $(i, T_i)$
How to prove that $$\rho_S=1-\frac{12}{n^3-n}\sum_{i<j}(j-i)\cdot I(T_i>T_j)$$