// File: /workspace/github_cpp_makefile_star2_O2/s-yata[P]louds-patricia/main.cpp
// Function: main
int main() {
  ios_base::sync_with_stdio(false);
  vector<string> keys;
  string line;
  while (getline(cin, line)) {
    keys.push_back(line);
  }

  high_resolution_clock::time_point begin = high_resolution_clock::now();
  louds::Patricia patricia;
  for (uint64_t i = 0; i < keys.size(); ++i) {
    patricia.add(keys[i]);
  }
  patricia.build();
  high_resolution_clock::time_point end = high_resolution_clock::now();
  double elapsed = (double)duration_cast<nanoseconds>(end - begin).count();
  cout << "build = " << (elapsed / keys.size()) << " ns/key" << endl;

  cout << "#keys = " << patricia.n_keys() << endl;
  cout << "#nodes = " << patricia.n_nodes() << endl;
  cout << "size = " << patricia.size() << " bytes" << endl;

  vector<int64_t> ids(keys.size());

  begin = high_resolution_clock::now();
  for (uint64_t i = 0; i < keys.size(); ++i) {
    ids[i] = patricia.lookup(keys[i]);
    assert(ids[i] != -1);
  }
  end = high_resolution_clock::now();
  elapsed = (double)duration_cast<nanoseconds>(end - begin).count();
  cout << "seq. lookup = " << (elapsed / keys.size()) << " ns/key" << endl;

  sort(ids.begin(), ids.end());
  for (uint64_t i = 0; i < ids.size(); ++i) {
    if (i != (uint64_t)ids[i]) {
      cout << "i = " << i << ", ids[i] = " << ids[i] << endl;
    }
    assert((uint64_t)ids[i] == i);
  }

  random_shuffle(keys.begin(), keys.end());

  begin = high_resolution_clock::now();
  for (uint64_t i = 0; i < keys.size(); ++i) {
    assert(patricia.lookup(keys[i]) != -1);
  }
  end = high_resolution_clock::now();
  elapsed = (double)duration_cast<nanoseconds>(end - begin).count();
  cout << "rnd. lookup = " << (elapsed / keys.size()) << " ns/key" << endl;

  return 0;
}

