import java.util.Scanner;


public class Main {

	public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		long[][] cells = new long[r+1][c+1]; //+1は総和セル
		
		for(int tate = 0;tate < r;tate++) {
			for(int yoko = 0;yoko < c;yoko++) {
				
				long num = sc.nextLong();
				
				cells[tate][yoko] = num;  //すべてのセルに値を代入した
				
			}
		}
		
		for(int tate = 0;tate < r;tate++) {
			
			long yokosum = 0;
			
			
			for(int yoko = 0;yoko < c;yoko++) {
				yokosum = yokosum + cells[tate][yoko];
				
			}
			
			cells[tate][c] = yokosum;    //左の総和をセルに入れる
		
		
		}
		
		for(int yoko = 0;yoko <= c;yoko++) {
			
			
			long tatesum = 0;
			
			
			for(int tate = 0;tate < r;tate++) {
				tatesum = tatesum + cells[tate][yoko];
				
			}
			
			cells[r][yoko] = tatesum;   //上の総和をセルに入れる
			
			
		}
		
		for(int tate = 0;tate <= r;tate++) {
			for(int yoko = 0;yoko <= c;yoko++) {
				
				System.out.print(cells[tate][yoko]);
				
				if(yoko == c) {
					
				}else {
					System.out.print(" ");
				}
				
				
				
			}
			
		if(tate == r) {
					
				}else {
					System.out.println("");
					
				}
		}
		
