import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = new String[2];
		int r, c;
		str = br.readLine().split(" ");
		r = Integer.parseInt(str[0]);
		c = Integer.parseInt(str[1]);
		int[][] mat = new int[r+1][c+1];
//		mat????????????
		for(int i=0;i<r+1;i++)
		{
			for(int j=0;j<c+1;j++)
			{
				mat[i][j] = 0;
			}
		}
		String[] str2 = new String[c];
		for(int i=0; i<r; i++)
		{
			str2 = br.readLine().split(" ");
			int buf = 0;
			for(int j=0; j<c; j++)
			{
				buf = Integer.parseInt(str2[j]);
				mat[i][j] = buf;
				mat[i][c] += buf;
				mat[r][j] += buf;
			}
			mat[r][c] += mat[i][c];
		}
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(mat[i][j]);
				if(j!=c) System.out.print(" ");
				else System.out.println();
			}
		}
	}
} import java.io.BufferedReader; BufferedReader java.io import java.io.IOException; IOException java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = new String[2];
		int r, c;
		str = br.readLine().split(" ");
		r = Integer.parseInt(str[0]);
		c = Integer.parseInt(str[1]);
		int[][] mat = new int[r+1][c+1];
//		mat????????????
		for(int i=0;i<r+1;i++)
		{
			for(int j=0;j<c+1;j++)
			{
				mat[i][j] = 0;
			}
		}
		String[] str2 = new String[c];
		for(int i=0; i<r; i++)
		{
			str2 = br.readLine().split(" ");
			int buf = 0;
			for(int j=0; j<c; j++)
			{
				buf = Integer.parseInt(str2[j]);
				mat[i][j] = buf;
				mat[i][c] += buf;
				mat[r][j] += buf;
			}
			mat[r][c] += mat[i][c];
		}
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(mat[i][j]);
				if(j!=c) System.out.print(" ");
				else System.out.println();
			}
		}
	}
} Main public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = new String[2];
		int r, c;
		str = br.readLine().split(" ");
		r = Integer.parseInt(str[0]);
		c = Integer.parseInt(str[1]);
		int[][] mat = new int[r+1][c+1];
//		mat????????????
		for(int i=0;i<r+1;i++)
		{
			for(int j=0;j<c+1;j++)
			{
				mat[i][j] = 0;
			}
		}
		String[] str2 = new String[c];
		for(int i=0; i<r; i++)
		{
			str2 = br.readLine().split(" ");
			int buf = 0;
			for(int j=0; j<c; j++)
			{
				buf = Integer.parseInt(str2[j]);
				mat[i][j] = buf;
				mat[i][c] += buf;
				mat[r][j] += buf;
			}
			mat[r][c] += mat[i][c];
		}
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(mat[i][j]);
				if(j!=c) System.out.print(" ");
				else System.out.println();
			}
		}
	} main {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = new String[2];
		int r, c;
		str = br.readLine().split(" ");
		r = Integer.parseInt(str[0]);
		c = Integer.parseInt(str[1]);
		int[][] mat = new int[r+1][c+1];
//		mat????????????
		for(int i=0;i<r+1;i++)
		{
			for(int j=0;j<c+1;j++)
			{
				mat[i][j] = 0;
			}
		}
		String[] str2 = new String[c];
		for(int i=0; i<r; i++)
		{
			str2 = br.readLine().split(" ");
			int buf = 0;
			for(int j=0; j<c; j++)
			{
				buf = Integer.parseInt(str2[j]);
				mat[i][j] = buf;
				mat[i][c] += buf;
				mat[r][j] += buf;
			}
			mat[r][c] += mat[i][c];
		}
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(mat[i][j]);
				if(j!=c) System.out.print(" ");
				else System.out.println();
			}
		}
	} BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] str = new String[2]; str new String[2] 2 int r r c; c str = br.readLine().split(" ") str br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " r = Integer.parseInt(str[0]) r Integer.parseInt(str[0]) Integer.parseInt Integer str[0] str 0 c = Integer.parseInt(str[1]) c Integer.parseInt(str[1]) Integer.parseInt Integer str[1] str 1 int[][] mat = new int[r+1][c+1]; mat new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i=0;i<r+1;i++)
		{
			for(int j=0;j<c+1;j++)
			{
				mat[i][j] = 0;
			}
		} int i=0; int i=0; i 0 i<r+1 i r+1 r 1 i++ i++ i {
			for(int j=0;j<c+1;j++)
			{
				mat[i][j] = 0;
			}
		} {
			for(int j=0;j<c+1;j++)
			{
				mat[i][j] = 0;
			}
		} for(int j=0;j<c+1;j++)
			{
				mat[i][j] = 0;
			} int j=0; int j=0; j 0 j<c+1 j c+1 c 1 j++ j++ j {
				mat[i][j] = 0;
			} {
				mat[i][j] = 0;
			} mat[i][j] = 0 mat[i][j] mat[i] mat i j 0 String[] str2 = new String[c]; str2 new String[c] c for(int i=0; i<r; i++)
		{
			str2 = br.readLine().split(" ");
			int buf = 0;
			for(int j=0; j<c; j++)
			{
				buf = Integer.parseInt(str2[j]);
				mat[i][j] = buf;
				mat[i][c] += buf;
				mat[r][j] += buf;
			}
			mat[r][c] += mat[i][c];
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			str2 = br.readLine().split(" ");
			int buf = 0;
			for(int j=0; j<c; j++)
			{
				buf = Integer.parseInt(str2[j]);
				mat[i][j] = buf;
				mat[i][c] += buf;
				mat[r][j] += buf;
			}
			mat[r][c] += mat[i][c];
		} {
			str2 = br.readLine().split(" ");
			int buf = 0;
			for(int j=0; j<c; j++)
			{
				buf = Integer.parseInt(str2[j]);
				mat[i][j] = buf;
				mat[i][c] += buf;
				mat[r][j] += buf;
			}
			mat[r][c] += mat[i][c];
		} str2 = br.readLine().split(" ") str2 br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int buf = 0; buf 0 for(int j=0; j<c; j++)
			{
				buf = Integer.parseInt(str2[j]);
				mat[i][j] = buf;
				mat[i][c] += buf;
				mat[r][j] += buf;
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				buf = Integer.parseInt(str2[j]);
				mat[i][j] = buf;
				mat[i][c] += buf;
				mat[r][j] += buf;
			} {
				buf = Integer.parseInt(str2[j]);
				mat[i][j] = buf;
				mat[i][c] += buf;
				mat[r][j] += buf;
			} buf = Integer.parseInt(str2[j]) buf Integer.parseInt(str2[j]) Integer.parseInt Integer str2[j] str2 j mat[i][j] = buf mat[i][j] mat[i] mat i j buf mat[i][c] += buf mat[i][c] mat[i] mat i c buf mat[r][j] += buf mat[r][j] mat[r] mat r j buf mat[r][c] += mat[i][c] mat[r][c] mat[r] mat r c mat[i][c] mat[i] mat i c for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(mat[i][j]);
				if(j!=c) System.out.print(" ");
				else System.out.println();
			}
		} int i=0; int i=0; i 0 i<r+1 i r+1 r 1 i++ i++ i {
			for(int j=0; j<c+1; j++)
			{
				System.out.print(mat[i][j]);
				if(j!=c) System.out.print(" ");
				else System.out.println();
			}
		} {
			for(int j=0; j<c+1; j++)
			{
				System.out.print(mat[i][j]);
				if(j!=c) System.out.print(" ");
				else System.out.println();
			}
		} for(int j=0; j<c+1; j++)
			{
				System.out.print(mat[i][j]);
				if(j!=c) System.out.print(" ");
				else System.out.println();
			} int j=0; int j=0; j 0 j<c+1 j c+1 c 1 j++ j++ j {
				System.out.print(mat[i][j]);
				if(j!=c) System.out.print(" ");
				else System.out.println();
			} {
				System.out.print(mat[i][j]);
				if(j!=c) System.out.print(" ");
				else System.out.println();
			} System.out.print(mat[i][j]) System.out.print System.out System System.out mat[i][j] mat[i] mat i j if(j!=c) System.out.print(" ");
				else System.out.println(); j!=c j c 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 IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = new String[2];
		int r, c;
		str = br.readLine().split(" ");
		r = Integer.parseInt(str[0]);
		c = Integer.parseInt(str[1]);
		int[][] mat = new int[r+1][c+1];
