// File: /workspace/github_cpp_makefile_star2_O1/razimantv[P]DancingLinks/rectangles/rectangles.cpp
// Function: main
int main() {
  // Read the dimensions of the board
  int H, W;
  std::cin >> H >> W;
  if (H < 1 || W<1) {
    std::cerr << "Invalid board size" << std::endl;
    return 0;
  }
  std::vector<std::vector<int>> board(H), prefixsum(H);

  // Read the board and compute prefix sums
  for (int i = 0; i < H; ++i) {
    board[i].resize(W);
    prefixsum[i].resize(W);
    for (int j = 0; j < W; ++j) {
      std::cin >> board[i][j];
      if (board[i][j] < 0) {
        std::cerr << "Invalid board size" << std::endl;
        return 0;
      }
      prefixsum[i][j] = elem(prefixsum, i, j - 1) + elem(prefixsum, i - 1, j) -
                        elem(prefixsum, i - 1, j - 1) + (board[i][j] > 0);
    }
  }

  // Generate the possible rectangles which contain the cell and have right area
  // These will be the subsets which we try to cover the set elements with
  std::vector<std::tuple<int, int, int, int>> rectangles; // i1, i2, j1, j2
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (board[i][j] == 0) continue;
      // Loop over all possibilities of rectangle size
      for (int h = board[i][j] / (W + 1) + 1; h <= H; ++h) {
        if (board[i][j] % h) continue;
        int w = board[i][j] / h;

        // Loop over all possibilities of rectangle position
        for (int i1 = std::max(0, i - h + 1), i2 = i1 + h - 1;
             i1 <= i && i2 < H; ++i1, ++i2) {
          for (int j1 = std::max(0, j - w + 1), j2 = j1 + w - 1;
               j1 <= j && j2 < W; ++j1, ++j2) {
            // There should be only one non-zero cell in the rectangle
            int cnt = elem(prefixsum, i2, j2) - elem(prefixsum, i1 - 1, j2) -
                      elem(prefixsum, i2, j1 - 1) +
                      elem(prefixsum, i1 - 1, j1 - 1);
            if (cnt != 1) continue;
            rectangles.push_back(std::make_tuple(i1, i2, j1, j2));
          }
        }
      }
    }
  }

  // Rectangles are the rows and cells are the columns
  // Let us build the adjacency matrix now
  int R = rectangles.size(), C = H * W;
  char* mat;
  mat = new (std::nothrow) char[R * C];
  if (mat == NULL) {
    printf("Memory allocation error\n");
    return 1;
  }
  memset(mat, 0, R * C);
  for (int r = 0; r < rectangles.size(); ++r) {
    auto rect = rectangles[r];
    for (int i = std::get<0>(rect); i <= std::get<1>(rect); ++i) {
      for (int j = std::get<2>(rect); j <= std::get<3>(rect); ++j) {
        int c = i * W + j;
        mat[r * C + c] = 1;
      }
    }
  }

  // Solve using dancing links
  DancingLinks N;
  N.Create(R, C, 0, mat);
  std::vector<std::vector<int> > all;
  std::vector<int> cur;
  N.solve(all, cur, false);

  if(all.size() != 1) {
    std::cerr << "No solution found" << std::endl;
  }

  // Assign board vales as unique rectangle IDs
  for (int r = 0; r < all[0].size(); ++r) {
    auto rect = rectangles[all[0][r]];
    for (int i = std::get<0>(rect); i <= std::get<1>(rect); ++i) {
      for (int j = std::get<2>(rect); j <= std::get<3>(rect); ++j) {
        board[i][j] = r;
      }
    }
  }

  // And print the board
  for (const auto& row : board) {
    std::copy(row.begin(), row.end(),
              std::ostream_iterator<int>(std::cout, " "));
    std::cout << std::endl;
  }
  return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq 0x3c54(%rip), %rdi      # 0x4fd8
