import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int[][] n=new int[101][101];
int[] tate=new int[101];
int[] yoko=new int[101];

int sum=0;
int x=scan.nextInt();
int y=scan.nextInt();
for(int i=0;i<x;i++){
tate[i]=0;
yoko[i]=0;
}
for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
n[i][j]=scan.nextInt();
tate[j]+=n[i][j];
yoko[i]+=n[i][j];
sum+=n[i][j];
}
}
for(int i=0;i<x+1;i++){
for(int j=0;j<y;j++){
if(i!=x){
System.out.print(n[i][j]);
System.out.print(" ");
if(j==y-1)
System.out.println(yoko[i]);
}
else
System.out.print(tate[j]+" ");
}
}
System.out.println(sum);

}
} import java.util.Scanner; Scanner java.util class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int[][] n=new int[101][101];
int[] tate=new int[101];
int[] yoko=new int[101];

int sum=0;
int x=scan.nextInt();
int y=scan.nextInt();
for(int i=0;i<x;i++){
tate[i]=0;
yoko[i]=0;
}
for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
n[i][j]=scan.nextInt();
tate[j]+=n[i][j];
yoko[i]+=n[i][j];
sum+=n[i][j];
}
}
for(int i=0;i<x+1;i++){
for(int j=0;j<y;j++){
if(i!=x){
System.out.print(n[i][j]);
System.out.print(" ");
if(j==y-1)
System.out.println(yoko[i]);
}
else
System.out.print(tate[j]+" ");
}
}
System.out.println(sum);

}
} Main public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int[][] n=new int[101][101];
int[] tate=new int[101];
int[] yoko=new int[101];