//		mat????????????
		for(int i=0;i<r+1;i++)
		{
			for(int j=0;j<c+1;j++)
			{
				mat[i][j] = 0;
			}
		}
		String[] str2 = new String[c];
		for(int i=0; i<r; i++)
		{
			str2 = br.readLine().split(" ");
			int buf = 0;
			for(int j=0; j<c; j++)
			{
				buf = Integer.parseInt(str2[j]);
				mat[i][j] = buf;
				mat[i][c] += buf;
				mat[r][j] += buf;
			}
			mat[r][c] += mat[i][c];
		}
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(mat[i][j]);
				if(j!=c) System.out.print(" ");
				else System.out.println();
			}
		}
	}
} public class Main
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = new String[2];
		int r, c;
		str = br.readLine().split(" ");
		r = Integer.parseInt(str[0]);
		c = Integer.parseInt(str[1]);
		int[][] mat = new int[r+1][c+1];
//		mat????????????
		for(int i=0;i<r+1;i++)
		{
			for(int j=0;j<c+1;j++)
			{
				mat[i][j] = 0;
			}
		}
		String[] str2 = new String[c];
		for(int i=0; i<r; i++)
		{
			str2 = br.readLine().split(" ");
			int buf = 0;
			for(int j=0; j<c; j++)
			{
				buf = Integer.parseInt(str2[j]);
				mat[i][j] = buf;
				mat[i][c] += buf;
				mat[r][j] += buf;
			}
			mat[r][c] += mat[i][c];
		}
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(mat[i][j]);
				if(j!=c) System.out.print(" ");
				else System.out.println();
			}
		}
	}
} Main
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main
{
	public static void main(String[] args)throws IOException
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] str = new String[2];
		int r, c;
		str = br.readLine().split(" ");
		r = Integer.parseInt(str[0]);
		c = Integer.parseInt(str[1]);
		int[][] mat = new int[r+1][c+1];
//		mat????????????
		for(int i=0;i<r+1;i++)
		{
			for(int j=0;j<c+1;j++)
			{
				mat[i][j] = 0;
			}
		}
		String[] str2 = new String[c];
		for(int i=0; i<r; i++)
		{
			str2 = br.readLine().split(" ");
			int buf = 0;
			for(int j=0; j<c; j++)
			{
				buf = Integer.parseInt(str2[j]);
				mat[i][j] = buf;
				mat[i][c] += buf;
				mat[r][j] += buf;
			}
			mat[r][c] += mat[i][c];
		}
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(mat[i][j]);
				if(j!=c) System.out.print(" ");
				else System.out.println();
			}
		}
	}
}