import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] array = new int[r + 1][c + 1];
		
		for(int i = 0;i < r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				array[i][j] = scan.nextInt();
				array[r][j] += array[i][j];
				array[i][c] += array[i][j];
			}
			array[r][c] += array[i][c];
		}
		
		for(int i = 0;i <= r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				System.out.print(array[i][j] + " ");
			}
			System.out.println(array[i][c]);
		}
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] array = new int[r + 1][c + 1];
		
		for(int i = 0;i < r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				array[i][j] = scan.nextInt();
				array[r][j] += array[i][j];
				array[i][c] += array[i][j];
			}
			array[r][c] += array[i][c];
		}
		
		for(int i = 0;i <= r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				System.out.print(array[i][j] + " ");
			}
			System.out.println(array[i][c]);
		}
	}
} Main public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] array = new int[r + 1][c + 1];
		
		for(int i = 0;i < r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				array[i][j] = scan.nextInt();
				array[r][j] += array[i][j];
				array[i][c] += array[i][j];
			}
			array[r][c] += array[i][c];
		}
		
		for(int i = 0;i <= r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				System.out.print(array[i][j] + " ");
			}
			System.out.println(array[i][c]);
		}
	} main {
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] array = new int[r + 1][c + 1];
		
		for(int i = 0;i < r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				array[i][j] = scan.nextInt();
				array[r][j] += array[i][j];
				array[i][c] += array[i][j];
			}
			array[r][c] += array[i][c];
		}
		
		for(int i = 0;i <= r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				System.out.print(array[i][j] + " ");
			}
			System.out.println(array[i][c]);
		}
	} Scanner scan = new Scanner(System.in); scan new Scanner(System.in) int r = scan.nextInt(); r scan.nextInt() scan.nextInt scan int c = scan.nextInt(); c scan.nextInt() scan.nextInt scan int[][] array = new int[r + 1][c + 1]; array new int[r + 1][c + 1] r + 1 r 1 c + 1 c 1 for(int i = 0;i < r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				array[i][j] = scan.nextInt();
				array[r][j] += array[i][j];
				array[i][c] += array[i][j];
			}
			array[r][c] += array[i][c];
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			for(int j = 0;j < c;j++)
			{
				array[i][j] = scan.nextInt();
				array[r][j] += array[i][j];
				array[i][c] += array[i][j];
			}
			array[r][c] += array[i][c];
		} {
			for(int j = 0;j < c;j++)
			{
				array[i][j] = scan.nextInt();
				array[r][j] += array[i][j];
				array[i][c] += array[i][j];
			}
			array[r][c] += array[i][c];
		} for(int j = 0;j < c;j++)
			{
				array[i][j] = scan.nextInt();
				array[r][j] += array[i][j];
				array[i][c] += array[i][j];
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				array[i][j] = scan.nextInt();
				array[r][j] += array[i][j];
				array[i][c] += array[i][j];
			} {
				array[i][j] = scan.nextInt();
				array[r][j] += array[i][j];
				array[i][c] += array[i][j];
			} array[i][j] = scan.nextInt() array[i][j] array[i] array i j scan.nextInt() scan.nextInt scan array[r][j] += array[i][j] array[r][j] array[r] array r j array[i][j] array[i] array i j array[i][c] += array[i][j] array[i][c] array[i] array i c array[i][j] array[i] array i j array[r][c] += array[i][c] array[r][c] array[r] array r c array[i][c] array[i] array i c for(int i = 0;i <= r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				System.out.print(array[i][j] + " ");
			}
			System.out.println(array[i][c]);
		} int i = 0; int i = 0; i 0 i <= r i r i++ i++ i {
			for(int j = 0;j < c;j++)
			{
				System.out.print(array[i][j] + " ");
			}
			System.out.println(array[i][c]);
		} {
			for(int j = 0;j < c;j++)
			{
				System.out.print(array[i][j] + " ");
			}
			System.out.println(array[i][c]);
		} for(int j = 0;j < c;j++)
			{
				System.out.print(array[i][j] + " ");
			} int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
				System.out.print(array[i][j] + " ");
			} {
				System.out.print(array[i][j] + " ");
			} System.out.print(array[i][j] + " ") System.out.print System.out System System.out array[i][j] + " " array[i][j] array[i] array i j " " System.out.println(array[i][c]) System.out.println System.out System System.out array[i][c] array[i] array i c String[] args args public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] array = new int[r + 1][c + 1];
		
		for(int i = 0;i < r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				array[i][j] = scan.nextInt();
				array[r][j] += array[i][j];
				array[i][c] += array[i][j];
			}
			array[r][c] += array[i][c];
		}
		
		for(int i = 0;i <= r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				System.out.print(array[i][j] + " ");
			}
			System.out.println(array[i][c]);
		}
	}
} public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] array = new int[r + 1][c + 1];
		
		for(int i = 0;i < r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				array[i][j] = scan.nextInt();
				array[r][j] += array[i][j];
				array[i][c] += array[i][j];
			}
			array[r][c] += array[i][c];
		}
		
		for(int i = 0;i <= r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				System.out.print(array[i][j] + " ");
			}
			System.out.println(array[i][c]);
		}
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int r = scan.nextInt();
		int c = scan.nextInt();
		int[][] array = new int[r + 1][c + 1];
		
		for(int i = 0;i < r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				array[i][j] = scan.nextInt();
				array[r][j] += array[i][j];
				array[i][c] += array[i][j];
			}
			array[r][c] += array[i][c];
		}
		
		for(int i = 0;i <= r;i++)
		{
			for(int j = 0;j < c;j++)
			{
				System.out.print(array[i][j] + " ");
			}
			System.out.println(array[i][c]);
		}
	}
}