
#include<iostream.h>
using namespace std;
int main(){ int m,n,a[100][100],b[100][100],s[100][100],t=0;
    cout<<"nhap so hang n="; cin>>n;
    cout<<"nhap vao so cot m="; cin>>m;
    
    for(int i=0;i<n;i++)
       for(int j=0;j<m;j++)
           {cout<<"a["<<i+1<<"]["<<j+1<<"]="; 
            cin>>a[i][j];
            }
    for(int i=0;i<n;i++)
       for(int j=0;j<m;j++)
           {cout<<"b["<<i+1<<"]["<<j+1<<"]=";
            cin>>b[i][j];
           }
    
    cout<<"ma tran tong:\n";
    for(int i=0;i<n;i++)
      {for(int j=0;j<m;j++)
               {s[i][j]=a[i][j]+b[i][j];
                cout<<" "<<s[i][j];
                }
      cout<<"\n";
      }
    
    //"ma tran doi dau";  
    for(int i=0;i<n;i++)
      for(int j=0;j<m;j++)
           if(s[i][j]<0) s[i][j]=s[i][j]*(-1);
    
      
    //"sap xep ma tran";
    for(int i=0;i<m-1;i++)
     for(int j=i+1;j<m;j++)
       if(s[0][i]>s[0][j]){t=s[0][i];
                            s[0][i]=s[0][j];
                            s[0][j]=t;
                           }
    for(int i=0;i<n;i++)
     {for(int j=0;j<m;j++)
              cout<<" "<<s[i][j];
     cout<<"\n";
     }
       
    int tong=0;
    for(int i=0;i<m-1;i++)
     for(int j=i+1;j<m;j++)
      tong=tong+s[i][j];
    cout<<"\n tong cac phan tu: "<<tong;
          
    system("pause");
    return 0;
    }
