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