// File: 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 %rbp
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
movq %rdi, -0x10(%rbp)
addq $0x20, %rdi
callq 0x3eb0
movq %rax, -0xe0(%rbp)
leaq -0x29(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0x3ee0
movq -0xe0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
leaq -0x28(%rbp), %rdi
callq 0x3f00
jmp 0x2e97
leaq -0x29(%rbp), %rdi
callq 0x3f70
movq -0xe8(%rbp), %rdi
addq $0x8, %rdi
callq 0x3eb0
movq %rax, -0xf8(%rbp)
leaq -0x59(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x3ee0
movq -0xf8(%rbp), %rsi
movq -0xf0(%rbp), %rdx
leaq -0x58(%rbp), %rdi
callq 0x3f00
jmp 0x2ee0
leaq -0x59(%rbp), %rdi
callq 0x3f70
leaq -0x68(%rbp), %rdi
callq 0x3f90
leaq -0x70(%rbp), %rdi
callq 0x3f90
movl $0x0, -0x74(%rbp)
movq -0xe8(%rbp), %rdi
movl -0x74(%rbp), %eax
movq %rax, -0x100(%rbp)
addq $0x20, %rdi
callq 0x3eb0
movq %rax, %rcx
movq -0x100(%rbp), %rax
cmpq %rcx, %rax
jae 0x3004
movl $0x0, -0x78(%rbp)
movq -0xe8(%rbp), %rdi
movl -0x78(%rbp), %eax
movq %rax, -0x108(%rbp)
addq $0x20, %rdi
movl -0x74(%rbp), %eax
movl %eax, %esi
callq 0x3dc0
movq %rax, %rdi
callq 0x3fb0
movq %rax, %rcx
movq -0x108(%rbp), %rax
cmpq %rcx, %rax
jae 0x2ff4
movq -0xe8(%rbp), %rdi
addq $0x20, %rdi
movl -0x74(%rbp), %eax
movl %eax, %esi
callq 0x3dc0
movq %rax, %rdi
movl -0x78(%rbp), %eax
movl %eax, %esi
callq 0x3fd0
movl (%rax), %eax
movl %eax, -0x10c(%rbp)
movl -0x74(%rbp), %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0x3fd0
movl -0x10c(%rbp), %ecx
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0x78(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x78(%rbp)
jmp 0x2f36
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x29(%rbp), %rdi
callq 0x3f70
jmp 0x32ae
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x59(%rbp), %rdi
callq 0x3f70
jmp 0x32a5
jmp 0x2ff6
movl -0x74(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x74(%rbp)
jmp 0x2f02
movl $0x0, -0x7c(%rbp)
movq -0xe8(%rbp), %rdi
movl -0x7c(%rbp), %eax
movq %rax, -0x118(%rbp)
addq $0x8, %rdi
callq 0x3eb0
movq %rax, %rcx
movq -0x118(%rbp), %rax
cmpq %rcx, %rax
jae 0x30d5
movl $0x0, -0x80(%rbp)
movq -0xe8(%rbp), %rdi
movl -0x80(%rbp), %eax
movq %rax, -0x120(%rbp)
addq $0x8, %rdi
movl -0x7c(%rbp), %eax
movl %eax, %esi
callq 0x3dc0
movq %rax, %rdi
callq 0x3fb0
movq %rax, %rcx
movq -0x120(%rbp), %rax
cmpq %rcx, %rax
jae 0x30c5
movq -0xe8(%rbp), %rdi
addq $0x8, %rdi
movl -0x7c(%rbp), %eax
movl %eax, %esi
callq 0x3dc0
movq %rax, %rdi
movl -0x80(%rbp), %eax
movl %eax, %esi
callq 0x3fd0
movl (%rax), %eax
movl %eax, -0x124(%rbp)
movl -0x7c(%rbp), %eax
movl %eax, %esi
leaq -0x58(%rbp), %rdi
callq 0x3fd0
movl -0x124(%rbp), %ecx
addl (%rax), %ecx
movl %ecx, (%rax)
movl -0x80(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x80(%rbp)
jmp 0x303f
jmp 0x30c7
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0x300b
leaq -0x28(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x4030
movq -0x138(%rbp), %rdi
movq %rax, -0x90(%rbp)
callq 0x4060
movq %rax, -0x98(%rbp)
movq -0x90(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x3ff0
movq %rax, -0x130(%rbp)
jmp 0x311b
movq -0x130(%rbp), %rax
movq %rax, -0x88(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x68(%rbp)
leaq -0x58(%rbp), %rdi
movq %rdi, -0x148(%rbp)
callq 0x4030
movq -0x148(%rbp), %rdi
movq %rax, -0xa8(%rbp)
callq 0x4060
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x3ff0
movq %rax, -0x140(%rbp)
jmp 0x317a
movq -0x140(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x70(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x4030
movq %rax, -0xb8(%rbp)
movq -0x68(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x4090
movq %rax, -0x150(%rbp)
jmp 0x31ca
movq -0x150(%rbp), %rsi
movq 0x10df0(%rip), %rdi     # 0x13fc8
callq 0x2320
movq %rax, -0x158(%rbp)
jmp 0x31e6
movq -0x158(%rbp), %rdi
movq 0x10dc4(%rip), %rsi     # 0x13fb8
callq 0x21c0
jmp 0x31fb
leaq -0x58(%rbp), %rdi
callq 0x4030
movq %rax, -0xc8(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0xc8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x4090
movq %rax, -0x160(%rbp)
jmp 0x3232
movq -0x160(%rbp), %rsi
movq 0x10d88(%rip), %rdi     # 0x13fc8
callq 0x2320
movq %rax, -0x168(%rbp)
jmp 0x324e
movq -0x168(%rbp), %rdi
movq 0x10d5c(%rip), %rsi     # 0x13fb8
callq 0x21c0
jmp 0x3263
movq -0x10(%rbp), %rax
movq %rax, -0x170(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x40d0
leaq -0x28(%rbp), %rdi
callq 0x40d0
movq -0x170(%rbp), %rax
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x38(%rbp)
movl %eax, -0x3c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x40d0
leaq -0x28(%rbp), %rdi
callq 0x40d0
movq -0x38(%rbp), %rdi
callq 0x22f0
nopw (%rax,%rax)