import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int r=Integer.parseInt(sc.next());
int c=Integer.parseInt(sc.next());
int[][] rc=new int[r+1][c+1];
for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
    rc[i][j]=sc.nextInt();
   
    }
}
for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
 rc[i][c]+=rc[i][j];
    rc[r][j]+=rc[i][j];
   rc[r][c]+=rc[i][j];
    }
}

for(int j=0;j<r+1;j++){
    for(int i=0;i<c+1;i++){
    if(i!=c){System.out.print(rc[j][i]+" ");}else{System.out.println(rc[j][i]);}
    }
}

}
} import java.util.*; util.* java public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int r=Integer.parseInt(sc.next());
int c=Integer.parseInt(sc.next());
int[][] rc=new int[r+1][c+1];
for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
    rc[i][j]=sc.nextInt();
   
    }
}
for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
 rc[i][c]+=rc[i][j];
    rc[r][j]+=rc[i][j];
   rc[r][c]+=rc[i][j];
    }
}

for(int j=0;j<r+1;j++){
    for(int i=0;i<c+1;i++){
    if(i!=c){System.out.print(rc[j][i]+" ");}else{System.out.println(rc[j][i]);}
    }
}

}
} Main public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int r=Integer.parseInt(sc.next());
int c=Integer.parseInt(sc.next());
int[][] rc=new int[r+1][c+1];
for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
    rc[i][j]=sc.nextInt();
   
    }
}
for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
 rc[i][c]+=rc[i][j];
    rc[r][j]+=rc[i][j];
   rc[r][c]+=rc[i][j];
    }
}

for(int j=0;j<r+1;j++){
    for(int i=0;i<c+1;i++){
    if(i!=c){System.out.print(rc[j][i]+" ");}else{System.out.println(rc[j][i]);}
    }
}

} main {
Scanner sc = new Scanner(System.in);
int r=Integer.parseInt(sc.next());
int c=Integer.parseInt(sc.next());
int[][] rc=new int[r+1][c+1];
for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
    rc[i][j]=sc.nextInt();
   
    }
}
for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
 rc[i][c]+=rc[i][j];
    rc[r][j]+=rc[i][j];
   rc[r][c]+=rc[i][j];
    }
}

