svd_real

(256000 kilobytes, 1000 milliseconds)

Submissions: 0 · Accepted: 0

Submit code

Statement

Singular value decomposition

This task uses real numbers, not modular arithmetic. Given a real (n\times m)
matrix (A), output a thin singular value decomposition

\[ A=U\Sigma V^T. \]

Let (r=\min(n,m)). (U) has shape (n\times r), (V) has shape
(m\times r), and \(\Sigma=\operatorname{diag}(\sigma_1,\ldots,\sigma_r)).
The singular values must be non-negative and sorted in non-increasing order.

The checker accepts small floating-point error. Signs are not fixed: replacing
one column of (U) and the corresponding column of (V) by their negatives is
equivalent.

Input

The first line contains (n,m). The next (n) lines contain real entries of
(A).

Output

Print (U) as (n) rows of (r) values, then the (r) singular values, then
(V) as (m) rows of (r) values. Columns of (U) and (V) must be
orthonormal, and the reconstruction error must be at most (10^{-5}).

Constraints