// File: /workspace/github_cpp_makefile_star2_O1/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 $0x18, %rsp
movl %edi, %ebx
movl %edi, 0xc(%rsp)
testl %edi, %edi
jle 0x122b
leaq (,%rbx,4), %r14
leaq 0x3d75d8(%rip), %rdi    # 0x3d87c0
movl $0xff, %esi
movq %r14, %rdx
callq 0x1030
leaq 0x3d6624(%rip), %rdi    # 0x3d7820
movl $0xff, %esi
movq %r14, %rdx
callq 0x1030
leaq 0x3d94f0(%rip), %rdi    # 0x3da700
xorl %esi, %esi
movq %r14, %rdx
callq 0x1030
leaq 0x3d853f(%rip), %rdi    # 0x3d9760
xorl %esi, %esi
movq %r14, %rdx
callq 0x1030
leaq 0x2e0e(%rip), %rsi      # 0x4040
cmpl $0x0, 0xc(%rsp)
jle 0x1277
leaq (,%rbx,4), %rax
xorl %ecx, %ecx
leaq 0x3d94b6(%rip), %rdx    # 0x3da700
xorl %edi, %edi
movl (%rdi,%rdx), %r8d
movl (%rsi,%rdi), %r9d
cmpl %r9d, %r8d
cmovgl %r8d, %r9d
movl %r9d, (%rdi,%rdx)
addq $0x4, %rdi
cmpq %rdi, %rax
jne 0x124c
incq %rcx
addq $0xfa0, %rsi            # imm = 0xFA0
cmpq %rbx, %rcx
jne 0x124a
cmpl $0x0, 0xc(%rsp)
jle 0x1422
leaq (,%rbx,4), %r13
xorl %eax, %eax
leaq 0x3d36ad(%rip), %r14    # 0x3d4940
leaq 0x3d4646(%rip), %r15    # 0x3d58e0
movq %rax, 0x10(%rsp)
movl $0xfa0, %edx            # imm = 0xFA0
movq %r14, %rdi
xorl %esi, %esi
callq 0x1030
movl $0xfa0, %edx            # imm = 0xFA0
movq %r15, %rdi
movl $0x3f, %esi
callq 0x1030
leaq 0x3d6559(%rip), %r8     # 0x3d7820
movq %r8, %rax
xorl %r12d, %r12d
cmpl $-0x1, (%rax)
je 0x12e3
incq %r12
addq $0x4, %rax
cmpq %r12, %rbx
jne 0x12cd
movl %ebx, %r12d
jmp 0x12f6
movl %r12d, %edi
movl 0xc(%rsp), %esi
callq 0x113c
leaq 0x3d652a(%rip), %r8     # 0x3d7820
movl %r12d, %r12d
cmpl $-0x1, (%r8,%r12,4)
leaq 0x3d74bb(%rip), %r9     # 0x3d87c0
leaq 0x3d5574(%rip), %r10    # 0x3d6880
leaq 0x3d93ed(%rip), %r11    # 0x3da700
jne 0x1411
movl $0xffffffff, %eax       # imm = 0xFFFFFFFF
movq %r15, %rcx
xorl %edx, %edx
movl (%rcx), %esi
cmpl $0xc4653600, %esi       # imm = 0xC4653600
je 0x133d
cmpl $-0x1, %eax
je 0x133b
movslq %eax, %rdi
cmpl %esi, (%r15,%rdi,4)
jl 0x133d
movl %edx, %eax
incq %rdx
addq $0x4, %rcx
cmpq %rdx, %rbx
jne 0x1323
movslq %eax, %rbp
movl (%r15,%rbp,4), %ecx
testl %ecx, %ecx
je 0x1393
xorl %edx, %edx
leaq 0x3d8403(%rip), %rsi    # 0x3d9760
cmpl $0x0, (%rdx,%r14)
je 0x1367
subl %ecx, (%rdx,%rsi)
addq $0x4, %rdx
cmpq %rdx, %r13
jne 0x135d
xorl %edx, %edx
movl (%rdx,%r15), %esi
cmpl $0xc4653600, %esi       # imm = 0xC4653600
jne 0x1384
addl %ecx, (%rdx,%r11)
jmp 0x138a
subl %ecx, %esi
movl %esi, (%rdx,%r15)
addq $0x4, %rdx
cmpq %rdx, %r13
jne 0x1372
movl (%r9,%rbp,4), %edi
cmpl $-0x1, %edi
je 0x13c9
movl %ebx, %esi
callq 0x113c
leaq 0x3d9356(%rip), %r11    # 0x3da700
leaq 0x3d54cf(%rip), %r10    # 0x3d6880
leaq 0x3d7408(%rip), %r9     # 0x3d87c0
leaq 0x3d6461(%rip), %r8     # 0x3d7820
movl $0xc4653600, (%r15,%rbp,4) # imm = 0xC4653600
jmp 0x1406
movl (%r10,%rbp,4), %ecx
cmpl %r12d, %ecx
jne 0x13d6
movl %eax, %edx
jmp 0x13fb
movslq %ecx, %rcx
movl (%r8,%rcx,4), %edx
movl %ecx, (%r9,%rbp,4)
movl %eax, (%r8,%rcx,4)
movslq %edx, %rbp
movl $0xffffffff, (%r9,%rbp,4) # imm = 0xFFFFFFFF
movl (%r10,%rbp,4), %ecx
movl %edx, %eax
cmpl %r12d, %ecx
jne 0x13d6
movl %ecx, (%r9,%rbp,4)
movslq %ecx, %rax
movl %edx, (%r8,%rax,4)
cmpl $-0x1, (%r8,%r12,4)
je 0x1319
movq 0x10(%rsp), %rax
incl %eax
cmpl 0xc(%rsp), %eax
jne 0x129a
cmpl $0x0, 0xc(%rsp)
jle 0x145f
imulq $0xfa0, %rbx, %rcx      # imm = 0xFA0
xorl %edx, %edx
leaq 0x3d63e7(%rip), %rsi    # 0x3d7820
xorl %eax, %eax
leaq 0x2bfe(%rip), %r8       # 0x4040
movslq (%rsi), %rdi
leaq (%rdx,%rdi,4), %rdi
addl (%r8,%rdi), %eax
addq $0x4, %rsi
addq $0xfa0, %rdx            # imm = 0xFA0
cmpq %rdx, %rcx
jne 0x1442
jmp 0x1461
xorl %eax, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq