import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int r, c;
		int i, j;
		int[][] sheet = new int[101][101];
		
		for(i = 0; i < 101; i++){
			for(j = 0; j < 101; j++){
				sheet[i][j] = 0;
			}
		}
		
		r = sc.nextInt();
		c = sc.nextInt();
		
		for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][j] = sc.nextInt();
			}
		}
		
		for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][c] += sheet[i][j];
			}
		}
		
		for(j = 0; j <= c; j++){
			for(i = 0; i < r; i++){
				sheet[r][j] += sheet[i][j];
			}
		}
		
		for(i = 0; i <= r; i++){
			for(j = 0; j <= c; j++){
				System.out.print(sheet[i][j]);
				
				if(j < c){
					System.out.print(" ");
				}
			}
			
			System.out.println("");
		}
	}
} import java.util.*; util.* java public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int r, c;
		int i, j;
		int[][] sheet = new int[101][101];
		
		for(i = 0; i < 101; i++){
			for(j = 0; j < 101; j++){
				sheet[i][j] = 0;
			}
		}
		
		r = sc.nextInt();
		c = sc.nextInt();
		
		for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][j] = sc.nextInt();
			}
		}
		
		for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][c] += sheet[i][j];
			}
		}
		
		for(j = 0; j <= c; j++){
			for(i = 0; i < r; i++){
				sheet[r][j] += sheet[i][j];
			}
		}
		
		for(i = 0; i <= r; i++){
			for(j = 0; j <= c; j++){
				System.out.print(sheet[i][j]);
				
				if(j < c){
					System.out.print(" ");
				}
			}
			
			System.out.println("");
		}
	}
} Main public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int r, c;
		int i, j;
		int[][] sheet = new int[101][101];
		
		for(i = 0; i < 101; i++){
			for(j = 0; j < 101; j++){
				sheet[i][j] = 0;
			}
		}
		
		r = sc.nextInt();
		c = sc.nextInt();
		
		for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][j] = sc.nextInt();
			}
		}
		
		for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][c] += sheet[i][j];
			}
		}
		
		for(j = 0; j <= c; j++){
			for(i = 0; i < r; i++){
				sheet[r][j] += sheet[i][j];
			}
		}
		
		for(i = 0; i <= r; i++){
			for(j = 0; j <= c; j++){
				System.out.print(sheet[i][j]);
				
				if(j < c){
					System.out.print(" ");
				}
			}
			
			System.out.println("");
		}
	} main {
		Scanner sc = new Scanner(System.in);
		int r, c;
		int i, j;
		int[][] sheet = new int[101][101];
		
		for(i = 0; i < 101; i++){
			for(j = 0; j < 101; j++){
				sheet[i][j] = 0;
			}
		}
		
		r = sc.nextInt();
		c = sc.nextInt();
		
		for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][j] = sc.nextInt();
			}
		}
		
		for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][c] += sheet[i][j];
			}
		}
		
		for(j = 0; j <= c; j++){
			for(i = 0; i < r; i++){
				sheet[r][j] += sheet[i][j];
			}
		}
		
		for(i = 0; i <= r; i++){
			for(j = 0; j <= c; j++){
				System.out.print(sheet[i][j]);
				
				if(j < c){
					System.out.print(" ");
				}
			}
			
			System.out.println("");
		}
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int r r c; c int i i j; j int[][] sheet = new int[101][101]; sheet new int[101][101] 101 101 for(i = 0; i < 101; i++){
			for(j = 0; j < 101; j++){
				sheet[i][j] = 0;
			}
		} i = 0; i = 0 i 0 i < 101 i 101 i++ i++ i {
			for(j = 0; j < 101; j++){
				sheet[i][j] = 0;
			}
		} {
			for(j = 0; j < 101; j++){
				sheet[i][j] = 0;
			}
		} for(j = 0; j < 101; j++){
				sheet[i][j] = 0;
			} j = 0; j = 0 j 0 j < 101 j 101 j++ j++ j {
				sheet[i][j] = 0;
			} {
				sheet[i][j] = 0;
			} sheet[i][j] = 0 sheet[i][j] sheet[i] sheet i j 0 r = sc.nextInt() r sc.nextInt() sc.nextInt sc c = sc.nextInt() c sc.nextInt() sc.nextInt sc for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][j] = sc.nextInt();
			}
		} i = 0; i = 0 i 0 i < r i r i++ i++ i {
			for(j = 0; j < c; j++){
				sheet[i][j] = sc.nextInt();
			}
		} {
			for(j = 0; j < c; j++){
				sheet[i][j] = sc.nextInt();
			}
		} for(j = 0; j < c; j++){
				sheet[i][j] = sc.nextInt();
			} j = 0; j = 0 j 0 j < c j c j++ j++ j {
				sheet[i][j] = sc.nextInt();
			} {
				sheet[i][j] = sc.nextInt();
			} sheet[i][j] = sc.nextInt() sheet[i][j] sheet[i] sheet i j sc.nextInt() sc.nextInt sc for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][c] += sheet[i][j];
			}
		} i = 0; i = 0 i 0 i < r i r i++ i++ i {
			for(j = 0; j < c; j++){
				sheet[i][c] += sheet[i][j];
			}
		} {
			for(j = 0; j < c; j++){
				sheet[i][c] += sheet[i][j];
			}
		} for(j = 0; j < c; j++){
				sheet[i][c] += sheet[i][j];
			} j = 0; j = 0 j 0 j < c j c j++ j++ j {
				sheet[i][c] += sheet[i][j];
			} {
				sheet[i][c] += sheet[i][j];
			} sheet[i][c] += sheet[i][j] sheet[i][c] sheet[i] sheet i c sheet[i][j] sheet[i] sheet i j for(j = 0; j <= c; j++){
			for(i = 0; i < r; i++){
				sheet[r][j] += sheet[i][j];
			}
		} j = 0; j = 0 j 0 j <= c j c j++ j++ j {
			for(i = 0; i < r; i++){
				sheet[r][j] += sheet[i][j];
			}
		} {
			for(i = 0; i < r; i++){
				sheet[r][j] += sheet[i][j];
			}
		} for(i = 0; i < r; i++){
				sheet[r][j] += sheet[i][j];
			} i = 0; i = 0 i 0 i < r i r i++ i++ i {
				sheet[r][j] += sheet[i][j];
			} {
				sheet[r][j] += sheet[i][j];
			} sheet[r][j] += sheet[i][j] sheet[r][j] sheet[r] sheet r j sheet[i][j] sheet[i] sheet i j for(i = 0; i <= r; i++){
			for(j = 0; j <= c; j++){
				System.out.print(sheet[i][j]);
				
				if(j < c){
					System.out.print(" ");
				}
			}
			
			System.out.println("");
		} i = 0; i = 0 i 0 i <= r i r i++ i++ i {
			for(j = 0; j <= c; j++){
				System.out.print(sheet[i][j]);
				
				if(j < c){
					System.out.print(" ");
				}
			}
			
			System.out.println("");
		} {
			for(j = 0; j <= c; j++){
				System.out.print(sheet[i][j]);
				
				if(j < c){
					System.out.print(" ");
				}
			}
			
			System.out.println("");
		} for(j = 0; j <= c; j++){
				System.out.print(sheet[i][j]);
				
				if(j < c){
					System.out.print(" ");
				}
			} j = 0; j = 0 j 0 j <= c j c j++ j++ j {
				System.out.print(sheet[i][j]);
				
				if(j < c){
					System.out.print(" ");
				}
			} {
				System.out.print(sheet[i][j]);
				
				if(j < c){
					System.out.print(" ");
				}
			} System.out.print(sheet[i][j]) System.out.print System.out System System.out sheet[i][j] sheet[i] sheet i j if(j < c){
					System.out.print(" ");
				} j < c j c {
					System.out.print(" ");
				} System.out.print(" ") System.out.print System.out System System.out " " System.out.println("") System.out.println System.out System System.out "" String args[] args public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int r, c;
		int i, j;
		int[][] sheet = new int[101][101];
		
		for(i = 0; i < 101; i++){
			for(j = 0; j < 101; j++){
				sheet[i][j] = 0;
			}
		}
		
		r = sc.nextInt();
		c = sc.nextInt();
		
		for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][j] = sc.nextInt();
			}
		}
		
		for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][c] += sheet[i][j];
			}
		}
		
		for(j = 0; j <= c; j++){
			for(i = 0; i < r; i++){
				sheet[r][j] += sheet[i][j];
			}
		}
		
		for(i = 0; i <= r; i++){
			for(j = 0; j <= c; j++){
				System.out.print(sheet[i][j]);
				
				if(j < c){
					System.out.print(" ");
				}
			}
			
			System.out.println("");
		}
	}
} public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int r, c;
		int i, j;
		int[][] sheet = new int[101][101];
		
		for(i = 0; i < 101; i++){
			for(j = 0; j < 101; j++){
				sheet[i][j] = 0;
			}
		}
		
		r = sc.nextInt();
		c = sc.nextInt();
		
		for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][j] = sc.nextInt();
			}
		}
		
		for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][c] += sheet[i][j];
			}
		}
		
		for(j = 0; j <= c; j++){
			for(i = 0; i < r; i++){
				sheet[r][j] += sheet[i][j];
			}
		}
		
		for(i = 0; i <= r; i++){
			for(j = 0; j <= c; j++){
				System.out.print(sheet[i][j]);
				
				if(j < c){
					System.out.print(" ");
				}
			}
			
			System.out.println("");
		}
	}
} Main
import java.util.*;

public class Main{
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		int r, c;
		int i, j;
		int[][] sheet = new int[101][101];
		
		for(i = 0; i < 101; i++){
			for(j = 0; j < 101; j++){
				sheet[i][j] = 0;
			}
		}
		
		r = sc.nextInt();
		c = sc.nextInt();
		
		for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][j] = sc.nextInt();
			}
		}
		
		for(i = 0; i < r; i++){
			for(j = 0; j < c; j++){
				sheet[i][c] += sheet[i][j];
			}
		}
		
		for(j = 0; j <= c; j++){
			for(i = 0; i < r; i++){
				sheet[r][j] += sheet[i][j];
			}
		}
		
		for(i = 0; i <= r; i++){
			for(j = 0; j <= c; j++){
				System.out.print(sheet[i][j]);
				
				if(j < c){
					System.out.print(" ");
				}
			}
			
			System.out.println("");
		}
	}
}