Under construction

Still being built. Things may change

Sum

Time limit3sMemory limit512 MB

Summary
Given an n by m matrix modulo a prime p, find K rank-one style pairs of vectors b and c whose sum of outer products equals the matrix, with nonzero row and column sums.
Level

Hard8 of 10

Topics
Matrix, Math, Implementation
Solved
No attempts yet

Statement

Given a rectangular array aa of size n×mn \times m and a prime number pp, find two rectangular arrays, bb of size K×nK \times n and cc of size K×mK \times m, such that:

  1. 0≤bi,j<p0 \le b_{i,j} < p (∀1≤i≤K,1≤j≤n\forall 1 \le i \le K, 1 \le j \le n)
  2. 0≤ci,j<p0 \le c_{i,j} < p (∀1≤i≤K,1≤j≤m\forall 1 \le i \le K, 1 \le j \le m)
  3. ∑j=1nbi,j≥1\sum_{j=1}^{n} b_{i,j} \ge 1 (∀1≤i≤K\forall 1 \le i \le K)
  4. ∑i=1mci,j≥1\sum_{i=1}^{m} c_{i,j} \ge 1 (∀1≤j≤K\forall 1 \le j \le K)
  5. ∑l=1Kbl,i⋅cl,j≡ai,j(modp)\sum_{l=1}^{K} b_{l,i} \cdot c_{l,j} \equiv a_{i,j} \pmod{p} (∀1≤i≤n,1≤j≤m\forall 1 \le i \le n, 1 \le j \le m)

Input

The first line contains four positive integers nn, mm, KK, pp (1≤n⋅m,K⋅n,K⋅m≤1051 \le n \cdot m, K \cdot n, K \cdot m \le 10^5; 2≤p≤109+72 \le p \le 10^9 + 7; pp is prime).

The ii-th of the following nn lines contains mm integers ai,1,ai,2,…,ai,ma_{i,1}, a_{i,2}, \ldots, a_{i,m} (0≤ai,j<p0 \le a_{i,j} < p).

Output

If there is no solution, print a line No solution!.

Otherwise, print KK lines. The ii-th line contains n+mn + m integers bi,1,bi,2,…,bi,n,ci,1,ci,2,…,ci,mb_{i,1}, b_{i,2}, \ldots, b_{i,n}, c_{i,1}, c_{i,2}, \ldots, c_{i,m}.

If there are several possible answers, print any one of them.

Examples2

  1. Example 1

    Input
    1 1 1 97
    0
    
    Expected output
    No solution!
    
  2. Example 2

    Input
    3 3 1 97
    1 2 3
    2 4 6
    3 6 9
    
    Expected output
    1 2 3 1 2 3