// File: 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
movq %rsp, %rbp
subq $0x2f0, %rsp            # imm = 0x2F0
movq %rdi, -0x1c0(%rbp)
movq %rdi, %rax
movq %rax, -0x1b8(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movslq -0xc(%rbp), %rax
movq %rax, -0x20(%rbp)
imulq $0xabcdef, -0x20(%rbp), %rax # imm = 0xABCDEF
movslq -0x10(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
imulq $0xabcdef, -0x20(%rbp), %rax # imm = 0xABCDEF
movslq -0x14(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
imulq $0xabcdef, -0x20(%rbp), %rax # imm = 0xABCDEF
movslq -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
leaq 0x5f821e3(%rip), %rdi   # 0x5f87468
leaq -0x20(%rbp), %rsi
callq 0x8780
cmpq $0x0, %rax
je 0x52b8
leaq 0x5f821cd(%rip), %rdi   # 0x5f87468
leaq -0x20(%rbp), %rsi
callq 0x87b0
movq -0x1c0(%rbp), %rdi
movq %rax, %rsi
callq 0x87e0
jmp 0x5ca7
movl -0x18(%rbp), %eax
incl %eax
cltq
movq %rax, -0x1d0(%rbp)
movl $0xffffffff, -0x3c(%rbp) # imm = 0xFFFFFFFF
leaq -0x3d(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x84b0
movq -0x1d0(%rbp), %rsi
movq -0x1c8(%rbp), %rcx
leaq -0x38(%rbp), %rdi
leaq -0x3c(%rbp), %rdx
callq 0x84d0
jmp 0x52fa
leaq -0x3d(%rbp), %rdi
callq 0x8550
leaq -0xa0(%rbp), %rdi
callq 0x88d0
jmp 0x5311
movl $0x0, -0xb4(%rbp)
movl -0x10(%rbp), %eax
incl %eax
movl %eax, -0xc0(%rbp)
movl -0x14(%rbp), %eax
incl %eax
movl %eax, -0xc4(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xc4(%rbp), %rsi
callq 0x8960
movq %rax, -0x1d8(%rbp)
jmp 0x534d
movq -0x1d8(%rbp), %rax
movq %rax, -0xbc(%rbp)
leaq -0xb4(%rbp), %rdi
leaq -0xbc(%rbp), %rsi
callq 0x8920
movl %edx, -0x1e4(%rbp)
movq %rax, -0x1e0(%rbp)
jmp 0x537d
movl -0x1e4(%rbp), %eax
movq -0x1e0(%rbp), %rcx
movq %rcx, -0xd8(%rbp)
movl %eax, -0xd0(%rbp)
movl -0xd0(%rbp), %eax
movl %eax, -0xa8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x8b70
jmp 0x53c6
jmp 0x53c8
leaq -0xa0(%rbp), %rdi
callq 0x8990
cmpq $0x0, %rax
je 0x5b57
leaq -0xa0(%rbp), %rdi
callq 0x89c0
movl (%rax), %eax
movl %eax, -0xdc(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x89c0
movl 0x4(%rax), %eax
movl %eax, -0xe0(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x89c0
movl 0x8(%rax), %eax
movl %eax, -0xe4(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x89f0
movslq -0xdc(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
cmpl $-0x1, (%rax)
je 0x549d
movslq -0xdc(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
movl (%rax), %eax
movl -0xe4(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jg 0x549d
jmp 0x53c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x3d(%rbp), %rdi
callq 0x8550
jmp 0x5cb7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x5c9c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x5c90
movl -0xe0(%rbp), %eax
cmpl -0xc(%rbp), %eax
jle 0x5508
movslq -0xdc(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
cmpl $-0x1, (%rax)
je 0x54dc
movslq -0xdc(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
movl (%rax), %eax
movl -0xe4(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x5503
movl -0xe4(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x1e8(%rbp)
movslq -0xdc(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
movl -0x1e8(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x53c8
movl -0xe0(%rbp), %eax
cmpl -0xc(%rbp), %eax
jg 0x58a1
movslq -0xe4(%rbp), %rax
movq %rax, -0x1f8(%rbp)
movq 0x5f81edc(%rip), %rdi   # 0x5f87408
callq 0x8620
movq %rax, -0x1f0(%rbp)
jmp 0x553a
movq -0x1f8(%rbp), %rax
movq -0x1f0(%rbp), %rcx
cmpq %rcx, %rax
jae 0x58a1
movq 0x5f81eb0(%rip), %rdi   # 0x5f87408
movslq -0xe0(%rbp), %rsi
callq 0x3490
movq %rax, -0x200(%rbp)
jmp 0x556d
movq -0x200(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x20c(%rbp)
movq 0x5f81e84(%rip), %rdi   # 0x5f87408
movslq -0xe4(%rbp), %rsi
callq 0x3490
movq %rax, -0x208(%rbp)
jmp 0x5599
movl -0x20c(%rbp), %eax
movq -0x208(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x58a1
movq 0x5f81e50(%rip), %rax   # 0x5f87408
movq 0x20(%rax), %rdi
movslq -0xe0(%rbp), %rsi
movslq -0xe4(%rbp), %rdx
callq 0x8a60
movq %rax, -0x218(%rbp)
jmp 0x55d8
movq -0x218(%rbp), %rax
movl %eax, -0xe8(%rbp)
movl -0xe0(%rbp), %eax
movl -0xe8(%rbp), %ecx
addl %ecx, %eax
cltq
movq %rax, -0x228(%rbp)
movq 0x5f81e05(%rip), %rdi   # 0x5f87408
callq 0x8620
movq %rax, -0x220(%rbp)
jmp 0x5611
movq -0x220(%rbp), %rcx
movq -0x228(%rbp), %rax
subq %rcx, %rax
setbe %al
movb %al, -0x231(%rbp)
leaq -0x109(%rbp), %rdi
movq %rdi, -0x230(%rbp)
callq 0x3430
movq -0x230(%rbp), %rdx
leaq 0x16a9c(%rip), %rsi     # 0x1c0e8
leaq -0x108(%rbp), %rdi
callq 0x8300
jmp 0x565a
movb -0x231(%rbp), %al
movzbl %al, %edi
andl $0x1, %edi
leaq -0x108(%rbp), %rsi
callq 0x3a80
jmp 0x5674
leaq -0x108(%rbp), %rdi
callq 0x34a8
leaq -0x109(%rbp), %rdi
callq 0x32c0
movl -0xe4(%rbp), %eax
movl -0xe8(%rbp), %ecx
addl %ecx, %eax
cltq
movq %rax, -0x248(%rbp)
movq 0x5f81d5e(%rip), %rdi   # 0x5f87408
callq 0x8620
movq %rax, -0x240(%rbp)
jmp 0x56b8
movq -0x240(%rbp), %rcx
movq -0x248(%rbp), %rax
subq %rcx, %rax
setbe %al
movb %al, -0x251(%rbp)
leaq -0x131(%rbp), %rdi
movq %rdi, -0x250(%rbp)
callq 0x3430
movq -0x250(%rbp), %rdx
leaq 0x16a01(%rip), %rsi     # 0x1c0f4
leaq -0x130(%rbp), %rdi
callq 0x8300
jmp 0x5701
movb -0x251(%rbp), %al
movzbl %al, %edi
andl $0x1, %edi
leaq -0x130(%rbp), %rsi
callq 0x3a80
jmp 0x571b
leaq -0x130(%rbp), %rdi
callq 0x34a8
leaq -0x131(%rbp), %rdi
callq 0x32c0
movl -0xc(%rbp), %eax
movl -0xe0(%rbp), %ecx
subl %ecx, %eax
incl %eax
movl %eax, -0x138(%rbp)
leaq -0xe8(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x8b30
movq %rax, -0x260(%rbp)
jmp 0x5762
movq -0x260(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xe8(%rbp)
movl -0xe0(%rbp), %eax
movl -0xe8(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x154(%rbp)
movl -0xe4(%rbp), %eax
movl -0xe8(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x158(%rbp)
leaq -0x154(%rbp), %rdi
leaq -0x158(%rbp), %rsi
callq 0x8960
movq %rax, -0x268(%rbp)
jmp 0x57b5
movq -0x268(%rbp), %rax
movq %rax, -0x150(%rbp)
leaq -0xdc(%rbp), %rdi
leaq -0x150(%rbp), %rsi
callq 0x8ba0
movl %edx, -0x274(%rbp)
movq %rax, -0x270(%rbp)
jmp 0x57e5
movl -0x274(%rbp), %eax
movq -0x270(%rbp), %rcx
movq %rcx, -0x168(%rbp)
movl %eax, -0x160(%rbp)
movl -0x160(%rbp), %eax
movl %eax, -0x140(%rbp)
movq -0x168(%rbp), %rax
movq %rax, -0x148(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x8b70
jmp 0x582e
jmp 0x5b52
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x5859
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x34a8
leaq -0x109(%rbp), %rdi
callq 0x32c0
jmp 0x5c90
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x5890
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x130(%rbp), %rdi
callq 0x34a8
leaq -0x131(%rbp), %rdi
callq 0x32c0
jmp 0x5c90
movl $0x0, -0x16c(%rbp)
movl -0x16c(%rbp), %eax
movl -0x18(%rbp), %ecx
subl -0xdc(%rbp), %ecx
cmpl %ecx, %eax
jg 0x5b50
movl -0xe0(%rbp), %eax
addl -0x16c(%rbp), %eax
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
jle 0x58dd
jmp 0x5b50
movl $0x0, -0x170(%rbp)
movl -0x170(%rbp), %eax
movl -0x18(%rbp), %ecx
subl -0xdc(%rbp), %ecx
cmpl %ecx, %eax
jg 0x5b3a
movl -0xe4(%rbp), %eax
movl -0x170(%rbp), %ecx
addl %ecx, %eax
cltq
movq %rax, -0x288(%rbp)
movq 0x5f81aec(%rip), %rdi   # 0x5f87408
callq 0x8620
movq %rax, -0x280(%rbp)
jmp 0x592a
movq -0x288(%rbp), %rax
movq -0x280(%rbp), %rcx
cmpq %rcx, %rax
jbe 0x5942
jmp 0x5b3a
movl -0x16c(%rbp), %eax
addl -0x170(%rbp), %eax
cmpl $0x0, %eax
jle 0x5b24
movl -0xe0(%rbp), %eax
addl -0x16c(%rbp), %eax
movl -0xc(%rbp), %ecx
addl $0x1, %ecx
cmpl %ecx, %eax
je 0x5a24
movl -0xe4(%rbp), %eax
movl -0x170(%rbp), %ecx
addl %ecx, %eax
cltq
movq %rax, -0x298(%rbp)
movq 0x5f81a79(%rip), %rdi   # 0x5f87408
callq 0x8620
movq %rax, -0x290(%rbp)
jmp 0x599d
movq -0x298(%rbp), %rax
movq -0x290(%rbp), %rcx
cmpq %rcx, %rax
je 0x5a24
movq 0x5f81a51(%rip), %rdi   # 0x5f87408
movl -0xe0(%rbp), %eax
movl -0x16c(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x3490
movq %rax, -0x2a0(%rbp)
jmp 0x59d6
movq -0x2a0(%rbp), %rax
movsbl (%rax), %eax
movl %eax, -0x2ac(%rbp)
movq 0x5f81a1b(%rip), %rdi   # 0x5f87408
movl -0xe4(%rbp), %eax
movl -0x170(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x3490
movq %rax, -0x2a8(%rbp)
jmp 0x5a0c
movl -0x2ac(%rbp), %eax
movq -0x2a8(%rbp), %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x5b22
movl -0xdc(%rbp), %eax
movl %eax, -0x2bc(%rbp)
leaq -0x16c(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x8be0
movq %rax, -0x2b8(%rbp)
jmp 0x5a4c
movl -0x2bc(%rbp), %eax
movq -0x2b8(%rbp), %rcx
movl (%rcx), %ecx
addl %ecx, %eax
movl %eax, -0x184(%rbp)
movl -0xe0(%rbp), %eax
movl -0x16c(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x190(%rbp)
movl -0xe4(%rbp), %eax
movl -0x170(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x194(%rbp)
leaq -0x190(%rbp), %rdi
leaq -0x194(%rbp), %rsi
callq 0x8960
movq %rax, -0x2c8(%rbp)
jmp 0x5aa7
movq -0x2c8(%rbp), %rax
movq %rax, -0x18c(%rbp)
leaq -0x184(%rbp), %rdi
leaq -0x18c(%rbp), %rsi
callq 0x8920
movl %edx, -0x2d4(%rbp)
movq %rax, -0x2d0(%rbp)
jmp 0x5ad7
movl -0x2d4(%rbp), %eax
movq -0x2d0(%rbp), %rcx
movq %rcx, -0x1a8(%rbp)
movl %eax, -0x1a0(%rbp)
movl -0x1a0(%rbp), %eax
movl %eax, -0x178(%rbp)
movq -0x1a8(%rbp), %rax
movq %rax, -0x180(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x88f0
jmp 0x5b20
jmp 0x5b22
jmp 0x5b24
jmp 0x5b26
movl -0x170(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x170(%rbp)
jmp 0x58e7
jmp 0x5b3c
movl -0x16c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x16c(%rbp)
jmp 0x58ab
jmp 0x5b52
jmp 0x53c8
movl $0x0, -0x1ac(%rbp)
movl -0x1ac(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x5c32
movslq -0x1ac(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
cmpl $-0x1, (%rax)
je 0x5c1c
movl -0x1ac(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
cmpl $-0x1, (%rax)
je 0x5be2
movl -0x1ac(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
movl (%rax), %eax
movl %eax, -0x2d8(%rbp)
movslq -0x1ac(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
movq %rax, %rcx
movl -0x2d8(%rbp), %eax
movl (%rcx), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jle 0x5c1a
movslq -0x1ac(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
movl (%rax), %eax
subl $0x1, %eax
movl %eax, -0x2dc(%rbp)
movl -0x1ac(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq -0x38(%rbp), %rdi
callq 0x8590
movl -0x2dc(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x5c1c
jmp 0x5c1e
movl -0x1ac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1ac(%rbp)
jmp 0x5b61
leaq 0x5f8182f(%rip), %rdi   # 0x5f87468
leaq -0x20(%rbp), %rsi
callq 0x87b0
movq %rax, -0x2e8(%rbp)
jmp 0x5c4b
movq -0x2e8(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x8c20
movq %rax, -0x2f0(%rbp)
jmp 0x5c64
movq -0x2f0(%rbp), %rsi
movq -0x1c0(%rbp), %rdi
callq 0x87e0
jmp 0x5c79
leaq -0xa0(%rbp), %rdi
callq 0x8e70
leaq -0x38(%rbp), %rdi
callq 0x8640
jmp 0x5ca7
leaq -0xa0(%rbp), %rdi
callq 0x8e70
leaq -0x38(%rbp), %rdi
callq 0x8640
jmp 0x5cb7
movq -0x1b8(%rbp), %rax
addq $0x2f0, %rsp            # imm = 0x2F0
popq %rbp
retq
movq -0x48(%rbp), %rdi
callq 0x3420