		System.out.println("");
		

	}
	

} import java.util.Scanner; Scanner java.util public class Main {

	public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		long[][] cells = new long[r+1][c+1]; //+1は総和セル
		
		for(int tate = 0;tate < r;tate++) {
			for(int yoko = 0;yoko < c;yoko++) {
				
				long num = sc.nextLong();
				
				cells[tate][yoko] = num;  //すべてのセルに値を代入した
				
			}
		}
		
		for(int tate = 0;tate < r;tate++) {
			
			long yokosum = 0;
			
			
			for(int yoko = 0;yoko < c;yoko++) {
				yokosum = yokosum + cells[tate][yoko];
				
			}
			
			cells[tate][c] = yokosum;    //左の総和をセルに入れる
		
		
		}
		
		for(int yoko = 0;yoko <= c;yoko++) {
			
			
			long tatesum = 0;
			
			
			for(int tate = 0;tate < r;tate++) {
				tatesum = tatesum + cells[tate][yoko];
				
			}
			
			cells[r][yoko] = tatesum;   //上の総和をセルに入れる
			
			
		}
		
		for(int tate = 0;tate <= r;tate++) {
			for(int yoko = 0;yoko <= c;yoko++) {
				
				System.out.print(cells[tate][yoko]);
				
				if(yoko == c) {
					
				}else {
					System.out.print(" ");
				}
				
				
				
			}
			
		if(tate == r) {
					
				}else {
					System.out.println("");
					
				}
		}
		
		System.out.println("");
		

	}
	

} Main public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		long[][] cells = new long[r+1][c+1]; //+1は総和セル
		
		for(int tate = 0;tate < r;tate++) {
			for(int yoko = 0;yoko < c;yoko++) {
				
				long num = sc.nextLong();
				
				cells[tate][yoko] = num;  //すべてのセルに値を代入した
				
			}
		}
		
		for(int tate = 0;tate < r;tate++) {
			
			long yokosum = 0;
			
			
			for(int yoko = 0;yoko < c;yoko++) {
				yokosum = yokosum + cells[tate][yoko];
				
			}
			
			cells[tate][c] = yokosum;    //左の総和をセルに入れる
		
		
		}
		
		for(int yoko = 0;yoko <= c;yoko++) {
			
			
			long tatesum = 0;
			
			
			for(int tate = 0;tate < r;tate++) {
				tatesum = tatesum + cells[tate][yoko];
				
			}
			
			cells[r][yoko] = tatesum;   //上の総和をセルに入れる
			
			
		}
		
		for(int tate = 0;tate <= r;tate++) {
			for(int yoko = 0;yoko <= c;yoko++) {
				
				System.out.print(cells[tate][yoko]);
				
				if(yoko == c) {
					
				}else {
					System.out.print(" ");
				}
				
				
				
			}
			
		if(tate == r) {
					
				}else {
					System.out.println("");
					
				}
		}
		
		System.out.println("");
		

	} main {
		
		Scanner sc = new Scanner(System.in);
		
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		long[][] cells = new long[r+1][c+1]; //+1は総和セル
		
		for(int tate = 0;tate < r;tate++) {
			for(int yoko = 0;yoko < c;yoko++) {
				
				long num = sc.nextLong();
				
				cells[tate][yoko] = num;  //すべてのセルに値を代入した
				
			}
		}
		
		for(int tate = 0;tate < r;tate++) {
			
			long yokosum = 0;
			
			
			for(int yoko = 0;yoko < c;yoko++) {
				yokosum = yokosum + cells[tate][yoko];
				
			}
			
			cells[tate][c] = yokosum;    //左の総和をセルに入れる
		
		
		}
		
		for(int yoko = 0;yoko <= c;yoko++) {
			
			
			long tatesum = 0;
			
			
			for(int tate = 0;tate < r;tate++) {
				tatesum = tatesum + cells[tate][yoko];
				
			}
			
			cells[r][yoko] = tatesum;   //上の総和をセルに入れる
			
			
		}
		
		for(int tate = 0;tate <= r;tate++) {
			for(int yoko = 0;yoko <= c;yoko++) {
				
				System.out.print(cells[tate][yoko]);
				
				if(yoko == c) {
					
				}else {
					System.out.print(" ");
				}
				
				
				
			}
			
		if(tate == r) {
					
				}else {
					System.out.println("");
					
				}
		}
		
		System.out.println("");
		

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int r = sc.nextInt(); r sc.nextInt() sc.nextInt sc int c = sc.nextInt(); c sc.nextInt() sc.nextInt sc long[][] cells = new long[r+1][c+1]; cells new long[r+1][c+1] r+1 r 1 c+1 c 1 for(int tate = 0;tate < r;tate++) {
			for(int yoko = 0;yoko < c;yoko++) {
				
				long num = sc.nextLong();
				
				cells[tate][yoko] = num;  //すべてのセルに値を代入した
				
			}
		} int tate = 0; int tate = 0; tate 0 tate < r tate r tate++ tate++ tate {
			for(int yoko = 0;yoko < c;yoko++) {
				
				long num = sc.nextLong();
				
				cells[tate][yoko] = num;  //すべてのセルに値を代入した
				
			}
		} {
			for(int yoko = 0;yoko < c;yoko++) {
				
				long num = sc.nextLong();
				
				cells[tate][yoko] = num;  //すべてのセルに値を代入した
				
			}
		} for(int yoko = 0;yoko < c;yoko++) {
				
				long num = sc.nextLong();
				
				cells[tate][yoko] = num;  //すべてのセルに値を代入した
				
			} int yoko = 0; int yoko = 0; yoko 0 yoko < c yoko c yoko++ yoko++ yoko {
				
				long num = sc.nextLong();
				
				cells[tate][yoko] = num;  //すべてのセルに値を代入した
				
			} {
				
				long num = sc.nextLong();
				
				cells[tate][yoko] = num;  //すべてのセルに値を代入した
				
			} long num = sc.nextLong(); num sc.nextLong() sc.nextLong sc cells[tate][yoko] = num cells[tate][yoko] cells[tate] cells tate yoko num for(int tate = 0;tate < r;tate++) {
			
			long yokosum = 0;
			
			
			for(int yoko = 0;yoko < c;yoko++) {
				yokosum = yokosum + cells[tate][yoko];
				
			}
			
			cells[tate][c] = yokosum;    //左の総和をセルに入れる
		
		
		} int tate = 0; int tate = 0; tate 0 tate < r tate r tate++ tate++ tate {
			
			long yokosum = 0;
			
			
			for(int yoko = 0;yoko < c;yoko++) {
				yokosum = yokosum + cells[tate][yoko];
				
			}
			
			cells[tate][c] = yokosum;    //左の総和をセルに入れる
		
		
		} {
			
			long yokosum = 0;
			
			
			for(int yoko = 0;yoko < c;yoko++) {
				yokosum = yokosum + cells[tate][yoko];
				
			}
			
			cells[tate][c] = yokosum;    //左の総和をセルに入れる
		
		
		} long yokosum = 0; yokosum 0 for(int yoko = 0;yoko < c;yoko++) {
				yokosum = yokosum + cells[tate][yoko];
				
			} int yoko = 0; int yoko = 0; yoko 0 yoko < c yoko c yoko++ yoko++ yoko {
				yokosum = yokosum + cells[tate][yoko];
				
			} {
				yokosum = yokosum + cells[tate][yoko];
				
			} yokosum = yokosum + cells[tate][yoko] yokosum yokosum + cells[tate][yoko] yokosum cells[tate][yoko] cells[tate] cells tate yoko cells[tate][c] = yokosum cells[tate][c] cells[tate] cells tate c yokosum for(int yoko = 0;yoko <= c;yoko++) {
			
			
			long tatesum = 0;
			
			
			for(int tate = 0;tate < r;tate++) {
				tatesum = tatesum + cells[tate][yoko];
				
			}
			
			cells[r][yoko] = tatesum;   //上の総和をセルに入れる
			
			
		} int yoko = 0; int yoko = 0; yoko 0 yoko <= c yoko c yoko++ yoko++ yoko {
			
			
			long tatesum = 0;
			
			
			for(int tate = 0;tate < r;tate++) {
				tatesum = tatesum + cells[tate][yoko];
				
			}
			
			cells[r][yoko] = tatesum;   //上の総和をセルに入れる
			
			
		} {
			
			
			long tatesum = 0;
			
			
			for(int tate = 0;tate < r;tate++) {
				tatesum = tatesum + cells[tate][yoko];
				
			}
			
			cells[r][yoko] = tatesum;   //上の総和をセルに入れる
			
			
		} long tatesum = 0; tatesum 0 for(int tate = 0;tate < r;tate++) {
				tatesum = tatesum + cells[tate][yoko];
				
			} int tate = 0; int tate = 0; tate 0 tate < r tate r tate++ tate++ tate {
				tatesum = tatesum + cells[tate][yoko];
				
			} {
				tatesum = tatesum + cells[tate][yoko];
				
			} tatesum = tatesum + cells[tate][yoko] tatesum tatesum + cells[tate][yoko] tatesum cells[tate][yoko] cells[tate] cells tate yoko cells[r][yoko] = tatesum cells[r][yoko] cells[r] cells r yoko tatesum for(int tate = 0;tate <= r;tate++) {
			for(int yoko = 0;yoko <= c;yoko++) {
				
				System.out.print(cells[tate][yoko]);
				
				if(yoko == c) {
					
				}else {
					System.out.print(" ");
				}
				
				
				
			}
			
		if(tate == r) {
					
				}else {
					System.out.println("");
					
				}
		} int tate = 0; int tate = 0; tate 0 tate <= r tate r tate++ tate++ tate {
			for(int yoko = 0;yoko <= c;yoko++) {
				
				System.out.print(cells[tate][yoko]);
				
				if(yoko == c) {
					
				}else {
					System.out.print(" ");
				}
				
				
				
			}
			
		if(tate == r) {
					
				}else {
					System.out.println("");
					
				}
		} {
			for(int yoko = 0;yoko <= c;yoko++) {
				
				System.out.print(cells[tate][yoko]);
				
				if(yoko == c) {
					
				}else {
					System.out.print(" ");
				}
				
				
				
			}
			
		if(tate == r) {
					
				}else {
					System.out.println("");
					
				}
		} for(int yoko = 0;yoko <= c;yoko++) {
				
				System.out.print(cells[tate][yoko]);
				
				if(yoko == c) {
					
				}else {
					System.out.print(" ");
				}
				
				
				
			} int yoko = 0; int yoko = 0; yoko 0 yoko <= c yoko c yoko++ yoko++ yoko {
				
				System.out.print(cells[tate][yoko]);
				
				if(yoko == c) {
					
				}else {
					System.out.print(" ");
				}
				
				
				
			} {
				
				System.out.print(cells[tate][yoko]);
				
				if(yoko == c) {
					
				}else {
					System.out.print(" ");
				}
				
				
				
			} System.out.print(cells[tate][yoko]) System.out.print System.out System System.out cells[tate][yoko] cells[tate] cells tate yoko if(yoko == c) {
					
				}else {
					System.out.print(" ");
				} yoko == c yoko c {
					
				} {
					System.out.print(" ");
				} System.out.print(" ") System.out.print System.out System System.out " " if(tate == r) {
					
				}else {
					System.out.println("");
					
				} tate == r tate r {
					
				} {
					System.out.println("");
					
				} System.out.println("") System.out.println 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 = sc.nextInt();
		int c = sc.nextInt();
		
		long[][] cells = new long[r+1][c+1]; //+1は総和セル
		
		for(int tate = 0;tate < r;tate++) {
			for(int yoko = 0;yoko < c;yoko++) {
				
				long num = sc.nextLong();
				
				cells[tate][yoko] = num;  //すべてのセルに値を代入した
				
			}
		}
		
		for(int tate = 0;tate < r;tate++) {
			
			long yokosum = 0;
			
			
			for(int yoko = 0;yoko < c;yoko++) {
				yokosum = yokosum + cells[tate][yoko];
				
			}
			
			cells[tate][c] = yokosum;    //左の総和をセルに入れる
		
		
		}
		
		for(int yoko = 0;yoko <= c;yoko++) {
			
			
			long tatesum = 0;
			
			
			for(int tate = 0;tate < r;tate++) {
				tatesum = tatesum + cells[tate][yoko];
				
			}
			
			cells[r][yoko] = tatesum;   //上の総和をセルに入れる
			
			
		}
		
		for(int tate = 0;tate <= r;tate++) {
			for(int yoko = 0;yoko <= c;yoko++) {
				
				System.out.print(cells[tate][yoko]);
				
				if(yoko == c) {
					
				}else {
					System.out.print(" ");
				}
				
				
				
			}
			
		if(tate == r) {
					
				}else {
					System.out.println("");
					
				}
		}
		
		System.out.println("");
		

	}
	

} public class Main {

	public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		long[][] cells = new long[r+1][c+1]; //+1は総和セル
		
		for(int tate = 0;tate < r;tate++) {
			for(int yoko = 0;yoko < c;yoko++) {
				
				long num = sc.nextLong();
				
				cells[tate][yoko] = num;  //すべてのセルに値を代入した
				
			}
		}
		
		for(int tate = 0;tate < r;tate++) {
			
			long yokosum = 0;
			
			
			for(int yoko = 0;yoko < c;yoko++) {
				yokosum = yokosum + cells[tate][yoko];
				
			}
			
			cells[tate][c] = yokosum;    //左の総和をセルに入れる
		
		
		}
		
		for(int yoko = 0;yoko <= c;yoko++) {
			
			
			long tatesum = 0;
			
			
			for(int tate = 0;tate < r;tate++) {
				tatesum = tatesum + cells[tate][yoko];
				
			}
			
			cells[r][yoko] = tatesum;   //上の総和をセルに入れる
			
			
		}
		
		for(int tate = 0;tate <= r;tate++) {
			for(int yoko = 0;yoko <= c;yoko++) {
				
				System.out.print(cells[tate][yoko]);
				
				if(yoko == c) {
					
				}else {
					System.out.print(" ");
				}
				
				
				
			}
			
		if(tate == r) {
					
				}else {
					System.out.println("");
					
				}
		}
		
		System.out.println("");
		

	}
	

} Main
import java.util.Scanner;


