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

public final class Main {

	public static void main(String[] args) 
	throws IOException {
		// TODO Auto-generated method stub

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] arraysize = TempReaderCall.splitIntArrayFromString(TempReaderCall.getStdInRead(br));
		
		int[] ctotal = new int[arraysize[1]];
		ArrayList<String> list = TempReaderCall.getStdInReadlines(br, arraysize[0]);
		
		for (int i=0; i<arraysize[0]; i++){
			int[] rowdata = TempReaderCall.splitIntArrayFromString(list.get(i));
			addColumnData(ctotal, rowdata);
			System.out.println(list.get(i) + " " + sum(rowdata));
		}
		
		System.out.println(printRow(ctotal) + sum(ctotal));
		
	}
	
	static int sum (int[] data){
		int total = 0;
		for(int i=0; i < data.length; i++)
			total += data[i];
		
		return total;
	}
	
	static void addColumnData(int[] ctotal, int[] rowdata){
		for(int i=0; i<ctotal.length; i++)
			ctotal[i] += rowdata[i];
	}
	
	static String printRow(int[] ctotal){
		String line = "";
		for(int i=0; i < ctotal.length; i++) 
			line = line + Integer.toString(ctotal[i]) + " ";
		return line;
	}

}


class TempReaderCall{
	
	static ArrayList<String> getStdInReadlines(BufferedReader br, int line) throws IOException {
		ArrayList<String> list = new ArrayList<String>();
		for (int i = 0; i < line; i++)
			list.add(br.readLine());
		return list;
	}
	
	static String getStdInRead(BufferedReader br) throws IOException {
		return (br.readLine());
	}
	
	
	static int[] splitIntArrayFromString(String st) {
		String[] sts = st.split(" ");
		int[] data = new int[sts.length];
		
		for (int i=0;i<sts.length;i++){
			data[i] = Integer.parseInt(sts[i]);
		}
		
		return data;
	}
} import java.util.ArrayList; ArrayList java.util import java.io.InputStreamReader; InputStreamReader java.io import java.io.IOException; IOException java.io import java.io.BufferedReader; BufferedReader java.io public final class Main {

	public static void main(String[] args) 
	throws IOException {
		// TODO Auto-generated method stub

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] arraysize = TempReaderCall.splitIntArrayFromString(TempReaderCall.getStdInRead(br));
		
		int[] ctotal = new int[arraysize[1]];
		ArrayList<String> list = TempReaderCall.getStdInReadlines(br, arraysize[0]);
		
		for (int i=0; i<arraysize[0]; i++){
			int[] rowdata = TempReaderCall.splitIntArrayFromString(list.get(i));
			addColumnData(ctotal, rowdata);
			System.out.println(list.get(i) + " " + sum(rowdata));
		}
		
		System.out.println(printRow(ctotal) + sum(ctotal));
		
	}
	
	static int sum (int[] data){
		int total = 0;
		for(int i=0; i < data.length; i++)
			total += data[i];
		
		return total;
	}
	
	static void addColumnData(int[] ctotal, int[] rowdata){
		for(int i=0; i<ctotal.length; i++)
			ctotal[i] += rowdata[i];
	}
	
	static String printRow(int[] ctotal){
		String line = "";
		for(int i=0; i < ctotal.length; i++) 
			line = line + Integer.toString(ctotal[i]) + " ";
		return line;
	}

} Main public static void main(String[] args) 
	throws IOException {
		// TODO Auto-generated method stub

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] arraysize = TempReaderCall.splitIntArrayFromString(TempReaderCall.getStdInRead(br));
		
		int[] ctotal = new int[arraysize[1]];
		ArrayList<String> list = TempReaderCall.getStdInReadlines(br, arraysize[0]);
		
		for (int i=0; i<arraysize[0]; i++){
			int[] rowdata = TempReaderCall.splitIntArrayFromString(list.get(i));
			addColumnData(ctotal, rowdata);
			System.out.println(list.get(i) + " " + sum(rowdata));
		}
		
		System.out.println(printRow(ctotal) + sum(ctotal));
		
	} main {
		// TODO Auto-generated method stub

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] arraysize = TempReaderCall.splitIntArrayFromString(TempReaderCall.getStdInRead(br));
		
		int[] ctotal = new int[arraysize[1]];
		ArrayList<String> list = TempReaderCall.getStdInReadlines(br, arraysize[0]);
		
		for (int i=0; i<arraysize[0]; i++){
			int[] rowdata = TempReaderCall.splitIntArrayFromString(list.get(i));
			addColumnData(ctotal, rowdata);
			System.out.println(list.get(i) + " " + sum(rowdata));
		}
		
		System.out.println(printRow(ctotal) + sum(ctotal));
		
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int[] arraysize = TempReaderCall.splitIntArrayFromString(TempReaderCall.getStdInRead(br)); arraysize TempReaderCall.splitIntArrayFromString(TempReaderCall.getStdInRead(br)) TempReaderCall.splitIntArrayFromString TempReaderCall TempReaderCall.getStdInRead(br) TempReaderCall.getStdInRead TempReaderCall br int[] ctotal = new int[arraysize[1]]; ctotal new int[arraysize[1]] arraysize[1] arraysize 1 ArrayList<String> list = TempReaderCall.getStdInReadlines(br, arraysize[0]); list TempReaderCall.getStdInReadlines(br, arraysize[0]) TempReaderCall.getStdInReadlines TempReaderCall br arraysize[0] arraysize 0 for (int i=0; i<arraysize[0]; i++){
			int[] rowdata = TempReaderCall.splitIntArrayFromString(list.get(i));
			addColumnData(ctotal, rowdata);
			System.out.println(list.get(i) + " " + sum(rowdata));
		} int i=0; int i=0; i 0 i<arraysize[0] i arraysize[0] arraysize 0 i++ i++ i {
			int[] rowdata = TempReaderCall.splitIntArrayFromString(list.get(i));
			addColumnData(ctotal, rowdata);
			System.out.println(list.get(i) + " " + sum(rowdata));
		} {
			int[] rowdata = TempReaderCall.splitIntArrayFromString(list.get(i));
			addColumnData(ctotal, rowdata);
			System.out.println(list.get(i) + " " + sum(rowdata));
		} int[] rowdata = TempReaderCall.splitIntArrayFromString(list.get(i)); rowdata TempReaderCall.splitIntArrayFromString(list.get(i)) TempReaderCall.splitIntArrayFromString TempReaderCall list.get(i) list.get list i addColumnData(ctotal, rowdata) addColumnData ctotal rowdata System.out.println(list.get(i) + " " + sum(rowdata)) System.out.println System.out System System.out list.get(i) + " " + sum(rowdata) list.get(i) + " " + sum(rowdata) list.get(i) list.get list i " " sum(rowdata) sum rowdata System.out.println(printRow(ctotal) + sum(ctotal)) System.out.println System.out System System.out printRow(ctotal) + sum(ctotal) printRow(ctotal) printRow ctotal sum(ctotal) sum ctotal String[] args args static int sum (int[] data){
		int total = 0;
		for(int i=0; i < data.length; i++)
			total += data[i];
		
		return total;
	} sum {
		int total = 0;
		for(int i=0; i < data.length; i++)
			total += data[i];
		
		return total;
	} int total = 0; total 0 for(int i=0; i < data.length; i++)
			total += data[i]; int i=0; int i=0; i 0 i < data.length i data.length data data.length i++ i++ i total += data[i]; total += data[i] total data[i] data i return total; total int[] data data static void addColumnData(int[] ctotal, int[] rowdata){
		for(int i=0; i<ctotal.length; i++)
			ctotal[i] += rowdata[i];
	} addColumnData {
		for(int i=0; i<ctotal.length; i++)
			ctotal[i] += rowdata[i];
	} for(int i=0; i<ctotal.length; i++)
			ctotal[i] += rowdata[i]; int i=0; int i=0; i 0 i<ctotal.length i ctotal.length ctotal ctotal.length i++ i++ i ctotal[i] += rowdata[i]; ctotal[i] += rowdata[i] ctotal[i] ctotal i rowdata[i] rowdata i int[] ctotal ctotal int[] rowdata rowdata static String printRow(int[] ctotal){
		String line = "";
		for(int i=0; i < ctotal.length; i++) 
			line = line + Integer.toString(ctotal[i]) + " ";
		return line;
	} printRow {
		String line = "";
		for(int i=0; i < ctotal.length; i++) 
			line = line + Integer.toString(ctotal[i]) + " ";
		return line;
	} String line = ""; line "" for(int i=0; i < ctotal.length; i++) 
			line = line + Integer.toString(ctotal[i]) + " "; int i=0; int i=0; i 0 i < ctotal.length i ctotal.length ctotal ctotal.length i++ i++ i line = line + Integer.toString(ctotal[i]) + " "; line = line + Integer.toString(ctotal[i]) + " " line line + Integer.toString(ctotal[i]) + " " line + Integer.toString(ctotal[i]) + " " line Integer.toString(ctotal[i]) Integer.toString Integer ctotal[i] ctotal i " " return line; line int[] ctotal ctotal class TempReaderCall{
	
	static ArrayList<String> getStdInReadlines(BufferedReader br, int line) throws IOException {
		ArrayList<String> list = new ArrayList<String>();
		for (int i = 0; i < line; i++)
			list.add(br.readLine());
		return list;
	}
	
	static String getStdInRead(BufferedReader br) throws IOException {
		return (br.readLine());
	}
	
	
	static int[] splitIntArrayFromString(String st) {
		String[] sts = st.split(" ");
		int[] data = new int[sts.length];
		
		for (int i=0;i<sts.length;i++){
			data[i] = Integer.parseInt(sts[i]);
		}
		
		return data;
	}
} TempReaderCall static ArrayList<String> getStdInReadlines(BufferedReader br, int line) throws IOException {
		ArrayList<String> list = new ArrayList<String>();
		for (int i = 0; i < line; i++)
			list.add(br.readLine());
		return list;
	} getStdInReadlines {
		ArrayList<String> list = new ArrayList<String>();
		for (int i = 0; i < line; i++)
			list.add(br.readLine());
		return list;
	} ArrayList<String> list = new ArrayList<String>(); list new ArrayList<String>() for (int i = 0; i < line; i++)
			list.add(br.readLine()); int i = 0; int i = 0; i 0 i < line i line i++ i++ i list.add(br.readLine()); list.add(br.readLine()) list.add list br.readLine() br.readLine br return list; list BufferedReader br br int line line static String getStdInRead(BufferedReader br) throws IOException {
		return (br.readLine());
	} getStdInRead {
		return (br.readLine());
	} return (br.readLine()); (br.readLine()) br.readLine br BufferedReader br br static int[] splitIntArrayFromString(String st) {
		String[] sts = st.split(" ");
		int[] data = new int[sts.length];
		
		for (int i=0;i<sts.length;i++){
			data[i] = Integer.parseInt(sts[i]);
		}
		
		return data;
	} splitIntArrayFromString {
		String[] sts = st.split(" ");
		int[] data = new int[sts.length];
		
		for (int i=0;i<sts.length;i++){
			data[i] = Integer.parseInt(sts[i]);
		}
		
		return data;
	} String[] sts = st.split(" "); sts st.split(" ") st.split st " " int[] data = new int[sts.length]; data new int[sts.length] sts.length sts sts.length for (int i=0;i<sts.length;i++){
			data[i] = Integer.parseInt(sts[i]);
		} int i=0; int i=0; i 0 i<sts.length i sts.length sts sts.length i++ i++ i {
			data[i] = Integer.parseInt(sts[i]);
		} {
			data[i] = Integer.parseInt(sts[i]);
		} data[i] = Integer.parseInt(sts[i]) data[i] data i Integer.parseInt(sts[i]) Integer.parseInt Integer sts[i] sts i return data; data String st st public final class Main {

	public static void main(String[] args) 
	throws IOException {
		// TODO Auto-generated method stub

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] arraysize = TempReaderCall.splitIntArrayFromString(TempReaderCall.getStdInRead(br));
		
		int[] ctotal = new int[arraysize[1]];
		ArrayList<String> list = TempReaderCall.getStdInReadlines(br, arraysize[0]);
		
		for (int i=0; i<arraysize[0]; i++){
			int[] rowdata = TempReaderCall.splitIntArrayFromString(list.get(i));
			addColumnData(ctotal, rowdata);
			System.out.println(list.get(i) + " " + sum(rowdata));
		}
		
		System.out.println(printRow(ctotal) + sum(ctotal));
		
	}
	
	static int sum (int[] data){
		int total = 0;
		for(int i=0; i < data.length; i++)
			total += data[i];
		
		return total;
	}
	
	static void addColumnData(int[] ctotal, int[] rowdata){
		for(int i=0; i<ctotal.length; i++)
			ctotal[i] += rowdata[i];
	}
	
	static String printRow(int[] ctotal){
		String line = "";
		for(int i=0; i < ctotal.length; i++) 
			line = line + Integer.toString(ctotal[i]) + " ";
		return line;
	}

} public final class Main {

	public static void main(String[] args) 
	throws IOException {
		// TODO Auto-generated method stub

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] arraysize = TempReaderCall.splitIntArrayFromString(TempReaderCall.getStdInRead(br));
		
		int[] ctotal = new int[arraysize[1]];
		ArrayList<String> list = TempReaderCall.getStdInReadlines(br, arraysize[0]);
		
		for (int i=0; i<arraysize[0]; i++){
			int[] rowdata = TempReaderCall.splitIntArrayFromString(list.get(i));
			addColumnData(ctotal, rowdata);
			System.out.println(list.get(i) + " " + sum(rowdata));
		}
		
		System.out.println(printRow(ctotal) + sum(ctotal));
		
	}
	
	static int sum (int[] data){
		int total = 0;
		for(int i=0; i < data.length; i++)
			total += data[i];
		
		return total;
	}
	
	static void addColumnData(int[] ctotal, int[] rowdata){
		for(int i=0; i<ctotal.length; i++)
			ctotal[i] += rowdata[i];
	}
	
	static String printRow(int[] ctotal){
		String line = "";
		for(int i=0; i < ctotal.length; i++) 
			line = line + Integer.toString(ctotal[i]) + " ";
		return line;
	}

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

