#include <iostream>
using namespace std;
void cit_afis_mat(int a[][100], int& n, int& m)
{
int b[100];
cin >> n >> m;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
cin >> a[i][j];
}
}
cout << endl;
for (int i = 0; i < n; ++i)
{
for (int j = 0; j < m; ++j)
{
cout << a[i][j] << " ";
}
cout << endl;
}
cout << endl;
for (int i = 0; i < n; ++i)
{
int s = 0;
for (int j = 0; j < m; ++j)
{
b[j] = a[i][j];
s += b[j];
}
cout << s << " ";
}
}
int main()
{
int n, m, a[100][100];
cit_afis_mat(a, n, m);
return 0;
}