[proofplan]
We decompose the pooled rank of each $X_i$ into two contributions: the number of $X$-observations not exceeding it and the number of $Y$-observations not exceeding it. The first contribution sums to $1+\cdots+m$ because the $X$-observations are distinct. The second contribution counts exactly the cross-pairs with $Y_j<X_i$. Since every cross-pair satisfies exactly one of $Y_j<X_i$ or $X_i<Y_j$, subtracting from the total number $mn$ of cross-pairs gives the desired formula.
[/proofplan]
[step:Decompose each pooled rank into its $X$ and $Y$ contributions]
For each $i \in \{1,\dots,m\}$, define $A_i$ and $B_i$ by
\begin{align*}
A_i &:= \#\{k \in \{1,\dots,m\} : X_k \le X_i\}.
\end{align*}
Also define
\begin{align*}
B_i &:= \#\{j \in \{1,\dots,n\} : Y_j \le X_i\}.
\end{align*}
By the definition of the pooled rank,
\begin{align*}
R_i = A_i + B_i.
\end{align*}
Because the observations are pairwise distinct, $Y_j \le X_i$ is equivalent to $Y_j < X_i$ for every pair $(i,j)$. Hence
\begin{align*}
B_i = \#\{j \in \{1,\dots,n\} : Y_j < X_i\}.
\end{align*}
[/step]
[step:Sum the within-sample rank contributions]
Since $X_1,\dots,X_m$ are pairwise distinct, the values $A_1,\dots,A_m$ are exactly the integers $1,\dots,m$ in some order. Therefore
\begin{align*}
\sum_{i=1}^m A_i = \sum_{r=1}^m r = \frac{m(m+1)}{2}.
\end{align*}
[guided]
The number $A_i$ is the rank of $X_i$ inside the $X$-sample alone. Because the $X$-observations are pairwise distinct, no two of them can have the same within-sample rank: for each $r \in \{1,\dots,m\}$, there is exactly one $X_i$ that is the $r$-th smallest among $X_1,\dots,X_m$.
Thus the list $(A_1,\dots,A_m)$ is a permutation of $(1,\dots,m)$. Summing a permutation does not change the sum, so
\begin{align*}
\sum_{i=1}^m A_i = 1+2+\cdots+m = \sum_{r=1}^m r.
\end{align*}
The finite arithmetic sum is
\begin{align*}
\sum_{r=1}^m r = \frac{m(m+1)}{2}.
\end{align*}
Therefore
\begin{align*}
\sum_{i=1}^m A_i = \frac{m(m+1)}{2}.
\end{align*}
[/guided]
[/step]
[step:Identify the summed $Y$ contributions with cross-pairs below the $X$ observations]
Summing the decomposition $R_i=A_i+B_i$ over $i \in \{1,\dots,m\}$ gives
\begin{align*}
S_X
= \sum_{i=1}^m R_i
= \sum_{i=1}^m A_i + \sum_{i=1}^m B_i
= \frac{m(m+1)}{2} + \sum_{i=1}^m B_i.
\end{align*}
By the definition of $B_i$,
\begin{align*}
\sum_{i=1}^m B_i
= \#\{(i,j) \in \{1,\dots,m\} \times \{1,\dots,n\} : Y_j < X_i\}.
\end{align*}
Hence
\begin{align*}
\#\{(i,j) : Y_j < X_i\}
= S_X-\frac{m(m+1)}{2}.
\end{align*}
[/step]
[step:Pass from pairs with $Y_j<X_i$ to pairs with $X_i<Y_j$]
Let $C_-$ be the set
\begin{align*}
C_- &:= \{(i,j) \in \{1,\dots,m\} \times \{1,\dots,n\} : Y_j < X_i\}.
\end{align*}
Let $C_+$ be the set
\begin{align*}
C_+ &:= \{(i,j) \in \{1,\dots,m\} \times \{1,\dots,n\} : X_i < Y_j\}.
\end{align*}
For each cross-pair $(i,j)$, pairwise distinctness excludes $X_i=Y_j$, so exactly one of $Y_j<X_i$ and $X_i<Y_j$ holds. Therefore $C_-$ and $C_+$ partition the Cartesian product $\{1,\dots,m\}\times\{1,\dots,n\}$, whose cardinality is $mn$. Thus
\begin{align*}
\#C_+ = mn-\#C_-.
\end{align*}
Using the previous step and the definition $U_{m,n}=\#C_+$,
\begin{align*}
U_{m,n}
= mn-\left(S_X-\frac{m(m+1)}{2}\right)
= mn+\frac{m(m+1)}{2}-S_X.
\end{align*}
Since $S_X=\sum_{i=1}^m R_i$, this is precisely
\begin{align*}
U_{m,n}=mn+\frac{m(m+1)}{2}-\sum_{i=1}^m R_i.
\end{align*}
The same affine identity also gives
\begin{align*}
S_X = mn+\frac{m(m+1)}{2}-U_{m,n},
\end{align*}
so $U_{m,n}$ and $S_X$ determine each other uniquely.
[/step]