public final class Main {

	public static void main(String[] args) 
	throws IOException {
		// TODO Auto-generated method stub

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int[] arraysize = TempReaderCall.splitIntArrayFromString(TempReaderCall.getStdInRead(br));
		
		int[] ctotal = new int[arraysize[1]];
		ArrayList<String> list = TempReaderCall.getStdInReadlines(br, arraysize[0]);
		
		for (int i=0; i<arraysize[0]; i++){
			int[] rowdata = TempReaderCall.splitIntArrayFromString(list.get(i));
			addColumnData(ctotal, rowdata);
			System.out.println(list.get(i) + " " + sum(rowdata));
		}
		
		System.out.println(printRow(ctotal) + sum(ctotal));
		
	}
	
	static int sum (int[] data){
		int total = 0;
		for(int i=0; i < data.length; i++)
			total += data[i];
		
		return total;
	}
	
	static void addColumnData(int[] ctotal, int[] rowdata){
		for(int i=0; i<ctotal.length; i++)
			ctotal[i] += rowdata[i];
	}
	
	static String printRow(int[] ctotal){
		String line = "";
		for(int i=0; i < ctotal.length; i++) 
			line = line + Integer.toString(ctotal[i]) + " ";
		return line;
	}

}


class TempReaderCall{
	
	static ArrayList<String> getStdInReadlines(BufferedReader br, int line) throws IOException {
		ArrayList<String> list = new ArrayList<String>();
		for (int i = 0; i < line; i++)
			list.add(br.readLine());
		return list;
	}
	
	static String getStdInRead(BufferedReader br) throws IOException {
		return (br.readLine());
	}
	
	
	static int[] splitIntArrayFromString(String st) {
		String[] sts = st.split(" ");
		int[] data = new int[sts.length];
		
		for (int i=0;i<sts.length;i++){
			data[i] = Integer.parseInt(sts[i]);
		}
		
		return data;
	}
}