import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
		
		String[] matrixStr = input.readLine().split(" ");
		
		int row = Integer.parseInt(matrixStr[0]);
		
		int column = Integer.parseInt(matrixStr[1]);
		
		int[][] spreadsheet = new int[row + 1][column +1];
		
		for(int rowNum = 0; rowNum < row; rowNum++)
		{
			String[] rowStr = input.readLine().split(" ");
			
			int rowSum = 0;
			
			for(int columnNum = 0; columnNum < column; columnNum++)
			{
				spreadsheet[rowNum][columnNum] = Integer.parseInt(rowStr[columnNum]);
				
				rowSum = rowSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[rowNum][column] = rowSum;
		}
		
		for(int columnNum = 0; columnNum <= column; columnNum++)
		{
			int columnSum = 0;
			
			for(int rowNum = 0; rowNum < row; rowNum++)
			{
				columnSum = columnSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[row][columnNum] = columnSum;
		}
		
		for(int rowNum = 0; rowNum <= row; rowNum++)
		{
			for(int columnNum = 0; columnNum <= column; columnNum++)
			{
				System.out.print(spreadsheet[rowNum][columnNum]);
				
				if(columnNum != column)
				{
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}
 import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
		
		String[] matrixStr = input.readLine().split(" ");
		
		int row = Integer.parseInt(matrixStr[0]);
		
		int column = Integer.parseInt(matrixStr[1]);
		
		int[][] spreadsheet = new int[row + 1][column +1];
		
		for(int rowNum = 0; rowNum < row; rowNum++)
		{
			String[] rowStr = input.readLine().split(" ");
			
			int rowSum = 0;
			
			for(int columnNum = 0; columnNum < column; columnNum++)
			{
				spreadsheet[rowNum][columnNum] = Integer.parseInt(rowStr[columnNum]);
				
				rowSum = rowSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[rowNum][column] = rowSum;
		}
		
		for(int columnNum = 0; columnNum <= column; columnNum++)
		{
			int columnSum = 0;
			
			for(int rowNum = 0; rowNum < row; rowNum++)
			{
				columnSum = columnSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[row][columnNum] = columnSum;
		}
		
		for(int rowNum = 0; rowNum <= row; rowNum++)
		{
			for(int columnNum = 0; columnNum <= column; columnNum++)
			{
				System.out.print(spreadsheet[rowNum][columnNum]);
				
				if(columnNum != column)
				{
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
} Main public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
		
		String[] matrixStr = input.readLine().split(" ");
		
		int row = Integer.parseInt(matrixStr[0]);
		
		int column = Integer.parseInt(matrixStr[1]);
		
		int[][] spreadsheet = new int[row + 1][column +1];
		
		for(int rowNum = 0; rowNum < row; rowNum++)
		{
			String[] rowStr = input.readLine().split(" ");
			
			int rowSum = 0;
			
			for(int columnNum = 0; columnNum < column; columnNum++)
			{
				spreadsheet[rowNum][columnNum] = Integer.parseInt(rowStr[columnNum]);
				
				rowSum = rowSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[rowNum][column] = rowSum;
		}
		
		for(int columnNum = 0; columnNum <= column; columnNum++)
		{
			int columnSum = 0;
			
			for(int rowNum = 0; rowNum < row; rowNum++)
			{
				columnSum = columnSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[row][columnNum] = columnSum;
		}
		
		for(int rowNum = 0; rowNum <= row; rowNum++)
		{
			for(int columnNum = 0; columnNum <= column; columnNum++)
			{
				System.out.print(spreadsheet[rowNum][columnNum]);
				
				if(columnNum != column)
				{
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	} main {
		BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
		
		String[] matrixStr = input.readLine().split(" ");
		
		int row = Integer.parseInt(matrixStr[0]);
		
		int column = Integer.parseInt(matrixStr[1]);
		
		int[][] spreadsheet = new int[row + 1][column +1];
		
		for(int rowNum = 0; rowNum < row; rowNum++)
		{
			String[] rowStr = input.readLine().split(" ");
			
			int rowSum = 0;
			
			for(int columnNum = 0; columnNum < column; columnNum++)
			{
				spreadsheet[rowNum][columnNum] = Integer.parseInt(rowStr[columnNum]);
				
				rowSum = rowSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[rowNum][column] = rowSum;
		}
		
		for(int columnNum = 0; columnNum <= column; columnNum++)
		{
			int columnSum = 0;
			
			for(int rowNum = 0; rowNum < row; rowNum++)
			{
				columnSum = columnSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[row][columnNum] = columnSum;
		}
		
		for(int rowNum = 0; rowNum <= row; rowNum++)
		{
			for(int columnNum = 0; columnNum <= column; columnNum++)
			{
				System.out.print(spreadsheet[rowNum][columnNum]);
				
				if(columnNum != column)
				{
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	} BufferedReader input = new BufferedReader (new InputStreamReader (System.in)); input new BufferedReader (new InputStreamReader (System.in)) String[] matrixStr = input.readLine().split(" "); matrixStr input.readLine().split(" ") input.readLine().split input.readLine() input.readLine input " " int row = Integer.parseInt(matrixStr[0]); row Integer.parseInt(matrixStr[0]) Integer.parseInt Integer matrixStr[0] matrixStr 0 int column = Integer.parseInt(matrixStr[1]); column Integer.parseInt(matrixStr[1]) Integer.parseInt Integer matrixStr[1] matrixStr 1 int[][] spreadsheet = new int[row + 1][column +1]; spreadsheet new int[row + 1][column +1] row + 1 row 1 column +1 column 1 for(int rowNum = 0; rowNum < row; rowNum++)
		{
			String[] rowStr = input.readLine().split(" ");
			
			int rowSum = 0;
			
			for(int columnNum = 0; columnNum < column; columnNum++)
			{
				spreadsheet[rowNum][columnNum] = Integer.parseInt(rowStr[columnNum]);
				
				rowSum = rowSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[rowNum][column] = rowSum;
		} int rowNum = 0; int rowNum = 0; rowNum 0 rowNum < row rowNum row rowNum++ rowNum++ rowNum {
			String[] rowStr = input.readLine().split(" ");
			
			int rowSum = 0;
			
			for(int columnNum = 0; columnNum < column; columnNum++)
			{
				spreadsheet[rowNum][columnNum] = Integer.parseInt(rowStr[columnNum]);
				
				rowSum = rowSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[rowNum][column] = rowSum;
		} {
			String[] rowStr = input.readLine().split(" ");
			
			int rowSum = 0;
			
			for(int columnNum = 0; columnNum < column; columnNum++)
			{
				spreadsheet[rowNum][columnNum] = Integer.parseInt(rowStr[columnNum]);
				
				rowSum = rowSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[rowNum][column] = rowSum;
		} String[] rowStr = input.readLine().split(" "); rowStr input.readLine().split(" ") input.readLine().split input.readLine() input.readLine input " " int rowSum = 0; rowSum 0 for(int columnNum = 0; columnNum < column; columnNum++)
			{
				spreadsheet[rowNum][columnNum] = Integer.parseInt(rowStr[columnNum]);
				
				rowSum = rowSum + spreadsheet[rowNum][columnNum];
			} int columnNum = 0; int columnNum = 0; columnNum 0 columnNum < column columnNum column columnNum++ columnNum++ columnNum {
				spreadsheet[rowNum][columnNum] = Integer.parseInt(rowStr[columnNum]);
				
				rowSum = rowSum + spreadsheet[rowNum][columnNum];
			} {
				spreadsheet[rowNum][columnNum] = Integer.parseInt(rowStr[columnNum]);
				
				rowSum = rowSum + spreadsheet[rowNum][columnNum];
			} spreadsheet[rowNum][columnNum] = Integer.parseInt(rowStr[columnNum]) spreadsheet[rowNum][columnNum] spreadsheet[rowNum] spreadsheet rowNum columnNum Integer.parseInt(rowStr[columnNum]) Integer.parseInt Integer rowStr[columnNum] rowStr columnNum rowSum = rowSum + spreadsheet[rowNum][columnNum] rowSum rowSum + spreadsheet[rowNum][columnNum] rowSum spreadsheet[rowNum][columnNum] spreadsheet[rowNum] spreadsheet rowNum columnNum spreadsheet[rowNum][column] = rowSum spreadsheet[rowNum][column] spreadsheet[rowNum] spreadsheet rowNum column rowSum for(int columnNum = 0; columnNum <= column; columnNum++)
		{
			int columnSum = 0;
			
			for(int rowNum = 0; rowNum < row; rowNum++)
			{
				columnSum = columnSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[row][columnNum] = columnSum;
		} int columnNum = 0; int columnNum = 0; columnNum 0 columnNum <= column columnNum column columnNum++ columnNum++ columnNum {
			int columnSum = 0;
			
			for(int rowNum = 0; rowNum < row; rowNum++)
			{
				columnSum = columnSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[row][columnNum] = columnSum;
		} {
			int columnSum = 0;
			
			for(int rowNum = 0; rowNum < row; rowNum++)
			{
				columnSum = columnSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[row][columnNum] = columnSum;
		} int columnSum = 0; columnSum 0 for(int rowNum = 0; rowNum < row; rowNum++)
			{
				columnSum = columnSum + spreadsheet[rowNum][columnNum];
			} int rowNum = 0; int rowNum = 0; rowNum 0 rowNum < row rowNum row rowNum++ rowNum++ rowNum {
				columnSum = columnSum + spreadsheet[rowNum][columnNum];
			} {
				columnSum = columnSum + spreadsheet[rowNum][columnNum];
			} columnSum = columnSum + spreadsheet[rowNum][columnNum] columnSum columnSum + spreadsheet[rowNum][columnNum] columnSum spreadsheet[rowNum][columnNum] spreadsheet[rowNum] spreadsheet rowNum columnNum spreadsheet[row][columnNum] = columnSum spreadsheet[row][columnNum] spreadsheet[row] spreadsheet row columnNum columnSum for(int rowNum = 0; rowNum <= row; rowNum++)
		{
			for(int columnNum = 0; columnNum <= column; columnNum++)
			{
				System.out.print(spreadsheet[rowNum][columnNum]);
				
				if(columnNum != column)
				{
					System.out.print(" ");
				}
			}
			System.out.println();
		} int rowNum = 0; int rowNum = 0; rowNum 0 rowNum <= row rowNum row rowNum++ rowNum++ rowNum {
			for(int columnNum = 0; columnNum <= column; columnNum++)
			{
				System.out.print(spreadsheet[rowNum][columnNum]);
				
				if(columnNum != column)
				{
					System.out.print(" ");
				}
			}
			System.out.println();
		} {
			for(int columnNum = 0; columnNum <= column; columnNum++)
			{
				System.out.print(spreadsheet[rowNum][columnNum]);
				
				if(columnNum != column)
				{
					System.out.print(" ");
				}
			}
			System.out.println();
		} for(int columnNum = 0; columnNum <= column; columnNum++)
			{
				System.out.print(spreadsheet[rowNum][columnNum]);
				
				if(columnNum != column)
				{
					System.out.print(" ");
				}
			} int columnNum = 0; int columnNum = 0; columnNum 0 columnNum <= column columnNum column columnNum++ columnNum++ columnNum {
				System.out.print(spreadsheet[rowNum][columnNum]);
				
				if(columnNum != column)
				{
					System.out.print(" ");
				}
			} {
				System.out.print(spreadsheet[rowNum][columnNum]);
				
				if(columnNum != column)
				{
					System.out.print(" ");
				}
			} System.out.print(spreadsheet[rowNum][columnNum]) System.out.print System.out System System.out spreadsheet[rowNum][columnNum] spreadsheet[rowNum] spreadsheet rowNum columnNum if(columnNum != column)
				{
					System.out.print(" ");
				} columnNum != column columnNum column {
					System.out.print(" ");
				} System.out.print(" ") System.out.print System.out System System.out " " System.out.println() System.out.println System.out System System.out String[] args args public class Main {
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
		
		String[] matrixStr = input.readLine().split(" ");
		
		int row = Integer.parseInt(matrixStr[0]);
		
		int column = Integer.parseInt(matrixStr[1]);
		
		int[][] spreadsheet = new int[row + 1][column +1];
		
		for(int rowNum = 0; rowNum < row; rowNum++)
		{
			String[] rowStr = input.readLine().split(" ");
			
			int rowSum = 0;
			
			for(int columnNum = 0; columnNum < column; columnNum++)
			{
				spreadsheet[rowNum][columnNum] = Integer.parseInt(rowStr[columnNum]);
				
				rowSum = rowSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[rowNum][column] = rowSum;
		}
		
		for(int columnNum = 0; columnNum <= column; columnNum++)
		{
			int columnSum = 0;
			
			for(int rowNum = 0; rowNum < row; rowNum++)
			{
				columnSum = columnSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[row][columnNum] = columnSum;
		}
		
		for(int rowNum = 0; rowNum <= row; rowNum++)
		{
			for(int columnNum = 0; columnNum <= column; columnNum++)
			{
				System.out.print(spreadsheet[rowNum][columnNum]);
				
				if(columnNum != column)
				{
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
} public class Main {
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
		
		String[] matrixStr = input.readLine().split(" ");
		
		int row = Integer.parseInt(matrixStr[0]);
		
		int column = Integer.parseInt(matrixStr[1]);
		
		int[][] spreadsheet = new int[row + 1][column +1];
		
		for(int rowNum = 0; rowNum < row; rowNum++)
		{
			String[] rowStr = input.readLine().split(" ");
			
			int rowSum = 0;
			
			for(int columnNum = 0; columnNum < column; columnNum++)
			{
				spreadsheet[rowNum][columnNum] = Integer.parseInt(rowStr[columnNum]);
				
				rowSum = rowSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[rowNum][column] = rowSum;
		}
		
		for(int columnNum = 0; columnNum <= column; columnNum++)
		{
			int columnSum = 0;
			
			for(int rowNum = 0; rowNum < row; rowNum++)
			{
				columnSum = columnSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[row][columnNum] = columnSum;
		}
		
		for(int rowNum = 0; rowNum <= row; rowNum++)
		{
			for(int columnNum = 0; columnNum <= column; columnNum++)
			{
				System.out.print(spreadsheet[rowNum][columnNum]);
				
				if(columnNum != column)
				{
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader input = new BufferedReader (new InputStreamReader (System.in));
		
		String[] matrixStr = input.readLine().split(" ");
		
		int row = Integer.parseInt(matrixStr[0]);
		
		int column = Integer.parseInt(matrixStr[1]);
		
		int[][] spreadsheet = new int[row + 1][column +1];
		
		for(int rowNum = 0; rowNum < row; rowNum++)
		{
			String[] rowStr = input.readLine().split(" ");
			
			int rowSum = 0;
			
			for(int columnNum = 0; columnNum < column; columnNum++)
			{
				spreadsheet[rowNum][columnNum] = Integer.parseInt(rowStr[columnNum]);
				
				rowSum = rowSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[rowNum][column] = rowSum;
		}
		
		for(int columnNum = 0; columnNum <= column; columnNum++)
		{
			int columnSum = 0;
			
			for(int rowNum = 0; rowNum < row; rowNum++)
			{
				columnSum = columnSum + spreadsheet[rowNum][columnNum];
			}
			
			spreadsheet[row][columnNum] = columnSum;
		}
		
		for(int rowNum = 0; rowNum <= row; rowNum++)
		{
			for(int columnNum = 0; columnNum <= column; columnNum++)
			{
				System.out.print(spreadsheet[rowNum][columnNum]);
				
				if(columnNum != column)
				{
					System.out.print(" ");
				}
			}
			System.out.println();
		}
	}
}

