#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 /*<<< orphan*/ construct_groups(int *);
int *malloc(int);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ scanf(char *, int *);
int solve(int, int *);
int main() {
  int *group = malloc(sizeof(int) * 32000);
  construct_groups(group);
  int case_num, index;
  scanf("%d", &case_num);
  while (case_num-- > 0) {
    scanf("%d", &index);
    printf("%d\n", solve(index, group));
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    $0x1f400,%edi
call   1060 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <construct_groups@plt>
lea    0xe83(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x14(%rbp),%eax
mov    %eax,%ecx
add    $0xffffffff,%ecx
mov    %ecx,-0x14(%rbp)
cmp    $0x0,%eax
jle    11c9 <main+0x79>
lea    0xe5f(%rip),%rdi
lea    -0x18(%rbp),%rsi
call   1070 <scanf@plt>
mov    -0x18(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1030 <solve@plt>
mov    %eax,%esi
lea    0xe44(%rip),%rdi
call   1040 <printf@plt>
jmp    1186 <main+0x36>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    $0x1f400,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <construct_groups@plt>
lea    0xe8c(%rip),%rdi
mov    %rsp,%rsi
call   1070 <scanf@plt>
mov    (%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,(%rsp)
test   %eax,%eax
jle    11ce <main+0x7e>
lea    0xe70(%rip),%r14
lea    0x4(%rsp),%r15
lea    0xe67(%rip),%r12
nopl   0x0(%rax)
mov    %r14,%rdi
mov    %r15,%rsi
call   1070 <scanf@plt>
mov    0x4(%rsp),%edi
mov    %rbx,%rsi
call   1030 <solve@plt>
mov    %r12,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
mov    (%rsp),%eax
lea    -0x1(%rax),%ecx
mov    %ecx,(%rsp)
test   %eax,%eax
jg     11a0 <main+0x50>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 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
store i32 0, i32* %1
%5 = call i32* @malloc(i32 128000)
store i32* %5, i32** %2
%6 = load i32*, i32** %2
%7 = call i32 @construct_groups(i32* %6)
%8 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
br label %9
9: ; preds = %13, %0
%10 = load i32, i32* %3
%11 = add nsw i32 %10, -1
store i32 %11, i32* %3
%12 = icmp sgt i32 %10, 0
br i1 %12, label %13, label %19
13: ; preds = %9
%14 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%15 = load i32, i32* %4
%16 = load i32*, i32** %2
%17 = call i32 @solve(i32 %15, i32* %16)
%18 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %17)
br label %9
19: ; preds = %9
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.1 = [4 x i8] c"%d\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = tail call i32* @malloc(i32 128000)
%4 = tail call i32 @construct_groups(i32* %3)
%5 = bitcast i32* %1 to i8*
%6 = bitcast i32* %2 to i8*
%7 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %1)
%8 = load i32, i32* %1
%9 = add nsw i32 %8, -1
store i32 %9, i32* %1
%10 = icmp sgt i32 %8, 0
br i1 %10, label %11, label %19
11: ; preds = %0, %11
%12 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %2)
%13 = load i32, i32* %2
%14 = call i32 @solve(i32 %13, i32* %3)
%15 = call i32 @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %14)
%16 = load i32, i32* %1
%17 = add nsw i32 %16, -1
store i32 %17, i32* %1
%18 = icmp sgt i32 %16, 0
br i1 %18, label %11, label %19
19: ; preds = %11, %0
ret i32 0
}