import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");

        int num1 = Integer.parseInt(line[0]);
        int num2 = Integer.parseInt(line[1]);
        ArrayList<Integer> aryNum = new ArrayList<Integer>();
        int[] totalCol = new int[num2];

        for(int i = 0; i < num1; i++){
        	String[] input = br.readLine().split(" ");
        	int total = 0;
        	for(int j = 0; j < num2; j++){
        		total += Integer.parseInt(input[j]);
        		aryNum.add(Integer.parseInt(input[j]));
        		totalCol[j] += Integer.parseInt(input[j]);
        	}
        	aryNum.add(total);
        }

        int count = 1;
        int lastTotal = 0;
        for(int num : aryNum){

        	System.out.print(num);
        	if(count % (num2 + 1) == 0){
        		lastTotal += num;
        		System.out.println();
        	}else{
        		System.out.print(" ");
        	}
        	count++;
        }

        for(int num : totalCol){
        	System.out.print(num + " ");
        }
        System.out.println(lastTotal);

    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io import java.util.ArrayList; ArrayList java.util public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");

        int num1 = Integer.parseInt(line[0]);
        int num2 = Integer.parseInt(line[1]);
        ArrayList<Integer> aryNum = new ArrayList<Integer>();
        int[] totalCol = new int[num2];

        for(int i = 0; i < num1; i++){
        	String[] input = br.readLine().split(" ");
        	int total = 0;
        	for(int j = 0; j < num2; j++){
        		total += Integer.parseInt(input[j]);
        		aryNum.add(Integer.parseInt(input[j]));
        		totalCol[j] += Integer.parseInt(input[j]);
        	}
        	aryNum.add(total);
        }

        int count = 1;
        int lastTotal = 0;
        for(int num : aryNum){

        	System.out.print(num);
        	if(count % (num2 + 1) == 0){
        		lastTotal += num;
        		System.out.println();
        	}else{
        		System.out.print(" ");
        	}
        	count++;
        }

        for(int num : totalCol){
        	System.out.print(num + " ");
        }
        System.out.println(lastTotal);

    }
} Main public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");

        int num1 = Integer.parseInt(line[0]);
        int num2 = Integer.parseInt(line[1]);
        ArrayList<Integer> aryNum = new ArrayList<Integer>();
        int[] totalCol = new int[num2];

        for(int i = 0; i < num1; i++){
        	String[] input = br.readLine().split(" ");
        	int total = 0;
        	for(int j = 0; j < num2; j++){
        		total += Integer.parseInt(input[j]);
        		aryNum.add(Integer.parseInt(input[j]));
        		totalCol[j] += Integer.parseInt(input[j]);
        	}
        	aryNum.add(total);
        }

        int count = 1;
        int lastTotal = 0;
        for(int num : aryNum){

        	System.out.print(num);
        	if(count % (num2 + 1) == 0){
        		lastTotal += num;
        		System.out.println();
        	}else{
        		System.out.print(" ");
        	}
        	count++;
        }

        for(int num : totalCol){
        	System.out.print(num + " ");
        }
        System.out.println(lastTotal);

    } main {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");

        int num1 = Integer.parseInt(line[0]);
        int num2 = Integer.parseInt(line[1]);
        ArrayList<Integer> aryNum = new ArrayList<Integer>();
        int[] totalCol = new int[num2];

        for(int i = 0; i < num1; i++){
        	String[] input = br.readLine().split(" ");
        	int total = 0;
        	for(int j = 0; j < num2; j++){
        		total += Integer.parseInt(input[j]);
        		aryNum.add(Integer.parseInt(input[j]));
        		totalCol[j] += Integer.parseInt(input[j]);
        	}
        	aryNum.add(total);
        }

        int count = 1;
        int lastTotal = 0;
        for(int num : aryNum){

        	System.out.print(num);
        	if(count % (num2 + 1) == 0){
        		lastTotal += num;
        		System.out.println();
        	}else{
        		System.out.print(" ");
        	}
        	count++;
        }

        for(int num : totalCol){
        	System.out.print(num + " ");
        }
        System.out.println(lastTotal);

    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] line = br.readLine().split(" "); line br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int num1 = Integer.parseInt(line[0]); num1 Integer.parseInt(line[0]) Integer.parseInt Integer line[0] line 0 int num2 = Integer.parseInt(line[1]); num2 Integer.parseInt(line[1]) Integer.parseInt Integer line[1] line 1 ArrayList<Integer> aryNum = new ArrayList<Integer>(); aryNum new ArrayList<Integer>() int[] totalCol = new int[num2]; totalCol new int[num2] num2 for(int i = 0; i < num1; i++){
        	String[] input = br.readLine().split(" ");
        	int total = 0;
        	for(int j = 0; j < num2; j++){
        		total += Integer.parseInt(input[j]);
        		aryNum.add(Integer.parseInt(input[j]));
        		totalCol[j] += Integer.parseInt(input[j]);
        	}
        	aryNum.add(total);
        } int i = 0; int i = 0; i 0 i < num1 i num1 i++ i++ i {
        	String[] input = br.readLine().split(" ");
        	int total = 0;
        	for(int j = 0; j < num2; j++){
        		total += Integer.parseInt(input[j]);
        		aryNum.add(Integer.parseInt(input[j]));
        		totalCol[j] += Integer.parseInt(input[j]);
        	}
        	aryNum.add(total);
        } {
        	String[] input = br.readLine().split(" ");
        	int total = 0;
        	for(int j = 0; j < num2; j++){
        		total += Integer.parseInt(input[j]);
        		aryNum.add(Integer.parseInt(input[j]));
        		totalCol[j] += Integer.parseInt(input[j]);
        	}
        	aryNum.add(total);
        } String[] input = br.readLine().split(" "); input br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int total = 0; total 0 for(int j = 0; j < num2; j++){
        		total += Integer.parseInt(input[j]);
        		aryNum.add(Integer.parseInt(input[j]));
        		totalCol[j] += Integer.parseInt(input[j]);
        	} int j = 0; int j = 0; j 0 j < num2 j num2 j++ j++ j {
        		total += Integer.parseInt(input[j]);
        		aryNum.add(Integer.parseInt(input[j]));
        		totalCol[j] += Integer.parseInt(input[j]);
        	} {
        		total += Integer.parseInt(input[j]);
        		aryNum.add(Integer.parseInt(input[j]));
        		totalCol[j] += Integer.parseInt(input[j]);
        	} total += Integer.parseInt(input[j]) total Integer.parseInt(input[j]) Integer.parseInt Integer input[j] input j aryNum.add(Integer.parseInt(input[j])) aryNum.add aryNum Integer.parseInt(input[j]) Integer.parseInt Integer input[j] input j totalCol[j] += Integer.parseInt(input[j]) totalCol[j] totalCol j Integer.parseInt(input[j]) Integer.parseInt Integer input[j] input j aryNum.add(total) aryNum.add aryNum total int count = 1; count 1 int lastTotal = 0; lastTotal 0 for(int num : aryNum){

        	System.out.print(num);
        	if(count % (num2 + 1) == 0){
        		lastTotal += num;
        		System.out.println();
        	}else{
        		System.out.print(" ");
        	}
        	count++;
        } int num aryNum {

        	System.out.print(num);
        	if(count % (num2 + 1) == 0){
        		lastTotal += num;
        		System.out.println();
        	}else{
        		System.out.print(" ");
        	}
        	count++;
        } {

        	System.out.print(num);
        	if(count % (num2 + 1) == 0){
        		lastTotal += num;
        		System.out.println();
        	}else{
        		System.out.print(" ");
        	}
        	count++;
        } System.out.print(num) System.out.print System.out System System.out num if(count % (num2 + 1) == 0){
        		lastTotal += num;
        		System.out.println();
        	}else{
        		System.out.print(" ");
        	} count % (num2 + 1) == 0 count % (num2 + 1) count (num2 + 1) num2 1 0 {
        		lastTotal += num;
        		System.out.println();
        	} lastTotal += num lastTotal num System.out.println() System.out.println System.out System System.out {
        		System.out.print(" ");
        	} System.out.print(" ") System.out.print System.out System System.out " " count++ count for(int num : totalCol){
        	System.out.print(num + " ");
        } int num totalCol {
        	System.out.print(num + " ");
        } {
        	System.out.print(num + " ");
        } System.out.print(num + " ") System.out.print System.out System System.out num + " " num " " System.out.println(lastTotal) System.out.println System.out System System.out lastTotal String[] args args public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");

        int num1 = Integer.parseInt(line[0]);
        int num2 = Integer.parseInt(line[1]);
        ArrayList<Integer> aryNum = new ArrayList<Integer>();
        int[] totalCol = new int[num2];

        for(int i = 0; i < num1; i++){
        	String[] input = br.readLine().split(" ");
        	int total = 0;
        	for(int j = 0; j < num2; j++){
        		total += Integer.parseInt(input[j]);
        		aryNum.add(Integer.parseInt(input[j]));
        		totalCol[j] += Integer.parseInt(input[j]);
        	}
        	aryNum.add(total);
        }

        int count = 1;
        int lastTotal = 0;
        for(int num : aryNum){

        	System.out.print(num);
        	if(count % (num2 + 1) == 0){
        		lastTotal += num;
        		System.out.println();
        	}else{
        		System.out.print(" ");
        	}
        	count++;
        }

        for(int num : totalCol){
        	System.out.print(num + " ");
        }
        System.out.println(lastTotal);

    }
} public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");

        int num1 = Integer.parseInt(line[0]);
        int num2 = Integer.parseInt(line[1]);
        ArrayList<Integer> aryNum = new ArrayList<Integer>();
        int[] totalCol = new int[num2];

        for(int i = 0; i < num1; i++){
        	String[] input = br.readLine().split(" ");
        	int total = 0;
        	for(int j = 0; j < num2; j++){
        		total += Integer.parseInt(input[j]);
        		aryNum.add(Integer.parseInt(input[j]));
        		totalCol[j] += Integer.parseInt(input[j]);
        	}
        	aryNum.add(total);
        }

        int count = 1;
        int lastTotal = 0;
        for(int num : aryNum){

        	System.out.print(num);
        	if(count % (num2 + 1) == 0){
        		lastTotal += num;
        		System.out.println();
        	}else{
        		System.out.print(" ");
        	}
        	count++;
        }

        for(int num : totalCol){
        	System.out.print(num + " ");
        }
        System.out.println(lastTotal);

    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] line = br.readLine().split(" ");

        int num1 = Integer.parseInt(line[0]);
        int num2 = Integer.parseInt(line[1]);
        ArrayList<Integer> aryNum = new ArrayList<Integer>();
        int[] totalCol = new int[num2];

        for(int i = 0; i < num1; i++){
        	String[] input = br.readLine().split(" ");
        	int total = 0;
        	for(int j = 0; j < num2; j++){
        		total += Integer.parseInt(input[j]);
        		aryNum.add(Integer.parseInt(input[j]));
        		totalCol[j] += Integer.parseInt(input[j]);
        	}
        	aryNum.add(total);
        }

        int count = 1;
        int lastTotal = 0;
        for(int num : aryNum){

        	System.out.print(num);
        	if(count % (num2 + 1) == 0){
        		lastTotal += num;
        		System.out.println();
        	}else{
        		System.out.print(" ");
        	}
        	count++;
        }

        for(int num : totalCol){
        	System.out.print(num + " ");
        }
        System.out.println(lastTotal);

    }
}