import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        
        int[][] array = new int[r + 1][c + 1];
        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                array[i][j] = sc.nextInt();
                array[i][c] += array[i][j];
                array[r][j] += array[i][j];
            }
            array[r][c] += array[i][c];
        }
        
        for(int i = 0; i < r + 1; i++){
            System.out.print(array[i][0]);
            for(int j = 1; j < c + 1; j++){
                System.out.print(" " + array[i][j]);
            }
            System.out.println();
        }
    }
} import java.util.Scanner; Scanner java.util public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        
        int[][] array = new int[r + 1][c + 1];
        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                array[i][j] = sc.nextInt();
                array[i][c] += array[i][j];
                array[r][j] += array[i][j];
            }
            array[r][c] += array[i][c];
        }
        
        for(int i = 0; i < r + 1; i++){
            System.out.print(array[i][0]);
            for(int j = 1; j < c + 1; j++){
                System.out.print(" " + array[i][j]);
            }
            System.out.println();
        }
    }
} Main public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        
        int[][] array = new int[r + 1][c + 1];
        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                array[i][j] = sc.nextInt();
                array[i][c] += array[i][j];
                array[r][j] += array[i][j];
            }
            array[r][c] += array[i][c];
        }
        
        for(int i = 0; i < r + 1; i++){
            System.out.print(array[i][0]);
            for(int j = 1; j < c + 1; j++){
                System.out.print(" " + array[i][j]);
            }
            System.out.println();
        }
    } main {
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        
        int[][] array = new int[r + 1][c + 1];
        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                array[i][j] = sc.nextInt();
                array[i][c] += array[i][j];
                array[r][j] += array[i][j];
            }
            array[r][c] += array[i][c];
        }
        
        for(int i = 0; i < r + 1; i++){
            System.out.print(array[i][0]);
            for(int j = 1; j < c + 1; j++){
                System.out.print(" " + array[i][j]);
            }
            System.out.println();
        }
    } 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[][] array = new int[r + 1][c + 1]; array 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++){
                array[i][j] = sc.nextInt();
                array[i][c] += array[i][j];
                array[r][j] += array[i][j];
            }
            array[r][c] += array[i][c];
        } int i = 0; int i = 0; i 0 i < r i r i++ i++ i {
            for(int j = 0; j < c; j++){
                array[i][j] = sc.nextInt();
                array[i][c] += array[i][j];
                array[r][j] += array[i][j];
            }
            array[r][c] += array[i][c];
        } {
            for(int j = 0; j < c; j++){
                array[i][j] = sc.nextInt();
                array[i][c] += array[i][j];
                array[r][j] += array[i][j];
            }
            array[r][c] += array[i][c];
        } for(int j = 0; j < c; j++){
                array[i][j] = sc.nextInt();
                array[i][c] += array[i][j];
                array[r][j] += array[i][j];
            } int j = 0; int j = 0; j 0 j < c j c j++ j++ j {
                array[i][j] = sc.nextInt();
                array[i][c] += array[i][j];
                array[r][j] += array[i][j];
            } {
                array[i][j] = sc.nextInt();
                array[i][c] += array[i][j];
                array[r][j] += array[i][j];
            } array[i][j] = sc.nextInt() array[i][j] array[i] array i j sc.nextInt() sc.nextInt sc array[i][c] += array[i][j] array[i][c] array[i] array i c array[i][j] array[i] array i j array[r][j] += array[i][j] array[r][j] array[r] array r j array[i][j] array[i] array i j array[r][c] += array[i][c] array[r][c] array[r] array r c array[i][c] array[i] array i c for(int i = 0; i < r + 1; i++){
            System.out.print(array[i][0]);
            for(int j = 1; j < c + 1; j++){
                System.out.print(" " + array[i][j]);
            }
            System.out.println();
        } int i = 0; int i = 0; i 0 i < r + 1 i r + 1 r 1 i++ i++ i {
            System.out.print(array[i][0]);
            for(int j = 1; j < c + 1; j++){
                System.out.print(" " + array[i][j]);
            }
            System.out.println();
        } {
            System.out.print(array[i][0]);
            for(int j = 1; j < c + 1; j++){
                System.out.print(" " + array[i][j]);
            }
            System.out.println();
        } System.out.print(array[i][0]) System.out.print System.out System System.out array[i][0] array[i] array i 0 for(int j = 1; j < c + 1; j++){
                System.out.print(" " + array[i][j]);
            } int j = 1; int j = 1; j 1 j < c + 1 j c + 1 c 1 j++ j++ j {
                System.out.print(" " + array[i][j]);
            } {
                System.out.print(" " + array[i][j]);
            } System.out.print(" " + array[i][j]) System.out.print System.out System System.out " " + array[i][j] " " array[i][j] array[i] array i j System.out.println() System.out.println System.out System System.out String[] args args public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        
        int[][] array = new int[r + 1][c + 1];
        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                array[i][j] = sc.nextInt();
                array[i][c] += array[i][j];
                array[r][j] += array[i][j];
            }
            array[r][c] += array[i][c];
        }
        
        for(int i = 0; i < r + 1; i++){
            System.out.print(array[i][0]);
            for(int j = 1; j < c + 1; j++){
                System.out.print(" " + array[i][j]);
            }
            System.out.println();
        }
    }
} public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int r = sc.nextInt();
        int c = sc.nextInt();
        
        int[][] array = new int[r + 1][c + 1];
        for(int i = 0; i < r; i++){
            for(int j = 0; j < c; j++){
                array[i][j] = sc.nextInt();
                array[i][c] += array[i][j];
                array[r][j] += array[i][j];
            }
            array[r][c] += array[i][c];
        }
        
        for(int i = 0; i < r + 1; i++){
            System.out.print(array[i][0]);
            for(int j = 1; j < c + 1; j++){
                System.out.print(" " + array[i][j]);
            }
            System.out.println();
        }
    }
} Main
import java.util.Scanner;

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