// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
movl 0x38(%rsp), %r12d
movq 0x5f68499(%rip), %r11   # 0x5f6c350
testq %r11, %r11
je 0x3fe2
movl %r8d, -0xc(%rsp)
movq %rdi, -0x8(%rsp)
movl %esi, %eax
subl %ecx, %eax
leal (%rax,%r9), %edi
addl $0x2, %edi
addl %r9d, %eax
leal (%r12,%rax), %r10d
addl $0x2, %r10d
movq 0x5f68481(%rip), %rax   # 0x5f6c368
movl 0x8(%rax), %eax
decl %eax
cmpl %eax, %r10d
cmovgel %eax, %r10d
subl %r12d, %edi
cmpl %eax, %edi
cmovgel %eax, %edi
movq 0x5f68476(%rip), %rax   # 0x5f6c378
movslq %esi, %rsi
movslq %ecx, %rbx
movslq %edi, %r14
movslq %r9d, %r15
movslq %r10d, %r8
xorl %r9d, %r9d
movq %r11, %r13
xorl %r12d, %r12d
movq (%rax), %r10
movl 0x4(%r10,%rsi,4), %ebp
subl (%r10,%rbx,4), %ebp
movl 0x4(%r10,%r14,4), %ecx
movl (%r10,%r15,4), %edi
subl %edi, %ecx
cmpl %ecx, %ebp
jge 0x3f3d
subl %ebp, %r9d
addl %ecx, %r9d
jmp 0x3f50
movl 0x4(%r10,%r8,4), %ecx
subl %edi, %ecx
cmpl %ecx, %ebp
jle 0x3f50
addl %r12d, %ebp
subl %ecx, %ebp
movl %ebp, %r12d
addq $0x18, %rax
decq %r13
jne 0x3f1a
movl %r12d, %r13d
cmpl %r12d, %r9d
cmovgl %r9d, %r13d
xorl %eax, %eax
movl 0x38(%rsp), %r12d
cmpl %r12d, %r13d
jg 0x4000
movq -0x8(%rsp), %rdi
movslq %edi, %rsi
subl %edx, %edi
movl -0xc(%rsp), %ecx
addl %ecx, %edi
leal (%rdi,%r12), %r9d
testl %r9d, %r9d
cmovlel %eax, %r9d
subl %r12d, %edi
testl %edi, %edi
cmovlel %eax, %edi
movq 0x5f683db(%rip), %rbx   # 0x5f6c378
movslq %edx, %r14
movslq %ecx, %r8
xorl %edx, %edx
movq (%rbx), %r10
movl 0x4(%r10,%r14,4), %ebp
subl (%r10,%rsi,4), %ebp
movl 0x4(%r10,%r8,4), %r15d
movl %r15d, %ecx
subl (%r10,%r9,4), %ecx
cmpl %ecx, %ebp
jge 0x3fc7
subl %ebp, %eax
addl %ecx, %eax
jmp 0x3fd7
subl (%r10,%rdi,4), %r15d
cmpl %r15d, %ebp
jle 0x3fd7
addl %edx, %ebp
subl %r15d, %ebp
movl %ebp, %edx
addq $0x18, %rbx
decq %r11
jne 0x3fa5
jmp 0x3fee
xorl %r13d, %r13d
testl %r12d, %r12d
js 0x3ffe
xorl %edx, %edx
xorl %eax, %eax
cmpl %edx, %eax
cmovgl %eax, %edx
addl %r13d, %edx
cmpl %r12d, %edx
setle %al
jmp 0x4000
xorl %eax, %eax
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq