#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int knapsack(int *, int, int, int **);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int main() {
  int i, j, n, m;
  int a[100];
  int sum, odd, knap;
  int **A = (int **)malloc(sizeof(int *) * (100 + 1));
  for (j = 0; j < 100 + 1; j++) {
    A[j] = (int *)malloc(sizeof(int) * 500 * 100 * 100);
  }
  scanf(" %d", &n);
  for (i = 0; i < n; i++) {
    scanf(" %d", &m);
    sum = 0;
    for (j = 0; j < m; j++) {
      scanf(" %d", &a[j]);
      sum += a[j];
    }
    odd = sum & 1;
    knap = knapsack(a, (sum / 2), m, A);
    sum = sum - knap * 2;
    printf("%d\n", sum);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x1d0,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x328,%edi
call   1040 <malloc@plt>
mov    %rax,-0x1c8(%rbp)
movl   $0x0,-0xc(%rbp)
cmpl   $0x65,-0xc(%rbp)
jge    119e <main+0x5e>
mov    $0x1312d00,%edi
call   1040 <malloc@plt>
mov    %rax,%rdx
mov    -0x1c8(%rbp),%rax
movslq -0xc(%rbp),%rcx
mov    %rdx,(%rax,%rcx,8)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    116a <main+0x2a>
lea    0xe5b(%rip),%rdi
lea    -0x10(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%eax
cmp    -0x10(%rbp),%eax
jge    12a3 <main+0x163>
lea    0xe38(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1050 <scanf@plt>
movl   $0x0,-0x1b4(%rbp)
movl   $0x0,-0xc(%rbp)
mov    -0xc(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1231 <main+0xf1>
movslq -0xc(%rbp),%rax
lea    -0x1b0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xdf9(%rip),%rdi
call   1050 <scanf@plt>
movslq -0xc(%rbp),%rax
mov    -0x1b0(%rbp,%rax,4),%eax
add    -0x1b4(%rbp),%eax
mov    %eax,-0x1b4(%rbp)
mov    -0xc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xc(%rbp)
jmp    11e2 <main+0xa2>
mov    -0x1b4(%rbp),%eax
and    $0x1,%eax
mov    %eax,-0x1b8(%rbp)
lea    -0x1b0(%rbp),%rdi
mov    -0x1b4(%rbp),%eax
mov    $0x2,%ecx
cltd
idiv   %ecx
mov    %eax,%esi
mov    -0x14(%rbp),%edx
mov    -0x1c8(%rbp),%rcx
call   1060 <knapsack@plt>
mov    %eax,-0x1bc(%rbp)
mov    -0x1b4(%rbp),%eax
mov    -0x1bc(%rbp),%ecx
shl    $0x1,%ecx
sub    %ecx,%eax
mov    %eax,-0x1b4(%rbp)
mov    -0x1b4(%rbp),%esi
lea    0xd74(%rip),%rdi
call   1030 <printf@plt>
mov    -0x8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x8(%rbp)
jmp    11b5 <main+0x75>
xor    %eax,%eax
add    $0x1d0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x1a8,%rsp
mov    $0x328,%edi
call   1040 <malloc@plt>
mov    %rax,%r14
xor    %ebx,%ebx
mov    $0x1312d00,%edi
call   1040 <malloc@plt>
mov    %rax,(%r14,%rbx,8)
add    $0x1,%rbx
cmp    $0x65,%rbx
jne    1160 <main+0x20>
lea    0xe81(%rip),%rdi
lea    0x4(%rsp),%rsi
call   1050 <scanf@plt>
cmpl   $0x0,0x4(%rsp)
jle    122a <main+0xea>
xor    %r13d,%r13d
lea    0xe62(%rip),%rbx
lea    0x10(%rsp),%r12
mov    %r14,0x8(%rsp)
jmp    11e1 <main+0xa1>
nopw   0x0(%rax,%rax,1)
mov    %ebp,%esi
shr    $0x1f,%esi
add    %ebp,%esi
sar    %esi
mov    %r12,%rdi
mov    %r14,%rcx
call   1060 <knapsack@plt>
add    %eax,%eax
sub    %eax,%ebp
lea    0xe35(%rip),%rdi
mov    %ebp,%esi
call   1030 <printf@plt>
add    $0x1,%r13d
cmp    0x4(%rsp),%r13d
jge    122a <main+0xea>
mov    %rbx,%rdi
mov    %rsp,%rsi
call   1050 <scanf@plt>
mov    (%rsp),%edx
mov    $0x0,%ebp
test   %edx,%edx
jle    11b0 <main+0x70>
xor    %r15d,%r15d
mov    %r12,%r14
xor    %ebp,%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1050 <scanf@plt>
add    (%r12),%ebp
add    $0x1,%r15
movslq (%rsp),%rdx
add    $0x4,%r12
cmp    %rdx,%r15
jl     1200 <main+0xc0>
mov    %r14,%r12
mov    0x8(%rsp),%r14
jmp    11b0 <main+0x70>
xor    %eax,%eax
add    $0x1a8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [4 x i8] c" %d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca i32
%5 = alloca i32
%6 = alloca [100 x i32]
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32**
store i32 0, i32* %1
%11 = call i64 @malloc(i32 808)
%12 = inttoptr i64 %11 to i32**
store i32** %12, i32*** %10
store i32 0, i32* %3
br label %13
13: ; preds = %23, %0
%14 = load i32, i32* %3
%15 = icmp slt i32 %14, 101
br i1 %15, label %16, label %26
16: ; preds = %13
%17 = call i64 @malloc(i32 20000000)
%18 = inttoptr i64 %17 to i32*
%19 = load i32**, i32*** %10
%20 = load i32, i32* %3
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i32*, i32** %19, i64 %21
store i32* %18, i32** %22
br label %23
23: ; preds = %16
%24 = load i32, i32* %3
%25 = add nsw i32 %24, 1
store i32 %25, i32* %3
br label %13
26: ; preds = %13
%27 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %4)
store i32 0, i32* %2
br label %28
28: ; preds = %67, %26
%29 = load i32, i32* %2
%30 = load i32, i32* %4
%31 = icmp slt i32 %29, %30
br i1 %31, label %32, label %70
32: ; preds = %28
%33 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %5)
store i32 0, i32* %7
store i32 0, i32* %3
br label %34
34: ; preds = %49, %32
%35 = load i32, i32* %3
%36 = load i32, i32* %5
%37 = icmp slt i32 %35, %36
br i1 %37, label %38, label %52
38: ; preds = %34
%39 = load i32, i32* %3
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds [100 x i32], [100 x i32]* %6, i64 0, i64 %40
%42 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %41)
%43 = load i32, i32* %3
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds [100 x i32], [100 x i32]* %6, i64 0, i64 %44
%46 = load i32, i32* %45
%47 = load i32, i32* %7
%48 = add nsw i32 %47, %46
store i32 %48, i32* %7
br label %49
49: ; preds = %38
%50 = load i32, i32* %3
%51 = add nsw i32 %50, 1
store i32 %51, i32* %3
br label %34
52: ; preds = %34
%53 = load i32, i32* %7
%54 = and i32 %53, 1
store i32 %54, i32* %8
%55 = getelementptr inbounds [100 x i32], [100 x i32]* %6, i64 0, i64 0
%56 = load i32, i32* %7
%57 = sdiv i32 %56, 2
%58 = load i32, i32* %5
%59 = load i32**, i32*** %10
%60 = call i32 @knapsack(i32* %55, i32 %57, i32 %58, i32** %59)
store i32 %60, i32* %9
%61 = load i32, i32* %7
%62 = load i32, i32* %9
%63 = mul nsw i32 %62, 2
%64 = sub nsw i32 %61, %63
store i32 %64, i32* %7
%65 = load i32, i32* %7
%66 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %65)
br label %67
67: ; preds = %52
%68 = load i32, i32* %2
%69 = add nsw i32 %68, 1
store i32 %69, i32* %2
br label %28
70: ; preds = %28
ret i32 0
}

LLVM IR (-O2):
@.str = [4 x i8] c" %d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [100 x i32]
%4 = bitcast i32* %1 to i8*
%5 = bitcast i32* %2 to i8*
%6 = bitcast [100 x i32]* %3 to i8*
%7 = tail call i64 @malloc(i32 808)
%8 = inttoptr i64 %7 to i32**
br label %9
9: ; preds = %0, %9
%10 = phi i64 [ 0, %0 ], [ %14, %9 ]
%11 = tail call i64 @malloc(i32 20000000)
%12 = inttoptr i64 %11 to i32*
%13 = getelementptr inbounds i32*, i32** %8, i64 %10
store i32* %12, i32** %13
%14 = add nuw nsw i64 %10, 1
%15 = icmp eq i64 %14, 101
br i1 %15, label %16, label %9
16: ; preds = %9
%17 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %1)
%18 = load i32, i32* %1
%19 = icmp sgt i32 %18, 0
br i1 %19, label %20, label %49
20: ; preds = %16
%21 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 0
br label %22
22: ; preds = %20, %38
%23 = phi i32 [ 0, %20 ], [ %46, %38 ]
%24 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %2)
%25 = load i32, i32* %2
%26 = icmp sgt i32 %25, 0
br i1 %26, label %27, label %38
27: ; preds = %22, %27
%28 = phi i64 [ %34, %27 ], [ 0, %22 ]
%29 = phi i32 [ %33, %27 ], [ 0, %22 ]
%30 = getelementptr inbounds [100 x i32], [100 x i32]* %3, i64 0, i64 %28
%31 = call i32 @scanf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32* %30)
%32 = load i32, i32* %30
%33 = add nsw i32 %32, %29
%34 = add nuw nsw i64 %28, 1
%35 = load i32, i32* %2
%36 = sext i32 %35 to i64
%37 = icmp slt i64 %34, %36
br i1 %37, label %27, label %38
38: ; preds = %27, %22
%39 = phi i32 [ 0, %22 ], [ %33, %27 ]
%40 = phi i32 [ %25, %22 ], [ %35, %27 ]
%41 = sdiv i32 %39, 2
%42 = call i32 @knapsack(i32* %21, i32 %41, i32 %40, i32** %8)
%43 = mul i32 %42, -2
%44 = add i32 %43, %39
%45 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %44)
%46 = add nuw nsw i32 %23, 1
%47 = load i32, i32* %1
%48 = icmp slt i32 %46, %47
br i1 %48, label %22, label %49
49: ; preds = %38, %16
ret i32 0
}