// File: 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:
subq $0x48, %rsp
movl %edi, 0x44(%rsp)
movl $0x0, 0x40(%rsp)
movl 0x40(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x12d3
movslq 0x40(%rsp), %rcx
leaq 0x3d753a(%rip), %rax    # 0x3d87c0
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movslq 0x40(%rsp), %rcx
leaq 0x3d6587(%rip), %rax    # 0x3d7820
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movslq 0x40(%rsp), %rcx
leaq 0x3d9454(%rip), %rax    # 0x3da700
movl $0x0, (%rax,%rcx,4)
movslq 0x40(%rsp), %rcx
leaq 0x3d84a1(%rip), %rax    # 0x3d9760
movl $0x0, (%rax,%rcx,4)
movl 0x40(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x40(%rsp)
jmp 0x1270
movl $0x0, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x1361
movl $0x0, 0x38(%rsp)
movl 0x38(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x134f
movslq 0x38(%rsp), %rax
leaq 0x3d93fd(%rip), %rdi    # 0x3da700
shlq $0x2, %rax
addq %rax, %rdi
movslq 0x3c(%rsp), %rax
leaq 0x2d2a(%rip), %rsi      # 0x4040
imulq $0xfa0, %rax, %rax      # imm = 0xFA0
addq %rax, %rsi
movslq 0x38(%rsp), %rax
shlq $0x2, %rax
addq %rax, %rsi
callq 0x1720
movl (%rax), %edx
movslq 0x38(%rsp), %rcx
leaq 0x3d93c1(%rip), %rax    # 0x3da700
movl %edx, (%rax,%rcx,4)
movl 0x38(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x38(%rsp)
jmp 0x12ed
jmp 0x1351
movl 0x3c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x3c(%rsp)
jmp 0x12db
movl $0x0, 0x34(%rsp)
movl 0x34(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x16aa
leaq 0x3d35c2(%rip), %rdi    # 0x3d4940
xorl %esi, %esi
movl $0xfa0, %edx            # imm = 0xFA0
callq 0x1030
leaq 0x3d454f(%rip), %rdi    # 0x3d58e0
movl $0x3f, %esi
movl $0xfa0, %edx            # imm = 0xFA0
callq 0x1030
movl $0x0, 0x30(%rsp)
movl 0x30(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x13e2
movslq 0x30(%rsp), %rcx
leaq 0x3d6462(%rip), %rax    # 0x3d7820
cmpl $-0x1, (%rax,%rcx,4)
jne 0x13d3
movl 0x30(%rsp), %edi
movl 0x44(%rsp), %esi
callq 0x1140
jmp 0x13e2
jmp 0x13d5
movl 0x30(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x30(%rsp)
jmp 0x13a8
jmp 0x13e4
movslq 0x30(%rsp), %rcx
leaq 0x3d6430(%rip), %rax    # 0x3d7820
cmpl $-0x1, (%rax,%rcx,4)
jne 0x1698
movl $0xffffffff, 0x2c(%rsp) # imm = 0xFFFFFFFF
movl $0x0, 0x28(%rsp)
movl 0x28(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x1475
movslq 0x28(%rsp), %rcx
leaq 0x3d44c0(%rip), %rax    # 0x3d58e0
cvtsi2sdl (%rax,%rcx,4), %xmm0
movsd 0xbdb(%rip), %xmm1      # 0x2008
ucomisd %xmm1, %xmm0
jne 0x1437
jp 0x1437
jmp 0x1466
cmpl $-0x1, 0x2c(%rsp)
je 0x145e
movslq 0x2c(%rsp), %rcx
leaq 0x3d4496(%rip), %rax    # 0x3d58e0
movl (%rax,%rcx,4), %eax
movslq 0x28(%rsp), %rdx
leaq 0x3d4487(%rip), %rcx    # 0x3d58e0
cmpl (%rcx,%rdx,4), %eax
jl 0x1466
movl 0x28(%rsp), %eax
movl %eax, 0x2c(%rsp)
jmp 0x1468
movl 0x28(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x28(%rsp)
jmp 0x140a
movslq 0x2c(%rsp), %rcx
leaq 0x3d445f(%rip), %rax    # 0x3d58e0
cmpl $0x0, (%rax,%rcx,4)
je 0x157d
movl $0x0, 0x24(%rsp)
movl 0x24(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x14e8
movslq 0x24(%rsp), %rcx
leaq 0x3d3497(%rip), %rax    # 0x3d4940
cmpl $0x0, (%rax,%rcx,4)
je 0x14d9
movslq 0x2c(%rsp), %rcx
leaq 0x3d4425(%rip), %rax    # 0x3d58e0
movl (%rax,%rcx,4), %eax
movslq 0x24(%rsp), %rcx
leaq 0x3d8296(%rip), %rdx    # 0x3d9760
movl (%rdx,%rcx,4), %edx
subl %eax, %edx
leaq 0x3d828a(%rip), %rax    # 0x3d9760
movl %edx, (%rax,%rcx,4)
jmp 0x14db
movl 0x24(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x24(%rsp)
jmp 0x1493
movl $0x0, 0x20(%rsp)
movslq 0x2c(%rsp), %rcx
leaq 0x3d43e4(%rip), %rax    # 0x3d58e0
movl (%rax,%rcx,4), %eax
movl %eax, 0x1c(%rsp)
movl 0x20(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x157b
movslq 0x20(%rsp), %rcx
leaq 0x3d43c7(%rip), %rax    # 0x3d58e0
cvtsi2sdl (%rax,%rcx,4), %xmm0
movsd 0xae2(%rip), %xmm1      # 0x2008
ucomisd %xmm1, %xmm0
jne 0x154d
jp 0x154d
movl 0x1c(%rsp), %edx
movslq 0x20(%rsp), %rcx
leaq 0x3d91c2(%rip), %rax    # 0x3da700
addl (%rax,%rcx,4), %edx
leaq 0x3d91b8(%rip), %rax    # 0x3da700
movl %edx, (%rax,%rcx,4)
jmp 0x156c
movl 0x1c(%rsp), %eax
movslq 0x20(%rsp), %rcx
leaq 0x3d4383(%rip), %rdx    # 0x3d58e0
movl (%rdx,%rcx,4), %edx
subl %eax, %edx
leaq 0x3d4377(%rip), %rax    # 0x3d58e0
movl %edx, (%rax,%rcx,4)
jmp 0x156e
movl 0x20(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x20(%rsp)
jmp 0x1503
jmp 0x157d
movslq 0x2c(%rsp), %rcx
leaq 0x3d7237(%rip), %rax    # 0x3d87c0
cmpl $-0x1, (%rax,%rcx,4)
jne 0x1668
movl 0x2c(%rsp), %eax
movl %eax, 0x18(%rsp)
movslq 0x18(%rsp), %rcx
leaq 0x3d52d9(%rip), %rax    # 0x3d6880
movl (%rax,%rcx,4), %eax
cmpl 0x30(%rsp), %eax
je 0x162a
movslq 0x18(%rsp), %rcx
leaq 0x3d52c4(%rip), %rax    # 0x3d6880
movslq (%rax,%rcx,4), %rcx
leaq 0x3d6259(%rip), %rax    # 0x3d7820
movl (%rax,%rcx,4), %eax
movl %eax, 0x14(%rsp)
movslq 0x18(%rsp), %rcx
leaq 0x3d52a6(%rip), %rax    # 0x3d6880
movl (%rax,%rcx,4), %edx
movslq 0x18(%rsp), %rcx
leaq 0x3d71d7(%rip), %rax    # 0x3d87c0
movl %edx, (%rax,%rcx,4)
movl 0x18(%rsp), %edx
movslq 0x18(%rsp), %rcx
leaq 0x3d71c4(%rip), %rax    # 0x3d87c0
movslq (%rax,%rcx,4), %rcx
leaq 0x3d6219(%rip), %rax    # 0x3d7820
movl %edx, (%rax,%rcx,4)
movslq 0x14(%rsp), %rcx
leaq 0x3d71aa(%rip), %rax    # 0x3d87c0
movl $0xffffffff, (%rax,%rcx,4) # imm = 0xFFFFFFFF
movl 0x14(%rsp), %eax
movl %eax, 0x18(%rsp)
jmp 0x159b
movslq 0x18(%rsp), %rcx
leaq 0x3d524a(%rip), %rax    # 0x3d6880
movl (%rax,%rcx,4), %edx
movslq 0x18(%rsp), %rcx
leaq 0x3d717b(%rip), %rax    # 0x3d87c0
movl %edx, (%rax,%rcx,4)
movl 0x18(%rsp), %edx
movslq 0x18(%rsp), %rcx
leaq 0x3d7168(%rip), %rax    # 0x3d87c0
movslq (%rax,%rcx,4), %rcx
leaq 0x3d61bd(%rip), %rax    # 0x3d7820
movl %edx, (%rax,%rcx,4)
jmp 0x1693
movslq 0x2c(%rsp), %rcx
leaq 0x3d714c(%rip), %rax    # 0x3d87c0
movl (%rax,%rcx,4), %edi
movl 0x44(%rsp), %esi
callq 0x1140
movslq 0x2c(%rsp), %rcx
leaq 0x3d4254(%rip), %rax    # 0x3d58e0
movl $0xc4653600, (%rax,%rcx,4) # imm = 0xC4653600
jmp 0x13e4
jmp 0x169a
movl 0x34(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x34(%rsp)
jmp 0x1369
movl $0x0, 0x10(%rsp)
movl $0x0, 0xc(%rsp)
movl 0xc(%rsp), %eax
cmpl 0x44(%rsp), %eax
jge 0x1702
movslq 0xc(%rsp), %rcx
leaq 0x2970(%rip), %rax      # 0x4040
imulq $0xfa0, %rcx, %rcx      # imm = 0xFA0
addq %rcx, %rax
movslq 0xc(%rsp), %rdx
leaq 0x3d613a(%rip), %rcx    # 0x3d7820
movslq (%rcx,%rdx,4), %rcx
movl (%rax,%rcx,4), %eax
addl 0x10(%rsp), %eax
movl %eax, 0x10(%rsp)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0x16ba
movl 0x10(%rsp), %eax
addq $0x48, %rsp
retq
nopl (%rax,%rax)