// File: /workspace/github_cpp_makefile_star2_O2/shangjingbo1226[P]MACFP/src/methods/MACFP.cpp
// Function: enumerateEdit(int, int, int, int, int, int, int, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>&)
bool enumerateEdit(int ptr, int length, int l, int r, int left, int right, int remainDist, vector<PII> &ret)
{
    if (remainDist == 0 && left == right) {
        return false;
    }
    if (ptr == r + 1) {
        ULL key = (left * MAGIC + right) * MAGIC + length;
        if (checked.count(key)) {
            return false;
        }
        checked.insert(key);
        for (int i = left; i <= right; ++ i) {
            int start = s->sa->sa[i];
            int end = s->sa->sa[i] + length - 1;
            if (max(start, l) > min(end, r)) {
                ret.push_back(make_pair(start, end));
            }
        }
        if (makeMaximal(ret).size() >= MIN_SUP) {
            return true;
        }
    }
    int last[alphabet.size()];
    for (int i = 0; i < alphabet.size(); ++ i) {
        int l = (i == 0) ? left - 1 : last[i - 1];
        int r = right + 1;
        while (l + 1 < r) {
            int mid = l + r >> 1;
            int index = s->sa->sa[mid] + length;
            if (index < s->size() && alphabet[i] < s->s[index]) {
                r = mid;
            } else {
                l = mid;
            }
        }
        last[i] = l;
    }
    for (int i = 0; i < alphabet.size(); ++ i) {
        int new_left = (i == 0) ? left : last[i - 1] + 1;
        while (s->sa->sa[new_left] + length == s->size()) {
            ++ new_left;
        }
        int new_right = last[i];

        if (new_left > new_right) {
            continue;
        }
        myAssert(s->s[s->sa->sa[new_left] + length] == alphabet[i], "index error");
        myAssert(s->s[s->sa->sa[new_right] + length] == alphabet[i], "index error");

        // replace
        if (ptr <= r && remainDist >= (s->s[ptr] != alphabet[i])) {
            if (enumerateEdit(ptr + 1, length + 1, l, r, new_left, new_right, remainDist - (s->s[ptr] != alphabet[i]), ret)) {
                return true;
            }
        }
        //insert
        if (remainDist > 0) {
            if (enumerateEdit(ptr, length + 1, l, r, new_left, new_right, remainDist - 1, ret)) {
                return true;
            }
        }
    }
    // delete
    if (remainDist > 0 && ptr <= r) {
        if (enumerateEdit(ptr + 1, length, l, r, left, right, remainDist - 1, ret)) {
            return true;
        }
    }
    return false;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %edx, -0x2c(%rbp)
movl 0x10(%rbp), %edx
movq %r8, %rax
movq %r8, -0x58(%rbp)
movq %r9, -0x68(%rbp)
xorl %r9d, %eax
orl %edx, %eax
jne 0x3d6d
xorl %r12d, %r12d
jmp 0x415a
movq %rcx, -0x38(%rbp)
leal 0x1(%rcx), %eax
movq %rsi, -0x60(%rbp)
movslq %esi, %rbx
movq %rdi, -0x50(%rbp)
cmpl %edi, %eax
jne 0x3e71
movslq -0x58(%rbp), %r15
imulq $0xabcdef, %r15, %rax   # imm = 0xABCDEF
movslq -0x68(%rbp), %r13
addq %r13, %rax
imulq $0xabcdef, %rax, %rax   # imm = 0xABCDEF
addq %rbx, %rax
leaq -0x98(%rbp), %rsi
movq %rax, (%rsi)
leaq 0x5f6868c(%rip), %rdi   # 0x5f6c440
callq 0x8070
testq %rax, %rax
sete %r12b
jne 0x415a
leaq 0x5f68673(%rip), %rdi   # 0x5f6c440
leaq -0x98(%rbp), %rsi
callq 0x8100
movq -0x60(%rbp), %rax
leal -0x1(%rax), %r14d
movq -0x38(%rbp), %rdi
cmpq %r13, %r15
jg 0x3e3b
movq 0x5f68577(%rip), %rax   # 0x5f6c368
movq 0x20(%rax), %rax
movq 0x28(%rax), %rax
movl (%rax,%r15,4), %eax
leal (%r14,%rax), %ecx
movl -0x2c(%rbp), %edx
cmpl %edx, %eax
cmovgl %eax, %edx
cmpl %edi, %ecx
movl %edi, %esi
cmovll %ecx, %esi
cmpl %esi, %edx
jle 0x3e36
shlq $0x20, %rcx
orq %rax, %rcx
movq %rcx, -0xb0(%rbp)
movq 0x18(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x83e8
movq -0x38(%rbp), %rdi
incq %r15
jmp 0x3de5
leaq -0xb0(%rbp), %r14
movq %r14, %rdi
movq 0x18(%rbp), %rsi
callq 0x2685
movq 0x8(%r14), %r15
subq (%r14), %r15
sarq $0x3, %r15
movslq 0xa36c(%rip), %r13      # 0xe1cc
movq %r14, %rdi
callq 0x733a
cmpq %r13, %r15
jae 0x415a
movq %rsp, -0x88(%rbp)
movq 0x5f684d1(%rip), %rax   # 0x5f6c350
movq %rsp, %r14
leaq 0xf(,%rax,4), %rax
andq $-0x10, %rax
subq %rax, %r14
movq %r14, %rsp
movq 0x5f684b5(%rip), %rax   # 0x5f6c350
movq -0x58(%rbp), %rcx
decl %ecx
movl %ecx, -0x40(%rbp)
movq -0x68(%rbp), %rcx
leal 0x1(%rcx), %edx
movq 0x5f684b6(%rip), %rsi   # 0x5f6c368
xorl %edi, %edi
movq 0x5f6848d(%rip), %r8    # 0x5f6c348
movq %r14, -0x80(%rbp)
cmpq %rax, %rdi
je 0x3f2a
movl -0x40(%rbp), %r9d
testq %rdi, %rdi
je 0x3ed2
movl -0x4(%r14,%rdi,4), %r9d
movl %edx, %r15d
movl %r9d, %r10d
leal 0x1(%r10), %r14d
movl %r15d, %r11d
cmpl %r11d, %r14d
jge 0x3f1d
leal (%r11,%r10), %r9d
sarl %r9d
movq 0x20(%rsi), %r15
movslq %r9d, %r12
movq 0x28(%r15), %r15
movslq (%r15,%r12,4), %r12
addq %rbx, %r12
cmpq %r12, 0x8(%rsi)
jbe 0x3f18
movb (%r8,%rdi), %r13b
movq (%rsi), %rcx
movl %r11d, %r15d
movl %r9d, %r11d
cmpb (%rcx,%r12), %r13b
jl 0x3edf
jmp 0x3ed5
movl %r11d, %r15d
jmp 0x3ed5
movq -0x80(%rbp), %r14
movl %r10d, (%r14,%rdi,4)
incq %rdi
jmp 0x3ebf
movq -0x50(%rbp), %rcx
movslq %ecx, %rdx
movq %rdx, -0x90(%rbp)
incl %ecx
movl %ecx, -0x44(%rbp)
movq -0x60(%rbp), %rcx
incl %ecx
movl %ecx, -0x48(%rbp)
movl 0x10(%rbp), %ecx
decl %ecx
movq %rcx, -0x70(%rbp)
xorl %r15d, %r15d
movq -0x38(%rbp), %rcx
cmpq %r15, %rax
jbe 0x4113
movq -0x58(%rbp), %rax
movl %eax, %edx
testq %r15, %r15
je 0x3f71
movl -0x4(%r14,%r15,4), %edx
incl %edx
movq 0x5f683f0(%rip), %rax   # 0x5f6c368
movq 0x8(%rax), %rdi
movq 0x20(%rax), %rsi
movslq %edx, %rdx
leal -0x1(%rdx), %r12d
shlq $0x2, %rdx
addq 0x28(%rsi), %rdx
movslq (%rdx), %rsi
addq %rbx, %rsi
incl %r12d
addq $0x4, %rdx
cmpq %rsi, %rdi
je 0x3f8f
movslq (%r14,%r15,4), %rdi
movq %rdi, -0x40(%rbp)
cmpl %r12d, %edi
jl 0x4104
movq (%rax), %rax
movb (%rax,%rsi), %r13b
movq 0x5f68388(%rip), %rax   # 0x5f6c348
movq %r15, -0x78(%rbp)
movb (%rax,%r15), %r14b
leaq -0xf0(%rbp), %r15
movq %r15, %rdi
leaq 0x5141(%rip), %rsi      # 0x911a
leaq -0xb0(%rbp), %rdx
callq 0x48da
xorl %edi, %edi
cmpb %r14b, %r13b
sete %dil
movq %r15, %rsi
callq 0x272c
movq %r15, %rdi
callq 0x2378
movq 0x5f68363(%rip), %rax   # 0x5f6c368
movq (%rax), %rcx
movq 0x20(%rax), %rax
movq 0x28(%rax), %rax
movq -0x40(%rbp), %rdx
movslq (%rax,%rdx,4), %rax
addq %rbx, %rax
movb (%rcx,%rax), %r15b
movq 0x5f68322(%rip), %rax   # 0x5f6c348
movq -0x78(%rbp), %rcx
movb (%rax,%rcx), %r14b
leaq -0xd0(%rbp), %r13
movq %r13, %rdi
leaq 0x50db(%rip), %rsi      # 0x911a
leaq -0xb0(%rbp), %rdx
callq 0x48da
xorl %edi, %edi
cmpb %r14b, %r15b
sete %dil
movq %r13, %rsi
callq 0x272c
movq %r13, %rdi
callq 0x2378
movq -0x38(%rbp), %rcx
cmpl -0x50(%rbp), %ecx
movq -0x80(%rbp), %r14
movq -0x78(%rbp), %r15
jl 0x40d5
movq 0x5f682ec(%rip), %rax   # 0x5f6c368
movq (%rax), %rax
movq -0x90(%rbp), %rdx
movb (%rax,%rdx), %al
movq 0x5f682b8(%rip), %rdx   # 0x5f6c348
movb (%rdx,%r15), %sil
xorl %edx, %edx
cmpb %sil, %al
setne %dl
movl 0x10(%rbp), %edi
cmpl %edi, %edx
jg 0x4104
xorl %edx, %edx
cmpb %sil, %al
setne %dl
movl 0x10(%rbp), %eax
subl %edx, %eax
movl -0x44(%rbp), %edi
movl -0x48(%rbp), %esi
movl -0x2c(%rbp), %edx
movl %r12d, %r8d
movq -0x40(%rbp), %r9
pushq 0x18(%rbp)
pushq %rax
callq 0x3d39
movq -0x38(%rbp), %rcx
addq $0x10, %rsp
testb %al, %al
jne 0x4150
movl 0x10(%rbp), %eax
testl %eax, %eax
jle 0x4104
movq -0x50(%rbp), %rdi
movl -0x48(%rbp), %esi
movl -0x2c(%rbp), %edx
movl %r12d, %r8d
movq -0x40(%rbp), %r9
pushq 0x18(%rbp)
pushq -0x70(%rbp)
callq 0x3d39
movq -0x38(%rbp), %rcx
addq $0x10, %rsp
testb %al, %al
jne 0x4150
incq %r15
movq 0x5f68242(%rip), %rax   # 0x5f6c350
jmp 0x3f56
cmpl -0x50(%rbp), %ecx
setl %al
movl 0x10(%rbp), %edx
testl %edx, %edx
setle %dl
orb %al, %dl
jne 0x414b
movl -0x44(%rbp), %edi
movq -0x60(%rbp), %rsi
movl -0x2c(%rbp), %edx
movq -0x58(%rbp), %r8
movq -0x68(%rbp), %r9
pushq 0x18(%rbp)
pushq -0x70(%rbp)
callq 0x3d39
popq %rcx
popq %rdx
movb $0x1, %r12b
testb %al, %al
jne 0x4153
xorl %r12d, %r12d
jmp 0x4153
movb $0x1, %r12b
movq -0x88(%rbp), %rsp
movl %r12d, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x417a
movq %rax, %rbx
leaq -0xf0(%rbp), %rdi
jmp 0x4189
movq %rax, %rbx
jmp 0x418e
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x2378
movq %rbx, %rdi
callq 0x2310