Problem Description: Simon work with Greek squares and matrix traces. The trace of a square matrix is the sum of the values on the main diagonal (which runs from the upper left to the lower right). An B-by-B square matrix is a Greek square if each cell contains one of B different values, and no value is repeated within a row or a column. In this problem, we will deal only with "beautiful Greek squares" in which the B values are the integers between 1 and B. Given a matrix that contains only integers between 1 and B, we want to compute its trace and check whether it is a beautiful Greek square. To give some additional information, instead of simply telling us whether the matrix is a beautiful Greek square or not, show the number of rows and the number of columns that contain repeated values.
C Program


#include<stdio.h>

int g[105][105];

int checkRow(int n,int r)

{

    int seen[105]={0};

    for(int j=0;j<n;j++)

        if(seen[g[r][j]]++) return 1;

    return 0;

}

int checkCol(int n,int c)

{

    int seen[105]={0};

    for(int i=0;i<n;i++)

        if(seen[g[i][c]]++) return 1;

    return 0;

}

void solve()

{

    int n;

    scanf("%d",&n);

    int trace=0,row=0,col=0;

    for(int i = 0;i < n;i++)

        for(int j = 0;j < n;j++)

            scanf("%d",&g[i][j]);

    for(int i=0;i<n;i++)

        trace += g[i][i];

    for(int i=0;i<n;i++)

        row += checkRow(n,i);

    for(int i=0;i<n;i++)

        col += checkCol(n,i);

    printf("%d %d %d\n",trace,row,col);

}

int main()

{

    int T;

    scanf("%d",&T);

    while(T--)

        solve();

    return 0;

}