Banana-Leopard/TASTY huggingface dataset:
// C++ program to find sum of
// middle row and column in matrix
#include <iostream>
using namespace std;
const int MAX = 100;
 
void middlesum(int mat[][MAX], int n)
{
 
    int  row_sum = 0, col_sum = 0;
     
    //loop for sum of row
    for (int i = 0; i < n; i++)
        row_sum += mat[n / 2][i];
     
    cout << "Sum of middle row = "
                    << row_sum<<endl;
     
    //loop for sum of column
    for (int i = 0; i < n; i++)
        col_sum += mat[i][n / 2];
     
    cout << "Sum of middle column = "
                            << col_sum;
}
 
// Driver function
int main()
{
    int mat[][MAX] = {{2, 5, 7},
                     {3, 7, 2},
                     {5, 6, 9}};
     
    middlesum(mat, 3);
    
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ program showing time difference
// in row major and column major access
#include <stdio.h>
#include <time.h>
 
// taking MAX 10000 so that time difference
// can be shown
#define MAX 10000
 
int arr[MAX][MAX] = { 0 };
 
void rowMajor()
{
 
    int i, j;
 
    // accessing element row wise
    for (i = 0; i < MAX; i++) {
        for (j = 0; j < MAX; j++) {
            arr[i][j]++;
        }
    }
}
 
void colMajor()
{
 
    int i, j;
 
    // accessing element column wise
    for (i = 0; i < MAX; i++) {
        for (j = 0; j < MAX; j++) {
            arr[j][i]++;
        }
    }
}
 
// driver code
int main()
{
    int i, j;
 
    // Time taken by row major order
    clock_t t = clock();
    rowMajor();
    t = clock() - t;
    printf("Row major access time :%f s\n",
           t / (float)CLOCKS_PER_SEC);
 
    // Time taken by column major order
    t = clock();
    colMajor();
    t = clock() - t;
    printf("Column major access time :%f s\n",
           t / (float)CLOCKS_PER_SEC);
    return 0;
}

Time complexity: quadratic
Space complexity: quadratic
// CPP program to rotate a matrix right by k times
#include <iostream>
 
// size of matrix
#define M 3
#define N 3
 
using namespace std;
 
// function to rotate matrix by k times
void rotateMatrix(int matrix[][M], int k) {
  // temporary array of size M
  int temp[M];
 
  // within the size of matrix
  k = k % M;
 
  for (int i = 0; i < N; i++) {
 
    // copy first M-k elements to temporary array
    for (int t = 0; t < M - k; t++)
      temp[t] = matrix[i][t];
 
    // copy the elements from k to end to starting
    for (int j = M - k; j < M; j++)
      matrix[i][j - M + k] = matrix[i][j];
 
    // copy elements from temporary array to end
    for (int j = k; j < M; j++)
      matrix[i][j] = temp[j - k];
  }
}
 
// function to display the matrix
void displayMatrix(int matrix[][M]) {
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < M; j++)
      cout << matrix[i][j] << " ";
    cout << endl;
  }
}
 
// Driver's code
int main() {
  int matrix[N][M] = {{12, 23, 34},
                     {45, 56, 67},
                     {78, 89, 91}};
  int k = 2;
 
  // rotate matrix by k
  rotateMatrix(matrix, k);
 
  // display rotated matrix
  displayMatrix(matrix);
 
  return 0;
}

Time complexity: quadratic
Space complexity: linear
// Program to check given matrix
// is idempotent matrix or not.
#include<bits/stdc++.h>
#define N 3
using namespace std;
 
// Function for matrix multiplication.
void multiply(int mat[][N], int res[][N])
{
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            res[i][j] = 0;
            for (int k = 0; k < N; k++)
                res[i][j] += mat[i][k] * mat[k][j];
        }
    }
}
 
// Function to check idempotent
// property of matrix.
bool checkIdempotent(int mat[][N])
{  
    // Calculate multiplication of matrix
    // with itself and store it into res.
    int res[N][N];
    multiply(mat, res);
 
    for (int i = 0; i < N; i++)   
        for (int j = 0; j < N; j++)       
            if (mat[i][j] != res[i][j])
                return false;
    return true;
}
 
