// File: /workspace/github_cpp_makefile_star2_O2/ikatanic[P]lcskpp/lcskpp.cpp
// Function: lcskpp(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, int, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>*)
int lcskpp(const string& a, const string& b, int k,
          vector<pair<int, int>>* reconstruction) {
  int m = b.size();
  vector<pair<int, int>> matches;
  calc_matches(a, b, k, &matches);

  int n_matches = matches.size();
  vector<pair<int, int>> MinYPrefix(m + 1, {m+1, -1});
  MinYPrefix[0].first = -1;

  int r = 0;  // current lcsk++ length
  int log_r = 1;  // log(r+1) + 1

  vector<int> match_dp(matches.size());
  vector<int> recon(matches.size());

  int ptr = 0;
  int query_ptr = 0;
  int cont_ptr = 0;
  int last_idx = -1;

  // We process matches row by row (while loop).
  // When at row i, we also handle queries on MinYPrefix for matches
  // in row i+k-1 (query_ptr).
  // cont_ptr points to ptr's possible continuation (applicable only to k > 1).
  while (ptr < n_matches) {
    int i = matches[ptr].first;  // current row index
    int i_row_ptr = ptr;


    while (query_ptr < n_matches && matches[query_ptr].first < i+k) {
      int query_row_i = matches[query_ptr].first;

      // count matches in row query_row_i
      int query_row_end = query_ptr;
      while (query_row_end < n_matches &&
             matches[query_row_end].first == query_row_i) query_row_end++;
      int row_count = query_row_end - query_ptr;

      // decide between binary search for each match (Hunt and Szymanski) and
      // sweep through MinYPrefix (Kuo and Cross).
      if (row_count * log_r * 6 < r) {
        int last_l = 0;
        while (query_ptr < query_row_end) {
          int j = matches[query_ptr].second;

          if (MinYPrefix[last_l].first < j-k+1) {
            int lo = last_l+1, hi = r+1;
            while (lo < hi) {
              int mid = (lo + hi) / 2;
              if (MinYPrefix[mid].first < j - k + 1)
                lo = mid + 1;
              else
                hi = mid;
            }
            last_l = lo;
          }

          recon[query_ptr] = MinYPrefix[last_l-1].second;
          match_dp[query_ptr++] = last_l-1+k;
        }
      } else {
        int l = 0;
        while (query_ptr < query_row_end) {
          int j = matches[query_ptr].second;
          while (MinYPrefix[l].first < j-k+1) l++;
          recon[query_ptr] = MinYPrefix[l-1].second;
          match_dp[query_ptr++] = l-1+k;
        }
      }
    }

    if (k > 1) {
      while (cont_ptr < i_row_ptr && matches[cont_ptr].first < i-1) cont_ptr++;
    }

    // now the main loop through matches in row i, finishing off their
    // dp calculation and doing updates to MinYPrefix
    while (ptr < n_matches && matches[ptr].first == i) {
      int j = matches[ptr].second;
      int& ptr_dp = match_dp[ptr];

      // update MinYPrefix
      for (int s = ptr_dp; s > ptr_dp-k && MinYPrefix[s].first > j; --s) {
        MinYPrefix[s] = {j, ptr};
      }

      // Try continuation
      if (k > 1) {
        while (cont_ptr < i_row_ptr && matches[cont_ptr].second < j-1)
          cont_ptr++;
        if (cont_ptr < i_row_ptr && matches[cont_ptr].second == j-1 &&
            match_dp[cont_ptr] + 1 > ptr_dp) {
                ptr_dp = match_dp[cont_ptr] + 1;
                recon[ptr] = cont_ptr;
                MinYPrefix[ptr_dp] = min(MinYPrefix[ptr_dp], {j, ptr});
              }
      }

      if (ptr_dp > r) {
        r = ptr_dp;
        last_idx = ptr;
        while ((1 << log_r) < r+1) log_r++;
      }

      ptr++;
    }
  }

  if (reconstruction) {
    reconstruction->clear();

    int i = last_idx;
    while (i != -1) {
      assert(0 <= i && i < matches.size());

      if (recon[i] != -1 &&
          matches[recon[i]].first+1 == matches[i].first &&
          matches[recon[i]].second+1 == matches[i].second) {
        // continuation
        reconstruction->push_back({matches[i].first, matches[i].second});
      } else {
        // non-overlapping match
        assert(recon[i] == -1 ||
          (matches[recon[i]].first + k <= matches[i].first &&
           matches[recon[i]].second + k <= matches[i].second));
        for (int j = 0; j < k; ++j) {
          reconstruction->push_back({matches[i].first-j, matches[i].second-j});
        }
      }

      i = recon[i];
    }
    reverse(reconstruction->begin(), reconstruction->end());
  }

  return r;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movq %rcx, %r15
movl %edx, %r14d
movq 0x8(%rsi), %rbx
pxor %xmm0, %xmm0
leaq 0x20(%rsp), %rcx
movdqa %xmm0, (%rcx)
andq $0x0, 0x10(%rcx)
callq 0x26ed
movq 0x28(%rsp), %r12
subq 0x20(%rsp), %r12
incl %ebx
movslq %ebx, %rsi
leaq 0xb0(%rsp), %rdx
movl %esi, (%rdx)
orl $-0x1, 0x4(%rdx)
leaq 0x90(%rsp), %rdi
leaq 0x78(%rsp), %rcx
callq 0x3988
movq 0x90(%rsp), %rax
orl $-0x1, (%rax)
movq 0x28(%rsp), %rsi
subq 0x20(%rsp), %rsi
sarq $0x3, %rsi
leaq 0xb0(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x37ba
movq %r15, 0xa8(%rsp)
movq 0x28(%rsp), %rsi
subq 0x20(%rsp), %rsi
sarq $0x3, %rsi
leaq 0x78(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x37ba
movq %r12, %r10
shrq $0x3, %r10
movslq %r10d, %r11
pushq $0x1
popq %rbp
pushq $-0x1
popq %r9
xorl %r15d, %r15d
pushq $0x2
popq %r13
xorl %edi, %edi
xorl %r8d, %r8d
movq $0x0, 0x10(%rsp)
movq %r10, 0x60(%rsp)
movq %r11, 0x58(%rsp)
cmpl %r10d, %r15d
jge 0x34e6
movl %r9d, 0x1c(%rsp)
movslq %r15d, %rsi
movq 0x20(%rsp), %rcx
movl (%rcx,%rsi,8), %eax
movq %rax, 0x68(%rsp)
leal (%rax,%r14), %r12d
imull $0x6, %ebp, %eax
movl %eax, 0x4c(%rsp)
movq 0x10(%rsp), %rax
incl %eax
movl %eax, 0x54(%rsp)
movq %rdi, 0x40(%rsp)
movq %rsi, 0x70(%rsp)
movl %r12d, 0x48(%rsp)
cmpl %r10d, %r8d
jge 0x337c
movslq %r8d, %r9
movl (%rcx,%r9,8), %edx
cmpl %r12d, %edx
jge 0x337c
movq %r9, %rax
cmpq %r11, %rax
jge 0x328e
cmpl %edx, (%rcx,%rax,8)
jne 0x3291
incq %rax
jmp 0x327f
movl %r10d, %eax
movslq %eax, %r10
subl %r8d, %eax
imull 0x4c(%rsp), %eax
movq 0x90(%rsp), %r11
movq 0x78(%rsp), %rdi
movq 0xb0(%rsp), %rsi
cmpl 0x10(%rsp), %eax
jge 0x331b
xorl %r12d, %r12d
cmpq %r10, %r9
jge 0x335b
movl 0x4(%rcx,%r9,8), %r8d
movslq %r12d, %rax
subl %r14d, %r8d
cmpl %r8d, (%r11,%rax,8)
jle 0x32ee
movslq %r12d, %rax
movl -0x4(%r11,%rax,8), %edx
movl %edx, (%rdi,%r9,4)
addl %r14d, %eax
decl %eax
movl %eax, (%rsi,%r9,4)
incq %r9
jmp 0x32ba
incl %r12d
movl 0x54(%rsp), %eax
movl %eax, %ebx
cmpl %ebx, %r12d
jge 0x32d4
leal (%rbx,%r12), %eax
cltd
idivl %r13d
cltq
leal 0x1(%rax), %edx
cmpl %r8d, (%r11,%rax,8)
cmovgl %r12d, %edx
cmovlel %ebx, %eax
movl %edx, %r12d
movl %eax, %ebx
jmp 0x32f7
xorl %eax, %eax
cmpq %r10, %r9
jge 0x3360
movl 0x4(%rcx,%r9,8), %edx
subl %r14d, %edx
cltq
leal -0x2(%rax), %r8d
decq %rax
movq %rax, %rbx
incl %r8d
incq %rax
cmpl %edx, 0x8(%r11,%rbx,8)
jle 0x3333
movslq %r8d, %rdx
movl 0x4(%r11,%rdx,8), %r8d
movl %r8d, (%rdi,%r9,4)
addl %r14d, %edx
movl %edx, (%rsi,%r9,4)
incq %r9
jmp 0x331d
movl 0x48(%rsp), %r12d
movl %r9d, %r8d
movq 0x60(%rsp), %r10
movq 0x58(%rsp), %r11
movq 0x40(%rsp), %rdi
movq 0x70(%rsp), %rsi
jmp 0x3263
cmpl $0x2, %r14d
jl 0x33a7
movq 0x68(%rsp), %rax
decl %eax
movslq %edi, %rdi
cmpl %r15d, %edi
cmovgl %edi, %r15d
movl 0x1c(%rsp), %r9d
cmpq %rsi, %rdi
jge 0x33ae
cmpl %eax, (%rcx,%rdi,8)
jge 0x33b1
incq %rdi
jmp 0x3398
movl 0x1c(%rsp), %r9d
jmp 0x33b1
movl %r15d, %edi
movq %rsi, %r15
movl %r8d, 0x50(%rsp)
cmpq %r11, %r15
jge 0x34de
movq 0x20(%rsp), %rdx
movq 0x68(%rsp), %rax
cmpl %eax, (%rdx,%r15,8)
jne 0x3220
movq %rdi, %rbx
movl 0x4(%rdx,%r15,8), %ecx
movq 0xb0(%rsp), %r12
movl (%r12,%r15,4), %eax
movq 0x90(%rsp), %rsi
movslq %eax, %rdi
movl %eax, %r8d
subl %r14d, %r8d
movslq %r8d, %r8
cmpq %r8, %rdi
jle 0x3419
cmpl %ecx, (%rsi,%rdi,8)
jle 0x3419
movl %ecx, (%rsi,%rdi,8)
movl %r15d, 0x4(%rsi,%rdi,8)
decq %rdi
movl (%r12,%r15,4), %eax
jmp 0x33f5
cmpl $0x2, %r14d
jl 0x343d
leal -0x1(%rcx), %esi
movq %rbx, %rdi
movslq %edi, %rdi
movq 0x70(%rsp), %r8
cmpq %r8, %rdi
jge 0x3440
cmpl %esi, 0x4(%rdx,%rdi,8)
jge 0x346c
incq %rdi
jmp 0x342d
movq %rbx, %rdi
cmpl 0x10(%rsp), %eax
movl 0x50(%rsp), %r8d
jle 0x3464
pushq $0x1
popq %rsi
movl %esi, %edx
movl %ebp, %ecx
shll %cl, %edx
incl %ebp
cmpl %eax, %edx
jle 0x344e
decl %ebp
movl %r15d, %r9d
movq %rax, 0x10(%rsp)
incq %r15
jmp 0x33b9
jne 0x3440
movl (%r12,%rdi,4), %edx
cmpl %eax, %edx
jl 0x3440
incl %edx
movl %edx, (%r12,%r15,4)
movq 0x78(%rsp), %rax
movl %edi, (%rax,%r15,4)
movq %rdi, 0x40(%rsp)
movslq (%r12,%r15,4), %rdi
shlq $0x3, %rdi
addq 0x90(%rsp), %rdi
movl %ecx, 0x8(%rsp)
movl %r15d, 0xc(%rsp)
leaq 0x8(%rsp), %rsi
movl %r9d, %ebx
callq 0x39de
movq 0x40(%rsp), %rdi
movq 0x58(%rsp), %r11
movl %ebx, %r9d
movq 0x60(%rsp), %r10
movslq (%r12,%r15,4), %rcx
movq 0x90(%rsp), %rdx
movq (%rax), %rax
movq %rax, (%rdx,%rcx,8)
movl (%r12,%r15,4), %eax
jmp 0x3440
movl %r10d, %r15d
jmp 0x3220
movq 0xa8(%rsp), %r13
testq %r13, %r13
je 0x35ef
movq (%r13), %rax
cmpq %rax, 0x8(%r13)
je 0x3505
movq %rax, 0x8(%r13)
xorl %ebx, %ebx
testl %r14d, %r14d
cmovgl %r14d, %ebx
leaq 0x8(%rsp), %r12
cmpl $-0x1, %r9d
je 0x35e2
testl %r9d, %r9d
js 0x3634
movl %r9d, %r15d
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
jbe 0x3634
movq 0x78(%rsp), %rcx
movslq (%rcx,%r15,4), %rcx
cmpq $-0x1, %rcx
je 0x35af
movl (%rax,%rcx,8), %edx
leal 0x1(%rdx), %edi
movl (%rax,%r15,8), %esi
cmpl %esi, %edi
jne 0x3592
movl 0x4(%rax,%rcx,8), %r8d
incl %r8d
cmpl 0x4(%rax,%r15,8), %r8d
jne 0x3592
movl %edi, 0x8(%rsp)
movl 0x4(%rax,%r15,8), %eax
movl %eax, 0xc(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x3c8c
movq 0x78(%rsp), %rax
movl (%rax,%r15,4), %r9d
jmp 0x3513
addl %r14d, %edx
cmpl %esi, %edx
jg 0x3653
movl 0x4(%rax,%rcx,8), %ecx
addl %r14d, %ecx
cmpl 0x4(%rax,%r15,8), %ecx
jg 0x3653
xorl %ebp, %ebp
cmpl %ebp, %ebx
je 0x3587
movq 0x20(%rsp), %rax
movq (%rax,%r15,8), %xmm0
movd %ebp, %xmm1
pshufd $0x50, %xmm1, %xmm1     # xmm1 = xmm1[0,0,1,1]
psubd %xmm1, %xmm0
movq %xmm0, 0x8(%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x3c8c
incl %ebp
jmp 0x35b1
movq (%r13), %rdi
movq 0x8(%r13), %rsi
callq 0x3de7
leaq 0x78(%rsp), %rdi
callq 0x3bc8
leaq 0xb0(%rsp), %rdi
callq 0x3bc8
leaq 0x90(%rsp), %rdi
callq 0x4616
leaq 0x20(%rsp), %rdi
callq 0x4616
movq 0x10(%rsp), %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x19fd(%rip), %rdi      # 0x5038
leaq 0x1a13(%rip), %rsi      # 0x5055
leaq 0x1a17(%rip), %rcx      # 0x5060
movl $0x81, %edx
callq 0x20f0
leaq 0x1a50(%rip), %rdi      # 0x50aa
leaq 0x19f4(%rip), %rsi      # 0x5055
leaq 0x19f8(%rip), %rcx      # 0x5060
movl $0x8c, %edx
callq 0x20f0
jmp 0x3687
movq %rax, %rbx
jmp 0x3694
movq %rax, %rbx
jmp 0x36a1
jmp 0x3680
movq %rax, %rbx
jmp 0x36ae
jmp 0x3687
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x3bc8
leaq 0xb0(%rsp), %rdi
callq 0x3bc8
leaq 0x90(%rsp), %rdi
callq 0x4616
leaq 0x20(%rsp), %rdi
callq 0x4616
movq %rbx, %rdi
callq 0x21e0