// File: /workspace/github_cpp_makefile_star2_O2/ruippeixotog[P]algo-lib/kuhn-munkres.cpp
// Function: kuhnMunkres(int)
int kuhnMunkres(int n) {
  for(int i = 0; i < n; i++) {
    mx[i] = my[i] = -1;
    lx[i] = ly[i] = 0;
  }
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < n; j++)
      ly[j] = max(ly[j], w[i][j]);
  }
  for(int i = 0; i < n; i++) {
    memset(s, 0, sizeof(s));
    memset(rem, 0x3f, sizeof(rem));

    int st;
    for(st = 0; st < n; st++) {
      if(mx[st] == -1) { kuhnAdd(st, n); break; }
    }
    while(mx[st] == -1) {
      int miny = -1;
      for(int y = 0; y < n; y++) {
        if(rem[y] != -INF && (miny == -1 || rem[miny] >= rem[y]))
          miny = y;
      }

      if(rem[miny]) {
        for(int x = 0; x < n; x++) if(s[x]) lx[x] -= rem[miny];
        for(int y = 0, d = rem[miny]; y < n; y++) {
          if(rem[y] == -INF) ly[y] += d;
          else rem[y] -= d;
        }
      }

      if(my[miny] == -1) {
        int cur = miny;
        while(remx[cur] != st) {
          int pmate = mx[remx[cur]];
          my[cur] = remx[cur]; mx[my[cur]] = cur;
          my[pmate] = -1; cur = pmate;
        }
        my[cur] = remx[cur]; mx[my[cur]] = cur;
      } else {
        kuhnAdd(my[miny], n); rem[miny] = -INF;
      }
    }
  }

  int ret = 0;
  for(int i = 0; i < n; i++)
    ret += w[i][mx[i]];
  return ret;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
