Banana-Leopard/TASTY huggingface dataset:
// CPP program to find number of possible moves of knight
#include <bits/stdc++.h>
#define n 4
#define m 4
using namespace std;
 
// To calculate possible moves
int findPossibleMoves(int mat[n][m], int p, int q)
{
    // All possible moves of a knight
    int X[8] = { 2, 1, -1, -2, -2, -1, 1, 2 };
    int Y[8] = { 1, 2, 2, 1, -1, -2, -2, -1 };
 
    int count = 0;
 
    // Check if each possible move is valid or not
    for (int i = 0; i < 8; i++) {
 
        // Position of knight after move
        int x = p + X[i];
        int y = q + Y[i];
 
        // count valid moves
        if (x >= 0 && y >= 0 && x < n && y < m
            && mat[x][y] == 0)
            count++;
    }
 
    // Return number of possible moves
    return count;
}
 
// Driver program to check findPossibleMoves()
int main()
{
    int mat[n][m] = { { 1, 0, 1, 0 },
                      { 0, 1, 1, 1 },
                      { 1, 1, 0, 1 },
                      { 0, 1, 1, 1 } };
 
    int p = 2, q = 2;
 
    cout << findPossibleMoves(mat, p, q);
 
    return 0;
}

Time complexity: constant
Space complexity: constant
// A simple C++ program to find sum of diagonals
#include <bits/stdc++.h>
using namespace std;
 
const int MAX = 100;
 
void printDiagonalSums(int mat[][MAX], int n)
{
    int principal = 0, secondary = 0;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
 
            // Condition for principal diagonal
            if (i == j)
                principal += mat[i][j];
 
            // Condition for secondary diagonal
            if ((i + j) == (n - 1))
                secondary += mat[i][j];
        }
    }
 
    cout << "Principal Diagonal:" << principal << endl;
    cout << "Secondary Diagonal:" << secondary << endl;
}
 
// Driver code
int main()
{
    int a[][MAX] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 },
                    { 1, 2, 3, 4 }, { 5, 6, 7, 8 } };
    printDiagonalSums(a, 4);
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// An efficient C++ program to find sum of diagonals
#include <bits/stdc++.h>
using namespace std;
 
const int MAX = 100;
 
void printDiagonalSums(int mat[][MAX], int n)
{
    int principal = 0, secondary = 0;
    for (int i = 0; i < n; i++) {
        principal += mat[i][i];
        secondary += mat[i][n - i - 1];       
    }
 
    cout << "Principal Diagonal:" << principal << endl;
    cout << "Secondary Diagonal:" << secondary << endl;
}
 
// Driver code
int main()
{
    int a[][MAX] = { { 1, 2, 3, 4 }, { 5, 6, 7, 8 },
                     { 1, 2, 3, 4 }, { 5, 6, 7, 8 } };
    printDiagonalSums(a, 4);
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ program to print boundary element of
// matrix.
#include <bits/stdc++.h>
using namespace std;
 
const int MAX = 100;
 
void printBoundary(int a[][MAX], int m, int n)
{
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            if (i == 0 || j == 0 || i == n - 1
                || j == n - 1)
                cout << a[i][j] << " ";
            else
                cout << " "
                     << " ";
        }
        cout << "\n";
    }
}
 
// Driver code
int main()
{
    int a[4][MAX] = { { 1, 2, 3, 4 },
                      { 5, 6, 7, 8 },
                      { 1, 2, 3, 4 },
                      { 5, 6, 7, 8 } };
 
    // Function call
    printBoundary(a, 4, 4);
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ program to find sum of boundary elements
// of matrix.
#include <bits/stdc++.h>
using namespace std;
 
const int MAX = 100;
 
int getBoundarySum(int a[][MAX], int m, int n)
{
    long long int sum = 0;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < n; j++) {
            if (i == 0)
                sum += a[i][j];
            else if (i == m - 1)
                sum += a[i][j];
            else if (j == 0)
                sum += a[i][j];
            else if (j == n - 1)
                sum += a[i][j];
        }
    }
    return sum;
}
 
// Driver code
int main()
{
    int a[][MAX] = { { 1, 2, 3, 4 },
                     { 5, 6, 7, 8 },
                     { 1, 2, 3, 4 },
                     { 5, 6, 7, 8 } };
 
    // Function call
    long long int sum = getBoundarySum(a, 4, 4);
    cout << "Sum of boundary elements is " << sum;
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ program to print a matrix in spiral
// form.
#include <iostream>
using namespace std;
 
const int MAX = 100;
 
void printSpiral(int mat[][MAX], int r, int c)
{
 
    int i, a = 0, b = 2;
 
    int low_row = (0 > a) ? 0 : a;
    int low_column = (0 > b) ? 0 : b - 1;
    int high_row = ((a + 1) >= r) ? r - 1 : a + 1;
    int high_column = ((b + 1) >= c) ? c - 1 : b + 1;
 
    while ((low_row > 0 - r && low_column > 0 - c)) {
 
        for (i = low_column + 1; i <= high_column &&
                         i < c && low_row >= 0; ++i)
            cout << mat[low_row][i] << " ";
        low_row -= 1;
 
        for (i = low_row + 2; i <= high_row && i < r &&
                                   high_column < c; ++i)
            cout << mat[i][high_column] << " ";
        high_column += 1;
 
        for (i = high_column - 2; i >= low_column &&
                               i >= 0 && high_row < r; --i)
            cout << mat[high_row][i] << " ";
        high_row += 1;
 
        for (i = high_row - 2; i > low_row && i >= 0
                                   && low_column >= 0; --i)
            cout << mat[i][low_column] << " ";
        low_column -= 1;
    }
    cout << endl;
}
 
// Driver code
int main()
{
    int mat[][MAX] = { { 1, 2, 3 }, { 4, 5, 6 }, { 7, 8, 9 } };
    int r = 3, c = 3;
 
    printSpiral(mat, r, c);
}

Time complexity: quadratic
Space complexity: constant
// C++ program to print matrix in snake order
#include <iostream>
#define M 4
#define N 4
using namespace std;
 
void print(int mat[M][N])
{
    // Traverse through all rows
    for (int i = 0; i < M; i++) {
 
        // If current row is even, print from
        // left to right
        if (i % 2 == 0) {
            for (int j = 0; j < N; j++)
                cout << mat[i][j] << " ";
 
            // If current row is odd, print from
            // right to left
        }
        else {
            for (int j = N - 1; j >= 0; j--)
                cout << mat[i][j] << " ";
        }
    }
}
 
// Driver code
int main()
{
    int mat[M][N] = { { 10, 20, 30, 40 },
                      { 15, 25, 35, 45 },
                      { 27, 29, 37, 48 },
                      { 32, 33, 39, 50 } };
 
    print(mat);
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ program to find the difference
// between the sum of diagonal.
#include <bits/stdc++.h>
#define MAX 100
using namespace std;
 
int difference(int arr[][MAX], int n)
{
    // Initialize sums of diagonals
    int d1 = 0, d2 = 0;
 
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            // finding sum of primary diagonal
            if (i == j)
                d1 += arr[i][j];
 
            // finding sum of secondary diagonal
            if (i == n - j - 1)
                d2 += arr[i][j];
        }
    }
 
    // Absolute difference of the sums
    // across the diagonals
    return abs(d1 - d2);
}
 
