#include <stdio.h>

int main(){
    int a[20][20];
    int m, n;
    printf("nhap m hang: ");
    scanf("%d", &m);
    printf("nhap n cot: ");
    scanf("%d", &n);
    for(int i = 0; i < m; ++i){
        for(int j = 0; j < n; ++j){
            printf("a[%d][%d] = ", i, j);
            scanf("%d", &a[i][j]);
        }
    }
    printf("\nMa tran vua nhap:\n");
    for(int i = 0; i < m; ++i){
        for(int j = 0; j < n; ++j){
            printf("%d ", a[i][j]);
        }
        printf("\n");
    }
    int x;
    int dem =0;
	printf ("nhap x:");
	scanf ("%d",&x);
	for (int i=1;i<=m;i++){
		for (int j=1;j<=n;j++){
			if (x==a[i][j]){
				printf("thay %d o vi hang %d,cot %d\n",x,i+1,j+1);
				dem++;
			}
		}
	}
	if (dem==0){
	 printf ("Khong tim thay %d trong ma tran\n",x );
	}
	if (m == n) {
        int tongCheoChinh = 0;
        int tongCheoPhu = 0;
        printf("\nCac ptu cua duong cheo chinh: ");
        for (int i = 0; i < m; i++) {
            printf("%d ", a[i][i]);
            tongCheoChinh += a[i][i];
        }
        printf("\nTong duong cheo chinh = %d\n", tongCheoChinh);
        printf("Cac phan tu tren duong cheo phu la: ");
        for (int i = 0; i < n; i++) {
            printf("%d ", a[i][n - 1 - i]);
            tongCheoPhu += a[i][n - 1 - i];
        }
        printf("\nTong duong cheo ph? = %d\n", tongCheoPhu);
    } else {
        printf("\nMa tran ko ton tai,ko co duong cheo chinh,duong cheo phu.\n");
    }
    return 0;
}