// File: /workspace/github_cpp_makefile_star2_O1/shangjingbo1226[P]MACFP/src/methods/MACFP.cpp
// Function: expandRight(int, int, int, int)
vector<int> expandRight(int rightBound, int r, int y, int remainDistance)
{
    ULL key = rightBound;
    key = key * MAGIC + r;
    key = key * MAGIC + y;
    key = key * MAGIC + remainDistance;
    if (bufferRight.count(key)) {
        return bufferRight[key];
    }
    vector<int> best(remainDistance + 1, -1);

    deque< pair<int, PII> > q;
    q.push_front(make_pair(0, make_pair(r + 1, y + 1)));
    while (q.size()) {
        int dist = q.front().first;
        int u = q.front().second.first;
        int v = q.front().second.second;
        q.pop_front();

        if (best[dist] != -1 && best[dist] <= v - 1) {
            continue;
        }

        if (u > rightBound) {
            if (best[dist] == -1 || best[dist] > v - 1) {
                best[dist] = v - 1;
            }
            continue;
        }

        if (u <= rightBound && v < s->size() && s->s[u] == s->s[v]) {
            int lcp = s->sa->lcp(u, v);
            myAssert(u + lcp <= s->size(), "u+lcp error");
            myAssert(v + lcp <= s->size(), "v+lcp error");
            lcp = min(lcp, rightBound - u + 1);
            q.push_front(make_pair(dist, make_pair(u + lcp, v + lcp)));
        } else {
            for (int du = 0; du <= remainDistance - dist; ++ du) {
                if (u + du > rightBound + 1) {
                    break;
                }
                for (int dv = 0; dv <= remainDistance - dist; ++ dv) {
                    if (v + dv > s->size()) {
                        break;
                    }
                    if (du + dv > 0){
                        if (u + du == rightBound + 1 || v + dv == s->size() || s->s[u + du] == s->s[v + dv]) {
                            q.push_back(make_pair(dist + max(du, dv), make_pair(u + du, v + dv)));
                        }
                    }
                }
            }
        }
    }
    for (int i = 0; i < remainDistance; ++ i) {
        if (best[i] != -1) {
            if (best[i + 1] == -1 || best[i + 1] > best[i] - 1) {
                best[i + 1] = best[i] - 1;
            }
        }
    }
    return bufferRight[key] = best;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movl %r8d, %r15d
movl %ecx, %r12d
movl %edx, %ebx
movl %esi, %ebp
movq %rdi, %r14
movslq %esi, %rax
imulq $0xabcdef, %rax, %rax   # imm = 0xABCDEF
movslq %edx, %rcx
addq %rax, %rcx
imulq $0xabcdef, %rcx, %rax   # imm = 0xABCDEF
movslq %r12d, %rcx
addq %rax, %rcx
imulq $0xabcdef, %rcx, %rax   # imm = 0xABCDEF
movslq %r8d, %rcx
addq %rax, %rcx
leaq 0x40(%rsp), %rsi
movq %rcx, (%rsi)
leaq 0x5f68b67(%rip), %rdi   # 0x5f6c3c8
callq 0x8480
testq %rax, %rax
je 0x388c
leaq 0x5f68b56(%rip), %rdi   # 0x5f6c3c8
leaq 0x40(%rsp), %rsi
callq 0x84fc
movq %r14, %rdi
movq %rax, %rsi
callq 0x5704
jmp 0x3d8e
leal 0x1(%r15), %eax
movl %eax, 0x2c(%rsp)
movslq %eax, %rsi
leaq 0x60(%rsp), %r13
movl $0xffffffff, (%r13)     # imm = 0xFFFFFFFF
leaq 0x48(%rsp), %rdi
leaq 0x18(%rsp), %rcx
movq %r13, %rdx
callq 0x5632
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%r13)
movaps %xmm0, 0x30(%r13)
movaps %xmm0, 0x20(%r13)
movaps %xmm0, 0x10(%r13)
movaps %xmm0, (%r13)
leaq 0x60(%rsp), %rdi
xorl %esi, %esi
callq 0x5dae
incl %ebx
incl %r12d
shlq $0x20, %r12
orq %r12, %rbx
movl $0x0, 0x18(%rsp)
movq %rbx, 0x1c(%rsp)
movq 0x18(%rsp), %rax
movl 0x20(%rsp), %ecx
movq %rax, 0x8(%rsp)
movl %ecx, 0x10(%rsp)
movq 0x70(%rsp), %rax
cmpq 0x78(%rsp), %rax
movq %r14, 0xb0(%rsp)
movq %r15, 0x30(%rsp)
je 0x393a
movl 0x10(%rsp), %ecx
movl %ecx, -0x4(%rax)
movq 0x8(%rsp), %rcx
movq %rcx, -0xc(%rax)
addq $-0xc, 0x70(%rsp)
jmp 0x3949
leaq 0x60(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x8a9e
movq %rbp, 0xb8(%rsp)
leal 0x1(%rbp), %eax
movl %eax, 0x28(%rsp)
cltq
movq %rax, 0x38(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, %rcx
subq 0x88(%rsp), %rcx
sarq $0x3, %rcx
cmpq $0x1, %rax
adcq $-0x1, %rcx
imulq $0x2a, %rcx, %rax
movq 0x90(%rsp), %rdx
subq 0x98(%rsp), %rdx
sarq $0x2, %rdx
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rdx
addq %rax, %rdx
movq 0x70(%rsp), %rax
movq 0x80(%rsp), %rcx
movq %rcx, %rsi
subq %rax, %rsi
sarq $0x2, %rsi
movabsq $0x5555555555555555, %rdi # imm = 0x5555555555555555
imulq %rdi, %rsi
cmpq %rsi, %rdx
je 0x3d07
movl (%rax), %edx
movl %edx, 0x4(%rsp)
movl 0x4(%rax), %ebx
movslq 0x8(%rax), %r12
addq $-0xc, %rcx
cmpq %rcx, %rax
je 0x39f1
addq $0xc, %rax
jmp 0x3a2c
movq 0x78(%rsp), %rdi
movl $0x1f8, %esi            # imm = 0x1F8
callq 0x21f0
movq 0x88(%rsp), %rax
leaq 0x8(%rax), %rcx
movq %rcx, 0x88(%rsp)
movq 0x8(%rax), %rax
movq %rax, 0x78(%rsp)
leaq 0x1f8(%rax), %rcx
movq %rcx, 0x80(%rsp)
movslq 0x4(%rsp), %rcx
movq %rax, 0x70(%rsp)
movq 0x48(%rsp), %rax
movl (%rax,%rcx,4), %edx
cmpl $-0x1, %edx
setne %sil
cmpl %r12d, %edx
setl %dil
testb %dil, %sil
jne 0x395f
cmpl 0xb8(%rsp), %ebx
jle 0x3a80
cmpl $-0x1, %edx
setne %sil
cmpl %r12d, %edx
setl %dl
testb %dl, %sil
jne 0x395f
decl %r12d
movl %r12d, (%rax,%rcx,4)
jmp 0x395f
movslq %ebx, %rsi
movq 0x5f688de(%rip), %rax   # 0x5f6c368
cmpq %r12, 0x8(%rax)
jbe 0x3bf4
movq (%rax), %rcx
movb (%rcx,%rsi), %dl
cmpb (%rcx,%r12), %dl
jne 0x3bf4
movq %rbx, %r13
movq 0x20(%rax), %rdi
movq %r12, %rdx
callq 0x5784
movq %rax, %rbp
movq 0x5f688ab(%rip), %rax   # 0x5f6c368
movq 0x8(%rax), %rbx
leaq 0x108(%rsp), %r14
movq %r14, 0xf8(%rsp)
leaq 0xf8(%rsp), %r15
movq %r15, %rdi
leaq 0x65fc(%rip), %rsi      # 0xa0df
leaq 0x6600(%rip), %rdx      # 0xa0ea
callq 0x809c
leal (%r13,%rbp), %eax
cltq
xorl %edi, %edi
cmpq %rax, %rbx
setae %dil
movq %r15, %rsi
callq 0x28d7
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
leaq 0xd8(%rsp), %r15
je 0x3b2c
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x21f0
movq 0x5f68835(%rip), %rax   # 0x5f6c368
movq 0x8(%rax), %rbx
leaq 0xe8(%rsp), %r14
movq %r14, 0xd8(%rsp)
movq %r15, %rdi
leaq 0x659a(%rip), %rsi      # 0xa0eb
leaq 0x659e(%rip), %rdx      # 0xa0f6
callq 0x809c
leal (%r12,%rbp), %eax
cltq
xorl %edi, %edi
cmpq %rax, %rbx
setae %dil
movq %r15, %rsi
callq 0x28d7
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
je 0x3b91
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x21f0
movl 0x28(%rsp), %eax
subl %r13d, %eax
cmpl %ebp, %eax
cmovgel %ebp, %eax
addl %eax, %r13d
addl %r12d, %eax
shlq $0x20, %rax
orq %rax, %r13
movl 0x4(%rsp), %eax
movl %eax, 0x18(%rsp)
movq %r13, 0x1c(%rsp)
movq 0x18(%rsp), %rax
movl 0x20(%rsp), %ecx
movq %rax, 0x8(%rsp)
movl %ecx, 0x10(%rsp)
movq 0x70(%rsp), %rax
cmpq 0x78(%rsp), %rax
je 0x3cf3
movl 0x10(%rsp), %ecx
movl %ecx, -0x4(%rax)
movq 0x8(%rsp), %rcx
movq %rcx, -0xc(%rax)
addq $-0xc, 0x70(%rsp)
jmp 0x395f
movl 0x4(%rsp), %eax
cmpl 0x30(%rsp), %eax
jg 0x395f
movl 0x2c(%rsp), %eax
movl %eax, %ebp
subl 0x4(%rsp), %ebp
movq %r12, %rax
shlq $0x20, %rax
movq %rax, 0xc8(%rsp)
xorl %r15d, %r15d
movq %rsi, 0xc0(%rsp)
movl %ebx, %r14d
addq 0xc8(%rsp), %r14
leaq (%r15,%rsi), %r13
cmpq 0x38(%rsp), %r13
jg 0x395f
movq %rbx, 0xd0(%rsp)
xorl %ebx, %ebx
leaq (%r12,%rbx), %rcx
movq 0x5f68713(%rip), %rax   # 0x5f6c368
movq 0x8(%rax), %rdx
cmpq %rcx, %rdx
jb 0x3cd0
movl %ebx, %esi
orl %r15d, %esi
je 0x3cb7
cmpq 0x38(%rsp), %r13
je 0x3c80
cmpq %rdx, %rcx
je 0x3c80
movq (%rax), %rax
movb (%rax,%r13), %cl
addq %r12, %rax
cmpb (%rbx,%rax), %cl
jne 0x3cb7
cmpl %ebx, %r15d
movl %ebx, %eax
cmoval %r15d, %eax
addl 0x4(%rsp), %eax
movl %eax, 0x18(%rsp)
movq %r14, 0x1c(%rsp)
movq 0x18(%rsp), %rax
movl 0x20(%rsp), %ecx
movq %rax, 0x8(%rsp)
movl %ecx, 0x10(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x8822
incq %rbx
movabsq $0x100000000, %rax      # imm = 0x100000000
addq %rax, %r14
cmpq %rbx, %rbp
jne 0x3c4a
incq %r15
movq 0xd0(%rsp), %rbx
incl %ebx
cmpq %rbp, %r15
movq 0xc0(%rsp), %rsi
jne 0x3c26
jmp 0x395f
leaq 0x60(%rsp), %rdi
leaq 0x8(%rsp), %rsi
callq 0x8a9e
jmp 0x395f
movq 0x30(%rsp), %rcx
testl %ecx, %ecx
movq 0xb0(%rsp), %r14
jle 0x3d44
movq 0x48(%rsp), %rax
movl %ecx, %ecx
xorl %edx, %edx
movl (%rax,%rdx,4), %esi
cmpl $-0x1, %esi
je 0x3d3c
movl 0x4(%rax,%rdx,4), %edi
cmpl $-0x1, %edi
je 0x3d36
cmpl %esi, %edi
jl 0x3d3c
decl %esi
movl %esi, 0x4(%rax,%rdx,4)
incq %rdx
cmpq %rdx, %rcx
jne 0x3d21
leaq 0x5f6867d(%rip), %rdi   # 0x5f6c3c8
leaq 0x40(%rsp), %rsi
callq 0x84fc
leaq 0x48(%rsp), %rsi
movq %rax, %rdi
callq 0x57c0
movq %r14, %rdi
movq %rax, %rsi
callq 0x5704
leaq 0x60(%rsp), %rdi
callq 0x87d2
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x3d8e
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq %r14, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3df0
jmp 0x3df0
movq %rax, %rbx
jmp 0x3dfd
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r14, %rdi
je 0x3df3
movq 0xe8(%rsp), %rsi
jmp 0x3de0
jmp 0x3df0
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0x3df3
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x21f0
jmp 0x3df3
jmp 0x3df0
jmp 0x3df0
jmp 0x3df0
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x87d2
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x3e14
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x21f0
movq %rbx, %rdi
callq 0x2330