Task 28

rref (256000 kilobytes, 1000 milliseconds)

Submissions: 0 · Accepted: 0

Submit code

Statement

Reduced row echelon form

All arithmetic is performed in

\[ \mathbb{F}_p, \qquad p = 1\,000\,000\,007. \]

You are given an \(n\times m\) matrix \(A\). Output its **reduced row echelon
form** (RREF), obtained using elementary row operations over \(\mathbb{F}_p\).

The RREF is unique. In particular, every nonzero row begins with a \(1\), that
leading \(1\) is the only nonzero entry in its column, and leading positions
move strictly to the right as the rows move down.

Input

The first line contains \(n\) and \(m\). The next \(n\) lines contain \(A\),
with \(m\) entries per line.

Output

Print the RREF of \(A\) as \(n\) rows with \(m\) integers per row. Every entry
is interpreted modulo \(p\); any integer representative is accepted.

Sample test

Input
2 3
1000000003 8 1000000001
1000000000 4 999999998

Output is validated by a special checker; any valid answer is accepted.