import java.util.Scanner;

public class Main {
	void spread(){
		Scanner s = new Scanner(System.in);
		int r = s.nextInt();
		int c = s.nextInt();
		int rxc[][] = new int[r+1][c+1];
		for(int i = 0;i < r;i++){
			int sumJ = 0;
			for(int j = 0;j<c;j++){
				rxc[i][j] = s.nextInt();
				sumJ+=rxc[i][j];
			}
			rxc[i][c] = sumJ;
		}
		for(int j = 0;j < c + 1;j++){
			int sumI = 0;
			for(int i = 0;i < r;i++){
				sumI+=rxc[i][j];
			}
			rxc[r][j] = sumI;
		}
		for(int i = 0;i < r+1;i++){
			for(int j = 0;j < c+1;j++){
				System.out.print(rxc[i][j]);
				if(j < c){
					System.out.print(" ");
				}
			}
			System.out.print("\n");
		}
	}
	public static void main(String args[]){
		Main m = new Main();
		m.spread();
	}
} import java.util.Scanner; Scanner java.util public class Main {
	void spread(){
		Scanner s = new Scanner(System.in);
		int r = s.nextInt();
		int c = s.nextInt();
		int rxc[][] = new int[r+1][c+1];
		for(int i = 0;i < r;i++){
			int sumJ = 0;
			for(int j = 0;j<c;j++){
				rxc[i][j] = s.nextInt();
				sumJ+=rxc[i][j];
			}
			rxc[i][c] = sumJ;
		}
		for(int j = 0;j < c + 1;j++){
			int sumI = 0;
			for(int i = 0;i < r;i++){
				sumI+=rxc[i][j];
			}
			rxc[r][j] = sumI;
		}
		for(int i = 0;i < r+1;i++){
			for(int j = 0;j < c+1;j++){
				System.out.print(rxc[i][j]);
				if(j < c){
					System.out.print(" ");
				}
			}
			System.out.print("\n");
		}
	}
	public static void main(String args[]){
		Main m = new Main();
		m.spread();
	}
} Main void spread(){
		Scanner s = new Scanner(System.in);
		int r = s.nextInt();
		int c = s.nextInt();
		int rxc[][] = new int[r+1][c+1];
		for(int i = 0;i < r;i++){
			int sumJ = 0;
			for(int j = 0;j<c;j++){
				rxc[i][j] = s.nextInt();
				sumJ+=rxc[i][j];
			}
			rxc[i][c] = sumJ;
		}
		for(int j = 0;j < c + 1;j++){
			int sumI = 0;
			for(int i = 0;i < r;i++){
				sumI+=rxc[i][j];
			}
			rxc[r][j] = sumI;
		}
		for(int i = 0;i < r+1;i++){
			for(int j = 0;j < c+1;j++){
				System.out.print(rxc[i][j]);
				if(j < c){
					System.out.print(" ");
				}
			}
			System.out.print("\n");
		}
	} spread {
		Scanner s = new Scanner(System.in);
		int r = s.nextInt();
		int c = s.nextInt();
		int rxc[][] = new int[r+1][c+1];
		for(int i = 0;i < r;i++){
			int sumJ = 0;
			for(int j = 0;j<c;j++){
				rxc[i][j] = s.nextInt();
				sumJ+=rxc[i][j];
			}
			rxc[i][c] = sumJ;
		}
		for(int j = 0;j < c + 1;j++){
			int sumI = 0;
			for(int i = 0;i < r;i++){
				sumI+=rxc[i][j];
			}
			rxc[r][j] = sumI;
		}
		for(int i = 0;i < r+1;i++){
			for(int j = 0;j < c+1;j++){
				System.out.print(rxc[i][j]);
				if(j < c){
					System.out.print(" ");
				}
			}
			System.out.print("\n");
		}
	} Scanner s = new Scanner(System.in); s new Scanner(System.in) int r = s.nextInt(); r s.nextInt() s.nextInt s int c = s.nextInt(); c s.nextInt() s.nextInt s int rxc[][] = new int[r+1][c+1]; rxc new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i = 0;i < r;i++){
			int sumJ = 0;
			for(int j = 0;j<c;j++){
				rxc[i][j] = s.nextInt();
				sumJ+=rxc[i][j];
			}
			rxc[i][c] = sumJ;
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			int sumJ = 0;
			for(int j = 0;j<c;j++){
				rxc[i][j] = s.nextInt();
				sumJ+=rxc[i][j];
			}
			rxc[i][c] = sumJ;
		} {
			int sumJ = 0;
			for(int j = 0;j<c;j++){
				rxc[i][j] = s.nextInt();
				sumJ+=rxc[i][j];
			}
			rxc[i][c] = sumJ;
		} int sumJ = 0; sumJ 0 for(int j = 0;j<c;j++){
				rxc[i][j] = s.nextInt();
				sumJ+=rxc[i][j];
			} int j = 0; int j = 0; j 0 j<c j c j++ j++ j {
				rxc[i][j] = s.nextInt();
				sumJ+=rxc[i][j];
			} {
				rxc[i][j] = s.nextInt();
				sumJ+=rxc[i][j];
			} rxc[i][j] = s.nextInt() rxc[i][j] rxc[i] rxc i j s.nextInt() s.nextInt s sumJ+=rxc[i][j] sumJ rxc[i][j] rxc[i] rxc i j rxc[i][c] = sumJ rxc[i][c] rxc[i] rxc i c sumJ for(int j = 0;j < c + 1;j++){
			int sumI = 0;
			for(int i = 0;i < r;i++){
				sumI+=rxc[i][j];
			}
			rxc[r][j] = sumI;
		} int j = 0; int j = 0; j 0 j < c + 1 j c + 1 c 1 j++ j++ j {
			int sumI = 0;
			for(int i = 0;i < r;i++){
				sumI+=rxc[i][j];
			}
			rxc[r][j] = sumI;
		} {
			int sumI = 0;
			for(int i = 0;i < r;i++){
				sumI+=rxc[i][j];
			}
			rxc[r][j] = sumI;
		} int sumI = 0; sumI 0 for(int i = 0;i < r;i++){
				sumI+=rxc[i][j];
			} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
				sumI+=rxc[i][j];
			} {
				sumI+=rxc[i][j];
			} sumI+=rxc[i][j] sumI rxc[i][j] rxc[i] rxc i j rxc[r][j] = sumI rxc[r][j] rxc[r] rxc r j sumI for(int i = 0;i < r+1;i++){
			for(int j = 0;j < c+1;j++){
				System.out.print(rxc[i][j]);
				if(j < c){
					System.out.print(" ");
				}
			}
			System.out.print("\n");
		} 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++){
				System.out.print(rxc[i][j]);
				if(j < c){
					System.out.print(" ");
				}
			}
			System.out.print("\n");
		} {
			for(int j = 0;j < c+1;j++){
				System.out.print(rxc[i][j]);
				if(j < c){
					System.out.print(" ");
				}
			}
			System.out.print("\n");
		} for(int j = 0;j < c+1;j++){
				System.out.print(rxc[i][j]);
				if(j < c){
					System.out.print(" ");
				}
			} int j = 0; int j = 0; j 0 j < c+1 j c+1 c 1 j++ j++ j {
				System.out.print(rxc[i][j]);
				if(j < c){
					System.out.print(" ");
				}
			} {
				System.out.print(rxc[i][j]);
				if(j < c){
					System.out.print(" ");
				}
			} System.out.print(rxc[i][j]) System.out.print System.out System System.out rxc[i][j] rxc[i] rxc 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.print("\n") System.out.print System.out System System.out "\n" public static void main(String args[]){
		Main m = new Main();
		m.spread();
	} main {
		Main m = new Main();
		m.spread();
	} Main m = new Main(); m new Main() m.spread() m.spread m String args[] args public class Main {
	void spread(){
		Scanner s = new Scanner(System.in);
		int r = s.nextInt();
		int c = s.nextInt();
		int rxc[][] = new int[r+1][c+1];
		for(int i = 0;i < r;i++){
			int sumJ = 0;
			for(int j = 0;j<c;j++){
				rxc[i][j] = s.nextInt();
				sumJ+=rxc[i][j];
			}
			rxc[i][c] = sumJ;
		}
		for(int j = 0;j < c + 1;j++){
			int sumI = 0;
			for(int i = 0;i < r;i++){
				sumI+=rxc[i][j];
			}
			rxc[r][j] = sumI;
		}
		for(int i = 0;i < r+1;i++){
			for(int j = 0;j < c+1;j++){
				System.out.print(rxc[i][j]);
				if(j < c){
					System.out.print(" ");
				}
			}
			System.out.print("\n");
		}
	}
	public static void main(String args[]){
		Main m = new Main();
		m.spread();
	}
} public class Main {
	void spread(){
		Scanner s = new Scanner(System.in);
		int r = s.nextInt();
		int c = s.nextInt();
		int rxc[][] = new int[r+1][c+1];
		for(int i = 0;i < r;i++){
			int sumJ = 0;
			for(int j = 0;j<c;j++){
				rxc[i][j] = s.nextInt();
				sumJ+=rxc[i][j];
			}
			rxc[i][c] = sumJ;
		}
		for(int j = 0;j < c + 1;j++){
			int sumI = 0;
			for(int i = 0;i < r;i++){
				sumI+=rxc[i][j];
			}
			rxc[r][j] = sumI;
		}
		for(int i = 0;i < r+1;i++){
			for(int j = 0;j < c+1;j++){
				System.out.print(rxc[i][j]);
				if(j < c){
					System.out.print(" ");
				}
			}
			System.out.print("\n");
		}
	}
	public static void main(String args[]){
		Main m = new Main();
		m.spread();
	}
} Main
import java.util.Scanner;

public class Main {
	void spread(){
		Scanner s = new Scanner(System.in);
		int r = s.nextInt();
		int c = s.nextInt();
		int rxc[][] = new int[r+1][c+1];
		for(int i = 0;i < r;i++){
			int sumJ = 0;
			for(int j = 0;j<c;j++){
				rxc[i][j] = s.nextInt();
				sumJ+=rxc[i][j];
			}
			rxc[i][c] = sumJ;
		}
		for(int j = 0;j < c + 1;j++){
			int sumI = 0;
			for(int i = 0;i < r;i++){
				sumI+=rxc[i][j];
			}
			rxc[r][j] = sumI;
		}
		for(int i = 0;i < r+1;i++){
			for(int j = 0;j < c+1;j++){
				System.out.print(rxc[i][j]);
				if(j < c){
					System.out.print(" ");
				}
			}
			System.out.print("\n");
		}
	}
	public static void main(String args[]){
		Main m = new Main();
		m.spread();
	}
}