import java.util.Scanner;

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

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