int sum=0;
int x=scan.nextInt();
int y=scan.nextInt();
for(int i=0;i<x;i++){
tate[i]=0;
yoko[i]=0;
}
for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
n[i][j]=scan.nextInt();
tate[j]+=n[i][j];
yoko[i]+=n[i][j];
sum+=n[i][j];
}
}
for(int i=0;i<x+1;i++){
for(int j=0;j<y;j++){
if(i!=x){
System.out.print(n[i][j]);
System.out.print(" ");
if(j==y-1)
System.out.println(yoko[i]);
}
else
System.out.print(tate[j]+" ");
}
}
System.out.println(sum);

} main {
Scanner scan=new Scanner(System.in);
int[][] n=new int[101][101];
int[] tate=new int[101];
int[] yoko=new int[101];

int sum=0;
int x=scan.nextInt();
int y=scan.nextInt();
for(int i=0;i<x;i++){
tate[i]=0;
yoko[i]=0;
}
for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
n[i][j]=scan.nextInt();
tate[j]+=n[i][j];
yoko[i]+=n[i][j];
sum+=n[i][j];
}
}
for(int i=0;i<x+1;i++){
for(int j=0;j<y;j++){
if(i!=x){
System.out.print(n[i][j]);
System.out.print(" ");
if(j==y-1)
System.out.println(yoko[i]);
}
else
System.out.print(tate[j]+" ");
}
}
System.out.println(sum);

} Scanner scan=new Scanner(System.in); scan new Scanner(System.in) int[][] n=new int[101][101]; n new int[101][101] 101 101 int[] tate=new int[101]; tate new int[101] 101 int[] yoko=new int[101]; yoko new int[101] 101 int sum=0; sum 0 int x=scan.nextInt(); x scan.nextInt() scan.nextInt scan int y=scan.nextInt(); y scan.nextInt() scan.nextInt scan for(int i=0;i<x;i++){
tate[i]=0;
yoko[i]=0;
} int i=0; int i=0; i 0 i<x i x i++ i++ i {
tate[i]=0;
yoko[i]=0;
} {
tate[i]=0;
yoko[i]=0;
} tate[i]=0 tate[i] tate i 0 yoko[i]=0 yoko[i] yoko i 0 for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
n[i][j]=scan.nextInt();
tate[j]+=n[i][j];
yoko[i]+=n[i][j];
sum+=n[i][j];
}
} int i=0; int i=0; i 0 i<x i x i++ i++ i {
for(int j=0;j<y;j++){
n[i][j]=scan.nextInt();
tate[j]+=n[i][j];
yoko[i]+=n[i][j];
sum+=n[i][j];
}
} {
for(int j=0;j<y;j++){
n[i][j]=scan.nextInt();
tate[j]+=n[i][j];
yoko[i]+=n[i][j];
sum+=n[i][j];
}
} for(int j=0;j<y;j++){
n[i][j]=scan.nextInt();
tate[j]+=n[i][j];
yoko[i]+=n[i][j];
sum+=n[i][j];
} int j=0; int j=0; j 0 j<y j y j++ j++ j {
n[i][j]=scan.nextInt();
tate[j]+=n[i][j];
yoko[i]+=n[i][j];
sum+=n[i][j];
} {
n[i][j]=scan.nextInt();
tate[j]+=n[i][j];
yoko[i]+=n[i][j];
sum+=n[i][j];
} n[i][j]=scan.nextInt() n[i][j] n[i] n i j scan.nextInt() scan.nextInt scan tate[j]+=n[i][j] tate[j] tate j n[i][j] n[i] n i j yoko[i]+=n[i][j] yoko[i] yoko i n[i][j] n[i] n i j sum+=n[i][j] sum n[i][j] n[i] n i j for(int i=0;i<x+1;i++){
for(int j=0;j<y;j++){
if(i!=x){
System.out.print(n[i][j]);
System.out.print(" ");
if(j==y-1)
System.out.println(yoko[i]);
}
else
System.out.print(tate[j]+" ");
}
} int i=0; int i=0; i 0 i<x+1 i x+1 x 1 i++ i++ i {
for(int j=0;j<y;j++){
if(i!=x){
System.out.print(n[i][j]);
System.out.print(" ");
if(j==y-1)
System.out.println(yoko[i]);
}
else
System.out.print(tate[j]+" ");
}
} {
for(int j=0;j<y;j++){
if(i!=x){
System.out.print(n[i][j]);
System.out.print(" ");
if(j==y-1)
System.out.println(yoko[i]);
}
else
System.out.print(tate[j]+" ");
}
} for(int j=0;j<y;j++){
if(i!=x){
System.out.print(n[i][j]);
System.out.print(" ");
if(j==y-1)
System.out.println(yoko[i]);
}
else
System.out.print(tate[j]+" ");
} int j=0; int j=0; j 0 j<y j y j++ j++ j {
if(i!=x){
System.out.print(n[i][j]);
System.out.print(" ");
if(j==y-1)
System.out.println(yoko[i]);
}
else
System.out.print(tate[j]+" ");
} {
if(i!=x){
System.out.print(n[i][j]);
System.out.print(" ");
if(j==y-1)
System.out.println(yoko[i]);
}
else
System.out.print(tate[j]+" ");
} if(i!=x){
System.out.print(n[i][j]);
System.out.print(" ");
if(j==y-1)
System.out.println(yoko[i]);
}
else
System.out.print(tate[j]+" "); i!=x i x {
System.out.print(n[i][j]);
System.out.print(" ");
if(j==y-1)
System.out.println(yoko[i]);
} System.out.print(n[i][j]) System.out.print System.out System System.out n[i][j] n[i] n i j System.out.print(" ") System.out.print System.out System System.out " " if(j==y-1)
System.out.println(yoko[i]); j==y-1 j y-1 y 1 System.out.println(yoko[i]) System.out.println System.out System System.out yoko[i] yoko i System.out.print(tate[j]+" ") System.out.print System.out System System.out tate[j]+" " tate[j] tate j " " System.out.println(sum) System.out.println System.out System System.out sum String[] args args
import java.util.Scanner;
class Main{
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
int[][] n=new int[101][101];
int[] tate=new int[101];
int[] yoko=new int[101];

int sum=0;
int x=scan.nextInt();
int y=scan.nextInt();
for(int i=0;i<x;i++){
tate[i]=0;
yoko[i]=0;
}
for(int i=0;i<x;i++){
for(int j=0;j<y;j++){
n[i][j]=scan.nextInt();
tate[j]+=n[i][j];
yoko[i]+=n[i][j];
sum+=n[i][j];
}
}
for(int i=0;i<x+1;i++){
for(int j=0;j<y;j++){
if(i!=x){
System.out.print(n[i][j]);
System.out.print(" ");
if(j==y-1)
System.out.println(yoko[i]);
}
else
System.out.print(tate[j]+" ");
}
}
System.out.println(sum);

}
}