// File: tanakh[P]icfpc2015/main.cpp
// Function: ga(problem const&, int, int, int, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&)
pair<string, int> ga(const problem &p, int seed, int tle, int mle, const string &tag)
{
  int best_score = -1;
  string best_move;

  int num_cands = 10;
  vector<vector<double>> cands;

  for (int i = 0; i < num_cands; i++) {
    vector<double> pp(NUM_FEATURES);
    for (int i = 0; i < (int)pp.size(); i++)
      pp[i] = genrand_real1() - 0.5;
    cands.push_back(pp);
  }

  for (int gen = 0; gen < 10000; gen++) {
    vector<pair<pair<int, string>, vector<double>>> ord;
    for (auto &ncand: cands) {
      auto rr = solve(p, seed, tle, mle, ncand, false);
      ord.emplace_back(make_pair(rr.second, rr.first), ncand);
    }

    int cur_best = -1, cur_best_ix = 0;
    for (int i = 0; i < num_cands; i++) {
      if (ord[i].first.first > cur_best) {
        cur_best = ord[i].first.first;
        cur_best_ix = i;
      }
    }
    cerr << "GEN: " << gen << ", score = " << cur_best << endl;

    if (best_score < cur_best) {
      best_score = ord[cur_best_ix].first.first;
      best_move = ord[cur_best_ix].first.second;

      cerr << "*BEST* " << p.id << "-" << seed << ": " << best_score << endl;
      output_solution(p.id, seed, best_score, best_move, tag);
    }

    vector<vector<double>> next_cands;

    while ((int)next_cands.size() < num_cands) {
      double x = genrand_real1();

      if (x < 0.1) {
        next_cands.push_back(select(ord));
      }
      else if (x < 0.97) {
        if (num_cands - next_cands.size() < 2) continue;

        vector<double> sa = select(ord);
        vector<double> sb = select(ord);

        for (int i = 0; i < (int)sa.size(); i++) {
          if (genrand_real1() < 0.5)
            swap(sa[i], sb[i]);
        }
        next_cands.push_back(sa);
        next_cands.push_back(sb);
      }
      else {
        vector<double> sa = select(ord);
        sa[genrand_int31()%sa.size()] = genrand_real1() - 0.5;
      }
    }

    cands = next_cands;
  }

  return make_pair(best_move, best_score);
}