// Driven Program
int main()
{
    int n = 3;
 
    int arr[][MAX] =
    {
        {11, 2, 4},
        {4 , 5, 6},
        {10, 8, -12}
    };
 
    cout << difference(arr, n);
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ program to find the difference
// between the sum of diagonal.
#include <bits/stdc++.h>
#define MAX 100
using namespace std;
 
int difference(int arr[][MAX], int n)
{
    // Initialize sums of diagonals
    int d1 = 0, d2 = 0;
 
    for (int i = 0; i < n; i++)
    {
          // d1 store the sum of diagonal from
          // top-left to bottom-right
        d1 += arr[i][i];
       
          // d2 store the sum of diagonal from
        // top-right to bottom-left
        d2 += arr[i][n-i-1];
    }
 
    // Absolute difference of the sums
    // across the diagonals
    return abs(d1 - d2);
}
 
// Driven Program
int main()
{
    int n = 3;
 
    int arr[][MAX] =
    {
        {11, 2, 4},
        {4 , 5, 6},
        {10, 8, -12}
    };
 
    cout << difference(arr, n);
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ program to fill a matrix with values from
// 1 to n*n in spiral fashion.
#include <bits/stdc++.h>
using namespace std;
 
const int MAX = 100;
 
// Fills a[m][n] with values from 1 to m*n in
// spiral fashion.
void spiralFill(int m, int n, int a[][MAX])
{
    // Initialize value to be filled in matrix
    int val = 1;
 
    /*  k - starting row index
        m - ending row index
        l - starting column index
        n - ending column index */
    int k = 0, l = 0;
    while (k < m && l < n)
    {
        /* Print the first row from the remaining
          rows */
        for (int i = l; i < n; ++i)
            a[k][i] = val++;
 
        k++;
 
        /* Print the last column from the remaining
          columns */
        for (int i = k; i < m; ++i)
            a[i][n-1] = val++;
        n--;
 
        /* Print the last row from the remaining
           rows */
        if (k < m)
        {
            for (int i = n-1; i >= l; --i)
                a[m-1][i] = val++;
            m--;
        }
 
        /* Print the first column from the remaining
           columns */
        if (l < n)
        {
            for (int i = m-1; i >= k; --i)
                 a[i][l] = val++;
            l++;
        }
    }
}
 
/* Driver program to test above functions */
int main()
{
    int m = 4, n = 4;
    int a[MAX][MAX];
    spiralFill(m, n, a);
    for (int i=0; i<m; i++)
    {
       for (int j=0; j<n; j++)
          cout << a[i][j] << " ";
       cout << endl;
    }
    return 0;
}

Time complexity: quadratic
Space complexity: quadratic
#include <iostream>
using namespace std;
 
// change row and column value to set the canvas size
const int row = 5;
const int col = 4;
 
// creates row boundary
int row_line()
{
    cout << endl;
    for (int i = 0; i < col; i++) {
        cout << " -----";
    }
    cout << endl;
}
 
// returns the count of alive neighbours
int count_live_neighbour_cell(int a[row][col], int r, int c)
{
    int i, j, count = 0;
    for (i = r - 1; i <= r + 1; i++) {
        for (j = c - 1; j <= c + 1; j++) {
            if ((i == r && j == c) || (i < 0 || j < 0)
                || (i >= row || j >= col)) {
                continue;
            }
            if (a[i][j] == 1) {
                count++;
            }
        }
    }
    return count;
}
 
int main()
{
    int a[row][col], b[row][col];
    int i, j;
    int neighbour_live_cell;
 
    // generate matrix canvas with random values (live and
    // dead cells)
    for (i = 0; i < row; i++) {
        for (j = 0; j < col; j++) {
            a[i][j] = rand() % 2;
        }
    }
 
    // print array matrix
    cout << "Initial Stage:";
    row_line();
    for (i = 0; i < row; i++) {
        cout << ":";
        for (j = 0; j < col; j++) {
            cout << "  " << a[i][j] << "  :";
        }
        row_line();
    }
 
    // next canvas values based on live neighbour count
    for (i = 0; i < row; i++) {
        for (j = 0; j < col; j++) {
            neighbour_live_cell
                = count_live_neighbour_cell(a, i, j);
            if (a[i][j] == 1
                && (neighbour_live_cell == 2
                    || neighbour_live_cell == 3)) {
                b[i][j] = 1;
            }
 
            else if (a[i][j] == 0
                     && neighbour_live_cell == 3) {
                b[i][j] = 1;
            }
 
            else {
                b[i][j] = 0;
            }
        }
    }
 
    // print next generation
    cout << "\nNext Generation:";
    row_line();
    for (i = 0; i < row; i++) {
        cout << ":";
        for (j = 0; j < col; j++) {
            cout << "  " << b[i][j] << "  :";
        }
        row_line();
    }
 
    return 0;
}
 
/*
###################################### OUTPUT
#################################### Initial Stage:
 ----- ----- ----- -----
:  1  :  1  :  0  :  0  :
 ----- ----- ----- -----
:  1  :  0  :  0  :  0  :
 ----- ----- ----- -----
:  0  :  0  :  1  :  1  :
 ----- ----- ----- -----
:  1  :  1  :  1  :  1  :
 ----- ----- ----- -----
:  1  :  0  :  1  :  0  :
 ----- ----- ----- -----
 
Next Generation:
 ----- ----- ----- -----
:  1  :  1  :  0  :  0  :
 ----- ----- ----- -----
:  1  :  0  :  1  :  0  :
 ----- ----- ----- -----
:  1  :  0  :  0  :  1  :
 ----- ----- ----- -----
:  1  :  0  :  0  :  0  :
 ----- ----- ----- -----
:  1  :  0  :  1  :  1  :
 ----- ----- ----- -----
 
 */
 
// This code is contributed by Tapesh(tapeshdua420)

Time complexity: quadratic
Space complexity: quadratic
// C++ program to find maximum sum of hour
// glass in matrix
#include<bits/stdc++.h>
using namespace std;
const int R = 5;
const int C = 5;
 
// Returns maximum sum of hour glass in ar[][]
int findMaxSum(int mat[R][C])
{
    if (R<3 || C<3){
         cout << "Not possible" << endl;
          exit(0);
    }
 
    // Here loop runs (R-2)*(C-2) times considering
    // different top left cells of hour glasses.
    int max_sum = INT_MIN;
    for (int i=0; i<R-2; i++)
    {
        for (int j=0; j<C-2; j++)
        {
            // Considering mat[i][j] as top left cell of
            // hour glass.
            int sum = (mat[i][j]+mat[i][j+1]+mat[i][j+2])+
                      (mat[i+1][j+1])+
                  (mat[i+2][j]+mat[i+2][j+1]+mat[i+2][j+2]);
 
            // If previous sum is less than current sum then
            // update new sum in max_sum
            max_sum = max(max_sum, sum);
        }
    }
    return max_sum;
}
 
// Driver code
int main()
{
    int mat[][C] = {{1, 2, 3, 0, 0},
                    {0, 0, 0, 0, 0},
                    {2, 1, 4, 0, 0},
                    {0, 0, 0, 0, 0},
                    {1, 1, 0, 1, 0}};
    int res = findMaxSum(mat);
    cout << "Maximum sum of hour glass = "<< res << endl;
    return 0;
}
 
//Code is modified by Susobhan Akhuli

Time complexity: quadratic
Space complexity: constant
// C++ program for finding maximum and minimum in
// a matrix.
#include<bits/stdc++.h>
using namespace std;
 
#define MAX 100
 
// Finds maximum and minimum in arr[0..n-1][0..n-1]
// using pair wise comparisons
void maxMin(int arr[][MAX], int n)
{
    int min = INT_MAX;
    int max = INT_MIN;
 
    // Traverses rows one by one
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j <= n/2; j++)
        {
            // Compare elements from beginning
            // and end of current row
            if (arr[i][j] > arr[i][n-j-1])
            {
                if (min > arr[i][n-j-1])
                    min = arr[i][n-j-1];
                if (max< arr[i][j])
                    max = arr[i][j];
            }
            else
            {
                if (min > arr[i][j])
                    min = arr[i][j];
                if (max< arr[i][n-j-1])
                    max = arr[i][n-j-1];
            }
        }
    }
    cout << "Maximum = " << max
         << ", Minimum = " << min;
}
 
