// File: /workspace/github_cpp_makefile_star2_O3/kmyk[P]procon26/main.cpp
// Function: main
int main(int argc, char **argv) {
    ios_base::sync_with_stdio(false);
    input_t a; cin >> a;
    int n = a.blocks.size();
    board brd = board(a.board);
    vector<block> blks(n); repeat (i,n) blks[i] = block(a.blocks[i]);
    assert (argc == 3 or argc == 4);
    int BEAM_WIDTH = atoi(argv[1]);
    double BEAM_SEARCH_TIME = atof(argv[2]);
    bool IS_CHOKUDAI = 3 < argc ? atoi(argv[3]) : false;
    if (BEAM_SEARCH_TIME > 0.01) { // 幅の自動調整
        clock_t start = clock();
        beam_search(brd, blks, BEAM_WIDTH, false);
        clock_t clock_per_width = (clock() - start) / BEAM_WIDTH;
        double sec_per_width = clock_per_width /(double) CLOCKS_PER_SEC;
        BEAM_WIDTH = min<int>(16384, (BEAM_SEARCH_TIME * 60 / sec_per_width - BEAM_WIDTH) * 0.95);
        cerr << "measured: " << sec_per_width << " sec/width" << endl;
    }
    cerr << "start with width: " <<  BEAM_WIDTH << endl;
    signal(SIGINT, &signal_handler);
    output_t b = { beam_search(brd, blks, BEAM_WIDTH, IS_CHOKUDAI) };
    signal(SIGINT, SIG_DFL);
    cerr << "*** done ***" << endl;
    cout << b;
    cerr << "***" << endl;
    export_to_file(b);
    cerr << g_best_score << " " << g_best_stone << endl;
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2948, %rsp           # imm = 0x2948
movq %rsi, %rbx
movl %edi, %r14d
xorl %edi, %edi
callq 0x2090
xorpd %xmm0, %xmm0
leaq 0x480(%rsp), %rsi
movupd %xmm0, 0x400(%rsi)
movq $0x0, 0x410(%rsi)
movq 0x6122(%rip), %rdi      # 0xffd8
callq 0x9818
leaq 0x480(%rsp), %rsi
movq 0x408(%rsi), %r15
subq 0x400(%rsi), %r15
leaq 0x898(%rsp), %rdi
callq 0x7536
movq %r14, 0x18(%rsp)
movq %rbx, 0x10(%rsp)
shrq $0x6, %r15
movslq %r15d, %rsi
leaq 0x38(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0xa434
testl %r15d, %r15d
jle 0xa069
andl $0x7fffffff, %r15d      # imm = 0x7FFFFFFF
movl $0x290, %ebx            # imm = 0x290
movl $0x350, %ebp            # imm = 0x350
xorl %r14d, %r14d
leaq 0x68(%rsp), %r12
movq %r15, 0x20(%rsp)
movq %rbp, 0x8(%rsp)
movq %r14, %rsi
shlq $0x6, %rsi
addq 0x880(%rsp), %rsi
movq %r12, %rdi
callq 0x8004
movq 0x38(%rsp), %r15
imulq $0x418, %r14, %rdi      # imm = 0x418
addq %r15, %rdi
movl $0x290, %edx            # imm = 0x290
movq %rdi, 0x28(%rsp)
movq %r12, %rsi
callq 0x2140
movq %rbx, 0x30(%rsp)
leaq (%r15,%rbx), %r13
leaq 0x2f8(%rsp), %rbx
xorl %ebp, %ebp
xorl %r12d, %r12d
leaq (%r12,%r13), %rdi
leaq (%rbx,%r12), %rsi
callq 0xa4c8
addq $0x18, %r12
cmpq $0x60, %r12
jne 0x9f78
incq %rbp
addq $0x60, %rbx
addq $0x60, %r13
cmpq $0x2, %rbp
jne 0x9f75
movq 0x8(%rsp), %rbp
addq %rbp, %r15
leaq 0x3b8(%rsp), %r13
xorl %ebx, %ebx
xorl %r12d, %r12d
leaq (%r15,%r12), %rdi
leaq (%r12,%r13), %rsi
callq 0xa500
addq $0x18, %r12
cmpq $0x60, %r12
jne 0x9fb5
incq %rbx
addq $0x60, %r13
addq $0x60, %r15
cmpq $0x2, %rbx
jne 0x9fb2
movq 0x478(%rsp), %rax
movq 0x28(%rsp), %rcx
movq %rax, 0x410(%rcx)
movl $0x408, %ebx            # imm = 0x408
movq 0x20(%rsp), %r15
movq 0x58(%rsp,%rbx), %rdi
testq %rdi, %rdi
je 0xa012
movq 0x68(%rsp,%rbx), %rsi
subq %rdi, %rsi
callq 0x2190
addq $-0x18, %rbx
cmpq $0x348, %rbx            # imm = 0x348
jne 0x9ffb
movl $0x348, %ebx            # imm = 0x348
leaq 0x68(%rsp), %r12
movq 0x58(%rsp,%rbx), %rdi
testq %rdi, %rdi
je 0xa040
movq 0x68(%rsp,%rbx), %rsi
subq %rdi, %rsi
callq 0x2190
addq $-0x18, %rbx
cmpq $0x288, %rbx            # imm = 0x288
jne 0xa029
incq %r14
movq 0x30(%rsp), %rbx
movl $0x418, %eax            # imm = 0x418
addq %rax, %rbx
addq %rax, %rbp
cmpq %r15, %r14
jne 0x9f25
movq 0x18(%rsp), %r14
leal -0x3(%r14), %eax
cmpl $0x2, %eax
jae 0xa39e
movq 0x10(%rsp), %rbx
movq 0x8(%rbx), %rdi
callq 0x2250
movl %eax, %ebp
movq 0x10(%rbx), %rdi
callq 0x21f0
cmpl $0x4, %r14d
movsd %xmm0, 0x8(%rsp)
jb 0xa0b7
movq 0x18(%rbx), %rdi
callq 0x2250
movsd 0x8(%rsp), %xmm0
testl %eax, %eax
setne %r14b
jmp 0xa0ba
xorl %r14d, %r14d
ucomisd 0x134e(%rip), %xmm0     # 0xb410
jbe 0xa1c4
callq 0x20f0
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
leaq 0x898(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x25f4
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0xa103
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
callq 0x20f0
subq %rbx, %rax
movslq %ebp, %rcx
cqto
idivq %rcx
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x12f5(%rip), %xmm0     # 0xb418
movsd 0x8(%rsp), %xmm1
mulsd 0x12ef(%rip), %xmm1     # 0xb420
movsd %xmm0, 0x8(%rsp)
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
subsd %xmm0, %xmm1
mulsd 0x12da(%rip), %xmm1     # 0xb428
cvttsd2si %xmm1, %eax
movl $0x4000, %ebp           # imm = 0x4000
cmpl %ebp, %eax
cmovll %eax, %ebp
movq 0x5e8d(%rip), %rdi      # 0xfff0
leaq 0x1315(%rip), %rsi      # 0xb47f
movl $0xa, %edx
callq 0x21b0
movq 0x5e75(%rip), %rdi      # 0xfff0
movsd 0x8(%rsp), %xmm0
callq 0x2260
movq %rax, %rbx
leaq 0x12fa(%rip), %rsi      # 0xb48a
movl $0xa, %edx
movq %rax, %rdi
callq 0x21b0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq 0x5e25(%rip), %rdi      # 0xfff0
leaq 0x12c3(%rip), %rsi      # 0xb495
movl $0x12, %edx
callq 0x21b0
movq 0x5e0d(%rip), %rdi      # 0xfff0
movl %ebp, %esi
callq 0x2290
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
leaq -0x44a(%rip), %rsi      # 0x9dd1
movl $0x2, %edi
callq 0x21d0
movzbl %r14b, %r8d
leaq 0x68(%rsp), %rdi
leaq 0x898(%rsp), %rsi
leaq 0x38(%rsp), %rdx
movl %ebp, %ecx
callq 0x25f4
movl $0x2, %edi
xorl %esi, %esi
callq 0x21d0
movq 0x5d9b(%rip), %rbx      # 0xfff0
leaq 0x124c(%rip), %rsi      # 0xb4a8
movl $0xc, %edx
movq %rbx, %rdi
callq 0x21b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x5d69(%rip), %rdi      # 0xfff0
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq 0x5d2d(%rip), %rdi      # 0xffc8
leaq 0x68(%rsp), %rsi
callq 0x9a47
movq 0x5d44(%rip), %rbx      # 0xfff0
leaq 0x11fe(%rip), %rsi      # 0xb4b1
movl $0x3, %edx
movq %rbx, %rdi
callq 0x21b0
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq 0x5d12(%rip), %rdi      # 0xfff0
callq 0x2030
movq %rax, %rdi
callq 0x2110
movl 0x5e7f(%rip), %esi      # 0x10170
movq 0x5cf8(%rip), %rdi      # 0xfff0
callq 0x2290
movq %rax, %rbx
leaq 0x1082(%rip), %rsi      # 0xb389
movl $0x1, %edx
movq %rax, %rdi
callq 0x21b0
movl 0x5e5a(%rip), %esi      # 0x10174
movq %rbx, %rdi
callq 0x2290
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0xa363
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x38(%rsp), %rdi
callq 0x4570
movq 0x880(%rsp), %rdi
testq %rdi, %rdi
je 0xa38a
movq 0x890(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
xorl %eax, %eax
addq $0x2948, %rsp           # imm = 0x2948
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10a3(%rip), %rdi      # 0xb448
leaq 0x10b3(%rip), %rsi      # 0xb45f
leaq 0x10b5(%rip), %rcx      # 0xb468
movl $0x2f, %edx
callq 0x20e0
jmp 0xa3ea
jmp 0xa3ea
jmp 0xa3c5
jmp 0xa3c5
movq %rax, %rbx
jmp 0xa3f7
jmp 0xa3ea
jmp 0xa3ea
movq %rax, %rbx
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0xa3ed
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0xa3ed
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x4570
movq 0x880(%rsp), %rdi
testq %rdi, %rdi
je 0xa414
movq 0x890(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq %rbx, %rdi
callq 0x22a0