user: 请从给定的汇编指令推导出C源代码：

```asm
<main>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  sub    $0xf88,%rsp
  lea    D19(%rip),%r12
  mov    %r12,%rdi
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  lea    -0x1f84(%rbp),%rsi
  call   <scanf@plt>
  movslq -0x1f84(%rbp),%rax
  mov    %rsp,%rcx
  lea    0xf(,%rax,4),%rdx
  mov    %eax,-0x1f98(%rbp)
  mov    %rdx,%rax
  and    $0xfffffffffffff000,%rdx
  sub    %rdx,%rcx
  and    $0xfffffffffffffff0,%rax
  cmp    %rcx,%rsp
  je     L98
L75:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L75
L98:
  and    $0xfff,%eax
  sub    %rax,%rsp
  test   %rax,%rax
  jne    L9
L8:
  lea    0x3(%rsp),%rax
  mov    %rax,%r13
  and    $0xfffffffffffffffc,%rax
  shr    $0x2,%r13
  cmpl   $0x0,-0x1f98(%rbp)
  mov    %rax,-0x1fa8(%rbp)
  jle    L32
  mov    %rax,%r14
  xor    %ebx,%ebx
L3:
  mov    %r14,%rsi
  mov    %r12,%rdi
  add    $0x1,%ebx
  add    $0x4,%r14
  call   <scanf@plt>
  mov    -0x1f84(%rbp),%eax
  cmp    %ebx,%eax
  jg     L3
  mov    %eax,-0x1f98(%rbp)
L32:
  mov    0x0(,%r13,4),%ecx
  xor    %eax,%eax
  lea    -0x1f80(%rbp),%r15
  xor    %edi,%edi
  mov    %ecx,%esi
  neg    %esi
  nopl   0x0(%rax,%rax,1)
L84:
  mov    %ecx,%edx
  sub    %eax,%edx
  cmp    %eax,%ecx
  cmovl  %esi,%edx
  cmp    %eax,%edx
  mov    %edi,%edx
  cmovle %ecx,%edx
  add    $0x1,%esi
  mov    %edx,(%r15,%rax,4)
  add    $0x1,%rax
  cmp    $0x3e9,%rax
  jne    L84
  movslq -0x1f98(%rbp),%rcx
  movl   $0xfffffffe,-0x1f94(%rbp)
  mov    %rcx,%rax
  mov    %rcx,-0x1fa0(%rbp)
  mov    $0x1,%ecx
  cmp    $0x1,%eax
  jle    L127
  mov    %r15,-0x1fb0(%rbp)
  mov    %rcx,%r15
L53:
  mov    -0x1fa8(%rbp),%rax
  mov    -0x1f94(%rbp),%r14d
  mov    -0x1fb0(%rbp),%rcx
  mov    (%rax,%r15,4),%r10d
  mov    %r15d,%eax
  and    $0x1,%r14d
  and    $0x1,%eax
  imul   $0x3e9,%r14,%r14
  mov    %eax,%r13d
  movslq %eax,%r12
  mov    %r10d,%r11d
  xor    %eax,%eax
  xor    $0x1,%r13d
  imul   $0xfa4,%r12,%r12
  neg    %r11d
  movslq %r13d,%r13
  imul   $0xfa4,%r13,%r13
  add    %rcx,%r12
  add    %rcx,%r13
  jmp    L149
  nopl   0x0(%rax,%rax,1)
L79:
  cmovge %ecx,%edx
L29:
  mov    %edx,(%r12,%rax,4)
  add    $0x1,%rax
  add    $0x1,%r11d
  cmp    $0x3e9,%rax
  je     L73
L149:
  mov    %eax,%esi
  mov    %eax,%r9d
  mov    %r10d,%edx
  cmp    %eax,%r10d
  jg     L141
  movslq %r11d,%rdx
  add    %r14,%rdx
  mov    -0x1f80(%rbp,%rdx,4),%ecx
  add    %r10d,%ecx
  mov    %ecx,%edx
L141:
  mov    0x0(%r13,%rax,4),%ecx
  mov    %esi,%edi
  mov    %edx,%r8d
  mov    %esi,%ebx
  sub    %edx,%edi
  sub    %esi,%r8d
  cmp    %r9d,%edx
  cmovl  %edi,%r8d
  mov    %ecx,%edi
  sub    %ecx,%ebx
  sub    %esi,%edi
  cmp    %r9d,%ecx
  cmovge %edi,%ebx
  cmp    %ebx,%r8d
  jne    L79
  cmp    %ecx,%edx
  cmovl  %ecx,%edx
  jmp    L29
L73:
  subl   $0x1,-0x1f94(%rbp)
  add    $0x1,%r15
  cmp    %r15,-0x1fa0(%rbp)
  jne    L53
L127:
  mov    -0x1f98(%rbp),%eax
  lea    D12(%rip),%rdi
  not    %eax
  and    $0x1,%eax
  imul   $0xfa4,%rax,%rax
  mov    -0xfe0(%rbp,%rax,1),%esi
  call   <printf@plt>
  mov    -0x38(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L122
  lea    -0x28(%rbp),%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
L9:
  orq    $0x0,-0x8(%rsp,%rax,1)
  jmp    L8
L122:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: tag: D19
datatype: string
name: unpack_data
arguments: tag: D12
datatype: string

tool: D19: %d

tool: D12: %d


assistant: ```c
int main() {
  int n;
  scanf("%d", &n);
  int w[n];
  for (int i = 0; i < n; i++)
    scanf("%d", w + i);
  int mem[2][1001];
  for (int t = 0; t <= 1000; t++) {
    mem[0][t] = t < (t > w[0] ? t - w[0] : w[0] - t) ? 0 : w[0];
  }
  for (int i = 1; i < n; i++) {
    for (int t = 0; t <= 1000; t++) {
      int incl = w[i] > t ? w[i] : w[i] + mem[!(i & 1)][t - w[i]], excl = mem[!(i & 1)][t];
      int a1 = t > incl ? t - incl : incl - t, a2 = t > excl ? t - excl : excl - t;
      mem[i & 1][t] = a1 == a2 ? (incl > excl ? incl : excl) : (a1 < a2 ? incl : excl);
    }
  }
  printf("%d\n", mem[!(n & 1)][1000]);
  return 0;
}
```