// File: /workspace/github_cpp_makefile_star2_O2/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 %r8d, -0xc(%rsp)
movl %edx, -0x10(%rsp)
movq %rdi, -0x8(%rsp)
movl 0x38(%rsp), %r8d
movq 0x5f68bed(%rip), %rax   # 0x5f6c368
movl 0x8(%rax), %ebp
decl %ebp
movslq %esi, %rax
subl %ecx, %esi
leal (%rsi,%r9), %edi
addl $0x2, %edi
addl %r9d, %esi
subl %r8d, %edi
cmpl %ebp, %edi
cmovgel %ebp, %edi
addl %r8d, %esi
addl $0x2, %esi
cmpl %ebp, %esi
cmovll %esi, %ebp
movq 0x5f68ba7(%rip), %rsi   # 0x5f6c350
movq 0x5f68bc8(%rip), %r11   # 0x5f6c378
movslq %ecx, %rbx
movslq %edi, %r14
movslq %r9d, %r9
movslq %ebp, %rdx
xorl %r8d, %r8d
movq %r11, %r12
movq %rsi, %r13
xorl %ebp, %ebp
subq $0x1, %r13
jb 0x380a
movq (%r12), %r10
movl 0x4(%r10,%rax,4), %ecx
subl (%r10,%rbx,4), %ecx
movl 0x4(%r10,%r14,4), %edi
movl (%r10,%r9,4), %r15d
subl %r15d, %edi
cmpl %edi, %ecx
jge 0x37f0
subl %ecx, %ebp
addl %edi, %ebp
jmp 0x3804
movl 0x4(%r10,%rdx,4), %edi
subl %r15d, %edi
cmpl %edi, %ecx
jle 0x3804
addl %r8d, %ecx
subl %edi, %ecx
movl %ecx, %r8d
addq $0x18, %r12
jmp 0x37c7
movl %r8d, %r13d
cmpl %r8d, %ebp
cmovgl %ebp, %r13d
xorl %eax, %eax
movl 0x38(%rsp), %r15d
cmpl %r15d, %r13d
jg 0x389f
movq -0x8(%rsp), %r12
movslq %r12d, %r9
movl -0x10(%rsp), %edx
subl %edx, %r12d
movl -0xc(%rsp), %ecx
addl %ecx, %r12d
movl %r12d, %ebx
subl %r15d, %ebx
testl %ebx, %ebx
cmovlel %eax, %ebx
addl %r15d, %r12d
testl %r12d, %r12d
cmovlel %eax, %r12d
movslq %edx, %rdx
movslq %ecx, %r8
xorl %ebp, %ebp
subq $0x1, %rsi
jb 0x3891
movq (%r11), %r10
movl 0x4(%r10,%rdx,4), %ecx
subl (%r10,%r9,4), %ecx
movl 0x4(%r10,%r8,4), %r14d
movl %r14d, %edi
subl (%r10,%r12,4), %edi
cmpl %edi, %ecx
jge 0x387b
subl %ecx, %ebp
addl %edi, %ebp
jmp 0x388b
subl (%r10,%rbx,4), %r14d
cmpl %r14d, %ecx
jle 0x388b
addl %eax, %ecx
subl %r14d, %ecx
movl %ecx, %eax
addq $0x18, %r11
jmp 0x3853
cmpl %eax, %ebp
cmovgl %ebp, %eax
addl %r13d, %eax
cmpl %r15d, %eax
setle %al
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq