import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int a[][]=new int[101][101];
		int i,j;
		
		int r=scan.nextInt(); int c=scan.nextInt();
		
		//初期化
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				a[i][j]=0;
			}
		}
		
		//読み込みと計算
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]+=a[i][j];
				a[r][j]+=a[i][j];
			}
			a[r][c]+=a[i][c];
		}
		
		//表示
		for(i=0;i<=r;i++){
			for(j=0;j<c;j++){
				System.out.printf("%d ",a[i][j]);
			}
			System.out.println(a[i][c]);
		}
		
	}
} import java.util.Scanner; Scanner java.util public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int a[][]=new int[101][101];
		int i,j;
		
		int r=scan.nextInt(); int c=scan.nextInt();
		
		//初期化
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				a[i][j]=0;
			}
		}
		
		//読み込みと計算
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]+=a[i][j];
				a[r][j]+=a[i][j];
			}
			a[r][c]+=a[i][c];
		}
		
		//表示
		for(i=0;i<=r;i++){
			for(j=0;j<c;j++){
				System.out.printf("%d ",a[i][j]);
			}
			System.out.println(a[i][c]);
		}
		
	}
} Main public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int a[][]=new int[101][101];
		int i,j;
		
		int r=scan.nextInt(); int c=scan.nextInt();
		
		//初期化
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				a[i][j]=0;
			}
		}
		
		//読み込みと計算
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]+=a[i][j];
				a[r][j]+=a[i][j];
			}
			a[r][c]+=a[i][c];
		}
		
		//表示
		for(i=0;i<=r;i++){
			for(j=0;j<c;j++){
				System.out.printf("%d ",a[i][j]);
			}
			System.out.println(a[i][c]);
		}
		
	} main {
		Scanner scan=new Scanner(System.in);
		int a[][]=new int[101][101];
		int i,j;
		
		int r=scan.nextInt(); int c=scan.nextInt();
		
		//初期化
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				a[i][j]=0;
			}
		}
		
		//読み込みと計算
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]+=a[i][j];
				a[r][j]+=a[i][j];
			}
			a[r][c]+=a[i][c];
		}
		
		//表示
		for(i=0;i<=r;i++){
			for(j=0;j<c;j++){
				System.out.printf("%d ",a[i][j]);
			}
			System.out.println(a[i][c]);
		}
		
	} Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int a[][]=new int[101][101]; a new int[101][101] 101 101 int i i j; j int r=scan.nextInt(); r scan.nextInt() scan.nextInt scan int c=scan.nextInt(); c scan.nextInt() scan.nextInt scan for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				a[i][j]=0;
			}
		} i=0; i=0 i 0 i<=r i r i++ i++ i {
			for(j=0;j<=c;j++){
				a[i][j]=0;
			}
		} {
			for(j=0;j<=c;j++){
				a[i][j]=0;
			}
		} for(j=0;j<=c;j++){
				a[i][j]=0;
			} j=0; j=0 j 0 j<=c j c j++ j++ j {
				a[i][j]=0;
			} {
				a[i][j]=0;
			} a[i][j]=0 a[i][j] a[i] a i j 0 for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]+=a[i][j];
				a[r][j]+=a[i][j];
			}
			a[r][c]+=a[i][c];
		} i=0; i=0 i 0 i<r i r i++ i++ i {
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]+=a[i][j];
				a[r][j]+=a[i][j];
			}
			a[r][c]+=a[i][c];
		} {
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]+=a[i][j];
				a[r][j]+=a[i][j];
			}
			a[r][c]+=a[i][c];
		} for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]+=a[i][j];
				a[r][j]+=a[i][j];
			} j=0; j=0 j 0 j<c j c j++ j++ j {
				a[i][j]=scan.nextInt();
				a[i][c]+=a[i][j];
				a[r][j]+=a[i][j];
			} {
				a[i][j]=scan.nextInt();
				a[i][c]+=a[i][j];
				a[r][j]+=a[i][j];
			} a[i][j]=scan.nextInt() a[i][j] a[i] a i j scan.nextInt() scan.nextInt scan a[i][c]+=a[i][j] a[i][c] a[i] a i c a[i][j] a[i] a i j a[r][j]+=a[i][j] a[r][j] a[r] a r j a[i][j] a[i] a i j a[r][c]+=a[i][c] a[r][c] a[r] a r c a[i][c] a[i] a i c for(i=0;i<=r;i++){
			for(j=0;j<c;j++){
				System.out.printf("%d ",a[i][j]);
			}
			System.out.println(a[i][c]);
		} i=0; i=0 i 0 i<=r i r i++ i++ i {
			for(j=0;j<c;j++){
				System.out.printf("%d ",a[i][j]);
			}
			System.out.println(a[i][c]);
		} {
			for(j=0;j<c;j++){
				System.out.printf("%d ",a[i][j]);
			}
			System.out.println(a[i][c]);
		} for(j=0;j<c;j++){
				System.out.printf("%d ",a[i][j]);
			} j=0; j=0 j 0 j<c j c j++ j++ j {
				System.out.printf("%d ",a[i][j]);
			} {
				System.out.printf("%d ",a[i][j]);
			} System.out.printf("%d ",a[i][j]) System.out.printf System.out System System.out "%d " a[i][j] a[i] a i j System.out.println(a[i][c]) System.out.println System.out System System.out a[i][c] a[i] a i c String[] args args public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int a[][]=new int[101][101];
		int i,j;
		
		int r=scan.nextInt(); int c=scan.nextInt();
		
		//初期化
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				a[i][j]=0;
			}
		}
		
		//読み込みと計算
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]+=a[i][j];
				a[r][j]+=a[i][j];
			}
			a[r][c]+=a[i][c];
		}
		
		//表示
		for(i=0;i<=r;i++){
			for(j=0;j<c;j++){
				System.out.printf("%d ",a[i][j]);
			}
			System.out.println(a[i][c]);
		}
		
	}
} public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int a[][]=new int[101][101];
		int i,j;
		
		int r=scan.nextInt(); int c=scan.nextInt();
		
		//初期化
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				a[i][j]=0;
			}
		}
		
		//読み込みと計算
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]+=a[i][j];
				a[r][j]+=a[i][j];
			}
			a[r][c]+=a[i][c];
		}
		
		//表示
		for(i=0;i<=r;i++){
			for(j=0;j<c;j++){
				System.out.printf("%d ",a[i][j]);
			}
			System.out.println(a[i][c]);
		}
		
	}
} Main
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		int a[][]=new int[101][101];
		int i,j;
		
		int r=scan.nextInt(); int c=scan.nextInt();
		
		//初期化
		for(i=0;i<=r;i++){
			for(j=0;j<=c;j++){
				a[i][j]=0;
			}
		}
		
		//読み込みと計算
		for(i=0;i<r;i++){
			for(j=0;j<c;j++){
				a[i][j]=scan.nextInt();
				a[i][c]+=a[i][j];
				a[r][j]+=a[i][j];
			}
			a[r][c]+=a[i][c];
		}
		
		//表示
		for(i=0;i<=r;i++){
			for(j=0;j<c;j++){
				System.out.printf("%d ",a[i][j]);
			}
			System.out.println(a[i][c]);
		}
		
	}
}
