import java.io.*;
import java.io.IOException;

class Main{
	public static void main(String args[]){
		String[] inp = new String[100];
		String ans = "";
		int sum=0;
		int r,c;
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
		inp = br.readLine().split("[\\s]+");
		r = Integer.parseInt(inp[0]);
		c = Integer.parseInt(inp[1]);
		
		
		int table[][] = new int[r+1][c+1];
		
		for(int i=0;i<r;i++){
			inp = br.readLine().split("[\\s]+");
			
			for(int j=0;j<c;j++){
				table[i][j] = Integer.parseInt(inp[j]);
				sum += table[i][j];
			}
			table[i][c]=sum;
			sum=0;
		}
		
		
		
		for(int j=0;j<c+1;j++){
			sum=0;
			for(int i=0;i<r+1;i++){
				sum += table[i][j];
				
			}
			table[r][j] = sum;
			
		}
		
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				ans +=table[i][j] + " ";
			}
			System.out.println(ans.substring(0, ans.length()-1));
			ans="";
		}
		}catch(IOException e){
			System.out.println(e);
			return;
		}
	}
}
 import java.io.*; io.* java import java.io.IOException; IOException java.io class Main{
	public static void main(String args[]){
		String[] inp = new String[100];
		String ans = "";
		int sum=0;
		int r,c;
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
		inp = br.readLine().split("[\\s]+");
		r = Integer.parseInt(inp[0]);
		c = Integer.parseInt(inp[1]);
		
		
		int table[][] = new int[r+1][c+1];
		
		for(int i=0;i<r;i++){
			inp = br.readLine().split("[\\s]+");
			
			for(int j=0;j<c;j++){
				table[i][j] = Integer.parseInt(inp[j]);
				sum += table[i][j];
			}
			table[i][c]=sum;
			sum=0;
		}
		
		
		
		for(int j=0;j<c+1;j++){
			sum=0;
			for(int i=0;i<r+1;i++){
				sum += table[i][j];
				
			}
			table[r][j] = sum;
			
		}
		
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				ans +=table[i][j] + " ";
			}
			System.out.println(ans.substring(0, ans.length()-1));
			ans="";
		}
		}catch(IOException e){
			System.out.println(e);
			return;
		}
	}
} Main public static void main(String args[]){
		String[] inp = new String[100];
		String ans = "";
		int sum=0;
		int r,c;
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
		inp = br.readLine().split("[\\s]+");
		r = Integer.parseInt(inp[0]);
		c = Integer.parseInt(inp[1]);
		
		
		int table[][] = new int[r+1][c+1];
		
		for(int i=0;i<r;i++){
			inp = br.readLine().split("[\\s]+");
			
			for(int j=0;j<c;j++){
				table[i][j] = Integer.parseInt(inp[j]);
				sum += table[i][j];
			}
			table[i][c]=sum;
			sum=0;
		}
		
		
		
		for(int j=0;j<c+1;j++){
			sum=0;
			for(int i=0;i<r+1;i++){
				sum += table[i][j];
				
			}
			table[r][j] = sum;
			
		}
		
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				ans +=table[i][j] + " ";
			}
			System.out.println(ans.substring(0, ans.length()-1));
			ans="";
		}
		}catch(IOException e){
			System.out.println(e);
			return;
		}
	} main {
		String[] inp = new String[100];
		String ans = "";
		int sum=0;
		int r,c;
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
		inp = br.readLine().split("[\\s]+");
		r = Integer.parseInt(inp[0]);
		c = Integer.parseInt(inp[1]);
		
		
		int table[][] = new int[r+1][c+1];
		
		for(int i=0;i<r;i++){
			inp = br.readLine().split("[\\s]+");
			
			for(int j=0;j<c;j++){
				table[i][j] = Integer.parseInt(inp[j]);
				sum += table[i][j];
			}
			table[i][c]=sum;
			sum=0;
		}
		
		
		
		for(int j=0;j<c+1;j++){
			sum=0;
			for(int i=0;i<r+1;i++){
				sum += table[i][j];
				
			}
			table[r][j] = sum;
			
		}
		
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				ans +=table[i][j] + " ";
			}
			System.out.println(ans.substring(0, ans.length()-1));
			ans="";
		}
		}catch(IOException e){
			System.out.println(e);
			return;
		}
	} String[] inp = new String[100]; inp new String[100] 100 String ans = ""; ans "" int sum=0; sum 0 int r r c; c BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) try{
		inp = br.readLine().split("[\\s]+");
		r = Integer.parseInt(inp[0]);
		c = Integer.parseInt(inp[1]);
		
		
		int table[][] = new int[r+1][c+1];
		
		for(int i=0;i<r;i++){
			inp = br.readLine().split("[\\s]+");
			
			for(int j=0;j<c;j++){
				table[i][j] = Integer.parseInt(inp[j]);
				sum += table[i][j];
			}
			table[i][c]=sum;
			sum=0;
		}
		
		
		
		for(int j=0;j<c+1;j++){
			sum=0;
			for(int i=0;i<r+1;i++){
				sum += table[i][j];
				
			}
			table[r][j] = sum;
			
		}
		
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				ans +=table[i][j] + " ";
			}
			System.out.println(ans.substring(0, ans.length()-1));
			ans="";
		}
		}catch(IOException e){
			System.out.println(e);
			return;
		} catch(IOException e){
			System.out.println(e);
			return;
		} IOException e {
			System.out.println(e);
			return;
		} System.out.println(e) System.out.println System.out System System.out e return; {
		inp = br.readLine().split("[\\s]+");
		r = Integer.parseInt(inp[0]);
		c = Integer.parseInt(inp[1]);
		
		
		int table[][] = new int[r+1][c+1];
		
		for(int i=0;i<r;i++){
			inp = br.readLine().split("[\\s]+");
			
			for(int j=0;j<c;j++){
				table[i][j] = Integer.parseInt(inp[j]);
				sum += table[i][j];
			}
			table[i][c]=sum;
			sum=0;
		}
		
		
		
		for(int j=0;j<c+1;j++){
			sum=0;
			for(int i=0;i<r+1;i++){
				sum += table[i][j];
				
			}
			table[r][j] = sum;
			
		}
		
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				ans +=table[i][j] + " ";
			}
			System.out.println(ans.substring(0, ans.length()-1));
			ans="";
		}
		} inp = br.readLine().split("[\\s]+") inp br.readLine().split("[\\s]+") br.readLine().split br.readLine() br.readLine br "[\\s]+" r = Integer.parseInt(inp[0]) r Integer.parseInt(inp[0]) Integer.parseInt Integer inp[0] inp 0 c = Integer.parseInt(inp[1]) c Integer.parseInt(inp[1]) Integer.parseInt Integer inp[1] inp 1 int table[][] = new int[r+1][c+1]; table new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i=0;i<r;i++){
			inp = br.readLine().split("[\\s]+");
			
			for(int j=0;j<c;j++){
				table[i][j] = Integer.parseInt(inp[j]);
				sum += table[i][j];
			}
			table[i][c]=sum;
			sum=0;
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			inp = br.readLine().split("[\\s]+");
			
			for(int j=0;j<c;j++){
				table[i][j] = Integer.parseInt(inp[j]);
				sum += table[i][j];
			}
			table[i][c]=sum;
			sum=0;
		} {
			inp = br.readLine().split("[\\s]+");
			
			for(int j=0;j<c;j++){
				table[i][j] = Integer.parseInt(inp[j]);
				sum += table[i][j];
			}
			table[i][c]=sum;
			sum=0;
		} inp = br.readLine().split("[\\s]+") inp br.readLine().split("[\\s]+") br.readLine().split br.readLine() br.readLine br "[\\s]+" for(int j=0;j<c;j++){
				table[i][j] = Integer.parseInt(inp[j]);
				sum += table[i][j];
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				table[i][j] = Integer.parseInt(inp[j]);
				sum += table[i][j];
			} {
				table[i][j] = Integer.parseInt(inp[j]);
				sum += table[i][j];
			} table[i][j] = Integer.parseInt(inp[j]) table[i][j] table[i] table i j Integer.parseInt(inp[j]) Integer.parseInt Integer inp[j] inp j sum += table[i][j] sum table[i][j] table[i] table i j table[i][c]=sum table[i][c] table[i] table i c sum sum=0 sum 0 for(int j=0;j<c+1;j++){
			sum=0;
			for(int i=0;i<r+1;i++){
				sum += table[i][j];
				
			}
			table[r][j] = sum;
			
		} int j=0; int j=0; j 0 j<c+1 j c+1 c 1 j++ j++ j {
			sum=0;
			for(int i=0;i<r+1;i++){
				sum += table[i][j];
				
			}
			table[r][j] = sum;
			
		} {
			sum=0;
			for(int i=0;i<r+1;i++){
				sum += table[i][j];
				
			}
			table[r][j] = sum;
			
		} sum=0 sum 0 for(int i=0;i<r+1;i++){
				sum += table[i][j];
				
			} int i=0; int i=0; i 0 i<r+1 i r+1 r 1 i++ i++ i {
				sum += table[i][j];
				
			} {
				sum += table[i][j];
				
			} sum += table[i][j] sum table[i][j] table[i] table i j table[r][j] = sum table[r][j] table[r] table r j sum for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				ans +=table[i][j] + " ";
			}
			System.out.println(ans.substring(0, ans.length()-1));
			ans="";
		} 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++){
				ans +=table[i][j] + " ";
			}
			System.out.println(ans.substring(0, ans.length()-1));
			ans="";
		} {
			for(int j=0;j<c+1;j++){
				ans +=table[i][j] + " ";
			}
			System.out.println(ans.substring(0, ans.length()-1));
			ans="";
		} for(int j=0;j<c+1;j++){
				ans +=table[i][j] + " ";
			} int j=0; int j=0; j 0 j<c+1 j c+1 c 1 j++ j++ j {
				ans +=table[i][j] + " ";
			} {
				ans +=table[i][j] + " ";
			} ans +=table[i][j] + " " ans table[i][j] + " " table[i][j] table[i] table i j " " System.out.println(ans.substring(0, ans.length()-1)) System.out.println System.out System System.out ans.substring(0, ans.length()-1) ans.substring ans 0 ans.length()-1 ans.length() ans.length ans 1 ans="" ans "" String args[] args
import java.io.*;
import java.io.IOException;

class Main{
	public static void main(String args[]){
		String[] inp = new String[100];
		String ans = "";
		int sum=0;
		int r,c;
		
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		try{
		inp = br.readLine().split("[\\s]+");
		r = Integer.parseInt(inp[0]);
		c = Integer.parseInt(inp[1]);
		
		
		int table[][] = new int[r+1][c+1];
		
		for(int i=0;i<r;i++){
			inp = br.readLine().split("[\\s]+");
			
			for(int j=0;j<c;j++){
				table[i][j] = Integer.parseInt(inp[j]);
				sum += table[i][j];
			}
			table[i][c]=sum;
			sum=0;
		}
		
		
		
		for(int j=0;j<c+1;j++){
			sum=0;
			for(int i=0;i<r+1;i++){
				sum += table[i][j];
				
			}
			table[r][j] = sum;
			
		}
		
		for(int i=0;i<r+1;i++){
			for(int j=0;j<c+1;j++){
				ans +=table[i][j] + " ";
			}
			System.out.println(ans.substring(0, ans.length()-1));
			ans="";
		}
		}catch(IOException e){
			System.out.println(e);
			return;
		}
	}
}

