// File: /workspace/github_cpp_makefile_star2_O1/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 0x2b94
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 0x2b8a
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 0x2b77
incq %rsi
movl %esi, %edi
cmpq %rdi, %rcx
ja 0x2b5a
movq 0x8(%rbx), %rax
movq 0x10(%rbx), %rcx
subq %rax, %rcx
je 0x2bea
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 0x2be0
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 0x2bcd
incq %rsi
movl %esi, %edi
cmpq %rdi, %rcx
ja 0x2bb0
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 0x2c10
movq %rax, %rsi
jmp 0x2c2d
movq %rax, %rdi
movl (%rdi), %r8d
movq %rdx, %rsi
cmpl (%rdx), %r8d
jl 0x2c21
movq %rdi, %rsi
addq $0x4, %rdx
movq %rsi, %rdi
cmpq %rcx, %rdx
jne 0x2c13
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rcx
cmpq %rcx, %rdi
sete %r8b
movq %rdi, %rdx
addq $0x4, %rdx
cmpq %rcx, %rdx
sete %r9b
orb %r8b, %r9b
je 0x2c56
movq %rdi, %r14
jmp 0x2c70
movl (%rdi), %r8d
movq %rdx, %r14
cmpl (%rdx), %r8d
jl 0x2c64
movq %rdi, %r14
addq $0x4, %rdx
movq %r14, %rdi
cmpq %rcx, %rdx
jne 0x2c56
subq %rax, %rsi
sarq $0x2, %rsi
movq 0x534a(%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 0x530b(%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 0x2d06
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2d1d
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 0x2d49
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2d49
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2d60
movq 0x38(%rsp), %rsi
subq %rdi, %rsi
callq 0x2180
movq %rbx, %rdi
callq 0x2230