import java.io.*;

public class Main{
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] tableSize = br.readLine().split(" ");
			int n = Integer.parseInt(tableSize[0]);
			int m = Integer.parseInt(tableSize[1]);
			int[][] table = new int[n][m];

			for (int i = 0; i < n; i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0; j < m; j++){
					table[i][j] = Integer.parseInt(str[j]);
				}
			}

			int[][] newTable = new int[n+1][m+1];
			int[] sumX = new int[m];
			int[] sumY = new int[n];
			int sumAll = 0;

			for (int x = 0; x < n+1; x++){
				if (x < n){
					for (int y = 0; y < m+1; y++){
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					}
				}else{
					for (int z = 0; z < m+1; z++){
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					}
				}
			}

			for (int s = 0; s < n+1; s++){
				for (int t = 0; t < m+1; t++){
					if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					}
				}
				System.out.println();
			}
		}catch(IOException e){
		System.out.println(e);
		}
	}
} import java.io.*; io.* java public class Main{
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] tableSize = br.readLine().split(" ");
			int n = Integer.parseInt(tableSize[0]);
			int m = Integer.parseInt(tableSize[1]);
			int[][] table = new int[n][m];

			for (int i = 0; i < n; i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0; j < m; j++){
					table[i][j] = Integer.parseInt(str[j]);
				}
			}

			int[][] newTable = new int[n+1][m+1];
			int[] sumX = new int[m];
			int[] sumY = new int[n];
			int sumAll = 0;

			for (int x = 0; x < n+1; x++){
				if (x < n){
					for (int y = 0; y < m+1; y++){
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					}
				}else{
					for (int z = 0; z < m+1; z++){
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					}
				}
			}

			for (int s = 0; s < n+1; s++){
				for (int t = 0; t < m+1; t++){
					if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					}
				}
				System.out.println();
			}
		}catch(IOException e){
		System.out.println(e);
		}
	}
} Main public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] tableSize = br.readLine().split(" ");
			int n = Integer.parseInt(tableSize[0]);
			int m = Integer.parseInt(tableSize[1]);
			int[][] table = new int[n][m];

			for (int i = 0; i < n; i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0; j < m; j++){
					table[i][j] = Integer.parseInt(str[j]);
				}
			}

			int[][] newTable = new int[n+1][m+1];
			int[] sumX = new int[m];
			int[] sumY = new int[n];
			int sumAll = 0;

			for (int x = 0; x < n+1; x++){
				if (x < n){
					for (int y = 0; y < m+1; y++){
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					}
				}else{
					for (int z = 0; z < m+1; z++){
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					}
				}
			}

			for (int s = 0; s < n+1; s++){
				for (int t = 0; t < m+1; t++){
					if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					}
				}
				System.out.println();
			}
		}catch(IOException e){
		System.out.println(e);
		}
	} main {
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] tableSize = br.readLine().split(" ");
			int n = Integer.parseInt(tableSize[0]);
			int m = Integer.parseInt(tableSize[1]);
			int[][] table = new int[n][m];

			for (int i = 0; i < n; i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0; j < m; j++){
					table[i][j] = Integer.parseInt(str[j]);
				}
			}

			int[][] newTable = new int[n+1][m+1];
			int[] sumX = new int[m];
			int[] sumY = new int[n];
			int sumAll = 0;

			for (int x = 0; x < n+1; x++){
				if (x < n){
					for (int y = 0; y < m+1; y++){
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					}
				}else{
					for (int z = 0; z < m+1; z++){
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					}
				}
			}

			for (int s = 0; s < n+1; s++){
				for (int t = 0; t < m+1; t++){
					if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					}
				}
				System.out.println();
			}
		}catch(IOException e){
		System.out.println(e);
		}
	} try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] tableSize = br.readLine().split(" ");
			int n = Integer.parseInt(tableSize[0]);
			int m = Integer.parseInt(tableSize[1]);
			int[][] table = new int[n][m];

			for (int i = 0; i < n; i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0; j < m; j++){
					table[i][j] = Integer.parseInt(str[j]);
				}
			}

			int[][] newTable = new int[n+1][m+1];
			int[] sumX = new int[m];
			int[] sumY = new int[n];
			int sumAll = 0;

			for (int x = 0; x < n+1; x++){
				if (x < n){
					for (int y = 0; y < m+1; y++){
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					}
				}else{
					for (int z = 0; z < m+1; z++){
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					}
				}
			}

			for (int s = 0; s < n+1; s++){
				for (int t = 0; t < m+1; t++){
					if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					}
				}
				System.out.println();
			}
		}catch(IOException e){
		System.out.println(e);
		} catch(IOException e){
		System.out.println(e);
		} IOException e {
		System.out.println(e);
		} System.out.println(e) System.out.println System.out System System.out e {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] tableSize = br.readLine().split(" ");
			int n = Integer.parseInt(tableSize[0]);
			int m = Integer.parseInt(tableSize[1]);
			int[][] table = new int[n][m];

			for (int i = 0; i < n; i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0; j < m; j++){
					table[i][j] = Integer.parseInt(str[j]);
				}
			}

			int[][] newTable = new int[n+1][m+1];
			int[] sumX = new int[m];
			int[] sumY = new int[n];
			int sumAll = 0;

			for (int x = 0; x < n+1; x++){
				if (x < n){
					for (int y = 0; y < m+1; y++){
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					}
				}else{
					for (int z = 0; z < m+1; z++){
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					}
				}
			}

			for (int s = 0; s < n+1; s++){
				for (int t = 0; t < m+1; t++){
					if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					}
				}
				System.out.println();
			}
		} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] tableSize = br.readLine().split(" "); tableSize br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int n = Integer.parseInt(tableSize[0]); n Integer.parseInt(tableSize[0]) Integer.parseInt Integer tableSize[0] tableSize 0 int m = Integer.parseInt(tableSize[1]); m Integer.parseInt(tableSize[1]) Integer.parseInt Integer tableSize[1] tableSize 1 int[][] table = new int[n][m]; table new int[n][m] n m for (int i = 0; i < n; i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0; j < m; j++){
					table[i][j] = Integer.parseInt(str[j]);
				}
			} int i = 0; int i = 0; i 0 i < n i n i++ i++ i {
				String[] str = br.readLine().split(" ");
				for(int j = 0; j < m; j++){
					table[i][j] = Integer.parseInt(str[j]);
				}
			} {
				String[] str = br.readLine().split(" ");
				for(int j = 0; j < m; j++){
					table[i][j] = Integer.parseInt(str[j]);
				}
			} String[] str = br.readLine().split(" "); str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int j = 0; j < m; j++){
					table[i][j] = Integer.parseInt(str[j]);
				} int j = 0; int j = 0; j 0 j < m j m j++ j++ j {
					table[i][j] = Integer.parseInt(str[j]);
				} {
					table[i][j] = Integer.parseInt(str[j]);
				} table[i][j] = Integer.parseInt(str[j]) table[i][j] table[i] table i j Integer.parseInt(str[j]) Integer.parseInt Integer str[j] str j int[][] newTable = new int[n+1][m+1]; newTable new int[n+1][m+1] n+1 n 1 m+1 m 1 int[] sumX = new int[m]; sumX new int[m] m int[] sumY = new int[n]; sumY new int[n] n int sumAll = 0; sumAll 0 for (int x = 0; x < n+1; x++){
				if (x < n){
					for (int y = 0; y < m+1; y++){
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					}
				}else{
					for (int z = 0; z < m+1; z++){
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					}
				}
			} int x = 0; int x = 0; x 0 x < n+1 x n+1 n 1 x++ x++ x {
				if (x < n){
					for (int y = 0; y < m+1; y++){
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					}
				}else{
					for (int z = 0; z < m+1; z++){
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					}
				}
			} {
				if (x < n){
					for (int y = 0; y < m+1; y++){
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					}
				}else{
					for (int z = 0; z < m+1; z++){
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					}
				}
			} if (x < n){
					for (int y = 0; y < m+1; y++){
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					}
				}else{
					for (int z = 0; z < m+1; z++){
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					}
				} x < n x n {
					for (int y = 0; y < m+1; y++){
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					}
				} for (int y = 0; y < m+1; y++){
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					} int y = 0; int y = 0; y 0 y < m+1 y m+1 m 1 y++ y++ y {
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					} {
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					} if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						} y < m y m {
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						} newTable[x][y] = table[x][y] newTable[x][y] newTable[x] newTable x y table[x][y] table[x] table x y sumAll += newTable[x][y] sumAll newTable[x][y] newTable[x] newTable x y {
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						} for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							} int a = 0; int a = 0; a 0 a < m a m a++ a++ a {
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							} {
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							} sumY[x] += table[x][a] sumY[x] sumY x table[x][a] table[x] table x a newTable[x][y] = sumY[x] newTable[x][y] newTable[x] newTable x y sumY[x] sumY x {
					for (int z = 0; z < m+1; z++){
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					}
				} for (int z = 0; z < m+1; z++){
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					} int z = 0; int z = 0; z 0 z < m+1 z m+1 m 1 z++ z++ z {
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					} {
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					} if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						} z < m z m {
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						} for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							} int b = 0; int b = 0; b 0 b < n b n b++ b++ b {
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							} {
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							} sumX[z] += table[b][z] sumX[z] sumX z table[b][z] table[b] table b z newTable[x][z] = sumX[z] newTable[x][z] newTable[x] newTable x z sumX[z] sumX z {
							newTable[x][z] = sumAll;
						} newTable[x][z] = sumAll newTable[x][z] newTable[x] newTable x z sumAll for (int s = 0; s < n+1; s++){
				for (int t = 0; t < m+1; t++){
					if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					}
				}
				System.out.println();
			} int s = 0; int s = 0; s 0 s < n+1 s n+1 n 1 s++ s++ s {
				for (int t = 0; t < m+1; t++){
					if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					}
				}
				System.out.println();
			} {
				for (int t = 0; t < m+1; t++){
					if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					}
				}
				System.out.println();
			} for (int t = 0; t < m+1; t++){
					if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					}
				} int t = 0; int t = 0; t 0 t < m+1 t m+1 m 1 t++ t++ t {
					if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					}
				} {
					if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					}
				} if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					} t < m t m {
						System.out.print(newTable[s][t] + " ");
					} System.out.print(newTable[s][t] + " ") System.out.print System.out System System.out newTable[s][t] + " " newTable[s][t] newTable[s] newTable s t " " {
						System.out.print(newTable[s][t]);
					} System.out.print(newTable[s][t]) System.out.print System.out System System.out newTable[s][t] newTable[s] newTable s t System.out.println() System.out.println System.out System System.out String[] args args public class Main{
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] tableSize = br.readLine().split(" ");
			int n = Integer.parseInt(tableSize[0]);
			int m = Integer.parseInt(tableSize[1]);
			int[][] table = new int[n][m];

			for (int i = 0; i < n; i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0; j < m; j++){
					table[i][j] = Integer.parseInt(str[j]);
				}
			}

			int[][] newTable = new int[n+1][m+1];
			int[] sumX = new int[m];
			int[] sumY = new int[n];
			int sumAll = 0;

			for (int x = 0; x < n+1; x++){
				if (x < n){
					for (int y = 0; y < m+1; y++){
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					}
				}else{
					for (int z = 0; z < m+1; z++){
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					}
				}
			}

			for (int s = 0; s < n+1; s++){
				for (int t = 0; t < m+1; t++){
					if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					}
				}
				System.out.println();
			}
		}catch(IOException e){
		System.out.println(e);
		}
	}
} public class Main{
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] tableSize = br.readLine().split(" ");
			int n = Integer.parseInt(tableSize[0]);
			int m = Integer.parseInt(tableSize[1]);
			int[][] table = new int[n][m];

			for (int i = 0; i < n; i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0; j < m; j++){
					table[i][j] = Integer.parseInt(str[j]);
				}
			}

			int[][] newTable = new int[n+1][m+1];
			int[] sumX = new int[m];
			int[] sumY = new int[n];
			int sumAll = 0;

			for (int x = 0; x < n+1; x++){
				if (x < n){
					for (int y = 0; y < m+1; y++){
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					}
				}else{
					for (int z = 0; z < m+1; z++){
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					}
				}
			}

			for (int s = 0; s < n+1; s++){
				for (int t = 0; t < m+1; t++){
					if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					}
				}
				System.out.println();
			}
		}catch(IOException e){
		System.out.println(e);
		}
	}
} Main
import java.io.*;

public class Main{
	public static void main(String[] args){
		try{
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			String[] tableSize = br.readLine().split(" ");
			int n = Integer.parseInt(tableSize[0]);
			int m = Integer.parseInt(tableSize[1]);
			int[][] table = new int[n][m];

			for (int i = 0; i < n; i++){
				String[] str = br.readLine().split(" ");
				for(int j = 0; j < m; j++){
					table[i][j] = Integer.parseInt(str[j]);
				}
			}

			int[][] newTable = new int[n+1][m+1];
			int[] sumX = new int[m];
			int[] sumY = new int[n];
			int sumAll = 0;

			for (int x = 0; x < n+1; x++){
				if (x < n){
					for (int y = 0; y < m+1; y++){
						if(y < m){
							newTable[x][y] = table[x][y];
							sumAll += newTable[x][y];
						}else{
							for (int a = 0; a < m; a++){
								sumY[x] += table[x][a];
								newTable[x][y] = sumY[x];
							}
						}
					}
				}else{
					for (int z = 0; z < m+1; z++){
						if (z < m){
							for (int b = 0; b < n; b++){
							sumX[z] += table[b][z];
							newTable[x][z] = sumX[z];
							}
						}else{
							newTable[x][z] = sumAll;
						}
					}
				}
			}

			for (int s = 0; s < n+1; s++){
				for (int t = 0; t < m+1; t++){
					if (t < m ){
						System.out.print(newTable[s][t] + " ");
					}else{
						System.out.print(newTable[s][t]);
					}
				}
				System.out.println();
			}
		}catch(IOException e){
		System.out.println(e);
		}
	}
}