import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] in=br.readLine().split(" ");
		int r=Integer.parseInt(in[0]);
		int c=Integer.parseInt(in[1]);
		int array[][]=new int[r+1][c+1];
		int sum;
		for(int i=0;i<r;i++){
			in=br.readLine().split(" ");
			for(int j=0;j<c;j++)
				array[i][j]=Integer.parseInt(in[j]);
		}
		for(int i=0;i<r;i++){
			sum=0;
			for(int j=0;j<c;j++)
				sum+=array[i][j];
			array[i][c]=sum;
		}
		for(int i=0;i<=c;i++){
			sum=0;
			for(int j=0;j<r;j++)
				sum+=array[j][i];
			array[r][i]=sum;
		}
		for(int i=0;i<=r;i++){
			System.out.print(array[i][0]);
			for(int j=1;j<=c;j++)
				System.out.print(" "+array[i][j]);
			System.out.println("");
		}
	}
} import java.util.*; util.* java import java.io.*; io.* java import java.lang.*; lang.* java import java.math.*; math.* java public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] in=br.readLine().split(" ");
		int r=Integer.parseInt(in[0]);
		int c=Integer.parseInt(in[1]);
		int array[][]=new int[r+1][c+1];
		int sum;
		for(int i=0;i<r;i++){
			in=br.readLine().split(" ");
			for(int j=0;j<c;j++)
				array[i][j]=Integer.parseInt(in[j]);
		}
		for(int i=0;i<r;i++){
			sum=0;
			for(int j=0;j<c;j++)
				sum+=array[i][j];
			array[i][c]=sum;
		}
		for(int i=0;i<=c;i++){
			sum=0;
			for(int j=0;j<r;j++)
				sum+=array[j][i];
			array[r][i]=sum;
		}
		for(int i=0;i<=r;i++){
			System.out.print(array[i][0]);
			for(int j=1;j<=c;j++)
				System.out.print(" "+array[i][j]);
			System.out.println("");
		}
	}
} Main public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] in=br.readLine().split(" ");
		int r=Integer.parseInt(in[0]);
		int c=Integer.parseInt(in[1]);
		int array[][]=new int[r+1][c+1];
		int sum;
		for(int i=0;i<r;i++){
			in=br.readLine().split(" ");
			for(int j=0;j<c;j++)
				array[i][j]=Integer.parseInt(in[j]);
		}
		for(int i=0;i<r;i++){
			sum=0;
			for(int j=0;j<c;j++)
				sum+=array[i][j];
			array[i][c]=sum;
		}
		for(int i=0;i<=c;i++){
			sum=0;
			for(int j=0;j<r;j++)
				sum+=array[j][i];
			array[r][i]=sum;
		}
		for(int i=0;i<=r;i++){
			System.out.print(array[i][0]);
			for(int j=1;j<=c;j++)
				System.out.print(" "+array[i][j]);
			System.out.println("");
		}
	} main {
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] in=br.readLine().split(" ");
		int r=Integer.parseInt(in[0]);
		int c=Integer.parseInt(in[1]);
		int array[][]=new int[r+1][c+1];
		int sum;
		for(int i=0;i<r;i++){
			in=br.readLine().split(" ");
			for(int j=0;j<c;j++)
				array[i][j]=Integer.parseInt(in[j]);
		}
		for(int i=0;i<r;i++){
			sum=0;
			for(int j=0;j<c;j++)
				sum+=array[i][j];
			array[i][c]=sum;
		}
		for(int i=0;i<=c;i++){
			sum=0;
			for(int j=0;j<r;j++)
				sum+=array[j][i];
			array[r][i]=sum;
		}
		for(int i=0;i<=r;i++){
			System.out.print(array[i][0]);
			for(int j=1;j<=c;j++)
				System.out.print(" "+array[i][j]);
			System.out.println("");
		}
	} Scanner stdIn=new Scanner(System.in); stdIn new Scanner(System.in) BufferedReader br=new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] in=br.readLine().split(" "); in br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int r=Integer.parseInt(in[0]); r Integer.parseInt(in[0]) Integer.parseInt Integer in[0] in 0 int c=Integer.parseInt(in[1]); c Integer.parseInt(in[1]) Integer.parseInt Integer in[1] in 1 int array[][]=new int[r+1][c+1]; array new int[r+1][c+1] r+1 r 1 c+1 c 1 int sum; sum for(int i=0;i<r;i++){
			in=br.readLine().split(" ");
			for(int j=0;j<c;j++)
				array[i][j]=Integer.parseInt(in[j]);
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			in=br.readLine().split(" ");
			for(int j=0;j<c;j++)
				array[i][j]=Integer.parseInt(in[j]);
		} {
			in=br.readLine().split(" ");
			for(int j=0;j<c;j++)
				array[i][j]=Integer.parseInt(in[j]);
		} in=br.readLine().split(" ") in br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int j=0;j<c;j++)
				array[i][j]=Integer.parseInt(in[j]); int j=0; int j=0; j 0 j<c j c j++ j++ j array[i][j]=Integer.parseInt(in[j]); array[i][j]=Integer.parseInt(in[j]) array[i][j] array[i] array i j Integer.parseInt(in[j]) Integer.parseInt Integer in[j] in j for(int i=0;i<r;i++){
			sum=0;
			for(int j=0;j<c;j++)
				sum+=array[i][j];
			array[i][c]=sum;
		} int i=0; int i=0; i 0 i<r i r i++ i++ i {
			sum=0;
			for(int j=0;j<c;j++)
				sum+=array[i][j];
			array[i][c]=sum;
		} {
			sum=0;
			for(int j=0;j<c;j++)
				sum+=array[i][j];
			array[i][c]=sum;
		} sum=0 sum 0 for(int j=0;j<c;j++)
				sum+=array[i][j]; int j=0; int j=0; j 0 j<c j c j++ j++ j sum+=array[i][j]; sum+=array[i][j] sum array[i][j] array[i] array i j array[i][c]=sum array[i][c] array[i] array i c sum for(int i=0;i<=c;i++){
			sum=0;
			for(int j=0;j<r;j++)
				sum+=array[j][i];
			array[r][i]=sum;
		} int i=0; int i=0; i 0 i<=c i c i++ i++ i {
			sum=0;
			for(int j=0;j<r;j++)
				sum+=array[j][i];
			array[r][i]=sum;
		} {
			sum=0;
			for(int j=0;j<r;j++)
				sum+=array[j][i];
			array[r][i]=sum;
		} sum=0 sum 0 for(int j=0;j<r;j++)
				sum+=array[j][i]; int j=0; int j=0; j 0 j<r j r j++ j++ j sum+=array[j][i]; sum+=array[j][i] sum array[j][i] array[j] array j i array[r][i]=sum array[r][i] array[r] array r i sum for(int i=0;i<=r;i++){
			System.out.print(array[i][0]);
			for(int j=1;j<=c;j++)
				System.out.print(" "+array[i][j]);
			System.out.println("");
		} int i=0; int i=0; i 0 i<=r i r i++ i++ i {
			System.out.print(array[i][0]);
			for(int j=1;j<=c;j++)
				System.out.print(" "+array[i][j]);
			System.out.println("");
		} {
			System.out.print(array[i][0]);
			for(int j=1;j<=c;j++)
				System.out.print(" "+array[i][j]);
			System.out.println("");
		} System.out.print(array[i][0]) System.out.print System.out System System.out array[i][0] array[i] array i 0 for(int j=1;j<=c;j++)
				System.out.print(" "+array[i][j]); int j=1; int j=1; j 1 j<=c j c j++ j++ 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("") System.out.println System.out System System.out "" String[] args args public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] in=br.readLine().split(" ");
		int r=Integer.parseInt(in[0]);
		int c=Integer.parseInt(in[1]);
		int array[][]=new int[r+1][c+1];
		int sum;
		for(int i=0;i<r;i++){
			in=br.readLine().split(" ");
			for(int j=0;j<c;j++)
				array[i][j]=Integer.parseInt(in[j]);
		}
		for(int i=0;i<r;i++){
			sum=0;
			for(int j=0;j<c;j++)
				sum+=array[i][j];
			array[i][c]=sum;
		}
		for(int i=0;i<=c;i++){
			sum=0;
			for(int j=0;j<r;j++)
				sum+=array[j][i];
			array[r][i]=sum;
		}
		for(int i=0;i<=r;i++){
			System.out.print(array[i][0]);
			for(int j=1;j<=c;j++)
				System.out.print(" "+array[i][j]);
			System.out.println("");
		}
	}
} public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] in=br.readLine().split(" ");
		int r=Integer.parseInt(in[0]);
		int c=Integer.parseInt(in[1]);
		int array[][]=new int[r+1][c+1];
		int sum;
		for(int i=0;i<r;i++){
			in=br.readLine().split(" ");
			for(int j=0;j<c;j++)
				array[i][j]=Integer.parseInt(in[j]);
		}
		for(int i=0;i<r;i++){
			sum=0;
			for(int j=0;j<c;j++)
				sum+=array[i][j];
			array[i][c]=sum;
		}
		for(int i=0;i<=c;i++){
			sum=0;
			for(int j=0;j<r;j++)
				sum+=array[j][i];
			array[r][i]=sum;
		}
		for(int i=0;i<=r;i++){
			System.out.print(array[i][0]);
			for(int j=1;j<=c;j++)
				System.out.print(" "+array[i][j]);
			System.out.println("");
		}
	}
} Main
import java.util.*;
import java.io.*;
import java.lang.*;
import java.math.*;
public class Main{
	public static void main(String[] args) throws IOException{
		Scanner stdIn=new Scanner(System.in);
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		String[] in=br.readLine().split(" ");
		int r=Integer.parseInt(in[0]);
		int c=Integer.parseInt(in[1]);
		int array[][]=new int[r+1][c+1];
		int sum;
		for(int i=0;i<r;i++){
			in=br.readLine().split(" ");
			for(int j=0;j<c;j++)
				array[i][j]=Integer.parseInt(in[j]);
		}
		for(int i=0;i<r;i++){
			sum=0;
			for(int j=0;j<c;j++)
				sum+=array[i][j];
			array[i][c]=sum;
		}
		for(int i=0;i<=c;i++){
			sum=0;
			for(int j=0;j<r;j++)
				sum+=array[j][i];
			array[r][i]=sum;
		}
		for(int i=0;i<=r;i++){
			System.out.print(array[i][0]);
			for(int j=1;j<=c;j++)
				System.out.print(" "+array[i][j]);
			System.out.println("");
		}
	}
}