// File: /workspace/github_cpp_makefile_star2_O1/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), %ebx
movq 0x5f68511(%rip), %r11   # 0x5f6c350
testq %r11, %r11
je 0x3ed6
movl %esi, %eax
subl %ecx, %eax
leal (%rax,%r9), %edi
addl $0x2, %edi
addl %r9d, %eax
addl %ebx, %eax
addl $0x2, %eax
movq 0x5f68506(%rip), %r10   # 0x5f6c368
movl 0x8(%r10), %r10d
decl %r10d
cmpl %r10d, %eax
cmovgel %r10d, %eax
movq %rbx, %r8
subl %ebx, %edi
cmpl %r10d, %edi
cmovgel %r10d, %edi
movq 0x5f684f5(%rip), %rbx   # 0x5f6c378
movslq %esi, %rsi
movslq %ecx, %r14
movslq %edi, %r15
movslq %r9d, %r9
movslq %eax, %r12
xorl %eax, %eax
movq %r11, %r13
xorl %edx, %edx
movq (%rbx), %r10
movl 0x4(%r10,%rsi,4), %ebp
subl (%r10,%r14,4), %ebp
movl 0x4(%r10,%r15,4), %ecx
movl (%r10,%r9,4), %edi
subl %edi, %ecx
cmpl %ecx, %ebp
jge 0x3eba
subl %ebp, %eax
addl %ecx, %eax
jmp 0x3ecb
movl 0x4(%r10,%r12,4), %ecx
subl %edi, %ecx
cmpl %ecx, %ebp
jle 0x3ecb
addl %edx, %ebp
subl %ecx, %ebp
movl %ebp, %edx
addq $0x18, %rbx
decq %r13
jne 0x3e99
jmp 0x3edd
movq %rbx, %r8
xorl %edx, %edx
xorl %eax, %eax
movl %edx, %r13d
cmpl %edx, %eax
cmovgl %eax, %r13d
xorl %eax, %eax
movq %r8, %rdi
cmpl %edi, %r13d
jg 0x3f80
movl $0x0, %esi
testq %r11, %r11
movq -0x8(%rsp), %r12
je 0x3f73
movslq %r12d, %r9
movl -0x10(%rsp), %ecx
subl %ecx, %r12d
movl -0xc(%rsp), %eax
addl %eax, %r12d
leal (%r12,%rdi), %ebx
xorl %esi, %esi
testl %ebx, %ebx
cmovlel %esi, %ebx
subl %edi, %r12d
testl %r12d, %r12d
cmovlel %esi, %r12d
movq 0x5f68448(%rip), %r14   # 0x5f6c378
movslq %ecx, %rdx
movslq %eax, %r8
xorl %eax, %eax
movq (%r14), %r10
movl 0x4(%r10,%rdx,4), %ebp
subl (%r10,%r9,4), %ebp
movl 0x4(%r10,%r8,4), %r15d
movl %r15d, %ecx
subl (%r10,%rbx,4), %ecx
cmpl %ecx, %ebp
jge 0x3f5a
subl %ebp, %esi
addl %ecx, %esi
jmp 0x3f6a
subl (%r10,%r12,4), %r15d
cmpl %r15d, %ebp
jle 0x3f6a
addl %eax, %ebp
subl %r15d, %ebp
movl %ebp, %eax
addq $0x18, %r14
decq %r11
jne 0x3f38
cmpl %eax, %esi
cmovgl %esi, %eax
addl %r13d, %eax
cmpl %edi, %eax
setle %al
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq