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

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


			String[] str = br.readLine().split(" ");
			int r = Integer.parseInt(str[0]);
			int c = Integer.parseInt(str[1]);
			int[] csum= new int[c + 1];

			for(int i = 0; i<r; i++){
				str = br.readLine().split(" ");
				int value=0;
				for(int j = 0; j<c; j++ ){
					value += Integer.parseInt(str[j]);
					csum[j] += Integer.parseInt(str[j]);
					System.out.print(str[j] + " ");
				}
				System.out.println(value);
			}
			for(int i=0;i<c;i++){
				csum[c] += csum[i];
				System.out.print(csum[i] + " ");
			}
			System.out.println(csum[c]);


	}
} 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{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


			String[] str = br.readLine().split(" ");
			int r = Integer.parseInt(str[0]);
			int c = Integer.parseInt(str[1]);
			int[] csum= new int[c + 1];

			for(int i = 0; i<r; i++){
				str = br.readLine().split(" ");
				int value=0;
				for(int j = 0; j<c; j++ ){
					value += Integer.parseInt(str[j]);
					csum[j] += Integer.parseInt(str[j]);
					System.out.print(str[j] + " ");
				}
				System.out.println(value);
			}
			for(int i=0;i<c;i++){
				csum[c] += csum[i];
				System.out.print(csum[i] + " ");
			}
			System.out.println(csum[c]);


	}
} Main public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


			String[] str = br.readLine().split(" ");
			int r = Integer.parseInt(str[0]);
			int c = Integer.parseInt(str[1]);
			int[] csum= new int[c + 1];

			for(int i = 0; i<r; i++){
				str = br.readLine().split(" ");
				int value=0;
				for(int j = 0; j<c; j++ ){
					value += Integer.parseInt(str[j]);
					csum[j] += Integer.parseInt(str[j]);
					System.out.print(str[j] + " ");
				}
				System.out.println(value);
			}
			for(int i=0;i<c;i++){
				csum[c] += csum[i];
				System.out.print(csum[i] + " ");
			}
			System.out.println(csum[c]);


	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


			String[] str = br.readLine().split(" ");
			int r = Integer.parseInt(str[0]);
			int c = Integer.parseInt(str[1]);
			int[] csum= new int[c + 1];

			for(int i = 0; i<r; i++){
				str = br.readLine().split(" ");
				int value=0;
				for(int j = 0; j<c; j++ ){
					value += Integer.parseInt(str[j]);
					csum[j] += Integer.parseInt(str[j]);
					System.out.print(str[j] + " ");
				}
				System.out.println(value);
			}
			for(int i=0;i<c;i++){
				csum[c] += csum[i];
				System.out.print(csum[i] + " ");
			}
			System.out.println(csum[c]);


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


			String[] str = br.readLine().split(" ");
			int r = Integer.parseInt(str[0]);
			int c = Integer.parseInt(str[1]);
			int[] csum= new int[c + 1];

			for(int i = 0; i<r; i++){
				str = br.readLine().split(" ");
				int value=0;
				for(int j = 0; j<c; j++ ){
					value += Integer.parseInt(str[j]);
					csum[j] += Integer.parseInt(str[j]);
					System.out.print(str[j] + " ");
				}
				System.out.println(value);
			}
			for(int i=0;i<c;i++){
				csum[c] += csum[i];
				System.out.print(csum[i] + " ");
			}
			System.out.println(csum[c]);


	}
} public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


			String[] str = br.readLine().split(" ");
			int r = Integer.parseInt(str[0]);
			int c = Integer.parseInt(str[1]);
			int[] csum= new int[c + 1];

			for(int i = 0; i<r; i++){
				str = br.readLine().split(" ");
				int value=0;
				for(int j = 0; j<c; j++ ){
					value += Integer.parseInt(str[j]);
					csum[j] += Integer.parseInt(str[j]);
					System.out.print(str[j] + " ");
				}
				System.out.println(value);
			}
			for(int i=0;i<c;i++){
				csum[c] += csum[i];
				System.out.print(csum[i] + " ");
			}
			System.out.println(csum[c]);


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

public class Main {
	public static void main(String[] args) throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));


			String[] str = br.readLine().split(" ");
			int r = Integer.parseInt(str[0]);
			int c = Integer.parseInt(str[1]);
			int[] csum= new int[c + 1];

			for(int i = 0; i<r; i++){
				str = br.readLine().split(" ");
				int value=0;
				for(int j = 0; j<c; j++ ){
					value += Integer.parseInt(str[j]);
					csum[j] += Integer.parseInt(str[j]);
					System.out.print(str[j] + " ");
				}
				System.out.println(value);
			}
			for(int i=0;i<c;i++){
				csum[c] += csum[i];
				System.out.print(csum[i] + " ");
			}
			System.out.println(csum[c]);


	}
}