for(int j=0;j<r+1;j++){
    for(int i=0;i<c+1;i++){
    if(i!=c){System.out.print(rc[j][i]+" ");}else{System.out.println(rc[j][i]);}
    }
}

} Scanner sc = new Scanner(System.in); sc new Scanner(System.in) int r=Integer.parseInt(sc.next()); r Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int c=Integer.parseInt(sc.next()); c Integer.parseInt(sc.next()) Integer.parseInt Integer sc.next() sc.next sc int[][] rc=new int[r+1][c+1]; rc new int[r+1][c+1] r+1 r 1 c+1 c 1 for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
    rc[i][j]=sc.nextInt();
   
    }
} int i=0; int i=0; i 0 i<r i r i++ i++ i {
    for(int j=0;j<c;j++){
    rc[i][j]=sc.nextInt();
   
    }
} {
    for(int j=0;j<c;j++){
    rc[i][j]=sc.nextInt();
   
    }
} for(int j=0;j<c;j++){
    rc[i][j]=sc.nextInt();
   
    } int j=0; int j=0; j 0 j<c j c j++ j++ j {
    rc[i][j]=sc.nextInt();
   
    } {
    rc[i][j]=sc.nextInt();
   
    } rc[i][j]=sc.nextInt() rc[i][j] rc[i] rc i j sc.nextInt() sc.nextInt sc for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
 rc[i][c]+=rc[i][j];
    rc[r][j]+=rc[i][j];
   rc[r][c]+=rc[i][j];
    }
} int i=0; int i=0; i 0 i<r i r i++ i++ i {
    for(int j=0;j<c;j++){
 rc[i][c]+=rc[i][j];
    rc[r][j]+=rc[i][j];
   rc[r][c]+=rc[i][j];
    }
} {
    for(int j=0;j<c;j++){
 rc[i][c]+=rc[i][j];
    rc[r][j]+=rc[i][j];
   rc[r][c]+=rc[i][j];
    }
} for(int j=0;j<c;j++){
 rc[i][c]+=rc[i][j];
    rc[r][j]+=rc[i][j];
   rc[r][c]+=rc[i][j];
    } int j=0; int j=0; j 0 j<c j c j++ j++ j {
 rc[i][c]+=rc[i][j];
    rc[r][j]+=rc[i][j];
   rc[r][c]+=rc[i][j];
    } {
 rc[i][c]+=rc[i][j];
    rc[r][j]+=rc[i][j];
   rc[r][c]+=rc[i][j];
    } rc[i][c]+=rc[i][j] rc[i][c] rc[i] rc i c rc[i][j] rc[i] rc i j rc[r][j]+=rc[i][j] rc[r][j] rc[r] rc r j rc[i][j] rc[i] rc i j rc[r][c]+=rc[i][j] rc[r][c] rc[r] rc r c rc[i][j] rc[i] rc i j for(int j=0;j<r+1;j++){
    for(int i=0;i<c+1;i++){
    if(i!=c){System.out.print(rc[j][i]+" ");}else{System.out.println(rc[j][i]);}
    }
} int j=0; int j=0; j 0 j<r+1 j r+1 r 1 j++ j++ j {
    for(int i=0;i<c+1;i++){
    if(i!=c){System.out.print(rc[j][i]+" ");}else{System.out.println(rc[j][i]);}
    }
} {
    for(int i=0;i<c+1;i++){
    if(i!=c){System.out.print(rc[j][i]+" ");}else{System.out.println(rc[j][i]);}
    }
} for(int i=0;i<c+1;i++){
    if(i!=c){System.out.print(rc[j][i]+" ");}else{System.out.println(rc[j][i]);}
    } int i=0; int i=0; i 0 i<c+1 i c+1 c 1 i++ i++ i {
    if(i!=c){System.out.print(rc[j][i]+" ");}else{System.out.println(rc[j][i]);}
    } {
    if(i!=c){System.out.print(rc[j][i]+" ");}else{System.out.println(rc[j][i]);}
    } if(i!=c){System.out.print(rc[j][i]+" ");}else{System.out.println(rc[j][i]);} i!=c i c {System.out.print(rc[j][i]+" ");} System.out.print(rc[j][i]+" ") System.out.print System.out System System.out rc[j][i]+" " rc[j][i] rc[j] rc j i " " {System.out.println(rc[j][i]);} System.out.println(rc[j][i]) System.out.println System.out System System.out rc[j][i] rc[j] rc j i String[] args args public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int r=Integer.parseInt(sc.next());
int c=Integer.parseInt(sc.next());
int[][] rc=new int[r+1][c+1];
for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
    rc[i][j]=sc.nextInt();
   
    }
}
for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
 rc[i][c]+=rc[i][j];
    rc[r][j]+=rc[i][j];
   rc[r][c]+=rc[i][j];
    }
}

for(int j=0;j<r+1;j++){
    for(int i=0;i<c+1;i++){
    if(i!=c){System.out.print(rc[j][i]+" ");}else{System.out.println(rc[j][i]);}
    }
}

}
} public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int r=Integer.parseInt(sc.next());
int c=Integer.parseInt(sc.next());
int[][] rc=new int[r+1][c+1];
for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
    rc[i][j]=sc.nextInt();
   
    }
}
for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
 rc[i][c]+=rc[i][j];
    rc[r][j]+=rc[i][j];
   rc[r][c]+=rc[i][j];
    }
}

for(int j=0;j<r+1;j++){
    for(int i=0;i<c+1;i++){
    if(i!=c){System.out.print(rc[j][i]+" ");}else{System.out.println(rc[j][i]);}
    }
}

}
} Main
import java.util.*;
public class Main {
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int r=Integer.parseInt(sc.next());
int c=Integer.parseInt(sc.next());
int[][] rc=new int[r+1][c+1];
for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
    rc[i][j]=sc.nextInt();
   
    }
}
for(int i=0;i<r;i++){
    for(int j=0;j<c;j++){
 rc[i][c]+=rc[i][j];
    rc[r][j]+=rc[i][j];
   rc[r][c]+=rc[i][j];
    }
}

for(int j=0;j<r+1;j++){
    for(int i=0;i<c+1;i++){
    if(i!=c){System.out.print(rc[j][i]+" ");}else{System.out.println(rc[j][i]);}
    }
}

}
}