xorl %eax, %eax
testl %edi, %edi
movl $0x0, %r13d
cmovgl %edi, %r13d
movl %edi, 0x4(%rsp)
movl %edi, %ebx
leaq (,%r13,4), %rbp
leaq 0x3d75cd(%rip), %rcx    # 0x3d87c0
leaq 0x3d6626(%rip), %rdx    # 0x3d7820
leaq 0x3d94ff(%rip), %r9     # 0x3da700
leaq 0x3d8558(%rip), %rsi    # 0x3d9760
cmpq %rax, %rbp
je 0x1224
orl $-0x1, (%rax,%rcx)
orl $-0x1, (%rax,%rdx)
andl $0x0, (%rax,%r9)
andl $0x0, (%rax,%rsi)
addq $0x4, %rax
jmp 0x1208
leaq (,%rbx,4), %rax
leaq 0x2e0d(%rip), %rcx      # 0x4040
xorl %edx, %edx
cmpq %r13, %rdx
je 0x1266
xorl %esi, %esi
cmpq %rsi, %rax
je 0x125a
movl (%rsi,%r9), %edi
movl (%rcx,%rsi), %r8d
cmpl %r8d, %edi
cmovgl %edi, %r8d
movl %r8d, (%rsi,%r9)
addq $0x4, %rsi
jmp 0x123c
incq %rdx
addq $0xfa0, %rcx            # imm = 0xFA0
jmp 0x1235
xorl %eax, %eax
leaq 0x3d36d1(%rip), %r14    # 0x3d4940
leaq 0x3d466a(%rip), %r15    # 0x3d58e0
movq %rbx, 0x10(%rsp)
cmpl %r13d, %eax
je 0x141b
movq %rax, 0x18(%rsp)
movl $0xfa0, %edx            # imm = 0xFA0
movq %r14, %rdi
xorl %esi, %esi
callq 0x1030
movl $0xfa0, %edx            # imm = 0xFA0
movq %r15, %rdi
pushq $0x3f
popq %rsi
callq 0x1030
leaq 0x3d6571(%rip), %r9     # 0x3d7820
leaq 0x3d750a(%rip), %r8     # 0x3d87c0
movq %r9, %rax
xorl %r12d, %r12d
cmpq %r12, %rbx
je 0x12cf
cmpl $-0x1, (%rax)
je 0x12d4
incq %r12
addq $0x4, %rax
jmp 0x12bc
movq %rbx, %r12
jmp 0x12f1
movl %r12d, %edi
movl 0x4(%rsp), %esi
callq 0x113c
leaq 0x3d6539(%rip), %r9     # 0x3d7820
leaq 0x3d74d2(%rip), %r8     # 0x3d87c0
movl %r12d, %ebx
movslq %ebx, %rax
movq %rax, 0x20(%rsp)
leaq 0x3d9400(%rip), %r10    # 0x3da700
leaq 0x3d5579(%rip), %r11    # 0x3d6880
movq %r12, 0x8(%rsp)
cmpl $-0x1, (%r9,%r12,4)
jne 0x140a
movq %r15, %rcx
xorl %edx, %edx
pushq $-0x1
popq %rax
leaq 0x3d843a(%rip), %rdi    # 0x3d9760
movslq %eax, %r12
cmpq %rdx, %r13
je 0x134e
movl (%rcx), %esi
cmpl $0xc4653600, %esi       # imm = 0xC4653600
je 0x1345
cmpl $-0x1, %eax
je 0x1343
cmpl %esi, (%r15,%r12,4)
jl 0x1345
movl %edx, %eax
incq %rdx
addq $0x4, %rcx
jmp 0x1326
movl (%r15,%r12,4), %ecx
testl %ecx, %ecx
je 0x1392
xorl %edx, %edx
cmpq %rdx, %rbp
je 0x136d
cmpl $0x0, (%rdx,%r14)
je 0x1367
subl %ecx, (%rdx,%rdi)
addq $0x4, %rdx
jmp 0x1358
xorl %edx, %edx
cmpq %rdx, %rbp
je 0x1392
movl (%rdx,%r15), %esi
cmpl $0xc4653600, %esi       # imm = 0xC4653600
jne 0x1386
addl %ecx, (%rdx,%r10)
jmp 0x138c
subl %ecx, %esi
movl %esi, (%rdx,%r15)
addq $0x4, %rdx
jmp 0x136f
movl (%r8,%r12,4), %edi
cmpl $-0x1, %edi
je 0x13d2
movl 0x4(%rsp), %esi
callq 0x113c
leaq 0x3d54d5(%rip), %r11    # 0x3d6880
leaq 0x3d934e(%rip), %r10    # 0x3da700
leaq 0x3d6467(%rip), %r9     # 0x3d7820
leaq 0x3d7400(%rip), %r8     # 0x3d87c0
movl $0xc4653600, (%r15,%r12,4) # imm = 0xC4653600
movq 0x8(%rsp), %r12
jmp 0x130c
movq 0x8(%rsp), %r12
movslq %eax, %rcx
movl (%r11,%rcx,4), %edx
cmpl %ebx, %edx
je 0x13f8
movslq %edx, %rsi
movslq (%r9,%rsi,4), %rax
movl %edx, (%r8,%rcx,4)
movl %ecx, (%r9,%rsi,4)
orl $-0x1, (%r8,%rax,4)
jmp 0x13d7
movl %ebx, (%r8,%rcx,4)
movq 0x20(%rsp), %rax
movl %ecx, (%r9,%rax,4)
jmp 0x130c
movq 0x18(%rsp), %rax
incl %eax
movq 0x10(%rsp), %rbx
jmp 0x127b
imulq $0xfa0, %r13, %rcx      # imm = 0xFA0
xorl %edx, %edx
leaq 0x3d63f5(%rip), %rsi    # 0x3d7820
leaq 0x2c0e(%rip), %rdi      # 0x4040
xorl %eax, %eax
cmpq %rdx, %rcx
je 0x1451
movslq (%rsi), %r8
leaq (%rdx,%r8,4), %r8
addl (%rdi,%r8), %eax
addq $0xfa0, %rdx            # imm = 0xFA0
addq $0x4, %rsi
jmp 0x1434
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq