// File: /workspace/github_cpp_makefile_star2_O2/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 $0x2918, %rsp           # imm = 0x2918
movq %rsi, %r14
movl %edi, %r15d
xorl %edi, %edi
callq 0x2080
leaq 0x850(%rsp), %rax
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq 0x7e7c(%rip), %rdi      # 0x11fd8
leaq 0x450(%rsp), %rsi
callq 0x9b74
leaq 0x450(%rsp), %rsi
movq 0x408(%rsi), %rbx
subq 0x400(%rsi), %rbx
leaq 0x868(%rsp), %rdi
callq 0x7590
shrq $0x6, %rbx
movslq %ebx, %rsi
leaq 0x8(%rsp), %rdi
leaq 0x38(%rsp), %rdx
callq 0xa472
xorl %r13d, %r13d
testl %ebx, %ebx
cmovlel %r13d, %ebx
imulq $0x418, %rbx, %rbp      # imm = 0x418
leaq 0x38(%rsp), %r12
xorl %ebx, %ebx
cmpq %rbx, %rbp
je 0xa1f6
movq 0x850(%rsp), %rsi
addq %r13, %rsi
movq %r12, %rdi
callq 0x7fa0
movq 0x8(%rsp), %rdi
addq %rbx, %rdi
movq %r12, %rsi
callq 0xa4c4
movq %r12, %rdi
callq 0x404c
addq $0x418, %rbx            # imm = 0x418
addq $0x40, %r13
jmp 0xa1b9
leal -0x3(%r15), %eax
cmpl $0x2, %eax
jae 0xa40d
movq 0x8(%r14), %rdi
callq 0x2220
movl %eax, %ebp
movq 0x10(%r14), %rdi
callq 0x21c0
cmpl $0x4, %r15d
movsd %xmm0, (%rsp)
jb 0xa238
movq 0x18(%r14), %rdi
callq 0x2220
movsd (%rsp), %xmm0
testl %eax, %eax
setne %r15b
jmp 0xa23b
xorl %r15d, %r15d
ucomisd 0x11bd(%rip), %xmm0     # 0xb400
jbe 0xa2ff
callq 0x20e0
movq %rax, %r14
leaq 0x20(%rsp), %rdi
leaq 0x868(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movl %ebp, %ecx
xorl %r8d, %r8d
callq 0x2490
leaq 0x20(%rsp), %rdi
callq 0x742c
callq 0x20e0
subq %r14, %rax
movslq %ebp, %rcx
cqto
idivq %rcx
cvtsi2sd %rax, %xmm0
divsd 0x1174(%rip), %xmm0     # 0xb408
movsd (%rsp), %xmm1
mulsd 0x116f(%rip), %xmm1     # 0xb410
movsd %xmm0, (%rsp)
divsd %xmm0, %xmm1
cvtsi2sd %ebp, %xmm0
subsd %xmm0, %xmm1
mulsd 0x115e(%rip), %xmm1     # 0xb418
cvttsd2si %xmm1, %eax
movl $0x4000, %ebp           # imm = 0x4000
cmpl %ebp, %eax
cmovll %eax, %ebp
movq 0x7d21(%rip), %rdi      # 0x11ff0
leaq 0x1199(%rip), %rsi      # 0xb46f
callq 0x2140
movq %rax, %rdi
movsd (%rsp), %xmm0
callq 0x2230
leaq 0x118b(%rip), %rsi      # 0xb47a
movq %rax, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x2090
movq 0x7cea(%rip), %rdi      # 0x11ff0
leaq 0x1178(%rip), %rsi      # 0xb485
callq 0x2140
movq %rax, %rdi
movl %ebp, %esi
callq 0x2260
movq %rax, %rdi
callq 0x2090
leaq -0x2aa(%rip), %rsi      # 0xa081
pushq $0x2
popq %rdi
callq 0x21a0
movzbl %r15b, %r8d
leaq 0x38(%rsp), %rdi
leaq 0x868(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movl %ebp, %ecx
callq 0x2490
pushq $0x2
popq %rdi
xorl %esi, %esi
callq 0x21a0
movq 0x7c8f(%rip), %rdi      # 0x11ff0
leaq 0x1130(%rip), %rsi      # 0xb498
callq 0x2140
movq %rax, %rdi
callq 0x2090
movq 0x7c4c(%rip), %rdi      # 0x11fc8
leaq 0x38(%rsp), %rsi
callq 0x9d14
movq 0x7c63(%rip), %rdi      # 0x11ff0
leaq 0x110d(%rip), %rsi      # 0xb4a1
callq 0x2140
movq %rax, %rdi
callq 0x2090
movl 0x7db1(%rip), %esi      # 0x12158
movq 0x7c42(%rip), %rdi      # 0x11ff0
callq 0x2260
leaq 0xfbf(%rip), %rsi       # 0xb379
movq %rax, %rdi
callq 0x2140
movl 0x7d94(%rip), %esi      # 0x1215c
movq %rax, %rdi
callq 0x2260
movq %rax, %rdi
callq 0x2090
leaq 0x38(%rsp), %rdi
callq 0x742c
leaq 0x8(%rsp), %rdi
callq 0x3cd6
leaq 0x850(%rsp), %rdi
callq 0xa5ce
xorl %eax, %eax
addq $0x2918, %rsp           # imm = 0x2918
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1024(%rip), %rdi      # 0xb438
leaq 0x1034(%rip), %rsi      # 0xb44f
leaq 0x1036(%rip), %rcx      # 0xb458
pushq $0x2f
popq %rdx
callq 0x20d0
jmp 0xa44a
jmp 0xa44a
jmp 0xa432
jmp 0xa432
movq %rax, %r14
jmp 0xa457
jmp 0xa44a
jmp 0xa44a
movq %rax, %r14
leaq 0x38(%rsp), %rdi
callq 0x742c
jmp 0xa44d
movq %rax, %r14
leaq 0x8(%rsp), %rdi
callq 0x3cd6
leaq 0x850(%rsp), %rdi
callq 0xa5ce
movq %r14, %rdi
callq 0x2270