import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int r = scan.nextInt();
	int c = scan.nextInt();
	int[][] sheet = new int[r+1][c+1];
	for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][j] = scan.nextInt();
	    }
	}
	for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][c] += sheet[i][j];
		sheet[r][j] += sheet[i][j];
	    }
	}
	for (int i = 0; i < c; i++) {
	    sheet[r][c] += sheet[r][i];
	}
	for (int i = 0; i < r + 1; i++) {
	    System.out.print(sheet[i][0]);
	    for (int j = 1; j < c + 1; j++) {
		System.out.print(" " + sheet[i][j]);
	    }
	    System.out.println();
	}
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int r = scan.nextInt();
	int c = scan.nextInt();
	int[][] sheet = new int[r+1][c+1];
	for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][j] = scan.nextInt();
	    }
	}
	for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][c] += sheet[i][j];
		sheet[r][j] += sheet[i][j];
	    }
	}
	for (int i = 0; i < c; i++) {
	    sheet[r][c] += sheet[r][i];
	}
	for (int i = 0; i < r + 1; i++) {
	    System.out.print(sheet[i][0]);
	    for (int j = 1; j < c + 1; j++) {
		System.out.print(" " + sheet[i][j]);
	    }
	    System.out.println();
	}
    }
} Main public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int r = scan.nextInt();
	int c = scan.nextInt();
	int[][] sheet = new int[r+1][c+1];
	for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][j] = scan.nextInt();
	    }
	}
	for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][c] += sheet[i][j];
		sheet[r][j] += sheet[i][j];
	    }
	}
	for (int i = 0; i < c; i++) {
	    sheet[r][c] += sheet[r][i];
	}
	for (int i = 0; i < r + 1; i++) {
	    System.out.print(sheet[i][0]);
	    for (int j = 1; j < c + 1; j++) {
		System.out.print(" " + sheet[i][j]);
	    }
	    System.out.println();
	}
    } main {
	Scanner scan = new Scanner(System.in);
	int r = scan.nextInt();
	int c = scan.nextInt();
	int[][] sheet = new int[r+1][c+1];
	for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][j] = scan.nextInt();
	    }
	}
	for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][c] += sheet[i][j];
		sheet[r][j] += sheet[i][j];
	    }
	}
	for (int i = 0; i < c; i++) {
	    sheet[r][c] += sheet[r][i];
	}
	for (int i = 0; i < r + 1; i++) {
	    System.out.print(sheet[i][0]);
	    for (int j = 1; j < c + 1; j++) {
		System.out.print(" " + sheet[i][j]);
	    }
	    System.out.println();
	}
    } 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[][] sheet = new int[r+1][c+1]; sheet new int[r+1][c+1] r+1 r 1 c+1 c 1 for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][j] = scan.nextInt();
	    }
	} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
	    for (int j = 0; j < c; j++) {
		sheet[i][j] = scan.nextInt();
	    }
	} {
	    for (int j = 0; j < c; j++) {
		sheet[i][j] = scan.nextInt();
	    }
	} for (int j = 0; j < c; j++) {
		sheet[i][j] = scan.nextInt();
	    } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
		sheet[i][j] = scan.nextInt();
	    } {
		sheet[i][j] = scan.nextInt();
	    } sheet[i][j] = scan.nextInt() sheet[i][j] sheet[i] sheet i j scan.nextInt() scan.nextInt scan for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][c] += sheet[i][j];
		sheet[r][j] += sheet[i][j];
	    }
	} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
	    for (int j = 0; j < c; j++) {
		sheet[i][c] += sheet[i][j];
		sheet[r][j] += sheet[i][j];
	    }
	} {
	    for (int j = 0; j < c; j++) {
		sheet[i][c] += sheet[i][j];
		sheet[r][j] += sheet[i][j];
	    }
	} for (int j = 0; j < c; j++) {
		sheet[i][c] += sheet[i][j];
		sheet[r][j] += sheet[i][j];
	    } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
		sheet[i][c] += sheet[i][j];
		sheet[r][j] += sheet[i][j];
	    } {
		sheet[i][c] += sheet[i][j];
		sheet[r][j] += sheet[i][j];
	    } sheet[i][c] += sheet[i][j] sheet[i][c] sheet[i] sheet i c sheet[i][j] sheet[i] sheet i j sheet[r][j] += sheet[i][j] sheet[r][j] sheet[r] sheet r j sheet[i][j] sheet[i] sheet i j for (int i = 0; i < c; i++) {
	    sheet[r][c] += sheet[r][i];
	} int i = 0; int i = 0; i 0 i < c i c i++ i++ i {
	    sheet[r][c] += sheet[r][i];
	} {
	    sheet[r][c] += sheet[r][i];
	} sheet[r][c] += sheet[r][i] sheet[r][c] sheet[r] sheet r c sheet[r][i] sheet[r] sheet r i for (int i = 0; i < r + 1; i++) {
	    System.out.print(sheet[i][0]);
	    for (int j = 1; j < c + 1; j++) {
		System.out.print(" " + sheet[i][j]);
	    }
	    System.out.println();
	} int i = 0; int i = 0; i 0 i < r + 1 i r + 1 r 1 i++ i++ i {
	    System.out.print(sheet[i][0]);
	    for (int j = 1; j < c + 1; j++) {
		System.out.print(" " + sheet[i][j]);
	    }
	    System.out.println();
	} {
	    System.out.print(sheet[i][0]);
	    for (int j = 1; j < c + 1; j++) {
		System.out.print(" " + sheet[i][j]);
	    }
	    System.out.println();
	} System.out.print(sheet[i][0]) System.out.print System.out System System.out sheet[i][0] sheet[i] sheet i 0 for (int j = 1; j < c + 1; j++) {
		System.out.print(" " + sheet[i][j]);
	    } int j = 1; int j = 1; j 1 j < c + 1 j c + 1 c 1 j++ j++ j {
		System.out.print(" " + sheet[i][j]);
	    } {
		System.out.print(" " + sheet[i][j]);
	    } System.out.print(" " + sheet[i][j]) System.out.print System.out System System.out " " + sheet[i][j] " " sheet[i][j] sheet[i] sheet i j System.out.println() System.out.println System.out System System.out String[] args args public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int r = scan.nextInt();
	int c = scan.nextInt();
	int[][] sheet = new int[r+1][c+1];
	for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][j] = scan.nextInt();
	    }
	}
	for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][c] += sheet[i][j];
		sheet[r][j] += sheet[i][j];
	    }
	}
	for (int i = 0; i < c; i++) {
	    sheet[r][c] += sheet[r][i];
	}
	for (int i = 0; i < r + 1; i++) {
	    System.out.print(sheet[i][0]);
	    for (int j = 1; j < c + 1; j++) {
		System.out.print(" " + sheet[i][j]);
	    }
	    System.out.println();
	}
    }
} public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int r = scan.nextInt();
	int c = scan.nextInt();
	int[][] sheet = new int[r+1][c+1];
	for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][j] = scan.nextInt();
	    }
	}
	for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][c] += sheet[i][j];
		sheet[r][j] += sheet[i][j];
	    }
	}
	for (int i = 0; i < c; i++) {
	    sheet[r][c] += sheet[r][i];
	}
	for (int i = 0; i < r + 1; i++) {
	    System.out.print(sheet[i][0]);
	    for (int j = 1; j < c + 1; j++) {
		System.out.print(" " + sheet[i][j]);
	    }
	    System.out.println();
	}
    }
} Main
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int r = scan.nextInt();
	int c = scan.nextInt();
	int[][] sheet = new int[r+1][c+1];
	for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][j] = scan.nextInt();
	    }
	}
	for (int i = 0; i < r; i++) {
	    for (int j = 0; j < c; j++) {
		sheet[i][c] += sheet[i][j];
		sheet[r][j] += sheet[i][j];
	    }
	}
	for (int i = 0; i < c; i++) {
	    sheet[r][c] += sheet[r][i];
	}
	for (int i = 0; i < r + 1; i++) {
	    System.out.print(sheet[i][0]);
	    for (int j = 1; j < c + 1; j++) {
		System.out.print(" " + sheet[i][j]);
	    }
	    System.out.println();
	}
    }
}