import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		
		//?????¨?¨????????????????????????????
		String s  = sc.nextLine();
		String [] ary = s.split(" ");
		int height = Integer.parseInt(ary[0]);
		int width = Integer.parseInt(ary[1]);
		
		//?????±????????????????´???????
		int [][] data = new int[height][width];
 		for(int i = 0; i < height; i++) {
			String strData  = sc.nextLine();
			String[] dataAry = strData.split(" ");
			for(int j = 0; j < width; j++) {
				data[i][j] = Integer.parseInt(dataAry[j]);
			}
		}
 		
 		//??\?????????????????±?????¨?????????
 		int sumG = 0;
 		for(int i = 0; i < data.length; i++) {
 			int sum = 0;
 			for(int j = 0; j <data[i].length; j++) {
 				System.out.print(data[i][j] + " ");
 				sum += data[i][j];
 			}
 			System.out.println(sum);
 		}
 		
 		//????¨??????¨?????????
 		for(int i = 0; i < width; i++) {
 			int sum = 0;
 			for(int j = 0; j < height; j++) {
 				sum += data[j][i];
 			}
 			sumG += sum;
 			System.out.print(sum + " ");
 		}
 		System.out.println(sumG);
 		
	}

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

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		
		//?????¨?¨????????????????????????????
		String s  = sc.nextLine();
		String [] ary = s.split(" ");
		int height = Integer.parseInt(ary[0]);
		int width = Integer.parseInt(ary[1]);
		
		//?????±????????????????´???????
		int [][] data = new int[height][width];
 		for(int i = 0; i < height; i++) {
			String strData  = sc.nextLine();
			String[] dataAry = strData.split(" ");
			for(int j = 0; j < width; j++) {
				data[i][j] = Integer.parseInt(dataAry[j]);
			}
		}
 		
 		//??\?????????????????±?????¨?????????
 		int sumG = 0;
 		for(int i = 0; i < data.length; i++) {
 			int sum = 0;
 			for(int j = 0; j <data[i].length; j++) {
 				System.out.print(data[i][j] + " ");
 				sum += data[i][j];
 			}
 			System.out.println(sum);
 		}
 		
 		//????¨??????¨?????????
 		for(int i = 0; i < width; i++) {
 			int sum = 0;
 			for(int j = 0; j < height; j++) {
 				sum += data[j][i];
 			}
 			sumG += sum;
 			System.out.print(sum + " ");
 		}
 		System.out.println(sumG);
 		
	}

} Main public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		
		//?????¨?¨????????????????????????????
		String s  = sc.nextLine();
		String [] ary = s.split(" ");
		int height = Integer.parseInt(ary[0]);
		int width = Integer.parseInt(ary[1]);
		
		//?????±????????????????´???????
		int [][] data = new int[height][width];
 		for(int i = 0; i < height; i++) {
			String strData  = sc.nextLine();
			String[] dataAry = strData.split(" ");
			for(int j = 0; j < width; j++) {
				data[i][j] = Integer.parseInt(dataAry[j]);
			}
		}
 		
 		//??\?????????????????±?????¨?????????
 		int sumG = 0;
 		for(int i = 0; i < data.length; i++) {
 			int sum = 0;
 			for(int j = 0; j <data[i].length; j++) {
 				System.out.print(data[i][j] + " ");
 				sum += data[i][j];
 			}
 			System.out.println(sum);
 		}
 		
 		//????¨??????¨?????????
 		for(int i = 0; i < width; i++) {
 			int sum = 0;
 			for(int j = 0; j < height; j++) {
 				sum += data[j][i];
 			}
 			sumG += sum;
 			System.out.print(sum + " ");
 		}
 		System.out.println(sumG);
 		
	} main {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		
		//?????¨?¨????????????????????????????
		String s  = sc.nextLine();
		String [] ary = s.split(" ");
		int height = Integer.parseInt(ary[0]);
		int width = Integer.parseInt(ary[1]);
		
		//?????±????????????????´???????
		int [][] data = new int[height][width];
 		for(int i = 0; i < height; i++) {
			String strData  = sc.nextLine();
			String[] dataAry = strData.split(" ");
			for(int j = 0; j < width; j++) {
				data[i][j] = Integer.parseInt(dataAry[j]);
			}
		}
 		
 		//??\?????????????????±?????¨?????????
 		int sumG = 0;
 		for(int i = 0; i < data.length; i++) {
 			int sum = 0;
 			for(int j = 0; j <data[i].length; j++) {
 				System.out.print(data[i][j] + " ");
 				sum += data[i][j];
 			}
 			System.out.println(sum);
 		}
 		
 		//????¨??????¨?????????
 		for(int i = 0; i < width; i++) {
 			int sum = 0;
 			for(int j = 0; j < height; j++) {
 				sum += data[j][i];
 			}
 			sumG += sum;
 			System.out.print(sum + " ");
 		}
 		System.out.println(sumG);
 		
	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) String s  = sc.nextLine(); s sc.nextLine() sc.nextLine sc String [] ary = s.split(" "); ary s.split(" ") s.split s " " int height = Integer.parseInt(ary[0]); height Integer.parseInt(ary[0]) Integer.parseInt Integer ary[0] ary 0 int width = Integer.parseInt(ary[1]); width Integer.parseInt(ary[1]) Integer.parseInt Integer ary[1] ary 1 int [][] data = new int[height][width]; data new int[height][width] height width for(int i = 0; i < height; i++) {
			String strData  = sc.nextLine();
			String[] dataAry = strData.split(" ");
			for(int j = 0; j < width; j++) {
				data[i][j] = Integer.parseInt(dataAry[j]);
			}
		} int i = 0; int i = 0; i 0 i < height i height i++ i++ i {
			String strData  = sc.nextLine();
			String[] dataAry = strData.split(" ");
			for(int j = 0; j < width; j++) {
				data[i][j] = Integer.parseInt(dataAry[j]);
			}
		} {
			String strData  = sc.nextLine();
			String[] dataAry = strData.split(" ");
			for(int j = 0; j < width; j++) {
				data[i][j] = Integer.parseInt(dataAry[j]);
			}
		} String strData  = sc.nextLine(); strData sc.nextLine() sc.nextLine sc String[] dataAry = strData.split(" "); dataAry strData.split(" ") strData.split strData " " for(int j = 0; j < width; j++) {
				data[i][j] = Integer.parseInt(dataAry[j]);
			} int j = 0; int j = 0; j 0 j < width j width j++ j++ j {
				data[i][j] = Integer.parseInt(dataAry[j]);
			} {
				data[i][j] = Integer.parseInt(dataAry[j]);
			} data[i][j] = Integer.parseInt(dataAry[j]) data[i][j] data[i] data i j Integer.parseInt(dataAry[j]) Integer.parseInt Integer dataAry[j] dataAry j int sumG = 0; sumG 0 for(int i = 0; i < data.length; i++) {
 			int sum = 0;
 			for(int j = 0; j <data[i].length; j++) {
 				System.out.print(data[i][j] + " ");
 				sum += data[i][j];
 			}
 			System.out.println(sum);
 		} int i = 0; int i = 0; i 0 i < data.length i data.length data data.length i++ i++ i {
 			int sum = 0;
 			for(int j = 0; j <data[i].length; j++) {
 				System.out.print(data[i][j] + " ");
 				sum += data[i][j];
 			}
 			System.out.println(sum);
 		} {
 			int sum = 0;
 			for(int j = 0; j <data[i].length; j++) {
 				System.out.print(data[i][j] + " ");
 				sum += data[i][j];
 			}
 			System.out.println(sum);
 		} int sum = 0; sum 0 for(int j = 0; j <data[i].length; j++) {
 				System.out.print(data[i][j] + " ");
 				sum += data[i][j];
 			} int j = 0; int j = 0; j 0 j <data[i].length j data[i].length data[i] data i data[i].length j++ j++ j {
 				System.out.print(data[i][j] + " ");
 				sum += data[i][j];
 			} {
 				System.out.print(data[i][j] + " ");
 				sum += data[i][j];
 			} System.out.print(data[i][j] + " ") System.out.print System.out System System.out data[i][j] + " " data[i][j] data[i] data i j " " sum += data[i][j] sum data[i][j] data[i] data i j System.out.println(sum) System.out.println System.out System System.out sum for(int i = 0; i < width; i++) {
 			int sum = 0;
 			for(int j = 0; j < height; j++) {
 				sum += data[j][i];
 			}
 			sumG += sum;
 			System.out.print(sum + " ");
 		} int i = 0; int i = 0; i 0 i < width i width i++ i++ i {
 			int sum = 0;
 			for(int j = 0; j < height; j++) {
 				sum += data[j][i];
 			}
 			sumG += sum;
 			System.out.print(sum + " ");
 		} {
 			int sum = 0;
 			for(int j = 0; j < height; j++) {
 				sum += data[j][i];
 			}
 			sumG += sum;
 			System.out.print(sum + " ");
 		} int sum = 0; sum 0 for(int j = 0; j < height; j++) {
 				sum += data[j][i];
 			} int j = 0; int j = 0; j 0 j < height j height j++ j++ j {
 				sum += data[j][i];
 			} {
 				sum += data[j][i];
 			} sum += data[j][i] sum data[j][i] data[j] data j i sumG += sum sumG sum System.out.print(sum + " ") System.out.print System.out System System.out sum + " " sum " " System.out.println(sumG) System.out.println System.out System System.out sumG String[] args args public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		
		//?????¨?¨????????????????????????????
		String s  = sc.nextLine();
		String [] ary = s.split(" ");
		int height = Integer.parseInt(ary[0]);
		int width = Integer.parseInt(ary[1]);
		
		//?????±????????????????´???????
		int [][] data = new int[height][width];
 		for(int i = 0; i < height; i++) {
			String strData  = sc.nextLine();
			String[] dataAry = strData.split(" ");
			for(int j = 0; j < width; j++) {
				data[i][j] = Integer.parseInt(dataAry[j]);
			}
		}
 		
 		//??\?????????????????±?????¨?????????
 		int sumG = 0;
 		for(int i = 0; i < data.length; i++) {
 			int sum = 0;
 			for(int j = 0; j <data[i].length; j++) {
 				System.out.print(data[i][j] + " ");
 				sum += data[i][j];
 			}
 			System.out.println(sum);
 		}
 		
 		//????¨??????¨?????????
 		for(int i = 0; i < width; i++) {
 			int sum = 0;
 			for(int j = 0; j < height; j++) {
 				sum += data[j][i];
 			}
 			sumG += sum;
 			System.out.print(sum + " ");
 		}
 		System.out.println(sumG);
 		
	}

} public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		
		//?????¨?¨????????????????????????????
		String s  = sc.nextLine();
		String [] ary = s.split(" ");
		int height = Integer.parseInt(ary[0]);
		int width = Integer.parseInt(ary[1]);
		
		//?????±????????????????´???????
		int [][] data = new int[height][width];
 		for(int i = 0; i < height; i++) {
			String strData  = sc.nextLine();
			String[] dataAry = strData.split(" ");
			for(int j = 0; j < width; j++) {
				data[i][j] = Integer.parseInt(dataAry[j]);
			}
		}
 		
 		//??\?????????????????±?????¨?????????
 		int sumG = 0;
 		for(int i = 0; i < data.length; i++) {
 			int sum = 0;
 			for(int j = 0; j <data[i].length; j++) {
 				System.out.print(data[i][j] + " ");
 				sum += data[i][j];
 			}
 			System.out.println(sum);
 		}
 		
 		//????¨??????¨?????????
 		for(int i = 0; i < width; i++) {
 			int sum = 0;
 			for(int j = 0; j < height; j++) {
 				sum += data[j][i];
 			}
 			sumG += sum;
 			System.out.print(sum + " ");
 		}
 		System.out.println(sumG);
 		
	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		
		//?????¨?¨????????????????????????????
		String s  = sc.nextLine();
		String [] ary = s.split(" ");
		int height = Integer.parseInt(ary[0]);
		int width = Integer.parseInt(ary[1]);
		
		//?????±????????????????´???????
		int [][] data = new int[height][width];
 		for(int i = 0; i < height; i++) {
			String strData  = sc.nextLine();
			String[] dataAry = strData.split(" ");
			for(int j = 0; j < width; j++) {
				data[i][j] = Integer.parseInt(dataAry[j]);
			}
		}
 		
 		//??\?????????????????±?????¨?????????
 		int sumG = 0;
 		for(int i = 0; i < data.length; i++) {
 			int sum = 0;
 			for(int j = 0; j <data[i].length; j++) {
 				System.out.print(data[i][j] + " ");
 				sum += data[i][j];
 			}
 			System.out.println(sum);
 		}
 		
 		//????¨??????¨?????????
 		for(int i = 0; i < width; i++) {
 			int sum = 0;
 			for(int j = 0; j < height; j++) {
 				sum += data[j][i];
 			}
 			sumG += sum;
 			System.out.print(sum + " ");
 		}
 		System.out.println(sumG);
 		
	}

}