// File: shangjingbo1226[P]MACFP/src/methods/MACFP.cpp
// Function: checkByPrefixSum(int, int, int, int, int, int, int)
bool checkByPrefixSum(int leftBound, int rightBound, int l, int r, int x, int y, int remainDistance)
{
    int length = rightBound - r + 1;
    int xMin = min((int)s->size() - 1, y + length + 1 - remainDistance);
    int xMax = min((int)s->size() - 1, y + length + 1 + remainDistance);
    int sum1 = 0, sum2 = 0;
    for (int i = 0; i < alphabet.size(); ++ i) {
        int goal = getSum(prefixSum[i], r, rightBound);
        int mini = getSum(prefixSum[i], y, xMin);
        int maxi = getSum(prefixSum[i], y, xMax);
        if (goal < mini) {
            sum1 += mini - goal;
        } else if (goal > maxi) {
            sum2 += goal - maxi;
        }
    }
    int dist = max(sum1, sum2);
    if (dist > remainDistance) {
        return false;
    }

    length = l - leftBound + 1;
    int yMin = max(0, x - length + 1 - remainDistance);
    int yMax = max(0, x - length + 1 + remainDistance);
    sum1 = sum2 = 0;
    for (int i = 0; i < alphabet.size(); ++ i) {
        int goal = getSum(prefixSum[i], leftBound, l);
        int mini = getSum(prefixSum[i], yMax, x);
        int maxi = getSum(prefixSum[i], yMin, x);
        if (goal < mini) {
            sum1 += mini - goal;
        } else if (goal > maxi) {
            sum2 += goal - maxi;
        }
    }
    dist += max(sum1, sum2);
    return dist <= remainDistance;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movl 0x10(%rbp), %eax
movl %edi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movl %edx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
movl %r8d, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
movl -0xc(%rbp), %eax
subl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movq 0x5f81713(%rip), %rdi   # 0x5f87408
callq 0x8620
subl $0x1, %eax
movl %eax, -0x28(%rbp)
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
addl $0x1, %eax
subl 0x10(%rbp), %eax
movl %eax, -0x2c(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x8b30
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movq 0x5f816e0(%rip), %rdi   # 0x5f87408
callq 0x8620
subl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x1c(%rbp), %eax
addl -0x20(%rbp), %eax
addl $0x1, %eax
addl 0x10(%rbp), %eax
movl %eax, -0x38(%rbp)
leaq -0x34(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0x8b30
movl (%rax), %eax
movl %eax, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x44(%rbp)
movslq -0x44(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq 0x5f8166d(%rip), %rdi   # 0x5f873e8
callq 0x31a0
movq %rax, %rcx
movq -0x88(%rbp), %rax
cmpq %rcx, %rax
jae 0x5e32
movslq -0x44(%rbp), %rsi
leaq 0x5f8167a(%rip), %rdi   # 0x5f87418
callq 0x8ee0
movq %rax, %rdi
movl -0x14(%rbp), %esi
movl -0xc(%rbp), %edx
callq 0x4790
movl %eax, -0x48(%rbp)
movslq -0x44(%rbp), %rsi
leaq 0x5f81659(%rip), %rdi   # 0x5f87418
callq 0x8ee0
movq %rax, %rdi
movl -0x1c(%rbp), %esi
movl -0x24(%rbp), %edx
callq 0x4790
movl %eax, -0x4c(%rbp)
movslq -0x44(%rbp), %rsi
leaq 0x5f81638(%rip), %rdi   # 0x5f87418
callq 0x8ee0
movq %rax, %rdi
movl -0x1c(%rbp), %esi
movl -0x30(%rbp), %edx
callq 0x4790
movl %eax, -0x50(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x4c(%rbp), %eax
jge 0x5e0c
movl -0x4c(%rbp), %eax
subl -0x48(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x5e22
movl -0x48(%rbp), %eax
cmpl -0x50(%rbp), %eax
jle 0x5e20
movl -0x48(%rbp), %eax
subl -0x50(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x5e22
jmp 0x5e24
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x5d69
leaq -0x3c(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x8be0
movl (%rax), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl 0x10(%rbp), %eax
jle 0x5e55
movb $0x0, -0x1(%rbp)
jmp 0x5fb2
movl -0x10(%rbp), %eax
subl -0x8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
movl $0x0, -0x5c(%rbp)
movl -0x18(%rbp), %eax
subl -0x20(%rbp), %eax
addl $0x1, %eax
subl 0x10(%rbp), %eax
movl %eax, -0x60(%rbp)
leaq -0x5c(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x8be0
movl (%rax), %eax
movl %eax, -0x58(%rbp)
movl $0x0, -0x68(%rbp)
movl -0x18(%rbp), %eax
subl -0x20(%rbp), %eax
addl $0x1, %eax
addl 0x10(%rbp), %eax
movl %eax, -0x6c(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x6c(%rbp), %rsi
callq 0x8be0
movl (%rax), %eax
movl %eax, -0x64(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x0, -0x3c(%rbp)
movl $0x0, -0x70(%rbp)
movslq -0x70(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq 0x5f81510(%rip), %rdi   # 0x5f873e8
callq 0x31a0
movq %rax, %rcx
movq -0x90(%rbp), %rax
cmpq %rcx, %rax
jae 0x5f8f
movslq -0x70(%rbp), %rsi
leaq 0x5f8151d(%rip), %rdi   # 0x5f87418
callq 0x8ee0
movq %rax, %rdi
movl -0x8(%rbp), %esi
movl -0x10(%rbp), %edx
callq 0x4790
movl %eax, -0x74(%rbp)
movslq -0x70(%rbp), %rsi
leaq 0x5f814fc(%rip), %rdi   # 0x5f87418
callq 0x8ee0
movq %rax, %rdi
movl -0x64(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x4790
movl %eax, -0x78(%rbp)
movslq -0x70(%rbp), %rsi
leaq 0x5f814db(%rip), %rdi   # 0x5f87418
callq 0x8ee0
movq %rax, %rdi
movl -0x58(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x4790
movl %eax, -0x7c(%rbp)
movl -0x74(%rbp), %eax
cmpl -0x78(%rbp), %eax
jge 0x5f69
movl -0x78(%rbp), %eax
subl -0x74(%rbp), %eax
addl -0x3c(%rbp), %eax
movl %eax, -0x3c(%rbp)
jmp 0x5f7f
movl -0x74(%rbp), %eax
cmpl -0x7c(%rbp), %eax
jle 0x5f7d
movl -0x74(%rbp), %eax
subl -0x7c(%rbp), %eax
addl -0x40(%rbp), %eax
movl %eax, -0x40(%rbp)
jmp 0x5f7f
jmp 0x5f81
movl -0x70(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x70(%rbp)
jmp 0x5ec6
leaq -0x3c(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x8be0
movl (%rax), %eax
addl -0x54(%rbp), %eax
movl %eax, -0x54(%rbp)
movl -0x54(%rbp), %eax
cmpl 0x10(%rbp), %eax
setle %al
andb $0x1, %al
movb %al, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x90, %rsp
popq %rbp
retq