// File: /workspace/github_cpp_makefile_star2_O1/shangjingbo1226[P]MACFP/src/methods/MACFP.cpp
// Function: dfs(int, int, int, int, int, int, int, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>&)
void dfs(int l, int r, int firstPosition, int lastPosition, int firstChunkStart, int lastChunkEnd, int remainDistance, vector<PII> &supports)
{
    ULL key = firstChunkStart;
    key = key * MAGIC + lastChunkEnd;
    key = key * MAGIC + firstPosition;
    key = key * MAGIC + lastPosition;

    if (explored.count(key)) {
        return;
    }
    explored.insert(key);

    if (!checkByPrefixSum(l, r, firstChunkStart, lastChunkEnd, firstPosition, lastPosition, remainDistance)) {
        return;
    }

    counter ++;

    vector<int> left = expandLeft(l, firstChunkStart, firstPosition, remainDistance);
    int leftStart = remainDistance + 1, leftEnd = 0;
    for (int i = 0; i <= remainDistance; ++ i) {
        if (left[i] != -1) {
            leftStart = min(leftStart, i);
            leftEnd = i;
        }
    }
    if (leftStart > leftEnd) {
        return;
    }

    vector<int> right = expandRight(r, lastChunkEnd, lastPosition, remainDistance);
    int rightStart = remainDistance + 1, rightEnd = 0;
    for (int i = 0; i <= remainDistance; ++ i) {
        if (right[i] != -1) {
            rightStart = min(rightStart, i);
            rightEnd = i;
        }
    }
    if (rightStart > rightEnd) {
        return;
    }

    for (int leftK = leftStart; leftK <= leftEnd; ++ leftK) {
        if (left[leftK] == -1) {
            continue;
        }
        for (int rightK = rightStart; rightK <= rightEnd && rightK <= remainDistance - leftK; ++ rightK) {
            if (right[rightK] == -1) {
                continue;
            }
            if (max(l, left[leftK]) <= min(r, right[rightK])) {
                continue;
            }
            supports.push_back(make_pair(left[leftK], right[rightK]));
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %r9d, %r12d
movl %r8d, %r13d
movl %ecx, %ebp
movl %edx, %r14d
movl %esi, %ebx
movl %edi, 0x18(%rsp)
movslq %r8d, %rax
imulq $0xabcdef, %rax, %rax   # imm = 0xABCDEF
movslq %r9d, %rcx
addq %rax, %rcx
imulq $0xabcdef, %rcx, %rax   # imm = 0xABCDEF
movslq %edx, %rcx
addq %rax, %rcx
imulq $0xabcdef, %rcx, %rax   # imm = 0xABCDEF
movslq %ebp, %rcx
addq %rax, %rcx
leaq 0x60(%rsp), %rsi
movq %rcx, (%rsi)
leaq 0x5f68425(%rip), %r15   # 0x5f6c408
movq %r15, %rdi
callq 0x8b80
testq %rax, %rax
jne 0x41dd
leaq 0x20(%rsp), %rdx
movq %r15, (%rdx)
leaq 0x60(%rsp), %rsi
movq %r15, %rdi
callq 0x8bfc
movl 0xa0(%rsp), %eax
movq %rax, %r15
movl %eax, (%rsp)
movl 0x18(%rsp), %edi
movl %ebx, %esi
movl %r13d, %edx
movl %r12d, %ecx
movl %r14d, %r8d
movl %ebp, %r9d
callq 0x3e1c
testb %al, %al
je 0x41dd
movl %ebx, 0x14(%rsp)
incl 0x5f683c1(%rip)         # 0x5f6c400
leaq 0x20(%rsp), %rdi
movl 0x18(%rsp), %esi
movl %r13d, %edx
movl %r14d, %ecx
movq %r15, %rbx
movl %ebx, %r8d
callq 0x31e1
incl %r15d
testl %ebx, %ebx
js 0x4092
movq 0x20(%rsp), %rax
movl %r15d, %r8d
xorl %edi, %edi
xorl %r13d, %r13d
movl %r15d, %esi
movl %r15d, %r14d
cmpl %esi, %edi
cmovll %edi, %r14d
cmpl $-0x1, (%rax,%rdi,4)
cmovel %esi, %r14d
cmovnel %edi, %r13d
incq %rdi
movl %r14d, %esi
cmpq %rdi, %r8
jne 0x4073
jmp 0x4098
xorl %r13d, %r13d
movl %r15d, %r14d
cmpl %r13d, %r14d
jg 0x41c6
leaq 0x38(%rsp), %rdi
movl 0x14(%rsp), %esi
movl %r12d, %edx
movl %ebp, %ecx
movl %ebx, %r8d
callq 0x380a
testl %ebx, %ebx
js 0x40ee
movq 0x38(%rsp), %rax
movl %r15d, %ecx
xorl %edx, %edx
xorl %r8d, %r8d
movl %r15d, %esi
movl 0x14(%rsp), %edi
cmpl %esi, %edx
cmovll %edx, %r15d
cmpl $-0x1, (%rax,%rdx,4)
cmovel %esi, %r15d
cmovnel %edx, %r8d
incq %rdx
movl %r15d, %esi
cmpq %rdx, %rcx
jne 0x40cf
jmp 0x40f5
xorl %r8d, %r8d
movl 0x14(%rsp), %edi
movl %r8d, 0x1c(%rsp)
cmpl %r8d, %r15d
jg 0x41af
cmpl %r13d, %r14d
jg 0x41af
movslq %r15d, %rax
decq %rax
movq %rax, 0x50(%rsp)
movslq %r14d, %rbx
movq 0x20(%rsp), %rax
cmpl $-0x1, (%rax,%rbx,4)
je 0x41a3
movl 0xa0(%rsp), %eax
subl %r14d, %eax
movl 0x1c(%rsp), %ecx
cmpl %eax, %ecx
cmovll %ecx, %eax
cmpl %eax, %r15d
jg 0x41a3
movslq %eax, %rbp
movq 0x50(%rsp), %r12
movq 0x38(%rsp), %rax
movl 0x4(%rax,%r12,4), %ecx
cmpl $-0x1, %ecx
je 0x419b
movq 0x20(%rsp), %rdx
movl (%rdx,%rbx,4), %esi
movl 0x18(%rsp), %r8d
cmpl %r8d, %esi
cmovlel %r8d, %esi
cmpl %edi, %ecx
cmovgel %edi, %ecx
cmpl %ecx, %esi
jle 0x419b
movl (%rdx,%rbx,4), %ecx
movl 0x4(%rax,%r12,4), %eax
shlq $0x20, %rax
orq %rcx, %rax
movq %rax, 0x58(%rsp)
movq 0xa8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x8e7a
movl 0x14(%rsp), %edi
incq %r12
cmpq %rbp, %r12
jl 0x4145
incl %r14d
cmpl %r13d, %r14d
jle 0x4117
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x41c6
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x41dd
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x420b
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x420b
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4222
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x2330