Task 25

solve_linear_system (256000 kilobytes, 1000 milliseconds)

Submissions: 0 · Accepted: 0

Submit code

Statement

Solve a linear system

Work in the finite field

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

You are given an \(n \times m\) matrix \(A\) and a vector \(b\) of length
\(n\). Determine whether the system

\[ A x = b \]

has a solution \(x \in \mathbb{F}_p^m\).

If there are several solutions, you may output any one of them.

Input

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

Output

If the system is inconsistent, print:

NO

Otherwise print `YES` followed by one line containing \(m\) values of a vector
\(x\) satisfying \(A x=b\) modulo \(p\).

All entries are reduced modulo \(p\); any integer representative is accepted.

Sample test

Input
2 3
1000000001 1000000003 0
1000000004 1 0
1000000003 28 

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