/**
表計算を行う簡単なプログラムを作成します。

表の行数rと列数c、r × c の要素を持つ表を読み込んで、
各行と列の合計を挿入した新しい表を出力するプログラムを作成して下さい。

 */

/*sucannerクラス使うためにインポート*/
import java.util.Scanner;

class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成
		Scanner sc = new Scanner(System.in);
		int intR = sc.nextInt();
		int intC = sc.nextInt();

		int Hyou[][] = new int[intR][intC];
		int intYokogoukei = 0;
		int intTategoukei = 0;
		int i = 0;
		int j = 0;
		int intSaigo = 0;
		for (i = 0; i < intR; i++) {

			for (j = 0; j < intC; j++) {
				Hyou[i][j] = sc.nextInt();
				intYokogoukei += Hyou[i][j];
				intSaigo += Hyou[i][j];
				System.out.print(Hyou[i][j] + " ");

			}
			System.out.println(intYokogoukei);
			intYokogoukei = 0;
		}
		for (int k = 0; k < intC; k++) {
			for (int l = 0; l < intR; l++) {
				intTategoukei += Hyou[l][k];

			}
			System.out.print(intTategoukei + " ");
			intTategoukei = 0;
		}
		System.out.println(intSaigo);

	}
} import java.util.Scanner; Scanner java.util class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成
		Scanner sc = new Scanner(System.in);
		int intR = sc.nextInt();
		int intC = sc.nextInt();

		int Hyou[][] = new int[intR][intC];
		int intYokogoukei = 0;
		int intTategoukei = 0;
		int i = 0;
		int j = 0;
		int intSaigo = 0;
		for (i = 0; i < intR; i++) {

			for (j = 0; j < intC; j++) {
				Hyou[i][j] = sc.nextInt();
				intYokogoukei += Hyou[i][j];
				intSaigo += Hyou[i][j];
				System.out.print(Hyou[i][j] + " ");

			}
			System.out.println(intYokogoukei);
			intYokogoukei = 0;
		}
		for (int k = 0; k < intC; k++) {
			for (int l = 0; l < intR; l++) {
				intTategoukei += Hyou[l][k];

			}
			System.out.print(intTategoukei + " ");
			intTategoukei = 0;
		}
		System.out.println(intSaigo);

	}
} Main // プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成
		Scanner sc = new Scanner(System.in);
		int intR = sc.nextInt();
		int intC = sc.nextInt();

		int Hyou[][] = new int[intR][intC];
		int intYokogoukei = 0;
		int intTategoukei = 0;
		int i = 0;
		int j = 0;
		int intSaigo = 0;
		for (i = 0; i < intR; i++) {

			for (j = 0; j < intC; j++) {
				Hyou[i][j] = sc.nextInt();
				intYokogoukei += Hyou[i][j];
				intSaigo += Hyou[i][j];
				System.out.print(Hyou[i][j] + " ");

			}
			System.out.println(intYokogoukei);
			intYokogoukei = 0;
		}
		for (int k = 0; k < intC; k++) {
			for (int l = 0; l < intR; l++) {
				intTategoukei += Hyou[l][k];

			}
			System.out.print(intTategoukei + " ");
			intTategoukei = 0;
		}
		System.out.println(intSaigo);

	} main {
		// 入力ストリームの生成
		Scanner sc = new Scanner(System.in);
		int intR = sc.nextInt();
		int intC = sc.nextInt();

		int Hyou[][] = new int[intR][intC];
		int intYokogoukei = 0;
		int intTategoukei = 0;
		int i = 0;
		int j = 0;
		int intSaigo = 0;
		for (i = 0; i < intR; i++) {

			for (j = 0; j < intC; j++) {
				Hyou[i][j] = sc.nextInt();
				intYokogoukei += Hyou[i][j];
				intSaigo += Hyou[i][j];
				System.out.print(Hyou[i][j] + " ");

			}
			System.out.println(intYokogoukei);
			intYokogoukei = 0;
		}
		for (int k = 0; k < intC; k++) {
			for (int l = 0; l < intR; l++) {
				intTategoukei += Hyou[l][k];

			}
			System.out.print(intTategoukei + " ");
			intTategoukei = 0;
		}
		System.out.println(intSaigo);

	} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int intR = sc.nextInt(); intR sc.nextInt() sc.nextInt sc int intC = sc.nextInt(); intC sc.nextInt() sc.nextInt sc int Hyou[][] = new int[intR][intC]; Hyou new int[intR][intC] intR intC int intYokogoukei = 0; intYokogoukei 0 int intTategoukei = 0; intTategoukei 0 int i = 0; i 0 int j = 0; j 0 int intSaigo = 0; intSaigo 0 for (i = 0; i < intR; i++) {

			for (j = 0; j < intC; j++) {
				Hyou[i][j] = sc.nextInt();
				intYokogoukei += Hyou[i][j];
				intSaigo += Hyou[i][j];
				System.out.print(Hyou[i][j] + " ");

			}
			System.out.println(intYokogoukei);
			intYokogoukei = 0;
		} i = 0; i = 0 i 0 i < intR i intR i++ i++ i {

			for (j = 0; j < intC; j++) {
				Hyou[i][j] = sc.nextInt();
				intYokogoukei += Hyou[i][j];
				intSaigo += Hyou[i][j];
				System.out.print(Hyou[i][j] + " ");

			}
			System.out.println(intYokogoukei);
			intYokogoukei = 0;
		} {

			for (j = 0; j < intC; j++) {
				Hyou[i][j] = sc.nextInt();
				intYokogoukei += Hyou[i][j];
				intSaigo += Hyou[i][j];
				System.out.print(Hyou[i][j] + " ");

			}
			System.out.println(intYokogoukei);
			intYokogoukei = 0;
		} for (j = 0; j < intC; j++) {
				Hyou[i][j] = sc.nextInt();
				intYokogoukei += Hyou[i][j];
				intSaigo += Hyou[i][j];
				System.out.print(Hyou[i][j] + " ");

			} j = 0; j = 0 j 0 j < intC j intC j++ j++ j {
				Hyou[i][j] = sc.nextInt();
				intYokogoukei += Hyou[i][j];
				intSaigo += Hyou[i][j];
				System.out.print(Hyou[i][j] + " ");

			} {
				Hyou[i][j] = sc.nextInt();
				intYokogoukei += Hyou[i][j];
				intSaigo += Hyou[i][j];
				System.out.print(Hyou[i][j] + " ");

			} Hyou[i][j] = sc.nextInt() Hyou[i][j] Hyou[i] Hyou i j sc.nextInt() sc.nextInt sc intYokogoukei += Hyou[i][j] intYokogoukei Hyou[i][j] Hyou[i] Hyou i j intSaigo += Hyou[i][j] intSaigo Hyou[i][j] Hyou[i] Hyou i j System.out.print(Hyou[i][j] + " ") System.out.print System.out System System.out Hyou[i][j] + " " Hyou[i][j] Hyou[i] Hyou i j " " System.out.println(intYokogoukei) System.out.println System.out System System.out intYokogoukei intYokogoukei = 0 intYokogoukei 0 for (int k = 0; k < intC; k++) {
			for (int l = 0; l < intR; l++) {
				intTategoukei += Hyou[l][k];

			}
			System.out.print(intTategoukei + " ");
			intTategoukei = 0;
		} int k = 0; int k = 0; k 0 k < intC k intC k++ k++ k {
			for (int l = 0; l < intR; l++) {
				intTategoukei += Hyou[l][k];

			}
			System.out.print(intTategoukei + " ");
			intTategoukei = 0;
		} {
			for (int l = 0; l < intR; l++) {
				intTategoukei += Hyou[l][k];

			}
			System.out.print(intTategoukei + " ");
			intTategoukei = 0;
		} for (int l = 0; l < intR; l++) {
				intTategoukei += Hyou[l][k];

			} int l = 0; int l = 0; l 0 l < intR l intR l++ l++ l {
				intTategoukei += Hyou[l][k];

			} {
				intTategoukei += Hyou[l][k];

			} intTategoukei += Hyou[l][k] intTategoukei Hyou[l][k] Hyou[l] Hyou l k System.out.print(intTategoukei + " ") System.out.print System.out System System.out intTategoukei + " " intTategoukei " " intTategoukei = 0 intTategoukei 0 System.out.println(intSaigo) System.out.println System.out System System.out intSaigo String[] args args
