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

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

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

