import java.util.Scanner;
import java.util.Arrays;

class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] numbers = new int[r+1][c+1];

		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				numbers[i][j] = scanner.nextInt();
			}
		}

		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				numbers[i][c] += numbers[i][j];
			}
		}

		for(int i = 0; i <= c; i++){
			for(int j = 0; j < r; j++){
				numbers[r][i] += numbers[j][i];
			}
		}

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

		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				numbers[i][j] = scanner.nextInt();
			}
		}

		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				numbers[i][c] += numbers[i][j];
			}
		}

		for(int i = 0; i <= c; i++){
			for(int j = 0; j < r; j++){
				numbers[r][i] += numbers[j][i];
			}
		}

		for(int i = 0; i <= r; i++){
			for(int j = 0; j < c; j++){
				System.out.print(numbers[i][j] + " ");
			}
			System.out.println(numbers[i][c]);
		}
		
	}
} Main public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] numbers = new int[r+1][c+1];

		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				numbers[i][j] = scanner.nextInt();
			}
		}

		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				numbers[i][c] += numbers[i][j];
			}
		}

		for(int i = 0; i <= c; i++){
			for(int j = 0; j < r; j++){
				numbers[r][i] += numbers[j][i];
			}
		}

		for(int i = 0; i <= r; i++){
			for(int j = 0; j < c; j++){
				System.out.print(numbers[i][j] + " ");
			}
			System.out.println(numbers[i][c]);
		}
		
	} main {
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] numbers = new int[r+1][c+1];

		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				numbers[i][j] = scanner.nextInt();
			}
		}

		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				numbers[i][c] += numbers[i][j];
			}
		}

		for(int i = 0; i <= c; i++){
			for(int j = 0; j < r; j++){
				numbers[r][i] += numbers[j][i];
			}
		}

		for(int i = 0; i <= r; i++){
			for(int j = 0; j < c; j++){
				System.out.print(numbers[i][j] + " ");
			}
			System.out.println(numbers[i][c]);
		}
		
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int r = scanner.nextInt(); r scanner.nextInt() scanner.nextInt scanner int c = scanner.nextInt(); c scanner.nextInt() scanner.nextInt scanner int[][] numbers = new int[r+1][c+1]; numbers new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				numbers[i][j] = scanner.nextInt();
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for(int j = 0; j < c; j++){
				numbers[i][j] = scanner.nextInt();
			}
		} {
			for(int j = 0; j < c; j++){
				numbers[i][j] = scanner.nextInt();
			}
		} for(int j = 0; j < c; j++){
				numbers[i][j] = scanner.nextInt();
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				numbers[i][j] = scanner.nextInt();
			} {
				numbers[i][j] = scanner.nextInt();
			} numbers[i][j] = scanner.nextInt() numbers[i][j] numbers[i] numbers i j scanner.nextInt() scanner.nextInt scanner for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				numbers[i][c] += numbers[i][j];
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for(int j = 0; j < c; j++){
				numbers[i][c] += numbers[i][j];
			}
		} {
			for(int j = 0; j < c; j++){
				numbers[i][c] += numbers[i][j];
			}
		} for(int j = 0; j < c; j++){
				numbers[i][c] += numbers[i][j];
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				numbers[i][c] += numbers[i][j];
			} {
				numbers[i][c] += numbers[i][j];
			} numbers[i][c] += numbers[i][j] numbers[i][c] numbers[i] numbers i c numbers[i][j] numbers[i] numbers i j for(int i = 0; i <= c; i++){
			for(int j = 0; j < r; j++){
				numbers[r][i] += numbers[j][i];
			}
		} int i = 0; int i = 0; i 0 i <= c i c i++ i++ i {
			for(int j = 0; j < r; j++){
				numbers[r][i] += numbers[j][i];
			}
		} {
			for(int j = 0; j < r; j++){
				numbers[r][i] += numbers[j][i];
			}
		} for(int j = 0; j < r; j++){
				numbers[r][i] += numbers[j][i];
			} int j = 0; int j = 0; j 0 j < r j r j++ j++ j {
				numbers[r][i] += numbers[j][i];
			} {
				numbers[r][i] += numbers[j][i];
			} numbers[r][i] += numbers[j][i] numbers[r][i] numbers[r] numbers r i numbers[j][i] numbers[j] numbers j i for(int i = 0; i <= r; i++){
			for(int j = 0; j < c; j++){
				System.out.print(numbers[i][j] + " ");
			}
			System.out.println(numbers[i][c]);
		} int i = 0; int i = 0; i 0 i <= r i r i++ i++ i {
			for(int j = 0; j < c; j++){
				System.out.print(numbers[i][j] + " ");
			}
			System.out.println(numbers[i][c]);
		} {
			for(int j = 0; j < c; j++){
				System.out.print(numbers[i][j] + " ");
			}
			System.out.println(numbers[i][c]);
		} for(int j = 0; j < c; j++){
				System.out.print(numbers[i][j] + " ");
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				System.out.print(numbers[i][j] + " ");
			} {
				System.out.print(numbers[i][j] + " ");
			} System.out.print(numbers[i][j] + " ") System.out.print System.out System System.out numbers[i][j] + " " numbers[i][j] numbers[i] numbers i j " " System.out.println(numbers[i][c]) System.out.println System.out System System.out numbers[i][c] numbers[i] numbers i c String[] args args
import java.util.Scanner;
import java.util.Arrays;

class Main{
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] numbers = new int[r+1][c+1];

		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				numbers[i][j] = scanner.nextInt();
			}
		}

		for(int i = 0; i < r; i++){
			for(int j = 0; j < c; j++){
				numbers[i][c] += numbers[i][j];
			}
		}

		for(int i = 0; i <= c; i++){
			for(int j = 0; j < r; j++){
				numbers[r][i] += numbers[j][i];
			}
		}

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