/**
表計算を行う簡単なプログラムを作成します。

表の行数rと列数c、r × c の要素を持つ表を読み込んで、
各行と列の合計を挿入した新しい表を出力するプログラムを作成して下さい。

 */

/*sucannerクラス使うためにインポート*/
import java.util.Scanner;

class Main {
	// プログラムのエントリポイント
	public static void main(String[] args) {
		// 入力ストリームの生成
		Scanner sc = new Scanner(System.in);
		int intR = sc.nextInt();
		int intC = sc.nextInt();

		int Hyou[][] = new int[intR][intC];
		int intYokogoukei = 0;
		int intTategoukei = 0;
		int i = 0;
		int j = 0;
		int intSaigo = 0;
		for (i = 0; i < intR; i++) {

			for (j = 0; j < intC; j++) {
				Hyou[i][j] = sc.nextInt();
				intYokogoukei += Hyou[i][j];
				intSaigo += Hyou[i][j];
				System.out.print(Hyou[i][j] + " ");

			}
			System.out.println(intYokogoukei);
			intYokogoukei = 0;
		}
		for (int k = 0; k < intC; k++) {
			for (int l = 0; l < intR; l++) {
				intTategoukei += Hyou[l][k];

			}
			System.out.print(intTategoukei + " ");
			intTategoukei = 0;
		}
		System.out.println(intSaigo);

	}
}