// File: ikatanic[P]lcskpp/./utils.h
// Function: radix_sort(std::vector<std::pair<unsigned long, int>, std::allocator<std::pair<unsigned long, int>>>&, unsigned long)
void radix_sort(vector<pair<uint64_t, int>> &v, uint64_t maks) {
  const int len = 9;
  const int sz = 1 << len;
  const int mask = sz - 1;
  static int pos[sz + 1];

  vector<pair<uint64_t, int>> w(v.size());

  int n_blocks = 0;
  while (maks > 1) {
    n_blocks++;
    maks >>= len;
  }

  for (int block = 0; block < n_blocks; ++block) {
    memset(pos, 0, sizeof pos);

    for (auto &x : v)
      ++pos[((x.first >> (block * len)) & mask) + 1];

    for (int i = 0; i < sz; ++i)
      pos[i + 1] += pos[i];

    for (auto &x : v)
      w[pos[(x.first >> (block * len)) & mask]++] = x;

    v.swap(w);
  }
}

// Assembly:
subq $0xb8, %rsp
movq %rdi, 0xb0(%rsp)
movq %rsi, 0xa8(%rsp)
movl $0x9, 0xa4(%rsp)
movl $0x200, 0xa0(%rsp) # imm = 0x200
movl $0x1ff, 0x9c(%rsp) # imm = 0x1FF
movq 0xb0(%rsp), %rdi
callq 0x5450
movq %rax, 0x8(%rsp)
leaq 0x7f(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0x5470
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
leaq 0x80(%rsp), %rdi
callq 0x5480
jmp 0x25d2
leaq 0x7f(%rsp), %rdi
callq 0x5500
movl $0x0, 0x68(%rsp)
cmpq $0x1, 0xa8(%rsp)
jbe 0x262d
movl 0x68(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x68(%rsp)
movq 0xa8(%rsp), %rax
shrq $0x9, %rax
movq %rax, 0xa8(%rsp)
jmp 0x25e4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
leaq 0x7f(%rsp), %rdi
callq 0x5500
jmp 0x2838
movl $0x0, 0x64(%rsp)
movl 0x64(%rsp), %eax
cmpl 0x68(%rsp), %eax
jge 0x2823
leaq 0xfb46(%rip), %rdi      # 0x12190
xorl %esi, %esi
movl $0x804, %edx            # imm = 0x804
callq 0x20d0
movq 0xb0(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x58(%rsp), %rdi
callq 0x5510
movq %rax, 0x50(%rsp)
movq 0x58(%rsp), %rdi
callq 0x5540
movq %rax, 0x48(%rsp)
leaq 0x50(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x5570
testb $0x1, %al
jne 0x2696
jmp 0x26e6
leaq 0x50(%rsp), %rdi
callq 0x55b0
movq %rax, 0x40(%rsp)
movq 0x40(%rsp), %rax
movq (%rax), %rax
imull $0x9, 0x64(%rsp), %ecx
movl %ecx, %ecx
shrq %cl, %rax
movq %rax, %rcx
andq $0x1ff, %rcx            # imm = 0x1FF
leaq 0xfac8(%rip), %rax      # 0x12190
movl 0x4(%rax,%rcx,4), %edx
addl $0x1, %edx
leaq 0xfaba(%rip), %rax      # 0x12190
movl %edx, 0x4(%rax,%rcx,4)
leaq 0x50(%rsp), %rdi
callq 0x55c0
jmp 0x2681
movl $0x0, 0x3c(%rsp)
cmpl $0x200, 0x3c(%rsp)      # imm = 0x200
jge 0x2732
movslq 0x3c(%rsp), %rcx
leaq 0xfa8c(%rip), %rax      # 0x12190
movl (%rax,%rcx,4), %edx
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movslq %eax, %rcx
leaq 0xfa78(%rip), %rax      # 0x12190
addl (%rax,%rcx,4), %edx
leaq 0xfa6e(%rip), %rax      # 0x12190
movl %edx, (%rax,%rcx,4)
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x26ee
movq 0xb0(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rdi
callq 0x5510
movq %rax, 0x28(%rsp)
movq 0x30(%rsp), %rdi
callq 0x5540
movq %rax, 0x20(%rsp)
leaq 0x28(%rsp), %rdi
leaq 0x20(%rsp), %rsi
callq 0x5570
testb $0x1, %al
jne 0x2775
jmp 0x27fe
leaq 0x28(%rsp), %rdi
callq 0x55b0
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq %rax, (%rsp)
movq (%rax), %rax
movl 0x64(%rsp), %edx
movl %edx, %ecx
leal (%rcx,%rcx,8), %ecx
shrq %cl, %rax
andl $0x1ff, %eax            # imm = 0x1FF
movl %eax, %ecx
leaq 0xf9e6(%rip), %rax      # 0x12190
movslq (%rax,%rcx,4), %rsi
movl %esi, %edx
incl %edx
movl %edx, (%rax,%rcx,4)
leaq 0x80(%rsp), %rdi
callq 0x55e0
movq (%rsp), %rsi
movq %rax, %rdi
callq 0x5600
jmp 0x27d0
jmp 0x27d2
leaq 0x28(%rsp), %rdi
callq 0x55c0
jmp 0x275d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x70(%rsp)
movl %eax, 0x6c(%rsp)
leaq 0x80(%rsp), %rdi
callq 0x5690
jmp 0x2838
movq 0xb0(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x5630
movl 0x64(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x64(%rsp)
jmp 0x2635
leaq 0x80(%rsp), %rdi
callq 0x5690
addq $0xb8, %rsp
retq
movq 0x70(%rsp), %rdi
callq 0x2260
nopw %cs:(%rax,%rax)