import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws IOException
	{
		int i,j,n,m;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );

		String[] nm = br.readLine().split(" ");

		n = Integer.parseInt(nm[0]);//input n
		m = Integer.parseInt(nm[1]);//input m

		int[][] matrix = new int[n][m];
		int[] vsum = new int[m];
		int sum=0;

		for(i=0; i<n; i++)//get matrix
		{
			String[] str = br.readLine().split(" ");

			for(j=0; j<m; j++)
			{
				matrix[i][j] = Integer.parseInt(str[j]);
			}
		}

		for(i=0; i<m; i++)//print reverse
		{
			for(j=0; j<n; j++)
			{
//				System.out.print(matrix[j][i] + " ");
				vsum[i] += matrix[j][i];
			}

//			System.out.println(vsum[i]);
		}

		for(i=0; i<n; i++)//printf
		{
			for(j=0; j<m; j++)
			{
				System.out.print(matrix[i][j] + " ");
				sum += matrix[i][j];
			}

			System.out.println(sum);
			sum = 0;
		}

		for(i=0; i<m; i++)
		{
			System.out.print(vsum[i] + " ");
			sum += vsum[i];
		}

		System.out.println(sum);
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main{

	public static void main(String[] args) throws IOException
	{
		int i,j,n,m;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );

		String[] nm = br.readLine().split(" ");

		n = Integer.parseInt(nm[0]);//input n
		m = Integer.parseInt(nm[1]);//input m

		int[][] matrix = new int[n][m];
		int[] vsum = new int[m];
		int sum=0;

		for(i=0; i<n; i++)//get matrix
		{
			String[] str = br.readLine().split(" ");

			for(j=0; j<m; j++)
			{
				matrix[i][j] = Integer.parseInt(str[j]);
			}
		}

		for(i=0; i<m; i++)//print reverse
		{
			for(j=0; j<n; j++)
			{
//				System.out.print(matrix[j][i] + " ");
				vsum[i] += matrix[j][i];
			}

//			System.out.println(vsum[i]);
		}

		for(i=0; i<n; i++)//printf
		{
			for(j=0; j<m; j++)
			{
				System.out.print(matrix[i][j] + " ");
				sum += matrix[i][j];
			}

			System.out.println(sum);
			sum = 0;
		}

		for(i=0; i<m; i++)
		{
			System.out.print(vsum[i] + " ");
			sum += vsum[i];
		}

		System.out.println(sum);
	}

} Main public static void main(String[] args) throws IOException
	{
		int i,j,n,m;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );

		String[] nm = br.readLine().split(" ");

		n = Integer.parseInt(nm[0]);//input n
		m = Integer.parseInt(nm[1]);//input m

		int[][] matrix = new int[n][m];
		int[] vsum = new int[m];
		int sum=0;

		for(i=0; i<n; i++)//get matrix
		{
			String[] str = br.readLine().split(" ");

			for(j=0; j<m; j++)
			{
				matrix[i][j] = Integer.parseInt(str[j]);
			}
		}

		for(i=0; i<m; i++)//print reverse
		{
			for(j=0; j<n; j++)
			{
//				System.out.print(matrix[j][i] + " ");
				vsum[i] += matrix[j][i];
			}

//			System.out.println(vsum[i]);
		}

		for(i=0; i<n; i++)//printf
		{
			for(j=0; j<m; j++)
			{
				System.out.print(matrix[i][j] + " ");
				sum += matrix[i][j];
			}

			System.out.println(sum);
			sum = 0;
		}

		for(i=0; i<m; i++)
		{
			System.out.print(vsum[i] + " ");
			sum += vsum[i];
		}

		System.out.println(sum);
	} main {
		int i,j,n,m;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );

		String[] nm = br.readLine().split(" ");

		n = Integer.parseInt(nm[0]);//input n
		m = Integer.parseInt(nm[1]);//input m

		int[][] matrix = new int[n][m];
		int[] vsum = new int[m];
		int sum=0;

		for(i=0; i<n; i++)//get matrix
		{
			String[] str = br.readLine().split(" ");

			for(j=0; j<m; j++)
			{
				matrix[i][j] = Integer.parseInt(str[j]);
			}
		}

		for(i=0; i<m; i++)//print reverse
		{
			for(j=0; j<n; j++)
			{
//				System.out.print(matrix[j][i] + " ");
				vsum[i] += matrix[j][i];
			}

//			System.out.println(vsum[i]);
		}

		for(i=0; i<n; i++)//printf
		{
			for(j=0; j<m; j++)
			{
				System.out.print(matrix[i][j] + " ");
				sum += matrix[i][j];
			}

			System.out.println(sum);
			sum = 0;
		}

		for(i=0; i<m; i++)
		{
			System.out.print(vsum[i] + " ");
			sum += vsum[i];
		}

		System.out.println(sum);
	} int i i j j n n m; m BufferedReader br = new BufferedReader(new InputStreamReader(System.in) ); br new BufferedReader(new InputStreamReader(System.in) ) String[] nm = br.readLine().split(" "); nm br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " n = Integer.parseInt(nm[0]) n Integer.parseInt(nm[0]) Integer.parseInt Integer nm[0] nm 0 m = Integer.parseInt(nm[1]) m Integer.parseInt(nm[1]) Integer.parseInt Integer nm[1] nm 1 int[][] matrix = new int[n][m]; matrix new int[n][m] n m int[] vsum = new int[m]; vsum new int[m] m int sum=0; sum 0 for(i=0; i<n; i++)//get matrix
		{
			String[] str = br.readLine().split(" ");

			for(j=0; j<m; j++)
			{
				matrix[i][j] = Integer.parseInt(str[j]);
			}
		} i=0; i=0 i 0 i<n i n i++ i++ i {
			String[] str = br.readLine().split(" ");

			for(j=0; j<m; j++)
			{
				matrix[i][j] = Integer.parseInt(str[j]);
			}
		} {
			String[] str = br.readLine().split(" ");

			for(j=0; j<m; j++)
			{
				matrix[i][j] = Integer.parseInt(str[j]);
			}
		} String[] str = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(j=0; j<m; j++)
			{
				matrix[i][j] = Integer.parseInt(str[j]);
			} j=0; j=0 j 0 j<m j m j++ j++ j {
				matrix[i][j] = Integer.parseInt(str[j]);
			} {
				matrix[i][j] = Integer.parseInt(str[j]);
			} matrix[i][j] = Integer.parseInt(str[j]) matrix[i][j] matrix[i] matrix i j Integer.parseInt(str[j]) Integer.parseInt Integer str[j] str j for(i=0; i<m; i++)//print reverse
		{
			for(j=0; j<n; j++)
			{
//				System.out.print(matrix[j][i] + " ");
				vsum[i] += matrix[j][i];
			}

//			System.out.println(vsum[i]);
		} i=0; i=0 i 0 i<m i m i++ i++ i {
			for(j=0; j<n; j++)
			{
//				System.out.print(matrix[j][i] + " ");
				vsum[i] += matrix[j][i];
			}

//			System.out.println(vsum[i]);
		} {
			for(j=0; j<n; j++)
			{
//				System.out.print(matrix[j][i] + " ");
				vsum[i] += matrix[j][i];
			}

//			System.out.println(vsum[i]);
		} for(j=0; j<n; j++)
			{
//				System.out.print(matrix[j][i] + " ");
				vsum[i] += matrix[j][i];
			} j=0; j=0 j 0 j<n j n j++ j++ j {
//				System.out.print(matrix[j][i] + " ");
				vsum[i] += matrix[j][i];
			} {
//				System.out.print(matrix[j][i] + " ");
				vsum[i] += matrix[j][i];
			} vsum[i] += matrix[j][i] vsum[i] vsum i matrix[j][i] matrix[j] matrix j i for(i=0; i<n; i++)//printf
		{
			for(j=0; j<m; j++)
			{
				System.out.print(matrix[i][j] + " ");
				sum += matrix[i][j];
			}

			System.out.println(sum);
			sum = 0;
		} i=0; i=0 i 0 i<n i n i++ i++ i {
			for(j=0; j<m; j++)
			{
				System.out.print(matrix[i][j] + " ");
				sum += matrix[i][j];
			}

			System.out.println(sum);
			sum = 0;
		} {
			for(j=0; j<m; j++)
			{
				System.out.print(matrix[i][j] + " ");
				sum += matrix[i][j];
			}

			System.out.println(sum);
			sum = 0;
		} for(j=0; j<m; j++)
			{
				System.out.print(matrix[i][j] + " ");
				sum += matrix[i][j];
			} j=0; j=0 j 0 j<m j m j++ j++ j {
				System.out.print(matrix[i][j] + " ");
				sum += matrix[i][j];
			} {
				System.out.print(matrix[i][j] + " ");
				sum += matrix[i][j];
			} System.out.print(matrix[i][j] + " ") System.out.print System.out System System.out matrix[i][j] + " " matrix[i][j] matrix[i] matrix i j " " sum += matrix[i][j] sum matrix[i][j] matrix[i] matrix i j System.out.println(sum) System.out.println System.out System System.out sum sum = 0 sum 0 for(i=0; i<m; i++)
		{
			System.out.print(vsum[i] + " ");
			sum += vsum[i];
		} i=0; i=0 i 0 i<m i m i++ i++ i {
			System.out.print(vsum[i] + " ");
			sum += vsum[i];
		} {
			System.out.print(vsum[i] + " ");
			sum += vsum[i];
		} System.out.print(vsum[i] + " ") System.out.print System.out System System.out vsum[i] + " " vsum[i] vsum i " " sum += vsum[i] sum vsum[i] vsum i System.out.println(sum) System.out.println System.out System System.out sum String[] args args public class Main{

	public static void main(String[] args) throws IOException
	{
		int i,j,n,m;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );

		String[] nm = br.readLine().split(" ");

		n = Integer.parseInt(nm[0]);//input n
		m = Integer.parseInt(nm[1]);//input m

		int[][] matrix = new int[n][m];
		int[] vsum = new int[m];
		int sum=0;

		for(i=0; i<n; i++)//get matrix
		{
			String[] str = br.readLine().split(" ");

			for(j=0; j<m; j++)
			{
				matrix[i][j] = Integer.parseInt(str[j]);
			}
		}

		for(i=0; i<m; i++)//print reverse
		{
			for(j=0; j<n; j++)
			{
//				System.out.print(matrix[j][i] + " ");
				vsum[i] += matrix[j][i];
			}

//			System.out.println(vsum[i]);
		}

		for(i=0; i<n; i++)//printf
		{
			for(j=0; j<m; j++)
			{
				System.out.print(matrix[i][j] + " ");
				sum += matrix[i][j];
			}

			System.out.println(sum);
			sum = 0;
		}

		for(i=0; i<m; i++)
		{
			System.out.print(vsum[i] + " ");
			sum += vsum[i];
		}

		System.out.println(sum);
	}

} public class Main{

	public static void main(String[] args) throws IOException
	{
		int i,j,n,m;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );

		String[] nm = br.readLine().split(" ");

		n = Integer.parseInt(nm[0]);//input n
		m = Integer.parseInt(nm[1]);//input m

		int[][] matrix = new int[n][m];
		int[] vsum = new int[m];
		int sum=0;

		for(i=0; i<n; i++)//get matrix
		{
			String[] str = br.readLine().split(" ");

			for(j=0; j<m; j++)
			{
				matrix[i][j] = Integer.parseInt(str[j]);
			}
		}

		for(i=0; i<m; i++)//print reverse
		{
			for(j=0; j<n; j++)
			{
//				System.out.print(matrix[j][i] + " ");
				vsum[i] += matrix[j][i];
			}

//			System.out.println(vsum[i]);
		}

		for(i=0; i<n; i++)//printf
		{
			for(j=0; j<m; j++)
			{
				System.out.print(matrix[i][j] + " ");
				sum += matrix[i][j];
			}

			System.out.println(sum);
			sum = 0;
		}

		for(i=0; i<m; i++)
		{
			System.out.print(vsum[i] + " ");
			sum += vsum[i];
		}

		System.out.println(sum);
	}

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws IOException
	{
		int i,j,n,m;

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in) );

		String[] nm = br.readLine().split(" ");

		n = Integer.parseInt(nm[0]);//input n
		m = Integer.parseInt(nm[1]);//input m

		int[][] matrix = new int[n][m];
		int[] vsum = new int[m];
		int sum=0;

		for(i=0; i<n; i++)//get matrix
		{
			String[] str = br.readLine().split(" ");

			for(j=0; j<m; j++)
			{
				matrix[i][j] = Integer.parseInt(str[j]);
			}
		}

		for(i=0; i<m; i++)//print reverse
		{
			for(j=0; j<n; j++)
			{
//				System.out.print(matrix[j][i] + " ");
				vsum[i] += matrix[j][i];
			}

//			System.out.println(vsum[i]);
		}

		for(i=0; i<n; i++)//printf
		{
			for(j=0; j<m; j++)
			{
				System.out.print(matrix[i][j] + " ");
				sum += matrix[i][j];
			}

			System.out.println(sum);
			sum = 0;
		}

		for(i=0; i<m; i++)
		{
			System.out.print(vsum[i] + " ");
			sum += vsum[i];
		}

		System.out.println(sum);
	}

}