import java.util.*;
 
class Main{
    public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		int c = scan.nextInt();
		int r = scan.nextInt();
		int[][] arr1 = new int[c][r];
		int[][] arr2 = new int[c+1][r+1];
		int sum = 0;
		//???????????????
		for(int i=0; i<c; i++){
			for(int j=0; j<r; j++){
				int p = scan.nextInt();
				arr1[i][j] = p;
				arr2[i][j] = p;
			}
		}
		//??????????¨????????´?
		for(int i=0; i<c; i++){
			for(int j=0; j<r; j++){
				sum += arr2[i][j];
			}
			arr2[i][r] = sum;
			sum = 0;
		}
		//??????????¨????????´?
		for(int i=0; i<r+1; i++){
			for(int j=0; j<c; j++){
				sum += arr2[j][i];
			}
			arr2[c][i] = sum;
			sum = 0;
		}
		//???????????????
		for(int i=0; i<c+1; i++){
			for(int j=0; j<r+1; j++){
				System.out.print(arr2[i][j]);
				if(j < r){
				System.out.print(" ");
				}
			}
			System.out.println("");
		}
    }
} import java.util.*; util.* java class Main{
    public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		int c = scan.nextInt();
		int r = scan.nextInt();
		int[][] arr1 = new int[c][r];
		int[][] arr2 = new int[c+1][r+1];
		int sum = 0;
		//???????????????
		for(int i=0; i<c; i++){
			for(int j=0; j<r; j++){
				int p = scan.nextInt();
				arr1[i][j] = p;
				arr2[i][j] = p;
			}
		}
		//??????????¨????????´?
		for(int i=0; i<c; i++){
			for(int j=0; j<r; j++){
				sum += arr2[i][j];
			}
			arr2[i][r] = sum;
			sum = 0;
		}
		//??????????¨????????´?
		for(int i=0; i<r+1; i++){
			for(int j=0; j<c; j++){
				sum += arr2[j][i];
			}
			arr2[c][i] = sum;
			sum = 0;
		}
		//???????????????
		for(int i=0; i<c+1; i++){
			for(int j=0; j<r+1; j++){
				System.out.print(arr2[i][j]);
				if(j < r){
				System.out.print(" ");
				}
			}
			System.out.println("");
		}
    }
} Main public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		int c = scan.nextInt();
		int r = scan.nextInt();
		int[][] arr1 = new int[c][r];
		int[][] arr2 = new int[c+1][r+1];
		int sum = 0;
		//???????????????
		for(int i=0; i<c; i++){
			for(int j=0; j<r; j++){
				int p = scan.nextInt();
				arr1[i][j] = p;
				arr2[i][j] = p;
			}
		}
		//??????????¨????????´?
		for(int i=0; i<c; i++){
			for(int j=0; j<r; j++){
				sum += arr2[i][j];
			}
			arr2[i][r] = sum;
			sum = 0;
		}
		//??????????¨????????´?
		for(int i=0; i<r+1; i++){
			for(int j=0; j<c; j++){
				sum += arr2[j][i];
			}
			arr2[c][i] = sum;
			sum = 0;
		}
		//???????????????
		for(int i=0; i<c+1; i++){
			for(int j=0; j<r+1; j++){
				System.out.print(arr2[i][j]);
				if(j < r){
				System.out.print(" ");
				}
			}
			System.out.println("");
		}
    } main {
		
		Scanner scan = new Scanner(System.in);
		int c = scan.nextInt();
		int r = scan.nextInt();
		int[][] arr1 = new int[c][r];
		int[][] arr2 = new int[c+1][r+1];
		int sum = 0;
		//???????????????
		for(int i=0; i<c; i++){
			for(int j=0; j<r; j++){
				int p = scan.nextInt();
				arr1[i][j] = p;
				arr2[i][j] = p;
			}
		}
		//??????????¨????????´?
		for(int i=0; i<c; i++){
			for(int j=0; j<r; j++){
				sum += arr2[i][j];
			}
			arr2[i][r] = sum;
			sum = 0;
		}
		//??????????¨????????´?
		for(int i=0; i<r+1; i++){
			for(int j=0; j<c; j++){
				sum += arr2[j][i];
			}
			arr2[c][i] = sum;
			sum = 0;
		}
		//???????????????
		for(int i=0; i<c+1; i++){
			for(int j=0; j<r+1; j++){
				System.out.print(arr2[i][j]);
				if(j < r){
				System.out.print(" ");
				}
			}
			System.out.println("");
		}
    } Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int c = scan.nextInt(); c scan.nextInt() scan.nextInt scan int r = scan.nextInt(); r scan.nextInt() scan.nextInt scan int[][] arr1 = new int[c][r]; arr1 new int[c][r] c r int[][] arr2 = new int[c+1][r+1]; arr2 new int[c+1][r+1] c+1 c 1 r+1 r 1 int sum = 0; sum 0 for(int i=0; i<c; i++){
			for(int j=0; j<r; j++){
				int p = scan.nextInt();
				arr1[i][j] = p;
				arr2[i][j] = p;
			}
		} int i=0; int i=0; i 0 i<c i c i++ i++ i {
			for(int j=0; j<r; j++){
				int p = scan.nextInt();
				arr1[i][j] = p;
				arr2[i][j] = p;
			}
		} {
			for(int j=0; j<r; j++){
				int p = scan.nextInt();
				arr1[i][j] = p;
				arr2[i][j] = p;
			}
		} for(int j=0; j<r; j++){
				int p = scan.nextInt();
				arr1[i][j] = p;
				arr2[i][j] = p;
			} int j=0; int j=0; j 0 j<r j r j++ j++ j {
				int p = scan.nextInt();
				arr1[i][j] = p;
				arr2[i][j] = p;
			} {
				int p = scan.nextInt();
				arr1[i][j] = p;
				arr2[i][j] = p;
			} int p = scan.nextInt(); p scan.nextInt() scan.nextInt scan arr1[i][j] = p arr1[i][j] arr1[i] arr1 i j p arr2[i][j] = p arr2[i][j] arr2[i] arr2 i j p for(int i=0; i<c; i++){
			for(int j=0; j<r; j++){
				sum += arr2[i][j];
			}
			arr2[i][r] = sum;
			sum = 0;
		} int i=0; int i=0; i 0 i<c i c i++ i++ i {
			for(int j=0; j<r; j++){
				sum += arr2[i][j];
			}
			arr2[i][r] = sum;
			sum = 0;
		} {
			for(int j=0; j<r; j++){
				sum += arr2[i][j];
			}
			arr2[i][r] = sum;
			sum = 0;
		} for(int j=0; j<r; j++){
				sum += arr2[i][j];
			} int j=0; int j=0; j 0 j<r j r j++ j++ j {
				sum += arr2[i][j];
			} {
				sum += arr2[i][j];
			} sum += arr2[i][j] sum arr2[i][j] arr2[i] arr2 i j arr2[i][r] = sum arr2[i][r] arr2[i] arr2 i r sum sum = 0 sum 0 for(int i=0; i<r+1; i++){
			for(int j=0; j<c; j++){
				sum += arr2[j][i];
			}
			arr2[c][i] = sum;
			sum = 0;
		} 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++){
				sum += arr2[j][i];
			}
			arr2[c][i] = sum;
			sum = 0;
		} {
			for(int j=0; j<c; j++){
				sum += arr2[j][i];
			}
			arr2[c][i] = sum;
			sum = 0;
		} for(int j=0; j<c; j++){
				sum += arr2[j][i];
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				sum += arr2[j][i];
			} {
				sum += arr2[j][i];
			} sum += arr2[j][i] sum arr2[j][i] arr2[j] arr2 j i arr2[c][i] = sum arr2[c][i] arr2[c] arr2 c i sum sum = 0 sum 0 for(int i=0; i<c+1; i++){
			for(int j=0; j<r+1; j++){
				System.out.print(arr2[i][j]);
				if(j < r){
				System.out.print(" ");
				}
			}
			System.out.println("");
		} int i=0; int i=0; i 0 i<c+1 i c+1 c 1 i++ i++ i {
			for(int j=0; j<r+1; j++){
				System.out.print(arr2[i][j]);
				if(j < r){
				System.out.print(" ");
				}
			}
			System.out.println("");
		} {
			for(int j=0; j<r+1; j++){
				System.out.print(arr2[i][j]);
				if(j < r){
				System.out.print(" ");
				}
			}
			System.out.println("");
		} for(int j=0; j<r+1; j++){
				System.out.print(arr2[i][j]);
				if(j < r){
				System.out.print(" ");
				}
			} int j=0; int j=0; j 0 j<r+1 j r+1 r 1 j++ j++ j {
				System.out.print(arr2[i][j]);
				if(j < r){
				System.out.print(" ");
				}
			} {
				System.out.print(arr2[i][j]);
				if(j < r){
				System.out.print(" ");
				}
			} System.out.print(arr2[i][j]) System.out.print System.out System System.out arr2[i][j] arr2[i] arr2 i j if(j < r){
				System.out.print(" ");
				} j < r j r {
				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
import java.util.*;
 
class Main{
    public static void main(String[] args){
		
		Scanner scan = new Scanner(System.in);
		int c = scan.nextInt();
		int r = scan.nextInt();
		int[][] arr1 = new int[c][r];
		int[][] arr2 = new int[c+1][r+1];
		int sum = 0;
		//???????????????
		for(int i=0; i<c; i++){
			for(int j=0; j<r; j++){
				int p = scan.nextInt();
				arr1[i][j] = p;
				arr2[i][j] = p;
			}
		}
		//??????????¨????????´?
		for(int i=0; i<c; i++){
			for(int j=0; j<r; j++){
				sum += arr2[i][j];
			}
			arr2[i][r] = sum;
			sum = 0;
		}
		//??????????¨????????´?
		for(int i=0; i<r+1; i++){
			for(int j=0; j<c; j++){
				sum += arr2[j][i];
			}
			arr2[c][i] = sum;
			sum = 0;
		}
		//???????????????
		for(int i=0; i<c+1; i++){
			for(int j=0; j<r+1; j++){
				System.out.print(arr2[i][j]);
				if(j < r){
				System.out.print(" ");
				}
			}
			System.out.println("");
		}
    }
}