// File: /workspace/github_cpp_makefile_star2_O3/Razakhel[P]RaZonogram/src/Grid.cpp
// Function: Grid::solve()
Grid& Grid::solve() { //TODO: implement solver
  Grid& solvedGrid = *this;
  std::vector<int> totalRowClues(rowClues.size());
  std::vector<int> totalColClues(colClues.size());
  std::vector<int>::iterator rowMax, colMax;

  // Calculates the cumulated amount of clues for each row
  for (unsigned int i = 0; i < rowClues.size(); ++i)
    for (unsigned int j = 0; j < rowClues[i].size(); ++j)
      totalRowClues[i] += rowClues[i][j];

  // Same for each column
  for (unsigned int i = 0; i < colClues.size(); ++i)
    for (unsigned int j = 0; j < colClues[i].size(); ++j)
      totalColClues[i] += colClues[i][j];

  rowMax = std::max_element(totalRowClues.begin(), totalRowClues.end());
  colMax = std::max_element(totalColClues.begin(), totalColClues.end());
  std::cout << std::distance(totalRowClues.begin(), rowMax) << std::endl;
  std::cout << std::distance(totalColClues.begin(), colMax) << std::endl;

  return solvedGrid;
}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x40, %rsp
movq %rdi, %rbx
movq 0x28(%rdi), %rsi
subq 0x20(%rdi), %rsi
sarq $0x3, %rsi
movabsq $-0x5555555555555555, %r14 # imm = 0xAAAAAAAAAAAAAAAB
imulq %r14, %rsi
leaq 0x28(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x3518
movq 0x10(%rbx), %rsi
subq 0x8(%rbx), %rsi
sarq $0x3, %rsi
imulq %r14, %rsi
leaq 0x10(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x3518
movq 0x20(%rbx), %rax
movq 0x28(%rbx), %rcx
subq %rax, %rcx
je 0x2b98
sarq $0x3, %rcx
imulq %r14, %rcx
movq 0x28(%rsp), %rdx
xorl %esi, %esi
leaq (%rsi,%rsi,2), %r8
movq (%rax,%r8,8), %rdi
movq 0x8(%rax,%r8,8), %r8
subq %rdi, %r8
je 0x2b8e
sarq $0x2, %r8
movl (%rdx,%rsi,4), %r9d
xorl %r10d, %r10d
addl (%rdi,%r10,4), %r9d
movl %r9d, (%rdx,%rsi,4)
incq %r10
movl %r10d, %r11d
cmpq %r11, %r8
ja 0x2b7b
incq %rsi
movl %esi, %edi
cmpq %rdi, %rcx
ja 0x2b5e
movq 0x8(%rbx), %rax
movq 0x10(%rbx), %rcx
subq %rax, %rcx
je 0x2bee
sarq $0x3, %rcx
imulq %r14, %rcx
movq 0x10(%rsp), %rdx
xorl %esi, %esi
leaq (%rsi,%rsi,2), %r8
movq (%rax,%r8,8), %rdi
movq 0x8(%rax,%r8,8), %r8
subq %rdi, %r8
je 0x2be4
sarq $0x2, %r8
movl (%rdx,%rsi,4), %r9d
xorl %r10d, %r10d
addl (%rdi,%r10,4), %r9d
movl %r9d, (%rdx,%rsi,4)
incq %r10
movl %r10d, %r11d
cmpq %r11, %r8
ja 0x2bd1
incq %rsi
movl %esi, %edi
cmpq %rdi, %rcx
ja 0x2bb4
movq 0x28(%rsp), %rax
movq 0x30(%rsp), %rcx
cmpq %rcx, %rax
sete %sil
leaq 0x4(%rax), %rdx
cmpq %rcx, %rdx
sete %dil
orb %sil, %dil
je 0x2c14
movq %rax, %rsi
jmp 0x2c30
movl (%rax), %edi
movq %rax, %rsi
movl (%rdx), %r8d
cmpl %r8d, %edi
cmovlel %r8d, %edi
cmovlq %rdx, %rsi
addq $0x4, %rdx
cmpq %rcx, %rdx
jne 0x2c19
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rcx
cmpq %rcx, %r14
sete %dil
movq %r14, %rdx
addq $0x4, %rdx
cmpq %rcx, %rdx
sete %r8b
orb %dil, %r8b
jne 0x2c6e
movl (%r14), %edi
movl (%rdx), %r8d
cmpl %r8d, %edi
cmovlel %r8d, %edi
cmovlq %rdx, %r14
addq $0x4, %rdx
cmpq %rcx, %rdx
jne 0x2c57
subq %rax, %rsi
sarq $0x2, %rsi
movq 0x534c(%rip), %rdi      # 0x7fc8
callq 0x2150
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r15, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20e0
subq 0x10(%rsp), %r14
sarq $0x2, %r14
movq 0x530d(%rip), %rdi      # 0x7fc8
movq %r14, %rsi
callq 0x2150
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x2160
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x20e0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2d04
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2d1b
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rax
addq $0x40, %rsp
popq %rbx
popq %r14
popq %r15
retq
movq %rax, %rbx
jmp 0x2d47
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2d47
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2d5e
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2230