// Assembly:
subq $0x288, %rsp            # imm = 0x288
movq %rdi, 0xa8(%rsp)
movq %rdi, %rax
movq %rax, 0xb0(%rsp)
movq %rdi, 0x280(%rsp)
movq %rsi, 0x278(%rsp)
movl %edx, 0x274(%rsp)
movl %ecx, 0x270(%rsp)
movl %r8d, 0x26c(%rsp)
movq %r9, 0x260(%rsp)
movl $0xffffffff, 0x25c(%rsp) # imm = 0xFFFFFFFF
leaq 0x238(%rsp), %rdi
callq 0x4500
movl $0xa, 0x234(%rsp)
leaq 0x218(%rsp), %rdi
callq 0x14790
movl $0x0, 0x214(%rsp)
movl 0x214(%rsp), %eax
cmpl 0x234(%rsp), %eax
jge 0xccbe
leaq 0x1f7(%rsp), %rdi
movq %rdi, 0xa0(%rsp)
callq 0x14440
movq 0xa0(%rsp), %rdx
leaq 0x1f8(%rsp), %rdi
movl $0xa, %esi
callq 0x14450
jmp 0xcba8
leaq 0x1f7(%rsp), %rdi
callq 0x144d0
movl $0x0, 0x1e0(%rsp)
movl 0x1e0(%rsp), %eax
movl %eax, 0x9c(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x144e0
movq %rax, %rcx
movl 0x9c(%rsp), %eax
cmpl %ecx, %eax
jge 0xcc5e
callq 0x4ee0
movsd 0x29422(%rip), %xmm1    # 0x36018
subsd %xmm1, %xmm0
movsd %xmm0, 0x90(%rsp)
movslq 0x1e0(%rsp), %rsi
leaq 0x1f8(%rsp), %rdi
callq 0x125a0
movsd 0x90(%rsp), %xmm0
movsd %xmm0, (%rax)
movl 0x1e0(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1e0(%rsp)
jmp 0xcbc0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0x1f7(%rsp), %rdi
callq 0x144d0
jmp 0xd45c
leaq 0x218(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x147a0
jmp 0xcc75
leaq 0x1f8(%rsp), %rdi
callq 0x12400
movl 0x214(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x214(%rsp)
jmp 0xcb63
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0x1f8(%rsp), %rdi
callq 0x12400
jmp 0xd45c
movl $0x0, 0x1dc(%rsp)
cmpl $0x2710, 0x1dc(%rsp) # imm = 0x2710
jge 0xd3ff
leaq 0x1c0(%rsp), %rdi
callq 0x14810
leaq 0x218(%rsp), %rax
movq %rax, 0x1b8(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x14820
movq %rax, 0x1b0(%rsp)
movq 0x1b8(%rsp), %rdi
callq 0x14850
movq %rax, 0x1a8(%rsp)
leaq 0x1b0(%rsp), %rdi
leaq 0x1a8(%rsp), %rsi
callq 0x14880
testb $0x1, %al
jne 0xcd3f
jmp 0xce5e
leaq 0x1b0(%rsp), %rdi
callq 0x148c0
movq %rax, 0x1a0(%rsp)
movq 0x278(%rsp), %rsi
movl 0x274(%rsp), %edx
movl 0x270(%rsp), %ecx
movl 0x26c(%rsp), %r8d
movq 0x1a0(%rsp), %r9
movq %rsp, %rax
movl $0x0, (%rax)
leaq 0x178(%rsp), %rdi
callq 0xad30
jmp 0xcd92
leaq 0x198(%rsp), %rsi
leaq 0x150(%rsp), %rdi
leaq 0x178(%rsp), %rdx
callq 0x14950
jmp 0xcdb1
movq 0x1a0(%rsp), %rdx
leaq 0x1c0(%rsp), %rdi
leaq 0x150(%rsp), %rsi
callq 0x148d0
jmp 0xcdd0
leaq 0x150(%rsp), %rdi
callq 0x14990
leaq 0x178(%rsp), %rdi
callq 0x14600
leaq 0x1b0(%rsp), %rdi
callq 0x149b0
jmp 0xcd21
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0xd3f0
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0xce4c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0x150(%rsp), %rdi
callq 0x14990
leaq 0x178(%rsp), %rdi
callq 0x14600
jmp 0xd3f0
movl $0xffffffff, 0x14c(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0x148(%rsp)
movl $0x0, 0x144(%rsp)
movl 0x144(%rsp), %eax
cmpl 0x234(%rsp), %eax
jge 0xcef0
movslq 0x144(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
callq 0x14750
movl (%rax), %eax
cmpl 0x14c(%rsp), %eax
jle 0xcedb
movslq 0x144(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
callq 0x14750
movl (%rax), %eax
movl %eax, 0x14c(%rsp)
movl 0x144(%rsp), %eax
movl %eax, 0x148(%rsp)
jmp 0xcedd
movl 0x144(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x144(%rsp)
jmp 0xce7f
movq 0x3d0f1(%rip), %rdi     # 0x49fe8
leaq 0x29746(%rip), %rsi     # 0x36644
callq 0x43c0
movq %rax, 0x88(%rsp)
jmp 0xcf0d
movq 0x88(%rsp), %rdi
movl 0x1dc(%rsp), %esi
callq 0x4600
movq %rax, 0x80(%rsp)
jmp 0xcf2b
movq 0x80(%rsp), %rdi
leaq 0x29710(%rip), %rsi     # 0x3664a
callq 0x43c0
movq %rax, 0x78(%rsp)
jmp 0xcf46
movq 0x78(%rsp), %rdi
movl 0x14c(%rsp), %esi
callq 0x4600
movq %rax, 0x70(%rsp)
jmp 0xcf5e
movq 0x70(%rsp), %rdi
movq 0x3d026(%rip), %rsi     # 0x49f90
callq 0x4400
jmp 0xcf71
movl 0x25c(%rsp), %eax
cmpl 0x14c(%rsp), %eax
jge 0xd0a9
movslq 0x148(%rsp), %rsi
leaq 0x1c0(%rsp), %rdi
movq %rdi, 0x68(%rsp)
callq 0x14750
movq 0x68(%rsp), %rdi
movl (%rax), %eax
movl %eax, 0x25c(%rsp)
movslq 0x148(%rsp), %rsi
callq 0x14750
movq %rax, %rsi
addq $0x8, %rsi
leaq 0x238(%rsp), %rdi
callq 0x4040
jmp 0xcfd0
movq 0x3d011(%rip), %rdi     # 0x49fe8
leaq 0x29655(%rip), %rsi     # 0x36633
callq 0x43c0
movq %rax, 0x60(%rsp)
jmp 0xcfea
movq 0x60(%rsp), %rdi
movq 0x278(%rsp), %rax
movl (%rax), %esi
callq 0x4600
movq %rax, 0x58(%rsp)
jmp 0xd005
movq 0x58(%rsp), %rdi
leaq 0x295bb(%rip), %rsi     # 0x365cc
callq 0x43c0
movq %rax, 0x50(%rsp)
jmp 0xd01d
movq 0x50(%rsp), %rdi
movl 0x274(%rsp), %esi
callq 0x4600
movq %rax, 0x48(%rsp)
jmp 0xd035
movq 0x48(%rsp), %rdi
leaq 0x29606(%rip), %rsi     # 0x36647
callq 0x43c0
movq %rax, 0x40(%rsp)
jmp 0xd04d
movq 0x40(%rsp), %rdi
movl 0x25c(%rsp), %esi
callq 0x4600
movq %rax, 0x38(%rsp)
jmp 0xd065
movq 0x38(%rsp), %rdi
movq 0x3cf1f(%rip), %rsi     # 0x49f90
callq 0x4400
jmp 0xd078
movq 0x278(%rsp), %rax
movl (%rax), %edi
movl 0x274(%rsp), %esi
movl 0x25c(%rsp), %edx
movq 0x260(%rsp), %r8
leaq 0x238(%rsp), %rcx
callq 0x9d60
jmp 0xd0a7
jmp 0xd0a9
leaq 0x128(%rsp), %rdi
callq 0x14790
leaq 0x128(%rsp), %rdi
callq 0x149d0
cmpl 0x234(%rsp), %eax
jge 0xd39c
callq 0x4ee0
movsd %xmm0, 0x120(%rsp)
movsd 0x28f6a(%rip), %xmm0    # 0x36050
ucomisd 0x120(%rsp), %xmm0
jbe 0xd170
leaq 0x108(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0xc920
jmp 0xd108
leaq 0x128(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x149f0
jmp 0xd11f
leaq 0x108(%rsp), %rdi
callq 0x12400
jmp 0xd397
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0xd3e3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0x108(%rsp), %rdi
callq 0x12400
jmp 0xd3e3
movsd 0x28ee0(%rip), %xmm0    # 0x36058
ucomisd 0x120(%rsp), %xmm0
jbe 0xd31c
movslq 0x234(%rsp), %rax
movq %rax, 0x30(%rsp)
leaq 0x128(%rsp), %rdi
callq 0x149d0
movq %rax, %rcx
movq 0x30(%rsp), %rax
subq %rcx, %rax
cmpq $0x2, %rax
jae 0xd1b7
jmp 0xd0b6
leaq 0xf0(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0xc920
jmp 0xd1ce
leaq 0xd8(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0xc920
jmp 0xd1e5
movl $0x0, 0xd4(%rsp)
movl 0xd4(%rsp), %eax
movl %eax, 0x2c(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x144e0
movq %rax, %rcx
movl 0x2c(%rsp), %eax
cmpl %ecx, %eax
jge 0xd29c
callq 0x4ee0
movaps %xmm0, %xmm1
movsd 0x28df1(%rip), %xmm0    # 0x36018
ucomisd %xmm1, %xmm0
jbe 0xd284
movslq 0xd4(%rsp), %rsi
leaq 0xf0(%rsp), %rdi
callq 0x125a0
movq %rax, 0x20(%rsp)
movslq 0xd4(%rsp), %rsi
leaq 0xd8(%rsp), %rdi
callq 0x125a0
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x14a20
jmp 0xd284
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
jmp 0xd30a
jmp 0xd286
movl 0xd4(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xd4(%rsp)
jmp 0xd1f0
leaq 0x128(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x147a0
jmp 0xd2b3
leaq 0x128(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x147a0
jmp 0xd2ca
leaq 0xd8(%rsp), %rdi
callq 0x12400
leaq 0xf0(%rsp), %rdi
callq 0x12400
jmp 0xd395
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0xd8(%rsp), %rdi
callq 0x12400
leaq 0xf0(%rsp), %rdi
callq 0x12400
jmp 0xd3e3
leaq 0xb8(%rsp), %rdi
leaq 0x1c0(%rsp), %rsi
callq 0xc920
jmp 0xd333
callq 0x4ee0
movsd 0x28cd8(%rip), %xmm1    # 0x36018
subsd %xmm1, %xmm0
movsd %xmm0, 0x18(%rsp)
callq 0x4ed0
movq %rax, 0x10(%rsp)
leaq 0xb8(%rsp), %rdi
callq 0x144e0
movq %rax, %rcx
movq 0x10(%rsp), %rax
xorl %edx, %edx
divq %rcx
movq %rdx, %rsi
leaq 0xb8(%rsp), %rdi
callq 0x125a0
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%rax)
leaq 0xb8(%rsp), %rdi
callq 0x12400
jmp 0xd397
jmp 0xd0b6
leaq 0x218(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x14a60
jmp 0xd3b3
leaq 0x128(%rsp), %rdi
callq 0x14d20
leaq 0x1c0(%rsp), %rdi
callq 0x14d80
movl 0x1dc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x1dc(%rsp)
jmp 0xccc9
leaq 0x128(%rsp), %rdi
callq 0x14d20
leaq 0x1c0(%rsp), %rdi
callq 0x14d80
jmp 0xd45c
movq 0xa8(%rsp), %rdi
leaq 0x238(%rsp), %rsi
leaq 0x25c(%rsp), %rdx
callq 0x14610
jmp 0xd41e
leaq 0x218(%rsp), %rdi
callq 0x14d20
leaq 0x238(%rsp), %rdi
callq 0x4700
movq 0xb0(%rsp), %rax
addq $0x288, %rsp            # imm = 0x288
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x1e8(%rsp)
movl %eax, 0x1e4(%rsp)
leaq 0x218(%rsp), %rdi
callq 0x14d20
leaq 0x238(%rsp), %rdi
callq 0x4700
movq 0x1e8(%rsp), %rdi
callq 0x4620
nopw %cs:(%rax,%rax)