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

public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
    	String[] n = br.readLine().split(" ");
        int r = Integer.parseInt(n[0]);
        int c = Integer.parseInt(n[1]);
        int[][] rc = new int[r][c];
        int[] yoko = new int[r];
        int[] tate = new int[c];
        int sum = 0;
        for (int i = 0; i < r; i++)
        {
        	String[] rcinput = br.readLine().split(" ");
        	for (int j = 0; j < c; j++)
        	{
        		rc[i][j] = Integer.parseInt(rcinput[j]);
        		yoko[i] += Integer.parseInt(rcinput[j]);
        		tate[j] += Integer.parseInt(rcinput[j]);
        		sum += Integer.parseInt(rcinput[j]);
        	}
        }
        
        for (int i = 0; i < r + 1; i++)
        {
        	for (int j = 0; j < c + 1; j++)
        	{
        		if (i < r && j <c)
        			System.out.print(rc[i][j] + " ");
        		else if (j == c && i != r)
        			System.out.println(yoko[i]);
        		else if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum);
        	}
        }
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
    	String[] n = br.readLine().split(" ");
        int r = Integer.parseInt(n[0]);
        int c = Integer.parseInt(n[1]);
        int[][] rc = new int[r][c];
        int[] yoko = new int[r];
        int[] tate = new int[c];
        int sum = 0;
        for (int i = 0; i < r; i++)
        {
        	String[] rcinput = br.readLine().split(" ");
        	for (int j = 0; j < c; j++)
        	{
        		rc[i][j] = Integer.parseInt(rcinput[j]);
        		yoko[i] += Integer.parseInt(rcinput[j]);
        		tate[j] += Integer.parseInt(rcinput[j]);
        		sum += Integer.parseInt(rcinput[j]);
        	}
        }
        
        for (int i = 0; i < r + 1; i++)
        {
        	for (int j = 0; j < c + 1; j++)
        	{
        		if (i < r && j <c)
        			System.out.print(rc[i][j] + " ");
        		else if (j == c && i != r)
        			System.out.println(yoko[i]);
        		else if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum);
        	}
        }
	}

} Main public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
    	String[] n = br.readLine().split(" ");
        int r = Integer.parseInt(n[0]);
        int c = Integer.parseInt(n[1]);
        int[][] rc = new int[r][c];
        int[] yoko = new int[r];
        int[] tate = new int[c];
        int sum = 0;
        for (int i = 0; i < r; i++)
        {
        	String[] rcinput = br.readLine().split(" ");
        	for (int j = 0; j < c; j++)
        	{
        		rc[i][j] = Integer.parseInt(rcinput[j]);
        		yoko[i] += Integer.parseInt(rcinput[j]);
        		tate[j] += Integer.parseInt(rcinput[j]);
        		sum += Integer.parseInt(rcinput[j]);
        	}
        }
        
        for (int i = 0; i < r + 1; i++)
        {
        	for (int j = 0; j < c + 1; j++)
        	{
        		if (i < r && j <c)
        			System.out.print(rc[i][j] + " ");
        		else if (j == c && i != r)
        			System.out.println(yoko[i]);
        		else if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum);
        	}
        }
	} main {
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
    	String[] n = br.readLine().split(" ");
        int r = Integer.parseInt(n[0]);
        int c = Integer.parseInt(n[1]);
        int[][] rc = new int[r][c];
        int[] yoko = new int[r];
        int[] tate = new int[c];
        int sum = 0;
        for (int i = 0; i < r; i++)
        {
        	String[] rcinput = br.readLine().split(" ");
        	for (int j = 0; j < c; j++)
        	{
        		rc[i][j] = Integer.parseInt(rcinput[j]);
        		yoko[i] += Integer.parseInt(rcinput[j]);
        		tate[j] += Integer.parseInt(rcinput[j]);
        		sum += Integer.parseInt(rcinput[j]);
        	}
        }
        
        for (int i = 0; i < r + 1; i++)
        {
        	for (int j = 0; j < c + 1; j++)
        	{
        		if (i < r && j <c)
        			System.out.print(rc[i][j] + " ");
        		else if (j == c && i != r)
        			System.out.println(yoko[i]);
        		else if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum);
        	}
        }
	} InputStreamReader isr = new InputStreamReader(System.in); isr new InputStreamReader(System.in) BufferedReader br = new BufferedReader(isr); br new BufferedReader(isr) String[] n = br.readLine().split(" "); n br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int r = Integer.parseInt(n[0]); r Integer.parseInt(n[0]) Integer.parseInt Integer n[0] n 0 int c = Integer.parseInt(n[1]); c Integer.parseInt(n[1]) Integer.parseInt Integer n[1] n 1 int[][] rc = new int[r][c]; rc new int[r][c] r c int[] yoko = new int[r]; yoko new int[r] r int[] tate = new int[c]; tate new int[c] c int sum = 0; sum 0 for (int i = 0; i < r; i++)
        {
        	String[] rcinput = br.readLine().split(" ");
        	for (int j = 0; j < c; j++)
        	{
        		rc[i][j] = Integer.parseInt(rcinput[j]);
        		yoko[i] += Integer.parseInt(rcinput[j]);
        		tate[j] += Integer.parseInt(rcinput[j]);
        		sum += Integer.parseInt(rcinput[j]);
        	}
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
        	String[] rcinput = br.readLine().split(" ");
        	for (int j = 0; j < c; j++)
        	{
        		rc[i][j] = Integer.parseInt(rcinput[j]);
        		yoko[i] += Integer.parseInt(rcinput[j]);
        		tate[j] += Integer.parseInt(rcinput[j]);
        		sum += Integer.parseInt(rcinput[j]);
        	}
        } {
        	String[] rcinput = br.readLine().split(" ");
        	for (int j = 0; j < c; j++)
        	{
        		rc[i][j] = Integer.parseInt(rcinput[j]);
        		yoko[i] += Integer.parseInt(rcinput[j]);
        		tate[j] += Integer.parseInt(rcinput[j]);
        		sum += Integer.parseInt(rcinput[j]);
        	}
        } String[] rcinput = br.readLine().split(" "); rcinput br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for (int j = 0; j < c; j++)
        	{
        		rc[i][j] = Integer.parseInt(rcinput[j]);
        		yoko[i] += Integer.parseInt(rcinput[j]);
        		tate[j] += Integer.parseInt(rcinput[j]);
        		sum += Integer.parseInt(rcinput[j]);
        	} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
        		rc[i][j] = Integer.parseInt(rcinput[j]);
        		yoko[i] += Integer.parseInt(rcinput[j]);
        		tate[j] += Integer.parseInt(rcinput[j]);
        		sum += Integer.parseInt(rcinput[j]);
        	} {
        		rc[i][j] = Integer.parseInt(rcinput[j]);
        		yoko[i] += Integer.parseInt(rcinput[j]);
        		tate[j] += Integer.parseInt(rcinput[j]);
        		sum += Integer.parseInt(rcinput[j]);
        	} rc[i][j] = Integer.parseInt(rcinput[j]) rc[i][j] rc[i] rc i j Integer.parseInt(rcinput[j]) Integer.parseInt Integer rcinput[j] rcinput j yoko[i] += Integer.parseInt(rcinput[j]) yoko[i] yoko i Integer.parseInt(rcinput[j]) Integer.parseInt Integer rcinput[j] rcinput j tate[j] += Integer.parseInt(rcinput[j]) tate[j] tate j Integer.parseInt(rcinput[j]) Integer.parseInt Integer rcinput[j] rcinput j sum += Integer.parseInt(rcinput[j]) sum Integer.parseInt(rcinput[j]) Integer.parseInt Integer rcinput[j] rcinput j for (int i = 0; i < r + 1; i++)
        {
        	for (int j = 0; j < c + 1; j++)
        	{
        		if (i < r && j <c)
        			System.out.print(rc[i][j] + " ");
        		else if (j == c && i != r)
        			System.out.println(yoko[i]);
        		else if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum);
        	}
        } int i = 0; int i = 0; i 0 i < r + 1 i r + 1 r 1 i++ i++ i {
        	for (int j = 0; j < c + 1; j++)
        	{
        		if (i < r && j <c)
        			System.out.print(rc[i][j] + " ");
        		else if (j == c && i != r)
        			System.out.println(yoko[i]);
        		else if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum);
        	}
        } {
        	for (int j = 0; j < c + 1; j++)
        	{
        		if (i < r && j <c)
        			System.out.print(rc[i][j] + " ");
        		else if (j == c && i != r)
        			System.out.println(yoko[i]);
        		else if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum);
        	}
        } for (int j = 0; j < c + 1; j++)
        	{
        		if (i < r && j <c)
        			System.out.print(rc[i][j] + " ");
        		else if (j == c && i != r)
        			System.out.println(yoko[i]);
        		else if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum);
        	} int j = 0; int j = 0; j 0 j < c + 1 j c + 1 c 1 j++ j++ j {
        		if (i < r && j <c)
        			System.out.print(rc[i][j] + " ");
        		else if (j == c && i != r)
        			System.out.println(yoko[i]);
        		else if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum);
        	} {
        		if (i < r && j <c)
        			System.out.print(rc[i][j] + " ");
        		else if (j == c && i != r)
        			System.out.println(yoko[i]);
        		else if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum);
        	} if (i < r && j <c)
        			System.out.print(rc[i][j] + " ");
        		else if (j == c && i != r)
        			System.out.println(yoko[i]);
        		else if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum); i < r && j <c i < r i r j <c j c System.out.print(rc[i][j] + " ") System.out.print System.out System System.out rc[i][j] + " " rc[i][j] rc[i] rc i j " " if (j == c && i != r)
        			System.out.println(yoko[i]);
        		else if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum); j == c && i != r j == c j c i != r i r System.out.println(yoko[i]) System.out.println System.out System System.out yoko[i] yoko i if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum); i == r && j != c i == r i r j != c j c System.out.print(tate[j] + " ") System.out.print System.out System System.out tate[j] + " " tate[j] tate j " " if (i == r && j == c)
        			System.out.println(sum); i == r && j == c i == r i r j == c j c 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 Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
    	String[] n = br.readLine().split(" ");
        int r = Integer.parseInt(n[0]);
        int c = Integer.parseInt(n[1]);
        int[][] rc = new int[r][c];
        int[] yoko = new int[r];
        int[] tate = new int[c];
        int sum = 0;
        for (int i = 0; i < r; i++)
        {
        	String[] rcinput = br.readLine().split(" ");
        	for (int j = 0; j < c; j++)
        	{
        		rc[i][j] = Integer.parseInt(rcinput[j]);
        		yoko[i] += Integer.parseInt(rcinput[j]);
        		tate[j] += Integer.parseInt(rcinput[j]);
        		sum += Integer.parseInt(rcinput[j]);
        	}
        }
        
        for (int i = 0; i < r + 1; i++)
        {
        	for (int j = 0; j < c + 1; j++)
        	{
        		if (i < r && j <c)
        			System.out.print(rc[i][j] + " ");
        		else if (j == c && i != r)
        			System.out.println(yoko[i]);
        		else if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum);
        	}
        }
	}

} public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
    	String[] n = br.readLine().split(" ");
        int r = Integer.parseInt(n[0]);
        int c = Integer.parseInt(n[1]);
        int[][] rc = new int[r][c];
        int[] yoko = new int[r];
        int[] tate = new int[c];
        int sum = 0;
        for (int i = 0; i < r; i++)
        {
        	String[] rcinput = br.readLine().split(" ");
        	for (int j = 0; j < c; j++)
        	{
        		rc[i][j] = Integer.parseInt(rcinput[j]);
        		yoko[i] += Integer.parseInt(rcinput[j]);
        		tate[j] += Integer.parseInt(rcinput[j]);
        		sum += Integer.parseInt(rcinput[j]);
        	}
        }
        
        for (int i = 0; i < r + 1; i++)
        {
        	for (int j = 0; j < c + 1; j++)
        	{
        		if (i < r && j <c)
        			System.out.print(rc[i][j] + " ");
        		else if (j == c && i != r)
        			System.out.println(yoko[i]);
        		else if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum);
        	}
        }
	}

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

public class Main {
	public static void main(String[] args)throws Exception{
		InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        
    	String[] n = br.readLine().split(" ");
        int r = Integer.parseInt(n[0]);
        int c = Integer.parseInt(n[1]);
        int[][] rc = new int[r][c];
        int[] yoko = new int[r];
        int[] tate = new int[c];
        int sum = 0;
        for (int i = 0; i < r; i++)
        {
        	String[] rcinput = br.readLine().split(" ");
        	for (int j = 0; j < c; j++)
        	{
        		rc[i][j] = Integer.parseInt(rcinput[j]);
        		yoko[i] += Integer.parseInt(rcinput[j]);
        		tate[j] += Integer.parseInt(rcinput[j]);
        		sum += Integer.parseInt(rcinput[j]);
        	}
        }
        
        for (int i = 0; i < r + 1; i++)
        {
        	for (int j = 0; j < c + 1; j++)
        	{
        		if (i < r && j <c)
        			System.out.print(rc[i][j] + " ");
        		else if (j == c && i != r)
        			System.out.println(yoko[i]);
        		else if (i == r && j != c)
        			System.out.print(tate[j] + " ");
        		else if (i == r && j == c)
        			System.out.println(sum);
        	}
        }
	}

}