import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		int r = Integer.parseInt(tmpArray[0]);
		int c = Integer.parseInt(tmpArray[1]);
		
		int[][] result = new int[r+1][c+1];
		
		for(int i = 0; i < r ; i++){
			tmpArray = br.readLine().split(" ");
			for(int j = 0; j < c ; j++){
				result[i][j] = Integer.parseInt(tmpArray[j]);
				result[i][c] += result[i][j];
				result[r][c] += result[i][j];
				result[r][j] += result[i][j];
			}
		}
		
		
		for(int i = 0; i <= r ; i++){
			for(int j = 0; j <= c ; j++){
				if(j != 0){
					System.out.print(" ");
				}
				System.out.print(result[i][j]);
			}
			System.out.println();
		}
	}

} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		int r = Integer.parseInt(tmpArray[0]);
		int c = Integer.parseInt(tmpArray[1]);
		
		int[][] result = new int[r+1][c+1];
		
		for(int i = 0; i < r ; i++){
			tmpArray = br.readLine().split(" ");
			for(int j = 0; j < c ; j++){
				result[i][j] = Integer.parseInt(tmpArray[j]);
				result[i][c] += result[i][j];
				result[r][c] += result[i][j];
				result[r][j] += result[i][j];
			}
		}
		
		
		for(int i = 0; i <= r ; i++){
			for(int j = 0; j <= c ; j++){
				if(j != 0){
					System.out.print(" ");
				}
				System.out.print(result[i][j]);
			}
			System.out.println();
		}
	}

} Main public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		int r = Integer.parseInt(tmpArray[0]);
		int c = Integer.parseInt(tmpArray[1]);
		
		int[][] result = new int[r+1][c+1];
		
		for(int i = 0; i < r ; i++){
			tmpArray = br.readLine().split(" ");
			for(int j = 0; j < c ; j++){
				result[i][j] = Integer.parseInt(tmpArray[j]);
				result[i][c] += result[i][j];
				result[r][c] += result[i][j];
				result[r][j] += result[i][j];
			}
		}
		
		
		for(int i = 0; i <= r ; i++){
			for(int j = 0; j <= c ; j++){
				if(j != 0){
					System.out.print(" ");
				}
				System.out.print(result[i][j]);
			}
			System.out.println();
		}
	} main {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		int r = Integer.parseInt(tmpArray[0]);
		int c = Integer.parseInt(tmpArray[1]);
		
		int[][] result = new int[r+1][c+1];
		
		for(int i = 0; i < r ; i++){
			tmpArray = br.readLine().split(" ");
			for(int j = 0; j < c ; j++){
				result[i][j] = Integer.parseInt(tmpArray[j]);
				result[i][c] += result[i][j];
				result[r][c] += result[i][j];
				result[r][j] += result[i][j];
			}
		}
		
		
		for(int i = 0; i <= r ; i++){
			for(int j = 0; j <= c ; j++){
				if(j != 0){
					System.out.print(" ");
				}
				System.out.print(result[i][j]);
			}
			System.out.println();
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] tmpArray = br.readLine().split(" "); tmpArray br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int r = Integer.parseInt(tmpArray[0]); r Integer.parseInt(tmpArray[0]) Integer.parseInt Integer tmpArray[0] tmpArray 0 int c = Integer.parseInt(tmpArray[1]); c Integer.parseInt(tmpArray[1]) Integer.parseInt Integer tmpArray[1] tmpArray 1 int[][] result = new int[r+1][c+1]; result new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i = 0; i < r ; i++){
			tmpArray = br.readLine().split(" ");
			for(int j = 0; j < c ; j++){
				result[i][j] = Integer.parseInt(tmpArray[j]);
				result[i][c] += result[i][j];
				result[r][c] += result[i][j];
				result[r][j] += result[i][j];
			}
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			tmpArray = br.readLine().split(" ");
			for(int j = 0; j < c ; j++){
				result[i][j] = Integer.parseInt(tmpArray[j]);
				result[i][c] += result[i][j];
				result[r][c] += result[i][j];
				result[r][j] += result[i][j];
			}
		} {
			tmpArray = br.readLine().split(" ");
			for(int j = 0; j < c ; j++){
				result[i][j] = Integer.parseInt(tmpArray[j]);
				result[i][c] += result[i][j];
				result[r][c] += result[i][j];
				result[r][j] += result[i][j];
			}
		} tmpArray = br.readLine().split(" ") tmpArray br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int j = 0; j < c ; j++){
				result[i][j] = Integer.parseInt(tmpArray[j]);
				result[i][c] += result[i][j];
				result[r][c] += result[i][j];
				result[r][j] += result[i][j];
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				result[i][j] = Integer.parseInt(tmpArray[j]);
				result[i][c] += result[i][j];
				result[r][c] += result[i][j];
				result[r][j] += result[i][j];
			} {
				result[i][j] = Integer.parseInt(tmpArray[j]);
				result[i][c] += result[i][j];
				result[r][c] += result[i][j];
				result[r][j] += result[i][j];
			} result[i][j] = Integer.parseInt(tmpArray[j]) result[i][j] result[i] result i j Integer.parseInt(tmpArray[j]) Integer.parseInt Integer tmpArray[j] tmpArray j result[i][c] += result[i][j] result[i][c] result[i] result i c result[i][j] result[i] result i j result[r][c] += result[i][j] result[r][c] result[r] result r c result[i][j] result[i] result i j result[r][j] += result[i][j] result[r][j] result[r] result r j result[i][j] result[i] result i j for(int i = 0; i <= r ; i++){
			for(int j = 0; j <= c ; j++){
				if(j != 0){
					System.out.print(" ");
				}
				System.out.print(result[i][j]);
			}
			System.out.println();
		} int i = 0; int i = 0; i 0 i <= r i r i++ i++ i {
			for(int j = 0; j <= c ; j++){
				if(j != 0){
					System.out.print(" ");
				}
				System.out.print(result[i][j]);
			}
			System.out.println();
		} {
			for(int j = 0; j <= c ; j++){
				if(j != 0){
					System.out.print(" ");
				}
				System.out.print(result[i][j]);
			}
			System.out.println();
		} for(int j = 0; j <= c ; j++){
				if(j != 0){
					System.out.print(" ");
				}
				System.out.print(result[i][j]);
			} int j = 0; int j = 0; j 0 j <= c j c j++ j++ j {
				if(j != 0){
					System.out.print(" ");
				}
				System.out.print(result[i][j]);
			} {
				if(j != 0){
					System.out.print(" ");
				}
				System.out.print(result[i][j]);
			} if(j != 0){
					System.out.print(" ");
				} j != 0 j 0 {
					System.out.print(" ");
				} System.out.print(" ") System.out.print System.out System System.out " " System.out.print(result[i][j]) System.out.print System.out System System.out result[i][j] result[i] result i j System.out.println() System.out.println System.out System System.out String[] args args public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		int r = Integer.parseInt(tmpArray[0]);
		int c = Integer.parseInt(tmpArray[1]);
		
		int[][] result = new int[r+1][c+1];
		
		for(int i = 0; i < r ; i++){
			tmpArray = br.readLine().split(" ");
			for(int j = 0; j < c ; j++){
				result[i][j] = Integer.parseInt(tmpArray[j]);
				result[i][c] += result[i][j];
				result[r][c] += result[i][j];
				result[r][j] += result[i][j];
			}
		}
		
		
		for(int i = 0; i <= r ; i++){
			for(int j = 0; j <= c ; j++){
				if(j != 0){
					System.out.print(" ");
				}
				System.out.print(result[i][j]);
			}
			System.out.println();
		}
	}

} public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		int r = Integer.parseInt(tmpArray[0]);
		int c = Integer.parseInt(tmpArray[1]);
		
		int[][] result = new int[r+1][c+1];
		
		for(int i = 0; i < r ; i++){
			tmpArray = br.readLine().split(" ");
			for(int j = 0; j < c ; j++){
				result[i][j] = Integer.parseInt(tmpArray[j]);
				result[i][c] += result[i][j];
				result[r][c] += result[i][j];
				result[r][j] += result[i][j];
			}
		}
		
		
		for(int i = 0; i <= r ; i++){
			for(int j = 0; j <= c ; j++){
				if(j != 0){
					System.out.print(" ");
				}
				System.out.print(result[i][j]);
			}
			System.out.println();
		}
	}

} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO ?????????????????????????????????????????????
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] tmpArray = br.readLine().split(" ");
		int r = Integer.parseInt(tmpArray[0]);
		int c = Integer.parseInt(tmpArray[1]);
		
		int[][] result = new int[r+1][c+1];
		
		for(int i = 0; i < r ; i++){
			tmpArray = br.readLine().split(" ");
			for(int j = 0; j < c ; j++){
				result[i][j] = Integer.parseInt(tmpArray[j]);
				result[i][c] += result[i][j];
				result[r][c] += result[i][j];
				result[r][j] += result[i][j];
			}
		}
		
		
		for(int i = 0; i <= r ; i++){
			for(int j = 0; j <= c ; j++){
				if(j != 0){
					System.out.print(" ");
				}
				System.out.print(result[i][j]);
			}
			System.out.println();
		}
	}

}