import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int[] s = new int[111];
		int r = input.nextInt();
		int c = input.nextInt();
		int t, sum;
		for(int i = 0; i < r; i++)
		{
			sum = 0;
			for(int k = 0; k < c; k++)
			{
				t = input.nextInt();
				sum += t;
				s[k] += t;
				System.out.print(t + " ");
			}
			s[c] += sum;
			System.out.println(sum);
		}
		for(int i = 0; i < c; i++)
			System.out.print(s[i] + " ");
		System.out.println(s[c]);
	}
} import java.util.*; util.* java public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int[] s = new int[111];
		int r = input.nextInt();
		int c = input.nextInt();
		int t, sum;
		for(int i = 0; i < r; i++)
		{
			sum = 0;
			for(int k = 0; k < c; k++)
			{
				t = input.nextInt();
				sum += t;
				s[k] += t;
				System.out.print(t + " ");
			}
			s[c] += sum;
			System.out.println(sum);
		}
		for(int i = 0; i < c; i++)
			System.out.print(s[i] + " ");
		System.out.println(s[c]);
	}
} Main public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int[] s = new int[111];
		int r = input.nextInt();
		int c = input.nextInt();
		int t, sum;
		for(int i = 0; i < r; i++)
		{
			sum = 0;
			for(int k = 0; k < c; k++)
			{
				t = input.nextInt();
				sum += t;
				s[k] += t;
				System.out.print(t + " ");
			}
			s[c] += sum;
			System.out.println(sum);
		}
		for(int i = 0; i < c; i++)
			System.out.print(s[i] + " ");
		System.out.println(s[c]);
	} main {
		Scanner input = new Scanner(System.in);
		int[] s = new int[111];
		int r = input.nextInt();
		int c = input.nextInt();
		int t, sum;
		for(int i = 0; i < r; i++)
		{
			sum = 0;
			for(int k = 0; k < c; k++)
			{
				t = input.nextInt();
				sum += t;
				s[k] += t;
				System.out.print(t + " ");
			}
			s[c] += sum;
			System.out.println(sum);
		}
		for(int i = 0; i < c; i++)
			System.out.print(s[i] + " ");
		System.out.println(s[c]);
	} Scanner input = new Scanner(System.in); input new Scanner(System.in) int[] s = new int[111]; s new int[111] 111 int r = input.nextInt(); r input.nextInt() input.nextInt input int c = input.nextInt(); c input.nextInt() input.nextInt input int t t sum; sum for(int i = 0; i < r; i++)
		{
			sum = 0;
			for(int k = 0; k < c; k++)
			{
				t = input.nextInt();
				sum += t;
				s[k] += t;
				System.out.print(t + " ");
			}
			s[c] += sum;
			System.out.println(sum);
		} int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
			sum = 0;
			for(int k = 0; k < c; k++)
			{
				t = input.nextInt();
				sum += t;
				s[k] += t;
				System.out.print(t + " ");
			}
			s[c] += sum;
			System.out.println(sum);
		} {
			sum = 0;
			for(int k = 0; k < c; k++)
			{
				t = input.nextInt();
				sum += t;
				s[k] += t;
				System.out.print(t + " ");
			}
			s[c] += sum;
			System.out.println(sum);
		} sum = 0 sum 0 for(int k = 0; k < c; k++)
			{
				t = input.nextInt();
				sum += t;
				s[k] += t;
				System.out.print(t + " ");
			} int k = 0; int k = 0; k 0 k < c k c k++ k++ k {
				t = input.nextInt();
				sum += t;
				s[k] += t;
				System.out.print(t + " ");
			} {
				t = input.nextInt();
				sum += t;
				s[k] += t;
				System.out.print(t + " ");
			} t = input.nextInt() t input.nextInt() input.nextInt input sum += t sum t s[k] += t s[k] s k t System.out.print(t + " ") System.out.print System.out System System.out t + " " t " " s[c] += sum s[c] s c sum System.out.println(sum) System.out.println System.out System System.out sum for(int i = 0; i < c; i++)
			System.out.print(s[i] + " "); int i = 0; int i = 0; i 0 i < c i c i++ i++ i System.out.print(s[i] + " "); System.out.print(s[i] + " ") System.out.print System.out System System.out s[i] + " " s[i] s i " " System.out.println(s[c]) System.out.println System.out System System.out s[c] s c String args[] args public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int[] s = new int[111];
		int r = input.nextInt();
		int c = input.nextInt();
		int t, sum;
		for(int i = 0; i < r; i++)
		{
			sum = 0;
			for(int k = 0; k < c; k++)
			{
				t = input.nextInt();
				sum += t;
				s[k] += t;
				System.out.print(t + " ");
			}
			s[c] += sum;
			System.out.println(sum);
		}
		for(int i = 0; i < c; i++)
			System.out.print(s[i] + " ");
		System.out.println(s[c]);
	}
} public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int[] s = new int[111];
		int r = input.nextInt();
		int c = input.nextInt();
		int t, sum;
		for(int i = 0; i < r; i++)
		{
			sum = 0;
			for(int k = 0; k < c; k++)
			{
				t = input.nextInt();
				sum += t;
				s[k] += t;
				System.out.print(t + " ");
			}
			s[c] += sum;
			System.out.println(sum);
		}
		for(int i = 0; i < c; i++)
			System.out.print(s[i] + " ");
		System.out.println(s[c]);
	}
} Main
import java.util.*;
public class Main
{
	public static void main(String args[])
	{
		Scanner input = new Scanner(System.in);
		int[] s = new int[111];
		int r = input.nextInt();
		int c = input.nextInt();
		int t, sum;
		for(int i = 0; i < r; i++)
		{
			sum = 0;
			for(int k = 0; k < c; k++)
			{
				t = input.nextInt();
				sum += t;
				s[k] += t;
				System.out.print(t + " ");
			}
			s[c] += sum;
			System.out.println(sum);
		}
		for(int i = 0; i < c; i++)
			System.out.print(s[i] + " ");
		System.out.println(s[c]);
	}
}