// File: /workspace/github_cpp_makefile_star2_O1/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 %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
xorl %r14d, %r14d
xorl %edi, %edi
callq 0x20a0
leaq 0x10(%rsp), %rbx
movq %r14, 0x10(%rbx)
vxorpd %xmm0, %xmm0, %xmm0
vmovapd %xmm0, (%rbx)
leaq 0x58(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq %r14, -0x8(%rbp)
movb $0x0, (%rbp)
movq 0x4d1b(%rip), %r14      # 0x8fe0
leaq 0x48(%rsp), %r15
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x2220
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
testb $0x5, 0x20(%rax,%rcx)
jne 0x4307
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4958
jmp 0x42ca
callq 0x2050
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x23fc
movq 0x10(%rsp), %rsi
cmpq %rsi, 0x18(%rsp)
je 0x4358
xorl %r15d, %r15d
leaq 0x8(%rsp), %r14
xorl %r12d, %r12d
addq %r15, %rsi
movq %r14, %rdi
callq 0x245e
incq %r12
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
addq $0x20, %r15
cmpq %rax, %r12
jb 0x4330
leaq 0x8(%rsp), %rdi
callq 0x2466
callq 0x2050
movq %rax, %r14
movq 0x4c5f(%rip), %rdi      # 0x8fd0
leaq 0x1e2f(%rip), %rsi      # 0x61a7
movl $0x8, %edx
callq 0x21a0
subq %rbx, %r14
vcvtsi2sd %r14, %xmm1, %xmm0
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x5, %rax
vcvtusi2sd %rax, %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
movq 0x4c27(%rip), %rdi      # 0x8fd0
callq 0x21d0
movq %rax, %rbx
leaq 0x1df8(%rip), %rsi      # 0x61b0
movl $0x7, %edx
movq %rax, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x4bdd(%rip), %rdi      # 0x8fd0
leaq 0x1dbe(%rip), %rsi      # 0x61b8
movl $0x8, %edx
callq 0x21a0
leaq 0x8(%rsp), %rdi
callq 0x2476
movq 0x4bbb(%rip), %rdi      # 0x8fd0
movq %rax, %rsi
callq 0x20f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x4b82(%rip), %rdi      # 0x8fd0
leaq 0x1d6c(%rip), %rsi      # 0x61c1
movl $0x9, %edx
callq 0x21a0
leaq 0x8(%rsp), %rdi
callq 0x247e
movq 0x4b60(%rip), %rdi      # 0x8fd0
movq %rax, %rsi
callq 0x20f0
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x4b27(%rip), %rdi      # 0x8fd0
leaq 0x1d1b(%rip), %rsi      # 0x61cb
movl $0x7, %edx
callq 0x21a0
leaq 0x8(%rsp), %rdi
callq 0x248a
movq 0x4b05(%rip), %rdi      # 0x8fd0
movq %rax, %rsi
callq 0x20f0
movq %rax, %rbx
leaq 0x1cf6(%rip), %rsi      # 0x61d3
movl $0x6, %edx
movq %rax, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x5, %rsi
leaq 0x30(%rsp), %rdi
leaq 0x2f(%rsp), %rdx
callq 0x4996
callq 0x2050
movq %rax, %rbx
movq 0x10(%rsp), %rsi
cmpq %rsi, 0x18(%rsp)
je 0x4588
xorl %r15d, %r15d
leaq 0x8(%rsp), %r14
xorl %r12d, %r12d
addq %r15, %rsi
movq %r14, %rdi
callq 0x246e
movq 0x30(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
cmpq $-0x1, %rax
je 0x4896
incq %r12
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
addq $0x20, %r15
cmpq %rax, %r12
jb 0x454d
callq 0x2050
movq %rax, %r14
movq 0x4a39(%rip), %rdi      # 0x8fd0
leaq 0x1c5d(%rip), %rsi      # 0x61fb
movl $0xe, %edx
callq 0x21a0
subq %rbx, %r14
vcvtsi2sd %r14, %xmm0, %xmm0
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x5, %rax
vcvtusi2sd %rax, %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
movq 0x4a01(%rip), %rdi      # 0x8fd0
callq 0x21d0
movq %rax, %rbx
leaq 0x1bd2(%rip), %rsi      # 0x61b0
movl $0x7, %edx
movq %rax, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r14
cmpq %r14, %rbx
je 0x464c
movq %r14, %rax
subq %rbx, %rax
sarq $0x3, %rax
lzcntq %rax, %rdx
addl %edx, %edx
xorq $0x7e, %rdx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4d6f
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4e58
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x470e
xorl %ebx, %ebx
movq 0x496b(%rip), %r14      # 0x8fd0
leaq 0x1b9e(%rip), %r15      # 0x620a
leaq 0x1b9c(%rip), %r12      # 0x620f
cmpq (%rax,%rbx,8), %rbx
je 0x46e2
movl $0x4, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x21a0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x20f0
movq %rax, %r13
movl $0xb, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x21a0
movq 0x30(%rsp), %rax
movq (%rax,%rbx,8), %rsi
movq %r13, %rdi
callq 0x2160
movq %rax, %r13
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %r13, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x30(%rsp), %rax
cmpq (%rax,%rbx,8), %rbx
jne 0x48b5
incq %rbx
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %rbx
jb 0x4673
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
cmpq %r14, %rbx
je 0x4768
leaq 0x20(%rbx), %rax
cmpq %r14, %rax
je 0x4768
movl $0x20, %r15d
callq 0x2060
cltq
movq %r15, %rcx
sarq $0x5, %rcx
incq %rcx
cqto
idivq %rcx
shlq $0x5, %rdx
cmpq %rdx, %r15
je 0x475a
leaq (%rbx,%r15), %rdi
addq %rbx, %rdx
movq %rdx, %rsi
callq 0x2120
leaq 0x20(%rbx,%r15), %rax
addq $0x20, %r15
cmpq %r14, %rax
jne 0x472c
callq 0x2050
movq %rax, %rbx
movq 0x10(%rsp), %rsi
cmpq %rsi, 0x18(%rsp)
je 0x47b9
xorl %r15d, %r15d
leaq 0x8(%rsp), %r14
xorl %r12d, %r12d
addq %r15, %rsi
movq %r14, %rdi
callq 0x246e
cmpq $-0x1, %rax
je 0x48d4
incq %r12
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
subq %rsi, %rax
sarq $0x5, %rax
addq $0x20, %r15
cmpq %rax, %r12
jb 0x4787
callq 0x2050
movq %rax, %r14
movq 0x4808(%rip), %rdi      # 0x8fd0
leaq 0x1a81(%rip), %rsi      # 0x6250
movl $0xe, %edx
callq 0x21a0
subq %rbx, %r14
vcvtsi2sd %r14, %xmm2, %xmm0
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
sarq $0x5, %rax
vcvtusi2sd %rax, %xmm2, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
movq 0x47d0(%rip), %rdi      # 0x8fd0
callq 0x21d0
movq %rax, %rbx
leaq 0x19a1(%rip), %rsi      # 0x61b0
movl $0x7, %edx
movq %rax, %rdi
callq 0x21a0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x2170
movsbl %al, %esi
movq %rbx, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2100
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x485a
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x8(%rsp), %rdi
callq 0x243c
movq 0x48(%rsp), %rdi
cmpq %rbp, %rdi
je 0x487b
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2190
leaq 0x10(%rsp), %rdi
callq 0x4a22
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x193d(%rip), %rdi      # 0x61da
leaq 0x1943(%rip), %rsi      # 0x61e7
leaq 0x1945(%rip), %rcx      # 0x61f0
movl $0x27, %edx
callq 0x20e0
leaq 0x195f(%rip), %rdi      # 0x621b
leaq 0x1924(%rip), %rsi      # 0x61e7
leaq 0x1926(%rip), %rcx      # 0x61f0
movl $0x32, %edx
callq 0x20e0
leaq 0x1956(%rip), %rdi      # 0x6231
leaq 0x1905(%rip), %rsi      # 0x61e7
leaq 0x1907(%rip), %rcx      # 0x61f0
movl $0x39, %edx
callq 0x20e0
jmp 0x4901
jmp 0x4901
jmp 0x492c
jmp 0x4906
jmp 0x4906
jmp 0x4906
jmp 0x4901
movq %rax, %rbx
jmp 0x4920
movq %rax, %rbx
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x4920
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x8(%rsp), %rdi
callq 0x243c
jmp 0x492f
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %rbp, %rdi
je 0x4946
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2190
leaq 0x10(%rsp), %rdi
callq 0x4a22
movq %rbx, %rdi
callq 0x2200