// File: kmyk[P]codevs-for-student-2016/Main.cpp
// Function: std::vector<std::pair<point_t, int>, std::allocator<std::pair<point_t, int>>> simulation::collect_erases<19ul, 10ul>(primitive::blocks_t<19ul, 10ul> const&, std::vector<point_t, std::allocator<point_t>> const&)
vector<pair<point_t,int> > collect_erases(blocks_t<H,W> const & field, vector<point_t> const & modified_blocks) {
        static const int dy[] = { -1, -1, 0, 1 }; // 下 右下 右 右上
        static const int dx[] = {  0,  1, 1, 1 };
        vector<pair<point_t,int> > erases;
        for (point_t p : modified_blocks) { // 変化したところだけ見る
            assert (field.at[p.x][p.y] != empty_block and field.at[p.x][p.y] != obstacle_block);
            repeat (j, 4) {
                int cnt = 1;
                int acc = field.at[p.x][p.y];
                int ly = p.y - dy[j];
                int lx = p.x - dx[j];
                for (; is_on_field(ly, lx, H, W); ++ cnt) {
                    block_t block = field.at[lx][ly];
                    if (block == empty_block) break;
                    if (acc + block > erasing_sum) break;
                    acc += block;
                    ly -= dy[j];
                    lx -= dx[j];
                }
                // しゃくとり法っぽく
                int ry = p.y + dy[j];
                int rx = p.x + dx[j];
                while (cnt --) {
                    while (is_on_field(ry, rx, H, W)) {
                        block_t block = field.at[rx][ry];
                        if (block == empty_block) break;
                        if (acc + block > erasing_sum) break;
                        acc += block;
                        ry += dy[j];
                        rx += dx[j];
                    }
                    ly += dy[j];
                    lx += dx[j];
                    if (acc == erasing_sum) erases.emplace_back(point(ly, lx), j);
                    acc -= field.at[lx][ly];
                }
            }
        }
        whole(sort, erases);
        erases.erase(whole(unique, erases), erases.end()); // 重複排除
        return erases;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0xc0(%rbp)
movq %rdi, %rax
movq %rax, -0xb8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
callq 0x1d170
movq -0x18(%rbp), %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1c2d0
movq %rax, -0x30(%rbp)
movq -0x28(%rbp), %rdi
callq 0x1c300
movq %rax, -0x38(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x1d190
testb $0x1, %al
jne 0x1c769
jmp 0x1c9f4
leaq -0x30(%rbp), %rdi
callq 0x1d1d0
movq (%rax), %rax
movq %rax, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
cmpl $0x4, -0x44(%rbp)
jge 0x1c9e4
movl $0x1, -0x48(%rbp)
movq -0x10(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0x1d1f0
movq %rax, %rdi
movslq -0x40(%rbp), %rsi
callq 0x1d220
movsbl (%rax), %eax
movl %eax, -0x4c(%rbp)
movl -0x40(%rbp), %eax
movslq -0x44(%rbp), %rdx
leaq 0x9e52(%rip), %rcx      # 0x26610
subl (%rcx,%rdx,4), %eax
movl %eax, -0x50(%rbp)
movl -0x3c(%rbp), %eax
movslq -0x44(%rbp), %rdx
leaq 0x9e4e(%rip), %rcx      # 0x26620
subl (%rcx,%rdx,4), %eax
movl %eax, -0x54(%rbp)
movl -0x50(%rbp), %edi
movl -0x54(%rbp), %esi
movl $0x13, %edx
movl $0xa, %ecx
callq 0x2500
testb $0x1, %al
jne 0x1c7f3
jmp 0x1c870
movq -0x10(%rbp), %rdi
movslq -0x54(%rbp), %rsi
callq 0x1d1f0
movq %rax, %rdi
movslq -0x50(%rbp), %rsi
callq 0x1d220
movb (%rax), %al
movb %al, -0x55(%rbp)
movsbl -0x55(%rbp), %eax
cmpl $0x0, %eax
jne 0x1c81c
jmp 0x1c870
movl -0x4c(%rbp), %eax
movsbl -0x55(%rbp), %ecx
addl %ecx, %eax
cmpl $0xa, %eax
jle 0x1c82c
jmp 0x1c870
movsbl -0x55(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movslq -0x44(%rbp), %rcx
leaq 0x9dcf(%rip), %rax      # 0x26610
movl (%rax,%rcx,4), %ecx
movl -0x50(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x50(%rbp)
movslq -0x44(%rbp), %rcx
leaq 0x9dc9(%rip), %rax      # 0x26620
movl (%rax,%rcx,4), %ecx
movl -0x54(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x54(%rbp)
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x1c7d8
movl -0x40(%rbp), %eax
movslq -0x44(%rbp), %rdx
leaq 0x9d92(%rip), %rcx      # 0x26610
addl (%rcx,%rdx,4), %eax
movl %eax, -0x5c(%rbp)
movl -0x3c(%rbp), %eax
movslq -0x44(%rbp), %rdx
leaq 0x9d8e(%rip), %rcx      # 0x26620
addl (%rcx,%rdx,4), %eax
movl %eax, -0x60(%rbp)
movl -0x48(%rbp), %eax
movl %eax, %ecx
addl $-0x1, %ecx
movl %ecx, -0x48(%rbp)
cmpl $0x0, %eax
je 0x1c9d4
jmp 0x1c8ae
movl -0x5c(%rbp), %edi
movl -0x60(%rbp), %esi
movl $0x13, %edx
movl $0xa, %ecx
callq 0x2500
testb $0x1, %al
jne 0x1c8c9
jmp 0x1c939
movq -0x10(%rbp), %rdi
movslq -0x60(%rbp), %rsi
callq 0x1d1f0
movq %rax, %rdi
movslq -0x5c(%rbp), %rsi
callq 0x1d220
movb (%rax), %al
movb %al, -0x61(%rbp)
movsbl -0x61(%rbp), %eax
cmpl $0x0, %eax
jne 0x1c8f2
jmp 0x1c939
movl -0x4c(%rbp), %eax
movsbl -0x61(%rbp), %ecx
addl %ecx, %eax
cmpl $0xa, %eax
jle 0x1c902
jmp 0x1c939
movsbl -0x61(%rbp), %eax
addl -0x4c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movslq -0x44(%rbp), %rcx
leaq 0x9cf9(%rip), %rax      # 0x26610
movl (%rax,%rcx,4), %eax
addl -0x5c(%rbp), %eax
movl %eax, -0x5c(%rbp)
movslq -0x44(%rbp), %rcx
leaq 0x9cf5(%rip), %rax      # 0x26620
movl (%rax,%rcx,4), %eax
addl -0x60(%rbp), %eax
movl %eax, -0x60(%rbp)
jmp 0x1c8ae
movslq -0x44(%rbp), %rcx
leaq 0x9ccc(%rip), %rax      # 0x26610
movl (%rax,%rcx,4), %eax
addl -0x50(%rbp), %eax
movl %eax, -0x50(%rbp)
movslq -0x44(%rbp), %rcx
leaq 0x9cc8(%rip), %rax      # 0x26620
movl (%rax,%rcx,4), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
cmpl $0xa, -0x4c(%rbp)
jne 0x1c9ab
movl -0x50(%rbp), %edi
movl -0x54(%rbp), %esi
callq 0x2550
movq -0xc0(%rbp), %rdi
movq %rax, -0x6c(%rbp)
leaq -0x6c(%rbp), %rsi
leaq -0x44(%rbp), %rdx
callq 0x1d250
jmp 0x1c98c
jmp 0x1c9ab
movq -0xc0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x78(%rbp)
movl %eax, -0x7c(%rbp)
callq 0x1d0d0
jmp 0x1cac0
movq -0x10(%rbp), %rdi
movslq -0x54(%rbp), %rsi
callq 0x1d1f0
movq %rax, %rdi
movslq -0x50(%rbp), %rsi
callq 0x1d220
movsbl (%rax), %ecx
movl -0x4c(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x4c(%rbp)
jmp 0x1c898
jmp 0x1c9d6
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x1c780
jmp 0x1c9e6
leaq -0x30(%rbp), %rdi
callq 0x1d2d0
jmp 0x1c753
movq -0xc0(%rbp), %rsi
leaq -0x7d(%rbp), %rdi
callq 0x1d2f0
jmp 0x1ca06
movq -0xc0(%rbp), %rsi
leaq -0x91(%rbp), %rdi
callq 0x1d3c0
movq %rax, -0xc8(%rbp)
jmp 0x1ca22
movq -0xc8(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x1d410
movq -0xc0(%rbp), %rdi
callq 0x1d450
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x1d410
movq -0xc0(%rbp), %rdi
movq -0x88(%rbp), %rsi
movq -0xa0(%rbp), %rdx
callq 0x1d330
movq %rax, -0xd0(%rbp)
jmp 0x1ca8c
movq -0xd0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movb $0x1, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
jne 0x1cab0
movq -0xc0(%rbp), %rdi
callq 0x1d0d0
movq -0xb8(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
movq -0x78(%rbp), %rdi
callq 0x22f0
nopl (%rax)