import java.io.IOException;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws IOException {

		Scanner scane = new Scanner(System.in);

		int r = 0, c = 0;

		r = scane.nextInt();
		c = scane.nextInt();

		int[][] rc = new int[r][c];

		int[] r1 = new int[r];
		int[] c1 = new int[c];

		for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				rc[i][j] = scane.nextInt();
			}
		}
		int nums =0;

		for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				r1[i] += rc[i][j];
			}
		}
		for(int i=0; i<rc[0].length; i++){
			for(int j=0; j<rc.length; j++){

				c1[i] += rc[j][i];
			}
			nums += c1[i];
		}


		for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				System.out.print(rc[i][j]+" ");
			}
			System.out.println(r1[i]+"");
		}
		for(int num : c1){
			System.out.print(num+" ");
		}
		System.out.print(nums+"\n");

	}
} import java.io.IOException; IOException java.io import java.util.Scanner; Scanner java.util class Main {

	public static void main(String[] args) throws IOException {

		Scanner scane = new Scanner(System.in);

		int r = 0, c = 0;

		r = scane.nextInt();
		c = scane.nextInt();

		int[][] rc = new int[r][c];

		int[] r1 = new int[r];
		int[] c1 = new int[c];

		for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				rc[i][j] = scane.nextInt();
			}
		}
		int nums =0;

		for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				r1[i] += rc[i][j];
			}
		}
		for(int i=0; i<rc[0].length; i++){
			for(int j=0; j<rc.length; j++){

				c1[i] += rc[j][i];
			}
			nums += c1[i];
		}


		for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				System.out.print(rc[i][j]+" ");
			}
			System.out.println(r1[i]+"");
		}
		for(int num : c1){
			System.out.print(num+" ");
		}
		System.out.print(nums+"\n");

	}
} Main public static void main(String[] args) throws IOException {

		Scanner scane = new Scanner(System.in);

		int r = 0, c = 0;

		r = scane.nextInt();
		c = scane.nextInt();

		int[][] rc = new int[r][c];

		int[] r1 = new int[r];
		int[] c1 = new int[c];

		for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				rc[i][j] = scane.nextInt();
			}
		}
		int nums =0;

		for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				r1[i] += rc[i][j];
			}
		}
		for(int i=0; i<rc[0].length; i++){
			for(int j=0; j<rc.length; j++){

				c1[i] += rc[j][i];
			}
			nums += c1[i];
		}


		for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				System.out.print(rc[i][j]+" ");
			}
			System.out.println(r1[i]+"");
		}
		for(int num : c1){
			System.out.print(num+" ");
		}
		System.out.print(nums+"\n");

	} main {

		Scanner scane = new Scanner(System.in);

		int r = 0, c = 0;

		r = scane.nextInt();
		c = scane.nextInt();

		int[][] rc = new int[r][c];

		int[] r1 = new int[r];
		int[] c1 = new int[c];

		for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				rc[i][j] = scane.nextInt();
			}
		}
		int nums =0;

		for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				r1[i] += rc[i][j];
			}
		}
		for(int i=0; i<rc[0].length; i++){
			for(int j=0; j<rc.length; j++){

				c1[i] += rc[j][i];
			}
			nums += c1[i];
		}


		for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				System.out.print(rc[i][j]+" ");
			}
			System.out.println(r1[i]+"");
		}
		for(int num : c1){
			System.out.print(num+" ");
		}
		System.out.print(nums+"\n");

	} Scanner scane = new Scanner(System.in); scane new Scanner(System.in) int r = 0 r 0 c = 0; c 0 r = scane.nextInt() r scane.nextInt() scane.nextInt scane c = scane.nextInt() c scane.nextInt() scane.nextInt scane int[][] rc = new int[r][c]; rc new int[r][c] r c int[] r1 = new int[r]; r1 new int[r] r int[] c1 = new int[c]; c1 new int[c] c for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				rc[i][j] = scane.nextInt();
			}
		} int i=0; int i=0; i 0 i<rc.length i rc.length rc rc.length i++ i++ i {
			for(int j=0; j<rc[0].length; j++){

				rc[i][j] = scane.nextInt();
			}
		} {
			for(int j=0; j<rc[0].length; j++){

				rc[i][j] = scane.nextInt();
			}
		} for(int j=0; j<rc[0].length; j++){

				rc[i][j] = scane.nextInt();
			} int j=0; int j=0; j 0 j<rc[0].length j rc[0].length rc[0] rc 0 rc[0].length j++ j++ j {

				rc[i][j] = scane.nextInt();
			} {

				rc[i][j] = scane.nextInt();
			} rc[i][j] = scane.nextInt() rc[i][j] rc[i] rc i j scane.nextInt() scane.nextInt scane int nums =0; nums 0 for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				r1[i] += rc[i][j];
			}
		} int i=0; int i=0; i 0 i<rc.length i rc.length rc rc.length i++ i++ i {
			for(int j=0; j<rc[0].length; j++){

				r1[i] += rc[i][j];
			}
		} {
			for(int j=0; j<rc[0].length; j++){

				r1[i] += rc[i][j];
			}
		} for(int j=0; j<rc[0].length; j++){

				r1[i] += rc[i][j];
			} int j=0; int j=0; j 0 j<rc[0].length j rc[0].length rc[0] rc 0 rc[0].length j++ j++ j {

				r1[i] += rc[i][j];
			} {

				r1[i] += rc[i][j];
			} r1[i] += rc[i][j] r1[i] r1 i rc[i][j] rc[i] rc i j for(int i=0; i<rc[0].length; i++){
			for(int j=0; j<rc.length; j++){

				c1[i] += rc[j][i];
			}
			nums += c1[i];
		} int i=0; int i=0; i 0 i<rc[0].length i rc[0].length rc[0] rc 0 rc[0].length i++ i++ i {
			for(int j=0; j<rc.length; j++){

				c1[i] += rc[j][i];
			}
			nums += c1[i];
		} {
			for(int j=0; j<rc.length; j++){

				c1[i] += rc[j][i];
			}
			nums += c1[i];
		} for(int j=0; j<rc.length; j++){

				c1[i] += rc[j][i];
			} int j=0; int j=0; j 0 j<rc.length j rc.length rc rc.length j++ j++ j {

				c1[i] += rc[j][i];
			} {

				c1[i] += rc[j][i];
			} c1[i] += rc[j][i] c1[i] c1 i rc[j][i] rc[j] rc j i nums += c1[i] nums c1[i] c1 i for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				System.out.print(rc[i][j]+" ");
			}
			System.out.println(r1[i]+"");
		} int i=0; int i=0; i 0 i<rc.length i rc.length rc rc.length i++ i++ i {
			for(int j=0; j<rc[0].length; j++){

				System.out.print(rc[i][j]+" ");
			}
			System.out.println(r1[i]+"");
		} {
			for(int j=0; j<rc[0].length; j++){

				System.out.print(rc[i][j]+" ");
			}
			System.out.println(r1[i]+"");
		} for(int j=0; j<rc[0].length; j++){

				System.out.print(rc[i][j]+" ");
			} int j=0; int j=0; j 0 j<rc[0].length j rc[0].length rc[0] rc 0 rc[0].length j++ j++ j {

				System.out.print(rc[i][j]+" ");
			} {

				System.out.print(rc[i][j]+" ");
			} System.out.print(rc[i][j]+" ") System.out.print System.out System System.out rc[i][j]+" " rc[i][j] rc[i] rc i j " " System.out.println(r1[i]+"") System.out.println System.out System System.out r1[i]+"" r1[i] r1 i "" for(int num : c1){
			System.out.print(num+" ");
		} int num c1 {
			System.out.print(num+" ");
		} {
			System.out.print(num+" ");
		} System.out.print(num+" ") System.out.print System.out System System.out num+" " num " " System.out.print(nums+"\n") System.out.print System.out System System.out nums+"\n" nums "\n" String[] args args
import java.io.IOException;
import java.util.Scanner;

class Main {

	public static void main(String[] args) throws IOException {

		Scanner scane = new Scanner(System.in);

		int r = 0, c = 0;

		r = scane.nextInt();
		c = scane.nextInt();

		int[][] rc = new int[r][c];

		int[] r1 = new int[r];
		int[] c1 = new int[c];

		for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				rc[i][j] = scane.nextInt();
			}
		}
		int nums =0;

		for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				r1[i] += rc[i][j];
			}
		}
		for(int i=0; i<rc[0].length; i++){
			for(int j=0; j<rc.length; j++){

				c1[i] += rc[j][i];
			}
			nums += c1[i];
		}


		for(int i=0; i<rc.length; i++){
			for(int j=0; j<rc[0].length; j++){

				System.out.print(rc[i][j]+" ");
			}
			System.out.println(r1[i]+"");
		}
		for(int num : c1){
			System.out.print(num+" ");
		}
		System.out.print(nums+"\n");

	}
}