import java.util.Scanner;

class Main {

	public static void main(String args[]){	
		Scanner scan = new Scanner(System.in);

		int m, n;
		int a1, a2, a3, a4;
		int c;
		int a[][];
		
		n = scan.nextInt();
		m = scan.nextInt();
		a = new int[n + 1][m + 1];
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				a1 = scan.nextInt();
				a[i][j] = a1;
				a[n][j] += a1;
				a[i][m] += a1;
			}
			a[n][m] += a[i][m];
		}
		
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= m; j++){
				System.out.print(a[i][j]);
				if(j != m){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
			
	}
}	 import java.util.Scanner; Scanner java.util class Main {

	public static void main(String args[]){	
		Scanner scan = new Scanner(System.in);

		int m, n;
		int a1, a2, a3, a4;
		int c;
		int a[][];
		
		n = scan.nextInt();
		m = scan.nextInt();
		a = new int[n + 1][m + 1];
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				a1 = scan.nextInt();
				a[i][j] = a1;
				a[n][j] += a1;
				a[i][m] += a1;
			}
			a[n][m] += a[i][m];
		}
		
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= m; j++){
				System.out.print(a[i][j]);
				if(j != m){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
			
	}
} Main public static void main(String args[]){	
		Scanner scan = new Scanner(System.in);

		int m, n;
		int a1, a2, a3, a4;
		int c;
		int a[][];
		
		n = scan.nextInt();
		m = scan.nextInt();
		a = new int[n + 1][m + 1];
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				a1 = scan.nextInt();
				a[i][j] = a1;
				a[n][j] += a1;
				a[i][m] += a1;
			}
			a[n][m] += a[i][m];
		}
		
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= m; j++){
				System.out.print(a[i][j]);
				if(j != m){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
			
	} main {	
		Scanner scan = new Scanner(System.in);

		int m, n;
		int a1, a2, a3, a4;
		int c;
		int a[][];
		
		n = scan.nextInt();
		m = scan.nextInt();
		a = new int[n + 1][m + 1];
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				a1 = scan.nextInt();
				a[i][j] = a1;
				a[n][j] += a1;
				a[i][m] += a1;
			}
			a[n][m] += a[i][m];
		}
		
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= m; j++){
				System.out.print(a[i][j]);
				if(j != m){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
			
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int m m n; n int a1 a1 a2 a2 a3 a3 a4; a4 int c; c int a[][]; a n = scan.nextInt() n scan.nextInt() scan.nextInt scan m = scan.nextInt() m scan.nextInt() scan.nextInt scan a = new int[n + 1][m + 1] a new int[n + 1][m + 1] n + 1 n 1 m + 1 m 1 for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				a1 = scan.nextInt();
				a[i][j] = a1;
				a[n][j] += a1;
				a[i][m] += a1;
			}
			a[n][m] += a[i][m];
		} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
			for(int j = 0; j < m; j++){
				a1 = scan.nextInt();
				a[i][j] = a1;
				a[n][j] += a1;
				a[i][m] += a1;
			}
			a[n][m] += a[i][m];
		} {
			for(int j = 0; j < m; j++){
				a1 = scan.nextInt();
				a[i][j] = a1;
				a[n][j] += a1;
				a[i][m] += a1;
			}
			a[n][m] += a[i][m];
		} for(int j = 0; j < m; j++){
				a1 = scan.nextInt();
				a[i][j] = a1;
				a[n][j] += a1;
				a[i][m] += a1;
			} int j = 0; int j = 0; j 0 j < m j m j++ j++ j {
				a1 = scan.nextInt();
				a[i][j] = a1;
				a[n][j] += a1;
				a[i][m] += a1;
			} {
				a1 = scan.nextInt();
				a[i][j] = a1;
				a[n][j] += a1;
				a[i][m] += a1;
			} a1 = scan.nextInt() a1 scan.nextInt() scan.nextInt scan a[i][j] = a1 a[i][j] a[i] a i j a1 a[n][j] += a1 a[n][j] a[n] a n j a1 a[i][m] += a1 a[i][m] a[i] a i m a1 a[n][m] += a[i][m] a[n][m] a[n] a n m a[i][m] a[i] a i m for(int i = 0; i <= n; i++){
			for(int j = 0; j <= m; j++){
				System.out.print(a[i][j]);
				if(j != m){
					System.out.print(" ");
				}
			}
			System.out.println();
		} int i = 0; int i = 0; i 0 i <= n i n i++ i++ i {
			for(int j = 0; j <= m; j++){
				System.out.print(a[i][j]);
				if(j != m){
					System.out.print(" ");
				}
			}
			System.out.println();
		} {
			for(int j = 0; j <= m; j++){
				System.out.print(a[i][j]);
				if(j != m){
					System.out.print(" ");
				}
			}
			System.out.println();
		} for(int j = 0; j <= m; j++){
				System.out.print(a[i][j]);
				if(j != m){
					System.out.print(" ");
				}
			} int j = 0; int j = 0; j 0 j <= m j m j++ j++ j {
				System.out.print(a[i][j]);
				if(j != m){
					System.out.print(" ");
				}
			} {
				System.out.print(a[i][j]);
				if(j != m){
					System.out.print(" ");
				}
			} System.out.print(a[i][j]) System.out.print System.out System System.out a[i][j] a[i] a i j if(j != m){
					System.out.print(" ");
				} j != m j m {
					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.Scanner;

class Main {

	public static void main(String args[]){	
		Scanner scan = new Scanner(System.in);

		int m, n;
		int a1, a2, a3, a4;
		int c;
		int a[][];
		
		n = scan.nextInt();
		m = scan.nextInt();
		a = new int[n + 1][m + 1];
		
		for(int i = 0; i < n; i++){
			for(int j = 0; j < m; j++){
				a1 = scan.nextInt();
				a[i][j] = a1;
				a[n][j] += a1;
				a[i][m] += a1;
			}
			a[n][m] += a[i][m];
		}
		
		for(int i = 0; i <= n; i++){
			for(int j = 0; j <= m; j++){
				System.out.print(a[i][j]);
				if(j != m){
					System.out.print(" ");
				}
			}
			System.out.println();
		}
			
	}
}	