Banana-Leopard/TASTY huggingface dataset:
// C++ program to print 2 coils of a
// 4n x 4n matrix.
#include<iostream>
using namespace std;
 
// Print coils in a matrix of size 4n x 4n
void printCoils(int n)
{
    // Number of elements in each coil
    int m = 8*n*n;
 
    // Let us fill elements in coil 1.
    int coil1[m];
 
    // First element of coil1
    // 4*n*2*n + 2*n;
    coil1[0] = 8*n*n + 2*n;
    int curr = coil1[0];
 
    int nflg = 1, step = 2;
 
    // Fill remaining m-1 elements in coil1[]
    int index = 1;
    while (index < m)
    {
        // Fill elements of current step from
        // down to up
        for (int i=0; i<step; i++)
        {
            // Next element from current element
            curr = coil1[index++] = (curr - 4*n*nflg);
            if (index >= m)
                break;
        }
        if (index >= m)
            break;
 
        // Fill elements of current step from
        // up to down.
        for (int i=0; i<step; i++)
        {
            curr = coil1[index++] = curr + nflg;
            if (index >= m)
                break;
        }
        nflg = nflg*(-1);
        step += 2;
    }
 
    /* get coil2 from coil1 */
    int coil2[m];
    for (int i=0; i<8*n*n; i++)
        coil2[i] = 16*n*n + 1 -coil1[i];
 
    // Print both coils
    cout << "Coil 1 : ";
    for(int i=0; i<8*n*n; i++)
        cout << coil1[i] << " ";
    cout << "\nCoil 2 : ";
    for (int i=0; i<8*n*n; i++)
        cout << coil2[i] << " ";
}
 
// Driver code
int main()
{
    int n = 1;
    printCoils(n);
    return 0;
}

Time complexity: quadratic
Space complexity: quadratic
// C++ program to find sum of matrix in which each
// element is absolute difference of its corresponding
// row and column number row.
#include<bits/stdc++.h>
using namespace std;
 
// Return the sum of matrix in which each element
// is absolute difference of its corresponding row
// and column number row
int findSum(int n)
{
    // Generate matrix
    int arr[n][n];
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            arr[i][j] = abs(i - j);
 
    // Compute sum
    int sum = 0;
    for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
            sum += arr[i][j];
 
    return sum;
}
 
// Driven Program
int main()
{
    int n = 3;
    cout << findSum(n) << endl;
    return 0;
}

Time complexity: quadratic
Space complexity: quadratic
// C++ program to find sum of matrix in which
// each element is absolute difference of its
// corresponding row and column number row.
#include<bits/stdc++.h>
using namespace std;
 
// Return the sum of matrix in which each
// element is absolute difference of its
// corresponding row and column number row
int findSum(int n)
{
    int sum = 0;
    for (int i = 0; i < n; i++)
        sum += i*(n-i);
    return 2*sum;
}
 
// Driven Program
int main()
{
    int n = 3;
    cout << findSum(n) << endl;
    return 0;
}

Time complexity: linear
Space complexity: constant
// C++ program to find sum of matrix in which
// each element is absolute difference of its
// corresponding row and column number row.
#include<bits/stdc++.h>
using namespace std;
 
// Return the sum of matrix in which each element
// is absolute difference of its corresponding
// row and column number row
int findSum(int n)
{
    n--;
    int sum = 0;
    sum += (n*(n+1))/2;
    sum += (n*(n+1)*(2*n + 1))/6;
    return sum;
}
 
// Driven Program
int main()
{
    int n = 3;
    cout << findSum(n) << endl;
    return 0;
}

Time complexity: constant
Space complexity: constant
// C++ program to find if a matrix is symmetric.
#include <bits/stdc++.h>
#define MAX 1000
using namespace std;
 
void checkHV(int arr[][MAX], int N, int M)
{
    // Initializing as both horizontal and vertical
    // symmetric.
    bool horizontal = true, vertical = true;
 
    // Checking for Horizontal Symmetry.  We compare
    // first row with last row, second row with second
    // last row and so on.
    for (int i = 0, k = N - 1; i < N / 2; i++, k--) {
        // Checking each cell of a column.
        for (int j = 0; j < M; j++) {
            // check if every cell is identical
            if (arr[i][j] != arr[k][j]) {
                horizontal = false;
                break;
            }
        }
    }
 
    // Checking for Vertical Symmetry.  We compare
    // first column with last column, second column
    // with second last column and so on.
    for (int j = 0, k = M - 1; j < M / 2; j++, k--) {
        // Checking each cell of a row.
        for (int i = 0; i < N; i++) {
            // check if every cell is identical
            if (arr[i][j] != arr[i][k]) {
                vertical = false;
                break;
            }
        }
    }
 
    if (!horizontal && !vertical)
        cout << "NO\n";
    else if (horizontal && !vertical)
        cout << "HORIZONTAL\n";
    else if (vertical && !horizontal)
        cout << "VERTICAL\n";
    else
        cout << "BOTH\n";
}
 
// Driven Program
int main()
{
    int mat[MAX][MAX]
        = { { 0, 1, 0 }, { 0, 0, 0 }, { 0, 1, 0 } };
    checkHV(mat, 3, 3);
 
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ program to find  maximum possible determinant
// of 0/n matrix.
#include <bits/stdc++.h>
using namespace std;
 
// Function for maximum determinant
int maxDet(int n)
{
    return (2*n*n*n);
}
 
// Function to print resultant matrix
void resMatrix ( int n)
{
    for (int i = 0; i < 3; i++)
    {
        for (int j = 0; j < 3; j++)
        {
            // three position where 0 appears
            if (i == 0 && j == 2)
                cout << "0 ";
            else if (i == 1 && j == 0)
                cout << "0 ";
            else if (i == 2 && j == 1)
                cout << "0 ";
 
            // position where n appears
            else
                cout << n << " ";
        }
        cout << "\n";
    }
}
 
// Driver code
int main()
{
    int n = 15;
    cout << "Maximum Determinant = " << maxDet(n);
 
    cout << "\nResultant Matrix :\n";
    resMatrix(n);
 
    return 0;
}

Time complexity: constant
Space complexity: constant
// C++ program to find sum of
// diagonals of spiral matrix
#include<bits/stdc++.h>
using namespace std;
 
// function returns sum of diagonals
int spiralDiaSum(int n)
{
    if (n == 1)
        return 1;
 
    // as order should be only odd
    // we should pass only odd-integers
    return (4*n*n - 6*n + 6 + spiralDiaSum(n-2));
}
 
// Driver program
int main()
{
    int n = 7;
    cout <<  spiralDiaSum(n);
    return 0;
}

Time complexity: linear
Space complexity: linear
// C++ program to find perimeter of area covered by
// 1 in 2D matrix consists of 0's and  1's.
#include<bits/stdc++.h>
using namespace std;
#define R 3
#define C 5
 
// Find the number of covered side for mat[i][j].
int numofneighbour(int mat[][C], int i, int j)
{
    int count = 0;
 
    // UP
    if (i > 0 && mat[i - 1][j])
        count++;
 
    // LEFT
    if (j > 0 && mat[i][j - 1])
        count++;
 
    // DOWN
    if (i < R-1 && mat[i + 1][j])
        count++;
 
    // RIGHT
    if (j < C-1 && mat[i][j + 1])
        count++;
 
    return count;
}
 
// Returns sum of perimeter of shapes formed with 1s
int findperimeter(int mat[R][C])
{
    int perimeter = 0;
 
    // Traversing the matrix and finding ones to
    // calculate their contribution.
    for (int i = 0; i < R; i++)
        for (int j = 0; j < C; j++)
            if (mat[i][j])
                perimeter += (4 - numofneighbour(mat, i ,j));
 
    return perimeter;
}
 
// Driven Program
int main()
{
    int mat[R][C] =
    {
        0, 1, 0, 0, 0,
        1, 1, 1, 0, 0,
        1, 0, 0, 0, 0,
    };
 
    cout << findperimeter(mat) << endl;
 
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ program to print cells with same rectangular
// sum diagonally
#include <bits/stdc++.h>
using namespace std;
#define R 4
#define C 4
 
// Method prints cell index at which rectangular sum is
// same at prime diagonal and other diagonal
void printCellWithSameRectangularArea(int mat[R][C],
                                     int m, int n)
{
    /* sum[i][j] denotes sum of sub-matrix, mat[0][0]
       to mat[i][j]
       sumr[i][j] denotes sum of sub-matrix, mat[i][j]
       to mat[m - 1][n - 1]  */
    int sum[m][n], sumr[m][n];
 
    //  Initialize both sum matrices by mat
    int totalSum = 0;
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < n; j++)
        {
            sumr[i][j] = sum[i][j] = mat[i][j];
            totalSum += mat[i][j];
        }
    }
 
    //  updating first and last row separately
    for (int i = 1; i < m; i++)
    {
        sum[i][0] += sum[i-1][0];
        sumr[m-i-1][n-1] += sumr[m-i][n-1];
    }
 
    //  updating first and last column separately
    for (int j = 1; j < n; j++)
    {
        sum[0][j] += sum[0][j-1];
        sumr[m-1][n-j-1] += sumr[m-1][n-j];
    }
 
    //  updating sum and sumr indices by nearby indices
    for (int i = 1; i < m; i++)
    {
        for (int j = 1; j < n; j++)
        {
            sum[i][j] += sum[i-1][j] + sum[i][j-1] -
                                      sum[i-1][j-1];
            sumr[m-i-1][n-j-1] += sumr[m-i][n-j-1] +
                                  sumr[m-i-1][n-j] -
                                  sumr[m-i][n-j];
        }
    }
 
    //  Uncomment below code to print sum and reverse sum
    // matrix
    /*
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                cout << sum[i][j] << " ";
            }
            cout << endl;
        }
        cout << endl;
        for (int i = 0; i < m; i++)
        {
            for (int j = 0; j < n; j++)
            {
                cout << sumr[i][j] << " ";
            }
            cout << endl;
        }
        cout << endl;    */
 
    /* print all those indices at which sum of prime diagonal
       rectangles is half of the total sum of matrix  */
    for (int i = 0; i < m; i++)
    {
        for (int j = 0; j < n; j++)
        {
            int mainDiagRectangleSum = sum[i][j] + sumr[i][j] -
                                                   mat[i][j];
            if (totalSum == 2 * mainDiagRectangleSum)
                cout << "(" << i << ", " << j << ")" << endl;
        }
    }
}
 
//  Driver code to test above methods
int main()
{
    int mat[R][C] =
    {
        1, 2, 3, 5,
        4, 1, 0, 2,
        0, 1, 2, 0,
        7, 1, 1, 0
    };
 
    printCellWithSameRectangularArea(mat, R, C);
 
    return 0;
}

Time complexity: quadratic
Space complexity: quadratic
// C++ program to print matrix in diagonal order
#include <bits/stdc++.h>
using namespace std;
const int MAX = 100;
 
void printMatrixDiagonal(int mat[MAX][MAX], int n)
{
    // Initialize indexes of element to be printed next
    int i = 0, j = 0;
 
    // Direction is initially from down to up
    bool isUp = true;
 
    // Traverse the matrix till all elements get traversed
    for (int k = 0; k < n * n;) {
        // If isUp = true then traverse from downward
        // to upward
        if (isUp) {
            for (; i >= 0 && j < n; j++, i--) {
                cout << mat[i][j] << " ";
                k++;
            }
 
            // Set i and j according to direction
            if (i < 0 && j <= n - 1)
                i = 0;
            if (j == n)
                i = i + 2, j--;
        }
 
        // If isUp = 0 then traverse up to down
        else {
            for (; j >= 0 && i < n; i++, j--) {
                cout << mat[i][j] << " ";
                k++;
            }
 
            // Set i and j according to direction
            if (j < 0 && i <= n - 1)
                j = 0;
            if (i == n)
                j = j + 2, i--;
        }
 
        // Revert the isUp to change the direction
        isUp = !isUp;
    }
}
 
int main()
{
    int mat[MAX][MAX] = { { 1, 2, 3 },
                          { 4, 5, 6 },
                          { 7, 8, 9 } };
 
    int n = 3;
    printMatrixDiagonal(mat, n);
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ program to print matrix in diagonal order
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    // Initialize matrix
    int mat[][4] = { { 1, 2, 3, 4 },
                     { 5, 6, 7, 8 },
                     { 9, 10, 11, 12 },
                     { 13, 14, 15, 16 } };
    // n - size
    // mode - switch to derive up/down traversal
    // it - iterator count - increases until it
    // reaches n and then decreases
    int n = 4, mode = 0, it = 0, lower = 0;
 
    // 2n will be the number of iterations
    for (int t = 0; t < (2 * n - 1); t++) {
        int t1 = t;
        if (t1 >= n) {
            mode++;
            t1 = n - 1;
            it--;
            lower++;
        }
        else {
            lower = 0;
            it++;
        }
        for (int i = t1; i >= lower; i--) {
            if ((t1 + mode) % 2 == 0) {
                cout << (mat[i][t1 + lower - i]) << endl;
            }
            else {
                cout << (mat[t1 + lower - i][i]) << endl;
            }
        }
    }
    return 0;
}
 
// This code is contributed by princiraj1992

Time complexity: quadratic
Space complexity: constant
// C++ program to find maximum difference of sum of
// elements of two rows
#include<bits/stdc++.h>
#define MAX 100
using namespace std;
 
// Function to find maximum difference of sum of
// elements of two rows such that second row appears
// before first row.
int maxRowDiff(int mat[][MAX], int m, int n)
{
    // auxiliary array to store sum of all elements
    // of each row
    int rowSum[m];
 
    // calculate sum of each row and store it in
    // rowSum array
    for (int i=0; i<m; i++)
    {
        int sum = 0;
        for (int j=0; j<n; j++)
            sum += mat[i][j];
        rowSum[i] = sum;
    }
 
    // calculating maximum difference of two elements
    // such that rowSum[i]<rowsum[j]
    int max_diff = rowSum[1] - rowSum[0];
    int min_element = rowSum[0];
    for (int i=1; i<m; i++)
    {
        // if current difference is greater than
        // previous then update it
        if (rowSum[i] - min_element > max_diff)
            max_diff = rowSum[i] - min_element;
 
        // if new element is less than previous minimum
        // element then update it so that
        // we may get maximum difference in remaining array
        if (rowSum[i] < min_element)
            min_element = rowSum[i];
    }
 
    return max_diff;
}
 
// Driver program to run the case
int main()
{
    int m = 5, n = 4;
    int mat[][MAX] = {{-1, 2, 3, 4},
                     {5, 3, -2, 1},
                     {6, 7, 2, -3},
                     {2, 9, 1, 4},
                     {2, 1, -2, 0}};
 
    cout << maxRowDiff(mat, m, n);
    return 0;
}

Time complexity: quadratic
Space complexity: linear
//  C++ program to get total coverage of all zeros in
// a binary matrix
#include <bits/stdc++.h>
using namespace std;
#define R 4
#define C 4
 
// Returns total coverage of all zeros in mat[][]
int getTotalCoverageOfMatrix(int mat[R][C])
{
    int res = 0;
 
    //  looping for all rows of matrix
    for (int i = 0; i < R; i++)
    {
        bool isOne = false;  // 1 is not seen yet
 
        // looping in columns from left to right
        // direction to get left ones
        for (int j = 0; j < C; j++)
        {
            // If one is found from left
            if (mat[i][j] == 1)
                isOne = true;
 
            // If 0 is found and we have found
            // a 1 before.
            else if (isOne)
                res++;
        }
 
        // Repeat the above process for right to
        // left direction.
        isOne = false;
        for (int j = C-1; j >= 0; j--)
        {
            if (mat[i][j] == 1)
                isOne = true;
            else if (isOne)
                res++;
        }
    }
 
    // Traversing across columns for up and down
    // directions.
    for (int j = 0; j < C; j++)
    {
        bool isOne = false;  // 1 is not seen yet
        for (int i = 0; i < R; i++)
        {
            if (mat[i][j] == 1)
                isOne = true;
            else if (isOne)
                res++;
        }
 
        isOne = false;
        for (int i = R-1; i >= 0; i--)
        {
            if (mat[i][j] == 1)
                isOne = true;
            else if (isOne)
                res++;
        }
    }
    return res;
}
 
//  Driver code to test above methods
int main()
{
    int mat[R][C] = {{0, 0, 0, 0},
        {1, 0, 0, 1},
        {0, 1, 1, 0},
        {0, 1, 0, 0}
    };
 
    cout << getTotalCoverageOfMatrix(mat);
 
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ program to find number of sorted rows
#include <bits/stdc++.h>
#define MAX 100
using namespace std;
 
// Function to count all sorted rows in a matrix
int sortedCount(int mat[][MAX], int r, int c)
{
    int result = 0; // Initialize result
 
    // Start from left side of matrix to
    // count increasing order rows
    for (int i=0; i<r; i++)
    {
        // Check if there is any pair ofs element
        // that are  not in increasing order.
        int j;
        for (j=0; j<c-1; j++)
            if (mat[i][j+1] <= mat[i][j])
                break;
 
        // If the loop didn't break (All elements
        // of current row were in increasing order)
        if (j == c-1)
            result++;
    }
 
    // Start from right side of matrix to
    // count increasing order rows ( reference
    // to left these are in decreasing order )
    for (int i=0; i<r; i++)
    {
        // Check if there is any pair ofs element
        // that are  not in decreasing order.
        int j;
        for (j=c-1; j>0; j--)
            if (mat[i][j-1] <= mat[i][j])
                break;
 
        // Note c > 1 condition is required to make
        // sure that a single column row is not counted
        // twice (Note that a single column row is sorted
        // both in increasing and decreasing order)
        if (c > 1 && j == 0)
            result++;
    }
    return result;
}
 
// Driver program to run the case
int main()
{
    int m = 4, n = 5;
    int mat[][MAX] = {{1, 2, 3, 4, 5},
                      {4, 3, 1, 2, 6},
                      {8, 7, 6, 5, 4},
                      {5, 7, 8, 9, 10}};
    cout << sortedCount(mat, m, n);
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ program to Find maximum XOR value in
// matrix either row / column wise
#include<iostream>
using namespace std;
 
// maximum number of row and column
const int MAX = 1000;
 
// function return the maximum xor value that is
// either row or column wise
int maxXOR(int mat[][MAX], int N)
{
    // for row xor and column xor
    int r_xor, c_xor;
    int max_xor = 0;
 
    // traverse matrix
    for (int i = 0 ; i < N ; i++)
    {
        r_xor = 0, c_xor = 0;
        for (int j = 0 ; j < N ; j++)
        {
            // xor row element
            r_xor = r_xor^mat[i][j];
 
            // for each column : j is act as row & i
            // act as column xor column element
            c_xor = c_xor^mat[j][i];
        }
 
        // update maximum between r_xor , c_xor
        if (max_xor < max(r_xor, c_xor))
            max_xor = max(r_xor, c_xor);
    }
 
    // return maximum xor value
    return max_xor;
}
 
// driver Code
int main()
{
    int N = 3;
 
    int mat[][MAX] = {{1 , 5, 4},
                      {3 , 7, 2 },
                      {5 , 9, 10}
    };
 
    cout << "maximum XOR value : "
         << maxXOR(mat, N);
    return 0;
}

Time complexity: quadratic
Space complexity: constant
// C++ program to find how many mirror can transfer
// light from bottom to right
#include <bits/stdc++.h>
using namespace std;
 
// method returns number of mirror which can transfer
// light from bottom to right
int maximumMirrorInMatrix(string mat[], int N)
{
    // To store first obstacles horizontally (from right)
    // and vertically (from bottom)
    int horizontal[N], vertical[N];
 
    // initialize both array as -1, signifying no obstacle
    memset(horizontal, -1, sizeof(horizontal));
    memset(vertical, -1, sizeof(vertical));
 
    // looping matrix to mark column for obstacles
    for (int i=0; i<N; i++)
    {
        for (int j=N-1; j>=0; j--)
        {
            if (mat[i][j] == 'B')
                continue;
 
            // mark rightmost column with obstacle
            horizontal[i] = j;
            break;
        }
    }
 
    // looping matrix to mark rows for obstacles
    for (int j=0; j<N; j++)
    {
        for (int i=N-1; i>=0; i--)
        {
            if (mat[i][j] == 'B')
                continue;
 
            // mark leftmost row with obstacle
            vertical[j] = i;
            break;
        }
    }
 
    int res = 0; // Initialize result
 
    // if there is not obstacle on right or below,
    // then mirror can be placed to transfer light
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            /* if i > vertical[j] then light can from bottom
               if j > horizontal[i] then light can go to right */
            if (i > vertical[j] && j > horizontal[i])
            {
                /* uncomment this code to print actual mirror
                   position also
                cout << i << " " << j << endl; */
                res++;
            }
        }
    }
 
    return res;
}
 
//  Driver code to test above method
int main()
{
    int N = 5;
 
    //  B - Blank     O - Obstacle
    string mat[N] = {"BBOBB",
                     "BBBBO",
                     "BBBBB",
                     "BOOBO",
                     "BBBOB"
                    };
 
    cout << maximumMirrorInMatrix(mat, N) << endl;
 
    return 0;
}

Time complexity: quadratic
Space complexity: linear
// C++ program to tell the Current direction in
// R x C grid
#include <iostream>
using namespace std;
typedef long long int ll;
 
// Function which tells the Current direction
void direction(ll R, ll C)
{
    if (R != C && R % 2 == 0 && C % 2 != 0 && R < C) {
        cout << "Left" << endl;
        return;
    }
    if (R != C && R % 2 != 0 && C % 2 == 0 && R > C) {
        cout << "Up" << endl;
        return;
    }
    if (R == C && R % 2 != 0 && C % 2 != 0) {
        cout << "Right" << endl;
        return;
    }
    if (R == C && R % 2 == 0 && C % 2 == 0) {
        cout << "Left" << endl;
        return;
    }
    if (R != C && R % 2 != 0 && C % 2 != 0 && R < C) {
        cout << "Right" << endl;
        return;
    }
    if (R != C && R % 2 != 0 && C % 2 != 0 && R > C) {
        cout << "Down" << endl;
        return;
    }
    if (R != C && R % 2 == 0 && C % 2 == 0 && R < C) {
        cout << "Left" << endl;
        return;
    }
    if (R != C && R % 2 == 0 && C % 2 == 0 && R > C) {
        cout << "Up" << endl;
        return;
    }
    if (R != C && R % 2 == 0 && C % 2 != 0 && R > C) {
        cout << "Down" << endl;
        return;
    }
    if (R != C && R % 2 != 0 && C % 2 == 0 && R < C) {
        cout << "Right" << endl;
        return;
    }
}
 
// Driver program to test the Cases
int main()
{
    ll R = 3, C = 1;
    direction(R, C);
    return 0;
}

Time complexity: constant
Space complexity: constant