// Assembly:
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x68, %rsp
xorl %edi, %edi
callq 0x20a0
leaq 0x10(%rsp), %rbx
leaq 0x58(%rsp), %rax
movq 0x41c5(%rip), %r14      # 0x7fe0
vxorpd %xmm0, %xmm0, %xmm0
leaq 0x48(%rsp), %r15
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
andq $0x0, 0x10(%rbx)
vmovapd %xmm0, (%rbx)
movb $0x0, (%rax)
movq %r14, %rdi
movq %r15, %rsi
callq 0x2050
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x3e5f
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4272
jmp 0x3e39
callq 0x2040
movq %rax, %rbx
movq %rsp, %rdi
callq 0x232c
xorl %r15d, %r15d
movq %rsp, %r14
xorl %r12d, %r12d
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rax, %r12
jae 0x3ea2
addq %r15, %rsi
movq %r14, %rdi
callq 0x238c
incq %r12
addq $0x20, %r15
jmp 0x3e78
movq %rsp, %rdi
callq 0x2394
callq 0x2040
movq %rax, %r14
movq 0x4117(%rip), %rdi      # 0x7fd0
leaq 0x1237(%rip), %rsi      # 0x50f7
callq 0x2150
movq 0x18(%rsp), %rcx
subq %rbx, %r14
subq 0x10(%rsp), %rcx
vcvtsi2sd %r14, %xmm1, %xmm0
sarq $0x5, %rcx
vcvtusi2sd %rcx, %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
movq %rax, %rdi
callq 0x21c0
leaq 0x120c(%rip), %rsi      # 0x5100
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
callq 0x20c0
movq 0x40c5(%rip), %rdi      # 0x7fd0
leaq 0x11f6(%rip), %rsi      # 0x5108
callq 0x2150
movq %rsp, %rdi
movq %rax, %rbx
callq 0x23a4
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2100
movq %rax, %rdi
callq 0x20c0
movq 0x4094(%rip), %rdi      # 0x7fd0
leaq 0x11ce(%rip), %rsi      # 0x5111
callq 0x2150
movq %rsp, %rdi
movq %rax, %rbx
callq 0x23ac
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2100
movq %rax, %rdi
callq 0x20c0
movq 0x4063(%rip), %rdi      # 0x7fd0
leaq 0x11a7(%rip), %rsi      # 0x511b
callq 0x2150
movq %rsp, %rdi
movq %rax, %rbx
callq 0x23b8
movq %rbx, %rdi
movq %rax, %rsi
callq 0x2100
leaq 0x118d(%rip), %rsi      # 0x5123
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
callq 0x20c0
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x5, %rsi
leaq 0x30(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x429e
xorl %r15d, %r15d
callq 0x2040
movq %rax, %rbx
movq %rsp, %r14
xorl %r12d, %r12d
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rax, %r12
jae 0x4027
addq %r15, %rsi
movq %r14, %rdi
callq 0x239c
movq 0x30(%rsp), %rcx
addq $0x20, %r15
movq %rax, (%rcx,%r12,8)
incq %r12
cmpq $-0x1, %rax
jne 0x3fd4
leaq 0x1118(%rip), %rdi      # 0x512a
leaq 0x111e(%rip), %rsi      # 0x5137
leaq 0x1120(%rip), %rcx      # 0x5140
pushq $0x27
jmp 0x4194
callq 0x2040
movq %rax, %r14
movq 0x3f9a(%rip), %rdi      # 0x7fd0
leaq 0x110e(%rip), %rsi      # 0x514b
callq 0x2150
movq 0x18(%rsp), %rcx
subq %rbx, %r14
subq 0x10(%rsp), %rcx
vcvtsi2sd %r14, %xmm2, %xmm0
sarq $0x5, %rcx
vcvtusi2sd %rcx, %xmm2, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
movq %rax, %rdi
callq 0x21c0
leaq 0x108f(%rip), %rsi      # 0x5100
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
callq 0x20c0
movq 0x30(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x46ab
movq 0x30(%rsp), %rax
movq 0x3f34(%rip), %r14      # 0x7fd0
leaq 0x10b7(%rip), %r15      # 0x515a
leaq 0x10b5(%rip), %r12      # 0x515f
xorl %ebx, %ebx
movq 0x38(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %rbx
jae 0x412e
movq %rbx, %rcx
cmpq (%rax,%rbx,8), %rbx
je 0x4109
movq %r14, %rdi
movq %r15, %rsi
callq 0x2150
movq %rax, %rdi
movq %rbx, %rsi
callq 0x2100
movq %rax, %rdi
movq %r12, %rsi
callq 0x2150
movq 0x30(%rsp), %rcx
movq (%rcx,%rbx,8), %rsi
movq %rax, %rdi
callq 0x2140
movq %rax, %rdi
callq 0x20c0
movq 0x30(%rsp), %rax
movq (%rax,%rbx,8), %rcx
leaq 0x1(%rbx), %rdx
cmpq %rcx, %rbx
movq %rdx, %rbx
je 0x40ac
leaq 0x104f(%rip), %rdi      # 0x516b
leaq 0x1014(%rip), %rsi      # 0x5137
leaq 0x1016(%rip), %rcx      # 0x5140
pushq $0x32
jmp 0x4194
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x42f1
pushq $-0x1
popq %r15
xorl %r12d, %r12d
callq 0x2040
movq %rax, %rbx
movq %rsp, %r14
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
incq %r15
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rax, %r15
jae 0x419a
addq %r12, %rsi
movq %r14, %rdi
callq 0x239c
addq $0x20, %r12
cmpq $-0x1, %rax
jne 0x414f
leaq 0xffd(%rip), %rdi       # 0x5181
leaq 0xfac(%rip), %rsi       # 0x5137
leaq 0xfae(%rip), %rcx       # 0x5140
pushq $0x39
popq %rdx
callq 0x20f0
callq 0x2040
movq %rax, %r14
movq 0x3e27(%rip), %rdi      # 0x7fd0
leaq 0xff0(%rip), %rsi       # 0x51a0
callq 0x2150
movq 0x18(%rsp), %rcx
subq %rbx, %r14
subq 0x10(%rsp), %rcx
vcvtsi2sd %r14, %xmm2, %xmm0
sarq $0x5, %rcx
vcvtusi2sd %rcx, %xmm2, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
movq %rax, %rdi
callq 0x21c0
leaq 0xf1c(%rip), %rsi       # 0x5100
movq %rax, %rdi
callq 0x2150
movq %rax, %rdi
callq 0x20c0
leaq 0x30(%rsp), %rdi
callq 0x45d2
movq %rsp, %rdi
callq 0x236c
leaq 0x48(%rsp), %rdi
callq 0x20b0
leaq 0x10(%rsp), %rdi
callq 0x4350
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
jmp 0x4236
jmp 0x4236
jmp 0x423b
jmp 0x4240
jmp 0x4236
jmp 0x4240
jmp 0x4240
movq %rax, %rbx
jmp 0x424d
movq %rax, %rbx
jmp 0x4255
leaq 0x30(%rsp), %rdi
movq %rax, %rbx
callq 0x45d2
movq %rsp, %rdi
callq 0x236c
leaq 0x48(%rsp), %rdi
callq 0x20b0
leaq 0x10(%rsp), %rdi
callq 0x4350
movq %rbx, %rdi
callq 0x21f0
nop