// Driver function.
int main()
{
    int mat[N][N] = {{2, -2, -4},
                    {-1, 3, 4},
                    {1, -2, -3}};
     
    // checkIdempotent function call.
    if (checkIdempotent(mat))
        cout << "Idempotent Matrix";
    else
        cout << "Not Idempotent Matrix.";
    return 0;
}

Time complexity: cubic
Space complexity: quadratic
// Program to implement involutory matrix.
#include <bits/stdc++.h>
#define N 3
using namespace std;
 
// Function for matrix multiplication.
void multiply(int mat[][N], int res[][N])
{
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            res[i][j] = 0;
            for (int k = 0; k < N; k++)
                res[i][j] += mat[i][k] * mat[k][j];
        }
    }
}
 
// Function to check involutory matrix.
bool InvolutoryMatrix(int mat[N][N])
{
    int res[N][N];
 
    // multiply function call.
    multiply(mat, res);
 
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            if (i == j && res[i][j] != 1)
                return false;
            if (i != j && res[i][j] != 0)
                return false;
        }
    }
    return true;
}
 
// Driver function.
int main()
{
    int mat[N][N] = { { 1, 0, 0 },
                      { 0, -1, 0 },
                      { 0, 0, -1 } };
 
    // Function call. If function return
    // true then if part will execute otherwise
    // else part will execute.
    if (InvolutoryMatrix(mat))
        cout << "Involutory Matrix";
    else
        cout << "Not Involutory Matrix";
 
    return 0;
}

Time complexity: cubic
Space complexity: quadratic
// C++ code to swap the element of first
// and last row and display the result
#include <iostream>
using namespace std;
 
#define n 4
 
void interchangeFirstLast(int m[][n])
{
    int rows = n;
 
    // swapping of element between first
    // and last rows
    for (int i = 0; i < n; i++) {
        int t = m[0][i];
        m[0][i] = m[rows - 1][i];
        m[rows - 1][i] = t;
    }
}
 
// Driver code
int main()
{
    // input in the array
    int m[n][n] = { { 8, 9, 7, 6 },
                    { 4, 7, 6, 5 },
                    { 3, 2, 1, 8 },
                    { 9, 9, 7, 7 } };
 
    // Function call
    interchangeFirstLast(m);
 
    // printing the interchanged matrix
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++)
            cout << m[i][j] << " ";
        cout << endl;
    }
}
 
// This code is contributed by Anant Agarwal.

Time complexity: linear
Space complexity: constant
/* C++ Program to print matrix in Zig-zag pattern*/
#include <iostream>
using namespace std;
#define C 3
 
// Utility function to print matrix
// in zig-zag form
void zigZagMatrix(int arr[][C], int n, int m)
{
    int row = 0, col = 0;
 
    // Boolean variable that will true if we
    // need to increment 'row' value otherwise
    // false- if increment 'col' value
    bool row_inc = 0;
 
    // Print matrix of lower half zig-zag pattern
    int mn = min(m, n);
    for (int len = 1; len <= mn; ++len) {
        for (int i = 0; i < len; ++i) {
            cout << arr[row][col] << " ";
 
            if (i + 1 == len)
                break;
            // If row_increment value is true
            // increment row and decrement col
            // else decrement row and increment
            // col
            if (row_inc)
                ++row, --col;
            else
                --row, ++col;
        }
 
        if (len == mn)
            break;
 
        // Update row or col value according
        // to the last increment
        if (row_inc)
            ++row, row_inc = false;
        else
            ++col, row_inc = true;
    }
 
    // Update the indexes of row and col variable
    if (row == 0) {
        if (col == m - 1)
            ++row;
        else
            ++col;
        row_inc = 1;
    }
    else {
        if (row == n - 1)
            ++col;
        else
            ++row;
        row_inc = 0;
    }
 
    // Print the next half zig-zag pattern
    int MAX = max(m, n) - 1;
    for (int len, diag = MAX; diag > 0; --diag) {
 
        if (diag > mn)
            len = mn;
        else
            len = diag;
 
        for (int i = 0; i < len; ++i) {
            cout << arr[row][col] << " ";
 
            if (i + 1 == len)
                break;
 
            // Update row or col value according
            // to the last increment
            if (row_inc)
                ++row, --col;
            else
                ++col, --row;
        }
 
        // Update the indexes of row and col variable
        if (row == 0 || col == m - 1) {
            if (col == m - 1)
                ++row;
            else
                ++col;
 
            row_inc = true;
        }
 
        else if (col == 0 || row == n - 1) {
            if (row == n - 1)
                ++col;
            else
                ++row;
 
            row_inc = false;
        }
    }
}
 
