import java.util.Scanner;

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

class Main{
	public static void main(String[] args){
		Scanner stdIn=new Scanner(System.in);
		int r,c,a[][]=new int[101][101],i,j;
		r=stdIn.nextInt();
		c=stdIn.nextInt();
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				a[i][j]=stdIn.nextInt();
				a[i][c]+=a[i][j];
			}
		}
		for(i=0;i<c;i++){
			for(j=0;j<r;j++)a[r][i]+=a[j][i];
			a[r][c]+=a[r][i];
		}
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				if(j!=0)System.out.print(" ");
				System.out.print(a[i][j]);
			}
			System.out.println();
		}
	}
}
