// File: /workspace/github_cpp_makefile_star2_O1/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 0x5d3a(%rip), %rdi      # 0xffd8
callq 0x9c14
leaq 0x480(%rsp), %rsi
movq 0x408(%rsi), %r15
subq 0x400(%rsi), %r15
leaq 0x898(%rsp), %rdi
callq 0x7736
movq %r14, 0x18(%rsp)
movq %rbx, 0x10(%rsp)
shrq $0x6, %r15
movslq %r15d, %rsi
leaq 0x38(%rsp), %rdi
leaq 0x68(%rsp), %rdx
callq 0xa81c
testl %r15d, %r15d
jle 0xa451
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 0x8346
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 0x9a0e
addq $0x18, %r12
cmpq $0x60, %r12
jne 0xa360
incq %rbp
addq $0x60, %rbx
addq $0x60, %r13
cmpq $0x2, %rbp
jne 0xa35d
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 0xa8b0
addq $0x18, %r12
cmpq $0x60, %r12
jne 0xa39d
incq %rbx
addq $0x60, %r13
addq $0x60, %r15
cmpq $0x2, %rbx
jne 0xa39a
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 0xa3fa
movq 0x68(%rsp,%rbx), %rsi
subq %rdi, %rsi
callq 0x2190
addq $-0x18, %rbx
cmpq $0x348, %rbx            # imm = 0x348
jne 0xa3e3
movl $0x348, %ebx            # imm = 0x348
leaq 0x68(%rsp), %r12
movq 0x58(%rsp,%rbx), %rdi
testq %rdi, %rdi
je 0xa428
movq 0x68(%rsp,%rbx), %rsi
subq %rdi, %rsi
callq 0x2190
addq $-0x18, %rbx
cmpq $0x288, %rbx            # imm = 0x288
jne 0xa411
incq %r14
movq 0x30(%rsp), %rbx
movl $0x418, %eax            # imm = 0x418
addq %rax, %rbx
addq %rax, %rbp
cmpq %r15, %r14
jne 0xa30d
movq 0x18(%rsp), %r14
leal -0x3(%r14), %eax
cmpl $0x2, %eax
jae 0xa786
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)
jl 0xa49f
movq 0x18(%rbx), %rdi
callq 0x2250
movsd 0x8(%rsp), %xmm0
testl %eax, %eax
setne %r14b
jmp 0xa4a2
xorl %r14d, %r14d
ucomisd 0xf56(%rip), %xmm0      # 0xb400
jbe 0xa5ac
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 0xa4eb
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 0xefd(%rip), %xmm0      # 0xb408
movsd 0x8(%rsp), %xmm1
mulsd 0xef7(%rip), %xmm1      # 0xb410
movsd %xmm0, 0x8(%rsp)
divsd %xmm0, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
subsd %xmm0, %xmm1
mulsd 0xee2(%rip), %xmm1      # 0xb418
cvttsd2si %xmm1, %eax
movl $0x4000, %ebp           # imm = 0x4000
cmpl %ebp, %eax
cmovll %eax, %ebp
movq 0x5aa5(%rip), %rdi      # 0xfff0
leaq 0xf1d(%rip), %rsi       # 0xb46f
movl $0xa, %edx
callq 0x21b0
movq 0x5a8d(%rip), %rdi      # 0xfff0
movsd 0x8(%rsp), %xmm0
callq 0x2260
movq %rax, %rbx
leaq 0xf02(%rip), %rsi       # 0xb47a
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 0x5a3d(%rip), %rdi      # 0xfff0
leaq 0xecb(%rip), %rsi       # 0xb485
movl $0x12, %edx
callq 0x21b0
movq 0x5a25(%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      # 0xa1b9
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 0x59b3(%rip), %rbx      # 0xfff0
leaq 0xe54(%rip), %rsi       # 0xb498
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 0x5981(%rip), %rdi      # 0xfff0
callq 0x2030
movq %rax, %rdi
callq 0x2110
movq 0x5945(%rip), %rdi      # 0xffc8
leaq 0x68(%rsp), %rsi
callq 0x9e37
movq 0x595c(%rip), %rbx      # 0xfff0
leaq 0xe06(%rip), %rsi       # 0xb4a1
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 0x592a(%rip), %rdi      # 0xfff0
callq 0x2030
movq %rax, %rdi
callq 0x2110
movl 0x5a97(%rip), %esi      # 0x10170
movq 0x5910(%rip), %rdi      # 0xfff0
callq 0x2290
movq %rax, %rbx
leaq 0xc8a(%rip), %rsi       # 0xb379
movl $0x1, %edx
movq %rax, %rdi
callq 0x21b0
movl 0x5a72(%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 0xa74b
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x38(%rsp), %rdi
callq 0x459c
movq 0x880(%rsp), %rdi
testq %rdi, %rdi
je 0xa772
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 0xcab(%rip), %rdi       # 0xb438
leaq 0xcbb(%rip), %rsi       # 0xb44f
leaq 0xcbd(%rip), %rcx       # 0xb458
movl $0x2f, %edx
callq 0x20e0
jmp 0xa7d2
jmp 0xa7d2
jmp 0xa7ad
jmp 0xa7ad
movq %rax, %rbx
jmp 0xa7df
jmp 0xa7d2
jmp 0xa7d2
movq %rax, %rbx
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0xa7d5
movq 0x78(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0xa7d5
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x459c
movq 0x880(%rsp), %rdi
testq %rdi, %rdi
je 0xa7fc
movq 0x890(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq %rbx, %rdi
callq 0x22a0