leaq 0xc(%rsp), %rbx
movq %rbx, %rsi
callq 0x10b0
leaq 0x8(%rsp), %rsi
movq %rax, %rdi
callq 0x10b0
movslq (%rbx), %rsi
testq %rsi, %rsi
jle 0x1b17
cmpl $0x0, 0x8(%rsp)
jle 0x1b17
leaq 0x68(%rsp), %rdi
leaq 0x30(%rsp), %rdx
callq 0x1c86
movslq 0xc(%rsp), %rsi
leaq 0x30(%rsp), %rdi
leaq 0x50(%rsp), %rdx
callq 0x1c86
cmpl $0x0, 0xc(%rsp)
jle 0x14d7
xorl %r15d, %r15d
leaq (%r15,%r15,2), %r12
leaq (,%r12,8), %r14
movq 0x68(%rsp), %rdi
addq %r14, %rdi
movslq 0x8(%rsp), %rsi
callq 0x1d0e
addq 0x30(%rsp), %r14
movslq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x1d0e
cmpl $0x0, 0x8(%rsp)
jle 0x14c6
leaq -0x1(%r15), %r14
leaq (%r14,%r14,2), %r13
xorl %ebp, %ebp
xorl %ebx, %ebx
movq 0x68(%rsp), %rax
movq (%rax,%r12,8), %rsi
addq %rbp, %rsi
movq 0x3b98(%rip), %rdi      # 0x4fd8
callq 0x10b0
movq 0x68(%rsp), %rax
movq (%rax,%r12,8), %rax
movl (%rax,%rbp), %eax
testl %eax, %eax
js 0x1b60
xorl %edx, %edx
movl $0x0, %ecx
testq %rbp, %rbp
je 0x1472
movq 0x30(%rsp), %rcx
movq (%rcx,%r12,8), %rcx
movl -0x4(%rcx,%rbp), %ecx
testq %r15, %r15
je 0x1483
movq 0x30(%rsp), %rdx
movq (%rdx,%r13,8), %rdx
movl (%rdx,%rbp), %edx
leaq -0x1(%rbx), %rdi
xorl %esi, %esi
orl %r14d, %edi
js 0x149b
movq 0x30(%rsp), %rsi
movq (%rsi,%r13,8), %rsi
movl -0x4(%rsi,%rbp), %esi
cmpl $0x1, %eax
sbbl $-0x1, %ecx
addl %edx, %ecx
subl %esi, %ecx
movq 0x30(%rsp), %rax
movq (%rax,%r12,8), %rax
movl %ecx, (%rax,%rbp)
incq %rbx
movslq 0x8(%rsp), %rax
addq $0x4, %rbp
cmpq %rax, %rbx
jl 0x142d
incq %r15
movslq 0xc(%rsp), %rax
cmpq %rax, %r15
jl 0x13e6
pxor %xmm0, %xmm0
movdqa %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
movl 0xc(%rsp), %r15d
testl %r15d, %r15d
jle 0x172f
movq $0x0, 0x10(%rsp)
movl 0x8(%rsp), %ecx
testl %ecx, %ecx
jle 0x1714
movq 0x10(%rsp), %rax
leaq (%rax,%rax,2), %rax
movq %rax, 0x98(%rsp)
xorl %r12d, %r12d
movq 0x68(%rsp), %rax
movq 0x98(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movl (%rax,%r12,4), %eax
testl %eax, %eax
je 0x1703
incl %ecx
cltd
idivl %ecx
cmpl 0xc(%rsp), %eax
jge 0x1703
movl %eax, %ecx
leal 0x1(%rcx), %esi
movq 0x68(%rsp), %rax
movq 0x98(%rsp), %rdx
movq (%rax,%rdx,8), %rax
movl (%rax,%r12,4), %eax
cltd
movl %esi, 0x1c(%rsp)
idivl %esi
testl %edx, %edx
je 0x1578
movl 0x1c(%rsp), %eax
jmp 0x1543
movl %eax, %esi
movq 0x10(%rsp), %rdx
movl %edx, %r10d
subl 0x1c(%rsp), %r10d
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovsl %eax, %r10d
movslq %r10d, %rax
cmpq %rax, %rdx
jle 0x1572
leal (%r10,%rcx), %r15d
incl %r15d
cmpl 0xc(%rsp), %r15d
jge 0x1572
incl %r10d
movl %r12d, %ecx
subl %esi, %ecx
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
cmovsl %eax, %ecx
addl %ecx, %esi
movl %esi, 0x20(%rsp)
movl %ecx, 0x4c(%rsp)
movslq %ecx, %rax
movq %rax, 0xb8(%rsp)
cmpq 0xb8(%rsp), %r12
jle 0x16df
movl 0x20(%rsp), %eax
cmpl 0x8(%rsp), %eax
jge 0x16df
movl %r15d, %r13d
leal -0x1(%r10), %ebx
movl 0x20(%rsp), %r14d
movl 0x4c(%rsp), %ebp
movq %rbx, 0x28(%rsp)
xorl %eax, %eax
movl %r14d, %ecx
orl %r15d, %ecx
movl %r14d, %edx
movl $0x0, %ecx
js 0x1625
movq 0x30(%rsp), %rcx
leaq (,%r13,2), %rsi
addq %r13, %rsi
movq (%rcx,%rsi,8), %rcx
movl (%rcx,%rdx,4), %ecx
movl %r14d, %esi
orl %ebx, %esi
js 0x163c
movq 0x30(%rsp), %rax
leaq (%rbx,%rbx,2), %rsi
movq (%rax,%rsi,8), %rax
movl (%rax,%rdx,4), %eax
xorl %edx, %edx
movl %ebp, %esi
orl %r15d, %esi
movl %ebp, %edi
movl $0x0, %esi
js 0x1663
movq 0x30(%rsp), %rsi
leaq (,%r13,2), %r8
addq %r13, %r8
movq (%rsi,%r8,8), %rsi
movl (%rsi,%rdi,4), %esi
movl %ebp, %r8d
orl %ebx, %r8d
js 0x167b
movq 0x30(%rsp), %rdx
leaq (%rbx,%rbx,2), %r8
movq (%rdx,%r8,8), %rdx
movl (%rdx,%rdi,4), %edx
incl %ebp
addl %esi, %eax
subl %eax, %ecx
addl %edx, %ecx
cmpl $0x1, %ecx
jne 0x16ca
movl %r14d, 0x80(%rsp)
movl %ebp, 0x84(%rsp)
movl %r15d, %ebx
movl %r15d, 0x88(%rsp)
movq %r10, %r15
movl %r10d, 0x8c(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x1f1c
movq %r15, %r10
movl %ebx, %r15d
movq 0x28(%rsp), %rbx
movl %ebp, %eax
cmpq %rax, %r12
jbe 0x16df
incl %r14d
cmpl 0x8(%rsp), %r14d
jl 0x15fc
movl %r10d, %eax
cmpq %rax, 0x10(%rsp)
jbe 0x1572
incl %r10d
incl %r15d
cmpl 0xc(%rsp), %r15d
jl 0x15cb
jmp 0x1572
incq %r12
movslq 0x8(%rsp), %rcx
cmpq %rcx, %r12
jl 0x1521
movq 0x10(%rsp), %rcx
incq %rcx
movslq 0xc(%rsp), %r15
movq %rcx, 0x10(%rsp)
cmpq %r15, %rcx
jl 0x1501
movq 0x50(%rsp), %r13
movq 0x58(%rsp), %rbx
movq %rbx, %rcx
subq %r13, %rcx
sarq $0x4, %rcx
movl 0x8(%rsp), %ebp
imull %ebp, %r15d
movl %r15d, %eax
movq %rcx, 0x28(%rsp)
imull %ecx, %eax
movslq %eax, %r12
movq 0x3850(%rip), %rsi      # 0x4fb0
movq %r12, %rdi
callq 0x11a0
testq %rax, %rax
je 0x1baa
movq %rax, %r14
movq %rbx, 0x20(%rsp)
xorl %ebx, %ebx
movq %rax, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x10a0
cmpq %r13, 0x20(%rsp)
je 0x1807
movq 0x28(%rsp), %rax
cmpq $0x1, %rax
adcq $0x0, %rax
xorl %ecx, %ecx
movq %rcx, %r8
shlq $0x4, %r8
movl 0x8(%r13,%r8), %edx
movl 0xc(%r13,%r8), %esi
cmpl %edx, %esi
jg 0x17fc
addq %r13, %r8
movl (%r8), %edi
movl 0x4(%r8), %r8d
movl %ebp, %r9d
imull %esi, %r9d
addl %r8d, %r9d
addl %ebx, %r9d
movl %edi, %r10d
subl %r8d, %r10d
incl %r10d
movl %r10d, %r11d
movl %r9d, %r12d
cmpl %edi, %r8d
jg 0x17ee
movslq %r12d, %r12
movb $0x1, (%r14,%r12)
incl %r12d
decl %r11d
jne 0x17de
leal 0x1(%rsi), %r11d
addl %ebp, %r9d
cmpl %edx, %esi
movl %r11d, %esi
jne 0x17d3
incq %rcx
addl %r15d, %ebx
cmpq %rax, %rcx
jne 0x179e
leaq 0x80(%rsp), %rdi
callq 0x20f4
leaq 0x80(%rsp), %rdi
movq 0x28(%rsp), %rsi
movl %r15d, %edx
xorl %ecx, %ecx
movq %r14, %r8
callq 0x21ec
pxor %xmm0, %xmm0
leaq 0xa0(%rsp), %rsi
movdqa %xmm0, (%rsi)
xorl %eax, %eax
movq %rax, 0x10(%rsi)
leaq 0xc0(%rsp), %rdx
movq %rax, 0x10(%rdx)
movdqa %xmm0, (%rdx)
leaq 0x80(%rsp), %rdi
xorl %ecx, %ecx
movl $0xffffffff, %r8d       # imm = 0xFFFFFFFF
callq 0x252a
movq 0xa8(%rsp), %rax
subq 0xa0(%rsp), %rax
cmpq $0x18, %rax
je 0x18c5
movq 0x376a(%rip), %rbx      # 0x4ff0
leaq 0x17c6(%rip), %rsi      # 0x3053
movl $0x11, %edx
movq %rbx, %rdi
callq 0x1130
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq 0x3738(%rip), %rdi      # 0x4ff0
callq 0x1040
movq %rax, %rdi
callq 0x10d0
movq 0xa0(%rsp), %rcx
movq (%rcx), %rax
movq 0x8(%rcx), %rcx
subq %rax, %rcx
je 0x1a40
sarq $0x2, %rcx
movq 0x50(%rsp), %rdx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %esi, %esi
movdqa 0x1718(%rip), %xmm0     # 0x3010
movdqa 0x1720(%rip), %xmm1     # 0x3020
movdqa 0x1728(%rip), %xmm2     # 0x3030
pcmpeqd %xmm3, %xmm3
movslq (%rax,%rsi,4), %r10
shlq $0x4, %r10
movl 0x8(%rdx,%r10), %edi
movslq 0xc(%rdx,%r10), %r8
cmpl %edi, %r8d
jg 0x1a34
addq %rdx, %r10
movslq 0x4(%r10), %r9
movl (%r10), %r10d
movq 0x68(%rsp), %r11
incl %edi
movl %r10d, %r14d
subl %r9d, %r14d
leaq 0x4(%r14), %rbx
andq $-0x4, %rbx
movq %r14, %xmm4
pshufd $0x44, %xmm4, %xmm4     # xmm4 = xmm4[0,1,0,1]
movq %r9, %r14
shlq $0x2, %r14
pxor %xmm2, %xmm4
cmpl %r9d, %r10d
jl 0x1a28
leaq (%r8,%r8,2), %r15
movq (%r11,%r15,8), %r15
addq %r14, %r15
addq $0xc, %r15
xorl %r12d, %r12d
movq %r12, %xmm5
pshufd $0x44, %xmm5, %xmm5     # xmm5 = xmm5[0,1,0,1]
movdqa %xmm5, %xmm6
por %xmm1, %xmm6
pxor %xmm2, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm4, %xmm7
pcmpeqd %xmm4, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %ebp
notl %ebp
testb $0x1, %bpl
je 0x19be
movl %esi, -0xc(%r15,%r12,4)
pxor %xmm3, %xmm6
pextrw $0x4, %xmm6, %ebp
testb $0x1, %bpl
je 0x19d2
movl %esi, -0x8(%r15,%r12,4)
por %xmm0, %xmm5
pxor %xmm2, %xmm5
movdqa %xmm5, %xmm6
pcmpgtd %xmm4, %xmm6
pcmpeqd %xmm4, %xmm5
pshufd $0xf5, %xmm5, %xmm7     # xmm7 = xmm5[1,1,3,3]
pand %xmm6, %xmm7
pshufd $0xf5, %xmm6, %xmm5     # xmm5 = xmm6[1,1,3,3]
por %xmm7, %xmm5
pxor %xmm3, %xmm5
pextrw $0x0, %xmm5, %ebp
testb $0x1, %bpl
je 0x1a0c
movl %esi, -0x4(%r15,%r12,4)
pextrw $0x4, %xmm5, %ebp
testb $0x1, %bpl
je 0x1a1b
movl %esi, (%r15,%r12,4)
addq $0x4, %r12
cmpq %r12, %rbx
jne 0x1976
incq %r8
cmpl %r8d, %edi
jne 0x195b
incq %rsi
cmpq %rcx, %rsi
jne 0x190c
movq 0x68(%rsp), %r12
movq 0x70(%rsp), %r13
cmpq %r13, %r12
je 0x1ad9
movq 0x356e(%rip), %rbx      # 0x4fc8
leaq 0xd8(%rsp), %r14
movq (%r12), %r15
movq 0x8(%r12), %rbp
movq %rbx, 0xd8(%rsp)
leaq 0x15eb(%rip), %rax      # 0x3065
movq %rax, 0xe0(%rsp)
subq %r15, %rbp
sarq $0x2, %rbp
testq %rbp, %rbp
jle 0x1aa9
incq %rbp
movq %r14, %rdi
movq %r15, %rsi
callq 0x20b6
addq $0x4, %r15
decq %rbp
cmpq $0x1, %rbp
jg 0x1a91
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1040
movq %rax, %rdi
callq 0x10d0
addq $0x18, %r12
cmpq %r13, %r12
jne 0x1a62
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x1af6
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
leaq 0xa0(%rsp), %rdi
callq 0x1d40
leaq 0x80(%rsp), %rdi
callq 0x2140
xorl %ebx, %ebx
jmp 0x1bbb
movq 0x34d2(%rip), %rbx      # 0x4ff0
leaq 0x151b(%rip), %rsi      # 0x3040
movl $0x12, %edx
movq %rbx, %rdi
callq 0x1130
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq %rbx, %rdi
callq 0x1040
movq %rax, %rdi
callq 0x10d0
xorl %ebx, %ebx
jmp 0x1be6
movq 0x3489(%rip), %rbx      # 0x4ff0
leaq 0x14d2(%rip), %rsi      # 0x3040
movl $0x12, %edx
movq %rbx, %rdi
callq 0x1130
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x1100
movsbl %al, %esi
movq 0x3457(%rip), %rdi      # 0x4ff0
callq 0x1040
xorl %ebx, %ebx
movq %rax, %rdi
callq 0x10d0
jmp 0x1bd2
leaq 0x151b(%rip), %rdi      # 0x30cc
callq 0x1170
movl $0x1, %ebx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x1bd2
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
leaq 0x30(%rsp), %rdi
callq 0x1d40
leaq 0x68(%rsp), %rdi
callq 0x1d40
movl %ebx, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x1c40
jmp 0x1c4f
jmp 0x1c13
movq %rax, %rbx
jmp 0x1c73
jmp 0x1c0e
jmp 0x1c0e
jmp 0x1c13
movq %rax, %rbx
jmp 0x1c69
movq %rax, %rbx
movq 0xc0(%rsp), %rdi
testq %rdi, %rdi
je 0x1c33
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
leaq 0xa0(%rsp), %rdi
callq 0x1d40
leaq 0x80(%rsp), %rdi
callq 0x2140
jmp 0x1c52
movq %rax, %rbx
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x1c69
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
leaq 0x30(%rsp), %rdi
callq 0x1d40
leaq 0x68(%rsp), %rdi
callq 0x1d40
movq %rbx, %rdi
callq 0x11c0
nop