import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int suma = 0;
		int[][] sheet = new int[r][c];

		for(int i=0; i<r; i++){
			for(int s=0; s<c; s++){
				sheet[i][s] = scan.nextInt();
			}
		}
		for(int i=0; i<r; i++){
			int sumw = 0;
			for(int s=0; s<c; s++){
				sumw += sheet[i][s];
				System.out.print(sheet[i][s] + " ");
				if(s == c-1){
					System.out.print(sumw + "\n");
					sumw = 0;
				}
			}
		}
		for(int i=0; i<c; i++){
			int sumh= 0;
			for(int s=0; s<r; s++){
				suma += sheet[s][i];
				sumh += sheet[s][i];
			}
			System.out.print(sumh + " ");
			if(i == c-1)
				System.out.print(suma + "\n");
		}

	}

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

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int suma = 0;
		int[][] sheet = new int[r][c];

		for(int i=0; i<r; i++){
			for(int s=0; s<c; s++){
				sheet[i][s] = scan.nextInt();
			}
		}
		for(int i=0; i<r; i++){
			int sumw = 0;
			for(int s=0; s<c; s++){
				sumw += sheet[i][s];
				System.out.print(sheet[i][s] + " ");
				if(s == c-1){
					System.out.print(sumw + "\n");
					sumw = 0;
				}
			}
		}
		for(int i=0; i<c; i++){
			int sumh= 0;
			for(int s=0; s<r; s++){
				suma += sheet[s][i];
				sumh += sheet[s][i];
			}
			System.out.print(sumh + " ");
			if(i == c-1)
				System.out.print(suma + "\n");
		}

	}

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

		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int suma = 0;
		int[][] sheet = new int[r][c];

		for(int i=0; i<r; i++){
			for(int s=0; s<c; s++){
				sheet[i][s] = scan.nextInt();
			}
		}
		for(int i=0; i<r; i++){
			int sumw = 0;
			for(int s=0; s<c; s++){
				sumw += sheet[i][s];
				System.out.print(sheet[i][s] + " ");
				if(s == c-1){
					System.out.print(sumw + "\n");
					sumw = 0;
				}
			}
		}
		for(int i=0; i<c; i++){
			int sumh= 0;
			for(int s=0; s<r; s++){
				suma += sheet[s][i];
				sumh += sheet[s][i];
			}
			System.out.print(sumh + " ");
			if(i == c-1)
				System.out.print(suma + "\n");
		}

	} main {

		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int suma = 0;
		int[][] sheet = new int[r][c];

		for(int i=0; i<r; i++){
			for(int s=0; s<c; s++){
				sheet[i][s] = scan.nextInt();
			}
		}
		for(int i=0; i<r; i++){
			int sumw = 0;
			for(int s=0; s<c; s++){
				sumw += sheet[i][s];
				System.out.print(sheet[i][s] + " ");
				if(s == c-1){
					System.out.print(sumw + "\n");
					sumw = 0;
				}
			}
		}
		for(int i=0; i<c; i++){
			int sumh= 0;
			for(int s=0; s<r; s++){
				suma += sheet[s][i];
				sumh += sheet[s][i];
			}
			System.out.print(sumh + " ");
			if(i == c-1)
				System.out.print(suma + "\n");
		}

	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int r = scan.nextInt(); r scan.nextInt() scan.nextInt scan int c = scan.nextInt(); c scan.nextInt() scan.nextInt scan int suma = 0; suma 0 int[][] sheet = new int[r][c]; sheet new int[r][c] r c for(int i=0; i<r; i++){
			for(int s=0; s<c; s++){
				sheet[i][s] = scan.nextInt();
			}
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			for(int s=0; s<c; s++){
				sheet[i][s] = scan.nextInt();
			}
		} {
			for(int s=0; s<c; s++){
				sheet[i][s] = scan.nextInt();
			}
		} for(int s=0; s<c; s++){
				sheet[i][s] = scan.nextInt();
			} int s=0; int s=0; s 0 s<c s c s++ s++ s {
				sheet[i][s] = scan.nextInt();
			} {
				sheet[i][s] = scan.nextInt();
			} sheet[i][s] = scan.nextInt() sheet[i][s] sheet[i] sheet i s scan.nextInt() scan.nextInt scan for(int i=0; i<r; i++){
			int sumw = 0;
			for(int s=0; s<c; s++){
				sumw += sheet[i][s];
				System.out.print(sheet[i][s] + " ");
				if(s == c-1){
					System.out.print(sumw + "\n");
					sumw = 0;
				}
			}
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			int sumw = 0;
			for(int s=0; s<c; s++){
				sumw += sheet[i][s];
				System.out.print(sheet[i][s] + " ");
				if(s == c-1){
					System.out.print(sumw + "\n");
					sumw = 0;
				}
			}
		} {
			int sumw = 0;
			for(int s=0; s<c; s++){
				sumw += sheet[i][s];
				System.out.print(sheet[i][s] + " ");
				if(s == c-1){
					System.out.print(sumw + "\n");
					sumw = 0;
				}
			}
		} int sumw = 0; sumw 0 for(int s=0; s<c; s++){
				sumw += sheet[i][s];
				System.out.print(sheet[i][s] + " ");
				if(s == c-1){
					System.out.print(sumw + "\n");
					sumw = 0;
				}
			} int s=0; int s=0; s 0 s<c s c s++ s++ s {
				sumw += sheet[i][s];
				System.out.print(sheet[i][s] + " ");
				if(s == c-1){
					System.out.print(sumw + "\n");
					sumw = 0;
				}
			} {
				sumw += sheet[i][s];
				System.out.print(sheet[i][s] + " ");
				if(s == c-1){
					System.out.print(sumw + "\n");
					sumw = 0;
				}
			} sumw += sheet[i][s] sumw sheet[i][s] sheet[i] sheet i s System.out.print(sheet[i][s] + " ") System.out.print System.out System System.out sheet[i][s] + " " sheet[i][s] sheet[i] sheet i s " " if(s == c-1){
					System.out.print(sumw + "\n");
					sumw = 0;
				} s == c-1 s c-1 c 1 {
					System.out.print(sumw + "\n");
					sumw = 0;
				} System.out.print(sumw + "\n") System.out.print System.out System System.out sumw + "\n" sumw "\n" sumw = 0 sumw 0 for(int i=0; i<c; i++){
			int sumh= 0;
			for(int s=0; s<r; s++){
				suma += sheet[s][i];
				sumh += sheet[s][i];
			}
			System.out.print(sumh + " ");
			if(i == c-1)
				System.out.print(suma + "\n");
		} int i=0; int i=0; i 0 i<c i c i++ i++ i {
			int sumh= 0;
			for(int s=0; s<r; s++){
				suma += sheet[s][i];
				sumh += sheet[s][i];
			}
			System.out.print(sumh + " ");
			if(i == c-1)
				System.out.print(suma + "\n");
		} {
			int sumh= 0;
			for(int s=0; s<r; s++){
				suma += sheet[s][i];
				sumh += sheet[s][i];
			}
			System.out.print(sumh + " ");
			if(i == c-1)
				System.out.print(suma + "\n");
		} int sumh= 0; sumh 0 for(int s=0; s<r; s++){
				suma += sheet[s][i];
				sumh += sheet[s][i];
			} int s=0; int s=0; s 0 s<r s r s++ s++ s {
				suma += sheet[s][i];
				sumh += sheet[s][i];
			} {
				suma += sheet[s][i];
				sumh += sheet[s][i];
			} suma += sheet[s][i] suma sheet[s][i] sheet[s] sheet s i sumh += sheet[s][i] sumh sheet[s][i] sheet[s] sheet s i System.out.print(sumh + " ") System.out.print System.out System System.out sumh + " " sumh " " if(i == c-1)
				System.out.print(suma + "\n"); i == c-1 i c-1 c 1 System.out.print(suma + "\n") System.out.print System.out System System.out suma + "\n" suma "\n" String[] args args
import java.util.Scanner;

class Main {

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int suma = 0;
		int[][] sheet = new int[r][c];

		for(int i=0; i<r; i++){
			for(int s=0; s<c; s++){
				sheet[i][s] = scan.nextInt();
			}
		}
		for(int i=0; i<r; i++){
			int sumw = 0;
			for(int s=0; s<c; s++){
				sumw += sheet[i][s];
				System.out.print(sheet[i][s] + " ");
				if(s == c-1){
					System.out.print(sumw + "\n");
					sumw = 0;
				}
			}
		}
		for(int i=0; i<c; i++){
			int sumh= 0;
			for(int s=0; s<r; s++){
				suma += sheet[s][i];
				sumh += sheet[s][i];
			}
			System.out.print(sumh + " ");
			if(i == c-1)
				System.out.print(suma + "\n");
		}

	}

}