import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] a = new int[r+1][c+1];

		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				if(i==r || j==c)
				{
					a[i][j] = 0;
				}
				else {
					a[i][j] = scanner.nextInt();
				}
			}
		}
		for(int i=0; i<r; i++)
		{
			for(int j=0; j<c; j++)
			{
				a[i][c] += a[i][j];
				a[r][j] += a[i][j];
			}
			a[r][c] += a[i][c];
		}
		
		
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(a[i][j]+(j<c?" ":"\n"));
			}
		}
	}
}
 import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] a = new int[r+1][c+1];

		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				if(i==r || j==c)
				{
					a[i][j] = 0;
				}
				else {
					a[i][j] = scanner.nextInt();
				}
			}
		}
		for(int i=0; i<r; i++)
		{
			for(int j=0; j<c; j++)
			{
				a[i][c] += a[i][j];
				a[r][j] += a[i][j];
			}
			a[r][c] += a[i][c];
		}
		
		
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(a[i][j]+(j<c?" ":"\n"));
			}
		}
	}
} Main public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] a = new int[r+1][c+1];

		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				if(i==r || j==c)
				{
					a[i][j] = 0;
				}
				else {
					a[i][j] = scanner.nextInt();
				}
			}
		}
		for(int i=0; i<r; i++)
		{
			for(int j=0; j<c; j++)
			{
				a[i][c] += a[i][j];
				a[r][j] += a[i][j];
			}
			a[r][c] += a[i][c];
		}
		
		
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(a[i][j]+(j<c?" ":"\n"));
			}
		}
	} main {
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] a = new int[r+1][c+1];

		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				if(i==r || j==c)
				{
					a[i][j] = 0;
				}
				else {
					a[i][j] = scanner.nextInt();
				}
			}
		}
		for(int i=0; i<r; i++)
		{
			for(int j=0; j<c; j++)
			{
				a[i][c] += a[i][j];
				a[r][j] += a[i][j];
			}
			a[r][c] += a[i][c];
		}
		
		
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(a[i][j]+(j<c?" ":"\n"));
			}
		}
	} Scanner scanner = new Scanner(System.in); scanner new Scanner(System.in) int r = scanner.nextInt(); r scanner.nextInt() scanner.nextInt scanner int c = scanner.nextInt(); c scanner.nextInt() scanner.nextInt scanner int[][] a = new int[r+1][c+1]; a 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++)
			{
				if(i==r || j==c)
				{
					a[i][j] = 0;
				}
				else {
					a[i][j] = scanner.nextInt();
				}
			}
		} 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++)
			{
				if(i==r || j==c)
				{
					a[i][j] = 0;
				}
				else {
					a[i][j] = scanner.nextInt();
				}
			}
		} {
			for(int j=0; j<c+1; j++)
			{
				if(i==r || j==c)
				{
					a[i][j] = 0;
				}
				else {
					a[i][j] = scanner.nextInt();
				}
			}
		} for(int j=0; j<c+1; j++)
			{
				if(i==r || j==c)
				{
					a[i][j] = 0;
				}
				else {
					a[i][j] = scanner.nextInt();
				}
			} int j=0; int j=0; j 0 j<c+1 j c+1 c 1 j++ j++ j {
				if(i==r || j==c)
				{
					a[i][j] = 0;
				}
				else {
					a[i][j] = scanner.nextInt();
				}
			} {
				if(i==r || j==c)
				{
					a[i][j] = 0;
				}
				else {
					a[i][j] = scanner.nextInt();
				}
			} if(i==r || j==c)
				{
					a[i][j] = 0;
				}
				else {
					a[i][j] = scanner.nextInt();
				} i==r || j==c i==r i r j==c j c {
					a[i][j] = 0;
				} a[i][j] = 0 a[i][j] a[i] a i j 0 {
					a[i][j] = scanner.nextInt();
				} a[i][j] = scanner.nextInt() a[i][j] a[i] a i j scanner.nextInt() scanner.nextInt scanner for(int i=0; i<r; i++)
		{
			for(int j=0; j<c; j++)
			{
				a[i][c] += a[i][j];
				a[r][j] += a[i][j];
			}
			a[r][c] += a[i][c];
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			for(int j=0; j<c; j++)
			{
				a[i][c] += a[i][j];
				a[r][j] += a[i][j];
			}
			a[r][c] += a[i][c];
		} {
			for(int j=0; j<c; j++)
			{
				a[i][c] += a[i][j];
				a[r][j] += a[i][j];
			}
			a[r][c] += a[i][c];
		} for(int j=0; j<c; j++)
			{
				a[i][c] += a[i][j];
				a[r][j] += a[i][j];
			} int j=0; int j=0; j 0 j<c j c j++ j++ j {
				a[i][c] += a[i][j];
				a[r][j] += a[i][j];
			} {
				a[i][c] += a[i][j];
				a[r][j] += a[i][j];
			} a[i][c] += a[i][j] a[i][c] a[i] a i c a[i][j] a[i] a i j a[r][j] += a[i][j] a[r][j] a[r] a r j a[i][j] a[i] a i j a[r][c] += a[i][c] a[r][c] a[r] a r c a[i][c] a[i] a i c for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(a[i][j]+(j<c?" ":"\n"));
			}
		} 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(a[i][j]+(j<c?" ":"\n"));
			}
		} {
			for(int j=0; j<c+1; j++)
			{
				System.out.print(a[i][j]+(j<c?" ":"\n"));
			}
		} for(int j=0; j<c+1; j++)
			{
				System.out.print(a[i][j]+(j<c?" ":"\n"));
			} int j=0; int j=0; j 0 j<c+1 j c+1 c 1 j++ j++ j {
				System.out.print(a[i][j]+(j<c?" ":"\n"));
			} {
				System.out.print(a[i][j]+(j<c?" ":"\n"));
			} System.out.print(a[i][j]+(j<c?" ":"\n")) System.out.print System.out System System.out a[i][j]+(j<c?" ":"\n") a[i][j] a[i] a i j (j<c?" ":"\n") j<c j c " " "\n" String[] args args public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] a = new int[r+1][c+1];

		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				if(i==r || j==c)
				{
					a[i][j] = 0;
				}
				else {
					a[i][j] = scanner.nextInt();
				}
			}
		}
		for(int i=0; i<r; i++)
		{
			for(int j=0; j<c; j++)
			{
				a[i][c] += a[i][j];
				a[r][j] += a[i][j];
			}
			a[r][c] += a[i][c];
		}
		
		
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(a[i][j]+(j<c?" ":"\n"));
			}
		}
	}
} public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] a = new int[r+1][c+1];

		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				if(i==r || j==c)
				{
					a[i][j] = 0;
				}
				else {
					a[i][j] = scanner.nextInt();
				}
			}
		}
		for(int i=0; i<r; i++)
		{
			for(int j=0; j<c; j++)
			{
				a[i][c] += a[i][j];
				a[r][j] += a[i][j];
			}
			a[r][c] += a[i][c];
		}
		
		
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(a[i][j]+(j<c?" ":"\n"));
			}
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		int r = scanner.nextInt();
		int c = scanner.nextInt();
		int[][] a = new int[r+1][c+1];

		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				if(i==r || j==c)
				{
					a[i][j] = 0;
				}
				else {
					a[i][j] = scanner.nextInt();
				}
			}
		}
		for(int i=0; i<r; i++)
		{
			for(int j=0; j<c; j++)
			{
				a[i][c] += a[i][j];
				a[r][j] += a[i][j];
			}
			a[r][c] += a[i][c];
		}
		
		
		for(int i=0; i<r+1; i++)
		{
			for(int j=0; j<c+1; j++)
			{
				System.out.print(a[i][j]+(j<c?" ":"\n"));
			}
		}
	}
}

