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

public class Main {

	public static void main(String[] args) {
		StringBuilder sb =new StringBuilder();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int r,c;
		String str;
		String strs[];
		try {
			str = br.readLine();
			strs=str.split(" ");
			r=Integer.parseInt(strs[0]);
			c=Integer.parseInt(strs[1]);
			int total[]=new int[c+1];
			for(int i=0;i<r;i++){
				int sum=0;
				str=br.readLine();
				strs=str.split(" ");
				for(int j=0;j<c;j++){
					sum+=Integer.parseInt(strs[j]);
					total[j]+=Integer.parseInt(strs[j]);
					sb.append(strs[j]).append(" ");
				}
				total[c]+=sum;
				sb.append(sum);
				sb.append("\n");
			}
			for(int i=0;i<c+1;i++){
				if(i != 0){
					sb.append(" ");
				}
				sb.append(total[i]);
			}
			System.out.println(sb);
		} catch (Exception e) {
			System.err.println(e);
		}

	}

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

	public static void main(String[] args) {
		StringBuilder sb =new StringBuilder();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int r,c;
		String str;
		String strs[];
		try {
			str = br.readLine();
			strs=str.split(" ");
			r=Integer.parseInt(strs[0]);
			c=Integer.parseInt(strs[1]);
			int total[]=new int[c+1];
			for(int i=0;i<r;i++){
				int sum=0;
				str=br.readLine();
				strs=str.split(" ");
				for(int j=0;j<c;j++){
					sum+=Integer.parseInt(strs[j]);
					total[j]+=Integer.parseInt(strs[j]);
					sb.append(strs[j]).append(" ");
				}
				total[c]+=sum;
				sb.append(sum);
				sb.append("\n");
			}
			for(int i=0;i<c+1;i++){
				if(i != 0){
					sb.append(" ");
				}
				sb.append(total[i]);
			}
			System.out.println(sb);
		} catch (Exception e) {
			System.err.println(e);
		}

	}

} Main public static void main(String[] args) {
		StringBuilder sb =new StringBuilder();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int r,c;
		String str;
		String strs[];
		try {
			str = br.readLine();
			strs=str.split(" ");
			r=Integer.parseInt(strs[0]);
			c=Integer.parseInt(strs[1]);
			int total[]=new int[c+1];
			for(int i=0;i<r;i++){
				int sum=0;
				str=br.readLine();
				strs=str.split(" ");
				for(int j=0;j<c;j++){
					sum+=Integer.parseInt(strs[j]);
					total[j]+=Integer.parseInt(strs[j]);
					sb.append(strs[j]).append(" ");
				}
				total[c]+=sum;
				sb.append(sum);
				sb.append("\n");
			}
			for(int i=0;i<c+1;i++){
				if(i != 0){
					sb.append(" ");
				}
				sb.append(total[i]);
			}
			System.out.println(sb);
		} catch (Exception e) {
			System.err.println(e);
		}

	} main {
		StringBuilder sb =new StringBuilder();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int r,c;
		String str;
		String strs[];
		try {
			str = br.readLine();
			strs=str.split(" ");
			r=Integer.parseInt(strs[0]);
			c=Integer.parseInt(strs[1]);
			int total[]=new int[c+1];
			for(int i=0;i<r;i++){
				int sum=0;
				str=br.readLine();
				strs=str.split(" ");
				for(int j=0;j<c;j++){
					sum+=Integer.parseInt(strs[j]);
					total[j]+=Integer.parseInt(strs[j]);
					sb.append(strs[j]).append(" ");
				}
				total[c]+=sum;
				sb.append(sum);
				sb.append("\n");
			}
			for(int i=0;i<c+1;i++){
				if(i != 0){
					sb.append(" ");
				}
				sb.append(total[i]);
			}
			System.out.println(sb);
		} catch (Exception e) {
			System.err.println(e);
		}

	} StringBuilder sb =new StringBuilder(); sb new StringBuilder() BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) int r r c; c String str; str String strs[]; strs try {
			str = br.readLine();
			strs=str.split(" ");
			r=Integer.parseInt(strs[0]);
			c=Integer.parseInt(strs[1]);
			int total[]=new int[c+1];
			for(int i=0;i<r;i++){
				int sum=0;
				str=br.readLine();
				strs=str.split(" ");
				for(int j=0;j<c;j++){
					sum+=Integer.parseInt(strs[j]);
					total[j]+=Integer.parseInt(strs[j]);
					sb.append(strs[j]).append(" ");
				}
				total[c]+=sum;
				sb.append(sum);
				sb.append("\n");
			}
			for(int i=0;i<c+1;i++){
				if(i != 0){
					sb.append(" ");
				}
				sb.append(total[i]);
			}
			System.out.println(sb);
		} catch (Exception e) {
			System.err.println(e);
		} catch (Exception e) {
			System.err.println(e);
		} Exception e {
			System.err.println(e);
		} System.err.println(e) System.err.println System.err System System.err e {
			str = br.readLine();
			strs=str.split(" ");
			r=Integer.parseInt(strs[0]);
			c=Integer.parseInt(strs[1]);
			int total[]=new int[c+1];
			for(int i=0;i<r;i++){
				int sum=0;
				str=br.readLine();
				strs=str.split(" ");
				for(int j=0;j<c;j++){
					sum+=Integer.parseInt(strs[j]);
					total[j]+=Integer.parseInt(strs[j]);
					sb.append(strs[j]).append(" ");
				}
				total[c]+=sum;
				sb.append(sum);
				sb.append("\n");
			}
			for(int i=0;i<c+1;i++){
				if(i != 0){
					sb.append(" ");
				}
				sb.append(total[i]);
			}
			System.out.println(sb);
		} str = br.readLine() str br.readLine() br.readLine br strs=str.split(" ") strs str.split(" ") str.split str " " r=Integer.parseInt(strs[0]) r Integer.parseInt(strs[0]) Integer.parseInt Integer strs[0] strs 0 c=Integer.parseInt(strs[1]) c Integer.parseInt(strs[1]) Integer.parseInt Integer strs[1] strs 1 int total[]=new int[c+1]; total new int[c+1] c+1 c 1 for(int i=0;i<r;i++){
				int sum=0;
				str=br.readLine();
				strs=str.split(" ");
				for(int j=0;j<c;j++){
					sum+=Integer.parseInt(strs[j]);
					total[j]+=Integer.parseInt(strs[j]);
					sb.append(strs[j]).append(" ");
				}
				total[c]+=sum;
				sb.append(sum);
				sb.append("\n");
			} int i=0; int i=0; i 0 i<r i r i++ i++ i {
				int sum=0;
				str=br.readLine();
				strs=str.split(" ");
				for(int j=0;j<c;j++){
					sum+=Integer.parseInt(strs[j]);
					total[j]+=Integer.parseInt(strs[j]);
					sb.append(strs[j]).append(" ");
				}
				total[c]+=sum;
				sb.append(sum);
				sb.append("\n");
			} {
				int sum=0;
				str=br.readLine();
				strs=str.split(" ");
				for(int j=0;j<c;j++){
					sum+=Integer.parseInt(strs[j]);
					total[j]+=Integer.parseInt(strs[j]);
					sb.append(strs[j]).append(" ");
				}
				total[c]+=sum;
				sb.append(sum);
				sb.append("\n");
			} int sum=0; sum 0 str=br.readLine() str br.readLine() br.readLine br strs=str.split(" ") strs str.split(" ") str.split str " " for(int j=0;j<c;j++){
					sum+=Integer.parseInt(strs[j]);
					total[j]+=Integer.parseInt(strs[j]);
					sb.append(strs[j]).append(" ");
				} int j=0; int j=0; j 0 j<c j c j++ j++ j {
					sum+=Integer.parseInt(strs[j]);
					total[j]+=Integer.parseInt(strs[j]);
					sb.append(strs[j]).append(" ");
				} {
					sum+=Integer.parseInt(strs[j]);
					total[j]+=Integer.parseInt(strs[j]);
					sb.append(strs[j]).append(" ");
				} sum+=Integer.parseInt(strs[j]) sum Integer.parseInt(strs[j]) Integer.parseInt Integer strs[j] strs j total[j]+=Integer.parseInt(strs[j]) total[j] total j Integer.parseInt(strs[j]) Integer.parseInt Integer strs[j] strs j sb.append(strs[j]).append(" ") sb.append(strs[j]).append sb.append(strs[j]) sb.append sb strs[j] strs j " " total[c]+=sum total[c] total c sum sb.append(sum) sb.append sb sum sb.append("\n") sb.append sb "\n" for(int i=0;i<c+1;i++){
				if(i != 0){
					sb.append(" ");
				}
				sb.append(total[i]);
			} int i=0; int i=0; i 0 i<c+1 i c+1 c 1 i++ i++ i {
				if(i != 0){
					sb.append(" ");
				}
				sb.append(total[i]);
			} {
				if(i != 0){
					sb.append(" ");
				}
				sb.append(total[i]);
			} if(i != 0){
					sb.append(" ");
				} i != 0 i 0 {
					sb.append(" ");
				} sb.append(" ") sb.append sb " " sb.append(total[i]) sb.append sb total[i] total i System.out.println(sb) System.out.println System.out System System.out sb String[] args args public class Main {

	public static void main(String[] args) {
		StringBuilder sb =new StringBuilder();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int r,c;
		String str;
		String strs[];
		try {
			str = br.readLine();
			strs=str.split(" ");
			r=Integer.parseInt(strs[0]);
			c=Integer.parseInt(strs[1]);
			int total[]=new int[c+1];
			for(int i=0;i<r;i++){
				int sum=0;
				str=br.readLine();
				strs=str.split(" ");
				for(int j=0;j<c;j++){
					sum+=Integer.parseInt(strs[j]);
					total[j]+=Integer.parseInt(strs[j]);
					sb.append(strs[j]).append(" ");
				}
				total[c]+=sum;
				sb.append(sum);
				sb.append("\n");
			}
			for(int i=0;i<c+1;i++){
				if(i != 0){
					sb.append(" ");
				}
				sb.append(total[i]);
			}
			System.out.println(sb);
		} catch (Exception e) {
			System.err.println(e);
		}

	}

} public class Main {

	public static void main(String[] args) {
		StringBuilder sb =new StringBuilder();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int r,c;
		String str;
		String strs[];
		try {
			str = br.readLine();
			strs=str.split(" ");
			r=Integer.parseInt(strs[0]);
			c=Integer.parseInt(strs[1]);
			int total[]=new int[c+1];
			for(int i=0;i<r;i++){
				int sum=0;
				str=br.readLine();
				strs=str.split(" ");
				for(int j=0;j<c;j++){
					sum+=Integer.parseInt(strs[j]);
					total[j]+=Integer.parseInt(strs[j]);
					sb.append(strs[j]).append(" ");
				}
				total[c]+=sum;
				sb.append(sum);
				sb.append("\n");
			}
			for(int i=0;i<c+1;i++){
				if(i != 0){
					sb.append(" ");
				}
				sb.append(total[i]);
			}
			System.out.println(sb);
		} catch (Exception e) {
			System.err.println(e);
		}

	}

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

public class Main {

	public static void main(String[] args) {
		StringBuilder sb =new StringBuilder();
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int r,c;
		String str;
		String strs[];
		try {
			str = br.readLine();
			strs=str.split(" ");
			r=Integer.parseInt(strs[0]);
			c=Integer.parseInt(strs[1]);
			int total[]=new int[c+1];
			for(int i=0;i<r;i++){
				int sum=0;
				str=br.readLine();
				strs=str.split(" ");
				for(int j=0;j<c;j++){
					sum+=Integer.parseInt(strs[j]);
					total[j]+=Integer.parseInt(strs[j]);
					sb.append(strs[j]).append(" ");
				}
				total[c]+=sum;
				sb.append(sum);
				sb.append("\n");
			}
			for(int i=0;i<c+1;i++){
				if(i != 0){
					sb.append(" ");
				}
				sb.append(total[i]);
			}
			System.out.println(sb);
		} catch (Exception e) {
			System.err.println(e);
		}

	}

}