import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int r = Integer.parseInt(std.next());
		int c = Integer.parseInt(std.next());
		int table[][] = new int[r+1][c+1];
		for(int i=0; i<=r-1; i++){
			int rsum = 0;
			for(int j=0; j<=c; j++){
				if(j<c){
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				}else{
					table[i][j] = rsum;
				}
			}
		}
		for(int j=0; j<=c; j++){
			int csum = 0;
			for(int i=0; i<=r; i++){
				if(i<r){
					csum += table[i][j];
				}else{
					table[i][j] = csum;
				}
			}
		}
		for(int i=0; i<=r; i++){
			String line = String.valueOf(table[i][0]);
			for(int j=1; j<=c; j++){
				line += ( " "+ String.valueOf(table[i][j]));
			}
			System.out.println(line);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int r = Integer.parseInt(std.next());
		int c = Integer.parseInt(std.next());
		int table[][] = new int[r+1][c+1];
		for(int i=0; i<=r-1; i++){
			int rsum = 0;
			for(int j=0; j<=c; j++){
				if(j<c){
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				}else{
					table[i][j] = rsum;
				}
			}
		}
		for(int j=0; j<=c; j++){
			int csum = 0;
			for(int i=0; i<=r; i++){
				if(i<r){
					csum += table[i][j];
				}else{
					table[i][j] = csum;
				}
			}
		}
		for(int i=0; i<=r; i++){
			String line = String.valueOf(table[i][0]);
			for(int j=1; j<=c; j++){
				line += ( " "+ String.valueOf(table[i][j]));
			}
			System.out.println(line);
		}
	}
} Main public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int r = Integer.parseInt(std.next());
		int c = Integer.parseInt(std.next());
		int table[][] = new int[r+1][c+1];
		for(int i=0; i<=r-1; i++){
			int rsum = 0;
			for(int j=0; j<=c; j++){
				if(j<c){
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				}else{
					table[i][j] = rsum;
				}
			}
		}
		for(int j=0; j<=c; j++){
			int csum = 0;
			for(int i=0; i<=r; i++){
				if(i<r){
					csum += table[i][j];
				}else{
					table[i][j] = csum;
				}
			}
		}
		for(int i=0; i<=r; i++){
			String line = String.valueOf(table[i][0]);
			for(int j=1; j<=c; j++){
				line += ( " "+ String.valueOf(table[i][j]));
			}
			System.out.println(line);
		}
	} main {
		Scanner std = new Scanner(System.in);
		int r = Integer.parseInt(std.next());
		int c = Integer.parseInt(std.next());
		int table[][] = new int[r+1][c+1];
		for(int i=0; i<=r-1; i++){
			int rsum = 0;
			for(int j=0; j<=c; j++){
				if(j<c){
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				}else{
					table[i][j] = rsum;
				}
			}
		}
		for(int j=0; j<=c; j++){
			int csum = 0;
			for(int i=0; i<=r; i++){
				if(i<r){
					csum += table[i][j];
				}else{
					table[i][j] = csum;
				}
			}
		}
		for(int i=0; i<=r; i++){
			String line = String.valueOf(table[i][0]);
			for(int j=1; j<=c; j++){
				line += ( " "+ String.valueOf(table[i][j]));
			}
			System.out.println(line);
		}
	} Scanner std = new Scanner(System.in); std new Scanner(System.in) int r = Integer.parseInt(std.next()); r Integer.parseInt(std.next()) Integer.parseInt Integer std.next() std.next std int c = Integer.parseInt(std.next()); c Integer.parseInt(std.next()) Integer.parseInt Integer std.next() std.next std int table[][] = new int[r+1][c+1]; table new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i=0; i<=r-1; i++){
			int rsum = 0;
			for(int j=0; j<=c; j++){
				if(j<c){
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				}else{
					table[i][j] = rsum;
				}
			}
		} int i=0; int i=0; i 0 i<=r-1 i r-1 r 1 i++ i++ i {
			int rsum = 0;
			for(int j=0; j<=c; j++){
				if(j<c){
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				}else{
					table[i][j] = rsum;
				}
			}
		} {
			int rsum = 0;
			for(int j=0; j<=c; j++){
				if(j<c){
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				}else{
					table[i][j] = rsum;
				}
			}
		} int rsum = 0; rsum 0 for(int j=0; j<=c; j++){
				if(j<c){
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				}else{
					table[i][j] = rsum;
				}
			} int j=0; int j=0; j 0 j<=c j c j++ j++ j {
				if(j<c){
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				}else{
					table[i][j] = rsum;
				}
			} {
				if(j<c){
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				}else{
					table[i][j] = rsum;
				}
			} if(j<c){
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				}else{
					table[i][j] = rsum;
				} j<c j c {
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				} table[i][j] = Integer.parseInt(std.next()) table[i][j] table[i] table i j Integer.parseInt(std.next()) Integer.parseInt Integer std.next() std.next std rsum += table[i][j] rsum table[i][j] table[i] table i j {
					table[i][j] = rsum;
				} table[i][j] = rsum table[i][j] table[i] table i j rsum for(int j=0; j<=c; j++){
			int csum = 0;
			for(int i=0; i<=r; i++){
				if(i<r){
					csum += table[i][j];
				}else{
					table[i][j] = csum;
				}
			}
		} int j=0; int j=0; j 0 j<=c j c j++ j++ j {
			int csum = 0;
			for(int i=0; i<=r; i++){
				if(i<r){
					csum += table[i][j];
				}else{
					table[i][j] = csum;
				}
			}
		} {
			int csum = 0;
			for(int i=0; i<=r; i++){
				if(i<r){
					csum += table[i][j];
				}else{
					table[i][j] = csum;
				}
			}
		} int csum = 0; csum 0 for(int i=0; i<=r; i++){
				if(i<r){
					csum += table[i][j];
				}else{
					table[i][j] = csum;
				}
			} int i=0; int i=0; i 0 i<=r i r i++ i++ i {
				if(i<r){
					csum += table[i][j];
				}else{
					table[i][j] = csum;
				}
			} {
				if(i<r){
					csum += table[i][j];
				}else{
					table[i][j] = csum;
				}
			} if(i<r){
					csum += table[i][j];
				}else{
					table[i][j] = csum;
				} i<r i r {
					csum += table[i][j];
				} csum += table[i][j] csum table[i][j] table[i] table i j {
					table[i][j] = csum;
				} table[i][j] = csum table[i][j] table[i] table i j csum for(int i=0; i<=r; i++){
			String line = String.valueOf(table[i][0]);
			for(int j=1; j<=c; j++){
				line += ( " "+ String.valueOf(table[i][j]));
			}
			System.out.println(line);
		} int i=0; int i=0; i 0 i<=r i r i++ i++ i {
			String line = String.valueOf(table[i][0]);
			for(int j=1; j<=c; j++){
				line += ( " "+ String.valueOf(table[i][j]));
			}
			System.out.println(line);
		} {
			String line = String.valueOf(table[i][0]);
			for(int j=1; j<=c; j++){
				line += ( " "+ String.valueOf(table[i][j]));
			}
			System.out.println(line);
		} String line = String.valueOf(table[i][0]); line String.valueOf(table[i][0]) String.valueOf String table[i][0] table[i] table i 0 for(int j=1; j<=c; j++){
				line += ( " "+ String.valueOf(table[i][j]));
			} int j=1; int j=1; j 1 j<=c j c j++ j++ j {
				line += ( " "+ String.valueOf(table[i][j]));
			} {
				line += ( " "+ String.valueOf(table[i][j]));
			} line += ( " "+ String.valueOf(table[i][j])) line ( " "+ String.valueOf(table[i][j])) " " String.valueOf(table[i][j]) String.valueOf String table[i][j] table[i] table i j System.out.println(line) System.out.println System.out System System.out line String[] args args public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int r = Integer.parseInt(std.next());
		int c = Integer.parseInt(std.next());
		int table[][] = new int[r+1][c+1];
		for(int i=0; i<=r-1; i++){
			int rsum = 0;
			for(int j=0; j<=c; j++){
				if(j<c){
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				}else{
					table[i][j] = rsum;
				}
			}
		}
		for(int j=0; j<=c; j++){
			int csum = 0;
			for(int i=0; i<=r; i++){
				if(i<r){
					csum += table[i][j];
				}else{
					table[i][j] = csum;
				}
			}
		}
		for(int i=0; i<=r; i++){
			String line = String.valueOf(table[i][0]);
			for(int j=1; j<=c; j++){
				line += ( " "+ String.valueOf(table[i][j]));
			}
			System.out.println(line);
		}
	}
} public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int r = Integer.parseInt(std.next());
		int c = Integer.parseInt(std.next());
		int table[][] = new int[r+1][c+1];
		for(int i=0; i<=r-1; i++){
			int rsum = 0;
			for(int j=0; j<=c; j++){
				if(j<c){
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				}else{
					table[i][j] = rsum;
				}
			}
		}
		for(int j=0; j<=c; j++){
			int csum = 0;
			for(int i=0; i<=r; i++){
				if(i<r){
					csum += table[i][j];
				}else{
					table[i][j] = csum;
				}
			}
		}
		for(int i=0; i<=r; i++){
			String line = String.valueOf(table[i][0]);
			for(int j=1; j<=c; j++){
				line += ( " "+ String.valueOf(table[i][j]));
			}
			System.out.println(line);
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner std = new Scanner(System.in);
		int r = Integer.parseInt(std.next());
		int c = Integer.parseInt(std.next());
		int table[][] = new int[r+1][c+1];
		for(int i=0; i<=r-1; i++){
			int rsum = 0;
			for(int j=0; j<=c; j++){
				if(j<c){
					table[i][j] = Integer.parseInt(std.next());
					rsum += table[i][j];
				}else{
					table[i][j] = rsum;
				}
			}
		}
		for(int j=0; j<=c; j++){
			int csum = 0;
			for(int i=0; i<=r; i++){
				if(i<r){
					csum += table[i][j];
				}else{
					table[i][j] = csum;
				}
			}
		}
		for(int i=0; i<=r; i++){
			String line = String.valueOf(table[i][0]);
			for(int j=1; j<=c; j++){
				line += ( " "+ String.valueOf(table[i][j]));
			}
			System.out.println(line);
		}
	}
}