// File: /workspace/github_cpp_makefile_star2_O3/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, %ebx
movl %edx, %r14d
movl %esi, 0x14(%rsp)
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 %ebx, %rcx
addq %rax, %rcx
leaq 0x60(%rsp), %rsi
movq %rcx, (%rsi)
leaq 0x5f683a5(%rip), %r15   # 0x5f6c408
movq %r15, %rdi
callq 0x92a0
testq %rax, %rax
jne 0x4257
leaq 0x20(%rsp), %rdx
movq %r15, (%rdx)
leaq 0x60(%rsp), %rsi
movq %r15, %rdi
callq 0x92fc
movl 0xa0(%rsp), %eax
movq %rax, %r15
movl %eax, (%rsp)
movl %ebp, %edi
movl 0x14(%rsp), %esi
movl %r13d, %edx
movl %r12d, %ecx
movl %r14d, %r8d
movl %ebx, %r9d
callq 0x3ea1
testb %al, %al
je 0x4257
movl %ebx, 0x10(%rsp)
incl 0x5f68341(%rip)         # 0x5f6c400
leaq 0x20(%rsp), %rdi
movl %ebp, 0x1c(%rsp)
movl %ebp, %esi
movl %r13d, %edx
movl %r14d, %ecx
movq %r15, %rbx
movl %ebx, %r8d
callq 0x321e
incl %r15d
movl %r15d, %ebp
testl %ebx, %ebx
movq %rbx, %r8
js 0x411f
movq 0x20(%rsp), %rax
xorl %edi, %edi
xorl %ebx, %ebx
movl %r15d, %r14d
movl 0x10(%rsp), %ecx
movl %r14d, %esi
cmpl %r14d, %edi
cmovll %edi, %r14d
cmpl $-0x1, (%rax,%rdi,4)
cmovel %esi, %r14d
cmovnel %edi, %ebx
incq %rdi
cmpq %rdi, %rbp
jne 0x40f8
cmpl %ebx, %r14d
jle 0x4128
jmp 0x4240
xorl %ebx, %ebx
movl %r15d, %r14d
movl 0x10(%rsp), %ecx
leaq 0x38(%rsp), %rdi
movl 0x14(%rsp), %esi
movl %r12d, %edx
movq %r8, %r12
callq 0x385f
testl %r12d, %r12d
movl 0x14(%rsp), %edi
js 0x4179
movq 0x38(%rsp), %rax
xorl %ecx, %ecx
xorl %esi, %esi
movl %r15d, %edx
cmpl %r15d, %ecx
cmovll %ecx, %r15d
cmpl $-0x1, (%rax,%rcx,4)
cmovel %edx, %r15d
cmovnel %ecx, %esi
incq %rcx
cmpq %rcx, %rbp
jne 0x414e
movl %esi, 0x18(%rsp)
cmpl %esi, %r15d
jle 0x4181
jmp 0x4229
movl $0x0, 0x18(%rsp)
movslq %r15d, %rax
decq %rax
movq %rax, 0x50(%rsp)
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl %ebx, 0x10(%rsp)
movslq %r14d, %rbx
movq 0x20(%rsp), %rax
cmpl $-0x1, (%rax,%rbx,4)
je 0x4219
movl 0xa0(%rsp), %eax
subl %r14d, %eax
movl 0x18(%rsp), %ecx
cmpl %eax, %ecx
cmovll %ecx, %eax
cmpl %eax, %r15d
jg 0x4219
movslq %eax, %rbp
movq 0x50(%rsp), %r12
movq 0x38(%rsp), %rax
movl 0x4(%rax,%r12,4), %eax
cmpq %r13, %rax
je 0x4211
movq 0x20(%rsp), %rcx
movl (%rcx,%rbx,4), %ecx
movl 0x1c(%rsp), %edx
cmpl %edx, %ecx
cmovgl %ecx, %edx
cmpl %edi, %eax
movl %edi, %esi
cmovll %eax, %esi
cmpl %esi, %edx
jle 0x4211
shlq $0x20, %rax
orq %rcx, %rax
movq %rax, 0x58(%rsp)
movq 0xa8(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x958a
movl 0x14(%rsp), %edi
incq %r12
cmpq %rbp, %r12
jl 0x41c4
incl %r14d
movl 0x10(%rsp), %ebx
cmpl %ebx, %r14d
jle 0x4196
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x4240
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4257
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 0x4285
movq %rax, %rbx
movq 0x38(%rsp), %rdi
testq %rdi, %rdi
je 0x4285
movq 0x48(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x429c
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x2330