import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] ar = br.readLine().split(" ");
        int x = Integer.parseInt(ar[0]);
        int y = Integer.parseInt(ar[1]);
        int[][] list = new int[x+1][y+1];
        for(int i = 0; i < x; i++){
            ar = br.readLine().split(" ");
            for(int j = 0; j < y; j++){
                list[i][j] = Integer.parseInt(ar[j]);
            }
        }
        for(int i = 0; i < list.length; i++){
            for(int j = 0; j < list[i].length; j++){
                if(j == list[i].length-1){
                    System.out.println(list[i][j]);
                }else if(i == list.length-1){
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }else{
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }
            }
        }
    }
} import java.io.BufferedReader; BufferedReader java.io import java.io.InputStreamReader; InputStreamReader java.io public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] ar = br.readLine().split(" ");
        int x = Integer.parseInt(ar[0]);
        int y = Integer.parseInt(ar[1]);
        int[][] list = new int[x+1][y+1];
        for(int i = 0; i < x; i++){
            ar = br.readLine().split(" ");
            for(int j = 0; j < y; j++){
                list[i][j] = Integer.parseInt(ar[j]);
            }
        }
        for(int i = 0; i < list.length; i++){
            for(int j = 0; j < list[i].length; j++){
                if(j == list[i].length-1){
                    System.out.println(list[i][j]);
                }else if(i == list.length-1){
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }else{
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }
            }
        }
    }
} Main public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] ar = br.readLine().split(" ");
        int x = Integer.parseInt(ar[0]);
        int y = Integer.parseInt(ar[1]);
        int[][] list = new int[x+1][y+1];
        for(int i = 0; i < x; i++){
            ar = br.readLine().split(" ");
            for(int j = 0; j < y; j++){
                list[i][j] = Integer.parseInt(ar[j]);
            }
        }
        for(int i = 0; i < list.length; i++){
            for(int j = 0; j < list[i].length; j++){
                if(j == list[i].length-1){
                    System.out.println(list[i][j]);
                }else if(i == list.length-1){
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }else{
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }
            }
        }
    } main {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] ar = br.readLine().split(" ");
        int x = Integer.parseInt(ar[0]);
        int y = Integer.parseInt(ar[1]);
        int[][] list = new int[x+1][y+1];
        for(int i = 0; i < x; i++){
            ar = br.readLine().split(" ");
            for(int j = 0; j < y; j++){
                list[i][j] = Integer.parseInt(ar[j]);
            }
        }
        for(int i = 0; i < list.length; i++){
            for(int j = 0; j < list[i].length; j++){
                if(j == list[i].length-1){
                    System.out.println(list[i][j]);
                }else if(i == list.length-1){
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }else{
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }
            }
        }
    } BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); br new BufferedReader(new InputStreamReader(System.in)) String[] ar = br.readLine().split(" "); ar br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " int x = Integer.parseInt(ar[0]); x Integer.parseInt(ar[0]) Integer.parseInt Integer ar[0] ar 0 int y = Integer.parseInt(ar[1]); y Integer.parseInt(ar[1]) Integer.parseInt Integer ar[1] ar 1 int[][] list = new int[x+1][y+1]; list new int[x+1][y+1] x+1 x 1 y+1 y 1 for(int i = 0; i < x; i++){
            ar = br.readLine().split(" ");
            for(int j = 0; j < y; j++){
                list[i][j] = Integer.parseInt(ar[j]);
            }
        } int i = 0; int i = 0; i 0 i < x i x i++ i++ i {
            ar = br.readLine().split(" ");
            for(int j = 0; j < y; j++){
                list[i][j] = Integer.parseInt(ar[j]);
            }
        } {
            ar = br.readLine().split(" ");
            for(int j = 0; j < y; j++){
                list[i][j] = Integer.parseInt(ar[j]);
            }
        } ar = br.readLine().split(" ") ar br.readLine().split(" ") br.readLine().split br.readLine() br.readLine br " " for(int j = 0; j < y; j++){
                list[i][j] = Integer.parseInt(ar[j]);
            } int j = 0; int j = 0; j 0 j < y j y j++ j++ j {
                list[i][j] = Integer.parseInt(ar[j]);
            } {
                list[i][j] = Integer.parseInt(ar[j]);
            } list[i][j] = Integer.parseInt(ar[j]) list[i][j] list[i] list i j Integer.parseInt(ar[j]) Integer.parseInt Integer ar[j] ar j for(int i = 0; i < list.length; i++){
            for(int j = 0; j < list[i].length; j++){
                if(j == list[i].length-1){
                    System.out.println(list[i][j]);
                }else if(i == list.length-1){
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }else{
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }
            }
        } int i = 0; int i = 0; i 0 i < list.length i list.length list list.length i++ i++ i {
            for(int j = 0; j < list[i].length; j++){
                if(j == list[i].length-1){
                    System.out.println(list[i][j]);
                }else if(i == list.length-1){
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }else{
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }
            }
        } {
            for(int j = 0; j < list[i].length; j++){
                if(j == list[i].length-1){
                    System.out.println(list[i][j]);
                }else if(i == list.length-1){
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }else{
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }
            }
        } for(int j = 0; j < list[i].length; j++){
                if(j == list[i].length-1){
                    System.out.println(list[i][j]);
                }else if(i == list.length-1){
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }else{
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }
            } int j = 0; int j = 0; j 0 j < list[i].length j list[i].length list[i] list i list[i].length j++ j++ j {
                if(j == list[i].length-1){
                    System.out.println(list[i][j]);
                }else if(i == list.length-1){
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }else{
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }
            } {
                if(j == list[i].length-1){
                    System.out.println(list[i][j]);
                }else if(i == list.length-1){
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }else{
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }
            } if(j == list[i].length-1){
                    System.out.println(list[i][j]);
                }else if(i == list.length-1){
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }else{
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                } j == list[i].length-1 j list[i].length-1 list[i].length list[i] list i list[i].length 1 {
                    System.out.println(list[i][j]);
                } System.out.println(list[i][j]) System.out.println System.out System System.out list[i][j] list[i] list i j if(i == list.length-1){
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }else{
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                } i == list.length-1 i list.length-1 list.length list list.length 1 {
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                } list[i][y] += list[i][j] list[i][y] list[i] list i y list[i][j] list[i] list i j System.out.print(list[i][j]+" ") System.out.print System.out System System.out list[i][j]+" " list[i][j] list[i] list i j " " {
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                } list[i][y] += list[i][j] list[i][y] list[i] list i y list[i][j] list[i] list i j list[x][j] += list[i][j] list[x][j] list[x] list x j list[i][j] list[i] list i j System.out.print(list[i][j]+" ") System.out.print System.out System System.out list[i][j]+" " list[i][j] list[i] list i j " " String[] args args public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] ar = br.readLine().split(" ");
        int x = Integer.parseInt(ar[0]);
        int y = Integer.parseInt(ar[1]);
        int[][] list = new int[x+1][y+1];
        for(int i = 0; i < x; i++){
            ar = br.readLine().split(" ");
            for(int j = 0; j < y; j++){
                list[i][j] = Integer.parseInt(ar[j]);
            }
        }
        for(int i = 0; i < list.length; i++){
            for(int j = 0; j < list[i].length; j++){
                if(j == list[i].length-1){
                    System.out.println(list[i][j]);
                }else if(i == list.length-1){
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }else{
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }
            }
        }
    }
} public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] ar = br.readLine().split(" ");
        int x = Integer.parseInt(ar[0]);
        int y = Integer.parseInt(ar[1]);
        int[][] list = new int[x+1][y+1];
        for(int i = 0; i < x; i++){
            ar = br.readLine().split(" ");
            for(int j = 0; j < y; j++){
                list[i][j] = Integer.parseInt(ar[j]);
            }
        }
        for(int i = 0; i < list.length; i++){
            for(int j = 0; j < list[i].length; j++){
                if(j == list[i].length-1){
                    System.out.println(list[i][j]);
                }else if(i == list.length-1){
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }else{
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }
            }
        }
    }
} Main
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] ar = br.readLine().split(" ");
        int x = Integer.parseInt(ar[0]);
        int y = Integer.parseInt(ar[1]);
        int[][] list = new int[x+1][y+1];
        for(int i = 0; i < x; i++){
            ar = br.readLine().split(" ");
            for(int j = 0; j < y; j++){
                list[i][j] = Integer.parseInt(ar[j]);
            }
        }
        for(int i = 0; i < list.length; i++){
            for(int j = 0; j < list[i].length; j++){
                if(j == list[i].length-1){
                    System.out.println(list[i][j]);
                }else if(i == list.length-1){
                    list[i][y] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }else{
                    list[i][y] += list[i][j];
                    list[x][j] += list[i][j];
                    System.out.print(list[i][j]+" ");
                }
            }
        }
    }
}