Explicit solution of Riemann-Hilbert problems for the Ernst equation