public class Main {

	public static void main(String [] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int r = sc.nextInt();
		int c = sc.nextInt();
		
		long[][] cells = new long[r+1][c+1]; //+1は総和セル
		
		for(int tate = 0;tate < r;tate++) {
			for(int yoko = 0;yoko < c;yoko++) {
				
				long num = sc.nextLong();
				
				cells[tate][yoko] = num;  //すべてのセルに値を代入した
				
			}
		}
		
		for(int tate = 0;tate < r;tate++) {
			
			long yokosum = 0;
			
			
			for(int yoko = 0;yoko < c;yoko++) {
				yokosum = yokosum + cells[tate][yoko];
				
			}
			
			cells[tate][c] = yokosum;    //左の総和をセルに入れる
		
		
		}
		
		for(int yoko = 0;yoko <= c;yoko++) {
			
			
			long tatesum = 0;
			
			
			for(int tate = 0;tate < r;tate++) {
				tatesum = tatesum + cells[tate][yoko];
				
			}
			
			cells[r][yoko] = tatesum;   //上の総和をセルに入れる
			
			
		}
		
		for(int tate = 0;tate <= r;tate++) {
			for(int yoko = 0;yoko <= c;yoko++) {
				
				System.out.print(cells[tate][yoko]);
				
				if(yoko == c) {
					
				}else {
					System.out.print(" ");
				}
				
				
				
			}
			
		if(tate == r) {
					
				}else {
					System.out.println("");
					
				}
		}
		
		System.out.println("");
		

	}
	

}
