// File: 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:
subq $0x2a8, %rsp            # imm = 0x2A8
movl $0x0, 0x2a4(%rsp)
xorl %edi, %edi
callq 0x20c0
leaq 0x288(%rsp), %rdi
callq 0xacd0
leaq 0x268(%rsp), %rdi
callq 0x21c0
movq 0x9de6(%rip), %rdi      # 0x13fe0
leaq 0x268(%rsp), %rsi
callq 0x2060
movq %rax, 0x180(%rsp)
jmp 0xa211
movq 0x180(%rsp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x21b0
movb %al, 0x17f(%rsp)
jmp 0xa231
movb 0x17f(%rsp), %al
testb $0x1, %al
jne 0xa23e
jmp 0xa270
leaq 0x288(%rsp), %rdi
leaq 0x268(%rsp), %rsi
callq 0xace0
jmp 0xa255
jmp 0xa1f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x260(%rsp)
movl %eax, 0x25c(%rsp)
jmp 0xac9c
callq 0x2050
movq %rax, 0x250(%rsp)
leaq 0x248(%rsp), %rdi
callq 0x23a0
jmp 0xa28c
movq $0x0, 0x240(%rsp)
movq 0x240(%rsp), %rax
movq %rax, 0x170(%rsp)
leaq 0x288(%rsp), %rdi
callq 0xad50
movq %rax, %rcx
movq 0x170(%rsp), %rax
cmpq %rcx, %rax
jae 0xa31d
movq 0x240(%rsp), %rsi
leaq 0x288(%rsp), %rdi
callq 0xad70
movq %rax, %rsi
leaq 0x248(%rsp), %rdi
callq 0x2450
jmp 0xa2ec
jmp 0xa2ee
movq 0x240(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x240(%rsp)
jmp 0xa298
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x260(%rsp)
movl %eax, 0x25c(%rsp)
jmp 0xac8f
leaq 0x248(%rsp), %rdi
callq 0x2480
jmp 0xa32c
callq 0x2050
movq %rax, 0x238(%rsp)
leaq 0x238(%rsp), %rdi
leaq 0x250(%rsp), %rsi
callq 0xadc0
movq %rax, 0x168(%rsp)
jmp 0xa358
movq 0x168(%rsp), %rax
movq %rax, 0x220(%rsp)
leaq 0x220(%rsp), %rdi
callq 0xad90
movq %rax, 0x160(%rsp)
jmp 0xa37f
movq 0x160(%rsp), %rax
movq %rax, 0x228(%rsp)
leaq 0x228(%rsp), %rdi
callq 0xae10
movq %rax, 0x158(%rsp)
jmp 0xa3a6
movq 0x158(%rsp), %rax
vcvtsi2sd %rax, %xmm0, %xmm0
vmovsd %xmm0, 0x230(%rsp)
movq 0x9c0d(%rip), %rdi      # 0x13fd0
leaq 0x3d42(%rip), %rsi      # 0xe10c
callq 0x2160
movq %rax, 0x150(%rsp)
jmp 0xa3d9
vmovsd 0x230(%rsp), %xmm0
vmovsd %xmm0, 0x140(%rsp)
leaq 0x288(%rsp), %rdi
callq 0xad50
vmovsd 0x140(%rsp), %xmm0
movq 0x150(%rsp), %rdi
vcvtusi2sd %rax, %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
callq 0x2250
movq %rax, 0x148(%rsp)
jmp 0xa422
movq 0x148(%rsp), %rdi
leaq 0x3ce4(%rip), %rsi      # 0xe115
callq 0x2160
movq %rax, 0x138(%rsp)
jmp 0xa440
movq 0x138(%rsp), %rdi
movq 0x9b71(%rip), %rsi      # 0x13fc0
callq 0x2190
jmp 0xa456
movq 0x9b73(%rip), %rdi      # 0x13fd0
leaq 0x3cb9(%rip), %rsi      # 0xe11d
callq 0x2160
movq %rax, 0x130(%rsp)
jmp 0xa473
leaq 0x248(%rsp), %rdi
callq 0x24d0
movq %rax, 0x128(%rsp)
jmp 0xa48a
movq 0x128(%rsp), %rsi
movq 0x130(%rsp), %rdi
callq 0x2070
movq %rax, 0x120(%rsp)
jmp 0xa4a9
movq 0x120(%rsp), %rdi
movq 0x9b08(%rip), %rsi      # 0x13fc0
callq 0x2190
jmp 0xa4bf
movq 0x9b0a(%rip), %rdi      # 0x13fd0
leaq 0x3c59(%rip), %rsi      # 0xe126
callq 0x2160
movq %rax, 0x118(%rsp)
jmp 0xa4dc
leaq 0x248(%rsp), %rdi
callq 0x24f0
movq %rax, 0x110(%rsp)
jmp 0xa4f3
movq 0x110(%rsp), %rsi
movq 0x118(%rsp), %rdi
callq 0x2070
movq %rax, 0x108(%rsp)
jmp 0xa512
movq 0x108(%rsp), %rdi
movq 0x9a9f(%rip), %rsi      # 0x13fc0
callq 0x2190
jmp 0xa528
movq 0x9aa1(%rip), %rdi      # 0x13fd0
leaq 0x3bfa(%rip), %rsi      # 0xe130
callq 0x2160
movq %rax, 0x100(%rsp)
jmp 0xa545
leaq 0x248(%rsp), %rdi
callq 0x2510
movq %rax, 0xf8(%rsp)
jmp 0xa55c
movq 0xf8(%rsp), %rsi
movq 0x100(%rsp), %rdi
callq 0x2070
movq %rax, 0xf0(%rsp)
jmp 0xa57b
movq 0xf0(%rsp), %rdi
leaq 0x3bae(%rip), %rsi      # 0xe138
callq 0x2160
movq %rax, 0xe8(%rsp)
jmp 0xa599
movq 0xe8(%rsp), %rdi
movq 0x9a18(%rip), %rsi      # 0x13fc0
callq 0x2190
jmp 0xa5af
leaq 0x288(%rsp), %rdi
callq 0xad50
movq %rax, 0xd8(%rsp)
leaq 0x207(%rsp), %rdi
movq %rdi, 0xe0(%rsp)
callq 0xae20
movq 0xd8(%rsp), %rsi
movq 0xe0(%rsp), %rdx
leaq 0x208(%rsp), %rdi
callq 0xae30
jmp 0xa5f8
leaq 0x207(%rsp), %rdi
callq 0xaeb0
callq 0x2050
movq %rax, 0x1f8(%rsp)
movq 0x1f8(%rsp), %rax
movq %rax, 0x250(%rsp)
movq $0x0, 0x1f0(%rsp)
movq 0x1f0(%rsp), %rax
movq %rax, 0xd0(%rsp)
leaq 0x288(%rsp), %rdi
callq 0xad50
movq %rax, %rcx
movq 0xd0(%rsp), %rax
cmpq %rcx, %rax
jae 0xa751
movq 0x1f0(%rsp), %rsi
leaq 0x288(%rsp), %rdi
callq 0xad70
movq %rax, %rsi
leaq 0x248(%rsp), %rdi
callq 0x24a0
movq %rax, 0xc8(%rsp)
jmp 0xa68e
movq 0x1f0(%rsp), %rsi
leaq 0x208(%rsp), %rdi
callq 0xaec0
movq 0xc8(%rsp), %rcx
movq %rcx, (%rax)
movq 0x1f0(%rsp), %rsi
leaq 0x208(%rsp), %rdi
callq 0xaec0
cmpq $-0x1, (%rax)
je 0xa6cb
jmp 0xa736
leaq 0x3a6d(%rip), %rdi      # 0xe13f
leaq 0x3a73(%rip), %rsi      # 0xe14c
movl $0x27, %edx
leaq 0x3a70(%rip), %rcx      # 0xe155
callq 0x2120
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x260(%rsp)
movl %eax, 0x25c(%rsp)
leaq 0x207(%rsp), %rdi
callq 0xaeb0
jmp 0xac8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x260(%rsp)
movl %eax, 0x25c(%rsp)
leaq 0x208(%rsp), %rdi
callq 0xb0e0
jmp 0xac8f
jmp 0xa738
movq 0x1f0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x1f0(%rsp)
jmp 0xa62e
callq 0x2050
movq %rax, 0x1e8(%rsp)
movq 0x1e8(%rsp), %rax
movq %rax, 0x238(%rsp)
leaq 0x238(%rsp), %rdi
leaq 0x250(%rsp), %rsi
callq 0xadc0
movq %rax, 0xc0(%rsp)
jmp 0xa78d
movq 0xc0(%rsp), %rax
movq %rax, 0x1d8(%rsp)
leaq 0x1d8(%rsp), %rdi
callq 0xad90
movq %rax, 0xb8(%rsp)
jmp 0xa7b4
movq 0xb8(%rsp), %rax
movq %rax, 0x1e0(%rsp)
leaq 0x1e0(%rsp), %rdi
callq 0xae10
movq %rax, 0xb0(%rsp)
jmp 0xa7db
movq 0xb0(%rsp), %rax
vcvtsi2sd %rax, %xmm0, %xmm0
vmovsd %xmm0, 0x230(%rsp)
movq 0x97d8(%rip), %rdi      # 0x13fd0
leaq 0x3961(%rip), %rsi      # 0xe160
callq 0x2160
movq %rax, 0xa8(%rsp)
jmp 0xa80e
vmovsd 0x230(%rsp), %xmm0
vmovsd %xmm0, 0x98(%rsp)
leaq 0x288(%rsp), %rdi
callq 0xad50
vmovsd 0x98(%rsp), %xmm0
movq 0xa8(%rsp), %rdi
vcvtusi2sd %rax, %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
callq 0x2250
movq %rax, 0xa0(%rsp)
jmp 0xa857
movq 0xa0(%rsp), %rdi
leaq 0x38af(%rip), %rsi      # 0xe115
callq 0x2160
movq %rax, 0x90(%rsp)
jmp 0xa875
movq 0x90(%rsp), %rdi
movq 0x973c(%rip), %rsi      # 0x13fc0
callq 0x2190
jmp 0xa88b
leaq 0x208(%rsp), %rdi
movq %rdi, 0x88(%rsp)
callq 0xaf20
movq 0x88(%rsp), %rdi
movq %rax, 0x1d0(%rsp)
callq 0xaf50
movq %rax, 0x1c8(%rsp)
movq 0x1d0(%rsp), %rdi
movq 0x1c8(%rsp), %rsi
callq 0xaee0
jmp 0xa8d4
movq $0x0, 0x1c0(%rsp)
movq 0x1c0(%rsp), %rax
movq %rax, 0x80(%rsp)
leaq 0x208(%rsp), %rdi
callq 0xaf80
movq %rax, %rcx
movq 0x80(%rsp), %rax
cmpq %rcx, %rax
jae 0xaa2b
movq 0x1c0(%rsp), %rax
movq %rax, 0x78(%rsp)
movq 0x1c0(%rsp), %rsi
leaq 0x208(%rsp), %rdi
callq 0xaec0
movq %rax, %rcx
movq 0x78(%rsp), %rax
cmpq (%rcx), %rax
je 0xa9cd
movq 0x9685(%rip), %rdi      # 0x13fd0
leaq 0x381d(%rip), %rsi      # 0xe16f
callq 0x2160
movq %rax, 0x70(%rsp)
jmp 0xa95e
movq 0x70(%rsp), %rdi
movq 0x1c0(%rsp), %rsi
callq 0x2070
movq %rax, 0x68(%rsp)
jmp 0xa977
movq 0x68(%rsp), %rdi
leaq 0x37f1(%rip), %rsi      # 0xe174
callq 0x2160
movq %rax, 0x60(%rsp)
jmp 0xa98f
movq 0x1c0(%rsp), %rsi
leaq 0x208(%rsp), %rdi
callq 0xaec0
movq 0x60(%rsp), %rdi
movq (%rax), %rsi
callq 0x2240
movq %rax, 0x58(%rsp)
jmp 0xa9b8
movq 0x58(%rsp), %rdi
movq 0x95fc(%rip), %rsi      # 0x13fc0
callq 0x2190
jmp 0xa9cb
jmp 0xa9cd
movq 0x1c0(%rsp), %rsi
leaq 0x208(%rsp), %rdi
callq 0xaec0
movq (%rax), %rax
cmpq 0x1c0(%rsp), %rax
jne 0xa9f1
jmp 0xaa10
leaq 0x3788(%rip), %rdi      # 0xe180
leaq 0x374d(%rip), %rsi      # 0xe14c
movl $0x32, %edx
leaq 0x374a(%rip), %rcx      # 0xe155
callq 0x2120
jmp 0xaa12
movq 0x1c0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x1c0(%rsp)
jmp 0xa8e0
leaq 0x288(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0xb080
movq 0x50(%rsp), %rdi
movq %rax, 0x1b8(%rsp)
callq 0xb0b0
movq %rax, 0x1b0(%rsp)
movq 0x1b8(%rsp), %rdi
movq 0x1b0(%rsp), %rsi
callq 0xafa0
jmp 0xaa6e
callq 0x2050
movq %rax, 0x1a8(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, 0x250(%rsp)
movq $0x0, 0x1a0(%rsp)
movq 0x1a0(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0x288(%rsp), %rdi
callq 0xad50
movq %rax, %rcx
movq 0x48(%rsp), %rax
cmpq %rcx, %rax
jae 0xab31
movq 0x1a0(%rsp), %rsi
leaq 0x288(%rsp), %rdi
callq 0xad70
movq %rax, %rsi
leaq 0x248(%rsp), %rdi
callq 0x24a0
movq %rax, 0x40(%rsp)
jmp 0xaaea
movq 0x40(%rsp), %rax
cmpq $-0x1, %rax
je 0xaaf7
jmp 0xab16
leaq 0x3698(%rip), %rdi      # 0xe196
leaq 0x3647(%rip), %rsi      # 0xe14c
movl $0x39, %edx
leaq 0x3644(%rip), %rcx      # 0xe155
callq 0x2120
jmp 0xab18
movq 0x1a0(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x1a0(%rsp)
jmp 0xaa97
callq 0x2050
movq %rax, 0x198(%rsp)
movq 0x198(%rsp), %rax
movq %rax, 0x238(%rsp)
leaq 0x238(%rsp), %rdi
leaq 0x250(%rsp), %rsi
callq 0xadc0
movq %rax, 0x38(%rsp)
jmp 0xab6a
movq 0x38(%rsp), %rax
movq %rax, 0x188(%rsp)
leaq 0x188(%rsp), %rdi
callq 0xad90
movq %rax, 0x30(%rsp)
jmp 0xab8b
movq 0x30(%rsp), %rax
movq %rax, 0x190(%rsp)
leaq 0x190(%rsp), %rdi
callq 0xae10
movq %rax, 0x28(%rsp)
jmp 0xabac
movq 0x28(%rsp), %rax
vcvtsi2sd %rax, %xmm0, %xmm0
vmovsd %xmm0, 0x230(%rsp)
movq 0x940a(%rip), %rdi      # 0x13fd0
leaq 0x35e8(%rip), %rsi      # 0xe1b5
callq 0x2160
movq %rax, 0x20(%rsp)
jmp 0xabd9
vmovsd 0x230(%rsp), %xmm0
vmovsd %xmm0, 0x10(%rsp)
leaq 0x288(%rsp), %rdi
callq 0xad50
vmovsd 0x10(%rsp), %xmm0
movq 0x20(%rsp), %rdi
vcvtusi2sd %rax, %xmm1, %xmm1
vdivsd %xmm1, %xmm0, %xmm0
callq 0x2250
movq %rax, 0x18(%rsp)
jmp 0xac16
movq 0x18(%rsp), %rdi
leaq 0x34f3(%rip), %rsi      # 0xe115
callq 0x2160
movq %rax, 0x8(%rsp)
jmp 0xac2e
movq 0x8(%rsp), %rdi
movq 0x9386(%rip), %rsi      # 0x13fc0
callq 0x2190
jmp 0xac41
movl $0x0, 0x2a4(%rsp)
leaq 0x208(%rsp), %rdi
callq 0xb0e0
leaq 0x248(%rsp), %rdi
callq 0x2410
leaq 0x268(%rsp), %rdi
callq 0x2110
leaq 0x288(%rsp), %rdi
callq 0xb140
movl 0x2a4(%rsp), %eax
addq $0x2a8, %rsp            # imm = 0x2A8
retq
leaq 0x248(%rsp), %rdi
callq 0x2410
leaq 0x268(%rsp), %rdi
callq 0x2110
leaq 0x288(%rsp), %rdi
callq 0xb140
movq 0x260(%rsp), %rdi
callq 0x2230
nopw %cs:(%rax,%rax)
nopl (%rax)