// File: 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
movq %rsp, %rbp
subq $0x2a00, %rsp           # imm = 0x2A00
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
xorl %edi, %edi
callq 0x2090
leaq -0x428(%rbp), %rdi
movq %rdi, -0x2990(%rbp)
callq 0x20010
movq -0x2990(%rbp), %rsi
movq 0x12557(%rip), %rdi     # 0x31fd8
callq 0x1e800
jmp 0x1fa88
leaq -0x28(%rbp), %rdi
callq 0x1ef30
movl %eax, -0x438(%rbp)
leaq -0x24e8(%rbp), %rdi
leaq -0x428(%rbp), %rsi
callq 0x17280
jmp 0x1faac
movslq -0x438(%rbp), %rax
movq %rax, -0x29a0(%rbp)
leaq -0x2501(%rbp), %rdi
movq %rdi, -0x2998(%rbp)
callq 0x5830
movq -0x29a0(%rbp), %rsi
movq -0x2998(%rbp), %rdx
leaq -0x2500(%rbp), %rdi
callq 0x20040
jmp 0x1fae9
leaq -0x2501(%rbp), %rdi
callq 0x7430
movl $0x0, -0x2508(%rbp)
movl -0x2508(%rbp), %eax
cmpl -0x438(%rbp), %eax
jge 0x1fbc2
leaq -0x28(%rbp), %rdi
movslq -0x2508(%rbp), %rsi
callq 0x1ee90
movq %rax, %rsi
leaq -0x2920(%rbp), %rdi
callq 0x18570
jmp 0x1fb32
movslq -0x2508(%rbp), %rsi
leaq -0x2500(%rbp), %rdi
callq 0x200b0
movq %rax, %rdi
leaq -0x2920(%rbp), %rsi
callq 0x200d0
leaq -0x2920(%rbp), %rdi
callq 0x70f0
movl -0x2508(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2508(%rbp)
jmp 0x1faff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x430(%rbp)
movl %eax, -0x434(%rbp)
jmp 0x1ffcc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x430(%rbp)
movl %eax, -0x434(%rbp)
leaq -0x2501(%rbp), %rdi
callq 0x7430
jmp 0x1ffcc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x430(%rbp)
movl %eax, -0x434(%rbp)
jmp 0x1ffc0
movb $0x1, %al
cmpl $0x3, -0x8(%rbp)
movb %al, -0x29a1(%rbp)
je 0x1fbdd
cmpl $0x4, -0x8(%rbp)
sete %al
movb %al, -0x29a1(%rbp)
movb -0x29a1(%rbp), %al
testb $0x1, %al
jne 0x1fbe9
jmp 0x1fbeb
jmp 0x1fc0a
leaq 0x1816(%rip), %rdi      # 0x21408
leaq 0x1826(%rip), %rsi      # 0x2141f
movl $0x2f, %edx
leaq 0x1823(%rip), %rcx      # 0x21428
callq 0x20d0
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x2220
movl %eax, -0x2924(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rdi
callq 0x21c0
movsd %xmm0, -0x2930(%rbp)
movl $0x3, %eax
cmpl -0x8(%rbp), %eax
jge 0x1fc51
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rdi
callq 0x2220
movl %eax, -0x29a8(%rbp)
jmp 0x1fc5b
xorl %eax, %eax
movl %eax, -0x29a8(%rbp)
jmp 0x1fc5b
movl -0x29a8(%rbp), %eax
cmpl $0x0, %eax
setne %al
andb $0x1, %al
movb %al, -0x2931(%rbp)
movsd -0x2930(%rbp), %xmm0
movsd 0x1751(%rip), %xmm1     # 0x213d0
ucomisd %xmm1, %xmm0
jbe 0x1fde8
callq 0x20e0
movq %rax, -0x2940(%rbp)
movl -0x2924(%rbp), %ecx
leaq -0x2958(%rbp), %rdi
leaq -0x24e8(%rbp), %rsi
leaq -0x2500(%rbp), %rdx
xorl %r8d, %r8d
callq 0x2560
jmp 0x1fcba
leaq -0x2958(%rbp), %rdi
callq 0x5210
callq 0x20e0
movq -0x2940(%rbp), %rcx
subq %rcx, %rax
movslq -0x2924(%rbp), %rcx
cqto
idivq %rcx
movq %rax, -0x2960(%rbp)
cvtsi2sdq -0x2960(%rbp), %xmm0
movsd 0x16df(%rip), %xmm1     # 0x213d8
divsd %xmm1, %xmm0
movsd %xmm0, -0x2968(%rbp)
movl $0x4000, -0x296c(%rbp)  # imm = 0x4000
movsd -0x2930(%rbp), %xmm0
movsd 0x16c1(%rip), %xmm1     # 0x213e0
mulsd %xmm1, %xmm0
movsd -0x2968(%rbp), %xmm1
divsd %xmm1, %xmm0
cvtsi2sdl -0x2924(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd 0x16a5(%rip), %xmm1     # 0x213e8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, -0x2970(%rbp)
leaq -0x296c(%rbp), %rdi
leaq -0x2970(%rbp), %rsi
callq 0x8440
movq %rax, -0x29b0(%rbp)
jmp 0x1fd6d
movq -0x29b0(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x2924(%rbp)
movq 0x1226d(%rip), %rdi     # 0x31ff0
leaq 0x16b5(%rip), %rsi      # 0x2143f
callq 0x2130
movq %rax, -0x29b8(%rbp)
jmp 0x1fd98
movq -0x29b8(%rbp), %rdi
movsd -0x2968(%rbp), %xmm0
callq 0x2270
movq %rax, -0x29c0(%rbp)
jmp 0x1fdb5
movq -0x29c0(%rbp), %rdi
leaq 0x1687(%rip), %rsi      # 0x2144a
callq 0x2130
movq %rax, -0x29c8(%rbp)
jmp 0x1fdd1
movq -0x29c8(%rbp), %rdi
movq 0x121d1(%rip), %rsi     # 0x31fb0
callq 0x2170
jmp 0x1fde6
jmp 0x1fde8
movq 0x12201(%rip), %rdi     # 0x31ff0
leaq 0x165f(%rip), %rsi      # 0x21455
callq 0x2130
movq %rax, -0x29d0(%rbp)
jmp 0x1fe04
movq -0x29d0(%rbp), %rdi
movl -0x2924(%rbp), %esi
callq 0x2250
movq %rax, -0x29d8(%rbp)
jmp 0x1fe1f
movq -0x29d8(%rbp), %rdi
movq 0x12183(%rip), %rsi     # 0x31fb0
callq 0x2170
jmp 0x1fe34
leaq -0x4cb(%rip), %rsi      # 0x1f970
movl $0x2, %edi
callq 0x21a0
movl -0x2924(%rbp), %ecx
movzbl -0x2931(%rbp), %r8d
andl $0x1, %r8d
leaq -0x2988(%rbp), %rdi
leaq -0x24e8(%rbp), %rsi
leaq -0x2500(%rbp), %rdx
callq 0x2560
jmp 0x1fe73
xorl %eax, %eax
movl %eax, %esi
movl $0x2, %edi
callq 0x21a0
movq 0x12168(%rip), %rdi     # 0x31ff0
leaq 0x15d9(%rip), %rsi      # 0x21468
callq 0x2130
movq %rax, -0x29e0(%rbp)
jmp 0x1fe9d
movq -0x29e0(%rbp), %rdi
movq 0x12105(%rip), %rsi     # 0x31fb0
callq 0x2170
jmp 0x1feb2
movq 0x1210f(%rip), %rdi     # 0x31fc8
leaq -0x2988(%rbp), %rsi
callq 0x1eb30
jmp 0x1fec7
movq 0x12122(%rip), %rdi     # 0x31ff0
leaq 0x159c(%rip), %rsi      # 0x21471
callq 0x2130
movq %rax, -0x29e8(%rbp)
jmp 0x1fee3
movq -0x29e8(%rbp), %rdi
movq 0x120bf(%rip), %rsi     # 0x31fb0
callq 0x2170
jmp 0x1fef8
leaq -0x2988(%rbp), %rdi
callq 0x1f960
movl 0x1224e(%rip), %esi     # 0x32158
movq 0x120df(%rip), %rdi     # 0x31ff0
callq 0x2250
movq %rax, -0x29f0(%rbp)
jmp 0x1ff1f
movq -0x29f0(%rbp), %rdi
leaq 0x141c(%rip), %rsi      # 0x21349
callq 0x2130
movq %rax, -0x29f8(%rbp)
jmp 0x1ff3b
movq -0x29f8(%rbp), %rdi
movl 0x12214(%rip), %esi     # 0x3215c
callq 0x2250
movq %rax, -0x2a00(%rbp)
jmp 0x1ff56
movq -0x2a00(%rbp), %rdi
movq 0x1204c(%rip), %rsi     # 0x31fb0
callq 0x2170
jmp 0x1ff6b
movl $0x0, -0x4(%rbp)
leaq -0x2988(%rbp), %rdi
callq 0x8af0
leaq -0x2500(%rbp), %rdi
callq 0x5780
leaq -0x428(%rbp), %rdi
callq 0x20200
movl -0x4(%rbp), %eax
addq $0x2a00, %rsp           # imm = 0x2A00
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x430(%rbp)
movl %eax, -0x434(%rbp)
leaq -0x2988(%rbp), %rdi
callq 0x8af0
leaq -0x2500(%rbp), %rdi
callq 0x5780
leaq -0x428(%rbp), %rdi
callq 0x20200
movq -0x430(%rbp), %rdi
callq 0x2260
nopw %cs:(%rax,%rax)
nop