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