import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int rowNum = sc.nextInt();
		int colNum = sc.nextInt();

		int sheet[][] = new int[rowNum][colNum];


		// 入力
		for(int i=0; i<rowNum; i++) {
			for(int j=0; j<colNum; j++) {
				sheet[i][j] = sc.nextInt();
			}
		}

		sc.close();

		// 出力
		// 1列ごとの合計値
		int colSum[] = new int[colNum];
		for(int i=0; i<rowNum; i++) {
			// 1行ごとの合計値
			int rowSum = 0;
			for(int j=0; j<colNum+1; j++) {
				if(j == colNum) {
					System.out.print(rowSum);
				} else {
					rowSum += sheet[i][j];
					colSum[j] += sheet[i][j];
					System.out.print(sheet[i][j] + " ");
				}
			}
			System.out.println("");
		}
		int totalSum = 0;
		for(int i=0; i<colNum; i++) {
			totalSum += colSum[i];
			System.out.print(colSum[i] + " ");
		}
		System.out.println(totalSum);


	}

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

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int rowNum = sc.nextInt();
		int colNum = sc.nextInt();

		int sheet[][] = new int[rowNum][colNum];


		// 入力
		for(int i=0; i<rowNum; i++) {
			for(int j=0; j<colNum; j++) {
				sheet[i][j] = sc.nextInt();
			}
		}

		sc.close();

		// 出力
		// 1列ごとの合計値
		int colSum[] = new int[colNum];
		for(int i=0; i<rowNum; i++) {
			// 1行ごとの合計値
			int rowSum = 0;
			for(int j=0; j<colNum+1; j++) {
				if(j == colNum) {
					System.out.print(rowSum);
				} else {
					rowSum += sheet[i][j];
					colSum[j] += sheet[i][j];
					System.out.print(sheet[i][j] + " ");
				}
			}
			System.out.println("");
		}
		int totalSum = 0;
		for(int i=0; i<colNum; i++) {
			totalSum += colSum[i];
			System.out.print(colSum[i] + " ");
		}
		System.out.println(totalSum);


	}

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

		Scanner sc = new Scanner(System.in);
		int rowNum = sc.nextInt();
		int colNum = sc.nextInt();

		int sheet[][] = new int[rowNum][colNum];


		// 入力
		for(int i=0; i<rowNum; i++) {
			for(int j=0; j<colNum; j++) {
				sheet[i][j] = sc.nextInt();
			}
		}

		sc.close();

		// 出力
		// 1列ごとの合計値
		int colSum[] = new int[colNum];
		for(int i=0; i<rowNum; i++) {
			// 1行ごとの合計値
			int rowSum = 0;
			for(int j=0; j<colNum+1; j++) {
				if(j == colNum) {
					System.out.print(rowSum);
				} else {
					rowSum += sheet[i][j];
					colSum[j] += sheet[i][j];
					System.out.print(sheet[i][j] + " ");
				}
			}
			System.out.println("");
		}
		int totalSum = 0;
		for(int i=0; i<colNum; i++) {
			totalSum += colSum[i];
			System.out.print(colSum[i] + " ");
		}
		System.out.println(totalSum);


	} main {

		Scanner sc = new Scanner(System.in);
		int rowNum = sc.nextInt();
		int colNum = sc.nextInt();

		int sheet[][] = new int[rowNum][colNum];


		// 入力
		for(int i=0; i<rowNum; i++) {
			for(int j=0; j<colNum; j++) {
				sheet[i][j] = sc.nextInt();
			}
		}

		sc.close();

		// 出力
		// 1列ごとの合計値
		int colSum[] = new int[colNum];
		for(int i=0; i<rowNum; i++) {
			// 1行ごとの合計値
			int rowSum = 0;
			for(int j=0; j<colNum+1; j++) {
				if(j == colNum) {
					System.out.print(rowSum);
				} else {
					rowSum += sheet[i][j];
					colSum[j] += sheet[i][j];
					System.out.print(sheet[i][j] + " ");
				}
			}
			System.out.println("");
		}
		int totalSum = 0;
		for(int i=0; i<colNum; i++) {
			totalSum += colSum[i];
			System.out.print(colSum[i] + " ");
		}
		System.out.println(totalSum);


	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int rowNum = sc.nextInt(); rowNum sc.nextInt() sc.nextInt sc int colNum = sc.nextInt(); colNum sc.nextInt() sc.nextInt sc int sheet[][] = new int[rowNum][colNum]; sheet new int[rowNum][colNum] rowNum colNum for(int i=0; i<rowNum; i++) {
			for(int j=0; j<colNum; j++) {
				sheet[i][j] = sc.nextInt();
			}
		} int i=0; int i=0; i 0 i<rowNum i rowNum i++ i++ i {
			for(int j=0; j<colNum; j++) {
				sheet[i][j] = sc.nextInt();
			}
		} {
			for(int j=0; j<colNum; j++) {
				sheet[i][j] = sc.nextInt();
			}
		} for(int j=0; j<colNum; j++) {
				sheet[i][j] = sc.nextInt();
			} int j=0; int j=0; j 0 j<colNum j colNum j++ j++ j {
				sheet[i][j] = sc.nextInt();
			} {
				sheet[i][j] = sc.nextInt();
			} sheet[i][j] = sc.nextInt() sheet[i][j] sheet[i] sheet i j sc.nextInt() sc.nextInt sc sc.close() sc.close sc int colSum[] = new int[colNum]; colSum new int[colNum] colNum for(int i=0; i<rowNum; i++) {
			// 1行ごとの合計値
			int rowSum = 0;
			for(int j=0; j<colNum+1; j++) {
				if(j == colNum) {
					System.out.print(rowSum);
				} else {
					rowSum += sheet[i][j];
					colSum[j] += sheet[i][j];
					System.out.print(sheet[i][j] + " ");
				}
			}
			System.out.println("");
		} int i=0; int i=0; i 0 i<rowNum i rowNum i++ i++ i {
			// 1行ごとの合計値
			int rowSum = 0;
			for(int j=0; j<colNum+1; j++) {
				if(j == colNum) {
					System.out.print(rowSum);
				} else {
					rowSum += sheet[i][j];
					colSum[j] += sheet[i][j];
					System.out.print(sheet[i][j] + " ");
				}
			}
			System.out.println("");
		} {
			// 1行ごとの合計値
			int rowSum = 0;
			for(int j=0; j<colNum+1; j++) {
				if(j == colNum) {
					System.out.print(rowSum);
				} else {
					rowSum += sheet[i][j];
					colSum[j] += sheet[i][j];
					System.out.print(sheet[i][j] + " ");
				}
			}
			System.out.println("");
		} int rowSum = 0; rowSum 0 for(int j=0; j<colNum+1; j++) {
				if(j == colNum) {
					System.out.print(rowSum);
				} else {
					rowSum += sheet[i][j];
					colSum[j] += sheet[i][j];
					System.out.print(sheet[i][j] + " ");
				}
			} int j=0; int j=0; j 0 j<colNum+1 j colNum+1 colNum 1 j++ j++ j {
				if(j == colNum) {
					System.out.print(rowSum);
				} else {
					rowSum += sheet[i][j];
					colSum[j] += sheet[i][j];
					System.out.print(sheet[i][j] + " ");
				}
			} {
				if(j == colNum) {
					System.out.print(rowSum);
				} else {
					rowSum += sheet[i][j];
					colSum[j] += sheet[i][j];
					System.out.print(sheet[i][j] + " ");
				}
			} if(j == colNum) {
					System.out.print(rowSum);
				} else {
					rowSum += sheet[i][j];
					colSum[j] += sheet[i][j];
					System.out.print(sheet[i][j] + " ");
				} j == colNum j colNum {
					System.out.print(rowSum);
				} System.out.print(rowSum) System.out.print System.out System System.out rowSum {
					rowSum += sheet[i][j];
					colSum[j] += sheet[i][j];
					System.out.print(sheet[i][j] + " ");
				} rowSum += sheet[i][j] rowSum sheet[i][j] sheet[i] sheet i j colSum[j] += sheet[i][j] colSum[j] colSum j sheet[i][j] sheet[i] 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 "" int totalSum = 0; totalSum 0 for(int i=0; i<colNum; i++) {
			totalSum += colSum[i];
			System.out.print(colSum[i] + " ");
		} int i=0; int i=0; i 0 i<colNum i colNum i++ i++ i {
			totalSum += colSum[i];
			System.out.print(colSum[i] + " ");
		} {
			totalSum += colSum[i];
			System.out.print(colSum[i] + " ");
		} totalSum += colSum[i] totalSum colSum[i] colSum i System.out.print(colSum[i] + " ") System.out.print System.out System System.out colSum[i] + " " colSum[i] colSum i " " System.out.println(totalSum) System.out.println System.out System System.out totalSum String[] args args public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int rowNum = sc.nextInt();
		int colNum = sc.nextInt();

		int sheet[][] = new int[rowNum][colNum];


		// 入力
		for(int i=0; i<rowNum; i++) {
			for(int j=0; j<colNum; j++) {
				sheet[i][j] = sc.nextInt();
			}
		}

		sc.close();

		// 出力
		// 1列ごとの合計値
		int colSum[] = new int[colNum];
		for(int i=0; i<rowNum; i++) {
			// 1行ごとの合計値
			int rowSum = 0;
			for(int j=0; j<colNum+1; j++) {
				if(j == colNum) {
					System.out.print(rowSum);
				} else {
					rowSum += sheet[i][j];
					colSum[j] += sheet[i][j];
					System.out.print(sheet[i][j] + " ");
				}
			}
			System.out.println("");
		}
		int totalSum = 0;
		for(int i=0; i<colNum; i++) {
			totalSum += colSum[i];
			System.out.print(colSum[i] + " ");
		}
		System.out.println(totalSum);


	}

} public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int rowNum = sc.nextInt();
		int colNum = sc.nextInt();

		int sheet[][] = new int[rowNum][colNum];


		// 入力
		for(int i=0; i<rowNum; i++) {
			for(int j=0; j<colNum; j++) {
				sheet[i][j] = sc.nextInt();
			}
		}

		sc.close();

		// 出力
		// 1列ごとの合計値
		int colSum[] = new int[colNum];
		for(int i=0; i<rowNum; i++) {
			// 1行ごとの合計値
			int rowSum = 0;
			for(int j=0; j<colNum+1; j++) {
				if(j == colNum) {
					System.out.print(rowSum);
				} else {
					rowSum += sheet[i][j];
					colSum[j] += sheet[i][j];
					System.out.print(sheet[i][j] + " ");
				}
			}
			System.out.println("");
		}
		int totalSum = 0;
		for(int i=0; i<colNum; i++) {
			totalSum += colSum[i];
			System.out.print(colSum[i] + " ");
		}
		System.out.println(totalSum);


	}

} Main
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int rowNum = sc.nextInt();
		int colNum = sc.nextInt();

		int sheet[][] = new int[rowNum][colNum];


		// 入力
		for(int i=0; i<rowNum; i++) {
			for(int j=0; j<colNum; j++) {
				sheet[i][j] = sc.nextInt();
			}
		}

		sc.close();

		// 出力
		// 1列ごとの合計値
		int colSum[] = new int[colNum];
		for(int i=0; i<rowNum; i++) {
			// 1行ごとの合計値
			int rowSum = 0;
			for(int j=0; j<colNum+1; j++) {
				if(j == colNum) {
					System.out.print(rowSum);
				} else {
					rowSum += sheet[i][j];
					colSum[j] += sheet[i][j];
					System.out.print(sheet[i][j] + " ");
				}
			}
			System.out.println("");
		}
		int totalSum = 0;
		for(int i=0; i<colNum; i++) {
			totalSum += colSum[i];
			System.out.print(colSum[i] + " ");
		}
		System.out.println(totalSum);


	}

}
