// File: /workspace/github_cpp_makefile_star2_O3/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 %edi, %edi
xorl %r14d, %r14d
callq 0x20a0
leaq 0x10(%rsp), %rbx
leaq 0x58(%rsp), %rbp
vxorpd %xmm0, %xmm0, %xmm0
leaq 0x48(%rsp), %r15
movq %rbp, -0x10(%rbp)
movq %r14, -0x8(%rbp)
movq %r14, 0x10(%rbx)
movq 0x4d7e(%rip), %r14      # 0x8fe0
vmovapd %xmm0, (%rbx)
movb $0x0, (%rbp)
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 0x42a7
movq %rbx, %rdi
movq %r15, %rsi
callq 0x48f8
jmp 0x426a
callq 0x2050
movq %rax, %rbx
leaq 0x8(%rsp), %rdi
callq 0x23fc
movq 0x10(%rsp), %rsi
cmpq %rsi, 0x18(%rsp)
je 0x42f8
leaq 0x8(%rsp), %r14
xorl %r15d, %r15d
xorl %r12d, %r12d
addq %r15, %rsi
movq %r14, %rdi
callq 0x245c
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
incq %r12
addq $0x20, %r15
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rax, %r12
jb 0x42d0
leaq 0x8(%rsp), %rdi
callq 0x2464
callq 0x2050
movq %rax, %r14
movq 0x4cbf(%rip), %rdi      # 0x8fd0
leaq 0x1e8f(%rip), %rsi      # 0x61a7
movl $0x8, %edx
callq 0x21a0
movq 0x18(%rsp), %rax
subq %rbx, %r14
subq 0x10(%rsp), %rax
vcvtsi2sd %r14, %xmm1, %xmm0
sarq $0x5, %rax
vcvtusi2sd %rax, %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
movq 0x4c87(%rip), %rdi      # 0x8fd0
callq 0x21d0
leaq 0x1e5b(%rip), %rsi      # 0x61b0
movl $0x7, %edx
movq %rax, %rdi
movq %rax, %rbx
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 0x4c3d(%rip), %rdi      # 0x8fd0
leaq 0x1e1e(%rip), %rsi      # 0x61b8
movl $0x8, %edx
callq 0x21a0
leaq 0x8(%rsp), %rdi
callq 0x2474
movq 0x4c1b(%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 0x4be2(%rip), %rdi      # 0x8fd0
leaq 0x1dcc(%rip), %rsi      # 0x61c1
movl $0x9, %edx
callq 0x21a0
leaq 0x8(%rsp), %rdi
callq 0x247c
movq 0x4bc0(%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 0x4b87(%rip), %rdi      # 0x8fd0
leaq 0x1d7b(%rip), %rsi      # 0x61cb
movl $0x7, %edx
callq 0x21a0
leaq 0x8(%rsp), %rdi
callq 0x2488
movq 0x4b65(%rip), %rdi      # 0x8fd0
movq %rax, %rsi
callq 0x20f0
leaq 0x1d59(%rip), %rsi      # 0x61d3
movl $0x6, %edx
movq %rax, %rdi
movq %rax, %rbx
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 0x4936
callq 0x2050
movq 0x10(%rsp), %rsi
movq %rax, %rbx
cmpq %rsi, 0x18(%rsp)
je 0x4528
leaq 0x8(%rsp), %r14
xorl %r15d, %r15d
xorl %r12d, %r12d
addq %r15, %rsi
movq %r14, %rdi
callq 0x246c
movq 0x30(%rsp), %rcx
movq %rax, (%rcx,%r12,8)
cmpq $-0x1, %rax
je 0x4835
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
incq %r12
addq $0x20, %r15
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rax, %r12
jb 0x44ed
callq 0x2050
movq %rax, %r14
movq 0x4a99(%rip), %rdi      # 0x8fd0
leaq 0x1cbd(%rip), %rsi      # 0x61fb
movl $0xe, %edx
callq 0x21a0
movq 0x18(%rsp), %rax
subq %rbx, %r14
subq 0x10(%rsp), %rax
vcvtsi2sd %r14, %xmm0, %xmm0
sarq $0x5, %rax
vcvtusi2sd %rax, %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
movq 0x4a61(%rip), %rdi      # 0x8fd0
callq 0x21d0
leaq 0x1c35(%rip), %rsi      # 0x61b0
movl $0x7, %edx
movq %rax, %rdi
movq %rax, %rbx
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 0x46ad
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 0x4ce3
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4dcc
movq 0x30(%rsp), %rax
cmpq %rax, 0x38(%rsp)
je 0x46ad
movq 0x49c9(%rip), %r14      # 0x8fd0
leaq 0x1bfc(%rip), %r15      # 0x620a
leaq 0x1bfa(%rip), %r12      # 0x620f
xorl %ebx, %ebx
cmpq (%rax,%rbx,8), %rbx
je 0x4695
movl $0x4, %edx
movq %r14, %rdi
movq %r15, %rsi
callq 0x21a0
movq %r14, %rdi
movq %rbx, %rsi
callq 0x20f0
movl $0xb, %edx
movq %rax, %r13
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 0x4873
movq 0x38(%rsp), %rcx
incq %rbx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rcx, %rbx
jb 0x4617
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %r14
cmpq %r14, %rbx
je 0x4707
leaq 0x20(%rbx), %rax
cmpq %r14, %rax
je 0x4707
movl $0x20, %r15d
callq 0x2060
cltq
movq %r15, %rcx
sarq $0x5, %rcx
incq %rcx
cqto
idivq %rcx
shlq $0x5, %rdx
cmpq %rdx, %r15
je 0x46f9
addq %rbx, %rdx
leaq (%rbx,%r15), %rdi
movq %rdx, %rsi
callq 0x2120
leaq 0x20(%rbx,%r15), %rax
addq $0x20, %r15
cmpq %r14, %rax
jne 0x46cb
callq 0x2050
movq 0x10(%rsp), %rsi
movq %rax, %rbx
cmpq %rsi, 0x18(%rsp)
je 0x4758
xorl %r15d, %r15d
leaq 0x8(%rsp), %r14
xorl %r12d, %r12d
addq %r15, %rsi
movq %r14, %rdi
callq 0x246c
cmpq $-0x1, %rax
je 0x4854
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rax
incq %r12
addq $0x20, %r15
subq %rsi, %rax
sarq $0x5, %rax
cmpq %rax, %r12
jb 0x4726
callq 0x2050
movq %rax, %r14
movq 0x4869(%rip), %rdi      # 0x8fd0
leaq 0x1ae2(%rip), %rsi      # 0x6250
movl $0xe, %edx
callq 0x21a0
movq 0x18(%rsp), %rax
subq %rbx, %r14
subq 0x10(%rsp), %rax
vcvtsi2sd %r14, %xmm2, %xmm0
sarq $0x5, %rax
vcvtusi2sd %rax, %xmm2, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
movq 0x4831(%rip), %rdi      # 0x8fd0
callq 0x21d0
leaq 0x1a05(%rip), %rsi      # 0x61b0
movl $0x7, %edx
movq %rax, %rdi
movq %rax, %rbx
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 0x47f9
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x8(%rsp), %rdi
callq 0x243c
movq 0x48(%rsp), %rdi
cmpq %rbp, %rdi
je 0x481a
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2190
leaq 0x10(%rsp), %rdi
callq 0x49c6
xorl %eax, %eax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x199e(%rip), %rdi      # 0x61da
leaq 0x19a4(%rip), %rsi      # 0x61e7
leaq 0x19a6(%rip), %rcx      # 0x61f0
movl $0x27, %edx
callq 0x20e0
leaq 0x19d6(%rip), %rdi      # 0x6231
leaq 0x1985(%rip), %rsi      # 0x61e7
leaq 0x1987(%rip), %rcx      # 0x61f0
movl $0x39, %edx
callq 0x20e0
leaq 0x19a1(%rip), %rdi      # 0x621b
leaq 0x1966(%rip), %rsi      # 0x61e7
leaq 0x1968(%rip), %rcx      # 0x61f0
movl $0x32, %edx
callq 0x20e0
jmp 0x48a0
jmp 0x48a0
jmp 0x48cb
jmp 0x48a5
jmp 0x48a5
jmp 0x48a5
jmp 0x48a0
movq %rax, %rbx
jmp 0x48bf
movq 0x30(%rsp), %rdi
movq %rax, %rbx
testq %rdi, %rdi
je 0x48bf
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
leaq 0x8(%rsp), %rdi
callq 0x243c
jmp 0x48ce
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %rbp, %rdi
je 0x48e5
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2190
leaq 0x10(%rsp), %rdi
callq 0x49c6
movq %rbx, %rdi
callq 0x2200
nop