public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();

		int[][] arr  = new int[r][c];
		int sum = 0;
		int kai = 0;
		for(int i = 0; i < r; i++){
			sum = 0;
			for(int j = 0; j < c; j++){
				arr[i][j] = scan.nextInt();
				System.out.print(arr[i][j] + " ");
				sum += arr[i][j];
			}
			kai += sum;
			System.out.println(sum);
		}

		for(int i = 0; i < c; i++){
			sum = 0;
			for(int j = 0; j < r; j++){
				sum += arr[j][i];
			}
			System.out.print(sum + " ");
		}
		System.out.println(kai);
	}
} public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();

		int[][] arr  = new int[r][c];
		int sum = 0;
		int kai = 0;
		for(int i = 0; i < r; i++){
			sum = 0;
			for(int j = 0; j < c; j++){
				arr[i][j] = scan.nextInt();
				System.out.print(arr[i][j] + " ");
				sum += arr[i][j];
			}
			kai += sum;
			System.out.println(sum);
		}

		for(int i = 0; i < c; i++){
			sum = 0;
			for(int j = 0; j < r; j++){
				sum += arr[j][i];
			}
			System.out.print(sum + " ");
		}
		System.out.println(kai);
	}
} Main public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();

		int[][] arr  = new int[r][c];
		int sum = 0;
		int kai = 0;
		for(int i = 0; i < r; i++){
			sum = 0;
			for(int j = 0; j < c; j++){
				arr[i][j] = scan.nextInt();
				System.out.print(arr[i][j] + " ");
				sum += arr[i][j];
			}
			kai += sum;
			System.out.println(sum);
		}

		for(int i = 0; i < c; i++){
			sum = 0;
			for(int j = 0; j < r; j++){
				sum += arr[j][i];
			}
			System.out.print(sum + " ");
		}
		System.out.println(kai);
	} main {
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();

		int[][] arr  = new int[r][c];
		int sum = 0;
		int kai = 0;
		for(int i = 0; i < r; i++){
			sum = 0;
			for(int j = 0; j < c; j++){
				arr[i][j] = scan.nextInt();
				System.out.print(arr[i][j] + " ");
				sum += arr[i][j];
			}
			kai += sum;
			System.out.println(sum);
		}

		for(int i = 0; i < c; i++){
			sum = 0;
			for(int j = 0; j < r; j++){
				sum += arr[j][i];
			}
			System.out.print(sum + " ");
		}
		System.out.println(kai);
	} java.util.Scanner scan = new java.util.Scanner(System.in); scan new java.util.Scanner(System.in) int r = scan.nextInt(); r scan.nextInt() scan.nextInt scan int c = scan.nextInt(); c scan.nextInt() scan.nextInt scan int[][] arr  = new int[r][c]; arr new int[r][c] r c int sum = 0; sum 0 int kai = 0; kai 0 for(int i = 0; i < r; i++){
			sum = 0;
			for(int j = 0; j < c; j++){
				arr[i][j] = scan.nextInt();
				System.out.print(arr[i][j] + " ");
				sum += arr[i][j];
			}
			kai += sum;
			System.out.println(sum);
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			sum = 0;
			for(int j = 0; j < c; j++){
				arr[i][j] = scan.nextInt();
				System.out.print(arr[i][j] + " ");
				sum += arr[i][j];
			}
			kai += sum;
			System.out.println(sum);
		} {
			sum = 0;
			for(int j = 0; j < c; j++){
				arr[i][j] = scan.nextInt();
				System.out.print(arr[i][j] + " ");
				sum += arr[i][j];
			}
			kai += sum;
			System.out.println(sum);
		} sum = 0 sum 0 for(int j = 0; j < c; j++){
				arr[i][j] = scan.nextInt();
				System.out.print(arr[i][j] + " ");
				sum += arr[i][j];
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				arr[i][j] = scan.nextInt();
				System.out.print(arr[i][j] + " ");
				sum += arr[i][j];
			} {
				arr[i][j] = scan.nextInt();
				System.out.print(arr[i][j] + " ");
				sum += arr[i][j];
			} arr[i][j] = scan.nextInt() arr[i][j] arr[i] arr i j scan.nextInt() scan.nextInt scan System.out.print(arr[i][j] + " ") System.out.print System.out System System.out arr[i][j] + " " arr[i][j] arr[i] arr i j " " sum += arr[i][j] sum arr[i][j] arr[i] arr i j kai += sum kai sum System.out.println(sum) System.out.println System.out System System.out sum for(int i = 0; i < c; i++){
			sum = 0;
			for(int j = 0; j < r; j++){
				sum += arr[j][i];
			}
			System.out.print(sum + " ");
		} int i = 0; int i = 0; i 0 i < c i c i++ i++ i {
			sum = 0;
			for(int j = 0; j < r; j++){
				sum += arr[j][i];
			}
			System.out.print(sum + " ");
		} {
			sum = 0;
			for(int j = 0; j < r; j++){
				sum += arr[j][i];
			}
			System.out.print(sum + " ");
		} sum = 0 sum 0 for(int j = 0; j < r; j++){
				sum += arr[j][i];
			} int j = 0; int j = 0; j 0 j < r j r j++ j++ j {
				sum += arr[j][i];
			} {
				sum += arr[j][i];
			} sum += arr[j][i] sum arr[j][i] arr[j] arr j i System.out.print(sum + " ") System.out.print System.out System System.out sum + " " sum " " System.out.println(kai) System.out.println System.out System System.out kai String[] args args public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();

		int[][] arr  = new int[r][c];
		int sum = 0;
		int kai = 0;
		for(int i = 0; i < r; i++){
			sum = 0;
			for(int j = 0; j < c; j++){
				arr[i][j] = scan.nextInt();
				System.out.print(arr[i][j] + " ");
				sum += arr[i][j];
			}
			kai += sum;
			System.out.println(sum);
		}

		for(int i = 0; i < c; i++){
			sum = 0;
			for(int j = 0; j < r; j++){
				sum += arr[j][i];
			}
			System.out.print(sum + " ");
		}
		System.out.println(kai);
	}
} public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();

		int[][] arr  = new int[r][c];
		int sum = 0;
		int kai = 0;
		for(int i = 0; i < r; i++){
			sum = 0;
			for(int j = 0; j < c; j++){
				arr[i][j] = scan.nextInt();
				System.out.print(arr[i][j] + " ");
				sum += arr[i][j];
			}
			kai += sum;
			System.out.println(sum);
		}

		for(int i = 0; i < c; i++){
			sum = 0;
			for(int j = 0; j < r; j++){
				sum += arr[j][i];
			}
			System.out.print(sum + " ");
		}
		System.out.println(kai);
	}
} Main
public class Main {
	public static void main(String[] args){
		java.util.Scanner scan = new java.util.Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();

		int[][] arr  = new int[r][c];
		int sum = 0;
		int kai = 0;
		for(int i = 0; i < r; i++){
			sum = 0;
			for(int j = 0; j < c; j++){
				arr[i][j] = scan.nextInt();
				System.out.print(arr[i][j] + " ");
				sum += arr[i][j];
			}
			kai += sum;
			System.out.println(sum);
		}

		for(int i = 0; i < c; i++){
			sum = 0;
			for(int j = 0; j < r; j++){
				sum += arr[j][i];
			}
			System.out.print(sum + " ");
		}
		System.out.println(kai);
	}
}