#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*/ printf(char *, ...);
int /*<<< orphan*/ scanf(char *, int *);
int solve2(int *, int);
int main(int argc, char **argv) {
  int num_tests, test = 0;
  int n, i, good;
  int seq[1000];
  int ret = 1;
  int total_good, total_bad;
  scanf("%d", &num_tests);
  if (num_tests < 1 || num_tests > 120) {
    printf("Illegal number of tests (1 <= T <= 120)\n");
    goto out;
  }
  total_good = total_bad = 0;
  while (test++ < num_tests) {
    scanf("%d", &n);
    if (n < 1 || n > 1000) {
      printf("Illegal sequence size (1 <= N <= 1000)\n");
      continue;
    }
    for (i = 0; i < n; i++)
      scanf("%d", &seq[i]);
    good = solve2(seq, n);
    if (good) {
      printf("GOOD\n");
      total_good++;
    } else {
      printf("BAD\n");
      total_bad++;
    }
  }
  printf("GOOD: %d\n", total_good);
  printf("BAD: %d\n", total_bad);
  ret = 0;
out:
  return ret;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xfe0,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0xfd4(%rbp)
lea    0xe9f(%rip),%rdi
lea    -0x14(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x1,-0x14(%rbp)
jl     117e <main+0x4e>
cmpl   $0x78,-0x14(%rbp)
jle    1191 <main+0x61>
lea    0xe7e(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    12c4 <main+0x194>
movl   $0x0,-0xfdc(%rbp)
movl   $0x0,-0xfd8(%rbp)
mov    -0x18(%rbp),%eax
mov    %eax,%ecx
add    $0x1,%ecx
mov    %ecx,-0x18(%rbp)
cmp    -0x14(%rbp),%eax
jge    1292 <main+0x162>
lea    0xe40(%rip),%rdi
lea    -0x1c(%rbp),%rsi
call   1040 <scanf@plt>
cmpl   $0x1,-0x1c(%rbp)
jl     11e0 <main+0xb0>
cmpl   $0x3e8,-0x1c(%rbp)
jle    11f3 <main+0xc3>
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
jmp    11a5 <main+0x75>
movl   $0x0,-0x20(%rbp)
mov    -0x20(%rbp),%eax
cmp    -0x1c(%rbp),%eax
jge    1232 <main+0x102>
movslq -0x20(%rbp),%rax
lea    -0xfd0(%rbp),%rsi
shl    $0x2,%rax
add    %rax,%rsi
lea    0xde1(%rip),%rdi
call   1040 <scanf@plt>
mov    -0x20(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x20(%rbp)
jmp    11fa <main+0xca>
lea    -0xfd0(%rbp),%rdi
mov    -0x1c(%rbp),%esi
call   1050 <solve2@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
je     1270 <main+0x140>
lea    0xdff(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xfd8(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfd8(%rbp)
jmp    128d <main+0x15d>
lea    0xde3(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xfdc(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0xfdc(%rbp)
jmp    11a5 <main+0x75>
mov    -0xfd8(%rbp),%esi
lea    0xdc0(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    -0xfdc(%rbp),%esi
lea    0xdb6(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
movl   $0x0,-0xfd4(%rbp)
mov    -0xfd4(%rbp),%eax
add    $0xfe0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0xfc8,%rsp
lea    0xea8(%rip),%rdi
lea    0xc(%rsp),%rsi
call   1050 <scanf@plt>
mov    0xc(%rsp),%eax
add    $0xffffff87,%eax
cmp    $0xffffff88,%eax
jae    1184 <main+0x44>
lea    0xed1(%rip),%rdi
call   1030 <puts@plt>
mov    $0x1,%ebx
jmp    1298 <main+0x158>
xor    %r12d,%r12d
mov    $0x1,%eax
lea    0xe6d(%rip),%rbx
lea    0x14(%rsp),%rbp
mov    $0xfffffc17,%r14d
xor    %r13d,%r13d
mov    %eax,%r15d
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %rbx,%rdi
mov    %rbp,%rsi
call   1050 <scanf@plt>
mov    0x14(%rsp),%eax
add    %r14d,%eax
cmp    $0xfffffc18,%eax
jae    11e8 <main+0xa8>
lea    0xe4f(%rip),%rdi
call   1030 <puts@plt>
lea    0x1(%r15),%eax
cmp    0xc(%rsp),%r15d
mov    %eax,%r15d
jl     11b0 <main+0x70>
jmp    1274 <main+0x134>
mov    %r13d,0x10(%rsp)
mov    %r12,0x18(%rsp)
lea    0x20(%rsp),%r13
xor    %r12d,%r12d
nopw   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    %r13,%rsi
call   1050 <scanf@plt>
add    $0x1,%r12
movslq 0x14(%rsp),%rsi
add    $0x4,%r13
cmp    %rsi,%r12
jl     1200 <main+0xc0>
lea    0x20(%rsp),%rdi
call   1060 <solve2@plt>
test   %eax,%eax
je     1247 <main+0x107>
lea    0xde8(%rip),%rdi
call   1030 <puts@plt>
mov    0x10(%rsp),%r13d
add    $0x1,%r13d
mov    0x18(%rsp),%r12
jmp    1261 <main+0x121>
lea    0xdc8(%rip),%rdi
call   1030 <puts@plt>
mov    0x18(%rsp),%r12
add    $0x1,%r12d
mov    0x10(%rsp),%r13d
lea    0x1(%r15),%eax
cmp    0xc(%rsp),%r15d
jge    1274 <main+0x134>
mov    %eax,%r15d
jmp    11b0 <main+0x70>
lea    0xd88(%rip),%rdi
xor    %ebx,%ebx
mov    %r13d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xd7f(%rip),%rdi
mov    %r12d,%esi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%eax
add    $0xfc8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"%d\00"
@.str.5 = [10 x i8] c"GOOD: %d\0A\00"
@.str.6 = [9 x i8] c"BAD: %d\0A\00"
@str = [4 x i8] c"BAD\00"
@str.7 = [5 x i8] c"GOOD\00"
@str.8 = [39 x i8] c"Illegal sequence size (1 <= N <= 1000)\00"
@str.9 = [40 x i8] c"Illegal number of tests (1 <= T <= 120)\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca [1000 x i32]
%6 = bitcast i32* %3 to i8*
%7 = bitcast i32* %4 to i8*
%8 = bitcast [1000 x i32]* %5 to i8*
%9 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %3)
%10 = load i32, i32* %3
%11 = add i32 %10, -121
%12 = icmp ult i32 %11, -120
br i1 %12, label %15, label %13
13: ; preds = %2
%14 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 0
br label %51
15: ; preds = %2
%16 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([40 x i8], [40 x i8]* @str.9, i64 0, i64 0))
br label %60
17: ; preds = %51, %23
%18 = phi i32 [ %52, %51 ], [ %25, %23 ]
%19 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %4)
%20 = load i32, i32* %4
%21 = add i32 %20, -1001
%22 = icmp ult i32 %21, -1000
br i1 %22, label %23, label %28
23: ; preds = %17
%24 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([39 x i8], [39 x i8]* @str.8, i64 0, i64 0))
%25 = add nsw i32 %18, 1
%26 = load i32, i32* %3
%27 = icmp slt i32 %18, %26
br i1 %27, label %17, label %55
28: ; preds = %17, %28
%29 = phi i64 [ %32, %28 ], [ 0, %17 ]
%30 = getelementptr inbounds [1000 x i32], [1000 x i32]* %5, i64 0, i64 %29
%31 = call i32 @scanf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i32* %30)
%32 = add nuw nsw i64 %29, 1
%33 = load i32, i32* %4
%34 = sext i32 %33 to i64
%35 = icmp slt i64 %32, %34
br i1 %35, label %28, label %36
36: ; preds = %28
%37 = call i32 @solve2(i32* %14, i32 %33)
%38 = icmp eq i32 %37, 0
br i1 %38, label %42, label %39
39: ; preds = %36
%40 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @str.7, i64 0, i64 0))
%41 = add nsw i32 %54, 1
br label %45
42: ; preds = %36
%43 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @str, i64 0, i64 0))
%44 = add nsw i32 %53, 1
br label %45
45: ; preds = %42, %39
%46 = phi i32 [ %41, %39 ], [ %54, %42 ]
%47 = phi i32 [ %53, %39 ], [ %44, %42 ]
%48 = add nsw i32 %18, 1
%49 = load i32, i32* %3
%50 = icmp slt i32 %18, %49
br i1 %50, label %51, label %55
51: ; preds = %13, %45
%52 = phi i32 [ 1, %13 ], [ %48, %45 ]
%53 = phi i32 [ 0, %13 ], [ %47, %45 ]
%54 = phi i32 [ 0, %13 ], [ %46, %45 ]
br label %17
55: ; preds = %45, %23
%56 = phi i32 [ %54, %23 ], [ %46, %45 ]
%57 = phi i32 [ %53, %23 ], [ %47, %45 ]
%58 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.5, i64 0, i64 0), i32 %56)
%59 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([9 x i8], [9 x i8]* @.str.6, i64 0, i64 0), i32 %57)
br label %60
60: ; preds = %55, %15
%61 = phi i32 [ 1, %15 ], [ 0, %55 ]
ret i32 %61
}