/* Driver program to test above function */
int main()
{
    int arr[MAX][MAX] = {5, 9, 11,
                        25, 0, 14,
                        21, 6, 4};
    maxMin(arr, 3);
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ program to print matrix in anti-spiral form
#include <bits/stdc++.h>
using namespace std;
#define R 4
#define C 5
 
void antiSpiralTraversal(int m, int n, int a[R][C])
{
    int i, k = 0, l = 0;
 
    /*  k - starting row index
        m - ending row index
        l - starting column index
        n - ending column index
        i - iterator  */
    stack<int> stk;
 
    while (k <= m && l <= n)
    {
        /* Print the first row from the remaining rows */
        for (i = l; i <= n; ++i)
            stk.push(a[k][i]);
        k++;
 
        /* Print the last column from the remaining columns */
        for (i = k; i <= m; ++i)
            stk.push(a[i][n]);
        n--;
 
        /* Print the last row from the remaining rows */
        if ( k <= m)
        {
            for (i = n; i >= l; --i)
                stk.push(a[m][i]);
            m--;
        }
 
        /* Print the first column from the remaining columns */
        if (l <= n)
        {
            for (i = m; i >= k; --i)
                stk.push(a[i][l]);
            l++;
        }
    }
 
    while (!stk.empty())
    {
        cout << stk.top() << " ";
        stk.pop();
    }
}
 
/* Driver program to test above functions */
int main()
{
    int mat[R][C] =
    {
        {1,  2,  3,  4,  5},
        {6,  7,  8,  9,  10},
        {11, 12, 13, 14, 15},
        {16, 17, 18, 19, 20}
    };
 
    antiSpiralTraversal(R-1, C-1, mat);
 
    return 0;
}

Time complexity: quadratic
Space complexity: quadratic
// C++ program to find trace and normal
// of given matrix
#include<bits/stdc++.h>
using namespace std;
 
// Size of given matrix
const int MAX = 100;
 
// Returns Normal of a matrix of size n x n
int findNormal(int mat[][MAX], int n)
{
    int sum = 0;
    for (int i=0; i<n; i++)
        for (int j=0; j<n; j++)
            sum += mat[i][j]*mat[i][j];
    return sqrt(sum);
}
 
// Returns trace of a matrix of size n x n
int findTrace(int mat[][MAX], int n)
{
    int sum = 0;
    for (int i=0; i<n; i++)
         sum += mat[i][i];
    return sum;
}
 
// Driven source
int main()
{
    int mat[][MAX] = {{1, 1, 1, 1, 1},
        {2, 2, 2, 2, 2},
        {3, 3, 3, 3, 3},
        {4, 4, 4, 4, 4},
        {5, 5, 5, 5, 5},
    };
    cout << "Trace of Matrix = "
         << findTrace(mat, 5) << endl;
    cout << "Normal of Matrix = "
         << findNormal(mat, 5) << endl;
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ program to find minimum operations required
// to set all the element of binary matrix
#include <bits/stdc++.h>
#define N 5
#define M 5
using namespace std;
 
// Return minimum operation required to make all 1s.
int minOperation(bool arr[N][M])
{
    int ans = 0;
    for (int i = N - 1; i >= 0; i--)
    {
        for (int j = M - 1; j >= 0; j--)
        {
            // check if this cell equals 0
            if(arr[i][j] == 0)
            {
                // increase the number of moves
                ans++;
 
                // flip from this cell to the start point
                for (int k = 0; k <= i; k++)
                {
                    for (int h = 0; h <= j; h++)
                    {
                        // flip the cell
                        if (arr[k][h] == 1)
                            arr[k][h] = 0;
                        else
                            arr[k][h] = 1;
                    }
                }
            }
        }
    }
    return ans;
}
 
// Driven Program
int main()
{
    bool mat[N][M] =
    {
        0, 0, 1, 1, 1,
        0, 0, 0, 1, 1,
        0, 0, 0, 1, 1,
        1, 1, 1, 1, 1,
        1, 1, 1, 1, 1
    };
 
    cout << minOperation(mat) << endl;
 
    return 0;
}

Time complexity: quadratic
Space complexity: quadratic
// This is a modified code of
// https://www.geeksforgeeks.org/print-a-given-matrix-in-spiral-form/
#include <iostream>
#define R 3
#define C 6
using namespace std;
 
// Function that print matrix in reverse spiral form.
void ReversespiralPrint(int m, int n, int a[R][C])
{
    // Large array to initialize it
    // with elements of matrix
    long int b[100];
     
    /* k - starting row index
    l - starting column index*/
    int i, k = 0, l = 0;
     
    // Counter for single dimension array
    //in which elements will be stored
    int z = 0;
     
    // Total elements in matrix
    int size = m*n;
 
    while (k < m && l < n)
    {
        // Variable to store value of matrix.
        int val;
         
        /* Print the first row from the remaining rows */
        for (i = l; i < n; ++i)
        {
            // printf("%d ", a[k][i]);
            val = a[k][i];
            b[z] = val;
            ++z;
        }
        k++;
 
        /* Print the last column from the remaining columns */
        for (i = k; i < m; ++i)
        {
            // printf("%d ", a[i][n-1]);
            val = a[i][n-1];
            b[z] = val;
            ++z;
        }
        n--;
 
        /* Print the last row from the remaining rows */
        if ( k < m)
        {
            for (i = n-1; i >= l; --i)
            {
                // printf("%d ", a[m-1][i]);
                val = a[m-1][i];
                b[z] = val;
                ++z;
            }
            m--;
        }
 
        /* Print the first column from the remaining columns */
        if (l < n)
        {
            for (i = m-1; i >= k; --i)
            {
                // printf("%d ", a[i][l]);
                val = a[i][l];
                b[z] = val;
                ++z;
            }
            l++;
        }
    }
    for (int i=size-1 ; i>=0 ; --i)
    {
        cout<<b[i]<<" ";
    }
}
 
/* Driver program to test above functions */
int main()
{
    int a[R][C] = { {1, 2, 3, 4, 5, 6},
                    {7, 8, 9, 10, 11, 12},
                    {13, 14, 15, 16, 17, 18}};
    ReversespiralPrint(R, C, a);
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ program to find sum of matrix element
// where each element is integer division of
// row and column.
#include<bits/stdc++.h>
using namespace std;
 
// Return sum of matrix element where each element
// is division of its corresponding row and column.
int findSum(int n)
{
    int ans = 0;
    for (int i = 1; i <= n; i++)   // for rows
        for (int j = 1; j <= n; j++) // for columns
            ans += (i/j);
    return ans;
}
 
// Driven Program
int main()
{
    int N = 2;
    cout << findSum(N) << endl;
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ program to find sum of matrix element
// where each element is integer division of
// row and column.
#include<bits/stdc++.h>
using namespace std;
 
// Return sum of matrix element where each
// element is division of its corresponding
// row and column.
int findSum(int n)
{
    int ans = 0, temp = 0, num;
 
    // For each column.
    for (int i = 1; i <= n && temp < n; i++)
    {
        // count the number of elements of
        // each column. Initialize to i -1
        // because number of zeroes are i - 1.
        temp = i - 1;
 
        // For multiply
        num = 1;
 
        while (temp < n)
        {
            if (temp + i <= n)
                ans += (i * num);
            else
                ans += ((n - temp) * num);
 
            temp += i;
            num ++;
        }
    }
 
    return ans;
}
 
// Driven Program
int main()
{
    int N = 2;
    cout << findSum(N) << endl;
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ program to find
// number of countOpsation
// to make two matrix equals
#include <bits/stdc++.h>
using namespace std;
 
const int MAX = 1000;
 
int countOps(int A[][MAX], int B[][MAX],
             int m, int n)
{
    // Update matrix A[][]
    // so that only A[][]
    // has to be countOpsed
    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            A[i][j] -= B[i][j];
 
    // Check necessary condition
    // for condition for
    // existence of full countOpsation
    for (int i = 1; i < n; i++)
    for (int j = 1; j < m; j++)
        if (A[i][j] - A[i][0] -
            A[0][j] + A[0][0] != 0)
        return -1;
 
    // If countOpsation is possible
    // calculate total countOpsation
    int result = 0;
    for (int i = 0; i < n; i++)
        result += abs(A[i][0]);
    for (int j = 0; j < m; j++)
        result += abs(A[0][j] - A[0][0]);
    return (result);
}
 
// Driver code
int main()
{
    int A[MAX][MAX] = { {1, 1, 1},
                        {1, 1, 1},
                        {1, 1, 1}};
    int B[MAX][MAX] = { {1, 2, 3},
                        {4, 5, 6},
                        {7, 8, 9}};
    cout << countOps(A, B, 3, 3) ;
    return 0;
}

Time complexity: quadratic
Space complexity: constant