// File: /workspace/github_cpp_makefile_star2_O2/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 $0x58, %rsp
movl %r9d, %r15d
movl %r8d, %r14d
movl %ecx, %r13d
movl %edx, %r12d
movl %esi, %ebx
movl %edi, %ebp
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 %r13d, %rcx
addq %rax, %rcx
leaq 0x20(%rsp), %rsi
movq %rcx, (%rsi)
leaq 0x5f68b07(%rip), %rdi   # 0x5f6c408
callq 0x8070
testq %rax, %rax
jne 0x3a0c
leaq 0x5f68af2(%rip), %rdi   # 0x5f6c408
leaq 0x20(%rsp), %rsi
callq 0x8100
movl 0x90(%rsp), %eax
movl %eax, (%rsp)
movl %ebp, %edi
movl %ebx, %esi
movl %r14d, %edx
movl %r15d, %ecx
movl %r12d, %r8d
movl %r13d, %r9d
callq 0x3757
testb %al, %al
je 0x3a0c
movl %r15d, 0xc(%rsp)
incl 0x5f68aae(%rip)         # 0x5f6c400
leaq 0x40(%rsp), %r15
movq %r15, %rdi
movl %ebp, %esi
movl %r14d, %edx
movl %r12d, %ecx
movl 0x90(%rsp), %r14d
movl %r14d, %r8d
callq 0x2e17
leal 0x1(%r14), %r12d
movq (%r15), %rax
movslq %r14d, %r15
movq %r14, %r8
xorl %ecx, %ecx
movl %r12d, %r14d
movl $0x0, 0x8(%rsp)
cmpq %r15, %rcx
jg 0x39b2
cmpl %r14d, %ecx
movl %r14d, %edx
cmovll %ecx, %edx
cmpl $-0x1, (%rax,%rcx,4)
cmovnel %edx, %r14d
movl 0x8(%rsp), %edx
cmovnel %ecx, %edx
movl %edx, 0x8(%rsp)
incq %rcx
jmp 0x398c
cmpl 0x8(%rsp), %r14d
jg 0x3a02
leaq 0x28(%rsp), %rdi
movl %ebx, %esi
movl 0xc(%rsp), %edx
movl %r13d, %ecx
callq 0x32e0
xorl %eax, %eax
movq 0x28(%rsp), %rcx
xorl %esi, %esi
cmpq %r15, %rax
jg 0x39f3
cmpl %r12d, %eax
movl %r12d, %edx
cmovll %eax, %edx
cmpl $-0x1, (%rcx,%rax,4)
cmovnel %edx, %r12d
cmovnel %eax, %esi
incq %rax
jmp 0x39d5
cmpl %esi, %r12d
jle 0x3a1b
leaq 0x28(%rsp), %rdi
callq 0x66a2
leaq 0x40(%rsp), %rdi
callq 0x66a2
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movslq %r12d, %rax
movq %rax, 0x10(%rsp)
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
movl %esi, 0xc(%rsp)
cmpl 0x8(%rsp), %r14d
jg 0x39f8
movslq %r14d, %r12
movq 0x40(%rsp), %rax
cmpl $-0x1, (%rax,%r12,4)
je 0x3ab3
movl 0x90(%rsp), %eax
subl %r14d, %eax
movl 0xc(%rsp), %ecx
cmpl %eax, %ecx
cmovll %ecx, %eax
movslq %eax, %r13
movq 0x10(%rsp), %r15
cmpq %r13, %r15
jg 0x3ab3
movq 0x28(%rsp), %rax
movl (%rax,%r15,4), %eax
cmpq %rdi, %rax
je 0x3aae
movq 0x40(%rsp), %rcx
movl (%rcx,%r12,4), %ecx
cmpl %ebp, %ecx
movl %ebp, %edx
cmovgl %ecx, %edx
cmpl %ebx, %eax
movl %ebx, %esi
cmovll %eax, %esi
cmpl %esi, %edx
jle 0x3aae
shlq $0x20, %rax
orq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0x98(%rsp), %rdi
leaq 0x18(%rsp), %rsi
callq 0x83e8
movl $0xffffffff, %edi       # imm = 0xFFFFFFFF
incq %r15
jmp 0x3a5d
incl %r14d
jmp 0x3a2c
movq %rax, %rbx
jmp 0x3acd
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x66a2
leaq 0x40(%rsp), %rdi
callq 0x66a2
movq %rbx, %rdi
callq 0x2310