// Driver code
int main()
{
    int matrix[][3] = { { 1, 2, 3 },
                        { 4, 5, 6 },
                        { 7, 8, 9 } };
    zigZagMatrix(matrix, 3, 3);
 
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ code to
// sort 2D matrix row-wise
#include<bits/stdc++.h>
using namespace std;
 
void sortRowWise(int m[][4],
                 int r, int c)
{
  // loop for rows of matrix
  for (int i = 0; i < r; i++)
  {
    // loop for column of matrix
    for (int j = 0; j < c; j++)
    {
      // loop for comparison and swapping
      for (int k = 0; k < c - j - 1; k++)
      {
        if (m[i][k] > m[i][k + 1])
        {
          // swapping of elements
          swap(m[i][k], m[i][k + 1]);
        }
      }
    }
  }
 
  // printing the sorted matrix
  for (int i = 0; i < r; i++)
  {
    for (int j = 0; j < c; j++)
      cout << m[i][j] << " ";
    cout << endl;
  }
}
 
// Driver code
int main()
{
  int m[][4] = {{9, 8, 7, 1},
                {7, 3, 0, 2},
                {9, 5, 3, 2},
                {6, 3, 1, 2}};
  int c = sizeof(m[0]) / sizeof(m[0][0]);
  int r = sizeof(m) / sizeof(m[0]);
  sortRowWise(m, r, c);
  return 0;
}
 
// This code is contributed by Rutvik_56

Time complexity: quadratic
Space complexity: constant
// C++ code to sort 2D
// matrix row-wise
#include <bits/stdc++.h>
using namespace std;
#define M 4
#define N 4
 
int sortRowWise(int m[M][N])
{
  // One by one sort
  // individual rows.
  for (int i = 0; i < M; i++)
    sort(m[i], m[i] + N);
 
  // Printing the sorted matrix
  for (int i = 0; i < M; i++)
  {
    for (int j = 0; j < N; j++)
      cout << (m[i][j]) << " ";
    cout << endl;
  }
}
 
// Driver code
int main()
{
  int m[M][N] = {{9, 8, 7, 1},
                 {7, 3, 0, 2},
                 {9, 5, 3, 2},
                 {6, 3, 1, 2}};
  sortRowWise(m);
}
 
// This code is contributed by gauravrajput1

Time complexity: quadratic
Space complexity: constant
// C++ code to check Markov Matrix
#include <iostream>
using namespace std;
 
#define n 3
 
bool checkMarkov(double m[][n])
{
    // outer loop to access rows
    // and inner to access columns
    for (int i = 0; i <n; i++) {
 
        // Find sum of current row
        double sum = 0;
        for (int j = 0; j < n; j++)
            sum = sum + m[i][j];
 
        if (sum != 1)
        return false;
    }
 
    return true;
}
 
// Driver Code
int main()
{
    // Matrix to check
    double m[3][3] = { { 0, 0, 1 },
                    { 0.5, 0, 0.5 },
                    { 1, 0, 0 } };
 
    // calls the function check()
    if (checkMarkov(m))
        cout << " yes ";
    else
        cout << " no ";
}
 
// This code is contributed by Anant Agarwal.

Time complexity: quadratic
Space complexity: constant
// Program to check matrix is diagonal matrix or not.
 
#include <bits/stdc++.h>
#define N 4
using namespace std;
 
// Function to check matrix
// is diagonal matrix or not.
bool isDiagonalMatrix(int mat[N][N])
{
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
 
            // condition to check other elements
            // except main diagonal are zero or not.
            if ((i != j) && (mat[i][j] != 0))
                return false;
    return true;
}
 
// Driver function
int main()
{
    int mat[N][N] = { { 4, 0, 0, 0 },
                      { 0, 7, 0, 0 },
                      { 0, 0, 5, 0 },
                      { 0, 0, 0, 1 } };
 
    if (isDiagonalMatrix(mat))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// Program to check matrix is scalar matrix or not.
#include <bits/stdc++.h>
#define N 4
using namespace std;
 
// Function to check matrix is scalar matrix or not.
bool isScalarMatrix(int mat[N][N])
{
    // Check all elements except main diagonal are
    // zero or not.
    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
            if ((i != j) && (mat[i][j] != 0))
                return false;
 
    // Check all diagonal elements are same or not.
    for (int i = 0; i < N - 1; i++)
        if (mat[i][i] != mat[i + 1][i + 1])
            return false;
    return true;
}
 
// Driver function
int main()
{
    int mat[N][N] = { { 2, 0, 0, 0 },
                      { 0, 2, 0, 0 },
                      { 0, 0, 2, 0 },
                      { 0, 0, 0, 2 } };
    // Function call
    if (isScalarMatrix(mat))
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ implementation to sort the matrix row-wise
// and column-wise
#include <bits/stdc++.h>
 
using namespace std;
 
#define MAX_SIZE 10
 
// function to sort each row of the matrix
void sortByRow(int mat[MAX_SIZE][MAX_SIZE], int n)
{
    for (int i = 0; i < n; i++)
 
        // sorting row number 'i'
        sort(mat[i], mat[i] + n);
}
 
// function to find transpose of the matrix
void transpose(int mat[MAX_SIZE][MAX_SIZE], int n)
{
    for (int i = 0; i < n; i++)
        for (int j = i + 1; j < n; j++)
 
            // swapping element at index (i, j)
            // by element at index (j, i)
            swap(mat[i][j], mat[j][i]);
}
 
// function to sort the matrix row-wise
// and column-wise
void sortMatRowAndColWise(int mat[MAX_SIZE][MAX_SIZE],
                                               int n)
{
    // sort rows of mat[][]
    sortByRow(mat, n);
 
    // get transpose of mat[][]
    transpose(mat, n);
 
    // again sort rows of mat[][]
    sortByRow(mat, n);
 
    // again get transpose of mat[][]
    transpose(mat, n);
}
 
// function to print the matrix
void printMat(int mat[MAX_SIZE][MAX_SIZE], int n)
{
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++)
            cout << mat[i][j] << " ";
        cout << endl;
    }
}
 
// Driver program to test above
int main()
{
    int mat[MAX_SIZE][MAX_SIZE] = { { 4, 1, 3 },
                            { 9, 6, 8 },
                            { 5, 2, 7 } };
    int n = 3;
 
    cout << "Original Matrix:\n";
    printMat(mat, n);
 
    sortMatRowAndColWise(mat, n);
 
    cout << "\nMatrix After Sorting:\n";
    printMat(mat, n);
 
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ Program to print Magic square
// of Doubly even order
#include<iostream>
using namespace std;
 
// Function for calculating Magic square
void doublyEven( int n )
{
    int arr[n][n], i, j;
 
    // filling matrix with its count value
    // starting from 1;
    for ( i = 0; i < n; i++)
        for ( j = 0; j < n; j++)
            arr[i][j] = (n*i) + j + 1;
     
    // change value of Array elements
    // at fix location as per rule
    // (n*n+1)-arr[i][j]
    // Top Left corner of Matrix
    // (order (n/4)*(n/4))
    for ( i = 0; i < n/4; i++)
        for ( j = 0; j < n/4; j++)
            arr[i][j] = (n*n + 1) - arr[i][j];
     
    // Top Right corner of Matrix
    // (order (n/4)*(n/4))
    for ( i = 0; i < n/4; i++)
        for ( j = 3 * (n/4); j < n; j++)
            arr[i][j] = (n*n + 1) - arr[i][j];
     
    // Bottom Left corner of Matrix
    // (order (n/4)*(n/4))
    for ( i = 3 * n/4; i < n; i++)
        for ( j = 0; j < n/4; j++)
            arr[i][j] = (n*n+1) - arr[i][j];
     
    // Bottom Right corner of Matrix
    // (order (n/4)*(n/4))
    for ( i = 3 * n/4; i < n; i++)
        for ( j = 3 * n/4; j < n; j++)
            arr[i][j] = (n*n + 1) - arr[i][j];
     
    // Centre of Matrix (order (n/2)*(n/2))
    for ( i = n/4; i < 3 * n/4; i++)
        for ( j = n/4; j < 3 * n/4; j++)
            arr[i][j] = (n*n + 1) - arr[i][j];
 
    // Printing the magic-square
    for (i = 0; i < n; i++)
    {
        for ( j = 0; j < n; j++)
            cout << arr[i][j] << " ";
        cout << "\n";
    }
}
 
// driver program
int main()
{
    int n=8;
    doublyEven(n); //Function call
    return 0;
}

Time complexity: quadratic
Space complexity: quadratic
// C++ program to generate odd sized magic squares
#include <bits/stdc++.h>
using namespace std;
 
// A function to generate odd sized magic squares
void generateSquare(int n)
{
    int magicSquare[n][n];
 
    // set all slots as 0
    memset(magicSquare, 0, sizeof(magicSquare));
 
    // Initialize position for 1
    int i = n / 2;
    int j = n - 1;
 
    // One by one put all values in magic square
    for (int num = 1; num <= n * n;) {
        if (i == -1 && j == n) // 3rd condition
        {
            j = n - 2;
            i = 0;
        }
        else {
            // 1st condition helper if next number
            // goes to out of square's right side
            if (j == n)
                j = 0;
 
            // 1st condition helper if next number
            // is goes to out of square's upper side
            if (i < 0)
                i = n - 1;
        }
        if (magicSquare[i][j]) // 2nd condition
        {
            j -= 2;
            i++;
            continue;
        }
        else
            magicSquare[i][j] = num++; // set number
 
        j++;
        i--; // 1st condition
    }
 
    // Print magic square
    cout << "The Magic Square for n=" << n
         << ":\nSum of "
            "each row or column "
         << n * (n * n + 1) / 2 << ":\n\n";
    for (i = 0; i < n; i++) {
        for (j = 0; j < n; j++)
 
            // setw(7) is used so that the matrix gets
            // printed in a proper square fashion.
            cout << setw(4) << magicSquare[i][j] << " ";
        cout << endl;
    }
}
 
// Driver code
int main()
{
 
    // Works only when n is odd
    int n = 7;
    generateSquare(n);
    return 0;
}
 
// This code is contributed by rathbhupendra

Time complexity: quadratic
Space complexity: quadratic
// C++ program to check whether a given
// matrix is magic matrix or not
#include <bits/stdc++.h>
 
# define my_sizeof(type) ((char *)(&type+1)-(char*)(&type))
using namespace std;
 
// Returns true if mat[][] is magic
// square, else returns false.
bool isMagicSquare(int mat[][3])
{
    int n = my_sizeof(mat)/my_sizeof(mat[0]);
    // calculate the sum of
    // the prime diagonal
    int i=0,j=0;
    // sumd1 and sumd2 are the sum of the two diagonals
    int sumd1 = 0, sumd2=0;
    for (i = 0; i < n; i++)
    {
        // (i, i) is the diagonal from top-left -> bottom-right
        // (i, n - i - 1) is the diagonal from top-right -> bottom-left
        sumd1 += mat[i][i];
        sumd2 += mat[i][n-1-i];
    }
    // if the two diagonal sums are unequal then it is not a magic square
    if(sumd1!=sumd2)
        return false;
 
    // For sums of Rows
    for (i = 0; i < n; i++) {
         
        int rowSum = 0, colSum = 0;   
        for (j = 0; j < n; j++)
        {
            rowSum += mat[i][j];
            colSum += mat[j][i];
        }
        if (rowSum != colSum || colSum != sumd1)
            return false;
    }
   return true;
}
 
// driver program to
// test above function
int main()
{
    int mat[3][3] = {{ 2, 7, 6 },
                    { 9, 5, 1 },
                    { 4, 3, 8 }};
     
    if (isMagicSquare(mat))
        cout << "Magic Square";
    else
        cout << "Not a magic Square";
     
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ code to find the Kronecker Product of two
// matrices and stores it as matrix C
#include <bits/stdc++.h>
using namespace std;
 
// rowa and cola are no of rows and columns
// of matrix A
// rowb and colb are no of rows and columns
// of matrix B
const int cola = 2, rowa = 3, colb = 3, rowb = 2;
 
// Function to computes the Kronecker Product
// of two matrices
void Kroneckerproduct(int A[][cola], int B[][colb])
{
 
    int C[rowa * rowb][cola * colb];
 
    // i loops till rowa
    for (int i = 0; i < rowa; i++) {
 
        // k loops till rowb
        for (int k = 0; k < cola; k++) {
 
            // j loops till cola
            for (int j = 0; j < rowb; j++) {
 
                // l loops till colb
                for (int l = 0; l < colb; l++) {
 
                    // Each element of matrix A is
                    // multiplied by whole Matrix B
                    // resp and stored as Matrix C
                    C[i * rowb + k][j * colb + l]
                        = A[i][j] * B[k][l];
                }
            }
        }
    }
 
    for (int i = 0; i < rowa * rowb; i++) {
        for (int j = 0; j < cola * colb; j++) {
            cout << C[i][j] << " ";
        }
        cout << endl;
    }
}
 
// Driver Code
int main()
{
    int A[3][2] = { { 1, 2 }, { 3, 4 }, { 1, 0 } },
        B[2][3] = { { 0, 5, 2 }, { 6, 7, 3 } };
 
    Kroneckerproduct(A, B);
    return 0;
}
 
// This code is contributed by shubhamsingh10

Time complexity: np
Space complexity: np
// C++ implementation to count sub-matrices having sum
// divisible by the value 'k'
#include <bits/stdc++.h>
using namespace std;
 
#define SIZE 10
 
// function to count all sub-arrays divisible by k
int subCount(int arr[], int n, int k)
{
    // create auxiliary hash array to count frequency
    // of remainders
    int mod[k];
    memset(mod, 0, sizeof(mod));
 
    // Traverse original array and compute cumulative
    // sum take remainder of this current cumulative
    // sum and increase count by 1 for this remainder
    // in mod[] array
    int cumSum = 0;
    for (int i = 0; i < n; i++) {
        cumSum += arr[i];
 
        // as the sum can be negative, taking modulo
        // twice
        mod[((cumSum % k) + k) % k]++;
    }
 
    int result = 0; // Initialize result
 
    // Traverse mod[]
    for (int i = 0; i < k; i++)
 
        // If there are more than one prefix subarrays
        // with a particular mod value.
        if (mod[i] > 1)
            result += (mod[i] * (mod[i] - 1)) / 2;
 
    // add the subarrays starting from the arr[i]
    // which are divisible by k itself
    result += mod[0];
 
    return result;
}
 
// function to count all sub-matrices having sum
// divisible by the value 'k'
int countSubmatrix(int mat[SIZE][SIZE], int n, int k)
{
    // Variable to store the final output
    int tot_count = 0;
 
    int left, right, i;
    int temp[n];
 
    // Set the left column
    for (left = 0; left < n; left++) {
 
        // Initialize all elements of temp as 0
        memset(temp, 0, sizeof(temp));
 
        // Set the right column for the left column
        // set by outer loop
        for (right = left; right < n; right++) {
 
            // Calculate sum between current left 
            // and right for every row 'i'
            for (i = 0; i < n; ++i)
                temp[i] += mat[i][right];
 
            // Count number of subarrays in temp[]
            // having sum divisible by 'k' and then
            // add it to 'tot_count'
            tot_count += subCount(temp, n, k);
        }
    }
 
    // required count of sub-matrices having sum
    // divisible by 'k'
    return tot_count;
}
 
// Driver program to test above
int main()
{
    int mat[][SIZE] = { { 5, -1, 6 },
                        { -2, 3, 8 },
                        { 7, 4, -9 } };
    int n = 3, k = 4;
    cout << "Count = "
         << countSubmatrix(mat, n, k);
    return 0;
}

Time complexity: cubic
Space complexity: linear