// File: zengfenfei[P]codility/src/TapeEquilibrium.cpp
// Function: solution(std::vector<int, std::allocator<int>>&)
int solution(vector<int> &A) {
	int n = A.size();
	vector<int> leftSums(n), rightSums(n);
	leftSums[0] = A[0];
	for (int i = 1; i < n; i++) {
		leftSums[i] = leftSums[i - 1] + A[i];
	}

	rightSums[n - 1] = A[n - 1];
	int minDiff = abs(leftSums[n - 2] - rightSums[n - 1]);
	for (int i = n - 2; i > 0; i--) {
		rightSums[i] = rightSums[i + 1] + A[i];
		int diff = abs(leftSums[i - 1] - rightSums[i]);
		if (diff < minDiff) {
			minDiff = diff;
		}
	}
	return minDiff;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xc0, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x14e0
movl %eax, -0xc(%rbp)
movslq -0xc(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0x78(%rbp)
callq 0x1500
movq -0x80(%rbp), %rsi
movq -0x78(%rbp), %rdx
leaq -0x28(%rbp), %rdi
callq 0x1520
jmp 0x1253
leaq -0x29(%rbp), %rdi
callq 0x1590
movslq -0xc(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0x88(%rbp)
callq 0x1500
movq -0x90(%rbp), %rsi
movq -0x88(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x1520
jmp 0x1290
leaq -0x59(%rbp), %rdi
callq 0x1590
movq -0x8(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x15b0
movl (%rax), %eax
movl %eax, -0x94(%rbp)
leaq -0x28(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x15b0
movl -0x94(%rbp), %ecx
movl %ecx, (%rax)
movl $0x1, -0x60(%rbp)
movl -0x60(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x136b
movl -0x60(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
leaq -0x28(%rbp), %rdi
callq 0x15b0
movl (%rax), %eax
movl %eax, -0x9c(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x60(%rbp), %rsi
callq 0x15b0
movq %rax, %rcx
movl -0x9c(%rbp), %eax
addl (%rcx), %eax
movl %eax, -0x98(%rbp)
movslq -0x60(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x15b0
movl -0x98(%rbp), %ecx
movl %ecx, (%rax)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x12ca
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x29(%rbp), %rdi
callq 0x1590
jmp 0x14c4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x59(%rbp), %rdi
callq 0x1590
leaq -0x28(%rbp), %rdi
callq 0x15d0
jmp 0x14c4
movq -0x8(%rbp), %rdi
movl -0xc(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x15b0
movl (%rax), %eax
movl %eax, -0xa4(%rbp)
movl -0xc(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
leaq -0x58(%rbp), %rdi
callq 0x15b0
movl -0xa4(%rbp), %ecx
movl %ecx, (%rax)
movl -0xc(%rbp), %eax
subl $0x2, %eax
movslq %eax, %rsi
leaq -0x28(%rbp), %rdi
callq 0x15b0
movl (%rax), %eax
movl %eax, -0xa0(%rbp)
movl -0xc(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
leaq -0x58(%rbp), %rdi
callq 0x15b0
movq %rax, %rcx
movl -0xa0(%rbp), %eax
subl (%rcx), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x64(%rbp)
movl -0xc(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x68(%rbp)
cmpl $0x0, -0x68(%rbp)
jle 0x149a
movl -0x68(%rbp), %eax
addl $0x1, %eax
movslq %eax, %rsi
leaq -0x58(%rbp), %rdi
callq 0x15b0
movl (%rax), %eax
movl %eax, -0xb0(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x68(%rbp), %rsi
callq 0x15b0
movq %rax, %rcx
movl -0xb0(%rbp), %eax
addl (%rcx), %eax
movl %eax, -0xac(%rbp)
movslq -0x68(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x15b0
movl -0xac(%rbp), %ecx
movl %ecx, (%rax)
movl -0x68(%rbp), %eax
subl $0x1, %eax
movslq %eax, %rsi
leaq -0x28(%rbp), %rdi
callq 0x15b0
movl (%rax), %eax
movl %eax, -0xa8(%rbp)
movslq -0x68(%rbp), %rsi
leaq -0x58(%rbp), %rdi
callq 0x15b0
movq %rax, %rcx
movl -0xa8(%rbp), %eax
subl (%rcx), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %eax
cmpl -0x64(%rbp), %eax
jge 0x148a
movl -0x6c(%rbp), %eax
movl %eax, -0x64(%rbp)
jmp 0x148c
movl -0x68(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x13e9
movl -0x64(%rbp), %eax
movl %eax, -0xb4(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x15d0
leaq -0x28(%rbp), %rdi
callq 0x15d0
movl -0xb4(%rbp), %eax
addq $0xc0, %rsp
popq %rbp
retq
movq -0x38(%rbp), %rdi
callq 0x10c0
nopl (%rax)