import java.io.*;
import java.util.Arrays;

public class Main{
	public static void main(String[] args) throws IOException{ 
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line1 = br.readLine();
		String[] spl = line1.split(" ");
		int r = Integer.parseInt(spl[0]);
		int c = Integer.parseInt(spl[1]);
		int[][] a = new int[r+1][c+1];
		for (int i = 0 ; i<r ; i++ ) {
			String line = br.readLine();
			String[] str = line.split(" ");
			for (int j = 0; j<c ; j++ ) {
				a[i][j] = Integer.parseInt(str[j]);
				a[i][c] += Integer.parseInt(str[j]);
				a[r][j] += Integer.parseInt(str[j]);
				a[r][c] += Integer.parseInt(str[j]);
			}	
		}
		for (int i = 0; i<r+1 ;i++ ) {
			for (int j = 0; j<c ;j++ ) {
				System.out.print(a[i][j]+" ");
			}
			System.out.println(a[i][c]);
		}
		
		
	}
} import java.io.*; io.* java import java.util.Arrays; Arrays java.util public class Main{
	public static void main(String[] args) throws IOException{ 
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line1 = br.readLine();
		String[] spl = line1.split(" ");
		int r = Integer.parseInt(spl[0]);
		int c = Integer.parseInt(spl[1]);
		int[][] a = new int[r+1][c+1];
		for (int i = 0 ; i<r ; i++ ) {
			String line = br.readLine();
			String[] str = line.split(" ");
			for (int j = 0; j<c ; j++ ) {
				a[i][j] = Integer.parseInt(str[j]);
				a[i][c] += Integer.parseInt(str[j]);
				a[r][j] += Integer.parseInt(str[j]);
				a[r][c] += Integer.parseInt(str[j]);
			}	
		}
		for (int i = 0; i<r+1 ;i++ ) {
			for (int j = 0; j<c ;j++ ) {
				System.out.print(a[i][j]+" ");
			}
			System.out.println(a[i][c]);
		}
		
		
	}
} Main public static void main(String[] args) throws IOException{ 
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line1 = br.readLine();
		String[] spl = line1.split(" ");
		int r = Integer.parseInt(spl[0]);
		int c = Integer.parseInt(spl[1]);
		int[][] a = new int[r+1][c+1];
		for (int i = 0 ; i<r ; i++ ) {
			String line = br.readLine();
			String[] str = line.split(" ");
			for (int j = 0; j<c ; j++ ) {
				a[i][j] = Integer.parseInt(str[j]);
				a[i][c] += Integer.parseInt(str[j]);
				a[r][j] += Integer.parseInt(str[j]);
				a[r][c] += Integer.parseInt(str[j]);
			}	
		}
		for (int i = 0; i<r+1 ;i++ ) {
			for (int j = 0; j<c ;j++ ) {
				System.out.print(a[i][j]+" ");
			}
			System.out.println(a[i][c]);
		}
		
		
	} main { 
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line1 = br.readLine();
		String[] spl = line1.split(" ");
		int r = Integer.parseInt(spl[0]);
		int c = Integer.parseInt(spl[1]);
		int[][] a = new int[r+1][c+1];
		for (int i = 0 ; i<r ; i++ ) {
			String line = br.readLine();
			String[] str = line.split(" ");
			for (int j = 0; j<c ; j++ ) {
				a[i][j] = Integer.parseInt(str[j]);
				a[i][c] += Integer.parseInt(str[j]);
				a[r][j] += Integer.parseInt(str[j]);
				a[r][c] += Integer.parseInt(str[j]);
			}	
		}
		for (int i = 0; i<r+1 ;i++ ) {
			for (int j = 0; j<c ;j++ ) {
				System.out.print(a[i][j]+" ");
			}
			System.out.println(a[i][c]);
		}
		
		
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String line1 = br.readLine(); line1 br.readLine() br.readLine br String[] spl = line1.split(" "); spl line1.split(" ") line1.split line1 " " int r = Integer.parseInt(spl[0]); r Integer.parseInt(spl[0]) Integer.parseInt Integer spl[0] spl 0 int c = Integer.parseInt(spl[1]); c Integer.parseInt(spl[1]) Integer.parseInt Integer spl[1] spl 1 int[][] a = new int[r+1][c+1]; a new int[r+1][c+1] r+1 r 1 c+1 c 1 for (int i = 0 ; i<r ; i++ ) {
			String line = br.readLine();
			String[] str = line.split(" ");
			for (int j = 0; j<c ; j++ ) {
				a[i][j] = Integer.parseInt(str[j]);
				a[i][c] += Integer.parseInt(str[j]);
				a[r][j] += Integer.parseInt(str[j]);
				a[r][c] += Integer.parseInt(str[j]);
			}	
		} int i = 0 ; int i = 0 ; i 0 i<r i r i++ i++ i {
			String line = br.readLine();
			String[] str = line.split(" ");
			for (int j = 0; j<c ; j++ ) {
				a[i][j] = Integer.parseInt(str[j]);
				a[i][c] += Integer.parseInt(str[j]);
				a[r][j] += Integer.parseInt(str[j]);
				a[r][c] += Integer.parseInt(str[j]);
			}	
		} {
			String line = br.readLine();
			String[] str = line.split(" ");
			for (int j = 0; j<c ; j++ ) {
				a[i][j] = Integer.parseInt(str[j]);
				a[i][c] += Integer.parseInt(str[j]);
				a[r][j] += Integer.parseInt(str[j]);
				a[r][c] += Integer.parseInt(str[j]);
			}	
		} String line = br.readLine(); line br.readLine() br.readLine br String[] str = line.split(" "); str line.split(" ") line.split line " " for (int j = 0; j<c ; j++ ) {
				a[i][j] = Integer.parseInt(str[j]);
				a[i][c] += Integer.parseInt(str[j]);
				a[r][j] += Integer.parseInt(str[j]);
				a[r][c] += Integer.parseInt(str[j]);
			} int j = 0; int j = 0; j 0 j<c j c j++ j++ j {
				a[i][j] = Integer.parseInt(str[j]);
				a[i][c] += Integer.parseInt(str[j]);
				a[r][j] += Integer.parseInt(str[j]);
				a[r][c] += Integer.parseInt(str[j]);
			} {
				a[i][j] = Integer.parseInt(str[j]);
				a[i][c] += Integer.parseInt(str[j]);
				a[r][j] += Integer.parseInt(str[j]);
				a[r][c] += Integer.parseInt(str[j]);
			} a[i][j] = Integer.parseInt(str[j]) a[i][j] a[i] a i j Integer.parseInt(str[j]) Integer.parseInt Integer str[j] str j a[i][c] += Integer.parseInt(str[j]) a[i][c] a[i] a i c Integer.parseInt(str[j]) Integer.parseInt Integer str[j] str j a[r][j] += Integer.parseInt(str[j]) a[r][j] a[r] a r j Integer.parseInt(str[j]) Integer.parseInt Integer str[j] str j a[r][c] += Integer.parseInt(str[j]) a[r][c] a[r] a r c Integer.parseInt(str[j]) Integer.parseInt Integer str[j] str j for (int i = 0; i<r+1 ;i++ ) {
			for (int j = 0; j<c ;j++ ) {
				System.out.print(a[i][j]+" ");
			}
			System.out.println(a[i][c]);
		} 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 ;j++ ) {
				System.out.print(a[i][j]+" ");
			}
			System.out.println(a[i][c]);
		} {
			for (int j = 0; j<c ;j++ ) {
				System.out.print(a[i][j]+" ");
			}
			System.out.println(a[i][c]);
		} for (int j = 0; j<c ;j++ ) {
				System.out.print(a[i][j]+" ");
			} int j = 0; int j = 0; j 0 j<c j c j++ j++ j {
				System.out.print(a[i][j]+" ");
			} {
				System.out.print(a[i][j]+" ");
			} System.out.print(a[i][j]+" ") System.out.print System.out System System.out a[i][j]+" " a[i][j] a[i] a i j " " System.out.println(a[i][c]) System.out.println System.out System System.out a[i][c] a[i] a i c String[] args args public class Main{
	public static void main(String[] args) throws IOException{ 
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line1 = br.readLine();
		String[] spl = line1.split(" ");
		int r = Integer.parseInt(spl[0]);
		int c = Integer.parseInt(spl[1]);
		int[][] a = new int[r+1][c+1];
		for (int i = 0 ; i<r ; i++ ) {
			String line = br.readLine();
			String[] str = line.split(" ");
			for (int j = 0; j<c ; j++ ) {
				a[i][j] = Integer.parseInt(str[j]);
				a[i][c] += Integer.parseInt(str[j]);
				a[r][j] += Integer.parseInt(str[j]);
				a[r][c] += Integer.parseInt(str[j]);
			}	
		}
		for (int i = 0; i<r+1 ;i++ ) {
			for (int j = 0; j<c ;j++ ) {
				System.out.print(a[i][j]+" ");
			}
			System.out.println(a[i][c]);
		}
		
		
	}
} public class Main{
	public static void main(String[] args) throws IOException{ 
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line1 = br.readLine();
		String[] spl = line1.split(" ");
		int r = Integer.parseInt(spl[0]);
		int c = Integer.parseInt(spl[1]);
		int[][] a = new int[r+1][c+1];
		for (int i = 0 ; i<r ; i++ ) {
			String line = br.readLine();
			String[] str = line.split(" ");
			for (int j = 0; j<c ; j++ ) {
				a[i][j] = Integer.parseInt(str[j]);
				a[i][c] += Integer.parseInt(str[j]);
				a[r][j] += Integer.parseInt(str[j]);
				a[r][c] += Integer.parseInt(str[j]);
			}	
		}
		for (int i = 0; i<r+1 ;i++ ) {
			for (int j = 0; j<c ;j++ ) {
				System.out.print(a[i][j]+" ");
			}
			System.out.println(a[i][c]);
		}
		
		
	}
} Main
import java.io.*;
import java.util.Arrays;

public class Main{
	public static void main(String[] args) throws IOException{ 
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line1 = br.readLine();
		String[] spl = line1.split(" ");
		int r = Integer.parseInt(spl[0]);
		int c = Integer.parseInt(spl[1]);
		int[][] a = new int[r+1][c+1];
		for (int i = 0 ; i<r ; i++ ) {
			String line = br.readLine();
			String[] str = line.split(" ");
			for (int j = 0; j<c ; j++ ) {
				a[i][j] = Integer.parseInt(str[j]);
				a[i][c] += Integer.parseInt(str[j]);
				a[r][j] += Integer.parseInt(str[j]);
				a[r][c] += Integer.parseInt(str[j]);
			}	
		}
		for (int i = 0; i<r+1 ;i++ ) {
			for (int j = 0; j<c ;j++ ) {
				System.out.print(a[i][j]+" ");
			}
			System.out.println(a[i][c]);
		}
		
		
	}
}