Count cells in a grid from which maximum number of cells can be reached by K vertical or horizontal jumps

Given a matrix mat[][] of dimensions N*M and a positive integer K, the task is to find the number of cells in a grid from which maximum cells can be reached by K jumps in the vertical or horizontal direction.Examples:Input: N = 3, M = 3, K = 2Output: 4Explanation:The cells represented as X are the cells from which maximum cells (= 2) can be reached by K (= 2) jumps:X O XO O OX O XInput: N = 5, M = 5, K = 2Output: 9Approach: The given problem can be solved by counting the number of possible cells for the rows and columns separately based on the following observations:Consider any row, say i such that i K, then these cells are connected to some row X where X mx1) {            mx1 = cont1 = aux;        }                  else if (aux == mx1)            cont1 += aux;    }              int mx2 = -1;              int cont2 = 0;      for (int i = 0; i < s && i < m; ++i) {                  int aux = (m - (i + 1)) / s + 1;                  if (aux > mx2)            mx2 = cont2 = aux;                  else if (aux == mx2)            cont2 += aux;    }          return (long long)(cont1 * cont2);}  int main(){    int N = 5, M = 5, K = 2;    cout