// File: kmyk[P]topcoder-marathon-match-100-same-color-pairs/./SameColorPairs.cpp
// Function: with_compress(int, int, int, std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>> const&, std::function<std::vector<std::array<int, 4ul>, std::allocator<std::array<int, 4ul>>> (int, int, int, std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>> const&)>)
vector<array<int, 4> > with_compress(int H, int W, int C, vector<vector<int> > const & board, function<vector<array<int, 4> > (int, int, int, vector<vector<int> > const &)> cont) {
    // check empty rows and cols
    vector<bool> is_empty_row(H, true);
    vector<bool> is_empty_col(W, true);
    REP (y, H) REP (x, W) {
        if (board[y][x] >= 0) {
            is_empty_row[y] = false;
            is_empty_col[x] = false;
        }
    }

    // construct maps
    vector<int> map_row;
    vector<int> map_col;
    REP (y, H) if (not is_empty_row[y]) map_row.push_back(y);
    REP (x, W) if (not is_empty_col[x]) map_col.push_back(x);

    // construct the compressed board
    vector<vector<int> > nboard(map_row.size(), vector<int>(map_col.size()));
    REP (y, map_row.size()) {
        REP (x, map_col.size()) {
            nboard[y][x] = board[map_row[y]][map_col[x]];
        }
    }

    // call the continuation
    vector<array<int, 4> > rects = cont(map_row.size(), map_col.size(), C, nboard);

    // make the return value
    for (auto & rect : rects) {
        int & y1 = rect[0];
        int & x1 = rect[1];
        int & y2 = rect[2];
        int & x2 = rect[3];
        y1 = map_row[y1];
        x1 = map_col[x1];
        y2 = map_row[y2];
        x2 = map_col[x2];
    }
    return rects;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x260, %rsp            # imm = 0x260
movq %r9, -0x1c8(%rbp)
movq %rdi, -0x1c0(%rbp)
movq %rdi, %rax
movq %rax, -0x1b8(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movslq -0xc(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movb $0x1, -0x51(%rbp)
leaq -0x52(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x6aa0
movq -0x1b0(%rbp), %rsi
movq -0x1a8(%rbp), %rcx
leaq -0x50(%rbp), %rdi
leaq -0x51(%rbp), %rdx
callq 0x6ac0
jmp 0x2564
leaq -0x52(%rbp), %rdi
callq 0x6b40
movslq -0x10(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movb $0x1, -0x91(%rbp)
leaq -0x92(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x6aa0
movq -0x1d8(%rbp), %rsi
movq -0x1d0(%rbp), %rcx
leaq -0x90(%rbp), %rdi
leaq -0x91(%rbp), %rdx
callq 0x6ac0
jmp 0x25b5
leaq -0x92(%rbp), %rdi
callq 0x6b40
movl $0x0, -0x98(%rbp)
movl -0x98(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x2728
movl $0x0, -0x9c(%rbp)
movl -0x9c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x2712
movq -0x20(%rbp), %rdi
movslq -0x98(%rbp), %rsi
callq 0x6b60
movq %rax, %rdi
movslq -0x9c(%rbp), %rsi
callq 0x6b80
cmpl $0x0, (%rax)
jl 0x26fc
movslq -0x98(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x6ba0
movq %rdx, -0x1e8(%rbp)
movq %rax, -0x1e0(%rbp)
jmp 0x263b
movq -0x1e8(%rbp), %rax
movq -0x1e0(%rbp), %rcx
movq %rcx, -0xb0(%rbp)
movq %rax, -0xa8(%rbp)
leaq -0xb0(%rbp), %rdi
xorl %esi, %esi
callq 0x6c00
movslq -0x9c(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x6ba0
movq %rdx, -0x1f8(%rbp)
movq %rax, -0x1f0(%rbp)
jmp 0x2688
movq -0x1f8(%rbp), %rax
movq -0x1f0(%rbp), %rcx
movq %rcx, -0xc0(%rbp)
movq %rax, -0xb8(%rbp)
leaq -0xc0(%rbp), %rdi
xorl %esi, %esi
callq 0x6c00
jmp 0x26fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x52(%rbp), %rdi
callq 0x6b40
jmp 0x2cda
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x92(%rbp), %rdi
callq 0x6b40
jmp 0x2cd1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x2cc5
jmp 0x26fe
movl -0x9c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x9c(%rbp)
jmp 0x25e4
jmp 0x2714
movl -0x98(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x98(%rbp)
jmp 0x25cb
leaq -0xd8(%rbp), %rdi
callq 0x6c50
leaq -0xf0(%rbp), %rdi
callq 0x6c50
movl $0x0, -0xf4(%rbp)
movl -0xf4(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x27e7
movslq -0xf4(%rbp), %rsi
leaq -0x50(%rbp), %rdi
callq 0x6ba0
movq %rdx, -0x208(%rbp)
movq %rax, -0x200(%rbp)
jmp 0x2779
movq -0x208(%rbp), %rax
movq -0x200(%rbp), %rcx
movq %rcx, -0x108(%rbp)
movq %rax, -0x100(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x6c70
xorb $-0x1, %al
testb $0x1, %al
jne 0x27a9
jmp 0x27d1
leaq -0xd8(%rbp), %rdi
leaq -0xf4(%rbp), %rsi
callq 0x6ca0
jmp 0x27be
jmp 0x27d1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x2cad
jmp 0x27d3
movl -0xf4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xf4(%rbp)
jmp 0x274a
movl $0x0, -0x10c(%rbp)
movl -0x10c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jge 0x2880
movslq -0x10c(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x6ba0
movq %rdx, -0x218(%rbp)
movq %rax, -0x210(%rbp)
jmp 0x2823
movq -0x218(%rbp), %rax
movq -0x210(%rbp), %rcx
movq %rcx, -0x120(%rbp)
movq %rax, -0x118(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x6c70
xorb $-0x1, %al
testb $0x1, %al
jne 0x2853
jmp 0x286a
leaq -0xf0(%rbp), %rdi
leaq -0x10c(%rbp), %rsi
callq 0x6ca0
jmp 0x2868
jmp 0x286a
jmp 0x286c
movl -0x10c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10c(%rbp)
jmp 0x27f1
leaq -0xd8(%rbp), %rdi
callq 0x6d10
movq %rax, -0x230(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x6d10
movq %rax, -0x228(%rbp)
leaq -0x151(%rbp), %rdi
movq %rdi, -0x220(%rbp)
callq 0x6d30
movq -0x228(%rbp), %rsi
movq -0x220(%rbp), %rdx
leaq -0x150(%rbp), %rdi
callq 0x6d50
jmp 0x28d5
leaq -0x152(%rbp), %rdi
movq %rdi, -0x238(%rbp)
callq 0x6dc0
movq -0x230(%rbp), %rsi
movq -0x238(%rbp), %rcx
leaq -0x138(%rbp), %rdi
leaq -0x150(%rbp), %rdx
callq 0x6de0
jmp 0x290b
leaq -0x152(%rbp), %rdi
callq 0x6e60
leaq -0x150(%rbp), %rdi
callq 0x6e80
leaq -0x151(%rbp), %rdi
callq 0x6ee0
movl $0x0, -0x158(%rbp)
movl -0x158(%rbp), %eax
movl %eax, -0x23c(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x6d10
movq %rax, %rcx
movl -0x23c(%rbp), %eax
cmpl %ecx, %eax
jge 0x2a8a
movl $0x0, -0x15c(%rbp)
movl -0x15c(%rbp), %eax
movl %eax, -0x240(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x6d10
movq %rax, %rcx
movl -0x240(%rbp), %eax
cmpl %ecx, %eax
jge 0x2a74
movq -0x20(%rbp), %rax
movq %rax, -0x258(%rbp)
movslq -0x158(%rbp), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x6f00
movq -0x258(%rbp), %rdi
movslq (%rax), %rsi
callq 0x6b60
movq %rax, -0x250(%rbp)
movslq -0x15c(%rbp), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x6f00
movq -0x250(%rbp), %rdi
movslq (%rax), %rsi
callq 0x6b80
movl (%rax), %eax
movl %eax, -0x244(%rbp)
movslq -0x158(%rbp), %rsi
leaq -0x138(%rbp), %rdi
callq 0x6f20
movq %rax, %rdi
movslq -0x15c(%rbp), %rsi
callq 0x6f00
movl -0x244(%rbp), %ecx
movl %ecx, (%rax)
movl -0x15c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x15c(%rbp)
jmp 0x296c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x2a63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x152(%rbp), %rdi
callq 0x6e60
leaq -0x150(%rbp), %rdi
callq 0x6e80
leaq -0x151(%rbp), %rdi
callq 0x6ee0
jmp 0x2cad
jmp 0x2a76
movl -0x158(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x158(%rbp)
jmp 0x2939
movb $0x0, -0x15d(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x6d10
movl %eax, -0x25c(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x6d10
movq -0x1c0(%rbp), %rdi
movq -0x1c8(%rbp), %rsi
movl -0x25c(%rbp), %edx
movl %eax, %ecx
movl -0x14(%rbp), %r8d
leaq -0x138(%rbp), %r9
callq 0x6f40
jmp 0x2ad7
movq -0x1c0(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rdi
callq 0x6fb0
movq %rax, -0x170(%rbp)
movq -0x168(%rbp), %rdi
callq 0x6fe0
movq %rax, -0x178(%rbp)
leaq -0x170(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x7010
testb $0x1, %al
jne 0x2b27
jmp 0x2c48
leaq -0x170(%rbp), %rdi
callq 0x7050
movq %rax, -0x180(%rbp)
movq -0x180(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x7070
movq %rax, -0x188(%rbp)
movq -0x180(%rbp), %rdi
movl $0x1, %esi
callq 0x7070
movq %rax, -0x190(%rbp)
movq -0x180(%rbp), %rdi
movl $0x2, %esi
callq 0x7070
movq %rax, -0x198(%rbp)
movq -0x180(%rbp), %rdi
movl $0x3, %esi
callq 0x7070
movq %rax, -0x1a0(%rbp)
movq -0x188(%rbp), %rax
movslq (%rax), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x6f00
movl (%rax), %ecx
movq -0x188(%rbp), %rax
movl %ecx, (%rax)
movq -0x190(%rbp), %rax
movslq (%rax), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x6f00
movl (%rax), %ecx
movq -0x190(%rbp), %rax
movl %ecx, (%rax)
movq -0x198(%rbp), %rax
movslq (%rax), %rsi
leaq -0xd8(%rbp), %rdi
callq 0x6f00
movl (%rax), %ecx
movq -0x198(%rbp), %rax
movl %ecx, (%rax)
movq -0x1a0(%rbp), %rax
movslq (%rax), %rsi
leaq -0xf0(%rbp), %rdi
callq 0x6f00
movl (%rax), %ecx
movq -0x1a0(%rbp), %rax
movl %ecx, (%rax)
leaq -0x170(%rbp), %rdi
callq 0x70a0
jmp 0x2b0b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x138(%rbp), %rdi
callq 0x7120
jmp 0x2cad
movb $0x1, -0x15d(%rbp)
testb $0x1, -0x15d(%rbp)
jne 0x2c64
movq -0x1c0(%rbp), %rdi
callq 0x70c0
leaq -0x138(%rbp), %rdi
callq 0x7120
leaq -0xf0(%rbp), %rdi
callq 0x6e80
leaq -0xd8(%rbp), %rdi
callq 0x6e80
leaq -0x90(%rbp), %rdi
callq 0x7180
leaq -0x50(%rbp), %rdi
callq 0x7180
movq -0x1b8(%rbp), %rax
addq $0x260, %rsp            # imm = 0x260
popq %rbp
retq
leaq -0xf0(%rbp), %rdi
callq 0x6e80
leaq -0xd8(%rbp), %rdi
callq 0x6e80
leaq -0x90(%rbp), %rdi
callq 0x7180
leaq -0x50(%rbp), %rdi
callq 0x7180
movq -0x60(%rbp), %rdi
callq 0x2340
nopw %cs:(%rax,%rax)